nirjharlo /
complete-google-seo-scan
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Implimentation of WordPress inbuilt functions for creating an extension of a default table class. |
||
| 4 | * |
||
| 5 | * $myPluginNameTable = new CGSS_OVERVIEW_TABLE(); |
||
| 6 | * $myPluginNameTable->prepare_items(); |
||
| 7 | * $myPluginNameTable->display(); |
||
| 8 | * |
||
| 9 | */ |
||
| 10 | if ( ! class_exists( 'CGSS_OVERVIEW_TABLE' ) ) { |
||
| 11 | |||
| 12 | final class CGSS_OVERVIEW_TABLE extends WP_List_Table { |
||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | public function __construct() { |
||
| 17 | |||
| 18 | parent::__construct( [ |
||
| 19 | 'singular' => __( 'Insight', 'textdomain' ), |
||
| 20 | 'plural' => __( 'Inssight', 'textdomain' ), |
||
| 21 | 'ajax' => false, |
||
| 22 | ] ); |
||
| 23 | } |
||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | //fetch the data using custom named method function |
||
| 28 | public static function get_insight() { |
||
| 29 | |||
| 30 | global $wpdb; |
||
| 31 | |||
| 32 | //Build the db query base |
||
| 33 | $sql = "SELECT * FROM {$wpdb->prefix}cgss_insight"; |
||
| 34 | |||
| 35 | //get the data from database |
||
| 36 | $result = $wpdb->get_results( $sql, 'ARRAY_A' ); |
||
| 37 | |||
| 38 | return $result; |
||
| 39 | } |
||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | //If there is no data to show |
||
| 44 | public function no_items() { |
||
| 45 | |||
| 46 | _e( 'Database is empty. Please reactivate the plugin.', 'cgss' ); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 47 | } |
||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | //How many rows are present there |
||
| 52 | public static function record_count() { |
||
| 53 | |||
| 54 | global $wpdb; |
||
| 55 | |||
| 56 | //Build the db query base |
||
| 57 | $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}cgss_insight"; |
||
| 58 | |||
| 59 | return $wpdb->get_var( $sql ); |
||
| 60 | } |
||
| 61 | |||
| 62 | |||
| 63 | |||
| 64 | //Display columns content |
||
| 65 | public function column_name( $item ) { |
||
| 66 | |||
| 67 | $title = sprintf( '<strong>%s</strong>', $item['item'] ); |
||
| 68 | |||
| 69 | //Change the page instruction where you want to show it |
||
| 70 | $actions = array(); |
||
| 71 | return $title . $this->row_actions( $actions ); |
||
| 72 | } |
||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | //set coulmns name |
||
| 77 | public function column_default( $item, $column_name ) { |
||
| 78 | |||
| 79 | switch ( $column_name ) { |
||
| 80 | |||
| 81 | case 'item': |
||
| 82 | //This is the first column |
||
| 83 | return $this->column_name( $item ); |
||
| 84 | case 'remark': |
||
| 85 | return $item[ $column_name ]; |
||
| 86 | |||
| 87 | default: |
||
| 88 | |||
| 89 | //Show the whole array for troubleshooting purposes |
||
| 90 | return print_r( $item, true ); |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | //Columns callback |
||
| 97 | public function get_columns() { |
||
| 98 | |||
| 99 | $columns = array( |
||
| 100 | 'item' => __( 'Item', 'textdomain' ), |
||
| 101 | 'remark' => __( 'Remark', 'textdomain' ), |
||
| 102 | ); |
||
| 103 | return $columns; |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | //Prapare the display variables for screen options |
||
| 109 | public function prepare_items() { |
||
| 110 | |||
| 111 | $this->_column_headers = $this->get_column_info(); |
||
| 112 | $this->items = self::get_insight(); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } ?> |
||
| 116 |