| 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 |
protected static function after_init() { |
| 22 |
|
| 23 |
$template_types = array( |
| 24 |
'embed', |
| 25 |
'404', |
| 26 |
'search', |
| 27 |
'frontpage', |
| 28 |
'home', |
| 29 |
'taxonomy', |
| 30 |
'attachment', |
| 31 |
'single', |
| 32 |
'page', |
| 33 |
'singular', |
| 34 |
'category', |
| 35 |
'tag', |
| 36 |
'author', |
| 37 |
'date', |
| 38 |
'archive', |
| 39 |
'index', |
| 40 |
); |
| 41 |
|
| 42 |
foreach( $template_types as $template_type ) { |
| 43 |
|
| 44 |
add_filter( "{$template_type}_template_hierarchy" , array( __CLASS__ , 'regist_template_hierarchy' ) , 100 ); |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
public static function regist_template_hierarchy( $templates ) { |
| 51 |
|
| 52 |
$find_templates = $templates; |
| 53 |
|
| 54 |
if( is_array( $find_templates ) ) { |
| 55 |
|
| 56 |
foreach( $find_templates as $find_template ) { |
| 57 |
|
| 58 |
self::$find_templates[] = $find_template; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
return $templates; |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
public static function mywp_debug_renders( $debug_renders ) { |
| 69 |
|
| 70 |
if( is_admin() ) { |
| 71 |
|
| 72 |
return $debug_renders; |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
$debug_renders[ self::$id ] = array( |
| 77 |
'debug_type' => 'dev', |
| 78 |
'title' => __( 'Current Frontend Information' , 'my-wp' ), |
| 79 |
); |
| 80 |
|
| 81 |
return $debug_renders; |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
protected static function get_debug_lists() { |
| 86 |
|
| 87 |
global $post; |
| 88 |
global $template; |
| 89 |
|
| 90 |
$debug_lists = array( |
| 91 |
'is_front_page()' => is_front_page(), |
| 92 |
'is_home()' => is_home(), |
| 93 |
'is_single()' => is_single(), |
| 94 |
'is_page()' => is_page(), |
| 95 |
'is_singular()' => is_singular(), |
| 96 |
'is_category()' => is_category(), |
| 97 |
'is_tag()' => is_tag(), |
| 98 |
'is_tax()' => is_tax(), |
| 99 |
'is_author()' => is_author(), |
| 100 |
'is_date()' => is_date(), |
| 101 |
'is_archive()' => is_archive(), |
| 102 |
'is_search()' => is_search(), |
| 103 |
'is_404()' => is_404(), |
| 104 |
'is_attachment()' => is_attachment(), |
| 105 |
'is_paged()' => is_paged(), |
| 106 |
'is_post_type_archive()' => is_post_type_archive(), |
| 107 |
'is_page_template()' => is_page_template(), |
| 108 |
'is_embed' => is_embed(), |
| 109 |
'is_main_query()' => is_main_query(), |
| 110 |
'is_preview()' => is_preview(), |
| 111 |
); |
| 112 |
|
| 113 |
$current_template = false; |
| 114 |
|
| 115 |
$all_templates = array(); |
| 116 |
|
| 117 |
if( ! empty( self::$find_templates ) ) { |
| 118 |
|
| 119 |
foreach( self::$find_templates as $key => $find_template ) { |
| 120 |
|
| 121 |
if( empty( $find_template ) ) { |
| 122 |
|
| 123 |
continue; |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
$current_theme_template = STYLESHEETPATH . '/' . $find_template; |
| 128 |
$parent_theme_template = TEMPLATEPATH . '/' . $find_template; |
| 129 |
$wp_compat_template = ABSPATH . WPINC . '/theme-compat/' . $find_template; |
| 130 |
|
| 131 |
$all_templates[ $current_theme_template ] = array( 'found' => 0 ); |
| 132 |
|
| 133 |
if( file_exists( $current_theme_template ) ) { |
| 134 |
|
| 135 |
$all_templates[ $current_theme_template ]['found'] = 1; |
| 136 |
|
| 137 |
if( empty( $current_template ) ) { |
| 138 |
|
| 139 |
$current_template = $current_theme_template; |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
if( is_child_theme() ) { |
| 146 |
|
| 147 |
$all_templates[ $parent_theme_template ] = array( 'found' => 0 ); |
| 148 |
|
| 149 |
if( file_exists( $parent_theme_template ) ) { |
| 150 |
|
| 151 |
$all_templates[ $parent_theme_template ]['found'] = 1; |
| 152 |
|
| 153 |
if( empty( $current_template ) ) { |
| 154 |
|
| 155 |
$current_template = $parent_theme_template; |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
$all_templates[ $wp_compat_template ] = array( 'found' => 0 ); |
| 164 |
|
| 165 |
if( file_exists( $wp_compat_template ) ) { |
| 166 |
|
| 167 |
$all_templates[ $wp_compat_template ]['found'] = 1; |
| 168 |
|
| 169 |
if( empty( $current_template ) ) { |
| 170 |
|
| 171 |
$current_template = $wp_compat_template; |
| 172 |
|
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
} |
| 180 |
|
| 181 |
$debug_lists['current_template'] = sprintf( '<strong>%s</strong> (%s)' , basename( $template ) , $current_template ); |
| 182 |
|
| 183 |
$debug_lists['find_locate_templates'] = array(); |
| 184 |
|
| 185 |
foreach( $all_templates as $template_file => $template_vals ) { |
| 186 |
|
| 187 |
$debug_lists['find_locate_templates'][ $template_file ] = $template_vals['found']; |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
/* |
| 192 |
if( is_front_page() ) { |
| 193 |
|
| 194 |
} elseif( is_home() ) { |
| 195 |
|
| 196 |
} elseif( is_single() ) { |
| 197 |
|
| 198 |
} elseif( is_page() ) { |
| 199 |
|
| 200 |
} elseif( is_singular() ) { |
| 201 |
|
| 202 |
} elseif( is_category() ) { |
| 203 |
|
| 204 |
} elseif( is_tag() ) { |
| 205 |
|
| 206 |
} elseif( is_tax() ) { |
| 207 |
|
| 208 |
} elseif( is_author() ) { |
| 209 |
|
| 210 |
} elseif( is_date() ) { |
| 211 |
|
| 212 |
} elseif( is_archive() ) { |
| 213 |
|
| 214 |
} elseif( is_search() ) { |
| 215 |
|
| 216 |
} elseif( is_404() ) { |
| 217 |
|
| 218 |
} elseif( is_attachment() ) { |
| 219 |
|
| 220 |
} elseif( is_paged() ) { |
| 221 |
|
| 222 |
} elseif( is_post_type_archive() ) { |
| 223 |
|
| 224 |
} elseif( is_page_template() ) { |
| 225 |
|
| 226 |
} elseif( is_embed() ) { |
| 227 |
|
| 228 |
} |
| 229 |
*/ |
| 230 |
|
| 231 |
if( is_singular() ) { |
| 232 |
|
| 233 |
$debug_lists['post'] = $post; |
| 234 |
|
| 235 |
if( ! empty( $post ) && is_object( $post ) ) { |
| 236 |
|
| 237 |
$debug_lists['post_id'] = intval( $post->ID ); |
| 238 |
$debug_lists['custom_fields'] = get_post_meta( $post->ID ); |
| 239 |
|
| 240 |
$debug_lists['taxonomies'] = array(); |
| 241 |
$debug_lists['terms'] = array(); |
| 242 |
|
| 243 |
$post_taxonomies = get_post_taxonomies( $post->ID ); |
| 244 |
|
| 245 |
if( ! empty( $post_taxonomies ) ) { |
| 246 |
|
| 247 |
foreach( $post_taxonomies as $taxonomy_name ) { |
| 248 |
|
| 249 |
$debug_lists['taxonomies'][ $taxonomy_name ] = false; |
| 250 |
$debug_lists['terms'][ $taxonomy_name ] = false; |
| 251 |
|
| 252 |
$taxonomy = get_taxonomy( $taxonomy_name ); |
| 253 |
|
| 254 |
$terms = wp_get_post_terms( $post->ID , $taxonomy_name ); |
| 255 |
|
| 256 |
if( empty( $taxonomy ) ) { |
| 257 |
|
| 258 |
continue; |
| 259 |
|
| 260 |
} |
| 261 |
|
| 262 |
$debug_lists['taxonomies'][ $taxonomy_name ] = $taxonomy; |
| 263 |
|
| 264 |
if( ! empty( $terms ) ) { |
| 265 |
|
| 266 |
$debug_lists['terms'][ $taxonomy_name ] = $terms; |
| 267 |
|
| 268 |
} |
| 269 |
|
| 270 |
} |
| 271 |
|
| 272 |
} |
| 273 |
|
| 274 |
} |
| 275 |
|
| 276 |
$debug_lists['get_permalink'] = esc_url( get_permalink( $post->ID ) ); |
| 277 |
$debug_lists['get_page_link'] = esc_url( get_page_link( $post->ID ) ); |
| 278 |
|
| 279 |
} elseif( is_archive() ) { |
| 280 |
|
| 281 |
if( is_category() or is_tag() or is_tax() ) { |
| 282 |
|
| 283 |
$term = get_queried_object(); |
| 284 |
|
| 285 |
$debug_lists['term'] = $term; |
| 286 |
|
| 287 |
if( ! empty( $term ) && is_object( $term ) ) { |
| 288 |
|
| 289 |
$debug_lists['taxonomy'] = $term->taxonomy; |
| 290 |
$debug_lists['term_id'] = $term->term_id; |
| 291 |
$debug_lists['custom_meta'] = get_term_meta( $term->term_id ); |
| 292 |
|
| 293 |
} |
| 294 |
|
| 295 |
} elseif( is_date() ) { |
| 296 |
|
| 297 |
$debug_lists['get_query_var("year")'] = get_query_var("year"); |
| 298 |
$debug_lists['get_query_var("m")'] = get_query_var("m"); |
| 299 |
$debug_lists['get_query_var("monthnum")'] = get_query_var("monthnum"); |
| 300 |
$debug_lists['get_query_var("day")'] = get_query_var("day"); |
| 301 |
|
| 302 |
} |
| 303 |
|
| 304 |
} elseif( is_search() ) { |
| 305 |
|
| 306 |
$debug_lists['get_search_query()'] = get_search_query(); |
| 307 |
|
| 308 |
} |
| 309 |
|
| 310 |
return $debug_lists; |
| 311 |
|
| 312 |
} |
| 313 |
|
| 314 |
protected static function mywp_developer_debug() { |
| 315 |
|
| 316 |
if( is_admin() ) { |
| 317 |
|
| 318 |
return false; |
| 319 |
|
| 320 |
} |
| 321 |
|
| 322 |
parent::mywp_developer_debug(); |
| 323 |
|
| 324 |
} |
| 325 |
|
| 326 |
protected static function mywp_debug_render() { |
| 327 |
|
| 328 |
if( is_admin() ) { |
| 329 |
|
| 330 |
return false; |
| 331 |
|
| 332 |
} |
| 333 |
|
| 334 |
parent::mywp_debug_render(); |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
} |
| 339 |
|
| 340 |
MywpDeveloperModuleDevFrontend::init(); |
| 341 |
|
| 342 |
endif; |
| 343 |
|