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

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