From 5f8be013b2d487f6907bc8c193d21495214da08c Mon Sep 17 00:00:00 2001 From: Oleksandr Zhyian Date: Tue, 22 Oct 2024 15:00:54 +0300 Subject: [PATCH] feat: add post views column to admin post table --- inc/class-statify-counter-column.php | 117 +++++++++++++++++++++++++++ inc/class-statify.php | 1 + statify.php | 1 + 3 files changed, 119 insertions(+) create mode 100644 inc/class-statify-counter-column.php diff --git a/inc/class-statify-counter-column.php b/inc/class-statify-counter-column.php new file mode 100644 index 0000000..e443cfd --- /dev/null +++ b/inc/class-statify-counter-column.php @@ -0,0 +1,117 @@ +prepare( + "SELECT COUNT(*) FROM `$wpdb->statify` WHERE `target` = %s", + $target + ); + + $result = $wpdb->get_var( $sql ); + + return (int) $result; + } +} diff --git a/inc/class-statify.php b/inc/class-statify.php index d940a4e..82b99e3 100755 --- a/inc/class-statify.php +++ b/inc/class-statify.php @@ -75,6 +75,7 @@ public static function init(): void { add_filter( 'plugin_row_meta', array( 'Statify_Backend', 'add_meta_link' ), 10, 2 ); add_filter( 'plugin_action_links_' . STATIFY_BASE, array( 'Statify_Backend', 'add_action_link' ) ); add_action( 'admin_init', array( 'Statify_Settings', 'register_settings' ) ); + add_action( 'admin_init', array( 'Statify_Counter_Column', 'init' ) ); add_action( 'admin_menu', array( 'Statify_Settings', 'add_admin_menu' ) ); add_action( 'update_option_statify', array( 'Statify_Settings', 'action_update_options' ), 10, 2 ); } else { // Frontend. diff --git a/statify.php b/statify.php index 1c4623a..64c1599 100644 --- a/statify.php +++ b/statify.php @@ -75,6 +75,7 @@ function statify_autoload( $class ) { 'Statify_Settings', 'Statify_Table', 'Statify_Cron', + 'Statify_Counter_Column', ); if ( in_array( $class, $plugin_classes, true ) ) {