PluginProbe
My WP Customize Admin/Frontend / 1.22.0
My WP Customize Admin/Frontend v1.22.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 / class.controller.php

class.controller.php in My WP Customize Admin/Frontend 1.22.0, at controller/class.controller.php

158 lines 4.0 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( 'MywpController' ) ) :
8
9 final class MywpController {
10
11 private static $controllers;
12
13 public static function get_controllers() {
14
15 if( self::$controllers ) {
16
17 return self::$controllers;
18
19 }
20
21 $pre_controllers = apply_filters( 'mywp_controllers' , array() );
22
23 if( empty( $pre_controllers ) ) {
24
25 return false;
26
27 }
28
29 $default = array(
30 'id' => '',
31 'initial_data' => array(),
32 'default_data' => array(),
33 'model' => '',
34 'network' => false,
35 );
36
37 $controllers = array();
38
39 foreach( $pre_controllers as $controller_id => $controller ) {
40
41 $controller = wp_parse_args( $controller , $default );
42
43 $controller['id'] = $controller_id;
44 $controller['initial_data'] = self::get_initial_data( $controller['initial_data'] , $controller_id );
45 $controller['default_data'] = self::get_default_data( $controller['default_data'] , $controller_id );
46 $controller['model'] = self::get_model( $controller , $controller_id );
47
48 $controllers[ $controller_id ] = $controller;
49
50 }
51
52 return $controllers;
53
54 }
55
56 public static function get_controller( $controller_id = false ) {
57
58 if( empty( $controller_id ) ) {
59
60 $called_text = sprintf( '%s::%s( %s )' , __CLASS__ , __FUNCTION__ , '$controller_id' );
61
62 MywpHelper::error_require_message( '$controller_id' , $called_text );
63
64 return false;
65
66 }
67
68 $controllers = self::get_controllers();
69
70 if( empty( $controllers[ $controller_id ] ) ) {
71
72 return false;
73
74 }
75
76 return $controllers[ $controller_id ];
77
78 }
79
80 public static function set_controllers() {
81
82 self::$controllers = self::get_controllers();
83
84 }
85
86 private static function get_initial_data( $initial_data , $controller_id ) {
87
88 $initial_data = apply_filters( "mywp_controller_initial_data_{$controller_id}" , $initial_data );
89 $initial_data = apply_filters( 'mywp_controller_initial_data' , $initial_data , $controller_id );
90
91 return $initial_data;
92
93 }
94
95 private static function get_default_data( $default_data , $controller_id ) {
96
97 $default_data = apply_filters( "mywp_controller_default_data_{$controller_id}" , $default_data );
98 $default_data = apply_filters( 'mywp_controller_default_data' , $default_data , $controller_id );
99
100 return $default_data;
101
102 }
103
104 private static function get_model( $controller , $controller_id ) {
105
106 do_action( 'mywp_controller_before_get_model' , $controller_id );
107
108 $pre_model = apply_filters( "mywp_controller_pre_get_model_{$controller_id}" , false , $controller );
109 $pre_model = apply_filters( 'mywp_controller_pre_get_model' , $pre_model , $controller_id , $controller );
110
111 if( $pre_model !== false ) {
112
113 return $pre_model;
114
115 }
116
117 $mywp_model = new MywpModel( $controller_id , 'controller' , $controller['network'] );
118
119 $mywp_model->set_initial_data( $controller['initial_data'] );
120 $mywp_model->set_default_data( $controller['default_data'] );
121
122 do_action( 'mywp_controller_after_get_model' , $controller_id );
123
124 return $mywp_model;
125
126 }
127
128 public static function get_posts( $args = array() , $controller_id = false ) {
129
130 do_action( 'mywp_controller_before_get_posts' , $args , $controller_id );
131
132 $args = apply_filters( "mywp_controller_pre_get_posts_args_{$controller_id}" , $args );
133 $args = apply_filters( 'mywp_controller_pre_get_posts_args' , $args , $controller_id );
134
135 $posts = apply_filters( "mywp_controller_pre_get_posts_{$controller_id}" , false , $args , $controller_id );
136 $posts = apply_filters( 'mywp_controller_pre_get_posts' , $posts , $args , $controller_id );
137
138 if( $posts !== false ) {
139
140 return $posts;
141
142 }
143
144 $posts = MywpPostType::get_posts( $args );
145
146 $posts = apply_filters( "mywp_controller_change_get_posts_{$controller_id}" , $posts , $args );
147 $posts = apply_filters( 'mywp_controller_change_get_posts' , $posts , $args , $controller_id );
148
149 do_action( 'mywp_controller_after_get_posts' , $posts , $args , $controller_id );
150
151 return $posts;
152
153 }
154
155 }
156
157 endif;
158