| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if ( ! class_exists( 'MywpControllerInit' ) ) : |
| 8 |
|
| 9 |
final class MywpControllerInit { |
| 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_action( 'mywp_request_admin' , array( __CLASS__ , 'controller_cache' ) ); |
| 37 |
add_action( 'mywp_request_frontend' , array( __CLASS__ , 'controller_cache' ) ); |
| 38 |
|
| 39 |
add_filter( 'mywp_debug_renders' , array( __CLASS__ , 'mywp_debug_renders' ) , 100 ); |
| 40 |
|
| 41 |
add_action( 'mywp_debug_render_controller' , array( __CLASS__ , 'mywp_debug_render_controller' ) ); |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
public static function plugins_loaded_include_modules() { |
| 46 |
|
| 47 |
$dir = MYWP_PLUGIN_PATH . 'controller/modules/'; |
| 48 |
|
| 49 |
$includes = array( |
| 50 |
'admin_dashboard' => $dir . 'mywp.controller.module.admin.dashboard.php', |
| 51 |
'admin_general' => $dir . 'mywp.controller.module.admin.general.php', |
| 52 |
'admin_nav_menu' => $dir . 'mywp.controller.module.admin.nav-menu.php', |
| 53 |
'admin_post_edit' => $dir . 'mywp.controller.module.admin.post.edit.php', |
| 54 |
'admin_posts' => $dir . 'mywp.controller.module.admin.posts.php', |
| 55 |
'admin_regist_metaboxes' => $dir . 'mywp.controller.module.admin.regist.metaboxes.php', |
| 56 |
'admin_sidebar' => $dir . 'mywp.controller.module.admin.sidebar.php', |
| 57 |
'admin_user_edit' => $dir . 'mywp.controller.module.admin.user-edit.php', |
| 58 |
'debug_general' => $dir . 'mywp.controller.module.debug.general.php', |
| 59 |
'frontend_author_archive' => $dir . 'mywp.controller.module.frontend.author-archive.php', |
| 60 |
'frontend_date_archive' => $dir . 'mywp.controller.module.frontend.date-archive.php', |
| 61 |
'frontend_taxonomy_archive' => $dir . 'mywp.controller.module.frontend.taxonomy-archive.php', |
| 62 |
'frontend_general' => $dir . 'mywp.controller.module.frontend.general.php', |
| 63 |
'main_general' => $dir . 'mywp.controller.module.main.general.php', |
| 64 |
'site_general' => $dir . 'mywp.controller.module.site.general.php', |
| 65 |
); |
| 66 |
|
| 67 |
$includes = apply_filters( 'mywp_controller_plugins_loaded_include_modules' , $includes ); |
| 68 |
|
| 69 |
MywpApi::require_files( $includes ); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
public static function after_setup_theme_include_modules() { |
| 74 |
|
| 75 |
$includes = array(); |
| 76 |
|
| 77 |
$includes = apply_filters( 'mywp_controller_after_setup_theme_include_modules' , $includes ); |
| 78 |
|
| 79 |
MywpApi::require_files( $includes ); |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
public static function controller_cache() { |
| 84 |
|
| 85 |
MywpController::set_controllers(); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
public static function mywp_debug_renders( $debug_renders ) { |
| 90 |
|
| 91 |
$debug_renders['controller'] = array( |
| 92 |
'debug_type' => 'mywp', |
| 93 |
'title' => __( 'Controller' , 'mywp' ), |
| 94 |
); |
| 95 |
|
| 96 |
return $debug_renders; |
| 97 |
|
| 98 |
} |
| 99 |
|
| 100 |
public static function mywp_debug_render_controller() { |
| 101 |
|
| 102 |
echo '<ul>'; |
| 103 |
|
| 104 |
$controllers = MywpController::get_controllers(); |
| 105 |
|
| 106 |
if( !empty( $controllers ) ) { |
| 107 |
|
| 108 |
foreach( $controllers as $controller_id => $controller ) { |
| 109 |
|
| 110 |
if( !empty( $controller['model'] ) && is_object( $controller['model'] ) ) { |
| 111 |
|
| 112 |
$controller['model']->get_data(); |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
printf( '<li>%s <textarea readonly="readonly">%s</textarea></li>' , $controller_id , print_r( $controller , true ) ); |
| 117 |
|
| 118 |
} |
| 119 |
|
| 120 |
} |
| 121 |
|
| 122 |
echo '</ul>'; |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
endif; |
| 129 |
|