| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpControllerAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpControllerModuleDebugGeneral' ) ) : |
| 12 |
|
| 13 |
final class MywpControllerModuleDebugGeneral extends MywpControllerAbstractModule { |
| 14 |
|
| 15 |
static protected $id = 'debug_general'; |
| 16 |
|
| 17 |
static protected $is_do_controller = true; |
| 18 |
|
| 19 |
public static function mywp_controller_initial_data( $initial_data ) { |
| 20 |
|
| 21 |
$initial_data['users'] = array(); |
| 22 |
|
| 23 |
return $initial_data; |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
public static function mywp_controller_default_data( $default_data ) { |
| 28 |
|
| 29 |
$default_data['users'] = array(); |
| 30 |
|
| 31 |
return $default_data; |
| 32 |
|
| 33 |
} |
| 34 |
|
| 35 |
protected static function after_init() { |
| 36 |
|
| 37 |
add_filter( 'mywp_is_debug' , array( __CLASS__ , 'mywp_is_debug' ) , 9 ); |
| 38 |
|
| 39 |
add_action( 'after_setup_theme' , array( __CLASS__ , 'after_setup_theme' ) , 49 ); |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
public static function mywp_wp_loaded() { |
| 44 |
|
| 45 |
add_action( 'mywp_request_admin' , array( __CLASS__ , 'mywp_request_admin' ) , 49 ); |
| 46 |
add_action( 'mywp_request_frontend' , array( __CLASS__ , 'mywp_request_frontend' ) , 49 ); |
| 47 |
add_action( 'mywp_ajax' , array( __CLASS__ , 'mywp_ajax' ) , 49 ); |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public static function mywp_is_debug( $is_debug ) { |
| 52 |
|
| 53 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 54 |
|
| 55 |
return false; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
$setting_data = self::get_setting_data(); |
| 60 |
|
| 61 |
if( empty( $setting_data['users'] ) ) { |
| 62 |
|
| 63 |
return false; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
$user_id = get_current_user_id(); |
| 68 |
|
| 69 |
if( empty( $user_id ) ) { |
| 70 |
|
| 71 |
return false; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
if( in_array( $user_id , $setting_data['users'] ) ) { |
| 76 |
|
| 77 |
return true; |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
self::after_do_function( __FUNCTION__ ); |
| 82 |
|
| 83 |
return false; |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
public static function after_setup_theme() { |
| 88 |
|
| 89 |
if( ! MywpDeveloper::is_debug() ) { |
| 90 |
|
| 91 |
return false; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
add_filter( 'mywp_post_types' , array( __CLASS__ , 'mywp_post_types' ) , 49 ); |
| 96 |
add_filter( 'mywp_taxonomy_types' , array( __CLASS__ , 'mywp_taxonomy_types' ) , 49 ); |
| 97 |
|
| 98 |
add_filter( 'mywp_debug_renders' , array( __CLASS__ , 'mywp_debug_renders' ) , 11 ); |
| 99 |
add_action( 'mywp_debug_render_shortcode' , array( __CLASS__ , 'mywp_debug_render_shortcode' ) , 11 ); |
| 100 |
add_action( 'mywp_debug_render_post_type' , array( __CLASS__ , 'mywp_debug_render_post_type' ) , 11 ); |
| 101 |
add_action( 'mywp_debug_render_taxonomy' , array( __CLASS__ , 'mywp_debug_render_taxonomy' ) , 11 ); |
| 102 |
add_action( 'mywp_debug_render_controller' , array( __CLASS__ , 'mywp_debug_render_controller' ) , 11 ); |
| 103 |
add_action( 'mywp_debug_render_current_setting' , array( __CLASS__ , 'mywp_debug_render_current_setting' ) , 11 ); |
| 104 |
add_action( 'mywp_debug_render_settings' , array( __CLASS__ , 'mywp_debug_render_settings' ) , 11 ); |
| 105 |
add_action( 'mywp_debug_render_thirdparty' , array( __CLASS__ , 'mywp_debug_render_thirdparty' ) , 11 ); |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
public static function mywp_post_types( $post_types ) { |
| 110 |
|
| 111 |
foreach( $post_types as $post_type_name => $post_type_setting ) { |
| 112 |
|
| 113 |
$post_types[ $post_type_name ]['show_ui'] = true; |
| 114 |
$post_types[ $post_type_name ]['delete_with_user'] = true; |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
return $post_types; |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
public static function mywp_taxonomy_types( $taxonomy_types ) { |
| 123 |
|
| 124 |
foreach( $taxonomy_types as $taxonomy_name => $taxonomy_setting ) { |
| 125 |
|
| 126 |
$taxonomy_types[ $taxonomy_name ]['show_ui'] = true; |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
return $taxonomy_types; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
public static function mywp_debug_renders( $debug_renders ) { |
| 135 |
|
| 136 |
$debug_renders['shortcode'] = array( |
| 137 |
'debug_type' => 'mywp', |
| 138 |
'title' => __( 'My WP Shortcode' , 'my-wp' ), |
| 139 |
); |
| 140 |
|
| 141 |
$debug_renders['post_type'] = array( |
| 142 |
'debug_type' => 'mywp', |
| 143 |
'title' => __( 'My WP Post_Type' , 'my-wp' ), |
| 144 |
); |
| 145 |
|
| 146 |
$debug_renders['taxonomy'] = array( |
| 147 |
'debug_type' => 'mywp', |
| 148 |
'title' => __( 'My WP Taxonomy' , 'my-wp' ), |
| 149 |
); |
| 150 |
|
| 151 |
$debug_renders['current_setting'] = array( |
| 152 |
'debug_type' => 'mywp', |
| 153 |
'title' => __( 'Current Setting' , 'my-wp' ), |
| 154 |
); |
| 155 |
|
| 156 |
$debug_renders['settings'] = array( |
| 157 |
'debug_type' => 'mywp', |
| 158 |
'title' => __( 'Settings' , 'my-wp' ), |
| 159 |
); |
| 160 |
|
| 161 |
$debug_renders['controller'] = array( |
| 162 |
'debug_type' => 'mywp', |
| 163 |
'title' => __( 'Controller' , 'my-wp' ), |
| 164 |
); |
| 165 |
|
| 166 |
$debug_renders['thirdparty'] = array( |
| 167 |
'debug_type' => 'dev', |
| 168 |
'title' => __( 'Thirdparty' , 'my-wp' ), |
| 169 |
); |
| 170 |
|
| 171 |
return $debug_renders; |
| 172 |
|
| 173 |
} |
| 174 |
|
| 175 |
public static function mywp_debug_render_shortcode() { |
| 176 |
|
| 177 |
echo '<ul>'; |
| 178 |
|
| 179 |
$shortcodes = MywpShortcode::get_shortcodes(); |
| 180 |
|
| 181 |
if( ! empty( $shortcodes ) ) { |
| 182 |
|
| 183 |
foreach( $shortcodes as $shortcode => $function ) { |
| 184 |
|
| 185 |
printf( '<li>%s</li>' , $shortcode ); |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
} |
| 190 |
|
| 191 |
echo '</ul>'; |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
public static function mywp_debug_render_post_type() { |
| 196 |
|
| 197 |
echo '<ul>'; |
| 198 |
|
| 199 |
$post_types = MywpPostType::get_post_types(); |
| 200 |
|
| 201 |
if( ! empty( $post_types ) ) { |
| 202 |
|
| 203 |
foreach( $post_types as $post_type_name => $args ) { |
| 204 |
|
| 205 |
printf( '<li>%s <textarea readonly="readonly">%s</textarea>' , $post_type_name , print_r( $args , true ) ); |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
echo '</ul>'; |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
public static function mywp_debug_render_taxonomy() { |
| 216 |
|
| 217 |
echo '<ul>'; |
| 218 |
|
| 219 |
$taxonomy_types = MywpTaxonomy::get_taxonomy_types(); |
| 220 |
|
| 221 |
if( ! empty( $taxonomy_types ) ) { |
| 222 |
|
| 223 |
foreach( $taxonomy_types as $taxonomy_name => $args ) { |
| 224 |
|
| 225 |
printf( '<li>%s <textarea readonly="readonly">%s</textarea>' , $taxonomy_name , print_r( $args , true ) ); |
| 226 |
|
| 227 |
} |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
echo '</ul>'; |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
public static function mywp_debug_render_controller() { |
| 236 |
|
| 237 |
echo '<ul>'; |
| 238 |
|
| 239 |
$controllers = MywpController::get_controllers(); |
| 240 |
|
| 241 |
if( ! empty( $controllers ) ) { |
| 242 |
|
| 243 |
foreach( $controllers as $controller_id => $controller ) { |
| 244 |
|
| 245 |
if( ! empty( $controller['model'] ) && is_object( $controller['model'] ) ) { |
| 246 |
|
| 247 |
$controller['model']->get_setting_data(); |
| 248 |
|
| 249 |
} |
| 250 |
|
| 251 |
printf( '<li>%s <textarea readonly="readonly">%s</textarea></li>' , $controller_id , print_r( $controller , true ) ); |
| 252 |
|
| 253 |
} |
| 254 |
|
| 255 |
} |
| 256 |
|
| 257 |
echo '</ul>'; |
| 258 |
|
| 259 |
} |
| 260 |
|
| 261 |
public static function mywp_debug_render_current_setting() { |
| 262 |
|
| 263 |
$current_setting_menu = MywpSettingMenu::get_current_menu(); |
| 264 |
|
| 265 |
if( ! empty( $current_setting_menu ) ) { |
| 266 |
|
| 267 |
printf( '<p>Current Setting Menu = <textarea readonly="readonly">%s</textarea></p>' , print_r( $current_setting_menu , true ) ); |
| 268 |
|
| 269 |
} |
| 270 |
|
| 271 |
$current_setting_screen = MywpSettingScreen::get_current_screen(); |
| 272 |
|
| 273 |
if( ! empty( $current_setting_screen ) ) { |
| 274 |
|
| 275 |
printf( '<p>Current Setting Screen = <textarea readonly="readonly">%s</textarea></p>' , print_r( $current_setting_screen , true ) ); |
| 276 |
|
| 277 |
} |
| 278 |
|
| 279 |
$mywp_model = false; |
| 280 |
|
| 281 |
if( ! empty( $current_setting_screen['id'] ) ) { |
| 282 |
|
| 283 |
$mywp_model = MywpSetting::get_model( $current_setting_screen['id'] ); |
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
printf( '<p>Current Setting Screen Model = <textarea readonly="readonly">%s</textarea></p>' , print_r( $mywp_model , true ) ); |
| 288 |
|
| 289 |
$current_setting_post_type = MywpSettingPostType::get_current_post_type(); |
| 290 |
|
| 291 |
if( ! empty( $current_setting_post_type ) ) { |
| 292 |
|
| 293 |
printf( '<p>Current Setting Post Type = <textarea readonly="readonly">%s</textarea></p>' , print_r( $current_setting_post_type , true ) ); |
| 294 |
|
| 295 |
} |
| 296 |
|
| 297 |
$current_setting_taxonomy = MywpSettingTaxonomy::get_current_taxonomy(); |
| 298 |
|
| 299 |
if( ! empty( $current_setting_taxonomy ) ) { |
| 300 |
|
| 301 |
printf( '<p>Current Setting Taxonomy = <textarea readonly="readonly">%s</textarea></p>' , print_r( $current_setting_taxonomy , true ) ); |
| 302 |
|
| 303 |
} |
| 304 |
|
| 305 |
$current_menu_id = MywpSettingMenu::get_current_menu_id(); |
| 306 |
|
| 307 |
if( ! empty( $current_menu_id ) ) { |
| 308 |
|
| 309 |
$current_setting_screens = MywpSettingScreen::get_setting_screens_by_menu_id( MywpSettingMenu::get_current_menu_id() ); |
| 310 |
|
| 311 |
if( ! empty( $current_setting_screens ) ) { |
| 312 |
|
| 313 |
printf( '<p>Current Setting Screens = <textarea readonly="readonly">%s</textarea></p>' , print_r( $current_setting_screens , true ) ); |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
} |
| 320 |
|
| 321 |
public static function mywp_debug_render_settings() { |
| 322 |
|
| 323 |
$setting_menus = MywpSettingMenu::get_setting_menus(); |
| 324 |
|
| 325 |
echo 'Setting Menus'; |
| 326 |
|
| 327 |
if( ! empty( $setting_menus ) ) { |
| 328 |
|
| 329 |
printf( '<textarea readonly="readonly">%s</textarea>' , print_r( $setting_menus , true ) ); |
| 330 |
|
| 331 |
} |
| 332 |
|
| 333 |
$menu_hook_names = MywpSettingMenu::get_menu_hook_names(); |
| 334 |
|
| 335 |
echo 'Menu Hook Names'; |
| 336 |
|
| 337 |
if( ! empty( $menu_hook_names ) ) { |
| 338 |
|
| 339 |
printf( '<textarea readonly="readonly">%s</textarea>' , print_r( $menu_hook_names , true ) ); |
| 340 |
|
| 341 |
} |
| 342 |
|
| 343 |
$setting_screens = MywpSettingScreen::get_setting_screens(); |
| 344 |
|
| 345 |
echo 'Setting Screens'; |
| 346 |
|
| 347 |
if( ! empty( $setting_screens ) ) { |
| 348 |
|
| 349 |
printf( '<textarea readonly="readonly">%s</textarea>' , print_r( $setting_screens , true ) ); |
| 350 |
|
| 351 |
} |
| 352 |
|
| 353 |
$setting_post_types = MywpSettingPostType::get_setting_post_types(); |
| 354 |
|
| 355 |
echo 'Setting Post Types'; |
| 356 |
|
| 357 |
if( ! empty( $setting_post_types ) ) { |
| 358 |
|
| 359 |
printf( '<textarea readonly="readonly">%s</textarea>' , print_r( $setting_post_types , true ) ); |
| 360 |
|
| 361 |
} |
| 362 |
|
| 363 |
$setting_taxonomies = MywpSettingTaxonomy::get_setting_taxonomies(); |
| 364 |
|
| 365 |
echo 'Setting Taxonomies'; |
| 366 |
|
| 367 |
if( ! empty( $setting_taxonomies ) ) { |
| 368 |
|
| 369 |
printf( '<textarea readonly="readonly">%s</textarea>' , print_r( $setting_taxonomies , true ) ); |
| 370 |
|
| 371 |
} |
| 372 |
|
| 373 |
} |
| 374 |
|
| 375 |
public static function mywp_debug_render_thirdparty() { |
| 376 |
|
| 377 |
$thirdparties = MywpThirdparty::get_plugins( true ); |
| 378 |
|
| 379 |
if( ! empty( $thirdparties ) ) { |
| 380 |
|
| 381 |
echo '<table class="debug-table">'; |
| 382 |
|
| 383 |
foreach( $thirdparties as $plugin_base_name => $plugin ) { |
| 384 |
|
| 385 |
echo '<tr>'; |
| 386 |
|
| 387 |
if( $plugin['activate'] ) { |
| 388 |
|
| 389 |
printf( '<th>%s (%s)</th>' , $plugin['plugin_name'] , $plugin['plugin_data']['Version'] ); |
| 390 |
|
| 391 |
} else { |
| 392 |
|
| 393 |
printf( '<th>%s</th>' , $plugin['plugin_name'] ); |
| 394 |
|
| 395 |
} |
| 396 |
|
| 397 |
echo '<td>'; |
| 398 |
|
| 399 |
if( $plugin['activate'] ) { |
| 400 |
|
| 401 |
printf( '<strong>%s</strong>' , __( 'Activated' , 'my-wp' ) ); |
| 402 |
|
| 403 |
} else { |
| 404 |
|
| 405 |
_e( 'Not Activated' , 'my-wp' ); |
| 406 |
|
| 407 |
} |
| 408 |
|
| 409 |
echo '<br />'; |
| 410 |
|
| 411 |
printf( __( 'plugin base name: %s' , 'my-wp' ) . '<br />' , $plugin['plugin_base_name'] ); |
| 412 |
|
| 413 |
if( $plugin['activate'] ) { |
| 414 |
|
| 415 |
printf( '<pre>%s</pre>' , print_r( $plugin['plugin_data'] , true ) ); |
| 416 |
|
| 417 |
} |
| 418 |
echo '</td>'; |
| 419 |
|
| 420 |
echo '</tr>'; |
| 421 |
|
| 422 |
} |
| 423 |
|
| 424 |
echo '</table>'; |
| 425 |
|
| 426 |
} |
| 427 |
|
| 428 |
} |
| 429 |
|
| 430 |
public static function mywp_request_admin() { |
| 431 |
|
| 432 |
if( ! MywpDeveloper::is_debug() ) { |
| 433 |
|
| 434 |
return false; |
| 435 |
|
| 436 |
} |
| 437 |
|
| 438 |
add_filter( 'current_edit_per_page' , array( __CLASS__ , 'current_edit_per_page' ) ); |
| 439 |
|
| 440 |
add_filter( 'mywp_setting_admin_sidebar_print_item_header_pre_add_title' , array( __CLASS__ , 'mywp_setting_admin_sidebar_print_item_header_pre_add_title' ) , 10 , 2 ); |
| 441 |
add_filter( 'mywp_setting_admin_toolbar_print_item_header_pre_add_title' , array( __CLASS__ , 'mywp_setting_admin_toolbar_print_item_header_pre_add_title' ) , 10 , 2 ); |
| 442 |
|
| 443 |
} |
| 444 |
|
| 445 |
public static function mywp_request_frontend() { |
| 446 |
|
| 447 |
if( ! MywpDeveloper::is_debug() ) { |
| 448 |
|
| 449 |
return false; |
| 450 |
|
| 451 |
} |
| 452 |
|
| 453 |
} |
| 454 |
|
| 455 |
public static function mywp_ajax() { |
| 456 |
|
| 457 |
if( ! MywpDeveloper::is_debug() ) { |
| 458 |
|
| 459 |
return false; |
| 460 |
|
| 461 |
} |
| 462 |
|
| 463 |
add_filter( 'mywp_setting_admin_sidebar_print_item_header_pre_add_title' , array( __CLASS__ , 'mywp_setting_admin_sidebar_print_item_header_pre_add_title' ) , 10 , 2 ); |
| 464 |
add_filter( 'mywp_setting_admin_toolbar_print_item_header_pre_add_title' , array( __CLASS__ , 'mywp_setting_admin_toolbar_print_item_header_pre_add_title' ) , 10 , 2 ); |
| 465 |
|
| 466 |
} |
| 467 |
|
| 468 |
public static function current_edit_per_page( $per_page ) { |
| 469 |
|
| 470 |
$per_page = 200; |
| 471 |
|
| 472 |
return $per_page; |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
public static function mywp_setting_admin_sidebar_print_item_header_pre_add_title( $pre_add_title , $item ) { |
| 477 |
|
| 478 |
$pre_add_title .= sprintf( '[%d]' , $item->ID ); |
| 479 |
|
| 480 |
return $pre_add_title; |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
public static function mywp_setting_admin_toolbar_print_item_header_pre_add_title( $pre_add_title , $item ) { |
| 485 |
|
| 486 |
$pre_add_title .= sprintf( '[%d]' , $item->ID ); |
| 487 |
|
| 488 |
return $pre_add_title; |
| 489 |
|
| 490 |
} |
| 491 |
|
| 492 |
} |
| 493 |
|
| 494 |
MywpControllerModuleDebugGeneral::init(); |
| 495 |
|
| 496 |
endif; |
| 497 |
|