nirjharlo /
complete-google-seo-scan
| 1 | <?php |
||||
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
||||
| 3 | |||||
| 4 | /** |
||||
| 5 | * Backend settings page class, can have settings fields or data table |
||||
| 6 | */ |
||||
| 7 | if ( ! class_exists( 'CGSS_SETTINGS' ) ) { |
||||
| 8 | |||||
| 9 | final class CGSS_SETTINGS { |
||||
| 10 | |||||
| 11 | public $capability; |
||||
| 12 | public $menuPage; |
||||
| 13 | public $subMenuPage; |
||||
| 14 | public $subMenuPageCpt; |
||||
| 15 | public $help; |
||||
| 16 | public $screen; |
||||
| 17 | |||||
| 18 | // Add basic actions for menu and settings |
||||
| 19 | public function __construct() { |
||||
| 20 | |||||
| 21 | $this->capability = 'manage_options'; |
||||
| 22 | $this->menuPage = array( |
||||
| 23 | 'name' => __( 'SEO Scan', 'cgss' ), |
||||
| 24 | 'heading' => __( 'SEO Scan', 'cgss' ), |
||||
| 25 | 'slug' => 'seo-scan' |
||||
| 26 | ); |
||||
| 27 | $this->subMenuPage = array( |
||||
| 28 | 'name' => __( 'Seo Scan Overview', 'cgss' ), |
||||
| 29 | 'heading' => __( 'Overview', 'cgss' ), |
||||
| 30 | 'slug' => 'seo-scan', |
||||
| 31 | 'parent_slug' => 'seo-scan', |
||||
| 32 | 'help' => false, |
||||
| 33 | 'screen' => true |
||||
| 34 | ); |
||||
| 35 | $this->subMenuPageCpt = $this->get_post_type_menus(); |
||||
| 36 | |||||
| 37 | $this->screen = ''; // true/false |
||||
| 38 | |||||
| 39 | add_action( 'admin_menu', array( $this, 'menu_page' ) ); |
||||
| 40 | add_action( 'admin_menu', array( $this, 'sub_menu_page' ) ); |
||||
| 41 | add_action( 'admin_menu', array( $this, 'cpt_sub_menu_page' ) ); |
||||
| 42 | add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 ); |
||||
| 43 | add_filter('screen_options_show_screen', array( $this, 'remove_screen_options')); |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | |||||
| 47 | public function remove_screen_options() { |
||||
| 48 | |||||
| 49 | if (isset($_GET['page']) && $_GET['page'] == 'seo-scan') { |
||||
| 50 | return false; |
||||
| 51 | } else { |
||||
| 52 | return true; |
||||
| 53 | } |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | // Get post type data to form menu variables |
||||
| 57 | public function get_post_type_menus() { |
||||
| 58 | |||||
| 59 | $menu_vars = array(); |
||||
| 60 | |||||
| 61 | $post_types = get_post_types( array( 'public' => true, ), 'names' ); |
||||
| 62 | unset( $post_types['attachment'] ); |
||||
| 63 | |||||
| 64 | foreach ( $post_types as $type ) { |
||||
| 65 | |||||
| 66 | $count_posts = wp_count_posts( $type ); |
||||
| 67 | if ( $count_posts->publish > 0 ) { |
||||
| 68 | |||||
| 69 | $type_name = ucwords( get_post_type_object( $type )->labels->singular_name ); |
||||
| 70 | $menu_vars[] = array( |
||||
| 71 | 'name' => $type_name . ' ' . __( 'Seo Scan', 'cgss' ), |
||||
| 72 | 'heading' => $type_name, |
||||
| 73 | 'slug' => 'seo-scan-' . $type, |
||||
| 74 | 'parent_slug' => 'seo-scan', |
||||
| 75 | 'help' => false, |
||||
| 76 | 'screen' => true |
||||
| 77 | ); |
||||
| 78 | } |
||||
| 79 | } |
||||
| 80 | |||||
| 81 | return $menu_vars; |
||||
| 82 | } |
||||
| 83 | |||||
| 84 | |||||
| 85 | // Add main menu page callback |
||||
| 86 | public function menu_page() { |
||||
| 87 | |||||
| 88 | if ($this->menuPage) { |
||||
| 89 | add_menu_page( |
||||
| 90 | $this->menuPage['name'], |
||||
| 91 | $this->menuPage['heading'], |
||||
| 92 | $this->capability, |
||||
| 93 | $this->menuPage['slug'], |
||||
| 94 | array( $this, 'overview_content_cb' ), |
||||
| 95 | 'dashicons-search' |
||||
| 96 | ); |
||||
| 97 | } |
||||
| 98 | } |
||||
| 99 | |||||
| 100 | |||||
| 101 | |||||
| 102 | //Add a Submenu page callback |
||||
| 103 | public function sub_menu_page() { |
||||
| 104 | |||||
| 105 | if ($this->subMenuPage) { |
||||
|
0 ignored issues
–
show
|
|||||
| 106 | $hook = add_submenu_page( |
||||
| 107 | $this->subMenuPage['parent_slug'], |
||||
| 108 | $this->subMenuPage['name'], |
||||
| 109 | $this->subMenuPage['heading'], |
||||
| 110 | $this->capability, |
||||
| 111 | $this->subMenuPage['slug'], |
||||
| 112 | array( $this, 'overview_content_cb' ) |
||||
| 113 | ); |
||||
| 114 | if ($this->subMenuPage['screen']) { |
||||
| 115 | add_action( 'load-' . $hook, array( $this, 'overview_screen_option' ) ); |
||||
| 116 | } |
||||
| 117 | } |
||||
| 118 | } |
||||
| 119 | |||||
| 120 | |||||
| 121 | |||||
| 122 | // Add Submenu page callback for cpts |
||||
| 123 | public function cpt_sub_menu_page() { |
||||
| 124 | |||||
| 125 | if ($this->subMenuPageCpt) { |
||||
| 126 | foreach ($this->subMenuPageCpt as $value) { |
||||
| 127 | $hook = add_submenu_page( |
||||
| 128 | $value['parent_slug'], |
||||
| 129 | $value['name'], |
||||
| 130 | $value['heading'], |
||||
| 131 | $this->capability, |
||||
| 132 | $value['slug'], |
||||
| 133 | array( $this, 'cpt_content_cb' ) |
||||
| 134 | ); |
||||
| 135 | if ($value['screen']) { |
||||
| 136 | add_action( 'load-' . $hook, array( $this, 'screen_option' ) ); |
||||
| 137 | } |
||||
| 138 | } |
||||
| 139 | } |
||||
| 140 | } |
||||
| 141 | |||||
| 142 | |||||
| 143 | |||||
| 144 | //Set screen option |
||||
| 145 | public function set_screen($status, $option, $value) { |
||||
| 146 | |||||
| 147 | if ( 'post_per_page' == $option ) return $value; // Related to PLUGIN_TABLE() |
||||
| 148 | //return $status; |
||||
| 149 | } |
||||
| 150 | |||||
| 151 | |||||
| 152 | |||||
| 153 | //Set screen option for Items table |
||||
| 154 | public function overview_screen_option() { |
||||
| 155 | |||||
| 156 | $this->overview = new CGSS_OVERVIEW_TABLE(); |
||||
| 157 | } |
||||
| 158 | |||||
| 159 | |||||
| 160 | |||||
| 161 | //Set screen option for Items table |
||||
| 162 | public function screen_option() { |
||||
| 163 | |||||
| 164 | $option = 'per_page'; |
||||
| 165 | $args = array( |
||||
| 166 | 'label' => __( 'Show per page', 'cgss' ), |
||||
| 167 | 'default' => 10, |
||||
| 168 | 'option' => 'post_per_page' // Related to CGSS_TABLE() |
||||
| 169 | ); |
||||
| 170 | add_screen_option( $option, $args ); |
||||
| 171 | $this->table = new CGSS_TABLE(); |
||||
| 172 | } |
||||
| 173 | |||||
| 174 | |||||
| 175 | |||||
| 176 | // Menu page callback |
||||
| 177 | public function overview_content_cb() { ?> |
||||
| 178 | |||||
| 179 | <div class="wrap"> |
||||
| 180 | <h1><?php echo get_admin_page_title(); ?> |
||||
| 181 | |
||||
| 182 | <a href="?page=seo-scan&fetch=true" class="button button-secondary"> |
||||
| 183 | <?php _e( 'Fetch Insight', 'cgss' ); ?> |
||||
|
0 ignored issues
–
show
The function
_e was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 184 | </a> |
||||
| 185 | </h1> |
||||
| 186 | <br class="clear"> |
||||
| 187 | <?php if (isset($_GET['fetch'])) : ?> |
||||
| 188 | <?php do_action( 'cgss_fetch_insight' ); ?> |
||||
| 189 | <?php endif; ?> |
||||
| 190 | <?php |
||||
| 191 | // Source: /lib/overview-table.php |
||||
| 192 | $this->overview = new CGSS_OVERVIEW_TABLE(); |
||||
| 193 | $this->overview->prepare_items(); |
||||
| 194 | $this->overview->display(); |
||||
| 195 | ?> |
||||
| 196 | <br class="clear"> |
||||
| 197 | </div> |
||||
| 198 | <?php |
||||
| 199 | } |
||||
| 200 | |||||
| 201 | |||||
| 202 | |||||
| 203 | // Add submenu page callback |
||||
| 204 | public function cpt_content_cb() { ?> |
||||
| 205 | |||||
| 206 | <div class="wrap"> |
||||
| 207 | <h1><?php echo get_admin_page_title(); ?></h1> |
||||
| 208 | <br class="clear"> |
||||
| 209 | <?php if (isset($_GET['scan'])) : ?> |
||||
| 210 | <?php do_action( 'cgss_scan' ); ?> |
||||
| 211 | <?php elseif (isset($_GET['compete'])) : ?> |
||||
| 212 | <?php do_action( 'cgss_compete' ); ?> |
||||
| 213 | <?php else : ?> |
||||
| 214 | <form method="post" action=""> |
||||
| 215 | <?php |
||||
| 216 | // Source: /lib/table.php |
||||
| 217 | $this->table = new CGSS_TABLE(); |
||||
| 218 | $this->table->prepare_items(); |
||||
| 219 | $this->table->display(); |
||||
| 220 | ?> |
||||
| 221 | </form> |
||||
| 222 | <?php endif; ?> |
||||
| 223 | <br class="clear"> |
||||
| 224 | </div> |
||||
| 225 | <?php |
||||
| 226 | } |
||||
| 227 | } |
||||
| 228 | } ?> |
||||
| 229 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.