PluginProbe
WPGlobus / trunk
WPGlobus vtrunk
3.0.5 3.0.4 trunk 2.1.15 2.10.10 2.12.2 2.2.35 2.3.12 2.4.17 2.5.23 2.6.8 2.7.14 2.8.11 3.0.0 3.0.1 3.0.2 3.0.3
wpglobus / includes / admin / debug / class-wpglobus-admin-debug.php

class-wpglobus-admin-debug.php in WPGlobus trunk, at includes/admin/debug/class-wpglobus-admin-debug.php

405 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPGlobus/Admin/Debug.
4 *
5 * @package WPGlobus\Admin
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly
10 }
11
12 if ( ! class_exists( 'WPGlobus_Admin_Debug' ) ) :
13
14 /**
15 * Class WPGlobus_Admin_Debug.
16 *
17 * @since 1.8.1
18 */
19 class WPGlobus_Admin_Debug {
20
21 /**
22 * Instance.
23 *
24 * @var WPGlobus_Admin_Debug
25 */
26 protected static $instance;
27
28 /**
29 * Debug mode.
30 *
31 * @since 2.2.35
32 */
33 protected static $mode = 'godmode';
34
35 /**
36 * Key.
37 *
38 * @since 2.2.35
39 */
40 protected static $key = '';
41
42 /**
43 * Get instance.
44 */
45 public static function get_instance() {
46 if ( null === self::$instance ) {
47 self::$instance = new self();
48 }
49
50 return self::$instance;
51 }
52
53 /**
54 * Constructor.
55 */
56 public function __construct() {
57
58 $get_debug = WPGlobus_WP::get_http_get_parameter( 'wpglobus-debug' );
59 if ( 'meta' === $get_debug ) {
60 self::$mode = 'meta';
61 } elseif ( 'wpglobus_options' === $get_debug || 'wpglobus-options' === $get_debug ) {
62 self::$mode = 'wpglobus_options';
63 } elseif ( 'yoast' === $get_debug ) {
64 self::$mode = 'yoast';
65 }
66
67 if ( 'godmode' !== self::$mode ) {
68 $get_key = WPGlobus_WP::get_http_get_parameter( 'key' );
69 if ( $get_key ) {
70 self::$key = $get_key;
71 }
72 }
73
74 /**
75 * Action.
76 *
77 * @scope admin
78 * @since 1.8.1
79 */
80 add_action( 'admin_print_scripts', array( $this, 'on__admin_scripts' ), 99 );
81
82 /**
83 * Action.
84 *
85 * @scope admin
86 * @since 1.8.1
87 */
88 add_action( 'admin_print_styles', array( $this, 'on__admin_styles' ), 99 );
89
90 /**
91 * Action.
92 *
93 * @scope admin
94 * @since 1.8.1
95 */
96 add_action( 'admin_footer', array( $this, 'on__admin_footer' ), 9999 );
97 }
98
99 /**
100 * Method is_enabled_section.
101 *
102 * @since 2.2.35
103 *
104 * @param string $section
105 *
106 * @return bool
107 */
108 public function is_enabled_section( $section ) {
109 if ( 'godmode' === self::$mode ) {
110 return true;
111 }
112 if ( $section === self::$mode ) {
113 return true;
114 }
115
116 return false;
117 }
118
119 /**
120 * Enqueue admin styles.
121 *
122 * @scope admin
123 * @since 1.8.1
124 */
125 public function on__admin_styles() {
126
127 wp_register_style(
128 'wpglobus-admin-debug',
129 WPGlobus::plugin_dir_url() . 'includes/css/wpglobus-admin-debug.css',
130 array(),
131 WPGLOBUS_VERSION
132 );
133 wp_enqueue_style( 'wpglobus-admin-debug' );
134 }
135
136 /**
137 * Enqueue admin scripts.
138 *
139 * @scope admin
140 * @since 1.8.1
141 */
142 public function on__admin_scripts() {
143
144 wp_register_script(
145 'wpglobus-admin-debug',
146 WPGlobus::plugin_dir_url() . 'includes/js/wpglobus-admin-debug' . WPGlobus::SCRIPT_SUFFIX() . '.js',
147 array( 'jquery' ),
148 WPGLOBUS_VERSION,
149 true
150 );
151 wp_enqueue_script( 'wpglobus-admin-debug' );
152 wp_localize_script(
153 'wpglobus-admin-debug',
154 'WPGlobusAdminDebug',
155 array(
156 'version' => WPGLOBUS_VERSION,
157 'data' => '',
158 )
159 );
160 }
161
162 /**
163 * Output table.
164 *
165 * @scope admin
166 * @since 1.8.1
167 */
168 public function on__admin_footer() {
169
170 static $fn_dump = 'print_r';
171
172 global $wpdb, $post, $pagenow;
173
174 $meta_query_caption = '';
175
176 if ( 'post.php' === $pagenow ) {
177 if ( is_object( $post ) ) {
178 // post.php page.
179 if ( empty( $post->ID ) || 0 === (int) $post->ID ) {
180 return;
181 }
182
183 $_id = $post->ID;
184 $meta_query_caption = "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = $_id";
185 /**
186 * Get metadata.
187 *
188 * @var array $metas
189 */
190 $metas = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
191 }
192 } elseif ( 'term.php' === $pagenow ) {
193
194 $get_tag_ID = WPGlobus_WP::get_http_get_parameter( 'tag_ID' );
195 if ( ! $get_tag_ID ) {
196 return;
197 }
198 $_id = $get_tag_ID;
199
200 $meta_query_caption = "SELECT meta_key, meta_value FROM $wpdb->termmeta WHERE term_id = $_id";
201
202 /**
203 * Get metadata.
204 *
205 * @var array $metas
206 */
207 $metas = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM $wpdb->termmeta WHERE term_id = %d", $_id ), ARRAY_A ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
208 } else {
209 return;
210 }
211 ?>
212 <div id="wpglobus-admin-debug-box" class="" style="display:none;">
213 <h4>WPGlobus debug box</h4>
214 <?php
215 if ( $this->is_enabled_section( 'yoast' ) ) :
216 /**
217 * Output yoast options.
218 */
219 if ( empty( self::$key ) ) {
220 $query_caption = "SELECT * FROM $wpdb->options WHERE option_name LIKE '%wpseo%' OR option_name LIKE '%yoast%'";
221
222 $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s", '%wpseo%', '%yoast%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
223 } else {
224 $_key = self::$key;
225 $query_caption = "SELECT * FROM $wpdb->options WHERE option_name = $_key";
226
227 $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->options WHERE option_name = %s", self::$key ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
228 }
229 ?>
230 <table class="table1">
231 <caption><strong><?php echo '"' . esc_html( $query_caption ) . '"'; ?></strong></caption>
232 <thead>
233 <tr>
234 <th><strong>â„–</strong></th>
235 <th><strong>option name</strong></th>
236 <th><strong>value</strong></th>
237 </tr>
238 </thead>
239 <tbody>
240 <?php
241 $order = 1;
242
243 /**
244 * Unused $key
245 *
246 * @noinspection PhpUnusedLocalVariableInspection
247 */
248 foreach ( $results as $key => $value ) {
249 $code = false;
250 /**
251 * UNUSED
252 * //if ( is_array( $meta ) ) {
253 * //$results[$key]['meta_key'] = htmlspecialchars( $meta['meta_value'] );
254 * //}
255 */
256 0 && wp_verify_nonce( '' );
257 $args = $_GET;
258 if ( empty( self::$key ) ) {
259 $args['wpglobus-debug'] = 'yoast';
260 $args = array_merge( $args, array( 'key' => $value->option_name ) );
261 $_url = admin_url( add_query_arg( $args, $pagenow ) );
262 } else {
263 $_url = admin_url( add_query_arg( $args, $pagenow ) );
264 }
265 ?>
266 <tr>
267 <td><?php echo esc_html( $order ); ?></td>
268 <td>
269 <a href="<?php echo esc_url( $_url ); ?>"><?php echo esc_html( $value->option_name ); ?></a>
270 </td>
271 <?php if ( $code ) { ?>
272 <td>
273 <pre><?php echo esc_html( $fn_dump( $value->option_value, true ) ); ?></pre>
274 </td>
275 <?php } else { ?>
276 <td><?php echo esc_html( $fn_dump( $value->option_value, true ) ); ?></td>
277 <?php } ?>
278 </tr>
279 <?php ++$order; ?>
280 <?php } ?>
281 </tbody>
282 </table>
283 <?php
284 endif;
285
286 if ( $this->is_enabled_section( 'meta' ) ) :
287 /**
288 * Output metadata.
289 */
290 ?>
291 <table class="table2">
292 <caption><strong><?php echo '"' . esc_html( $meta_query_caption ) . '"'; ?></strong></caption>
293 <thead>
294 <tr>
295 <th><strong>â„–</strong></th>
296 <th><strong>meta</strong></th>
297 <th><strong>value</strong></th>
298 </tr>
299 </thead>
300 <tbody>
301 <?php if ( empty( $metas ) ) { ?>
302 <tr>
303 <td></td>
304 <td>No data</td>
305 <td>No data</td>
306 </tr>
307 <?php
308 } else {
309 $order = 1;
310 foreach ( $metas as $key => $meta ) {
311 $code = false;
312 if ( is_array( $meta ) ) {
313 $_meta_key = 'meta_key';
314 $metas[ $key ][ $_meta_key ] = htmlspecialchars( $meta['meta_value'] );
315 }
316 ?>
317 <tr>
318 <td><?php echo esc_html( $order ); ?></td>
319 <td><?php echo esc_html( $fn_dump( $meta['meta_key'], true ) ); ?></td>
320 <?php if ( $code ) { ?>
321 <td>
322 <pre><?php echo esc_html( $fn_dump( $meta['meta_value'], true ) ); ?></pre>
323 </td>
324 <?php } else { ?>
325 <td><?php echo esc_html( $fn_dump( $meta['meta_value'], true ) ); ?></td>
326 <?php } ?>
327 </tr>
328 <?php
329 ++$order;
330 }
331 }
332 ?>
333 </tbody>
334 </table>
335 <?php
336 endif;
337
338 if ( $this->is_enabled_section( 'wpglobus_options' ) ) :
339 /**
340 * Output WPGlobus options.
341 */
342 $results = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM $wpdb->options WHERE option_name LIKE %s', '%wpglobus%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
343 ?>
344 <table class="table3">
345 <caption>
346 <strong><?php echo '"SELECT * FROM $wpdb->options WHERE option_name LIKE \'%wpglobus%\'"'; ?></strong>
347 </caption>
348 <caption><?php echo 'Option count: ' . count( $results ); ?></caption>
349 <thead>
350 <tr>
351 <th><strong>Option ID</strong></th>
352 <th><strong>Option Name</strong></th>
353 <th><strong>Option Value</strong></th>
354 </tr>
355 </thead>
356 <tbody>
357 <?php
358
359 $order = 1;
360
361 /**
362 * Unused $option_key
363 *
364 * @noinspection PhpUnusedLocalVariableInspection
365 */
366 foreach ( $results as $option_key => $option ) {
367 $code = false;
368 if ( is_array( $option->option_value ) ) {
369 foreach ( $option->option_value as $key => $value ) {
370 $option->option_value[ $key ] = htmlspecialchars( $value );
371 }
372 } elseif ( is_string( $option->option_value ) ) {
373 $option->option_value = htmlspecialchars( $option->option_value );
374 }
375 ?>
376 <tr>
377 <td><?php echo esc_html( $option->option_id ); ?></td>
378 <td><?php echo esc_html( $fn_dump( $option->option_name, true ) ); ?></td>
379 <?php if ( $code ) { ?>
380 <td>
381 <pre><?php echo esc_html( $fn_dump( $option->option_value, true ) ); ?></pre>
382 </td>
383 <?php } else { ?>
384 <td><?php echo esc_html( $fn_dump( $option->option_value, true ) ); ?></td>
385 <?php } ?>
386 </tr>
387 <?php
388 /**
389 * Result of $order ++ is unused.
390 *
391 * @noinspection PhpUnusedLocalVariableInspection
392 */
393 ++$order;
394 ?>
395 <?php } ?>
396 </tbody>
397 </table>
398 <?php endif; ?>
399 </div>
400 <?php
401 }
402 }
403
404 endif;
405