PluginProbe
My WP Customize Admin/Frontend / 1.2.0
My WP Customize Admin/Frontend v1.2.0
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 / controller / abstract.controller.module.php

abstract.controller.module.php in My WP Customize Admin/Frontend 1.2.0, at controller/abstract.controller.module.php

186 lines 3.7 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( 'MywpControllerAbstractModule' ) ) :
8
9 abstract class MywpControllerAbstractModule {
10
11 private static $instance;
12
13 static protected $id = '';
14
15 static protected $priority = 10;
16
17 static protected $model_use_filter = true;
18
19 static protected $network = false;
20
21 static protected $is_do_controller = false;
22
23 private function __construct() {}
24
25 public static function get_instance() {
26
27 $class = get_called_class();
28
29 if ( !isset( self::$instance[ $class ] ) ) {
30
31 self::$instance[ $class ] = new static();
32
33 }
34
35 return self::$instance[ $class ];
36
37 }
38
39 private function __clone() {}
40
41 private function __wakeup() {}
42
43 public static function init() {
44
45 $class = get_called_class();
46
47 if( empty( static::$id ) ) {
48
49 $called_text = sprintf( 'class %s' , $class );
50
51 MywpHelper::error_require_message( '"static protected $id"' , $called_text );
52
53 return false;
54
55 }
56
57 add_filter( 'mywp_controllers' , array( $class , 'mywp_controllers' ) , static::$priority );
58
59 add_filter( "mywp_controller_initial_data_{$class::$id}" , array( $class , 'mywp_controller_initial_data' ) , 9 );
60
61 add_filter( "mywp_controller_default_data_{$class::$id}" , array( $class , 'mywp_controller_default_data' ) , 9 );
62
63 add_action( 'mywp_wp_loaded' , array( $class , 'mywp_wp_loaded' ) , 1000 );
64
65 static::after_init();
66
67 }
68
69 protected static function after_init() {}
70
71 public static function mywp_controllers( $controllers ) {
72
73 $controllers[ static::$id ] = array(
74 'model_use_filter' => static::$model_use_filter,
75 'network' => static::$network,
76 );
77
78 return $controllers;
79
80 }
81
82 public static function mywp_controller_initial_data( $initial_data ) {
83
84 return $initial_data;
85
86 }
87
88 public static function mywp_controller_default_data( $default_data ) {
89
90 return $default_data;
91
92 }
93
94 public static function get_model() {
95
96 $controller = MywpController::get_controller( static::$id );
97
98 if( empty( $controller['model'] ) ) {
99
100 $called_text = sprintf( '%s::%s()' , __CLASS__ , __FUNCTION__ );
101
102 MywpHelper::error_not_found_message( '$controller["model"]' , $called_text );
103
104 return false;
105
106 }
107
108 return $controller["model"];
109
110 }
111
112 public static function get_setting_data() {
113
114 $mywp_model = static::get_model();
115
116 if( empty( $mywp_model ) ) {
117
118 $called_text = sprintf( '%s::%s()' , __CLASS__ , __FUNCTION__ );
119
120 MywpHelper::error_not_found_message( '$mywp_model' , $called_text );
121
122 return false;
123
124 }
125
126 return $mywp_model->get_setting_data();
127
128 }
129
130 protected static function is_do_controller() {
131
132 if( !empty( static::$is_do_controller ) ) {
133
134 return true;
135
136 }
137
138 $class = get_called_class();
139
140 $is_do_controller = apply_filters( "mywp_controller_is_do_{$class::$id}" , true );
141 $is_do_controller = apply_filters( 'mywp_controller_is_do' , $is_do_controller , static::$id );
142
143 return $is_do_controller;
144
145 }
146
147 protected static function is_do_function( $function_name = false ) {
148
149 if( empty( $function_name ) ) {
150
151 return false;
152
153 }
154
155 $class = get_called_class();
156
157 $function_name = strip_tags( $function_name );
158
159 $is_do_function = apply_filters( "mywp_controller_is_do_function_{$class::$id}_{$function_name}" , true );
160
161 return $is_do_function;
162
163 }
164
165 protected static function after_do_function( $function_name = false ) {
166
167 if( empty( $function_name ) ) {
168
169 return false;
170
171 }
172
173 $class = get_called_class();
174
175 $function_name = strip_tags( $function_name );
176
177 do_action( "mywp_controller_after_do_{$class::$id}_{$function_name}" );
178
179 }
180
181 public static function mywp_wp_loaded() {}
182
183 }
184
185 endif;
186