| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if ( ! class_exists( 'MywpDeveloperInit' ) ) : |
| 8 |
|
| 9 |
final class MywpDeveloperInit { |
| 10 |
|
| 11 |
private static $instance; |
| 12 |
|
| 13 |
private function __construct() {} |
| 14 |
|
| 15 |
public static function get_instance() { |
| 16 |
|
| 17 |
if ( !isset( self::$instance ) ) { |
| 18 |
|
| 19 |
self::$instance = new self(); |
| 20 |
|
| 21 |
} |
| 22 |
|
| 23 |
return self::$instance; |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
private function __clone() {} |
| 28 |
|
| 29 |
private function __wakeup() {} |
| 30 |
|
| 31 |
public static function init() { |
| 32 |
|
| 33 |
add_action( 'mywp_plugins_loaded' , array( __CLASS__ , 'plugins_loaded_include_modules' ) , 20 ); |
| 34 |
add_action( 'mywp_after_setup_theme' , array( __CLASS__ , 'after_setup_theme_include_modules' ) , 20 ); |
| 35 |
|
| 36 |
add_filter( 'mywp_debug_types' , array( __CLASS__ , 'add_debug_type_core' ) , 20 ); |
| 37 |
add_filter( 'mywp_debug_types' , array( __CLASS__ , 'add_debug_type_mywp' ) , 30 ); |
| 38 |
add_filter( 'mywp_debug_types' , array( __CLASS__ , 'add_debug_type_dev' ) , 40 ); |
| 39 |
add_filter( 'mywp_debug_types' , array( __CLASS__ , 'add_debug_type_custom' ) , 100 ); |
| 40 |
|
| 41 |
add_filter( 'mywp_debug_renders' , array( __CLASS__ , 'add_debug_renders_custom_example' ) ); |
| 42 |
|
| 43 |
add_action( 'mywp_debug_render_custom_example' , array( __CLASS__ , 'mywp_debug_render_custom_example' ) ); |
| 44 |
|
| 45 |
add_action( 'admin_enqueue_scripts' , array( __CLASS__ , 'enqueue_scripts' ) ); |
| 46 |
add_action( 'wp_enqueue_scripts' , array( __CLASS__ , 'enqueue_scripts' ) ); |
| 47 |
add_action( 'login_enqueue_scripts' , array( __CLASS__ , 'enqueue_scripts' ) ); |
| 48 |
|
| 49 |
add_action( 'admin_footer' , array( __CLASS__ , 'debug_footer_print' ) , 1000 ); |
| 50 |
add_action( 'wp_footer' , array( __CLASS__ , 'debug_footer_print' ) , 1000 ); |
| 51 |
add_action( 'login_footer' , array( __CLASS__ , 'debug_footer_print' ) , 1000 ); |
| 52 |
|
| 53 |
/* |
| 54 |
add_action( 'shutdown' , array( __CLASS__ , 'debug_footer_print' ) , 1000 ); |
| 55 |
*/ |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
public static function plugins_loaded_include_modules() { |
| 60 |
|
| 61 |
$dir = MYWP_PLUGIN_PATH . 'developer/modules/'; |
| 62 |
|
| 63 |
$includes = array( |
| 64 |
'core_environment' => $dir . 'mywp.developer.module.core.environment.php', |
| 65 |
'core_multisite' => $dir . 'mywp.developer.module.core.multisite.php', |
| 66 |
'core_site' => $dir . 'mywp.developer.module.core.site.php', |
| 67 |
'core_theme' => $dir . 'mywp.developer.module.core.theme.php', |
| 68 |
'core_user' => $dir . 'mywp.developer.module.core.user.php', |
| 69 |
'dev_actions' => $dir . 'mywp.developer.module.dev.actions.php', |
| 70 |
'dev_admin' => $dir . 'mywp.developer.module.dev.admin.php', |
| 71 |
'dev_debugtrace' => $dir . 'mywp.developer.module.dev.debugtrace.php', |
| 72 |
'dev_date' => $dir . 'mywp.developer.module.dev.date.php', |
| 73 |
'dev_frontend' => $dir . 'mywp.developer.module.dev.frontend.php', |
| 74 |
'dev_request' => $dir . 'mywp.developer.module.dev.request.php', |
| 75 |
'dev_times' => $dir . 'mywp.developer.module.dev.times.php', |
| 76 |
'mywp_cache' => $dir . 'mywp.developer.module.mywp.cache.php', |
| 77 |
'mywp_error' => $dir . 'mywp.developer.module.mywp.error.php', |
| 78 |
'mywp_info' => $dir . 'mywp.developer.module.mywp.info.php', |
| 79 |
); |
| 80 |
|
| 81 |
$includes = apply_filters( 'mywp_developer_plugins_loaded_include_modules' , $includes ); |
| 82 |
|
| 83 |
MywpApi::require_files( $includes ); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
public static function after_setup_theme_include_modules() { |
| 88 |
|
| 89 |
$includes = array(); |
| 90 |
|
| 91 |
$includes = apply_filters( 'mywp_developer_after_setup_theme_include_modules' , $includes ); |
| 92 |
|
| 93 |
MywpApi::require_files( $includes ); |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
public static function add_debug_type_core( $debug_types ) { |
| 98 |
|
| 99 |
$debug_types['core'] = __( 'Core' , 'my-wp' ); |
| 100 |
|
| 101 |
return $debug_types; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
public static function add_debug_type_mywp( $debug_types ) { |
| 106 |
|
| 107 |
$debug_types['mywp'] = __( 'My WP' , 'my-wp' ); |
| 108 |
|
| 109 |
return $debug_types; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
public static function add_debug_type_dev( $debug_types ) { |
| 114 |
|
| 115 |
$debug_types['dev'] = __( 'Dev' , 'my-wp' ); |
| 116 |
|
| 117 |
return $debug_types; |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
public static function add_debug_type_custom( $debug_types ) { |
| 122 |
|
| 123 |
$debug_types['custom'] = __( 'Custom' , 'my-wp' ); |
| 124 |
|
| 125 |
return $debug_types; |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
public static function add_debug_renders_custom_example( $debug_renders ) { |
| 130 |
|
| 131 |
$debug_renders['custom_example'] = array( |
| 132 |
'debug_type' => 'custom', |
| 133 |
'title' => __( 'You can add custom debug panel :-)' , 'my-wp' ), |
| 134 |
); |
| 135 |
|
| 136 |
return $debug_renders; |
| 137 |
|
| 138 |
} |
| 139 |
|
| 140 |
public static function mywp_debug_render_custom_example() { |
| 141 |
|
| 142 |
printf( '<a href="%s" target="_blank">%s</a>' , esc_url( 'https://mywpcustomize.com/document/mywp-debug-panel-extends/' ) , __( 'Document for Debug panel' , 'my-wp' ) ); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
public static function enqueue_scripts() { |
| 147 |
|
| 148 |
if( ! MywpDeveloper::is_debug() ) { |
| 149 |
|
| 150 |
return false; |
| 151 |
|
| 152 |
} |
| 153 |
|
| 154 |
wp_register_style( 'mywp_developer' , MywpApi::get_plugin_url( 'css' ) . 'developer.css' , array() , MYWP_VERSION ); |
| 155 |
wp_register_script( 'mywp_developer' , MywpApi::get_plugin_url( 'js' ) . 'developer.js' , array( 'jquery' ) , MYWP_VERSION ); |
| 156 |
|
| 157 |
wp_enqueue_style( 'mywp_developer' ); |
| 158 |
wp_enqueue_script( 'mywp_developer' ); |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
public static function debug_footer_print() { |
| 163 |
|
| 164 |
if( ! MywpDeveloper::is_debug() ) { |
| 165 |
|
| 166 |
return false; |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
if( MywpHelper::is_doing( 'cron' ) or MywpHelper::is_doing( 'xmlrpc' ) or MywpHelper::is_doing( 'ajax' ) or MywpHelper::is_doing( 'rest' ) ) { |
| 171 |
|
| 172 |
return false; |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
MywpApi::include_file( MYWP_PLUGIN_PATH . 'views/debug-footer.php' ); |
| 177 |
|
| 178 |
} |
| 179 |
|
| 180 |
} |
| 181 |
|
| 182 |
endif; |
| 183 |
|