PluginProbe
My WP Customize Admin/Frontend / trunk
My WP Customize Admin/Frontend vtrunk
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / developer / modules / mywp.developer.module.dev.frontend.php

mywp.developer.module.dev.frontend.php in My WP Customize Admin/Frontend trunk, at developer/modules/mywp.developer.module.dev.frontend.php

646 lines 15.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( ! class_exists( 'MywpDeveloperAbstractModule' ) ) {
8 return false;
9 }
10
11 if ( ! class_exists( 'MywpDeveloperModuleDevFrontend' ) ) :
12
13 final class MywpDeveloperModuleDevFrontend extends MywpDeveloperAbstractModule {
14
15 static protected $id = 'dev_frontend';
16
17 static protected $priority = 20;
18
19 static protected $find_templates = array();
20
21 static protected $header_templates = array();
22
23 static protected $sidebar_templates = array();
24
25 static protected $footer_templates = array();
26
27 protected static function after_init() {
28
29 $template_types = array(
30 'embed',
31 '404',
32 'search',
33 'frontpage',
34 'home',
35 'taxonomy',
36 'attachment',
37 'single',
38 'page',
39 'singular',
40 'category',
41 'tag',
42 'author',
43 'date',
44 'archive',
45 'index',
46 );
47
48 foreach( $template_types as $template_type ) {
49
50 add_filter( "{$template_type}_template_hierarchy" , array( __CLASS__ , 'regist_template_hierarchy' ) , 100 );
51
52 }
53
54 add_action( 'get_header' , array( __CLASS__ , 'regist_header_templates' ) , 100 );
55
56 add_action( 'get_sidebar' , array( __CLASS__ , 'regist_sidebar_templates' ) , 100 );
57
58 add_action( 'get_footer' , array( __CLASS__ , 'regist_footer_templates' ) , 100 );
59
60 }
61
62 public static function regist_template_hierarchy( $templates ) {
63
64 $find_templates = $templates;
65
66 if( is_array( $find_templates ) ) {
67
68 foreach( $find_templates as $find_template ) {
69
70 self::$find_templates[] = $find_template;
71
72 }
73
74 }
75
76 return $templates;
77
78 }
79
80 public static function regist_header_templates( $name ) {
81
82 $name = (string) $name;
83
84 if ( '' !== $name ) {
85
86 self::$header_templates[] = "header-{$name}.php";
87
88 }
89
90 self::$header_templates[] = 'header.php';
91
92 }
93
94 public static function regist_sidebar_templates( $name ) {
95
96 $name = (string) $name;
97
98 if ( '' !== $name ) {
99
100 self::$sidebar_templates[] = "sidebar-{$name}.php";
101
102 }
103
104 self::$sidebar_templates[] = 'sidebar.php';
105
106 }
107
108 public static function regist_footer_templates( $name ) {
109
110 $name = (string) $name;
111
112 if ( '' !== $name ) {
113
114 self::$footer_templates[] = "footer-{$name}.php";
115
116 }
117
118 self::$footer_templates[] = 'footer.php';
119
120 }
121
122 public static function mywp_debug_renders( $debug_renders ) {
123
124 if( is_admin() ) {
125
126 return $debug_renders;
127
128 }
129
130 $debug_renders[ self::$id ] = array(
131 'debug_type' => 'dev',
132 'title' => __( 'Current Frontend Information' , 'my-wp' ),
133 );
134
135 return $debug_renders;
136
137 }
138
139 protected static function get_debug_lists() {
140
141 global $wpdb;
142 global $post;
143 global $template;
144
145 $debug_lists = array(
146 'is_front_page()' => is_front_page(),
147 'is_home()' => is_home(),
148 'is_single()' => is_single(),
149 'is_page()' => is_page(),
150 'is_singular()' => is_singular(),
151 'is_category()' => is_category(),
152 'is_tag()' => is_tag(),
153 'is_tax()' => is_tax(),
154 'is_author()' => is_author(),
155 'is_date()' => is_date(),
156 'is_archive()' => is_archive(),
157 'is_search()' => is_search(),
158 'is_404()' => is_404(),
159 'is_attachment()' => is_attachment(),
160 'is_paged()' => is_paged(),
161 'is_post_type_archive()' => is_post_type_archive(),
162 'is_page_template()' => is_page_template(),
163 'is_embed' => is_embed(),
164 'is_main_query()' => is_main_query(),
165 'is_preview()' => is_preview(),
166 );
167
168 $current_template = false;
169
170 $all_templates = array();
171
172 if( ! empty( self::$find_templates ) ) {
173
174 foreach( self::$find_templates as $key => $find_template ) {
175
176 if( empty( $find_template ) ) {
177
178 continue;
179
180 }
181
182 $current_theme_template = MywpApi::get_theme_path() . '/' . $find_template;
183 $parent_theme_template = MywpApi::get_theme_path( true ) . '/' . $find_template;
184 $wp_compat_template = ABSPATH . WPINC . '/theme-compat/' . $find_template;
185
186 $all_templates[ $current_theme_template ] = array( 'found' => 0 );
187
188 if( file_exists( $current_theme_template ) ) {
189
190 $all_templates[ $current_theme_template ]['found'] = 1;
191
192 if( empty( $current_template ) ) {
193
194 $current_template = $current_theme_template;
195
196 }
197
198 }
199
200 if( is_child_theme() ) {
201
202 $all_templates[ $parent_theme_template ] = array( 'found' => 0 );
203
204 if( file_exists( $parent_theme_template ) ) {
205
206 $all_templates[ $parent_theme_template ]['found'] = 1;
207
208 if( empty( $current_template ) ) {
209
210 $current_template = $parent_theme_template;
211
212 }
213
214 }
215
216 }
217
218 $all_templates[ $wp_compat_template ] = array( 'found' => 0 );
219
220 if( file_exists( $wp_compat_template ) ) {
221
222 $all_templates[ $wp_compat_template ]['found'] = 1;
223
224 if( empty( $current_template ) ) {
225
226 $current_template = $wp_compat_template;
227
228 }
229
230 }
231
232 }
233
234 }
235
236 $file_name = false;
237
238 if( ! empty( $template ) ) {
239
240 $file_name = basename( $template );
241
242 }
243
244 $debug_lists['current_template'] = sprintf( '<strong>%s</strong> (%s)' , $file_name , $current_template );
245
246 $debug_lists['find_locate_templates'] = array();
247
248 foreach( $all_templates as $template_file => $template_vals ) {
249
250 $debug_lists['find_locate_templates'][ $template_file ] = $template_vals['found'];
251
252 }
253
254 $current_header_template = false;
255
256 $all_header_templates = array();
257
258 if( ! empty( self::$header_templates ) ) {
259
260 foreach( self::$header_templates as $key => $find_header_template ) {
261
262 if( empty( $find_header_template ) ) {
263
264 continue;
265
266 }
267
268 $current_theme_header_template = MywpApi::get_theme_path() . '/' . $find_header_template;
269 $parent_theme_header_template = MywpApi::get_theme_path( true ) . '/' . $find_header_template;
270 $wp_compat_header_template = ABSPATH . WPINC . '/theme-compat/' . $find_header_template;
271
272 $all_header_templates[ $current_theme_header_template ] = array( 'found' => 0 );
273
274 if( file_exists( $current_theme_header_template ) ) {
275
276 $all_header_templates[ $current_theme_header_template ]['found'] = 1;
277
278 if( empty( $current_header_template ) ) {
279
280 $current_header_template = $current_theme_header_template;
281
282 }
283
284 }
285
286 if( is_child_theme() ) {
287
288 $all_header_templates[ $parent_theme_header_template ] = array( 'found' => 0 );
289
290 if( file_exists( $parent_theme_header_template ) ) {
291
292 $all_header_templates[ $parent_theme_header_template ]['found'] = 1;
293
294 if( empty( $current_header_template ) ) {
295
296 $current_header_template = $parent_theme_header_template;
297
298 }
299
300 }
301
302 }
303
304 $all_header_templates[ $wp_compat_header_template ] = array( 'found' => 0 );
305
306 if( file_exists( $wp_compat_header_template ) ) {
307
308 $all_header_templates[ $wp_compat_header_template ]['found'] = 1;
309
310 if( empty( $current_header_template ) ) {
311
312 $current_header_template = $wp_compat_header_template;
313
314 }
315
316 }
317
318 }
319
320 }
321
322 $debug_lists['current_header_template'] = sprintf( '<strong>%s</strong> (%s)' , basename( $current_header_template ) , $current_header_template );
323
324 $debug_lists['find_locate_header_templates'] = array();
325
326 foreach( $all_header_templates as $template_file => $template_vals ) {
327
328 $debug_lists['find_locate_header_templates'][ $template_file ] = $template_vals['found'];
329
330 }
331
332 $current_sidebar_template = false;
333
334 $all_sidebar_templates = array();
335
336 if( ! empty( self::$sidebar_templates ) ) {
337
338 foreach( self::$sidebar_templates as $key => $find_sidebar_template ) {
339
340 if( empty( $find_sidebar_template ) ) {
341
342 continue;
343
344 }
345
346 $current_theme_sidebar_template = MywpApi::get_theme_path() . '/' . $find_sidebar_template;
347 $parent_theme_sidebar_template = MywpApi::get_theme_path( true ) . '/' . $find_sidebar_template;
348 $wp_compat_sidebar_template = ABSPATH . WPINC . '/theme-compat/' . $find_sidebar_template;
349
350 $all_sidebar_templates[ $current_theme_sidebar_template ] = array( 'found' => 0 );
351
352 if( file_exists( $current_theme_sidebar_template ) ) {
353
354 $all_sidebar_templates[ $current_theme_sidebar_template ]['found'] = 1;
355
356 if( empty( $current_sidebar_template ) ) {
357
358 $current_sidebar_template = $current_theme_sidebar_template;
359
360 }
361
362 }
363
364 if( is_child_theme() ) {
365
366 $all_sidebar_templates[ $parent_theme_sidebar_template ] = array( 'found' => 0 );
367
368 if( file_exists( $parent_theme_sidebar_template ) ) {
369
370 $all_sidebar_templates[ $parent_theme_sidebar_template ]['found'] = 1;
371
372 if( empty( $current_sidebar_template ) ) {
373
374 $current_sidebar_template = $parent_theme_sidebar_template;
375
376 }
377
378 }
379
380 }
381
382 $all_sidebar_templates[ $wp_compat_sidebar_template ] = array( 'found' => 0 );
383
384 if( file_exists( $wp_compat_sidebar_template ) ) {
385
386 $all_sidebar_templates[ $wp_compat_sidebar_template ]['found'] = 1;
387
388 if( empty( $current_sidebar_template ) ) {
389
390 $current_sidebar_template = $wp_compat_sidebar_template;
391
392 }
393
394 }
395
396 }
397
398 }
399
400 $debug_lists['current_sidebar_template'] = sprintf( '<strong>%s</strong> (%s)' , basename( $current_sidebar_template ) , $current_sidebar_template );
401
402 $debug_lists['find_locate_sidebar_templates'] = array();
403
404 foreach( $all_sidebar_templates as $template_file => $template_vals ) {
405
406 $debug_lists['find_locate_sidebar_templates'][ $template_file ] = $template_vals['found'];
407
408 }
409
410 $current_footer_template = false;
411
412 $all_footer_templates = array();
413
414 if( ! empty( self::$footer_templates ) ) {
415
416 foreach( self::$footer_templates as $key => $find_footer_template ) {
417
418 if( empty( $find_footer_template ) ) {
419
420 continue;
421
422 }
423
424 $current_theme_footer_template = MywpApi::get_theme_path() . '/' . $find_footer_template;
425 $parent_theme_footer_template = MywpApi::get_theme_path( true ) . '/' . $find_footer_template;
426 $wp_compat_footer_template = ABSPATH . WPINC . '/theme-compat/' . $find_footer_template;
427
428 $all_footer_templates[ $current_theme_footer_template ] = array( 'found' => 0 );
429
430 if( file_exists( $current_theme_footer_template ) ) {
431
432 $all_footer_templates[ $current_theme_footer_template ]['found'] = 1;
433
434 if( empty( $current_footer_template ) ) {
435
436 $current_footer_template = $current_theme_footer_template;
437
438 }
439
440 }
441
442 if( is_child_theme() ) {
443
444 $all_footer_templates[ $parent_theme_footer_template ] = array( 'found' => 0 );
445
446 if( file_exists( $parent_theme_footer_template ) ) {
447
448 $all_footer_templates[ $parent_theme_footer_template ]['found'] = 1;
449
450 if( empty( $current_footer_template ) ) {
451
452 $current_footer_template = $parent_theme_footer_template;
453
454 }
455
456 }
457
458 }
459
460 $all_footer_templates[ $wp_compat_footer_template ] = array( 'found' => 0 );
461
462 if( file_exists( $wp_compat_footer_template ) ) {
463
464 $all_footer_templates[ $wp_compat_footer_template ]['found'] = 1;
465
466 if( empty( $current_footer_template ) ) {
467
468 $current_footer_template = $wp_compat_footer_template;
469
470 }
471
472 }
473
474 }
475
476 }
477
478 $debug_lists['current_footer_template'] = sprintf( '<strong>%s</strong> (%s)' , basename( $current_footer_template ) , $current_footer_template );
479
480 $debug_lists['find_locate_footer_templates'] = array();
481
482 foreach( $all_footer_templates as $template_file => $template_vals ) {
483
484 $debug_lists['find_locate_footer_templates'][ $template_file ] = $template_vals['found'];
485
486 }
487
488 /*
489 if( is_front_page() ) {
490
491 } elseif( is_home() ) {
492
493 } elseif( is_single() ) {
494
495 } elseif( is_page() ) {
496
497 } elseif( is_singular() ) {
498
499 } elseif( is_category() ) {
500
501 } elseif( is_tag() ) {
502
503 } elseif( is_tax() ) {
504
505 } elseif( is_author() ) {
506
507 } elseif( is_date() ) {
508
509 } elseif( is_archive() ) {
510
511 } elseif( is_search() ) {
512
513 } elseif( is_404() ) {
514
515 } elseif( is_attachment() ) {
516
517 } elseif( is_paged() ) {
518
519 } elseif( is_post_type_archive() ) {
520
521 } elseif( is_page_template() ) {
522
523 } elseif( is_embed() ) {
524
525 }
526 */
527
528 if( is_singular() ) {
529
530 $debug_lists['post'] = $post;
531
532 if( ! empty( $post ) && is_object( $post ) ) {
533
534 $post_id = (int) $post->ID;
535
536 $debug_lists['post_id'] = $post_id;
537 $debug_lists['custom_fields'] = get_post_meta( $post_id );
538
539 $debug_lists['taxonomies'] = array();
540 $debug_lists['terms'] = array();
541
542 $post_taxonomies = get_post_taxonomies( $post_id );
543
544 if( ! empty( $post_taxonomies ) ) {
545
546 foreach( $post_taxonomies as $taxonomy_name ) {
547
548 $debug_lists['taxonomies'][ $taxonomy_name ] = false;
549 $debug_lists['terms'][ $taxonomy_name ] = false;
550
551 $taxonomy = get_taxonomy( $taxonomy_name );
552
553 $terms = wp_get_post_terms( $post_id , $taxonomy_name );
554
555 if( empty( $taxonomy ) ) {
556
557 continue;
558
559 }
560
561 $debug_lists['taxonomies'][ $taxonomy_name ] = $taxonomy;
562
563 if( ! empty( $terms ) ) {
564
565 $debug_lists['terms'][ $taxonomy_name ] = $terms;
566
567 }
568
569 }
570
571 }
572
573 $debug_lists['get_post( ' . $post_id . ' )'] = get_post( $post_id );
574 $debug_lists['MywpPostType::get_post( ' . $post_id . ' )'] = MywpPostType::get_post( $post_id );
575 $debug_lists['SELECT * FROM $wpdb->posts WHERE ID = ' . $post_id] = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) );
576
577 }
578
579 $debug_lists['get_permalink'] = esc_url( get_permalink( $post_id ) );
580 $debug_lists['get_page_link'] = esc_url( get_page_link( $post_id ) );
581
582 } elseif( is_archive() ) {
583
584 if( is_category() or is_tag() or is_tax() ) {
585
586 $term = get_queried_object();
587
588 $debug_lists['term'] = $term;
589
590 if( ! empty( $term ) && is_object( $term ) ) {
591
592 $debug_lists['taxonomy'] = $term->taxonomy;
593 $debug_lists['term_id'] = $term->term_id;
594 $debug_lists['custom_meta'] = get_term_meta( $term->term_id );
595
596 }
597
598 } elseif( is_date() ) {
599
600 $debug_lists['get_query_var("year")'] = get_query_var("year");
601 $debug_lists['get_query_var("m")'] = get_query_var("m");
602 $debug_lists['get_query_var("monthnum")'] = get_query_var("monthnum");
603 $debug_lists['get_query_var("day")'] = get_query_var("day");
604
605 }
606
607 } elseif( is_search() ) {
608
609 $debug_lists['get_search_query()'] = get_search_query();
610
611 }
612
613 return $debug_lists;
614
615 }
616
617 protected static function mywp_developer_debug() {
618
619 if( is_admin() ) {
620
621 return false;
622
623 }
624
625 parent::mywp_developer_debug();
626
627 }
628
629 protected static function mywp_debug_render() {
630
631 if( is_admin() ) {
632
633 return false;
634
635 }
636
637 parent::mywp_debug_render();
638
639 }
640
641 }
642
643 MywpDeveloperModuleDevFrontend::init();
644
645 endif;
646