base_prefix . 'top_ten'; $resultscount = $wpdb->get_row( $wpdb->prepare( "SELECT postnumber, cntaccess FROM {$table_name} WHERE postnumber = %d AND blog_id = %d ", $id, $blog_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $cntaccess = tptn_number_format_i18n( ( ( $resultscount ) ? $resultscount->cntaccess : 0 ) ); echo esc_html( $cntaccess ); } // Now process daily count. if ( ( 'tptn_daily' === $column_name ) && ( tptn_get_option( 'pv_in_admin' ) ) ) { $table_name = $wpdb->base_prefix . 'top_ten_daily'; $from_date = tptn_get_from_date(); $resultscount = $wpdb->get_row( $wpdb->prepare( "SELECT postnumber, SUM(cntaccess) as visits FROM {$table_name} WHERE postnumber = %d AND dp_date >= %s AND blog_id = %d GROUP BY postnumber ", $id, $from_date, $blog_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $cntaccess = tptn_number_format_i18n( ( ( $resultscount ) ? $resultscount->visits : 0 ) ); echo esc_html( $cntaccess ); } // Now process both. if ( ( 'tptn_both' === $column_name ) && ( tptn_get_option( 'pv_in_admin' ) ) ) { $table_name = $wpdb->base_prefix . 'top_ten'; $resultscount = $wpdb->get_row( $wpdb->prepare( "SELECT postnumber, cntaccess FROM {$table_name} WHERE postnumber = %d AND blog_id = %d ", $id, $blog_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $cntaccess = tptn_number_format_i18n( ( ( $resultscount ) ? $resultscount->cntaccess : 0 ) ); $table_name = $wpdb->base_prefix . 'top_ten_daily'; $from_date = tptn_get_from_date(); $resultscount = $wpdb->get_row( $wpdb->prepare( "SELECT postnumber, SUM(cntaccess) as visits FROM {$table_name} WHERE postnumber = %d AND dp_date >= %s AND blog_id = %d GROUP BY postnumber ", $id, $from_date, $blog_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $cntaccess .= ' / ' . tptn_number_format_i18n( ( ( $resultscount ) ? $resultscount->visits : 0 ) ); echo esc_html( $cntaccess ); } } add_action( 'manage_posts_custom_column', 'tptn_value', 10, 2 ); add_action( 'manage_pages_custom_column', 'tptn_value', 10, 2 ); /** * Register the columns as sortable. * * @since 1.9.8.2 * * @param array $cols Array with column names. * @return array Filtered columns array */ function tptn_column_register_sortable( $cols ) { if ( tptn_get_option( 'pv_in_admin' ) ) { $cols['tptn_total'] = array( 'tptn_total', true ); $cols['tptn_daily'] = array( 'tptn_daily', true ); } return $cols; } add_filter( 'manage_edit-post_sortable_columns', 'tptn_column_register_sortable' ); add_filter( 'manage_edit-page_sortable_columns', 'tptn_column_register_sortable' ); /** * Add custom post clauses to sort the columns. * * @since 1.9.8.2 * * @param array $clauses Lookup clauses. * @param object $wp_query WP Query object. * @return array Filtered clauses */ function tptn_column_clauses( $clauses, $wp_query ) { global $wpdb; if ( isset( $wp_query->query['orderby'] ) && 'tptn_total' === $wp_query->query['orderby'] ) { $table_name = $wpdb->base_prefix . 'top_ten'; $clauses['join'] .= "LEFT OUTER JOIN {$table_name} ON {$wpdb->posts}.ID={$table_name}.postnumber"; $clauses['orderby'] = 'cntaccess '; $clauses['orderby'] .= ( 'ASC' === strtoupper( $wp_query->get( 'order' ) ) ) ? 'ASC' : 'DESC'; } if ( isset( $wp_query->query['orderby'] ) && 'tptn_daily' === $wp_query->query['orderby'] ) { $table_name = $wpdb->base_prefix . 'top_ten_daily'; $from_date = tptn_get_from_date(); $clauses['join'] .= "LEFT OUTER JOIN {$table_name} ON {$wpdb->posts}.ID={$table_name}.postnumber"; $clauses['where'] .= " AND {$table_name}.dp_date >= '$from_date' "; $clauses['groupby'] = "{$table_name}.postnumber"; $clauses['orderby'] = "SUM({$table_name}.cntaccess) "; $clauses['orderby'] .= ( 'ASC' === strtoupper( $wp_query->get( 'order' ) ) ) ? 'ASC' : 'DESC'; } return $clauses; } add_filter( 'posts_clauses', 'tptn_column_clauses', 10, 2 ); /** * Output CSS for width of new column. * * @since 1.2 */ function tptn_admin_css() { ?>