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
|
|
|
|
19
|
|
|
|
20
|
|
|
// Add basic actions for menu and settings |
21
|
|
|
public function __construct() { |
22
|
|
|
|
23
|
|
|
$this->capability = 'manage_options'; |
24
|
|
|
$this->menuPage = array( |
25
|
|
|
'name' => __( 'SEO Scan', 'cgss' ), |
|
|
|
|
26
|
|
|
'heading' => __( 'SEO Scan', 'cgss' ), |
27
|
|
|
'slug' => 'seo-scan' |
28
|
|
|
); |
29
|
|
|
$this->subMenuPage = array( |
30
|
|
|
'name' => __( 'Seo Scan Overview', 'cgss' ), |
31
|
|
|
'heading' => __( 'Overview', 'cgss' ), |
32
|
|
|
'slug' => 'seo-scan', |
33
|
|
|
'parent_slug' => 'seo-scan', |
34
|
|
|
'help' => false, |
35
|
|
|
'screen' => true |
36
|
|
|
); |
37
|
|
|
$this->subMenuPageCpt = $this->get_post_type_menus(); |
38
|
|
|
|
39
|
|
|
$this->screen = ''; // true/false |
40
|
|
|
|
41
|
|
|
add_action( 'admin_menu', array( $this, 'menu_page' ) ); |
|
|
|
|
42
|
|
|
add_action( 'admin_menu', array( $this, 'sub_menu_page' ) ); |
43
|
|
|
add_action( 'admin_menu', array( $this, 'cpt_sub_menu_page' ) ); |
44
|
|
|
add_filter( 'set-screen-option', array( $this, 'set_screen' ), 10, 3 ); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
// Get post type data to form menu variables |
50
|
|
|
public function get_post_type_menus() { |
51
|
|
|
|
52
|
|
|
$menu_vars = array(); |
53
|
|
|
|
54
|
|
|
$post_types = get_post_types( array( 'public' => true, ), 'names' ); |
|
|
|
|
55
|
|
|
unset( $post_types['attachment'] ); |
56
|
|
|
|
57
|
|
|
foreach ( $post_types as $type ) { |
58
|
|
|
|
59
|
|
|
$count_posts = wp_count_posts( $type ); |
|
|
|
|
60
|
|
|
if ( $count_posts->publish > 0 ) { |
61
|
|
|
|
62
|
|
|
$type_name = ucwords( get_post_type_object( $type )->labels->singular_name ); |
|
|
|
|
63
|
|
|
$menu_vars[] = array( |
64
|
|
|
'name' => $type_name . ' ' . __( 'Seo Scan', 'cgss' ), |
|
|
|
|
65
|
|
|
'heading' => $type_name, |
66
|
|
|
'slug' => 'seo-scan-' . $type, |
67
|
|
|
'parent_slug' => 'seo-scan', |
68
|
|
|
'help' => false, |
69
|
|
|
'screen' => true |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $menu_vars; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
// Add main menu page callback |
79
|
|
|
public function menu_page() { |
80
|
|
|
|
81
|
|
|
if ($this->menuPage) { |
|
|
|
|
82
|
|
|
add_menu_page( |
|
|
|
|
83
|
|
|
$this->menuPage['name'], |
84
|
|
|
$this->menuPage['heading'], |
85
|
|
|
$this->capability, |
86
|
|
|
$this->menuPage['slug'], |
87
|
|
|
array( $this, 'overview_content_cb' ), |
88
|
|
|
'dashicons-search' |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
|
95
|
|
|
//Add a Submenu page callback |
96
|
|
|
public function sub_menu_page() { |
97
|
|
|
|
98
|
|
|
if ($this->subMenuPage) { |
|
|
|
|
99
|
|
|
$hook = add_submenu_page( |
|
|
|
|
100
|
|
|
$this->subMenuPage['parent_slug'], |
101
|
|
|
$this->subMenuPage['name'], |
102
|
|
|
$this->subMenuPage['heading'], |
103
|
|
|
$this->capability, |
104
|
|
|
$this->subMenuPage['slug'], |
105
|
|
|
array( $this, 'overview_content_cb' ) |
106
|
|
|
); |
107
|
|
|
if ($this->subMenuPage['screen']) { |
108
|
|
|
add_action( 'load-' . $hook, array( $this, 'overview_screen_option' ) ); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
|
115
|
|
|
// Add Submenu page callback for cpts |
116
|
|
|
public function cpt_sub_menu_page() { |
117
|
|
|
|
118
|
|
|
if ($this->subMenuPageCpt) { |
119
|
|
|
foreach ($this->subMenuPageCpt as $value) { |
120
|
|
|
$hook = add_submenu_page( |
|
|
|
|
121
|
|
|
$value['parent_slug'], |
122
|
|
|
$value['name'], |
123
|
|
|
$value['heading'], |
124
|
|
|
$this->capability, |
125
|
|
|
$value['slug'], |
126
|
|
|
array( $this, 'cpt_content_cb' ) |
127
|
|
|
); |
128
|
|
|
if ($value['screen']) { |
129
|
|
|
add_action( 'load-' . $hook, array( $this, 'screen_option' ) ); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
|
137
|
|
|
//Set screen option |
138
|
|
|
public function set_screen($status, $option, $value) { |
139
|
|
|
|
140
|
|
|
if ( 'post_per_page' == $option ) return $value; // Related to PLUGIN_TABLE() |
141
|
|
|
//return $status; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
|
145
|
|
|
|
146
|
|
|
//Set screen option for Items table |
147
|
|
|
public function overview_screen_option() { |
148
|
|
|
|
149
|
|
|
$this->overview = new CGSS_OVERVIEW_TABLE(); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
|
154
|
|
|
//Set screen option for Items table |
155
|
|
|
public function screen_option() { |
156
|
|
|
|
157
|
|
|
$option = 'per_page'; |
158
|
|
|
$args = array( |
159
|
|
|
'label' => __( 'Show per page', 'cgss' ), |
|
|
|
|
160
|
|
|
'default' => 10, |
161
|
|
|
'option' => 'post_per_page' // Related to CGSS_TABLE() |
162
|
|
|
); |
163
|
|
|
add_screen_option( $option, $args ); |
|
|
|
|
164
|
|
|
$this->table = new CGSS_TABLE(); |
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
|
169
|
|
|
// Menu page callback |
170
|
|
|
public function overview_content_cb() { ?> |
171
|
|
|
|
172
|
|
|
<div class="wrap"> |
173
|
|
|
<h1><?php echo get_admin_page_title(); ?> |
|
|
|
|
174
|
|
|
<a href="?page=seo-scan&fetch=true" class="button button-secondary"><?php _e( 'Fetch Insight', 'cgss' ); ?></a> |
|
|
|
|
175
|
|
|
</h1> |
176
|
|
|
<br class="clear"> |
177
|
|
|
<?php if (isset($_GET['fetch'])) : ?> |
178
|
|
|
<?php do_action( 'cgss_fetch_insight' ); ?> |
|
|
|
|
179
|
|
|
<?php endif; ?> |
180
|
|
|
<?php |
181
|
|
|
// Source: /lib/overview-table.php |
182
|
|
|
$this->overview = new CGSS_OVERVIEW_TABLE(); |
|
|
|
|
183
|
|
|
$this->overview->prepare_items(); |
184
|
|
|
$this->overview->display(); |
185
|
|
|
?> |
186
|
|
|
<br class="clear"> |
187
|
|
|
</div> |
188
|
|
|
<?php |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
|
193
|
|
|
// Add submenu page callback |
194
|
|
|
public function cpt_content_cb() { ?> |
195
|
|
|
|
196
|
|
|
<div class="wrap"> |
197
|
|
|
<h1><?php echo get_admin_page_title(); ?></h1> |
|
|
|
|
198
|
|
|
<br class="clear"> |
199
|
|
|
<?php if (isset($_GET['scan'])) : ?> |
200
|
|
|
<?php do_action( 'cgss_scan' ); ?> |
|
|
|
|
201
|
|
|
<?php elseif (isset($_GET['compete'])) : ?> |
202
|
|
|
<?php do_action( 'cgss_compete' ); ?> |
203
|
|
|
<?php else : ?> |
204
|
|
|
<form method="post" action=""> |
205
|
|
|
<?php |
206
|
|
|
// Source: /lib/table.php |
207
|
|
|
$this->table = new CGSS_TABLE(); |
|
|
|
|
208
|
|
|
$this->table->prepare_items(); |
209
|
|
|
$this->table->display(); |
210
|
|
|
?> |
211
|
|
|
</form> |
212
|
|
|
<?php endif; ?> |
213
|
|
|
<br class="clear"> |
214
|
|
|
</div> |
215
|
|
|
<?php |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
} ?> |