@@ -11,42 +11,42 @@ |
||
11 | 11 | class EE_Base |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @ override magic methods |
|
16 | - * @ return void |
|
17 | - */ |
|
18 | - public function __get($a) |
|
19 | - { |
|
20 | - return false; |
|
21 | - } |
|
14 | + /** |
|
15 | + * @ override magic methods |
|
16 | + * @ return void |
|
17 | + */ |
|
18 | + public function __get($a) |
|
19 | + { |
|
20 | + return false; |
|
21 | + } |
|
22 | 22 | |
23 | - public function __set($a, $b) |
|
24 | - { |
|
25 | - return false; |
|
26 | - } |
|
23 | + public function __set($a, $b) |
|
24 | + { |
|
25 | + return false; |
|
26 | + } |
|
27 | 27 | |
28 | - public function __isset($a) |
|
29 | - { |
|
30 | - return false; |
|
31 | - } |
|
28 | + public function __isset($a) |
|
29 | + { |
|
30 | + return false; |
|
31 | + } |
|
32 | 32 | |
33 | - public function __unset($a) |
|
34 | - { |
|
35 | - return false; |
|
36 | - } |
|
33 | + public function __unset($a) |
|
34 | + { |
|
35 | + return false; |
|
36 | + } |
|
37 | 37 | |
38 | - public function __clone() |
|
39 | - { |
|
40 | - return false; |
|
41 | - } |
|
38 | + public function __clone() |
|
39 | + { |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - public function __wakeup() |
|
44 | - { |
|
45 | - return false; |
|
46 | - } |
|
43 | + public function __wakeup() |
|
44 | + { |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | |
48 | - public function __destruct() |
|
49 | - { |
|
50 | - return false; |
|
51 | - } |
|
48 | + public function __destruct() |
|
49 | + { |
|
50 | + return false; |
|
51 | + } |
|
52 | 52 | } |
@@ -14,333 +14,333 @@ |
||
14 | 14 | class EE_Maintenance_Mode implements ResettableInterface |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
19 | - * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
20 | - */ |
|
21 | - const level_0_not_in_maintenance = 0; |
|
22 | - |
|
23 | - /** |
|
24 | - * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
25 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
26 | - */ |
|
27 | - const level_1_frontend_only_maintenance = 1; |
|
28 | - |
|
29 | - /** |
|
30 | - * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
31 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
32 | - * migration scripts before taking the site out of maintenance mode |
|
33 | - */ |
|
34 | - const level_2_complete_maintenance = 2; |
|
35 | - |
|
36 | - /** |
|
37 | - * the name of the option which stores the current level of maintenance mode |
|
38 | - */ |
|
39 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Maintenance_Mode $_instance |
|
44 | - */ |
|
45 | - private static $_instance; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Registry $EE |
|
49 | - */ |
|
50 | - protected $EE; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @singleton method used to instantiate class object |
|
55 | - * @return EE_Maintenance_Mode |
|
56 | - */ |
|
57 | - public static function instance() |
|
58 | - { |
|
59 | - // check if class object is instantiated |
|
60 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
61 | - self::$_instance = new self(); |
|
62 | - } |
|
63 | - return self::$_instance; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
69 | - * |
|
70 | - * @return EE_Maintenance_Mode |
|
71 | - */ |
|
72 | - public static function reset() |
|
73 | - { |
|
74 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
75 | - return self::instance(); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - *private constructor to prevent direct creation |
|
81 | - */ |
|
82 | - private function __construct() |
|
83 | - { |
|
84 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
85 | - add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
86 | - // shut 'er down down for maintenance ? |
|
87 | - add_filter('the_content', array($this, 'the_content'), 2); |
|
88 | - // add powered by EE msg |
|
89 | - add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * retrieves the maintenance mode option value from the db |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function real_level() |
|
99 | - { |
|
100 | - return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns whether or not the models reportedly are able to run queries or not |
|
106 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
107 | - * |
|
108 | - * @return boolean |
|
109 | - */ |
|
110 | - public function models_can_query() |
|
111 | - { |
|
112 | - return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
118 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
119 | - * to them as if teh site isn't in maintenance mode. |
|
120 | - * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
121 | - * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
122 | - * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
123 | - * |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - public function level() |
|
127 | - { |
|
128 | - $maintenance_mode_level = $this->real_level(); |
|
129 | - // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
130 | - if ($maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
131 | - && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
132 | - && current_user_can('administrator') // when the user is an admin |
|
133 | - ) { |
|
134 | - $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
135 | - } |
|
136 | - return $maintenance_mode_level; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
142 | - * |
|
143 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
144 | - */ |
|
145 | - public function set_maintenance_mode_if_db_old() |
|
146 | - { |
|
147 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
148 | - if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
149 | - update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
150 | - return true; |
|
151 | - } |
|
152 | - if ($this->level() === self::level_2_complete_maintenance) { |
|
153 | - // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
154 | - // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
155 | - update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
156 | - return false; |
|
157 | - } |
|
158 | - return false; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Updates the maintenance level on the site |
|
164 | - * |
|
165 | - * @param int $level |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function set_maintenance_level($level) |
|
169 | - { |
|
170 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
171 | - update_option(self::option_name_maintenance_mode, (int) $level); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public static function disable_frontend_for_maintenance() |
|
181 | - { |
|
182 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - public function load_assets_required_for_m_mode() |
|
190 | - { |
|
191 | - if ($this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
192 | - && ! wp_script_is('espresso_core') |
|
193 | - ) { |
|
194 | - wp_register_style( |
|
195 | - 'espresso_default', |
|
196 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
197 | - array('dashicons'), |
|
198 | - EVENT_ESPRESSO_VERSION |
|
199 | - ); |
|
200 | - wp_enqueue_style('espresso_default'); |
|
201 | - wp_register_script( |
|
202 | - 'espresso_core', |
|
203 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
204 | - array('jquery'), |
|
205 | - EVENT_ESPRESSO_VERSION, |
|
206 | - true |
|
207 | - ); |
|
208 | - wp_enqueue_script('espresso_core'); |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * replacement EE CPT template that displays message notifying site visitors |
|
215 | - * that EE has been temporarily placed into maintenance mode |
|
216 | - * does NOT get called on non-EE-CPT requests |
|
217 | - * |
|
218 | - * @return string |
|
219 | - */ |
|
220 | - public static function template_include() |
|
221 | - { |
|
222 | - // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
223 | - return get_template_directory() . '/index.php'; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * displays message notifying site visitors that EE has been temporarily |
|
229 | - * placed into maintenance mode when post_type != EE CPT |
|
230 | - * |
|
231 | - * @param string $the_content |
|
232 | - * @return string |
|
233 | - */ |
|
234 | - public function the_content($the_content) |
|
235 | - { |
|
236 | - // check if M-mode is engaged and for EE shortcode |
|
237 | - if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
238 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
239 | - $the_content = sprintf( |
|
240 | - esc_html__( |
|
241 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
242 | - 'event_espresso' |
|
243 | - ), |
|
244 | - '<h3>', |
|
245 | - '</h3><p>', |
|
246 | - '</p>' |
|
247 | - ); |
|
248 | - } |
|
249 | - return $the_content; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
255 | - */ |
|
256 | - public function display_maintenance_mode_notice() |
|
257 | - { |
|
258 | - // check if M-mode is engaged and for EE shortcode |
|
259 | - if (! (defined('DOING_AJAX') && DOING_AJAX) |
|
260 | - && $this->real_level() |
|
261 | - && ! is_admin() |
|
262 | - && current_user_can('administrator') |
|
263 | - && EE_Registry::instance()->REQ->is_espresso_page() |
|
264 | - ) { |
|
265 | - printf( |
|
266 | - esc_html__( |
|
267 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
268 | - 'event_espresso' |
|
269 | - ), |
|
270 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
271 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
272 | - ' » <a href="' . add_query_arg( |
|
273 | - array('page' => 'espresso_maintenance_settings'), |
|
274 | - admin_url('admin.php') |
|
275 | - ) . '">', |
|
276 | - '</a></p></div>' |
|
277 | - ); |
|
278 | - } |
|
279 | - } |
|
280 | - // espresso-notices important-notice ee-attention |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * override magic methods |
|
285 | - */ |
|
286 | - final public function __destruct() |
|
287 | - { |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - final public function __call($a, $b) |
|
292 | - { |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - final public function __get($a) |
|
297 | - { |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - final public function __set($a, $b) |
|
302 | - { |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - final public function __isset($a) |
|
307 | - { |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - final public function __unset($a) |
|
312 | - { |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - final public function __sleep() |
|
317 | - { |
|
318 | - return array(); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - final public function __wakeup() |
|
323 | - { |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - final public function __invoke() |
|
328 | - { |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - final public static function __set_state($a = null) |
|
333 | - { |
|
334 | - return EE_Maintenance_Mode::instance(); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - final public function __clone() |
|
339 | - { |
|
340 | - } |
|
17 | + /** |
|
18 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
19 | + * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
20 | + */ |
|
21 | + const level_0_not_in_maintenance = 0; |
|
22 | + |
|
23 | + /** |
|
24 | + * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
25 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
26 | + */ |
|
27 | + const level_1_frontend_only_maintenance = 1; |
|
28 | + |
|
29 | + /** |
|
30 | + * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
31 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
32 | + * migration scripts before taking the site out of maintenance mode |
|
33 | + */ |
|
34 | + const level_2_complete_maintenance = 2; |
|
35 | + |
|
36 | + /** |
|
37 | + * the name of the option which stores the current level of maintenance mode |
|
38 | + */ |
|
39 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Maintenance_Mode $_instance |
|
44 | + */ |
|
45 | + private static $_instance; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Registry $EE |
|
49 | + */ |
|
50 | + protected $EE; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @singleton method used to instantiate class object |
|
55 | + * @return EE_Maintenance_Mode |
|
56 | + */ |
|
57 | + public static function instance() |
|
58 | + { |
|
59 | + // check if class object is instantiated |
|
60 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
61 | + self::$_instance = new self(); |
|
62 | + } |
|
63 | + return self::$_instance; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
69 | + * |
|
70 | + * @return EE_Maintenance_Mode |
|
71 | + */ |
|
72 | + public static function reset() |
|
73 | + { |
|
74 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
75 | + return self::instance(); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + *private constructor to prevent direct creation |
|
81 | + */ |
|
82 | + private function __construct() |
|
83 | + { |
|
84 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
85 | + add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
86 | + // shut 'er down down for maintenance ? |
|
87 | + add_filter('the_content', array($this, 'the_content'), 2); |
|
88 | + // add powered by EE msg |
|
89 | + add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * retrieves the maintenance mode option value from the db |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function real_level() |
|
99 | + { |
|
100 | + return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns whether or not the models reportedly are able to run queries or not |
|
106 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
107 | + * |
|
108 | + * @return boolean |
|
109 | + */ |
|
110 | + public function models_can_query() |
|
111 | + { |
|
112 | + return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
118 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
119 | + * to them as if teh site isn't in maintenance mode. |
|
120 | + * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
121 | + * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
122 | + * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
123 | + * |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + public function level() |
|
127 | + { |
|
128 | + $maintenance_mode_level = $this->real_level(); |
|
129 | + // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
130 | + if ($maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
131 | + && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
132 | + && current_user_can('administrator') // when the user is an admin |
|
133 | + ) { |
|
134 | + $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
135 | + } |
|
136 | + return $maintenance_mode_level; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
142 | + * |
|
143 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
144 | + */ |
|
145 | + public function set_maintenance_mode_if_db_old() |
|
146 | + { |
|
147 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
148 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
149 | + update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
150 | + return true; |
|
151 | + } |
|
152 | + if ($this->level() === self::level_2_complete_maintenance) { |
|
153 | + // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
154 | + // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
155 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
156 | + return false; |
|
157 | + } |
|
158 | + return false; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Updates the maintenance level on the site |
|
164 | + * |
|
165 | + * @param int $level |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function set_maintenance_level($level) |
|
169 | + { |
|
170 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
171 | + update_option(self::option_name_maintenance_mode, (int) $level); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public static function disable_frontend_for_maintenance() |
|
181 | + { |
|
182 | + return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + public function load_assets_required_for_m_mode() |
|
190 | + { |
|
191 | + if ($this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
192 | + && ! wp_script_is('espresso_core') |
|
193 | + ) { |
|
194 | + wp_register_style( |
|
195 | + 'espresso_default', |
|
196 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
197 | + array('dashicons'), |
|
198 | + EVENT_ESPRESSO_VERSION |
|
199 | + ); |
|
200 | + wp_enqueue_style('espresso_default'); |
|
201 | + wp_register_script( |
|
202 | + 'espresso_core', |
|
203 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
204 | + array('jquery'), |
|
205 | + EVENT_ESPRESSO_VERSION, |
|
206 | + true |
|
207 | + ); |
|
208 | + wp_enqueue_script('espresso_core'); |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * replacement EE CPT template that displays message notifying site visitors |
|
215 | + * that EE has been temporarily placed into maintenance mode |
|
216 | + * does NOT get called on non-EE-CPT requests |
|
217 | + * |
|
218 | + * @return string |
|
219 | + */ |
|
220 | + public static function template_include() |
|
221 | + { |
|
222 | + // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
223 | + return get_template_directory() . '/index.php'; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * displays message notifying site visitors that EE has been temporarily |
|
229 | + * placed into maintenance mode when post_type != EE CPT |
|
230 | + * |
|
231 | + * @param string $the_content |
|
232 | + * @return string |
|
233 | + */ |
|
234 | + public function the_content($the_content) |
|
235 | + { |
|
236 | + // check if M-mode is engaged and for EE shortcode |
|
237 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
238 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
239 | + $the_content = sprintf( |
|
240 | + esc_html__( |
|
241 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
242 | + 'event_espresso' |
|
243 | + ), |
|
244 | + '<h3>', |
|
245 | + '</h3><p>', |
|
246 | + '</p>' |
|
247 | + ); |
|
248 | + } |
|
249 | + return $the_content; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
255 | + */ |
|
256 | + public function display_maintenance_mode_notice() |
|
257 | + { |
|
258 | + // check if M-mode is engaged and for EE shortcode |
|
259 | + if (! (defined('DOING_AJAX') && DOING_AJAX) |
|
260 | + && $this->real_level() |
|
261 | + && ! is_admin() |
|
262 | + && current_user_can('administrator') |
|
263 | + && EE_Registry::instance()->REQ->is_espresso_page() |
|
264 | + ) { |
|
265 | + printf( |
|
266 | + esc_html__( |
|
267 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
268 | + 'event_espresso' |
|
269 | + ), |
|
270 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
271 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
272 | + ' » <a href="' . add_query_arg( |
|
273 | + array('page' => 'espresso_maintenance_settings'), |
|
274 | + admin_url('admin.php') |
|
275 | + ) . '">', |
|
276 | + '</a></p></div>' |
|
277 | + ); |
|
278 | + } |
|
279 | + } |
|
280 | + // espresso-notices important-notice ee-attention |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * override magic methods |
|
285 | + */ |
|
286 | + final public function __destruct() |
|
287 | + { |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + final public function __call($a, $b) |
|
292 | + { |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + final public function __get($a) |
|
297 | + { |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + final public function __set($a, $b) |
|
302 | + { |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + final public function __isset($a) |
|
307 | + { |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + final public function __unset($a) |
|
312 | + { |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + final public function __sleep() |
|
317 | + { |
|
318 | + return array(); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + final public function __wakeup() |
|
323 | + { |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + final public function __invoke() |
|
328 | + { |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + final public static function __set_state($a = null) |
|
333 | + { |
|
334 | + return EE_Maintenance_Mode::instance(); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + final public function __clone() |
|
339 | + { |
|
340 | + } |
|
341 | 341 | |
342 | 342 | |
343 | - final public static function __callStatic($a, $b) |
|
344 | - { |
|
345 | - } |
|
343 | + final public static function __callStatic($a, $b) |
|
344 | + { |
|
345 | + } |
|
346 | 346 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | public static function instance() |
58 | 58 | { |
59 | 59 | // check if class object is instantiated |
60 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
60 | + if ( ! self::$_instance instanceof EE_Maintenance_Mode) { |
|
61 | 61 | self::$_instance = new self(); |
62 | 62 | } |
63 | 63 | return self::$_instance; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public static function disable_frontend_for_maintenance() |
181 | 181 | { |
182 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
182 | + return ( ! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | ) { |
194 | 194 | wp_register_style( |
195 | 195 | 'espresso_default', |
196 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
196 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
197 | 197 | array('dashicons'), |
198 | 198 | EVENT_ESPRESSO_VERSION |
199 | 199 | ); |
200 | 200 | wp_enqueue_style('espresso_default'); |
201 | 201 | wp_register_script( |
202 | 202 | 'espresso_core', |
203 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
203 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
204 | 204 | array('jquery'), |
205 | 205 | EVENT_ESPRESSO_VERSION, |
206 | 206 | true |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | public static function template_include() |
221 | 221 | { |
222 | 222 | // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
223 | - return get_template_directory() . '/index.php'; |
|
223 | + return get_template_directory().'/index.php'; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | public function display_maintenance_mode_notice() |
257 | 257 | { |
258 | 258 | // check if M-mode is engaged and for EE shortcode |
259 | - if (! (defined('DOING_AJAX') && DOING_AJAX) |
|
259 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) |
|
260 | 260 | && $this->real_level() |
261 | 261 | && ! is_admin() |
262 | 262 | && current_user_can('administrator') |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | ), |
270 | 270 | '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
271 | 271 | '"><span class="dashicons dashicons-no"></span></a><p>', |
272 | - ' » <a href="' . add_query_arg( |
|
272 | + ' » <a href="'.add_query_arg( |
|
273 | 273 | array('page' => 'espresso_maintenance_settings'), |
274 | 274 | admin_url('admin.php') |
275 | - ) . '">', |
|
275 | + ).'">', |
|
276 | 276 | '</a></p></div>' |
277 | 277 | ); |
278 | 278 | } |
@@ -27,474 +27,474 @@ discard block |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * This gets set in _setup_cpt |
|
32 | - * It will contain the object for the custom post type. |
|
33 | - * |
|
34 | - * @var EE_CPT_Base |
|
35 | - */ |
|
36 | - protected $_cpt_object; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * a boolean flag to set whether the current route is a cpt route or not. |
|
41 | - * |
|
42 | - * @var bool |
|
43 | - */ |
|
44 | - protected $_cpt_route = false; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This property allows cpt classes to define multiple routes as cpt routes. |
|
49 | - * //in this array we define what the custom post type for this route is. |
|
50 | - * array( |
|
51 | - * 'route_name' => 'custom_post_type_slug' |
|
52 | - * ) |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - protected $_cpt_routes = array(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
61 | - * in this format: |
|
62 | - * array( |
|
63 | - * 'post_type_slug' => 'edit_route' |
|
64 | - * ) |
|
65 | - * |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - protected $_cpt_edit_routes = array(); |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
73 | - * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
74 | - * _cpt_model_names property should be in the following format: array( |
|
75 | - * 'route_defined_by_action_param' => 'Model_Name') |
|
76 | - * |
|
77 | - * @var array $_cpt_model_names |
|
78 | - */ |
|
79 | - protected $_cpt_model_names = array(); |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @var EE_CPT_Base |
|
84 | - */ |
|
85 | - protected $_cpt_model_obj = false; |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
90 | - * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
91 | - * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
92 | - * Registration of containers should be done before load_page_dependencies() is run. |
|
93 | - * |
|
94 | - * @var array() |
|
95 | - */ |
|
96 | - protected $_autosave_containers = array(); |
|
97 | - protected $_autosave_fields = array(); |
|
98 | - |
|
99 | - /** |
|
100 | - * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
101 | - * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
102 | - * |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - protected $_pagenow_map; |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
110 | - * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
111 | - * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
112 | - * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
113 | - * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
114 | - * |
|
115 | - * @access protected |
|
116 | - * @abstract |
|
117 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
118 | - * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
119 | - * @return void |
|
120 | - */ |
|
121 | - abstract protected function _insert_update_cpt_item($post_id, $post); |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
126 | - * |
|
127 | - * @abstract |
|
128 | - * @access public |
|
129 | - * @param string $post_id The ID of the cpt that was trashed |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - abstract public function trash_cpt_item($post_id); |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
137 | - * |
|
138 | - * @param string $post_id theID of the cpt that was untrashed |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - abstract public function restore_cpt_item($post_id); |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
146 | - * from the db |
|
147 | - * |
|
148 | - * @param string $post_id the ID of the cpt that was deleted |
|
149 | - * @return void |
|
150 | - */ |
|
151 | - abstract public function delete_cpt_item($post_id); |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
156 | - * |
|
157 | - * @access protected |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - protected function _before_page_setup() |
|
161 | - { |
|
162 | - $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
163 | - $this->_cpt_routes = array_merge( |
|
164 | - array( |
|
165 | - 'create_new' => $this->page_slug, |
|
166 | - 'edit' => $this->page_slug, |
|
167 | - 'trash' => $this->page_slug, |
|
168 | - ), |
|
169 | - $this->_cpt_routes |
|
170 | - ); |
|
171 | - // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
172 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
173 | - ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
174 | - : get_post_type_object($page); |
|
175 | - // tweak pagenow for page loading. |
|
176 | - if (! $this->_pagenow_map) { |
|
177 | - $this->_pagenow_map = array( |
|
178 | - 'create_new' => 'post-new.php', |
|
179 | - 'edit' => 'post.php', |
|
180 | - 'trash' => 'post.php', |
|
181 | - ); |
|
182 | - } |
|
183 | - add_action('current_screen', array($this, 'modify_pagenow')); |
|
184 | - // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
185 | - // get current page from autosave |
|
186 | - $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
187 | - ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
188 | - : null; |
|
189 | - $this->_current_page = isset($this->_req_data['current_page']) |
|
190 | - ? $this->_req_data['current_page'] |
|
191 | - : $current_page; |
|
192 | - // autosave... make sure its only for the correct page |
|
193 | - // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
194 | - // setup autosave ajax hook |
|
195 | - // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
196 | - // } |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Simply ensure that we simulate the correct post route for cpt screens |
|
202 | - * |
|
203 | - * @param WP_Screen $current_screen |
|
204 | - * @return void |
|
205 | - */ |
|
206 | - public function modify_pagenow($current_screen) |
|
207 | - { |
|
208 | - global $pagenow, $hook_suffix; |
|
209 | - // possibly reset pagenow. |
|
210 | - if (! empty($this->_req_data['page']) |
|
211 | - && $this->_req_data['page'] == $this->page_slug |
|
212 | - && ! empty($this->_req_data['action']) |
|
213 | - && isset($this->_pagenow_map[ $this->_req_data['action'] ]) |
|
214 | - ) { |
|
215 | - $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ]; |
|
216 | - $hook_suffix = $pagenow; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * This method is used to register additional autosave containers to the _autosave_containers property. |
|
223 | - * |
|
224 | - * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
225 | - * automatically register the id for the post metabox as a container. |
|
226 | - * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
227 | - * you would send along the id of a metabox container. |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - protected function _register_autosave_containers($ids) |
|
231 | - { |
|
232 | - $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
238 | - * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
239 | - */ |
|
240 | - protected function _set_autosave_containers() |
|
241 | - { |
|
242 | - global $wp_meta_boxes; |
|
243 | - $containers = array(); |
|
244 | - if (empty($wp_meta_boxes)) { |
|
245 | - return; |
|
246 | - } |
|
247 | - $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array(); |
|
248 | - foreach ($current_metaboxes as $box_context) { |
|
249 | - foreach ($box_context as $box_details) { |
|
250 | - foreach ($box_details as $box) { |
|
251 | - if (is_array($box['callback']) |
|
252 | - && ( |
|
253 | - $box['callback'][0] instanceof EE_Admin_Page |
|
254 | - || $box['callback'][0] instanceof EE_Admin_Hooks |
|
255 | - ) |
|
256 | - ) { |
|
257 | - $containers[] = $box['id']; |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
263 | - // add hidden inputs container |
|
264 | - $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - protected function _load_autosave_scripts_styles() |
|
269 | - { |
|
270 | - /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
30 | + /** |
|
31 | + * This gets set in _setup_cpt |
|
32 | + * It will contain the object for the custom post type. |
|
33 | + * |
|
34 | + * @var EE_CPT_Base |
|
35 | + */ |
|
36 | + protected $_cpt_object; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * a boolean flag to set whether the current route is a cpt route or not. |
|
41 | + * |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | + protected $_cpt_route = false; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This property allows cpt classes to define multiple routes as cpt routes. |
|
49 | + * //in this array we define what the custom post type for this route is. |
|
50 | + * array( |
|
51 | + * 'route_name' => 'custom_post_type_slug' |
|
52 | + * ) |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + protected $_cpt_routes = array(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * This simply defines what the corresponding routes WP will be redirected to after completing a post save/update. |
|
61 | + * in this format: |
|
62 | + * array( |
|
63 | + * 'post_type_slug' => 'edit_route' |
|
64 | + * ) |
|
65 | + * |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + protected $_cpt_edit_routes = array(); |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * If child classes set the name of their main model via the $_cpt_obj_models property, EE_Admin_Page_CPT will |
|
73 | + * attempt to retrieve the related object model for the edit pages and assign it to _cpt_page_object. the |
|
74 | + * _cpt_model_names property should be in the following format: array( |
|
75 | + * 'route_defined_by_action_param' => 'Model_Name') |
|
76 | + * |
|
77 | + * @var array $_cpt_model_names |
|
78 | + */ |
|
79 | + protected $_cpt_model_names = array(); |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @var EE_CPT_Base |
|
84 | + */ |
|
85 | + protected $_cpt_model_obj = false; |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * This will hold an array of autosave containers that will be used to obtain input values and hook into the WP |
|
90 | + * autosave so we can save our inputs on the save_post hook! Children classes should add to this array by using |
|
91 | + * the _register_autosave_containers() method so that we don't override any other containers already registered. |
|
92 | + * Registration of containers should be done before load_page_dependencies() is run. |
|
93 | + * |
|
94 | + * @var array() |
|
95 | + */ |
|
96 | + protected $_autosave_containers = array(); |
|
97 | + protected $_autosave_fields = array(); |
|
98 | + |
|
99 | + /** |
|
100 | + * Array mapping from admin actions to their equivalent wp core pages for custom post types. So when a user visits |
|
101 | + * a page for an action, it will appear as if they were visiting the wp core page for that custom post type |
|
102 | + * |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + protected $_pagenow_map; |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
110 | + * saved. Child classes are required to declare this method. Typically you would use this to save any additional |
|
111 | + * data. Keep in mind also that "save_post" runs on EVERY post update to the database. ALSO very important. When a |
|
112 | + * post transitions from scheduled to published, the save_post action is fired but you will NOT have any _POST data |
|
113 | + * containing any extra info you may have from other meta saves. So MAKE sure that you handle this accordingly. |
|
114 | + * |
|
115 | + * @access protected |
|
116 | + * @abstract |
|
117 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
118 | + * @param EE_CPT_Base $post The post object of the cpt that was saved. |
|
119 | + * @return void |
|
120 | + */ |
|
121 | + abstract protected function _insert_update_cpt_item($post_id, $post); |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This is hooked into the WordPress do_action('trashed_post') hook and runs after a cpt has been trashed. |
|
126 | + * |
|
127 | + * @abstract |
|
128 | + * @access public |
|
129 | + * @param string $post_id The ID of the cpt that was trashed |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + abstract public function trash_cpt_item($post_id); |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * This is hooked into the WordPress do_action('untrashed_post') hook and runs after a cpt has been untrashed |
|
137 | + * |
|
138 | + * @param string $post_id theID of the cpt that was untrashed |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + abstract public function restore_cpt_item($post_id); |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * This is hooked into the WordPress do_action('delete_cpt_item') hook and runs after a cpt has been fully deleted |
|
146 | + * from the db |
|
147 | + * |
|
148 | + * @param string $post_id the ID of the cpt that was deleted |
|
149 | + * @return void |
|
150 | + */ |
|
151 | + abstract public function delete_cpt_item($post_id); |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Just utilizing the method EE_Admin exposes for doing things before page setup. |
|
156 | + * |
|
157 | + * @access protected |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + protected function _before_page_setup() |
|
161 | + { |
|
162 | + $page = isset($this->_req_data['page']) ? $this->_req_data['page'] : $this->page_slug; |
|
163 | + $this->_cpt_routes = array_merge( |
|
164 | + array( |
|
165 | + 'create_new' => $this->page_slug, |
|
166 | + 'edit' => $this->page_slug, |
|
167 | + 'trash' => $this->page_slug, |
|
168 | + ), |
|
169 | + $this->_cpt_routes |
|
170 | + ); |
|
171 | + // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
|
172 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
173 | + ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
174 | + : get_post_type_object($page); |
|
175 | + // tweak pagenow for page loading. |
|
176 | + if (! $this->_pagenow_map) { |
|
177 | + $this->_pagenow_map = array( |
|
178 | + 'create_new' => 'post-new.php', |
|
179 | + 'edit' => 'post.php', |
|
180 | + 'trash' => 'post.php', |
|
181 | + ); |
|
182 | + } |
|
183 | + add_action('current_screen', array($this, 'modify_pagenow')); |
|
184 | + // TODO the below will need to be reworked to account for the cpt routes that are NOT based off of page but action param. |
|
185 | + // get current page from autosave |
|
186 | + $current_page = isset($this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page']) |
|
187 | + ? $this->_req_data['ee_autosave_data']['ee-cpt-hidden-inputs']['current_page'] |
|
188 | + : null; |
|
189 | + $this->_current_page = isset($this->_req_data['current_page']) |
|
190 | + ? $this->_req_data['current_page'] |
|
191 | + : $current_page; |
|
192 | + // autosave... make sure its only for the correct page |
|
193 | + // if ( ! empty($this->_current_page) && $this->_current_page == $this->page_slug) { |
|
194 | + // setup autosave ajax hook |
|
195 | + // add_action('wp_ajax_ee-autosave', array( $this, 'do_extra_autosave_stuff' ), 10 ); //TODO reactivate when 4.2 autosave is implemented |
|
196 | + // } |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Simply ensure that we simulate the correct post route for cpt screens |
|
202 | + * |
|
203 | + * @param WP_Screen $current_screen |
|
204 | + * @return void |
|
205 | + */ |
|
206 | + public function modify_pagenow($current_screen) |
|
207 | + { |
|
208 | + global $pagenow, $hook_suffix; |
|
209 | + // possibly reset pagenow. |
|
210 | + if (! empty($this->_req_data['page']) |
|
211 | + && $this->_req_data['page'] == $this->page_slug |
|
212 | + && ! empty($this->_req_data['action']) |
|
213 | + && isset($this->_pagenow_map[ $this->_req_data['action'] ]) |
|
214 | + ) { |
|
215 | + $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ]; |
|
216 | + $hook_suffix = $pagenow; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * This method is used to register additional autosave containers to the _autosave_containers property. |
|
223 | + * |
|
224 | + * @todo We should automate this at some point by creating a wrapper for add_post_metabox and in our wrapper we |
|
225 | + * automatically register the id for the post metabox as a container. |
|
226 | + * @param array $ids an array of ids for containers that hold form inputs we want autosave to pickup. Typically |
|
227 | + * you would send along the id of a metabox container. |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + protected function _register_autosave_containers($ids) |
|
231 | + { |
|
232 | + $this->_autosave_containers = array_merge($this->_autosave_fields, (array) $ids); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Something nifty. We're going to loop through all the registered metaboxes and if the CALLBACK is an instance of |
|
238 | + * EE_Admin_Page OR EE_Admin_Hooks, then we'll add the id to our _autosave_containers array. |
|
239 | + */ |
|
240 | + protected function _set_autosave_containers() |
|
241 | + { |
|
242 | + global $wp_meta_boxes; |
|
243 | + $containers = array(); |
|
244 | + if (empty($wp_meta_boxes)) { |
|
245 | + return; |
|
246 | + } |
|
247 | + $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array(); |
|
248 | + foreach ($current_metaboxes as $box_context) { |
|
249 | + foreach ($box_context as $box_details) { |
|
250 | + foreach ($box_details as $box) { |
|
251 | + if (is_array($box['callback']) |
|
252 | + && ( |
|
253 | + $box['callback'][0] instanceof EE_Admin_Page |
|
254 | + || $box['callback'][0] instanceof EE_Admin_Hooks |
|
255 | + ) |
|
256 | + ) { |
|
257 | + $containers[] = $box['id']; |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + $this->_autosave_containers = array_merge($this->_autosave_containers, $containers); |
|
263 | + // add hidden inputs container |
|
264 | + $this->_autosave_containers[] = 'ee-cpt-hidden-inputs'; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + protected function _load_autosave_scripts_styles() |
|
269 | + { |
|
270 | + /*wp_register_script('cpt-autosave', EE_ADMIN_URL . 'assets/ee-cpt-autosave.js', array('ee-serialize-full-array', 'event_editor_js'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
271 | 271 | wp_enqueue_script('cpt-autosave');/**/ // todo re-enable when we start doing autosave again in 4.2 |
272 | 272 | |
273 | - // filter _autosave_containers |
|
274 | - $containers = apply_filters( |
|
275 | - 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
276 | - $this->_autosave_containers, |
|
277 | - $this |
|
278 | - ); |
|
279 | - $containers = apply_filters( |
|
280 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
281 | - $containers, |
|
282 | - $this |
|
283 | - ); |
|
284 | - |
|
285 | - wp_localize_script( |
|
286 | - 'event_editor_js', |
|
287 | - 'EE_AUTOSAVE_IDS', |
|
288 | - $containers |
|
289 | - ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
290 | - |
|
291 | - $unsaved_data_msg = array( |
|
292 | - 'eventmsg' => sprintf( |
|
293 | - __( |
|
294 | - "The changes you made to this %s will be lost if you navigate away from this page.", |
|
295 | - 'event_espresso' |
|
296 | - ), |
|
297 | - $this->_cpt_object->labels->singular_name |
|
298 | - ), |
|
299 | - 'inputChanged' => 0, |
|
300 | - ); |
|
301 | - wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - public function load_page_dependencies() |
|
306 | - { |
|
307 | - try { |
|
308 | - $this->_load_page_dependencies(); |
|
309 | - } catch (EE_Error $e) { |
|
310 | - $e->get_error(); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
317 | - * |
|
318 | - * @access protected |
|
319 | - * @return void |
|
320 | - */ |
|
321 | - protected function _load_page_dependencies() |
|
322 | - { |
|
323 | - // we only add stuff if this is a cpt_route! |
|
324 | - if (! $this->_cpt_route) { |
|
325 | - parent::_load_page_dependencies(); |
|
326 | - return; |
|
327 | - } |
|
328 | - // now let's do some automatic filters into the wp_system |
|
329 | - // and we'll check to make sure the CHILD class |
|
330 | - // automatically has the required methods in place. |
|
331 | - // the following filters are for setting all the redirects |
|
332 | - // on DEFAULT WP custom post type actions |
|
333 | - // let's add a hidden input to the post-edit form |
|
334 | - // so we know when we have to trigger our custom redirects! |
|
335 | - // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
336 | - add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
337 | - // inject our Admin page nav tabs... |
|
338 | - // let's make sure the nav tabs are set if they aren't already |
|
339 | - // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
340 | - add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
341 | - // modify the post_updated messages array |
|
342 | - add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
343 | - // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
344 | - // cpts use the same format for shortlinks as posts! |
|
345 | - add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
346 | - // This basically allows us to change the title of the "publish" metabox area |
|
347 | - // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
348 | - if (! empty($this->_labels['publishbox'])) { |
|
349 | - $box_label = is_array($this->_labels['publishbox']) |
|
350 | - && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
351 | - ? $this->_labels['publishbox'][ $this->_req_action ] |
|
352 | - : $this->_labels['publishbox']; |
|
353 | - add_meta_box( |
|
354 | - 'submitdiv', |
|
355 | - $box_label, |
|
356 | - 'post_submit_meta_box', |
|
357 | - $this->_cpt_routes[ $this->_req_action ], |
|
358 | - 'side', |
|
359 | - 'core' |
|
360 | - ); |
|
361 | - } |
|
362 | - // let's add page_templates metabox if this cpt added support for it. |
|
363 | - if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
364 | - add_meta_box( |
|
365 | - 'page_templates', |
|
366 | - __('Page Template', 'event_espresso'), |
|
367 | - array($this, 'page_template_meta_box'), |
|
368 | - $this->_cpt_routes[ $this->_req_action ], |
|
369 | - 'side', |
|
370 | - 'default' |
|
371 | - ); |
|
372 | - } |
|
373 | - // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
374 | - if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
375 | - add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
376 | - } |
|
377 | - // add preview button |
|
378 | - add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
379 | - // insert our own post_stati dropdown |
|
380 | - add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
381 | - // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
382 | - if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
383 | - add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
384 | - } |
|
385 | - // This allows for adding additional stuff after the title field on the wp post edit form. |
|
386 | - // This is also before the wp_editor for post description field. |
|
387 | - if (method_exists($this, 'edit_form_after_title')) { |
|
388 | - add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
389 | - } |
|
390 | - /** |
|
391 | - * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
392 | - */ |
|
393 | - add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
394 | - parent::_load_page_dependencies(); |
|
395 | - // notice we are ALSO going to load the pagenow hook set for this route |
|
396 | - // (see _before_page_setup for the reset of the pagenow global ). |
|
397 | - // This is for any plugins that are doing things properly |
|
398 | - // and hooking into the load page hook for core wp cpt routes. |
|
399 | - global $pagenow; |
|
400 | - do_action('load-' . $pagenow); |
|
401 | - $this->modify_current_screen(); |
|
402 | - add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
403 | - // we route REALLY early. |
|
404 | - try { |
|
405 | - $this->_route_admin_request(); |
|
406 | - } catch (EE_Error $e) { |
|
407 | - $e->get_error(); |
|
408 | - } |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
414 | - * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
415 | - * route instead. |
|
416 | - * |
|
417 | - * @param string $good_protocol_url The escaped url. |
|
418 | - * @param string $original_url The original url. |
|
419 | - * @param string $_context The context sent to the esc_url method. |
|
420 | - * @return string possibly a new url for our route. |
|
421 | - */ |
|
422 | - public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
423 | - { |
|
424 | - $routes_to_match = array( |
|
425 | - 0 => array( |
|
426 | - 'edit.php?post_type=espresso_attendees', |
|
427 | - 'admin.php?page=espresso_registrations&action=contact_list', |
|
428 | - ), |
|
429 | - 1 => array( |
|
430 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | - ), |
|
433 | - ); |
|
434 | - foreach ($routes_to_match as $route_matches) { |
|
435 | - if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
436 | - return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
437 | - } |
|
438 | - } |
|
439 | - return $good_protocol_url; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * Determine whether the current cpt supports page templates or not. |
|
445 | - * |
|
446 | - * @since %VER% |
|
447 | - * @param string $cpt_name The cpt slug we're checking on. |
|
448 | - * @return bool True supported, false not. |
|
449 | - * @throws InvalidArgumentException |
|
450 | - * @throws InvalidDataTypeException |
|
451 | - * @throws InvalidInterfaceException |
|
452 | - */ |
|
453 | - private function _supports_page_templates($cpt_name) |
|
454 | - { |
|
455 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
456 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
457 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
458 | - ); |
|
459 | - $cpt_args = $custom_post_types->getDefinitions(); |
|
460 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array(); |
|
461 | - $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
462 | - |
|
463 | - // if the installed version of WP is > 4.7 we do some additional checks. |
|
464 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
465 | - $post_templates = wp_get_theme()->get_post_templates(); |
|
466 | - // if there are $post_templates for this cpt, then we return false for this method because |
|
467 | - // that means we aren't going to load our page template manager and leave that up to the native |
|
468 | - // cpt template manager. |
|
469 | - $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
470 | - } |
|
471 | - |
|
472 | - return $cpt_has_support; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Callback for the page_templates metabox selector. |
|
478 | - * |
|
479 | - * @since %VER% |
|
480 | - * @return void |
|
481 | - */ |
|
482 | - public function page_template_meta_box() |
|
483 | - { |
|
484 | - global $post; |
|
485 | - $template = ''; |
|
486 | - |
|
487 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
488 | - $page_template_count = count(get_page_templates()); |
|
489 | - } else { |
|
490 | - $page_template_count = count(get_page_templates($post)); |
|
491 | - }; |
|
492 | - |
|
493 | - if ($page_template_count) { |
|
494 | - $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
495 | - $template = ! empty($page_template) ? $page_template : ''; |
|
496 | - } |
|
497 | - ?> |
|
273 | + // filter _autosave_containers |
|
274 | + $containers = apply_filters( |
|
275 | + 'FHEE__EE_Admin_Page_CPT___load_autosave_scripts_styles__containers', |
|
276 | + $this->_autosave_containers, |
|
277 | + $this |
|
278 | + ); |
|
279 | + $containers = apply_filters( |
|
280 | + 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
281 | + $containers, |
|
282 | + $this |
|
283 | + ); |
|
284 | + |
|
285 | + wp_localize_script( |
|
286 | + 'event_editor_js', |
|
287 | + 'EE_AUTOSAVE_IDS', |
|
288 | + $containers |
|
289 | + ); // todo once we enable autosaves, this needs to be switched to localize with "cpt-autosave" |
|
290 | + |
|
291 | + $unsaved_data_msg = array( |
|
292 | + 'eventmsg' => sprintf( |
|
293 | + __( |
|
294 | + "The changes you made to this %s will be lost if you navigate away from this page.", |
|
295 | + 'event_espresso' |
|
296 | + ), |
|
297 | + $this->_cpt_object->labels->singular_name |
|
298 | + ), |
|
299 | + 'inputChanged' => 0, |
|
300 | + ); |
|
301 | + wp_localize_script('event_editor_js', 'UNSAVED_DATA_MSG', $unsaved_data_msg); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + public function load_page_dependencies() |
|
306 | + { |
|
307 | + try { |
|
308 | + $this->_load_page_dependencies(); |
|
309 | + } catch (EE_Error $e) { |
|
310 | + $e->get_error(); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * overloading the EE_Admin_Page parent load_page_dependencies so we can get the cpt stuff added in appropriately |
|
317 | + * |
|
318 | + * @access protected |
|
319 | + * @return void |
|
320 | + */ |
|
321 | + protected function _load_page_dependencies() |
|
322 | + { |
|
323 | + // we only add stuff if this is a cpt_route! |
|
324 | + if (! $this->_cpt_route) { |
|
325 | + parent::_load_page_dependencies(); |
|
326 | + return; |
|
327 | + } |
|
328 | + // now let's do some automatic filters into the wp_system |
|
329 | + // and we'll check to make sure the CHILD class |
|
330 | + // automatically has the required methods in place. |
|
331 | + // the following filters are for setting all the redirects |
|
332 | + // on DEFAULT WP custom post type actions |
|
333 | + // let's add a hidden input to the post-edit form |
|
334 | + // so we know when we have to trigger our custom redirects! |
|
335 | + // Otherwise the redirects will happen on ALL post saves which wouldn't be good of course! |
|
336 | + add_action('edit_form_after_title', array($this, 'cpt_post_form_hidden_input')); |
|
337 | + // inject our Admin page nav tabs... |
|
338 | + // let's make sure the nav tabs are set if they aren't already |
|
339 | + // if ( empty( $this->_nav_tabs ) ) $this->_set_nav_tabs(); |
|
340 | + add_action('post_edit_form_tag', array($this, 'inject_nav_tabs')); |
|
341 | + // modify the post_updated messages array |
|
342 | + add_action('post_updated_messages', array($this, 'post_update_messages'), 10); |
|
343 | + // add shortlink button to cpt edit screens. We can do this as a universal thing BECAUSE, |
|
344 | + // cpts use the same format for shortlinks as posts! |
|
345 | + add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
|
346 | + // This basically allows us to change the title of the "publish" metabox area |
|
347 | + // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
|
348 | + if (! empty($this->_labels['publishbox'])) { |
|
349 | + $box_label = is_array($this->_labels['publishbox']) |
|
350 | + && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
351 | + ? $this->_labels['publishbox'][ $this->_req_action ] |
|
352 | + : $this->_labels['publishbox']; |
|
353 | + add_meta_box( |
|
354 | + 'submitdiv', |
|
355 | + $box_label, |
|
356 | + 'post_submit_meta_box', |
|
357 | + $this->_cpt_routes[ $this->_req_action ], |
|
358 | + 'side', |
|
359 | + 'core' |
|
360 | + ); |
|
361 | + } |
|
362 | + // let's add page_templates metabox if this cpt added support for it. |
|
363 | + if ($this->_supports_page_templates($this->_cpt_object->name)) { |
|
364 | + add_meta_box( |
|
365 | + 'page_templates', |
|
366 | + __('Page Template', 'event_espresso'), |
|
367 | + array($this, 'page_template_meta_box'), |
|
368 | + $this->_cpt_routes[ $this->_req_action ], |
|
369 | + 'side', |
|
370 | + 'default' |
|
371 | + ); |
|
372 | + } |
|
373 | + // this is a filter that allows the addition of extra html after the permalink field on the wp post edit-form |
|
374 | + if (method_exists($this, 'extra_permalink_field_buttons')) { |
|
375 | + add_filter('get_sample_permalink_html', array($this, 'extra_permalink_field_buttons'), 10, 4); |
|
376 | + } |
|
377 | + // add preview button |
|
378 | + add_filter('get_sample_permalink_html', array($this, 'preview_button_html'), 5, 4); |
|
379 | + // insert our own post_stati dropdown |
|
380 | + add_action('post_submitbox_misc_actions', array($this, 'custom_post_stati_dropdown'), 10); |
|
381 | + // This allows adding additional information to the publish post submitbox on the wp post edit form |
|
382 | + if (method_exists($this, 'extra_misc_actions_publish_box')) { |
|
383 | + add_action('post_submitbox_misc_actions', array($this, 'extra_misc_actions_publish_box'), 10); |
|
384 | + } |
|
385 | + // This allows for adding additional stuff after the title field on the wp post edit form. |
|
386 | + // This is also before the wp_editor for post description field. |
|
387 | + if (method_exists($this, 'edit_form_after_title')) { |
|
388 | + add_action('edit_form_after_title', array($this, 'edit_form_after_title'), 10); |
|
389 | + } |
|
390 | + /** |
|
391 | + * Filtering WP's esc_url to capture urls pointing to core wp routes so they point to our route. |
|
392 | + */ |
|
393 | + add_filter('clean_url', array($this, 'switch_core_wp_urls_with_ours'), 10, 3); |
|
394 | + parent::_load_page_dependencies(); |
|
395 | + // notice we are ALSO going to load the pagenow hook set for this route |
|
396 | + // (see _before_page_setup for the reset of the pagenow global ). |
|
397 | + // This is for any plugins that are doing things properly |
|
398 | + // and hooking into the load page hook for core wp cpt routes. |
|
399 | + global $pagenow; |
|
400 | + do_action('load-' . $pagenow); |
|
401 | + $this->modify_current_screen(); |
|
402 | + add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
|
403 | + // we route REALLY early. |
|
404 | + try { |
|
405 | + $this->_route_admin_request(); |
|
406 | + } catch (EE_Error $e) { |
|
407 | + $e->get_error(); |
|
408 | + } |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Since we don't want users going to default core wp routes, this will check any wp urls run through the |
|
414 | + * esc_url() method and if we see a url matching a pattern for our routes, we'll modify it to point to OUR |
|
415 | + * route instead. |
|
416 | + * |
|
417 | + * @param string $good_protocol_url The escaped url. |
|
418 | + * @param string $original_url The original url. |
|
419 | + * @param string $_context The context sent to the esc_url method. |
|
420 | + * @return string possibly a new url for our route. |
|
421 | + */ |
|
422 | + public function switch_core_wp_urls_with_ours($good_protocol_url, $original_url, $_context) |
|
423 | + { |
|
424 | + $routes_to_match = array( |
|
425 | + 0 => array( |
|
426 | + 'edit.php?post_type=espresso_attendees', |
|
427 | + 'admin.php?page=espresso_registrations&action=contact_list', |
|
428 | + ), |
|
429 | + 1 => array( |
|
430 | + 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | + 'admin.php?page=' . $this->_cpt_object->name, |
|
432 | + ), |
|
433 | + ); |
|
434 | + foreach ($routes_to_match as $route_matches) { |
|
435 | + if (strpos($good_protocol_url, $route_matches[0]) !== false) { |
|
436 | + return str_replace($route_matches[0], $route_matches[1], $good_protocol_url); |
|
437 | + } |
|
438 | + } |
|
439 | + return $good_protocol_url; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * Determine whether the current cpt supports page templates or not. |
|
445 | + * |
|
446 | + * @since %VER% |
|
447 | + * @param string $cpt_name The cpt slug we're checking on. |
|
448 | + * @return bool True supported, false not. |
|
449 | + * @throws InvalidArgumentException |
|
450 | + * @throws InvalidDataTypeException |
|
451 | + * @throws InvalidInterfaceException |
|
452 | + */ |
|
453 | + private function _supports_page_templates($cpt_name) |
|
454 | + { |
|
455 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
456 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
457 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
458 | + ); |
|
459 | + $cpt_args = $custom_post_types->getDefinitions(); |
|
460 | + $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array(); |
|
461 | + $cpt_has_support = ! empty($cpt_args['page_templates']); |
|
462 | + |
|
463 | + // if the installed version of WP is > 4.7 we do some additional checks. |
|
464 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
465 | + $post_templates = wp_get_theme()->get_post_templates(); |
|
466 | + // if there are $post_templates for this cpt, then we return false for this method because |
|
467 | + // that means we aren't going to load our page template manager and leave that up to the native |
|
468 | + // cpt template manager. |
|
469 | + $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
470 | + } |
|
471 | + |
|
472 | + return $cpt_has_support; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Callback for the page_templates metabox selector. |
|
478 | + * |
|
479 | + * @since %VER% |
|
480 | + * @return void |
|
481 | + */ |
|
482 | + public function page_template_meta_box() |
|
483 | + { |
|
484 | + global $post; |
|
485 | + $template = ''; |
|
486 | + |
|
487 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
488 | + $page_template_count = count(get_page_templates()); |
|
489 | + } else { |
|
490 | + $page_template_count = count(get_page_templates($post)); |
|
491 | + }; |
|
492 | + |
|
493 | + if ($page_template_count) { |
|
494 | + $page_template = get_post_meta($post->ID, '_wp_page_template', true); |
|
495 | + $template = ! empty($page_template) ? $page_template : ''; |
|
496 | + } |
|
497 | + ?> |
|
498 | 498 | <p><strong><?php _e('Template', 'event_espresso') ?></strong></p> |
499 | 499 | <label class="screen-reader-text" for="page_template"><?php _e('Page Template', 'event_espresso') ?></label><select |
500 | 500 | name="page_template" id="page_template"> |
@@ -502,470 +502,470 @@ discard block |
||
502 | 502 | <?php page_template_dropdown($template); ?> |
503 | 503 | </select> |
504 | 504 | <?php |
505 | - } |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
510 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
511 | - * |
|
512 | - * @param string $return the current html |
|
513 | - * @param int $id the post id for the page |
|
514 | - * @param string $new_title What the title is |
|
515 | - * @param string $new_slug what the slug is |
|
516 | - * @return string The new html string for the permalink area |
|
517 | - */ |
|
518 | - public function preview_button_html($return, $id, $new_title, $new_slug) |
|
519 | - { |
|
520 | - $post = get_post($id); |
|
521 | - if ('publish' !== get_post_status($post)) { |
|
522 | - // include shims for the `get_preview_post_link` function |
|
523 | - require_once(EE_CORE . 'wordpress-shims.php'); |
|
524 | - $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
525 | - . get_preview_post_link($id) |
|
526 | - . '" class="button button-small">' |
|
527 | - . __('Preview', 'event_espresso') |
|
528 | - . '</a></span>' |
|
529 | - . "\n"; |
|
530 | - } |
|
531 | - return $return; |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - /** |
|
536 | - * add our custom post stati dropdown on the wp post page for this cpt |
|
537 | - * |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public function custom_post_stati_dropdown() |
|
541 | - { |
|
542 | - |
|
543 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
544 | - $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
545 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
546 | - : ''; |
|
547 | - $template_args = array( |
|
548 | - 'cur_status' => $this->_cpt_model_obj->status(), |
|
549 | - 'statuses' => $statuses, |
|
550 | - 'cur_status_label' => $cur_status_label, |
|
551 | - 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
552 | - ); |
|
553 | - // we'll add a trash post status (WP doesn't add one for some reason) |
|
554 | - if ($this->_cpt_model_obj->status() === 'trash') { |
|
555 | - $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
556 | - $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
557 | - $template_args['statuses'] = $statuses; |
|
558 | - } |
|
559 | - |
|
560 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
561 | - EEH_Template::display_template($template, $template_args); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - public function setup_autosave_hooks() |
|
566 | - { |
|
567 | - $this->_set_autosave_containers(); |
|
568 | - $this->_load_autosave_scripts_styles(); |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
574 | - * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
575 | - * for the nonce in here, but then this method looks for two things: |
|
576 | - * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
577 | - * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
578 | - * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
579 | - * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
580 | - * template args. |
|
581 | - * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
582 | - * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
583 | - * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
584 | - * $this->_template_args['data']['items'] = array( |
|
585 | - * 'event-datetime-ids' => '1,2,3'; |
|
586 | - * ); |
|
587 | - * Keep in mind the following things: |
|
588 | - * - "where" index is for the input with the id as that string. |
|
589 | - * - "what" index is what will be used for the value of that input. |
|
590 | - * |
|
591 | - * @return void |
|
592 | - */ |
|
593 | - public function do_extra_autosave_stuff() |
|
594 | - { |
|
595 | - // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
596 | - $nonce = isset($this->_req_data['autosavenonce']) |
|
597 | - ? $this->_req_data['autosavenonce'] |
|
598 | - : null; |
|
599 | - $this->_verify_nonce($nonce, 'autosave'); |
|
600 | - // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
601 | - if (! defined('DOING_AUTOSAVE')) { |
|
602 | - define('DOING_AUTOSAVE', true); |
|
603 | - } |
|
604 | - // if we made it here then the nonce checked out. Let's run our methods and actions |
|
605 | - $autosave = "_ee_autosave_{$this->_current_view}"; |
|
606 | - if (method_exists($this, $autosave)) { |
|
607 | - $this->$autosave(); |
|
608 | - } else { |
|
609 | - $this->_template_args['success'] = true; |
|
610 | - } |
|
611 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
612 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
613 | - // now let's return json |
|
614 | - $this->_return_json(); |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
620 | - * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
621 | - * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
622 | - * |
|
623 | - * @access protected |
|
624 | - * @throws EE_Error |
|
625 | - * @return void |
|
626 | - */ |
|
627 | - protected function _extend_page_config_for_cpt() |
|
628 | - { |
|
629 | - // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
630 | - if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
631 | - return; |
|
632 | - } |
|
633 | - // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
634 | - if (! empty($this->_cpt_object)) { |
|
635 | - $this->_page_routes = array_merge( |
|
636 | - array( |
|
637 | - 'create_new' => '_create_new_cpt_item', |
|
638 | - 'edit' => '_edit_cpt_item', |
|
639 | - ), |
|
640 | - $this->_page_routes |
|
641 | - ); |
|
642 | - $this->_page_config = array_merge( |
|
643 | - array( |
|
644 | - 'create_new' => array( |
|
645 | - 'nav' => array( |
|
646 | - 'label' => $this->_cpt_object->labels->add_new_item, |
|
647 | - 'order' => 5, |
|
648 | - ), |
|
649 | - 'require_nonce' => false, |
|
650 | - ), |
|
651 | - 'edit' => array( |
|
652 | - 'nav' => array( |
|
653 | - 'label' => $this->_cpt_object->labels->edit_item, |
|
654 | - 'order' => 5, |
|
655 | - 'persistent' => false, |
|
656 | - 'url' => '', |
|
657 | - ), |
|
658 | - 'require_nonce' => false, |
|
659 | - ), |
|
660 | - ), |
|
661 | - $this->_page_config |
|
662 | - ); |
|
663 | - } |
|
664 | - // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
665 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
666 | - return; |
|
667 | - } |
|
668 | - $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false; |
|
669 | - // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
670 | - if (empty($this->_cpt_object)) { |
|
671 | - $msg = sprintf( |
|
672 | - __( |
|
673 | - 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
674 | - 'event_espresso' |
|
675 | - ), |
|
676 | - $this->page_slug, |
|
677 | - $this->_req_action, |
|
678 | - get_class($this) |
|
679 | - ); |
|
680 | - throw new EE_Error($msg); |
|
681 | - } |
|
682 | - if ($this->_cpt_route) { |
|
683 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
684 | - $this->_set_model_object($id); |
|
685 | - } |
|
686 | - } |
|
687 | - |
|
688 | - |
|
689 | - /** |
|
690 | - * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
691 | - * |
|
692 | - * @access protected |
|
693 | - * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
694 | - * @param bool $ignore_route_check |
|
695 | - * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
696 | - * @throws EE_Error |
|
697 | - * @throws InvalidArgumentException |
|
698 | - * @throws InvalidDataTypeException |
|
699 | - * @throws InvalidInterfaceException |
|
700 | - * @throws ReflectionException |
|
701 | - */ |
|
702 | - protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
703 | - { |
|
704 | - $model = null; |
|
705 | - if (empty($this->_cpt_model_names) |
|
706 | - || ( |
|
707 | - ! $ignore_route_check |
|
708 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
709 | - ) || ( |
|
710 | - $this->_cpt_model_obj instanceof EE_CPT_Base |
|
711 | - && $this->_cpt_model_obj->ID() === $id |
|
712 | - ) |
|
713 | - ) { |
|
714 | - // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
715 | - return; |
|
716 | - } |
|
717 | - // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
718 | - if ($ignore_route_check) { |
|
719 | - $post_type = get_post_type($id); |
|
720 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
721 | - $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
722 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
723 | - ); |
|
724 | - $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
725 | - if (isset($model_names[ $post_type ])) { |
|
726 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
727 | - } |
|
728 | - } else { |
|
729 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
730 | - } |
|
731 | - if ($model instanceof EEM_Base) { |
|
732 | - $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
733 | - } |
|
734 | - do_action( |
|
735 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
736 | - $this->_cpt_model_obj, |
|
737 | - $req_type |
|
738 | - ); |
|
739 | - } |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * admin_init_global |
|
744 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
745 | - * This method executes for ALL EE Admin pages. |
|
746 | - * |
|
747 | - * @access public |
|
748 | - * @return void |
|
749 | - */ |
|
750 | - public function admin_init_global() |
|
751 | - { |
|
752 | - $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
753 | - // its possible this is a new save so let's catch that instead |
|
754 | - $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
755 | - $post_type = $post ? $post->post_type : false; |
|
756 | - $current_route = isset($this->_req_data['current_route']) |
|
757 | - ? $this->_req_data['current_route'] |
|
758 | - : 'shouldneverwork'; |
|
759 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
760 | - ? $this->_cpt_routes[ $current_route ] |
|
761 | - : ''; |
|
762 | - add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
763 | - add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
764 | - if ($post_type === $route_to_check) { |
|
765 | - add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
766 | - } |
|
767 | - // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
768 | - $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
769 | - if (! empty($revision)) { |
|
770 | - $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
771 | - // doing a restore? |
|
772 | - if (! empty($action) && $action === 'restore') { |
|
773 | - // get post for revision |
|
774 | - $rev_post = get_post($revision); |
|
775 | - $rev_parent = get_post($rev_post->post_parent); |
|
776 | - // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
777 | - if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
778 | - add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
779 | - // restores of revisions |
|
780 | - add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
781 | - } |
|
782 | - } |
|
783 | - } |
|
784 | - // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
785 | - if ($post_type && $post_type === $route_to_check) { |
|
786 | - // $post_id, $post |
|
787 | - add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
788 | - // $post_id |
|
789 | - add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
790 | - add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
791 | - add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
792 | - add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
793 | - } |
|
794 | - } |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * Callback for the WordPress trashed_post hook. |
|
799 | - * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
800 | - * |
|
801 | - * @param int $post_id |
|
802 | - * @throws \EE_Error |
|
803 | - */ |
|
804 | - public function before_trash_cpt_item($post_id) |
|
805 | - { |
|
806 | - $this->_set_model_object($post_id, true, 'trash'); |
|
807 | - // if our cpt object isn't existent then get out immediately. |
|
808 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
809 | - return; |
|
810 | - } |
|
811 | - $this->trash_cpt_item($post_id); |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * Callback for the WordPress untrashed_post hook. |
|
817 | - * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
818 | - * |
|
819 | - * @param $post_id |
|
820 | - * @throws \EE_Error |
|
821 | - */ |
|
822 | - public function before_restore_cpt_item($post_id) |
|
823 | - { |
|
824 | - $this->_set_model_object($post_id, true, 'restore'); |
|
825 | - // if our cpt object isn't existent then get out immediately. |
|
826 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
827 | - return; |
|
828 | - } |
|
829 | - $this->restore_cpt_item($post_id); |
|
830 | - } |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * Callback for the WordPress after_delete_post hook. |
|
835 | - * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
836 | - * |
|
837 | - * @param $post_id |
|
838 | - * @throws \EE_Error |
|
839 | - */ |
|
840 | - public function before_delete_cpt_item($post_id) |
|
841 | - { |
|
842 | - $this->_set_model_object($post_id, true, 'delete'); |
|
843 | - // if our cpt object isn't existent then get out immediately. |
|
844 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
845 | - return; |
|
846 | - } |
|
847 | - $this->delete_cpt_item($post_id); |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - /** |
|
852 | - * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
853 | - * accordingly. |
|
854 | - * |
|
855 | - * @access public |
|
856 | - * @throws EE_Error |
|
857 | - * @return void |
|
858 | - */ |
|
859 | - public function verify_cpt_object() |
|
860 | - { |
|
861 | - $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
862 | - // verify event object |
|
863 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
864 | - throw new EE_Error( |
|
865 | - sprintf( |
|
866 | - __( |
|
867 | - 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
868 | - 'event_espresso' |
|
869 | - ), |
|
870 | - $label |
|
871 | - ) |
|
872 | - ); |
|
873 | - } |
|
874 | - // if auto-draft then throw an error |
|
875 | - if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
876 | - EE_Error::overwrite_errors(); |
|
877 | - EE_Error::add_error( |
|
878 | - sprintf( |
|
879 | - __( |
|
880 | - 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
881 | - 'event_espresso' |
|
882 | - ), |
|
883 | - $label |
|
884 | - ), |
|
885 | - __FILE__, |
|
886 | - __FUNCTION__, |
|
887 | - __LINE__ |
|
888 | - ); |
|
889 | - } |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - /** |
|
894 | - * admin_footer_scripts_global |
|
895 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
896 | - * will apply on ALL EE_Admin pages. |
|
897 | - * |
|
898 | - * @access public |
|
899 | - * @return void |
|
900 | - */ |
|
901 | - public function admin_footer_scripts_global() |
|
902 | - { |
|
903 | - $this->_add_admin_page_ajax_loading_img(); |
|
904 | - $this->_add_admin_page_overlay(); |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * add in any global scripts for cpt routes |
|
910 | - * |
|
911 | - * @return void |
|
912 | - */ |
|
913 | - public function load_global_scripts_styles() |
|
914 | - { |
|
915 | - parent::load_global_scripts_styles(); |
|
916 | - if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
917 | - // setup custom post status object for localize script but only if we've got a cpt object |
|
918 | - $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
919 | - if (! empty($statuses)) { |
|
920 | - // get ALL statuses! |
|
921 | - $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
922 | - // setup object |
|
923 | - $ee_cpt_statuses = array(); |
|
924 | - foreach ($statuses as $status => $label) { |
|
925 | - $ee_cpt_statuses[ $status ] = array( |
|
926 | - 'label' => $label, |
|
927 | - 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
928 | - ); |
|
929 | - } |
|
930 | - wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
931 | - } |
|
932 | - } |
|
933 | - } |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
938 | - * insert/updates |
|
939 | - * |
|
940 | - * @param int $post_id ID of post being updated |
|
941 | - * @param WP_Post $post Post object from WP |
|
942 | - * @param bool $update Whether this is an update or a new save. |
|
943 | - * @return void |
|
944 | - * @throws \EE_Error |
|
945 | - */ |
|
946 | - public function insert_update($post_id, $post, $update) |
|
947 | - { |
|
948 | - // make sure that if this is a revision OR trash action that we don't do any updates! |
|
949 | - if (isset($this->_req_data['action']) |
|
950 | - && ( |
|
951 | - $this->_req_data['action'] === 'restore' |
|
952 | - || $this->_req_data['action'] === 'trash' |
|
953 | - ) |
|
954 | - ) { |
|
955 | - return; |
|
956 | - } |
|
957 | - $this->_set_model_object($post_id, true, 'insert_update'); |
|
958 | - // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
959 | - if ($update |
|
960 | - && ( |
|
961 | - ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
962 | - || $this->_cpt_model_obj->ID() !== $post_id |
|
963 | - ) |
|
964 | - ) { |
|
965 | - return; |
|
966 | - } |
|
967 | - // check for autosave and update our req_data property accordingly. |
|
968 | - /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
505 | + } |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * if this post is a draft or scheduled post then we provide a preview button for user to click |
|
510 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
511 | + * |
|
512 | + * @param string $return the current html |
|
513 | + * @param int $id the post id for the page |
|
514 | + * @param string $new_title What the title is |
|
515 | + * @param string $new_slug what the slug is |
|
516 | + * @return string The new html string for the permalink area |
|
517 | + */ |
|
518 | + public function preview_button_html($return, $id, $new_title, $new_slug) |
|
519 | + { |
|
520 | + $post = get_post($id); |
|
521 | + if ('publish' !== get_post_status($post)) { |
|
522 | + // include shims for the `get_preview_post_link` function |
|
523 | + require_once(EE_CORE . 'wordpress-shims.php'); |
|
524 | + $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
|
525 | + . get_preview_post_link($id) |
|
526 | + . '" class="button button-small">' |
|
527 | + . __('Preview', 'event_espresso') |
|
528 | + . '</a></span>' |
|
529 | + . "\n"; |
|
530 | + } |
|
531 | + return $return; |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + /** |
|
536 | + * add our custom post stati dropdown on the wp post page for this cpt |
|
537 | + * |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public function custom_post_stati_dropdown() |
|
541 | + { |
|
542 | + |
|
543 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
544 | + $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
|
545 | + ? $statuses[ $this->_cpt_model_obj->status() ] |
|
546 | + : ''; |
|
547 | + $template_args = array( |
|
548 | + 'cur_status' => $this->_cpt_model_obj->status(), |
|
549 | + 'statuses' => $statuses, |
|
550 | + 'cur_status_label' => $cur_status_label, |
|
551 | + 'localized_status_save' => sprintf(__('Save %s', 'event_espresso'), $cur_status_label), |
|
552 | + ); |
|
553 | + // we'll add a trash post status (WP doesn't add one for some reason) |
|
554 | + if ($this->_cpt_model_obj->status() === 'trash') { |
|
555 | + $template_args['cur_status_label'] = __('Trashed', 'event_espresso'); |
|
556 | + $statuses['trash'] = __('Trashed', 'event_espresso'); |
|
557 | + $template_args['statuses'] = $statuses; |
|
558 | + } |
|
559 | + |
|
560 | + $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
561 | + EEH_Template::display_template($template, $template_args); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + public function setup_autosave_hooks() |
|
566 | + { |
|
567 | + $this->_set_autosave_containers(); |
|
568 | + $this->_load_autosave_scripts_styles(); |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * This is run on all WordPress autosaves AFTER the autosave is complete and sends along a $_POST object (available |
|
574 | + * in $this->_req_data) containing: post_ID of the saved post autosavenonce for the saved post We'll do the check |
|
575 | + * for the nonce in here, but then this method looks for two things: |
|
576 | + * 1. Execute a method (if exists) matching 'ee_autosave_' and appended with the given route. OR |
|
577 | + * 2. do_actions() for global or class specific actions that have been registered (for plugins/addons not in an |
|
578 | + * EE_Admin_Page class. PLEASE NOTE: Data will be returned using the _return_json() object and so the |
|
579 | + * $_template_args property should be used to hold the $data array. We're expecting the following things set in |
|
580 | + * template args. |
|
581 | + * 1. $template_args['error'] = IF there is an error you can add the message in here. |
|
582 | + * 2. $template_args['data']['items'] = an array of items that are setup in key index pairs of 'where_values_go' |
|
583 | + * => 'values_to_add'. In other words, for the datetime metabox we'll have something like |
|
584 | + * $this->_template_args['data']['items'] = array( |
|
585 | + * 'event-datetime-ids' => '1,2,3'; |
|
586 | + * ); |
|
587 | + * Keep in mind the following things: |
|
588 | + * - "where" index is for the input with the id as that string. |
|
589 | + * - "what" index is what will be used for the value of that input. |
|
590 | + * |
|
591 | + * @return void |
|
592 | + */ |
|
593 | + public function do_extra_autosave_stuff() |
|
594 | + { |
|
595 | + // next let's check for the autosave nonce (we'll use _verify_nonce ) |
|
596 | + $nonce = isset($this->_req_data['autosavenonce']) |
|
597 | + ? $this->_req_data['autosavenonce'] |
|
598 | + : null; |
|
599 | + $this->_verify_nonce($nonce, 'autosave'); |
|
600 | + // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
|
601 | + if (! defined('DOING_AUTOSAVE')) { |
|
602 | + define('DOING_AUTOSAVE', true); |
|
603 | + } |
|
604 | + // if we made it here then the nonce checked out. Let's run our methods and actions |
|
605 | + $autosave = "_ee_autosave_{$this->_current_view}"; |
|
606 | + if (method_exists($this, $autosave)) { |
|
607 | + $this->$autosave(); |
|
608 | + } else { |
|
609 | + $this->_template_args['success'] = true; |
|
610 | + } |
|
611 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
|
612 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
613 | + // now let's return json |
|
614 | + $this->_return_json(); |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * This takes care of setting up default routes and pages that utilize the core WP admin pages. |
|
620 | + * Child classes can override the defaults (in cases for adding metaboxes etc.) |
|
621 | + * but take care that you include the defaults here otherwise your core WP admin pages for the cpt won't work! |
|
622 | + * |
|
623 | + * @access protected |
|
624 | + * @throws EE_Error |
|
625 | + * @return void |
|
626 | + */ |
|
627 | + protected function _extend_page_config_for_cpt() |
|
628 | + { |
|
629 | + // before doing anything we need to make sure this runs ONLY when the loaded page matches the set page_slug |
|
630 | + if (isset($this->_req_data['page']) && $this->_req_data['page'] !== $this->page_slug) { |
|
631 | + return; |
|
632 | + } |
|
633 | + // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
|
634 | + if (! empty($this->_cpt_object)) { |
|
635 | + $this->_page_routes = array_merge( |
|
636 | + array( |
|
637 | + 'create_new' => '_create_new_cpt_item', |
|
638 | + 'edit' => '_edit_cpt_item', |
|
639 | + ), |
|
640 | + $this->_page_routes |
|
641 | + ); |
|
642 | + $this->_page_config = array_merge( |
|
643 | + array( |
|
644 | + 'create_new' => array( |
|
645 | + 'nav' => array( |
|
646 | + 'label' => $this->_cpt_object->labels->add_new_item, |
|
647 | + 'order' => 5, |
|
648 | + ), |
|
649 | + 'require_nonce' => false, |
|
650 | + ), |
|
651 | + 'edit' => array( |
|
652 | + 'nav' => array( |
|
653 | + 'label' => $this->_cpt_object->labels->edit_item, |
|
654 | + 'order' => 5, |
|
655 | + 'persistent' => false, |
|
656 | + 'url' => '', |
|
657 | + ), |
|
658 | + 'require_nonce' => false, |
|
659 | + ), |
|
660 | + ), |
|
661 | + $this->_page_config |
|
662 | + ); |
|
663 | + } |
|
664 | + // load the next section only if this is a matching cpt route as set in the cpt routes array. |
|
665 | + if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
666 | + return; |
|
667 | + } |
|
668 | + $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false; |
|
669 | + // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
|
670 | + if (empty($this->_cpt_object)) { |
|
671 | + $msg = sprintf( |
|
672 | + __( |
|
673 | + 'This page has been set as being related to a registered custom post type, however, the custom post type object could not be retrieved. There are two possible reasons for this: 1. The "%s" does not match a registered post type. or 2. The custom post type is not registered for the "%s" action as indexed in the "$_cpt_routes" property on this class (%s).', |
|
674 | + 'event_espresso' |
|
675 | + ), |
|
676 | + $this->page_slug, |
|
677 | + $this->_req_action, |
|
678 | + get_class($this) |
|
679 | + ); |
|
680 | + throw new EE_Error($msg); |
|
681 | + } |
|
682 | + if ($this->_cpt_route) { |
|
683 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
684 | + $this->_set_model_object($id); |
|
685 | + } |
|
686 | + } |
|
687 | + |
|
688 | + |
|
689 | + /** |
|
690 | + * Sets the _cpt_model_object property using what has been set for the _cpt_model_name and a given id. |
|
691 | + * |
|
692 | + * @access protected |
|
693 | + * @param int $id The id to retrieve the model object for. If empty we set a default object. |
|
694 | + * @param bool $ignore_route_check |
|
695 | + * @param string $req_type whether the current route is for inserting, updating, or deleting the CPT |
|
696 | + * @throws EE_Error |
|
697 | + * @throws InvalidArgumentException |
|
698 | + * @throws InvalidDataTypeException |
|
699 | + * @throws InvalidInterfaceException |
|
700 | + * @throws ReflectionException |
|
701 | + */ |
|
702 | + protected function _set_model_object($id = null, $ignore_route_check = false, $req_type = '') |
|
703 | + { |
|
704 | + $model = null; |
|
705 | + if (empty($this->_cpt_model_names) |
|
706 | + || ( |
|
707 | + ! $ignore_route_check |
|
708 | + && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
709 | + ) || ( |
|
710 | + $this->_cpt_model_obj instanceof EE_CPT_Base |
|
711 | + && $this->_cpt_model_obj->ID() === $id |
|
712 | + ) |
|
713 | + ) { |
|
714 | + // get out cuz we either don't have a model name OR the object has already been set and it has the same id as what has been sent. |
|
715 | + return; |
|
716 | + } |
|
717 | + // if ignore_route_check is true, then get the model name via CustomPostTypeDefinitions |
|
718 | + if ($ignore_route_check) { |
|
719 | + $post_type = get_post_type($id); |
|
720 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_types */ |
|
721 | + $custom_post_types = LoaderFactory::getLoader()->getShared( |
|
722 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
723 | + ); |
|
724 | + $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
|
725 | + if (isset($model_names[ $post_type ])) { |
|
726 | + $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
727 | + } |
|
728 | + } else { |
|
729 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
730 | + } |
|
731 | + if ($model instanceof EEM_Base) { |
|
732 | + $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
|
733 | + } |
|
734 | + do_action( |
|
735 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
736 | + $this->_cpt_model_obj, |
|
737 | + $req_type |
|
738 | + ); |
|
739 | + } |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * admin_init_global |
|
744 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
745 | + * This method executes for ALL EE Admin pages. |
|
746 | + * |
|
747 | + * @access public |
|
748 | + * @return void |
|
749 | + */ |
|
750 | + public function admin_init_global() |
|
751 | + { |
|
752 | + $post = isset($this->_req_data['post']) ? get_post($this->_req_data['post']) : null; |
|
753 | + // its possible this is a new save so let's catch that instead |
|
754 | + $post = isset($this->_req_data['post_ID']) ? get_post($this->_req_data['post_ID']) : $post; |
|
755 | + $post_type = $post ? $post->post_type : false; |
|
756 | + $current_route = isset($this->_req_data['current_route']) |
|
757 | + ? $this->_req_data['current_route'] |
|
758 | + : 'shouldneverwork'; |
|
759 | + $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
760 | + ? $this->_cpt_routes[ $current_route ] |
|
761 | + : ''; |
|
762 | + add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
|
763 | + add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
|
764 | + if ($post_type === $route_to_check) { |
|
765 | + add_filter('redirect_post_location', array($this, 'cpt_post_location_redirect'), 10, 2); |
|
766 | + } |
|
767 | + // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
|
768 | + $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
769 | + if (! empty($revision)) { |
|
770 | + $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
|
771 | + // doing a restore? |
|
772 | + if (! empty($action) && $action === 'restore') { |
|
773 | + // get post for revision |
|
774 | + $rev_post = get_post($revision); |
|
775 | + $rev_parent = get_post($rev_post->post_parent); |
|
776 | + // only do our redirect filter AND our restore revision action if the post_type for the parent is one of our cpts. |
|
777 | + if ($rev_parent && $rev_parent->post_type === $this->page_slug) { |
|
778 | + add_filter('wp_redirect', array($this, 'revision_redirect'), 10, 2); |
|
779 | + // restores of revisions |
|
780 | + add_action('wp_restore_post_revision', array($this, 'restore_revision'), 10, 2); |
|
781 | + } |
|
782 | + } |
|
783 | + } |
|
784 | + // NOTE we ONLY want to run these hooks if we're on the right class for the given post type. Otherwise we could see some really freaky things happen! |
|
785 | + if ($post_type && $post_type === $route_to_check) { |
|
786 | + // $post_id, $post |
|
787 | + add_action('save_post', array($this, 'insert_update'), 10, 3); |
|
788 | + // $post_id |
|
789 | + add_action('trashed_post', array($this, 'before_trash_cpt_item'), 10); |
|
790 | + add_action('trashed_post', array($this, 'dont_permanently_delete_ee_cpts'), 10); |
|
791 | + add_action('untrashed_post', array($this, 'before_restore_cpt_item'), 10); |
|
792 | + add_action('after_delete_post', array($this, 'before_delete_cpt_item'), 10); |
|
793 | + } |
|
794 | + } |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * Callback for the WordPress trashed_post hook. |
|
799 | + * Execute some basic checks before calling the trash_cpt_item declared in the child class. |
|
800 | + * |
|
801 | + * @param int $post_id |
|
802 | + * @throws \EE_Error |
|
803 | + */ |
|
804 | + public function before_trash_cpt_item($post_id) |
|
805 | + { |
|
806 | + $this->_set_model_object($post_id, true, 'trash'); |
|
807 | + // if our cpt object isn't existent then get out immediately. |
|
808 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
809 | + return; |
|
810 | + } |
|
811 | + $this->trash_cpt_item($post_id); |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * Callback for the WordPress untrashed_post hook. |
|
817 | + * Execute some basic checks before calling the restore_cpt_method in the child class. |
|
818 | + * |
|
819 | + * @param $post_id |
|
820 | + * @throws \EE_Error |
|
821 | + */ |
|
822 | + public function before_restore_cpt_item($post_id) |
|
823 | + { |
|
824 | + $this->_set_model_object($post_id, true, 'restore'); |
|
825 | + // if our cpt object isn't existent then get out immediately. |
|
826 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
827 | + return; |
|
828 | + } |
|
829 | + $this->restore_cpt_item($post_id); |
|
830 | + } |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * Callback for the WordPress after_delete_post hook. |
|
835 | + * Execute some basic checks before calling the delete_cpt_item method in the child class. |
|
836 | + * |
|
837 | + * @param $post_id |
|
838 | + * @throws \EE_Error |
|
839 | + */ |
|
840 | + public function before_delete_cpt_item($post_id) |
|
841 | + { |
|
842 | + $this->_set_model_object($post_id, true, 'delete'); |
|
843 | + // if our cpt object isn't existent then get out immediately. |
|
844 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
845 | + return; |
|
846 | + } |
|
847 | + $this->delete_cpt_item($post_id); |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + /** |
|
852 | + * This simply verifies if the cpt_model_object is instantiated for the given page and throws an error message |
|
853 | + * accordingly. |
|
854 | + * |
|
855 | + * @access public |
|
856 | + * @throws EE_Error |
|
857 | + * @return void |
|
858 | + */ |
|
859 | + public function verify_cpt_object() |
|
860 | + { |
|
861 | + $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
|
862 | + // verify event object |
|
863 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
864 | + throw new EE_Error( |
|
865 | + sprintf( |
|
866 | + __( |
|
867 | + 'Something has gone wrong with the page load because we are unable to set up the object for the %1$s. This usually happens when the given id for the page route is NOT for the correct custom post type for this page', |
|
868 | + 'event_espresso' |
|
869 | + ), |
|
870 | + $label |
|
871 | + ) |
|
872 | + ); |
|
873 | + } |
|
874 | + // if auto-draft then throw an error |
|
875 | + if ($this->_cpt_model_obj->get('status') === 'auto-draft') { |
|
876 | + EE_Error::overwrite_errors(); |
|
877 | + EE_Error::add_error( |
|
878 | + sprintf( |
|
879 | + __( |
|
880 | + 'This %1$s was saved without a title, description, or excerpt which means that none of the extra details you added were saved properly. All autodrafts will show up in the "draft" view of your event list table. You can delete them from there. Please click the "Add %1$s" button to refresh and restart.', |
|
881 | + 'event_espresso' |
|
882 | + ), |
|
883 | + $label |
|
884 | + ), |
|
885 | + __FILE__, |
|
886 | + __FUNCTION__, |
|
887 | + __LINE__ |
|
888 | + ); |
|
889 | + } |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + /** |
|
894 | + * admin_footer_scripts_global |
|
895 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
896 | + * will apply on ALL EE_Admin pages. |
|
897 | + * |
|
898 | + * @access public |
|
899 | + * @return void |
|
900 | + */ |
|
901 | + public function admin_footer_scripts_global() |
|
902 | + { |
|
903 | + $this->_add_admin_page_ajax_loading_img(); |
|
904 | + $this->_add_admin_page_overlay(); |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * add in any global scripts for cpt routes |
|
910 | + * |
|
911 | + * @return void |
|
912 | + */ |
|
913 | + public function load_global_scripts_styles() |
|
914 | + { |
|
915 | + parent::load_global_scripts_styles(); |
|
916 | + if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
917 | + // setup custom post status object for localize script but only if we've got a cpt object |
|
918 | + $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
|
919 | + if (! empty($statuses)) { |
|
920 | + // get ALL statuses! |
|
921 | + $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
|
922 | + // setup object |
|
923 | + $ee_cpt_statuses = array(); |
|
924 | + foreach ($statuses as $status => $label) { |
|
925 | + $ee_cpt_statuses[ $status ] = array( |
|
926 | + 'label' => $label, |
|
927 | + 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
|
928 | + ); |
|
929 | + } |
|
930 | + wp_localize_script('ee_admin_js', 'eeCPTstatuses', $ee_cpt_statuses); |
|
931 | + } |
|
932 | + } |
|
933 | + } |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * This is a wrapper for the insert/update routes for cpt items so we can add things that are common to ALL |
|
938 | + * insert/updates |
|
939 | + * |
|
940 | + * @param int $post_id ID of post being updated |
|
941 | + * @param WP_Post $post Post object from WP |
|
942 | + * @param bool $update Whether this is an update or a new save. |
|
943 | + * @return void |
|
944 | + * @throws \EE_Error |
|
945 | + */ |
|
946 | + public function insert_update($post_id, $post, $update) |
|
947 | + { |
|
948 | + // make sure that if this is a revision OR trash action that we don't do any updates! |
|
949 | + if (isset($this->_req_data['action']) |
|
950 | + && ( |
|
951 | + $this->_req_data['action'] === 'restore' |
|
952 | + || $this->_req_data['action'] === 'trash' |
|
953 | + ) |
|
954 | + ) { |
|
955 | + return; |
|
956 | + } |
|
957 | + $this->_set_model_object($post_id, true, 'insert_update'); |
|
958 | + // if our cpt object is not instantiated and its NOT the same post_id as what is triggering this callback, then exit. |
|
959 | + if ($update |
|
960 | + && ( |
|
961 | + ! $this->_cpt_model_obj instanceof EE_CPT_Base |
|
962 | + || $this->_cpt_model_obj->ID() !== $post_id |
|
963 | + ) |
|
964 | + ) { |
|
965 | + return; |
|
966 | + } |
|
967 | + // check for autosave and update our req_data property accordingly. |
|
968 | + /*if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && isset( $this->_req_data['ee_autosave_data'] ) ) { |
|
969 | 969 | foreach( (array) $this->_req_data['ee_autosave_data'] as $id => $values ) { |
970 | 970 | |
971 | 971 | foreach ( (array) $values as $key => $value ) { |
@@ -975,532 +975,532 @@ discard block |
||
975 | 975 | |
976 | 976 | }/**/ // TODO reactivate after autosave is implemented in 4.2 |
977 | 977 | |
978 | - // take care of updating any selected page_template IF this cpt supports it. |
|
979 | - if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
980 | - // wp version aware. |
|
981 | - if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
982 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
983 | - } else { |
|
984 | - $post->page_template = $this->_req_data['page_template']; |
|
985 | - $page_templates = wp_get_theme()->get_page_templates($post); |
|
986 | - } |
|
987 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) { |
|
988 | - EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
989 | - } else { |
|
990 | - update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
991 | - } |
|
992 | - } |
|
993 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
994 | - return; |
|
995 | - } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
996 | - $this->_insert_update_cpt_item($post_id, $post); |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - /** |
|
1001 | - * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
1002 | - * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
1003 | - * so we don't have to check for our CPT. |
|
1004 | - * |
|
1005 | - * @param int $post_id ID of the post |
|
1006 | - * @return void |
|
1007 | - */ |
|
1008 | - public function dont_permanently_delete_ee_cpts($post_id) |
|
1009 | - { |
|
1010 | - // only do this if we're actually processing one of our CPTs |
|
1011 | - // if our cpt object isn't existent then get out immediately. |
|
1012 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1013 | - return; |
|
1014 | - } |
|
1015 | - delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
1016 | - delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
1017 | - // our cpts may have comments so let's take care of that too |
|
1018 | - delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1024 | - * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1025 | - * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1026 | - * |
|
1027 | - * @param int $post_id ID of cpt item |
|
1028 | - * @param int $revision_id ID of revision being restored |
|
1029 | - * @return void |
|
1030 | - */ |
|
1031 | - public function restore_revision($post_id, $revision_id) |
|
1032 | - { |
|
1033 | - $this->_restore_cpt_item($post_id, $revision_id); |
|
1034 | - // global action |
|
1035 | - do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1036 | - // class specific action so you can limit hooking into a specific page. |
|
1037 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1038 | - } |
|
1039 | - |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * @see restore_revision() for details |
|
1043 | - * @param int $post_id ID of cpt item |
|
1044 | - * @param int $revision_id ID of revision for item |
|
1045 | - * @return void |
|
1046 | - */ |
|
1047 | - abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1048 | - |
|
1049 | - |
|
1050 | - /** |
|
1051 | - * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1052 | - * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1053 | - * To fix we have to reset the current_screen using the page_slug |
|
1054 | - * (which is identical - or should be - to our registered_post_type id.) |
|
1055 | - * Also, since the core WP file loads the admin_header.php for WP |
|
1056 | - * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1057 | - * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1058 | - * |
|
1059 | - * @return void |
|
1060 | - */ |
|
1061 | - public function modify_current_screen() |
|
1062 | - { |
|
1063 | - // ONLY do this if the current page_route IS a cpt route |
|
1064 | - if (! $this->_cpt_route) { |
|
1065 | - return; |
|
1066 | - } |
|
1067 | - // routing things REALLY early b/c this is a cpt admin page |
|
1068 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1069 | - $this->_current_screen = get_current_screen(); |
|
1070 | - $this->_current_screen->base = 'event-espresso'; |
|
1071 | - $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
1072 | - /*try { |
|
978 | + // take care of updating any selected page_template IF this cpt supports it. |
|
979 | + if ($this->_supports_page_templates($post->post_type) && ! empty($this->_req_data['page_template'])) { |
|
980 | + // wp version aware. |
|
981 | + if (RecommendedVersions::compareWordPressVersion('4.7', '>=')) { |
|
982 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
983 | + } else { |
|
984 | + $post->page_template = $this->_req_data['page_template']; |
|
985 | + $page_templates = wp_get_theme()->get_page_templates($post); |
|
986 | + } |
|
987 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) { |
|
988 | + EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
989 | + } else { |
|
990 | + update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
|
991 | + } |
|
992 | + } |
|
993 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
|
994 | + return; |
|
995 | + } //TODO we'll remove this after reimplementing autosave in 4.2 |
|
996 | + $this->_insert_update_cpt_item($post_id, $post); |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + /** |
|
1001 | + * This hooks into the wp_trash_post() function and removes the `_wp_trash_meta_status` and `_wp_trash_meta_time` |
|
1002 | + * post meta IF the trashed post is one of our CPT's - note this method should only be called with our cpt routes |
|
1003 | + * so we don't have to check for our CPT. |
|
1004 | + * |
|
1005 | + * @param int $post_id ID of the post |
|
1006 | + * @return void |
|
1007 | + */ |
|
1008 | + public function dont_permanently_delete_ee_cpts($post_id) |
|
1009 | + { |
|
1010 | + // only do this if we're actually processing one of our CPTs |
|
1011 | + // if our cpt object isn't existent then get out immediately. |
|
1012 | + if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1013 | + return; |
|
1014 | + } |
|
1015 | + delete_post_meta($post_id, '_wp_trash_meta_status'); |
|
1016 | + delete_post_meta($post_id, '_wp_trash_meta_time'); |
|
1017 | + // our cpts may have comments so let's take care of that too |
|
1018 | + delete_post_meta($post_id, '_wp_trash_meta_comments_status'); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * This is a wrapper for the restore_cpt_revision route for cpt items so we can make sure that when a revision is |
|
1024 | + * triggered that we restore related items. In order to work cpt classes MUST have a restore_cpt_revision method |
|
1025 | + * in them. We also have our OWN action in here so addons can hook into the restore process easily. |
|
1026 | + * |
|
1027 | + * @param int $post_id ID of cpt item |
|
1028 | + * @param int $revision_id ID of revision being restored |
|
1029 | + * @return void |
|
1030 | + */ |
|
1031 | + public function restore_revision($post_id, $revision_id) |
|
1032 | + { |
|
1033 | + $this->_restore_cpt_item($post_id, $revision_id); |
|
1034 | + // global action |
|
1035 | + do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
|
1036 | + // class specific action so you can limit hooking into a specific page. |
|
1037 | + do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1038 | + } |
|
1039 | + |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * @see restore_revision() for details |
|
1043 | + * @param int $post_id ID of cpt item |
|
1044 | + * @param int $revision_id ID of revision for item |
|
1045 | + * @return void |
|
1046 | + */ |
|
1047 | + abstract protected function _restore_cpt_item($post_id, $revision_id); |
|
1048 | + |
|
1049 | + |
|
1050 | + /** |
|
1051 | + * Execution of this method is added to the end of the load_page_dependencies method in the parent |
|
1052 | + * so that we can fix a bug where default core metaboxes were not being called in the sidebar. |
|
1053 | + * To fix we have to reset the current_screen using the page_slug |
|
1054 | + * (which is identical - or should be - to our registered_post_type id.) |
|
1055 | + * Also, since the core WP file loads the admin_header.php for WP |
|
1056 | + * (and there are a bunch of other things edit-form-advanced.php loads that need to happen really early) |
|
1057 | + * we need to load it NOW, hence our _route_admin_request in here. (Otherwise screen options won't be set). |
|
1058 | + * |
|
1059 | + * @return void |
|
1060 | + */ |
|
1061 | + public function modify_current_screen() |
|
1062 | + { |
|
1063 | + // ONLY do this if the current page_route IS a cpt route |
|
1064 | + if (! $this->_cpt_route) { |
|
1065 | + return; |
|
1066 | + } |
|
1067 | + // routing things REALLY early b/c this is a cpt admin page |
|
1068 | + set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1069 | + $this->_current_screen = get_current_screen(); |
|
1070 | + $this->_current_screen->base = 'event-espresso'; |
|
1071 | + $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
|
1072 | + /*try { |
|
1073 | 1073 | $this->_route_admin_request(); |
1074 | 1074 | } catch ( EE_Error $e ) { |
1075 | 1075 | $e->get_error(); |
1076 | 1076 | }/**/ |
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1082 | - * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1083 | - * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1084 | - * default to be. |
|
1085 | - * |
|
1086 | - * @param string $title The new title (or existing if there is no editor_title defined) |
|
1087 | - * @return string |
|
1088 | - */ |
|
1089 | - public function add_custom_editor_default_title($title) |
|
1090 | - { |
|
1091 | - return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
1092 | - ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1093 | - : $title; |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1099 | - * |
|
1100 | - * @param string $shortlink The already generated shortlink |
|
1101 | - * @param int $id Post ID for this item |
|
1102 | - * @param string $context The context for the link |
|
1103 | - * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1104 | - * @return string |
|
1105 | - */ |
|
1106 | - public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1107 | - { |
|
1108 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
1109 | - $post = get_post($id); |
|
1110 | - if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1111 | - $shortlink = home_url('?p=' . $post->ID); |
|
1112 | - } |
|
1113 | - } |
|
1114 | - return $shortlink; |
|
1115 | - } |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1120 | - * already run in modify_current_screen()) |
|
1121 | - * |
|
1122 | - * @return void |
|
1123 | - */ |
|
1124 | - public function route_admin_request() |
|
1125 | - { |
|
1126 | - if ($this->_cpt_route) { |
|
1127 | - return; |
|
1128 | - } |
|
1129 | - try { |
|
1130 | - $this->_route_admin_request(); |
|
1131 | - } catch (EE_Error $e) { |
|
1132 | - $e->get_error(); |
|
1133 | - } |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1139 | - * |
|
1140 | - * @return void |
|
1141 | - */ |
|
1142 | - public function cpt_post_form_hidden_input() |
|
1143 | - { |
|
1144 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1145 | - // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1146 | - echo '<div id="ee-cpt-hidden-inputs">'; |
|
1147 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1148 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1149 | - echo '</div>'; |
|
1150 | - } |
|
1151 | - |
|
1152 | - |
|
1153 | - /** |
|
1154 | - * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1155 | - * |
|
1156 | - * @param string $location Original location url |
|
1157 | - * @param int $status Status for http header |
|
1158 | - * @return string new (or original) url to redirect to. |
|
1159 | - */ |
|
1160 | - public function revision_redirect($location, $status) |
|
1161 | - { |
|
1162 | - // get revision |
|
1163 | - $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1164 | - // can't do anything without revision so let's get out if not present |
|
1165 | - if (empty($rev_id)) { |
|
1166 | - return $location; |
|
1167 | - } |
|
1168 | - // get rev_post_data |
|
1169 | - $rev = get_post($rev_id); |
|
1170 | - $admin_url = $this->_admin_base_url; |
|
1171 | - $query_args = array( |
|
1172 | - 'action' => 'edit', |
|
1173 | - 'post' => $rev->post_parent, |
|
1174 | - 'revision' => $rev_id, |
|
1175 | - 'message' => 5, |
|
1176 | - ); |
|
1177 | - $this->_process_notices($query_args, true); |
|
1178 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1179 | - } |
|
1180 | - |
|
1181 | - |
|
1182 | - /** |
|
1183 | - * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1184 | - * |
|
1185 | - * @param string $link the original generated link |
|
1186 | - * @param int $id post id |
|
1187 | - * @param string $context optional, defaults to display. How to write the '&' |
|
1188 | - * @return string the link |
|
1189 | - */ |
|
1190 | - public function modify_edit_post_link($link, $id, $context) |
|
1191 | - { |
|
1192 | - $post = get_post($id); |
|
1193 | - if (! isset($this->_req_data['action']) |
|
1194 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1195 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1196 | - ) { |
|
1197 | - return $link; |
|
1198 | - } |
|
1199 | - $query_args = array( |
|
1200 | - 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
1201 | - ? $this->_cpt_edit_routes[ $post->post_type ] |
|
1202 | - : 'edit', |
|
1203 | - 'post' => $id, |
|
1204 | - ); |
|
1205 | - return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1206 | - } |
|
1207 | - |
|
1208 | - |
|
1209 | - /** |
|
1210 | - * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1211 | - * our routes. |
|
1212 | - * |
|
1213 | - * @param string $delete_link original delete link |
|
1214 | - * @param int $post_id id of cpt object |
|
1215 | - * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1216 | - * @return string new delete link |
|
1217 | - * @throws EE_Error |
|
1218 | - */ |
|
1219 | - public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1220 | - { |
|
1221 | - $post = get_post($post_id); |
|
1222 | - |
|
1223 | - if (empty($this->_req_data['action']) |
|
1224 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1225 | - || ! $post instanceof WP_Post |
|
1226 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1227 | - ) { |
|
1228 | - return $delete_link; |
|
1229 | - } |
|
1230 | - $this->_set_model_object($post->ID, true); |
|
1231 | - |
|
1232 | - // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1233 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1234 | - |
|
1235 | - return EE_Admin_Page::add_query_args_and_nonce( |
|
1236 | - array( |
|
1237 | - 'page' => $this->_req_data['page'], |
|
1238 | - 'action' => $action, |
|
1239 | - $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1240 | - => $post->ID, |
|
1241 | - ), |
|
1242 | - admin_url() |
|
1243 | - ); |
|
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1249 | - * so that we can hijack the default redirect locations for wp custom post types |
|
1250 | - * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1251 | - * |
|
1252 | - * @param string $location This is the incoming currently set redirect location |
|
1253 | - * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1254 | - * @return string the new location to redirect to |
|
1255 | - */ |
|
1256 | - public function cpt_post_location_redirect($location, $post_id) |
|
1257 | - { |
|
1258 | - // we DO have a match so let's setup the url |
|
1259 | - // we have to get the post to determine our route |
|
1260 | - $post = get_post($post_id); |
|
1261 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1262 | - // shared query_args |
|
1263 | - $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1264 | - $admin_url = $this->_admin_base_url; |
|
1265 | - if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1266 | - $status = get_post_status($post_id); |
|
1267 | - if (isset($this->_req_data['publish'])) { |
|
1268 | - switch ($status) { |
|
1269 | - case 'pending': |
|
1270 | - $message = 8; |
|
1271 | - break; |
|
1272 | - case 'future': |
|
1273 | - $message = 9; |
|
1274 | - break; |
|
1275 | - default: |
|
1276 | - $message = 6; |
|
1277 | - } |
|
1278 | - } else { |
|
1279 | - $message = 'draft' === $status ? 10 : 1; |
|
1280 | - } |
|
1281 | - } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1282 | - $message = 2; |
|
1283 | - } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1284 | - $message = 3; |
|
1285 | - } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1286 | - $message = 7; |
|
1287 | - } else { |
|
1288 | - $message = 4; |
|
1289 | - } |
|
1290 | - // change the message if the post type is not viewable on the frontend |
|
1291 | - $this->_cpt_object = get_post_type_object($post->post_type); |
|
1292 | - $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1293 | - $query_args = array_merge(array('message' => $message), $query_args); |
|
1294 | - $this->_process_notices($query_args, true); |
|
1295 | - return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1296 | - } |
|
1297 | - |
|
1298 | - |
|
1299 | - /** |
|
1300 | - * This method is called to inject nav tabs on core WP cpt pages |
|
1301 | - * |
|
1302 | - * @access public |
|
1303 | - * @return void |
|
1304 | - */ |
|
1305 | - public function inject_nav_tabs() |
|
1306 | - { |
|
1307 | - // can we hijack and insert the nav_tabs? |
|
1308 | - $nav_tabs = $this->_get_main_nav_tabs(); |
|
1309 | - // first close off existing form tag |
|
1310 | - $html = '>'; |
|
1311 | - $html .= $nav_tabs; |
|
1312 | - // now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1313 | - $html .= '<span></span'; |
|
1314 | - echo $html; |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * This just sets up the post update messages when an update form is loaded |
|
1320 | - * |
|
1321 | - * @access public |
|
1322 | - * @param array $messages the original messages array |
|
1323 | - * @return array the new messages array |
|
1324 | - */ |
|
1325 | - public function post_update_messages($messages) |
|
1326 | - { |
|
1327 | - global $post; |
|
1328 | - $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1329 | - $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1330 | - /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * This allows child classes to modify the default editor title that appears when people add a new or edit an |
|
1082 | + * existing CPT item. * This uses the _labels property set by the child class via _define_page_props. Just make |
|
1083 | + * sure you have a key in _labels property that equals 'editor_title' and the value can be whatever you want the |
|
1084 | + * default to be. |
|
1085 | + * |
|
1086 | + * @param string $title The new title (or existing if there is no editor_title defined) |
|
1087 | + * @return string |
|
1088 | + */ |
|
1089 | + public function add_custom_editor_default_title($title) |
|
1090 | + { |
|
1091 | + return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
1092 | + ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1093 | + : $title; |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * hooks into the wp_get_shortlink button and makes sure that the shortlink gets generated |
|
1099 | + * |
|
1100 | + * @param string $shortlink The already generated shortlink |
|
1101 | + * @param int $id Post ID for this item |
|
1102 | + * @param string $context The context for the link |
|
1103 | + * @param bool $allow_slugs Whether to allow post slugs in the shortlink. |
|
1104 | + * @return string |
|
1105 | + */ |
|
1106 | + public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
|
1107 | + { |
|
1108 | + if (! empty($id) && get_option('permalink_structure') !== '') { |
|
1109 | + $post = get_post($id); |
|
1110 | + if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
|
1111 | + $shortlink = home_url('?p=' . $post->ID); |
|
1112 | + } |
|
1113 | + } |
|
1114 | + return $shortlink; |
|
1115 | + } |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * overriding the parent route_admin_request method so we DON'T run the route twice on cpt core page loads (it's |
|
1120 | + * already run in modify_current_screen()) |
|
1121 | + * |
|
1122 | + * @return void |
|
1123 | + */ |
|
1124 | + public function route_admin_request() |
|
1125 | + { |
|
1126 | + if ($this->_cpt_route) { |
|
1127 | + return; |
|
1128 | + } |
|
1129 | + try { |
|
1130 | + $this->_route_admin_request(); |
|
1131 | + } catch (EE_Error $e) { |
|
1132 | + $e->get_error(); |
|
1133 | + } |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Add a hidden form input to cpt core pages so that we know to do redirects to our routes on saves |
|
1139 | + * |
|
1140 | + * @return void |
|
1141 | + */ |
|
1142 | + public function cpt_post_form_hidden_input() |
|
1143 | + { |
|
1144 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1145 | + // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
|
1146 | + echo '<div id="ee-cpt-hidden-inputs">'; |
|
1147 | + echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1148 | + echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1149 | + echo '</div>'; |
|
1150 | + } |
|
1151 | + |
|
1152 | + |
|
1153 | + /** |
|
1154 | + * This allows us to redirect the location of revision restores when they happen so it goes to our CPT routes. |
|
1155 | + * |
|
1156 | + * @param string $location Original location url |
|
1157 | + * @param int $status Status for http header |
|
1158 | + * @return string new (or original) url to redirect to. |
|
1159 | + */ |
|
1160 | + public function revision_redirect($location, $status) |
|
1161 | + { |
|
1162 | + // get revision |
|
1163 | + $rev_id = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
|
1164 | + // can't do anything without revision so let's get out if not present |
|
1165 | + if (empty($rev_id)) { |
|
1166 | + return $location; |
|
1167 | + } |
|
1168 | + // get rev_post_data |
|
1169 | + $rev = get_post($rev_id); |
|
1170 | + $admin_url = $this->_admin_base_url; |
|
1171 | + $query_args = array( |
|
1172 | + 'action' => 'edit', |
|
1173 | + 'post' => $rev->post_parent, |
|
1174 | + 'revision' => $rev_id, |
|
1175 | + 'message' => 5, |
|
1176 | + ); |
|
1177 | + $this->_process_notices($query_args, true); |
|
1178 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1179 | + } |
|
1180 | + |
|
1181 | + |
|
1182 | + /** |
|
1183 | + * Modify the edit post link generated by wp core function so that EE CPTs get setup differently. |
|
1184 | + * |
|
1185 | + * @param string $link the original generated link |
|
1186 | + * @param int $id post id |
|
1187 | + * @param string $context optional, defaults to display. How to write the '&' |
|
1188 | + * @return string the link |
|
1189 | + */ |
|
1190 | + public function modify_edit_post_link($link, $id, $context) |
|
1191 | + { |
|
1192 | + $post = get_post($id); |
|
1193 | + if (! isset($this->_req_data['action']) |
|
1194 | + || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1195 | + || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1196 | + ) { |
|
1197 | + return $link; |
|
1198 | + } |
|
1199 | + $query_args = array( |
|
1200 | + 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
1201 | + ? $this->_cpt_edit_routes[ $post->post_type ] |
|
1202 | + : 'edit', |
|
1203 | + 'post' => $id, |
|
1204 | + ); |
|
1205 | + return self::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
1206 | + } |
|
1207 | + |
|
1208 | + |
|
1209 | + /** |
|
1210 | + * Modify the trash link on our cpt edit pages so it has the required query var for triggering redirect properly on |
|
1211 | + * our routes. |
|
1212 | + * |
|
1213 | + * @param string $delete_link original delete link |
|
1214 | + * @param int $post_id id of cpt object |
|
1215 | + * @param bool $force_delete whether this is forcing a hard delete instead of trash |
|
1216 | + * @return string new delete link |
|
1217 | + * @throws EE_Error |
|
1218 | + */ |
|
1219 | + public function modify_delete_post_link($delete_link, $post_id, $force_delete) |
|
1220 | + { |
|
1221 | + $post = get_post($post_id); |
|
1222 | + |
|
1223 | + if (empty($this->_req_data['action']) |
|
1224 | + || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1225 | + || ! $post instanceof WP_Post |
|
1226 | + || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1227 | + ) { |
|
1228 | + return $delete_link; |
|
1229 | + } |
|
1230 | + $this->_set_model_object($post->ID, true); |
|
1231 | + |
|
1232 | + // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
|
1233 | + $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1234 | + |
|
1235 | + return EE_Admin_Page::add_query_args_and_nonce( |
|
1236 | + array( |
|
1237 | + 'page' => $this->_req_data['page'], |
|
1238 | + 'action' => $action, |
|
1239 | + $this->_cpt_model_obj->get_model()->get_primary_key_field()->get_name() |
|
1240 | + => $post->ID, |
|
1241 | + ), |
|
1242 | + admin_url() |
|
1243 | + ); |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * This is the callback for the 'redirect_post_location' filter in wp-admin/post.php |
|
1249 | + * so that we can hijack the default redirect locations for wp custom post types |
|
1250 | + * that WE'RE using and send back to OUR routes. This should only be hooked in on the right route. |
|
1251 | + * |
|
1252 | + * @param string $location This is the incoming currently set redirect location |
|
1253 | + * @param string $post_id This is the 'ID' value of the wp_posts table |
|
1254 | + * @return string the new location to redirect to |
|
1255 | + */ |
|
1256 | + public function cpt_post_location_redirect($location, $post_id) |
|
1257 | + { |
|
1258 | + // we DO have a match so let's setup the url |
|
1259 | + // we have to get the post to determine our route |
|
1260 | + $post = get_post($post_id); |
|
1261 | + $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1262 | + // shared query_args |
|
1263 | + $query_args = array('action' => $edit_route, 'post' => $post_id); |
|
1264 | + $admin_url = $this->_admin_base_url; |
|
1265 | + if (isset($this->_req_data['save']) || isset($this->_req_data['publish'])) { |
|
1266 | + $status = get_post_status($post_id); |
|
1267 | + if (isset($this->_req_data['publish'])) { |
|
1268 | + switch ($status) { |
|
1269 | + case 'pending': |
|
1270 | + $message = 8; |
|
1271 | + break; |
|
1272 | + case 'future': |
|
1273 | + $message = 9; |
|
1274 | + break; |
|
1275 | + default: |
|
1276 | + $message = 6; |
|
1277 | + } |
|
1278 | + } else { |
|
1279 | + $message = 'draft' === $status ? 10 : 1; |
|
1280 | + } |
|
1281 | + } elseif (isset($this->_req_data['addmeta']) && $this->_req_data['addmeta']) { |
|
1282 | + $message = 2; |
|
1283 | + } elseif (isset($this->_req_data['deletemeta']) && $this->_req_data['deletemeta']) { |
|
1284 | + $message = 3; |
|
1285 | + } elseif ($this->_req_data['action'] === 'post-quickpress-save-cont') { |
|
1286 | + $message = 7; |
|
1287 | + } else { |
|
1288 | + $message = 4; |
|
1289 | + } |
|
1290 | + // change the message if the post type is not viewable on the frontend |
|
1291 | + $this->_cpt_object = get_post_type_object($post->post_type); |
|
1292 | + $message = $message === 1 && ! $this->_cpt_object->publicly_queryable ? 4 : $message; |
|
1293 | + $query_args = array_merge(array('message' => $message), $query_args); |
|
1294 | + $this->_process_notices($query_args, true); |
|
1295 | + return self::add_query_args_and_nonce($query_args, $admin_url); |
|
1296 | + } |
|
1297 | + |
|
1298 | + |
|
1299 | + /** |
|
1300 | + * This method is called to inject nav tabs on core WP cpt pages |
|
1301 | + * |
|
1302 | + * @access public |
|
1303 | + * @return void |
|
1304 | + */ |
|
1305 | + public function inject_nav_tabs() |
|
1306 | + { |
|
1307 | + // can we hijack and insert the nav_tabs? |
|
1308 | + $nav_tabs = $this->_get_main_nav_tabs(); |
|
1309 | + // first close off existing form tag |
|
1310 | + $html = '>'; |
|
1311 | + $html .= $nav_tabs; |
|
1312 | + // now let's handle the remaining tag ( missing ">" is CORRECT ) |
|
1313 | + $html .= '<span></span'; |
|
1314 | + echo $html; |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + /** |
|
1319 | + * This just sets up the post update messages when an update form is loaded |
|
1320 | + * |
|
1321 | + * @access public |
|
1322 | + * @param array $messages the original messages array |
|
1323 | + * @return array the new messages array |
|
1324 | + */ |
|
1325 | + public function post_update_messages($messages) |
|
1326 | + { |
|
1327 | + global $post; |
|
1328 | + $id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1329 | + $id = empty($id) && is_object($post) ? $post->ID : null; |
|
1330 | + /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
|
1331 | 1331 | |
1332 | 1332 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1333 | - $messages[ $post->post_type ] = array( |
|
1334 | - 0 => '', // Unused. Messages start at index 1. |
|
1335 | - 1 => sprintf( |
|
1336 | - __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1337 | - $this->_cpt_object->labels->singular_name, |
|
1338 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1339 | - '</a>' |
|
1340 | - ), |
|
1341 | - 2 => __('Custom field updated', 'event_espresso'), |
|
1342 | - 3 => __('Custom field deleted.', 'event_espresso'), |
|
1343 | - 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1344 | - 5 => isset($_GET['revision']) ? sprintf( |
|
1345 | - __('%s restored to revision from %s', 'event_espresso'), |
|
1346 | - $this->_cpt_object->labels->singular_name, |
|
1347 | - wp_post_revision_title((int) $_GET['revision'], false) |
|
1348 | - ) |
|
1349 | - : false, |
|
1350 | - 6 => sprintf( |
|
1351 | - __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1352 | - $this->_cpt_object->labels->singular_name, |
|
1353 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1354 | - '</a>' |
|
1355 | - ), |
|
1356 | - 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1357 | - 8 => sprintf( |
|
1358 | - __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1359 | - $this->_cpt_object->labels->singular_name, |
|
1360 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1361 | - '</a>' |
|
1362 | - ), |
|
1363 | - 9 => sprintf( |
|
1364 | - __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1365 | - $this->_cpt_object->labels->singular_name, |
|
1366 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1367 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1368 | - '</a>' |
|
1369 | - ), |
|
1370 | - 10 => sprintf( |
|
1371 | - __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1372 | - $this->_cpt_object->labels->singular_name, |
|
1373 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1374 | - '</a>' |
|
1375 | - ), |
|
1376 | - ); |
|
1377 | - return $messages; |
|
1378 | - } |
|
1379 | - |
|
1380 | - |
|
1381 | - /** |
|
1382 | - * default method for the 'create_new' route for cpt admin pages. |
|
1383 | - * For reference what to include in here, see wp-admin/post-new.php |
|
1384 | - * |
|
1385 | - * @access protected |
|
1386 | - * @return void |
|
1387 | - */ |
|
1388 | - protected function _create_new_cpt_item() |
|
1389 | - { |
|
1390 | - // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1391 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1392 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1393 | - $post_type_object = $this->_cpt_object; |
|
1394 | - $title = $post_type_object->labels->add_new_item; |
|
1395 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1396 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1397 | - // modify the default editor title field with default title. |
|
1398 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1399 | - $this->loadEditorTemplate(true); |
|
1400 | - } |
|
1401 | - |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * Enqueues auto-save and loads the editor template |
|
1405 | - * |
|
1406 | - * @param bool $creating |
|
1407 | - */ |
|
1408 | - private function loadEditorTemplate($creating = true) |
|
1409 | - { |
|
1410 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1411 | - // these vars are used by the template |
|
1412 | - $editing = true; |
|
1413 | - $post_ID = $post->ID; |
|
1414 | - if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1415 | - // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1416 | - // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1417 | - if ($creating) { |
|
1418 | - wp_enqueue_script('autosave'); |
|
1419 | - } else { |
|
1420 | - if (isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1421 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
1422 | - ) { |
|
1423 | - $create_new_action = apply_filters( |
|
1424 | - 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1425 | - 'create_new', |
|
1426 | - $this |
|
1427 | - ); |
|
1428 | - $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
1429 | - array( |
|
1430 | - 'action' => $create_new_action, |
|
1431 | - 'page' => $this->page_slug, |
|
1432 | - ), |
|
1433 | - 'admin.php' |
|
1434 | - ); |
|
1435 | - } |
|
1436 | - } |
|
1437 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1438 | - } |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - public function add_new_admin_page_global() |
|
1443 | - { |
|
1444 | - $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1445 | - ?> |
|
1333 | + $messages[ $post->post_type ] = array( |
|
1334 | + 0 => '', // Unused. Messages start at index 1. |
|
1335 | + 1 => sprintf( |
|
1336 | + __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
|
1337 | + $this->_cpt_object->labels->singular_name, |
|
1338 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1339 | + '</a>' |
|
1340 | + ), |
|
1341 | + 2 => __('Custom field updated', 'event_espresso'), |
|
1342 | + 3 => __('Custom field deleted.', 'event_espresso'), |
|
1343 | + 4 => sprintf(__('%1$s updated.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1344 | + 5 => isset($_GET['revision']) ? sprintf( |
|
1345 | + __('%s restored to revision from %s', 'event_espresso'), |
|
1346 | + $this->_cpt_object->labels->singular_name, |
|
1347 | + wp_post_revision_title((int) $_GET['revision'], false) |
|
1348 | + ) |
|
1349 | + : false, |
|
1350 | + 6 => sprintf( |
|
1351 | + __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
|
1352 | + $this->_cpt_object->labels->singular_name, |
|
1353 | + '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1354 | + '</a>' |
|
1355 | + ), |
|
1356 | + 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
|
1357 | + 8 => sprintf( |
|
1358 | + __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
|
1359 | + $this->_cpt_object->labels->singular_name, |
|
1360 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1361 | + '</a>' |
|
1362 | + ), |
|
1363 | + 9 => sprintf( |
|
1364 | + __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
|
1365 | + $this->_cpt_object->labels->singular_name, |
|
1366 | + '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1367 | + '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1368 | + '</a>' |
|
1369 | + ), |
|
1370 | + 10 => sprintf( |
|
1371 | + __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
|
1372 | + $this->_cpt_object->labels->singular_name, |
|
1373 | + '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1374 | + '</a>' |
|
1375 | + ), |
|
1376 | + ); |
|
1377 | + return $messages; |
|
1378 | + } |
|
1379 | + |
|
1380 | + |
|
1381 | + /** |
|
1382 | + * default method for the 'create_new' route for cpt admin pages. |
|
1383 | + * For reference what to include in here, see wp-admin/post-new.php |
|
1384 | + * |
|
1385 | + * @access protected |
|
1386 | + * @return void |
|
1387 | + */ |
|
1388 | + protected function _create_new_cpt_item() |
|
1389 | + { |
|
1390 | + // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1391 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1392 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1393 | + $post_type_object = $this->_cpt_object; |
|
1394 | + $title = $post_type_object->labels->add_new_item; |
|
1395 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1396 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1397 | + // modify the default editor title field with default title. |
|
1398 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1399 | + $this->loadEditorTemplate(true); |
|
1400 | + } |
|
1401 | + |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * Enqueues auto-save and loads the editor template |
|
1405 | + * |
|
1406 | + * @param bool $creating |
|
1407 | + */ |
|
1408 | + private function loadEditorTemplate($creating = true) |
|
1409 | + { |
|
1410 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1411 | + // these vars are used by the template |
|
1412 | + $editing = true; |
|
1413 | + $post_ID = $post->ID; |
|
1414 | + if (apply_filters('FHEE__EE_Admin_Page_CPT___create_new_cpt_item__replace_editor', false, $post) === false) { |
|
1415 | + // only enqueue autosave when creating event (necessary to get permalink/url generated) |
|
1416 | + // otherwise EE doesn't support autosave fully, so to prevent user confusion we disable it in edit context. |
|
1417 | + if ($creating) { |
|
1418 | + wp_enqueue_script('autosave'); |
|
1419 | + } else { |
|
1420 | + if (isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1421 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
1422 | + ) { |
|
1423 | + $create_new_action = apply_filters( |
|
1424 | + 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
|
1425 | + 'create_new', |
|
1426 | + $this |
|
1427 | + ); |
|
1428 | + $post_new_file = EE_Admin_Page::add_query_args_and_nonce( |
|
1429 | + array( |
|
1430 | + 'action' => $create_new_action, |
|
1431 | + 'page' => $this->page_slug, |
|
1432 | + ), |
|
1433 | + 'admin.php' |
|
1434 | + ); |
|
1435 | + } |
|
1436 | + } |
|
1437 | + include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1438 | + } |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + public function add_new_admin_page_global() |
|
1443 | + { |
|
1444 | + $admin_page = ! empty($this->_req_data['post']) ? 'post-php' : 'post-new-php'; |
|
1445 | + ?> |
|
1446 | 1446 | <script type="text/javascript"> |
1447 | 1447 | adminpage = '<?php echo $admin_page; ?>'; |
1448 | 1448 | </script> |
1449 | 1449 | <?php |
1450 | - } |
|
1451 | - |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * default method for the 'edit' route for cpt admin pages |
|
1455 | - * For reference on what to put in here, refer to wp-admin/post.php |
|
1456 | - * |
|
1457 | - * @access protected |
|
1458 | - * @return string template for edit cpt form |
|
1459 | - */ |
|
1460 | - protected function _edit_cpt_item() |
|
1461 | - { |
|
1462 | - global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1463 | - $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1464 | - $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1465 | - if (empty($post)) { |
|
1466 | - wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', 'event_espresso')); |
|
1467 | - } |
|
1468 | - if (! empty($_GET['get-post-lock'])) { |
|
1469 | - wp_set_post_lock($post_id); |
|
1470 | - wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1471 | - exit(); |
|
1472 | - } |
|
1473 | - |
|
1474 | - // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1475 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1476 | - $post_type_object = $this->_cpt_object; |
|
1477 | - |
|
1478 | - if (! wp_check_post_lock($post->ID)) { |
|
1479 | - wp_set_post_lock($post->ID); |
|
1480 | - } |
|
1481 | - add_action('admin_footer', '_admin_notice_post_locked'); |
|
1482 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1483 | - wp_enqueue_script('admin-comments'); |
|
1484 | - enqueue_comment_hotkeys_js(); |
|
1485 | - } |
|
1486 | - add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1487 | - // modify the default editor title field with default title. |
|
1488 | - add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1489 | - $this->loadEditorTemplate(false); |
|
1490 | - } |
|
1491 | - |
|
1492 | - |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * some getters |
|
1496 | - */ |
|
1497 | - /** |
|
1498 | - * This returns the protected _cpt_model_obj property |
|
1499 | - * |
|
1500 | - * @return EE_CPT_Base |
|
1501 | - */ |
|
1502 | - public function get_cpt_model_obj() |
|
1503 | - { |
|
1504 | - return $this->_cpt_model_obj; |
|
1505 | - } |
|
1450 | + } |
|
1451 | + |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * default method for the 'edit' route for cpt admin pages |
|
1455 | + * For reference on what to put in here, refer to wp-admin/post.php |
|
1456 | + * |
|
1457 | + * @access protected |
|
1458 | + * @return string template for edit cpt form |
|
1459 | + */ |
|
1460 | + protected function _edit_cpt_item() |
|
1461 | + { |
|
1462 | + global $post, $title, $is_IE, $post_type, $post_type_object; |
|
1463 | + $post_id = isset($this->_req_data['post']) ? $this->_req_data['post'] : null; |
|
1464 | + $post = ! empty($post_id) ? get_post($post_id, OBJECT, 'edit') : null; |
|
1465 | + if (empty($post)) { |
|
1466 | + wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', 'event_espresso')); |
|
1467 | + } |
|
1468 | + if (! empty($_GET['get-post-lock'])) { |
|
1469 | + wp_set_post_lock($post_id); |
|
1470 | + wp_redirect(get_edit_post_link($post_id, 'url')); |
|
1471 | + exit(); |
|
1472 | + } |
|
1473 | + |
|
1474 | + // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
|
1475 | + $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1476 | + $post_type_object = $this->_cpt_object; |
|
1477 | + |
|
1478 | + if (! wp_check_post_lock($post->ID)) { |
|
1479 | + wp_set_post_lock($post->ID); |
|
1480 | + } |
|
1481 | + add_action('admin_footer', '_admin_notice_post_locked'); |
|
1482 | + if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1483 | + wp_enqueue_script('admin-comments'); |
|
1484 | + enqueue_comment_hotkeys_js(); |
|
1485 | + } |
|
1486 | + add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
|
1487 | + // modify the default editor title field with default title. |
|
1488 | + add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
|
1489 | + $this->loadEditorTemplate(false); |
|
1490 | + } |
|
1491 | + |
|
1492 | + |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * some getters |
|
1496 | + */ |
|
1497 | + /** |
|
1498 | + * This returns the protected _cpt_model_obj property |
|
1499 | + * |
|
1500 | + * @return EE_CPT_Base |
|
1501 | + */ |
|
1502 | + public function get_cpt_model_obj() |
|
1503 | + { |
|
1504 | + return $this->_cpt_model_obj; |
|
1505 | + } |
|
1506 | 1506 | } |
@@ -169,11 +169,11 @@ discard block |
||
169 | 169 | $this->_cpt_routes |
170 | 170 | ); |
171 | 171 | // let's see if the current route has a value for cpt_object_slug if it does we use that instead of the page |
172 | - $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
173 | - ? get_post_type_object($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
172 | + $this->_cpt_object = isset($this->_req_data['action']) && isset($this->_cpt_routes[$this->_req_data['action']]) |
|
173 | + ? get_post_type_object($this->_cpt_routes[$this->_req_data['action']]) |
|
174 | 174 | : get_post_type_object($page); |
175 | 175 | // tweak pagenow for page loading. |
176 | - if (! $this->_pagenow_map) { |
|
176 | + if ( ! $this->_pagenow_map) { |
|
177 | 177 | $this->_pagenow_map = array( |
178 | 178 | 'create_new' => 'post-new.php', |
179 | 179 | 'edit' => 'post.php', |
@@ -207,12 +207,12 @@ discard block |
||
207 | 207 | { |
208 | 208 | global $pagenow, $hook_suffix; |
209 | 209 | // possibly reset pagenow. |
210 | - if (! empty($this->_req_data['page']) |
|
210 | + if ( ! empty($this->_req_data['page']) |
|
211 | 211 | && $this->_req_data['page'] == $this->page_slug |
212 | 212 | && ! empty($this->_req_data['action']) |
213 | - && isset($this->_pagenow_map[ $this->_req_data['action'] ]) |
|
213 | + && isset($this->_pagenow_map[$this->_req_data['action']]) |
|
214 | 214 | ) { |
215 | - $pagenow = $this->_pagenow_map[ $this->_req_data['action'] ]; |
|
215 | + $pagenow = $this->_pagenow_map[$this->_req_data['action']]; |
|
216 | 216 | $hook_suffix = $pagenow; |
217 | 217 | } |
218 | 218 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | if (empty($wp_meta_boxes)) { |
245 | 245 | return; |
246 | 246 | } |
247 | - $current_metaboxes = isset($wp_meta_boxes[ $this->page_slug ]) ? $wp_meta_boxes[ $this->page_slug ] : array(); |
|
247 | + $current_metaboxes = isset($wp_meta_boxes[$this->page_slug]) ? $wp_meta_boxes[$this->page_slug] : array(); |
|
248 | 248 | foreach ($current_metaboxes as $box_context) { |
249 | 249 | foreach ($box_context as $box_details) { |
250 | 250 | foreach ($box_details as $box) { |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $this |
278 | 278 | ); |
279 | 279 | $containers = apply_filters( |
280 | - 'FHEE__EE_Admin_Page_CPT__' . get_class($this) . '___load_autosave_scripts_styles__containers', |
|
280 | + 'FHEE__EE_Admin_Page_CPT__'.get_class($this).'___load_autosave_scripts_styles__containers', |
|
281 | 281 | $containers, |
282 | 282 | $this |
283 | 283 | ); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | protected function _load_page_dependencies() |
322 | 322 | { |
323 | 323 | // we only add stuff if this is a cpt_route! |
324 | - if (! $this->_cpt_route) { |
|
324 | + if ( ! $this->_cpt_route) { |
|
325 | 325 | parent::_load_page_dependencies(); |
326 | 326 | return; |
327 | 327 | } |
@@ -345,16 +345,16 @@ discard block |
||
345 | 345 | add_filter('pre_get_shortlink', array($this, 'add_shortlink_button_to_editor'), 10, 4); |
346 | 346 | // This basically allows us to change the title of the "publish" metabox area |
347 | 347 | // on CPT pages by setting a 'publishbox' value in the $_labels property array in the child class. |
348 | - if (! empty($this->_labels['publishbox'])) { |
|
348 | + if ( ! empty($this->_labels['publishbox'])) { |
|
349 | 349 | $box_label = is_array($this->_labels['publishbox']) |
350 | - && isset($this->_labels['publishbox'][ $this->_req_action ]) |
|
351 | - ? $this->_labels['publishbox'][ $this->_req_action ] |
|
350 | + && isset($this->_labels['publishbox'][$this->_req_action]) |
|
351 | + ? $this->_labels['publishbox'][$this->_req_action] |
|
352 | 352 | : $this->_labels['publishbox']; |
353 | 353 | add_meta_box( |
354 | 354 | 'submitdiv', |
355 | 355 | $box_label, |
356 | 356 | 'post_submit_meta_box', |
357 | - $this->_cpt_routes[ $this->_req_action ], |
|
357 | + $this->_cpt_routes[$this->_req_action], |
|
358 | 358 | 'side', |
359 | 359 | 'core' |
360 | 360 | ); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | 'page_templates', |
366 | 366 | __('Page Template', 'event_espresso'), |
367 | 367 | array($this, 'page_template_meta_box'), |
368 | - $this->_cpt_routes[ $this->_req_action ], |
|
368 | + $this->_cpt_routes[$this->_req_action], |
|
369 | 369 | 'side', |
370 | 370 | 'default' |
371 | 371 | ); |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | // This is for any plugins that are doing things properly |
398 | 398 | // and hooking into the load page hook for core wp cpt routes. |
399 | 399 | global $pagenow; |
400 | - do_action('load-' . $pagenow); |
|
400 | + do_action('load-'.$pagenow); |
|
401 | 401 | $this->modify_current_screen(); |
402 | 402 | add_action('admin_enqueue_scripts', array($this, 'setup_autosave_hooks'), 30); |
403 | 403 | // we route REALLY early. |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | 'admin.php?page=espresso_registrations&action=contact_list', |
428 | 428 | ), |
429 | 429 | 1 => array( |
430 | - 'edit.php?post_type=' . $this->_cpt_object->name, |
|
431 | - 'admin.php?page=' . $this->_cpt_object->name, |
|
430 | + 'edit.php?post_type='.$this->_cpt_object->name, |
|
431 | + 'admin.php?page='.$this->_cpt_object->name, |
|
432 | 432 | ), |
433 | 433 | ); |
434 | 434 | foreach ($routes_to_match as $route_matches) { |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
458 | 458 | ); |
459 | 459 | $cpt_args = $custom_post_types->getDefinitions(); |
460 | - $cpt_args = isset($cpt_args[ $cpt_name ]) ? $cpt_args[ $cpt_name ]['args'] : array(); |
|
460 | + $cpt_args = isset($cpt_args[$cpt_name]) ? $cpt_args[$cpt_name]['args'] : array(); |
|
461 | 461 | $cpt_has_support = ! empty($cpt_args['page_templates']); |
462 | 462 | |
463 | 463 | // if the installed version of WP is > 4.7 we do some additional checks. |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | // if there are $post_templates for this cpt, then we return false for this method because |
467 | 467 | // that means we aren't going to load our page template manager and leave that up to the native |
468 | 468 | // cpt template manager. |
469 | - $cpt_has_support = ! isset($post_templates[ $cpt_name ]) ? $cpt_has_support : false; |
|
469 | + $cpt_has_support = ! isset($post_templates[$cpt_name]) ? $cpt_has_support : false; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | return $cpt_has_support; |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | $post = get_post($id); |
521 | 521 | if ('publish' !== get_post_status($post)) { |
522 | 522 | // include shims for the `get_preview_post_link` function |
523 | - require_once(EE_CORE . 'wordpress-shims.php'); |
|
523 | + require_once(EE_CORE.'wordpress-shims.php'); |
|
524 | 524 | $return .= '<span_id="view-post-btn"><a target="_blank" href="' |
525 | 525 | . get_preview_post_link($id) |
526 | 526 | . '" class="button button-small">' |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | |
543 | 543 | $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
544 | 544 | $cur_status_label = array_key_exists($this->_cpt_model_obj->status(), $statuses) |
545 | - ? $statuses[ $this->_cpt_model_obj->status() ] |
|
545 | + ? $statuses[$this->_cpt_model_obj->status()] |
|
546 | 546 | : ''; |
547 | 547 | $template_args = array( |
548 | 548 | 'cur_status' => $this->_cpt_model_obj->status(), |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $template_args['statuses'] = $statuses; |
558 | 558 | } |
559 | 559 | |
560 | - $template = EE_ADMIN_TEMPLATE . 'status_dropdown.template.php'; |
|
560 | + $template = EE_ADMIN_TEMPLATE.'status_dropdown.template.php'; |
|
561 | 561 | EEH_Template::display_template($template, $template_args); |
562 | 562 | } |
563 | 563 | |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | : null; |
599 | 599 | $this->_verify_nonce($nonce, 'autosave'); |
600 | 600 | // make sure we define doing autosave (cause WP isn't triggering this we want to make sure we define it) |
601 | - if (! defined('DOING_AUTOSAVE')) { |
|
601 | + if ( ! defined('DOING_AUTOSAVE')) { |
|
602 | 602 | define('DOING_AUTOSAVE', true); |
603 | 603 | } |
604 | 604 | // if we made it here then the nonce checked out. Let's run our methods and actions |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | $this->_template_args['success'] = true; |
610 | 610 | } |
611 | 611 | do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__global_after', $this); |
612 | - do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_' . get_class($this), $this); |
|
612 | + do_action('AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_'.get_class($this), $this); |
|
613 | 613 | // now let's return json |
614 | 614 | $this->_return_json(); |
615 | 615 | } |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | return; |
632 | 632 | } |
633 | 633 | // set page routes and page config but ONLY if we're not viewing a custom setup cpt route as defined in _cpt_routes |
634 | - if (! empty($this->_cpt_object)) { |
|
634 | + if ( ! empty($this->_cpt_object)) { |
|
635 | 635 | $this->_page_routes = array_merge( |
636 | 636 | array( |
637 | 637 | 'create_new' => '_create_new_cpt_item', |
@@ -662,10 +662,10 @@ discard block |
||
662 | 662 | ); |
663 | 663 | } |
664 | 664 | // load the next section only if this is a matching cpt route as set in the cpt routes array. |
665 | - if (! isset($this->_cpt_routes[ $this->_req_action ])) { |
|
665 | + if ( ! isset($this->_cpt_routes[$this->_req_action])) { |
|
666 | 666 | return; |
667 | 667 | } |
668 | - $this->_cpt_route = isset($this->_cpt_routes[ $this->_req_action ]) ? true : false; |
|
668 | + $this->_cpt_route = isset($this->_cpt_routes[$this->_req_action]) ? true : false; |
|
669 | 669 | // add_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', array( $this, 'modify_current_screen') ); |
670 | 670 | if (empty($this->_cpt_object)) { |
671 | 671 | $msg = sprintf( |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | if (empty($this->_cpt_model_names) |
706 | 706 | || ( |
707 | 707 | ! $ignore_route_check |
708 | - && ! isset($this->_cpt_routes[ $this->_req_action ]) |
|
708 | + && ! isset($this->_cpt_routes[$this->_req_action]) |
|
709 | 709 | ) || ( |
710 | 710 | $this->_cpt_model_obj instanceof EE_CPT_Base |
711 | 711 | && $this->_cpt_model_obj->ID() === $id |
@@ -722,11 +722,11 @@ discard block |
||
722 | 722 | 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
723 | 723 | ); |
724 | 724 | $model_names = $custom_post_types->getCustomPostTypeModelNames($post_type); |
725 | - if (isset($model_names[ $post_type ])) { |
|
726 | - $model = EE_Registry::instance()->load_model($model_names[ $post_type ]); |
|
725 | + if (isset($model_names[$post_type])) { |
|
726 | + $model = EE_Registry::instance()->load_model($model_names[$post_type]); |
|
727 | 727 | } |
728 | 728 | } else { |
729 | - $model = EE_Registry::instance()->load_model($this->_cpt_model_names[ $this->_req_action ]); |
|
729 | + $model = EE_Registry::instance()->load_model($this->_cpt_model_names[$this->_req_action]); |
|
730 | 730 | } |
731 | 731 | if ($model instanceof EEM_Base) { |
732 | 732 | $this->_cpt_model_obj = ! empty($id) ? $model->get_one_by_ID($id) : $model->create_default_object(); |
@@ -756,8 +756,8 @@ discard block |
||
756 | 756 | $current_route = isset($this->_req_data['current_route']) |
757 | 757 | ? $this->_req_data['current_route'] |
758 | 758 | : 'shouldneverwork'; |
759 | - $route_to_check = $post_type && isset($this->_cpt_routes[ $current_route ]) |
|
760 | - ? $this->_cpt_routes[ $current_route ] |
|
759 | + $route_to_check = $post_type && isset($this->_cpt_routes[$current_route]) |
|
760 | + ? $this->_cpt_routes[$current_route] |
|
761 | 761 | : ''; |
762 | 762 | add_filter('get_delete_post_link', array($this, 'modify_delete_post_link'), 10, 3); |
763 | 763 | add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 3); |
@@ -766,10 +766,10 @@ discard block |
||
766 | 766 | } |
767 | 767 | // now let's filter redirect if we're on a revision page and the revision is for an event CPT. |
768 | 768 | $revision = isset($this->_req_data['revision']) ? $this->_req_data['revision'] : null; |
769 | - if (! empty($revision)) { |
|
769 | + if ( ! empty($revision)) { |
|
770 | 770 | $action = isset($this->_req_data['action']) ? $this->_req_data['action'] : null; |
771 | 771 | // doing a restore? |
772 | - if (! empty($action) && $action === 'restore') { |
|
772 | + if ( ! empty($action) && $action === 'restore') { |
|
773 | 773 | // get post for revision |
774 | 774 | $rev_post = get_post($revision); |
775 | 775 | $rev_parent = get_post($rev_post->post_parent); |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | { |
806 | 806 | $this->_set_model_object($post_id, true, 'trash'); |
807 | 807 | // if our cpt object isn't existent then get out immediately. |
808 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
808 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
809 | 809 | return; |
810 | 810 | } |
811 | 811 | $this->trash_cpt_item($post_id); |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | { |
824 | 824 | $this->_set_model_object($post_id, true, 'restore'); |
825 | 825 | // if our cpt object isn't existent then get out immediately. |
826 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
826 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
827 | 827 | return; |
828 | 828 | } |
829 | 829 | $this->restore_cpt_item($post_id); |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | { |
842 | 842 | $this->_set_model_object($post_id, true, 'delete'); |
843 | 843 | // if our cpt object isn't existent then get out immediately. |
844 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
844 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base || $this->_cpt_model_obj->ID() !== $post_id) { |
|
845 | 845 | return; |
846 | 846 | } |
847 | 847 | $this->delete_cpt_item($post_id); |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | { |
861 | 861 | $label = ! empty($this->_cpt_object) ? $this->_cpt_object->labels->singular_name : $this->page_label; |
862 | 862 | // verify event object |
863 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
863 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
864 | 864 | throw new EE_Error( |
865 | 865 | sprintf( |
866 | 866 | __( |
@@ -916,13 +916,13 @@ discard block |
||
916 | 916 | if ($this->_cpt_model_obj instanceof EE_CPT_Base) { |
917 | 917 | // setup custom post status object for localize script but only if we've got a cpt object |
918 | 918 | $statuses = $this->_cpt_model_obj->get_custom_post_statuses(); |
919 | - if (! empty($statuses)) { |
|
919 | + if ( ! empty($statuses)) { |
|
920 | 920 | // get ALL statuses! |
921 | 921 | $statuses = $this->_cpt_model_obj->get_all_post_statuses(); |
922 | 922 | // setup object |
923 | 923 | $ee_cpt_statuses = array(); |
924 | 924 | foreach ($statuses as $status => $label) { |
925 | - $ee_cpt_statuses[ $status ] = array( |
|
925 | + $ee_cpt_statuses[$status] = array( |
|
926 | 926 | 'label' => $label, |
927 | 927 | 'save_label' => sprintf(__('Save as %s', 'event_espresso'), $label), |
928 | 928 | ); |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | $post->page_template = $this->_req_data['page_template']; |
985 | 985 | $page_templates = wp_get_theme()->get_page_templates($post); |
986 | 986 | } |
987 | - if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[ $this->_req_data['page_template'] ])) { |
|
987 | + if ('default' != $this->_req_data['page_template'] && ! isset($page_templates[$this->_req_data['page_template']])) { |
|
988 | 988 | EE_Error::add_error(__('Invalid Page Template.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
989 | 989 | } else { |
990 | 990 | update_post_meta($post_id, '_wp_page_template', $this->_req_data['page_template']); |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | { |
1010 | 1010 | // only do this if we're actually processing one of our CPTs |
1011 | 1011 | // if our cpt object isn't existent then get out immediately. |
1012 | - if (! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1012 | + if ( ! $this->_cpt_model_obj instanceof EE_CPT_Base) { |
|
1013 | 1013 | return; |
1014 | 1014 | } |
1015 | 1015 | delete_post_meta($post_id, '_wp_trash_meta_status'); |
@@ -1034,7 +1034,7 @@ discard block |
||
1034 | 1034 | // global action |
1035 | 1035 | do_action('AHEE_EE_Admin_Page_CPT__restore_revision', $post_id, $revision_id); |
1036 | 1036 | // class specific action so you can limit hooking into a specific page. |
1037 | - do_action('AHEE_EE_Admin_Page_CPT_' . get_class($this) . '__restore_revision', $post_id, $revision_id); |
|
1037 | + do_action('AHEE_EE_Admin_Page_CPT_'.get_class($this).'__restore_revision', $post_id, $revision_id); |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
@@ -1061,11 +1061,11 @@ discard block |
||
1061 | 1061 | public function modify_current_screen() |
1062 | 1062 | { |
1063 | 1063 | // ONLY do this if the current page_route IS a cpt route |
1064 | - if (! $this->_cpt_route) { |
|
1064 | + if ( ! $this->_cpt_route) { |
|
1065 | 1065 | return; |
1066 | 1066 | } |
1067 | 1067 | // routing things REALLY early b/c this is a cpt admin page |
1068 | - set_current_screen($this->_cpt_routes[ $this->_req_action ]); |
|
1068 | + set_current_screen($this->_cpt_routes[$this->_req_action]); |
|
1069 | 1069 | $this->_current_screen = get_current_screen(); |
1070 | 1070 | $this->_current_screen->base = 'event-espresso'; |
1071 | 1071 | $this->_add_help_tabs(); // we make sure we add any help tabs back in! |
@@ -1088,8 +1088,8 @@ discard block |
||
1088 | 1088 | */ |
1089 | 1089 | public function add_custom_editor_default_title($title) |
1090 | 1090 | { |
1091 | - return isset($this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ]) |
|
1092 | - ? $this->_labels['editor_title'][ $this->_cpt_routes[ $this->_req_action ] ] |
|
1091 | + return isset($this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]]) |
|
1092 | + ? $this->_labels['editor_title'][$this->_cpt_routes[$this->_req_action]] |
|
1093 | 1093 | : $title; |
1094 | 1094 | } |
1095 | 1095 | |
@@ -1105,10 +1105,10 @@ discard block |
||
1105 | 1105 | */ |
1106 | 1106 | public function add_shortlink_button_to_editor($shortlink, $id, $context, $allow_slugs) |
1107 | 1107 | { |
1108 | - if (! empty($id) && get_option('permalink_structure') !== '') { |
|
1108 | + if ( ! empty($id) && get_option('permalink_structure') !== '') { |
|
1109 | 1109 | $post = get_post($id); |
1110 | 1110 | if (isset($post->post_type) && $this->page_slug === $post->post_type) { |
1111 | - $shortlink = home_url('?p=' . $post->ID); |
|
1111 | + $shortlink = home_url('?p='.$post->ID); |
|
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | return $shortlink; |
@@ -1141,11 +1141,11 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | public function cpt_post_form_hidden_input() |
1143 | 1143 | { |
1144 | - echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="' . $this->_admin_base_url . '" />'; |
|
1144 | + echo '<input type="hidden" name="ee_cpt_item_redirect_url" value="'.$this->_admin_base_url.'" />'; |
|
1145 | 1145 | // we're also going to add the route value and the current page so we can direct autosave parsing correctly |
1146 | 1146 | echo '<div id="ee-cpt-hidden-inputs">'; |
1147 | - echo '<input type="hidden" id="current_route" name="current_route" value="' . $this->_current_view . '" />'; |
|
1148 | - echo '<input type="hidden" id="current_page" name="current_page" value="' . $this->page_slug . '" />'; |
|
1147 | + echo '<input type="hidden" id="current_route" name="current_route" value="'.$this->_current_view.'" />'; |
|
1148 | + echo '<input type="hidden" id="current_page" name="current_page" value="'.$this->page_slug.'" />'; |
|
1149 | 1149 | echo '</div>'; |
1150 | 1150 | } |
1151 | 1151 | |
@@ -1190,15 +1190,15 @@ discard block |
||
1190 | 1190 | public function modify_edit_post_link($link, $id, $context) |
1191 | 1191 | { |
1192 | 1192 | $post = get_post($id); |
1193 | - if (! isset($this->_req_data['action']) |
|
1194 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1195 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1193 | + if ( ! isset($this->_req_data['action']) |
|
1194 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1195 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1196 | 1196 | ) { |
1197 | 1197 | return $link; |
1198 | 1198 | } |
1199 | 1199 | $query_args = array( |
1200 | - 'action' => isset($this->_cpt_edit_routes[ $post->post_type ]) |
|
1201 | - ? $this->_cpt_edit_routes[ $post->post_type ] |
|
1200 | + 'action' => isset($this->_cpt_edit_routes[$post->post_type]) |
|
1201 | + ? $this->_cpt_edit_routes[$post->post_type] |
|
1202 | 1202 | : 'edit', |
1203 | 1203 | 'post' => $id, |
1204 | 1204 | ); |
@@ -1221,16 +1221,16 @@ discard block |
||
1221 | 1221 | $post = get_post($post_id); |
1222 | 1222 | |
1223 | 1223 | if (empty($this->_req_data['action']) |
1224 | - || ! isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1224 | + || ! isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1225 | 1225 | || ! $post instanceof WP_Post |
1226 | - || $post->post_type !== $this->_cpt_routes[ $this->_req_data['action'] ] |
|
1226 | + || $post->post_type !== $this->_cpt_routes[$this->_req_data['action']] |
|
1227 | 1227 | ) { |
1228 | 1228 | return $delete_link; |
1229 | 1229 | } |
1230 | 1230 | $this->_set_model_object($post->ID, true); |
1231 | 1231 | |
1232 | 1232 | // returns something like `trash_event` or `trash_attendee` or `trash_venue` |
1233 | - $action = 'trash_' . str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1233 | + $action = 'trash_'.str_replace('ee_', '', strtolower(get_class($this->_cpt_model_obj))); |
|
1234 | 1234 | |
1235 | 1235 | return EE_Admin_Page::add_query_args_and_nonce( |
1236 | 1236 | array( |
@@ -1258,7 +1258,7 @@ discard block |
||
1258 | 1258 | // we DO have a match so let's setup the url |
1259 | 1259 | // we have to get the post to determine our route |
1260 | 1260 | $post = get_post($post_id); |
1261 | - $edit_route = $this->_cpt_edit_routes[ $post->post_type ]; |
|
1261 | + $edit_route = $this->_cpt_edit_routes[$post->post_type]; |
|
1262 | 1262 | // shared query_args |
1263 | 1263 | $query_args = array('action' => $edit_route, 'post' => $post_id); |
1264 | 1264 | $admin_url = $this->_admin_base_url; |
@@ -1330,12 +1330,12 @@ discard block |
||
1330 | 1330 | /*$current_route = isset($this->_req_data['current_route']) ? $this->_req_data['current_route'] : 'shouldneverwork'; |
1331 | 1331 | |
1332 | 1332 | $route_to_check = $post_type && isset( $this->_cpt_routes[$current_route]) ? $this->_cpt_routes[$current_route] : '';/**/ |
1333 | - $messages[ $post->post_type ] = array( |
|
1333 | + $messages[$post->post_type] = array( |
|
1334 | 1334 | 0 => '', // Unused. Messages start at index 1. |
1335 | 1335 | 1 => sprintf( |
1336 | 1336 | __('%1$s updated. %2$sView %1$s%3$s', 'event_espresso'), |
1337 | 1337 | $this->_cpt_object->labels->singular_name, |
1338 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1338 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1339 | 1339 | '</a>' |
1340 | 1340 | ), |
1341 | 1341 | 2 => __('Custom field updated', 'event_espresso'), |
@@ -1350,27 +1350,27 @@ discard block |
||
1350 | 1350 | 6 => sprintf( |
1351 | 1351 | __('%1$s published. %2$sView %1$s%3$s', 'event_espresso'), |
1352 | 1352 | $this->_cpt_object->labels->singular_name, |
1353 | - '<a href="' . esc_url(get_permalink($id)) . '">', |
|
1353 | + '<a href="'.esc_url(get_permalink($id)).'">', |
|
1354 | 1354 | '</a>' |
1355 | 1355 | ), |
1356 | 1356 | 7 => sprintf(__('%1$s saved.', 'event_espresso'), $this->_cpt_object->labels->singular_name), |
1357 | 1357 | 8 => sprintf( |
1358 | 1358 | __('%1$s submitted. %2$sPreview %1$s%3$s', 'event_espresso'), |
1359 | 1359 | $this->_cpt_object->labels->singular_name, |
1360 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))) . '">', |
|
1360 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))).'">', |
|
1361 | 1361 | '</a>' |
1362 | 1362 | ), |
1363 | 1363 | 9 => sprintf( |
1364 | 1364 | __('%1$s scheduled for: %2$s. %3$s">Preview %1$s%3$s', 'event_espresso'), |
1365 | 1365 | $this->_cpt_object->labels->singular_name, |
1366 | - '<strong>' . date_i18n('M j, Y @ G:i', strtotime($post->post_date)) . '</strong>', |
|
1367 | - '<a target="_blank" href="' . esc_url(get_permalink($id)), |
|
1366 | + '<strong>'.date_i18n('M j, Y @ G:i', strtotime($post->post_date)).'</strong>', |
|
1367 | + '<a target="_blank" href="'.esc_url(get_permalink($id)), |
|
1368 | 1368 | '</a>' |
1369 | 1369 | ), |
1370 | 1370 | 10 => sprintf( |
1371 | 1371 | __('%1$s draft updated. %2$s">Preview page%3$s', 'event_espresso'), |
1372 | 1372 | $this->_cpt_object->labels->singular_name, |
1373 | - '<a target="_blank" href="' . esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1373 | + '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($id))), |
|
1374 | 1374 | '</a>' |
1375 | 1375 | ), |
1376 | 1376 | ); |
@@ -1389,10 +1389,10 @@ discard block |
||
1389 | 1389 | { |
1390 | 1390 | // gather template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
1391 | 1391 | global $post, $title, $is_IE, $post_type, $post_type_object; |
1392 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1392 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1393 | 1393 | $post_type_object = $this->_cpt_object; |
1394 | 1394 | $title = $post_type_object->labels->add_new_item; |
1395 | - $post = $post = get_default_post_to_edit($this->_cpt_routes[ $this->_req_action ], true); |
|
1395 | + $post = $post = get_default_post_to_edit($this->_cpt_routes[$this->_req_action], true); |
|
1396 | 1396 | add_action('admin_print_styles', array($this, 'add_new_admin_page_global')); |
1397 | 1397 | // modify the default editor title field with default title. |
1398 | 1398 | add_filter('enter_title_here', array($this, 'add_custom_editor_default_title'), 10); |
@@ -1417,8 +1417,8 @@ discard block |
||
1417 | 1417 | if ($creating) { |
1418 | 1418 | wp_enqueue_script('autosave'); |
1419 | 1419 | } else { |
1420 | - if (isset($this->_cpt_routes[ $this->_req_data['action'] ]) |
|
1421 | - && ! isset($this->_labels['hide_add_button_on_cpt_route'][ $this->_req_data['action'] ]) |
|
1420 | + if (isset($this->_cpt_routes[$this->_req_data['action']]) |
|
1421 | + && ! isset($this->_labels['hide_add_button_on_cpt_route'][$this->_req_data['action']]) |
|
1422 | 1422 | ) { |
1423 | 1423 | $create_new_action = apply_filters( |
1424 | 1424 | 'FHEE__EE_Admin_Page_CPT___edit_cpt_item__create_new_action', |
@@ -1434,7 +1434,7 @@ discard block |
||
1434 | 1434 | ); |
1435 | 1435 | } |
1436 | 1436 | } |
1437 | - include_once WP_ADMIN_PATH . 'edit-form-advanced.php'; |
|
1437 | + include_once WP_ADMIN_PATH.'edit-form-advanced.php'; |
|
1438 | 1438 | } |
1439 | 1439 | } |
1440 | 1440 | |
@@ -1465,21 +1465,21 @@ discard block |
||
1465 | 1465 | if (empty($post)) { |
1466 | 1466 | wp_die(__('You attempted to edit an item that doesn’t exist. Perhaps it was deleted?', 'event_espresso')); |
1467 | 1467 | } |
1468 | - if (! empty($_GET['get-post-lock'])) { |
|
1468 | + if ( ! empty($_GET['get-post-lock'])) { |
|
1469 | 1469 | wp_set_post_lock($post_id); |
1470 | 1470 | wp_redirect(get_edit_post_link($post_id, 'url')); |
1471 | 1471 | exit(); |
1472 | 1472 | } |
1473 | 1473 | |
1474 | 1474 | // template vars for WP_ADMIN_PATH . 'edit-form-advanced.php' |
1475 | - $post_type = $this->_cpt_routes[ $this->_req_action ]; |
|
1475 | + $post_type = $this->_cpt_routes[$this->_req_action]; |
|
1476 | 1476 | $post_type_object = $this->_cpt_object; |
1477 | 1477 | |
1478 | - if (! wp_check_post_lock($post->ID)) { |
|
1478 | + if ( ! wp_check_post_lock($post->ID)) { |
|
1479 | 1479 | wp_set_post_lock($post->ID); |
1480 | 1480 | } |
1481 | 1481 | add_action('admin_footer', '_admin_notice_post_locked'); |
1482 | - if (post_type_supports($this->_cpt_routes[ $this->_req_action ], 'comments')) { |
|
1482 | + if (post_type_supports($this->_cpt_routes[$this->_req_action], 'comments')) { |
|
1483 | 1483 | wp_enqueue_script('admin-comments'); |
1484 | 1484 | enqueue_comment_hotkeys_js(); |
1485 | 1485 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! class_exists('WP_List_Table')) { |
4 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
4 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -20,847 +20,847 @@ discard block |
||
20 | 20 | abstract class EE_Admin_List_Table extends WP_List_Table |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * holds the data that will be processed for the table |
|
25 | - * |
|
26 | - * @var array $_data |
|
27 | - */ |
|
28 | - protected $_data; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This holds the value of all the data available for the given view (for all pages). |
|
33 | - * |
|
34 | - * @var int $_all_data_count |
|
35 | - */ |
|
36 | - protected $_all_data_count; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Will contain the count of trashed items for the view label. |
|
41 | - * |
|
42 | - * @var int $_trashed_count |
|
43 | - */ |
|
44 | - protected $_trashed_count; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This is what will be referenced as the slug for the current screen |
|
49 | - * |
|
50 | - * @var string $_screen |
|
51 | - */ |
|
52 | - protected $_screen; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * this is the EE_Admin_Page object |
|
57 | - * |
|
58 | - * @var EE_Admin_Page $_admin_page |
|
59 | - */ |
|
60 | - protected $_admin_page; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * The current view |
|
65 | - * |
|
66 | - * @var string $_view |
|
67 | - */ |
|
68 | - protected $_view; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * array of possible views for this table |
|
73 | - * |
|
74 | - * @var array $_views |
|
75 | - */ |
|
76 | - protected $_views; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * An array of key => value pairs containing information about the current table |
|
81 | - * array( |
|
82 | - * 'plural' => 'plural label', |
|
83 | - * 'singular' => 'singular label', |
|
84 | - * 'ajax' => false, //whether to use ajax or not |
|
85 | - * 'screen' => null, //string used to reference what screen this is |
|
86 | - * (WP_List_table converts to screen object) |
|
87 | - * ) |
|
88 | - * |
|
89 | - * @var array $_wp_list_args |
|
90 | - */ |
|
91 | - protected $_wp_list_args; |
|
92 | - |
|
93 | - /** |
|
94 | - * an array of column names |
|
95 | - * array( |
|
96 | - * 'internal-name' => 'Title' |
|
97 | - * ) |
|
98 | - * |
|
99 | - * @var array $_columns |
|
100 | - */ |
|
101 | - protected $_columns; |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of sortable columns |
|
105 | - * array( |
|
106 | - * 'internal-name' => 'orderby' //or |
|
107 | - * 'internal-name' => array( 'orderby', true ) |
|
108 | - * ) |
|
109 | - * |
|
110 | - * @var array $_sortable_columns |
|
111 | - */ |
|
112 | - protected $_sortable_columns; |
|
113 | - |
|
114 | - /** |
|
115 | - * callback method used to perform AJAX row reordering |
|
116 | - * |
|
117 | - * @var string $_ajax_sorting_callback |
|
118 | - */ |
|
119 | - protected $_ajax_sorting_callback; |
|
120 | - |
|
121 | - /** |
|
122 | - * An array of hidden columns (if needed) |
|
123 | - * array('internal-name', 'internal-name') |
|
124 | - * |
|
125 | - * @var array $_hidden_columns |
|
126 | - */ |
|
127 | - protected $_hidden_columns; |
|
128 | - |
|
129 | - /** |
|
130 | - * holds the per_page value |
|
131 | - * |
|
132 | - * @var int $_per_page |
|
133 | - */ |
|
134 | - protected $_per_page; |
|
135 | - |
|
136 | - /** |
|
137 | - * holds what page number is currently being viewed |
|
138 | - * |
|
139 | - * @var int $_current_page |
|
140 | - */ |
|
141 | - protected $_current_page; |
|
142 | - |
|
143 | - /** |
|
144 | - * the reference string for the nonce_action |
|
145 | - * |
|
146 | - * @var string $_nonce_action_ref |
|
147 | - */ |
|
148 | - protected $_nonce_action_ref; |
|
149 | - |
|
150 | - /** |
|
151 | - * property to hold incoming request data (as set by the admin_page_core) |
|
152 | - * |
|
153 | - * @var array $_req_data |
|
154 | - */ |
|
155 | - protected $_req_data; |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * yes / no array for admin form fields |
|
160 | - * |
|
161 | - * @var array $_yes_no |
|
162 | - */ |
|
163 | - protected $_yes_no = array(); |
|
164 | - |
|
165 | - /** |
|
166 | - * Array describing buttons that should appear at the bottom of the page |
|
167 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
168 | - * and the values are another array with the following keys |
|
169 | - * array( |
|
170 | - * 'route' => 'page_route', |
|
171 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
172 | - * ) |
|
173 | - * |
|
174 | - * @var array $_bottom_buttons |
|
175 | - */ |
|
176 | - protected $_bottom_buttons = array(); |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Used to indicate what should be the primary column for the list table. |
|
181 | - * If not present then falls back to what WP calculates |
|
182 | - * as the primary column. |
|
183 | - * |
|
184 | - * @type string $_primary_column |
|
185 | - */ |
|
186 | - protected $_primary_column = ''; |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Used to indicate whether the table has a checkbox column or not. |
|
191 | - * |
|
192 | - * @type bool $_has_checkbox_column |
|
193 | - */ |
|
194 | - protected $_has_checkbox_column = false; |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
199 | - */ |
|
200 | - public function __construct(EE_Admin_Page $admin_page) |
|
201 | - { |
|
202 | - $this->_admin_page = $admin_page; |
|
203 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
204 | - $this->_view = $this->_admin_page->get_view(); |
|
205 | - $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
206 | - $this->_current_page = $this->get_pagenum(); |
|
207 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
208 | - $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
|
209 | - |
|
210 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10); |
|
211 | - |
|
212 | - $this->_setup_data(); |
|
213 | - $this->_add_view_counts(); |
|
214 | - |
|
215 | - $this->_nonce_action_ref = $this->_view; |
|
216 | - |
|
217 | - $this->_set_properties(); |
|
218 | - |
|
219 | - // set primary column |
|
220 | - add_filter('list_table_primary_column', array($this, 'set_primary_column')); |
|
221 | - |
|
222 | - // set parent defaults |
|
223 | - parent::__construct($this->_wp_list_args); |
|
224 | - |
|
225 | - $this->prepare_items(); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * _setup_data |
|
231 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
232 | - * |
|
233 | - * @uses $this->_admin_page |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - abstract protected function _setup_data(); |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
241 | - * properties set: |
|
242 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
243 | - * _columns = set the columns in an array. |
|
244 | - * _sortable_columns = columns that are sortable (array). |
|
245 | - * _hidden_columns = columns that are hidden (array) |
|
246 | - * _default_orderby = the default orderby for sorting. |
|
247 | - * |
|
248 | - * @abstract |
|
249 | - * @access protected |
|
250 | - * @return void |
|
251 | - */ |
|
252 | - abstract protected function _set_properties(); |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * _get_table_filters |
|
257 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
258 | - * get's shown in the table. |
|
259 | - * |
|
260 | - * @abstract |
|
261 | - * @access protected |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - abstract protected function _get_table_filters(); |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
269 | - * counts of the views is accurate. |
|
270 | - * |
|
271 | - * @abstract |
|
272 | - * @access protected |
|
273 | - * @return void |
|
274 | - */ |
|
275 | - abstract protected function _add_view_counts(); |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * _get_hidden_fields |
|
280 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
281 | - * |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - protected function _get_hidden_fields() |
|
285 | - { |
|
286 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
287 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
288 | - // if action is STILL empty, then we set it to default |
|
289 | - $action = empty($action) ? 'default' : $action; |
|
290 | - $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
291 | - $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
292 | - $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
293 | - |
|
294 | - $bulk_actions = $this->_get_bulk_actions(); |
|
295 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
296 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
297 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
298 | - } |
|
299 | - |
|
300 | - return $field; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * _set_column_info |
|
306 | - * we're using this to set the column headers property. |
|
307 | - * |
|
308 | - * @access protected |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - protected function _set_column_info() |
|
312 | - { |
|
313 | - $columns = $this->get_columns(); |
|
314 | - $hidden = $this->get_hidden_columns(); |
|
315 | - $_sortable = $this->get_sortable_columns(); |
|
316 | - |
|
317 | - /** |
|
318 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
319 | - * Note that $this->screen->id is in the format |
|
320 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
321 | - * table it is: event-espresso_page_espresso_messages. |
|
322 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
323 | - * hook prefix ("event-espresso") will be different. |
|
324 | - * |
|
325 | - * @var array |
|
326 | - */ |
|
327 | - $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
328 | - |
|
329 | - $sortable = array(); |
|
330 | - foreach ($_sortable as $id => $data) { |
|
331 | - if (empty($data)) { |
|
332 | - continue; |
|
333 | - } |
|
334 | - // fix for offset errors with WP_List_Table default get_columninfo() |
|
335 | - if (is_array($data)) { |
|
336 | - $_data[0] = key($data); |
|
337 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
338 | - } else { |
|
339 | - $_data[0] = $data; |
|
340 | - } |
|
341 | - |
|
342 | - $data = (array) $data; |
|
343 | - |
|
344 | - if (! isset($data[1])) { |
|
345 | - $_data[1] = false; |
|
346 | - } |
|
347 | - |
|
348 | - $sortable[ $id ] = $_data; |
|
349 | - } |
|
350 | - $primary = $this->get_primary_column_name(); |
|
351 | - $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
357 | - * |
|
358 | - * @return string |
|
359 | - */ |
|
360 | - protected function get_primary_column_name() |
|
361 | - { |
|
362 | - foreach (class_parents($this) as $parent) { |
|
363 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
364 | - return parent::get_primary_column_name(); |
|
365 | - } |
|
366 | - } |
|
367 | - return $this->_primary_column; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
373 | - * |
|
374 | - * @param EE_Base_Class $item |
|
375 | - * @param string $column_name |
|
376 | - * @param string $primary |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - protected function handle_row_actions($item, $column_name, $primary) |
|
380 | - { |
|
381 | - foreach (class_parents($this) as $parent) { |
|
382 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
383 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
384 | - } |
|
385 | - } |
|
386 | - return ''; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * _get_bulk_actions |
|
392 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
393 | - * |
|
394 | - * @access protected |
|
395 | - * @return array bulk_actions |
|
396 | - */ |
|
397 | - protected function _get_bulk_actions() |
|
398 | - { |
|
399 | - $actions = array(); |
|
400 | - // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
401 | - // formatted array for the wp_list_table(); |
|
402 | - foreach ($this->_views as $view => $args) { |
|
403 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
404 | - // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
405 | - // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
406 | - foreach ($args['bulk_action'] as $route => $label) { |
|
407 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
408 | - $actions[ $route ] = $label; |
|
409 | - } |
|
410 | - } |
|
411 | - } |
|
412 | - } |
|
413 | - return $actions; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Generate the table navigation above or below the table. |
|
419 | - * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
420 | - * |
|
421 | - * @since 4.9.44.rc.001 |
|
422 | - */ |
|
423 | - public function display_tablenav($which) |
|
424 | - { |
|
425 | - if ('top' === $which) { |
|
426 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
427 | - } |
|
428 | - ?> |
|
23 | + /** |
|
24 | + * holds the data that will be processed for the table |
|
25 | + * |
|
26 | + * @var array $_data |
|
27 | + */ |
|
28 | + protected $_data; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This holds the value of all the data available for the given view (for all pages). |
|
33 | + * |
|
34 | + * @var int $_all_data_count |
|
35 | + */ |
|
36 | + protected $_all_data_count; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Will contain the count of trashed items for the view label. |
|
41 | + * |
|
42 | + * @var int $_trashed_count |
|
43 | + */ |
|
44 | + protected $_trashed_count; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This is what will be referenced as the slug for the current screen |
|
49 | + * |
|
50 | + * @var string $_screen |
|
51 | + */ |
|
52 | + protected $_screen; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * this is the EE_Admin_Page object |
|
57 | + * |
|
58 | + * @var EE_Admin_Page $_admin_page |
|
59 | + */ |
|
60 | + protected $_admin_page; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * The current view |
|
65 | + * |
|
66 | + * @var string $_view |
|
67 | + */ |
|
68 | + protected $_view; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * array of possible views for this table |
|
73 | + * |
|
74 | + * @var array $_views |
|
75 | + */ |
|
76 | + protected $_views; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * An array of key => value pairs containing information about the current table |
|
81 | + * array( |
|
82 | + * 'plural' => 'plural label', |
|
83 | + * 'singular' => 'singular label', |
|
84 | + * 'ajax' => false, //whether to use ajax or not |
|
85 | + * 'screen' => null, //string used to reference what screen this is |
|
86 | + * (WP_List_table converts to screen object) |
|
87 | + * ) |
|
88 | + * |
|
89 | + * @var array $_wp_list_args |
|
90 | + */ |
|
91 | + protected $_wp_list_args; |
|
92 | + |
|
93 | + /** |
|
94 | + * an array of column names |
|
95 | + * array( |
|
96 | + * 'internal-name' => 'Title' |
|
97 | + * ) |
|
98 | + * |
|
99 | + * @var array $_columns |
|
100 | + */ |
|
101 | + protected $_columns; |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of sortable columns |
|
105 | + * array( |
|
106 | + * 'internal-name' => 'orderby' //or |
|
107 | + * 'internal-name' => array( 'orderby', true ) |
|
108 | + * ) |
|
109 | + * |
|
110 | + * @var array $_sortable_columns |
|
111 | + */ |
|
112 | + protected $_sortable_columns; |
|
113 | + |
|
114 | + /** |
|
115 | + * callback method used to perform AJAX row reordering |
|
116 | + * |
|
117 | + * @var string $_ajax_sorting_callback |
|
118 | + */ |
|
119 | + protected $_ajax_sorting_callback; |
|
120 | + |
|
121 | + /** |
|
122 | + * An array of hidden columns (if needed) |
|
123 | + * array('internal-name', 'internal-name') |
|
124 | + * |
|
125 | + * @var array $_hidden_columns |
|
126 | + */ |
|
127 | + protected $_hidden_columns; |
|
128 | + |
|
129 | + /** |
|
130 | + * holds the per_page value |
|
131 | + * |
|
132 | + * @var int $_per_page |
|
133 | + */ |
|
134 | + protected $_per_page; |
|
135 | + |
|
136 | + /** |
|
137 | + * holds what page number is currently being viewed |
|
138 | + * |
|
139 | + * @var int $_current_page |
|
140 | + */ |
|
141 | + protected $_current_page; |
|
142 | + |
|
143 | + /** |
|
144 | + * the reference string for the nonce_action |
|
145 | + * |
|
146 | + * @var string $_nonce_action_ref |
|
147 | + */ |
|
148 | + protected $_nonce_action_ref; |
|
149 | + |
|
150 | + /** |
|
151 | + * property to hold incoming request data (as set by the admin_page_core) |
|
152 | + * |
|
153 | + * @var array $_req_data |
|
154 | + */ |
|
155 | + protected $_req_data; |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * yes / no array for admin form fields |
|
160 | + * |
|
161 | + * @var array $_yes_no |
|
162 | + */ |
|
163 | + protected $_yes_no = array(); |
|
164 | + |
|
165 | + /** |
|
166 | + * Array describing buttons that should appear at the bottom of the page |
|
167 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
168 | + * and the values are another array with the following keys |
|
169 | + * array( |
|
170 | + * 'route' => 'page_route', |
|
171 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
172 | + * ) |
|
173 | + * |
|
174 | + * @var array $_bottom_buttons |
|
175 | + */ |
|
176 | + protected $_bottom_buttons = array(); |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Used to indicate what should be the primary column for the list table. |
|
181 | + * If not present then falls back to what WP calculates |
|
182 | + * as the primary column. |
|
183 | + * |
|
184 | + * @type string $_primary_column |
|
185 | + */ |
|
186 | + protected $_primary_column = ''; |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Used to indicate whether the table has a checkbox column or not. |
|
191 | + * |
|
192 | + * @type bool $_has_checkbox_column |
|
193 | + */ |
|
194 | + protected $_has_checkbox_column = false; |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
199 | + */ |
|
200 | + public function __construct(EE_Admin_Page $admin_page) |
|
201 | + { |
|
202 | + $this->_admin_page = $admin_page; |
|
203 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
204 | + $this->_view = $this->_admin_page->get_view(); |
|
205 | + $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
206 | + $this->_current_page = $this->get_pagenum(); |
|
207 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
208 | + $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
|
209 | + |
|
210 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10); |
|
211 | + |
|
212 | + $this->_setup_data(); |
|
213 | + $this->_add_view_counts(); |
|
214 | + |
|
215 | + $this->_nonce_action_ref = $this->_view; |
|
216 | + |
|
217 | + $this->_set_properties(); |
|
218 | + |
|
219 | + // set primary column |
|
220 | + add_filter('list_table_primary_column', array($this, 'set_primary_column')); |
|
221 | + |
|
222 | + // set parent defaults |
|
223 | + parent::__construct($this->_wp_list_args); |
|
224 | + |
|
225 | + $this->prepare_items(); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * _setup_data |
|
231 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
232 | + * |
|
233 | + * @uses $this->_admin_page |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + abstract protected function _setup_data(); |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
241 | + * properties set: |
|
242 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
243 | + * _columns = set the columns in an array. |
|
244 | + * _sortable_columns = columns that are sortable (array). |
|
245 | + * _hidden_columns = columns that are hidden (array) |
|
246 | + * _default_orderby = the default orderby for sorting. |
|
247 | + * |
|
248 | + * @abstract |
|
249 | + * @access protected |
|
250 | + * @return void |
|
251 | + */ |
|
252 | + abstract protected function _set_properties(); |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * _get_table_filters |
|
257 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
258 | + * get's shown in the table. |
|
259 | + * |
|
260 | + * @abstract |
|
261 | + * @access protected |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + abstract protected function _get_table_filters(); |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
269 | + * counts of the views is accurate. |
|
270 | + * |
|
271 | + * @abstract |
|
272 | + * @access protected |
|
273 | + * @return void |
|
274 | + */ |
|
275 | + abstract protected function _add_view_counts(); |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * _get_hidden_fields |
|
280 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
281 | + * |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + protected function _get_hidden_fields() |
|
285 | + { |
|
286 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
287 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
288 | + // if action is STILL empty, then we set it to default |
|
289 | + $action = empty($action) ? 'default' : $action; |
|
290 | + $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
291 | + $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
292 | + $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
293 | + |
|
294 | + $bulk_actions = $this->_get_bulk_actions(); |
|
295 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
296 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
297 | + . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
298 | + } |
|
299 | + |
|
300 | + return $field; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * _set_column_info |
|
306 | + * we're using this to set the column headers property. |
|
307 | + * |
|
308 | + * @access protected |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + protected function _set_column_info() |
|
312 | + { |
|
313 | + $columns = $this->get_columns(); |
|
314 | + $hidden = $this->get_hidden_columns(); |
|
315 | + $_sortable = $this->get_sortable_columns(); |
|
316 | + |
|
317 | + /** |
|
318 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
319 | + * Note that $this->screen->id is in the format |
|
320 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
321 | + * table it is: event-espresso_page_espresso_messages. |
|
322 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
323 | + * hook prefix ("event-espresso") will be different. |
|
324 | + * |
|
325 | + * @var array |
|
326 | + */ |
|
327 | + $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
328 | + |
|
329 | + $sortable = array(); |
|
330 | + foreach ($_sortable as $id => $data) { |
|
331 | + if (empty($data)) { |
|
332 | + continue; |
|
333 | + } |
|
334 | + // fix for offset errors with WP_List_Table default get_columninfo() |
|
335 | + if (is_array($data)) { |
|
336 | + $_data[0] = key($data); |
|
337 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
338 | + } else { |
|
339 | + $_data[0] = $data; |
|
340 | + } |
|
341 | + |
|
342 | + $data = (array) $data; |
|
343 | + |
|
344 | + if (! isset($data[1])) { |
|
345 | + $_data[1] = false; |
|
346 | + } |
|
347 | + |
|
348 | + $sortable[ $id ] = $_data; |
|
349 | + } |
|
350 | + $primary = $this->get_primary_column_name(); |
|
351 | + $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
357 | + * |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + protected function get_primary_column_name() |
|
361 | + { |
|
362 | + foreach (class_parents($this) as $parent) { |
|
363 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
364 | + return parent::get_primary_column_name(); |
|
365 | + } |
|
366 | + } |
|
367 | + return $this->_primary_column; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
373 | + * |
|
374 | + * @param EE_Base_Class $item |
|
375 | + * @param string $column_name |
|
376 | + * @param string $primary |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + protected function handle_row_actions($item, $column_name, $primary) |
|
380 | + { |
|
381 | + foreach (class_parents($this) as $parent) { |
|
382 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
383 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
384 | + } |
|
385 | + } |
|
386 | + return ''; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * _get_bulk_actions |
|
392 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
393 | + * |
|
394 | + * @access protected |
|
395 | + * @return array bulk_actions |
|
396 | + */ |
|
397 | + protected function _get_bulk_actions() |
|
398 | + { |
|
399 | + $actions = array(); |
|
400 | + // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
401 | + // formatted array for the wp_list_table(); |
|
402 | + foreach ($this->_views as $view => $args) { |
|
403 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
404 | + // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
405 | + // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
406 | + foreach ($args['bulk_action'] as $route => $label) { |
|
407 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
408 | + $actions[ $route ] = $label; |
|
409 | + } |
|
410 | + } |
|
411 | + } |
|
412 | + } |
|
413 | + return $actions; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Generate the table navigation above or below the table. |
|
419 | + * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
420 | + * |
|
421 | + * @since 4.9.44.rc.001 |
|
422 | + */ |
|
423 | + public function display_tablenav($which) |
|
424 | + { |
|
425 | + if ('top' === $which) { |
|
426 | + wp_nonce_field('bulk-' . $this->_args['plural']); |
|
427 | + } |
|
428 | + ?> |
|
429 | 429 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
430 | 430 | <?php if ($this->_get_bulk_actions()) { ?> |
431 | 431 | <div class="alignleft actions bulkactions"> |
432 | 432 | <?php $this->bulk_actions(); ?> |
433 | 433 | </div> |
434 | 434 | <?php } |
435 | - $this->extra_tablenav($which); |
|
436 | - $this->pagination($which); |
|
437 | - ?> |
|
435 | + $this->extra_tablenav($which); |
|
436 | + $this->pagination($which); |
|
437 | + ?> |
|
438 | 438 | |
439 | 439 | <br class="clear"/> |
440 | 440 | </div> |
441 | 441 | <?php |
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * _filters |
|
447 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
448 | - * button. |
|
449 | - * |
|
450 | - * @access private |
|
451 | - * @return string html showing filters |
|
452 | - */ |
|
453 | - private function _filters() |
|
454 | - { |
|
455 | - $classname = get_class($this); |
|
456 | - $filters = apply_filters( |
|
457 | - "FHEE__{$classname}__filters", |
|
458 | - (array) $this->_get_table_filters(), |
|
459 | - $this, |
|
460 | - $this->_screen |
|
461 | - ); |
|
462 | - |
|
463 | - if (empty($filters)) { |
|
464 | - return; |
|
465 | - } |
|
466 | - foreach ($filters as $filter) { |
|
467 | - echo $filter; |
|
468 | - } |
|
469 | - // add filter button at end |
|
470 | - echo '<input type="submit" class="button-secondary" value="' |
|
471 | - . esc_html__('Filter', 'event_espresso') |
|
472 | - . '" id="post-query-submit" />'; |
|
473 | - // add reset filters button at end |
|
474 | - echo '<a class="button button-secondary" href="' |
|
475 | - . $this->_admin_page->get_current_page_view_url() |
|
476 | - . '" style="display:inline-block">' |
|
477 | - . esc_html__('Reset Filters', 'event_espresso') |
|
478 | - . '</a>'; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * Callback for 'list_table_primary_column' WordPress filter |
|
484 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
485 | - * column when class is instantiated. |
|
486 | - * |
|
487 | - * @see WP_List_Table::get_primary_column_name |
|
488 | - * @param string $column_name |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - public function set_primary_column($column_name) |
|
492 | - { |
|
493 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * |
|
499 | - */ |
|
500 | - public function prepare_items() |
|
501 | - { |
|
502 | - |
|
503 | - $this->_set_column_info(); |
|
504 | - // $this->_column_headers = $this->get_column_info(); |
|
505 | - $total_items = $this->_all_data_count; |
|
506 | - $this->process_bulk_action(); |
|
507 | - |
|
508 | - $this->items = $this->_data; |
|
509 | - $this->set_pagination_args( |
|
510 | - array( |
|
511 | - 'total_items' => $total_items, |
|
512 | - 'per_page' => $this->_per_page, |
|
513 | - 'total_pages' => ceil($total_items / $this->_per_page), |
|
514 | - ) |
|
515 | - ); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * This column is the default for when there is no defined column method for a registered column. |
|
521 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
522 | - * |
|
523 | - * @param EE_Base_Class $item |
|
524 | - * @param string $column_name The column being called. |
|
525 | - * @return string html content for the column |
|
526 | - */ |
|
527 | - public function column_default($item, $column_name) |
|
528 | - { |
|
529 | - /** |
|
530 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
531 | - * Note that $this->screen->id is in the format |
|
532 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
533 | - * table it is: event-espresso_page_espresso_messages. |
|
534 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
535 | - * hook prefix ("event-espresso") will be different. |
|
536 | - */ |
|
537 | - do_action( |
|
538 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
539 | - $item, |
|
540 | - $this->_screen |
|
541 | - ); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Get a list of columns. The format is: |
|
547 | - * 'internal-name' => 'Title' |
|
548 | - * |
|
549 | - * @since 3.1.0 |
|
550 | - * @access public |
|
551 | - * @abstract |
|
552 | - * @return array |
|
553 | - */ |
|
554 | - public function get_columns() |
|
555 | - { |
|
556 | - /** |
|
557 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
558 | - * Note that $this->screen->id is in the format |
|
559 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
560 | - * table it is: event-espresso_page_espresso_messages. |
|
561 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
562 | - * hook prefix ("event-espresso") will be different. |
|
563 | - * |
|
564 | - * @var array |
|
565 | - */ |
|
566 | - $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
567 | - return $columns; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Get an associative array ( id => link ) with the list |
|
573 | - * of views available on this table. |
|
574 | - * |
|
575 | - * @since 3.1.0 |
|
576 | - * @access protected |
|
577 | - * @return array |
|
578 | - */ |
|
579 | - public function get_views() |
|
580 | - { |
|
581 | - return $this->_views; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Generate the views html. |
|
587 | - */ |
|
588 | - public function display_views() |
|
589 | - { |
|
590 | - $views = $this->get_views(); |
|
591 | - $assembled_views = array(); |
|
592 | - |
|
593 | - if (empty($views)) { |
|
594 | - return; |
|
595 | - } |
|
596 | - echo "<ul class='subsubsub'>\n"; |
|
597 | - foreach ($views as $view) { |
|
598 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
599 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
600 | - $assembled_views[ $view['slug'] ] = "\t<li class='" . $view['class'] . "'>" |
|
601 | - . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>' |
|
602 | - . ' <span class="count">(' . $count . ')</span>'; |
|
603 | - } |
|
604 | - } |
|
605 | - |
|
606 | - echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
607 | - echo "</ul>"; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Generates content for a single row of the table |
|
613 | - * |
|
614 | - * @since 4.1 |
|
615 | - * @access public |
|
616 | - * @param EE_Base_Class $item The current item |
|
617 | - */ |
|
618 | - public function single_row($item) |
|
619 | - { |
|
620 | - $row_class = $this->_get_row_class($item); |
|
621 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
622 | - $this->single_row_columns($item); |
|
623 | - echo '</tr>'; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * This simply sets up the row class for the table rows. |
|
629 | - * Allows for easier overriding of child methods for setting up sorting. |
|
630 | - * |
|
631 | - * @param EE_Base_Class $item the current item |
|
632 | - * @return string |
|
633 | - */ |
|
634 | - protected function _get_row_class($item) |
|
635 | - { |
|
636 | - static $row_class = ''; |
|
637 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
638 | - |
|
639 | - $new_row_class = $row_class; |
|
640 | - |
|
641 | - if (! empty($this->_ajax_sorting_callback)) { |
|
642 | - $new_row_class .= ' rowsortable'; |
|
643 | - } |
|
644 | - |
|
645 | - return $new_row_class; |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * @return array |
|
651 | - */ |
|
652 | - public function get_sortable_columns() |
|
653 | - { |
|
654 | - return (array) $this->_sortable_columns; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function get_ajax_sorting_callback() |
|
662 | - { |
|
663 | - return $this->_ajax_sorting_callback; |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * @return array |
|
669 | - */ |
|
670 | - public function get_hidden_columns() |
|
671 | - { |
|
672 | - $user_id = get_current_user_id(); |
|
673 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
674 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
675 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
676 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
677 | - } |
|
678 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
679 | - return (array) get_user_option($ref, $user_id); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * Generates the columns for a single row of the table. |
|
685 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
686 | - * column. |
|
687 | - * |
|
688 | - * @since 3.1.0 |
|
689 | - * @param EE_Base_Class $item The current item |
|
690 | - */ |
|
691 | - public function single_row_columns($item) |
|
692 | - { |
|
693 | - list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
694 | - |
|
695 | - global $wp_version; |
|
696 | - $use_hidden_class = version_compare($wp_version, '4.3-RC', '>='); |
|
697 | - |
|
698 | - foreach ($columns as $column_name => $column_display_name) { |
|
699 | - |
|
700 | - /** |
|
701 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
702 | - * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
703 | - */ |
|
704 | - $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
|
705 | - $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
|
706 | - |
|
707 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
708 | - if ($primary === $column_name) { |
|
709 | - $classes .= ' has-row-actions column-primary'; |
|
710 | - } |
|
711 | - |
|
712 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
713 | - |
|
714 | - $class = "class='$classes'"; |
|
715 | - |
|
716 | - $attributes = "$class$style$data"; |
|
717 | - |
|
718 | - if ($column_name === 'cb') { |
|
719 | - echo '<th scope="row" class="check-column">'; |
|
720 | - echo apply_filters( |
|
721 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
722 | - $this->column_cb($item), |
|
723 | - $item, |
|
724 | - $this |
|
725 | - ); |
|
726 | - echo '</th>'; |
|
727 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
728 | - echo "<td $attributes>"; |
|
729 | - echo apply_filters( |
|
730 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
731 | - call_user_func(array($this, 'column_' . $column_name), $item), |
|
732 | - $item, |
|
733 | - $this |
|
734 | - ); |
|
735 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
736 | - echo "</td>"; |
|
737 | - } else { |
|
738 | - echo "<td $attributes>"; |
|
739 | - echo apply_filters( |
|
740 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
741 | - $this->column_default($item, $column_name), |
|
742 | - $item, |
|
743 | - $column_name, |
|
744 | - $this |
|
745 | - ); |
|
746 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
747 | - echo "</td>"; |
|
748 | - } |
|
749 | - } |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Extra controls to be displayed between bulk actions and pagination |
|
755 | - * |
|
756 | - * @access public |
|
757 | - * @param string $which |
|
758 | - * @throws \EE_Error |
|
759 | - */ |
|
760 | - public function extra_tablenav($which) |
|
761 | - { |
|
762 | - if ($which === 'top') { |
|
763 | - $this->_filters(); |
|
764 | - echo $this->_get_hidden_fields(); |
|
765 | - } else { |
|
766 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
767 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
768 | - $route = isset($action['route']) ? $action['route'] : ''; |
|
769 | - $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
770 | - echo $this->_admin_page->get_action_link_or_button( |
|
771 | - $route, |
|
772 | - $type, |
|
773 | - $extra_request, |
|
774 | - 'button button-secondary', |
|
775 | - '', |
|
776 | - false |
|
777 | - ); |
|
778 | - } |
|
779 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
780 | - echo '</div>'; |
|
781 | - } |
|
782 | - // echo $this->_entries_per_page_dropdown; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Get an associative array ( option_name => option_title ) with the list |
|
788 | - * of bulk actions available on this table. |
|
789 | - * |
|
790 | - * @since 3.1.0 |
|
791 | - * @access protected |
|
792 | - * @return array |
|
793 | - */ |
|
794 | - public function get_bulk_actions() |
|
795 | - { |
|
796 | - return (array) $this->_get_bulk_actions(); |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Processing bulk actions. |
|
801 | - */ |
|
802 | - public function process_bulk_action() |
|
803 | - { |
|
804 | - // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
805 | - // reference in case there is a case where it gets used. |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - /** |
|
810 | - * returns the EE admin page this list table is associated with |
|
811 | - * |
|
812 | - * @return EE_Admin_Page |
|
813 | - */ |
|
814 | - public function get_admin_page() |
|
815 | - { |
|
816 | - return $this->_admin_page; |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * A "helper" function for all children to provide an html string of |
|
822 | - * actions to output in their content. It is preferable for child classes |
|
823 | - * to use this method for generating their actions content so that it's |
|
824 | - * filterable by plugins |
|
825 | - * |
|
826 | - * @param string $action_container what are the html container |
|
827 | - * elements for this actions string? |
|
828 | - * @param string $action_class What class is for the container |
|
829 | - * element. |
|
830 | - * @param string $action_items The contents for the action items |
|
831 | - * container. This is filtered before |
|
832 | - * returned. |
|
833 | - * @param string $action_id What id (optional) is used for the |
|
834 | - * container element. |
|
835 | - * @param EE_Base_Class $item The object for the column displaying |
|
836 | - * the actions. |
|
837 | - * @return string The assembled action elements container. |
|
838 | - */ |
|
839 | - protected function _action_string( |
|
840 | - $action_items, |
|
841 | - $item, |
|
842 | - $action_container = 'ul', |
|
843 | - $action_class = '', |
|
844 | - $action_id = '' |
|
845 | - ) { |
|
846 | - $content = ''; |
|
847 | - $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
848 | - $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
849 | - $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
850 | - try { |
|
851 | - $content .= apply_filters( |
|
852 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
853 | - $action_items, |
|
854 | - $item, |
|
855 | - $this |
|
856 | - ); |
|
857 | - } catch (\Exception $e) { |
|
858 | - if (WP_DEBUG) { |
|
859 | - \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
860 | - } |
|
861 | - $content .= $action_items; |
|
862 | - } |
|
863 | - $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
864 | - return $content; |
|
865 | - } |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * _filters |
|
447 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
448 | + * button. |
|
449 | + * |
|
450 | + * @access private |
|
451 | + * @return string html showing filters |
|
452 | + */ |
|
453 | + private function _filters() |
|
454 | + { |
|
455 | + $classname = get_class($this); |
|
456 | + $filters = apply_filters( |
|
457 | + "FHEE__{$classname}__filters", |
|
458 | + (array) $this->_get_table_filters(), |
|
459 | + $this, |
|
460 | + $this->_screen |
|
461 | + ); |
|
462 | + |
|
463 | + if (empty($filters)) { |
|
464 | + return; |
|
465 | + } |
|
466 | + foreach ($filters as $filter) { |
|
467 | + echo $filter; |
|
468 | + } |
|
469 | + // add filter button at end |
|
470 | + echo '<input type="submit" class="button-secondary" value="' |
|
471 | + . esc_html__('Filter', 'event_espresso') |
|
472 | + . '" id="post-query-submit" />'; |
|
473 | + // add reset filters button at end |
|
474 | + echo '<a class="button button-secondary" href="' |
|
475 | + . $this->_admin_page->get_current_page_view_url() |
|
476 | + . '" style="display:inline-block">' |
|
477 | + . esc_html__('Reset Filters', 'event_espresso') |
|
478 | + . '</a>'; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * Callback for 'list_table_primary_column' WordPress filter |
|
484 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
485 | + * column when class is instantiated. |
|
486 | + * |
|
487 | + * @see WP_List_Table::get_primary_column_name |
|
488 | + * @param string $column_name |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + public function set_primary_column($column_name) |
|
492 | + { |
|
493 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * |
|
499 | + */ |
|
500 | + public function prepare_items() |
|
501 | + { |
|
502 | + |
|
503 | + $this->_set_column_info(); |
|
504 | + // $this->_column_headers = $this->get_column_info(); |
|
505 | + $total_items = $this->_all_data_count; |
|
506 | + $this->process_bulk_action(); |
|
507 | + |
|
508 | + $this->items = $this->_data; |
|
509 | + $this->set_pagination_args( |
|
510 | + array( |
|
511 | + 'total_items' => $total_items, |
|
512 | + 'per_page' => $this->_per_page, |
|
513 | + 'total_pages' => ceil($total_items / $this->_per_page), |
|
514 | + ) |
|
515 | + ); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * This column is the default for when there is no defined column method for a registered column. |
|
521 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
522 | + * |
|
523 | + * @param EE_Base_Class $item |
|
524 | + * @param string $column_name The column being called. |
|
525 | + * @return string html content for the column |
|
526 | + */ |
|
527 | + public function column_default($item, $column_name) |
|
528 | + { |
|
529 | + /** |
|
530 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
531 | + * Note that $this->screen->id is in the format |
|
532 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
533 | + * table it is: event-espresso_page_espresso_messages. |
|
534 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
535 | + * hook prefix ("event-espresso") will be different. |
|
536 | + */ |
|
537 | + do_action( |
|
538 | + 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
539 | + $item, |
|
540 | + $this->_screen |
|
541 | + ); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Get a list of columns. The format is: |
|
547 | + * 'internal-name' => 'Title' |
|
548 | + * |
|
549 | + * @since 3.1.0 |
|
550 | + * @access public |
|
551 | + * @abstract |
|
552 | + * @return array |
|
553 | + */ |
|
554 | + public function get_columns() |
|
555 | + { |
|
556 | + /** |
|
557 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
558 | + * Note that $this->screen->id is in the format |
|
559 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
560 | + * table it is: event-espresso_page_espresso_messages. |
|
561 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
562 | + * hook prefix ("event-espresso") will be different. |
|
563 | + * |
|
564 | + * @var array |
|
565 | + */ |
|
566 | + $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
567 | + return $columns; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Get an associative array ( id => link ) with the list |
|
573 | + * of views available on this table. |
|
574 | + * |
|
575 | + * @since 3.1.0 |
|
576 | + * @access protected |
|
577 | + * @return array |
|
578 | + */ |
|
579 | + public function get_views() |
|
580 | + { |
|
581 | + return $this->_views; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Generate the views html. |
|
587 | + */ |
|
588 | + public function display_views() |
|
589 | + { |
|
590 | + $views = $this->get_views(); |
|
591 | + $assembled_views = array(); |
|
592 | + |
|
593 | + if (empty($views)) { |
|
594 | + return; |
|
595 | + } |
|
596 | + echo "<ul class='subsubsub'>\n"; |
|
597 | + foreach ($views as $view) { |
|
598 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
599 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
600 | + $assembled_views[ $view['slug'] ] = "\t<li class='" . $view['class'] . "'>" |
|
601 | + . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>' |
|
602 | + . ' <span class="count">(' . $count . ')</span>'; |
|
603 | + } |
|
604 | + } |
|
605 | + |
|
606 | + echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
607 | + echo "</ul>"; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Generates content for a single row of the table |
|
613 | + * |
|
614 | + * @since 4.1 |
|
615 | + * @access public |
|
616 | + * @param EE_Base_Class $item The current item |
|
617 | + */ |
|
618 | + public function single_row($item) |
|
619 | + { |
|
620 | + $row_class = $this->_get_row_class($item); |
|
621 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
622 | + $this->single_row_columns($item); |
|
623 | + echo '</tr>'; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * This simply sets up the row class for the table rows. |
|
629 | + * Allows for easier overriding of child methods for setting up sorting. |
|
630 | + * |
|
631 | + * @param EE_Base_Class $item the current item |
|
632 | + * @return string |
|
633 | + */ |
|
634 | + protected function _get_row_class($item) |
|
635 | + { |
|
636 | + static $row_class = ''; |
|
637 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
638 | + |
|
639 | + $new_row_class = $row_class; |
|
640 | + |
|
641 | + if (! empty($this->_ajax_sorting_callback)) { |
|
642 | + $new_row_class .= ' rowsortable'; |
|
643 | + } |
|
644 | + |
|
645 | + return $new_row_class; |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * @return array |
|
651 | + */ |
|
652 | + public function get_sortable_columns() |
|
653 | + { |
|
654 | + return (array) $this->_sortable_columns; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function get_ajax_sorting_callback() |
|
662 | + { |
|
663 | + return $this->_ajax_sorting_callback; |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * @return array |
|
669 | + */ |
|
670 | + public function get_hidden_columns() |
|
671 | + { |
|
672 | + $user_id = get_current_user_id(); |
|
673 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
674 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
675 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
676 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
677 | + } |
|
678 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
679 | + return (array) get_user_option($ref, $user_id); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * Generates the columns for a single row of the table. |
|
685 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
686 | + * column. |
|
687 | + * |
|
688 | + * @since 3.1.0 |
|
689 | + * @param EE_Base_Class $item The current item |
|
690 | + */ |
|
691 | + public function single_row_columns($item) |
|
692 | + { |
|
693 | + list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
694 | + |
|
695 | + global $wp_version; |
|
696 | + $use_hidden_class = version_compare($wp_version, '4.3-RC', '>='); |
|
697 | + |
|
698 | + foreach ($columns as $column_name => $column_display_name) { |
|
699 | + |
|
700 | + /** |
|
701 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
702 | + * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
703 | + */ |
|
704 | + $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
|
705 | + $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
|
706 | + |
|
707 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
708 | + if ($primary === $column_name) { |
|
709 | + $classes .= ' has-row-actions column-primary'; |
|
710 | + } |
|
711 | + |
|
712 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
713 | + |
|
714 | + $class = "class='$classes'"; |
|
715 | + |
|
716 | + $attributes = "$class$style$data"; |
|
717 | + |
|
718 | + if ($column_name === 'cb') { |
|
719 | + echo '<th scope="row" class="check-column">'; |
|
720 | + echo apply_filters( |
|
721 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
722 | + $this->column_cb($item), |
|
723 | + $item, |
|
724 | + $this |
|
725 | + ); |
|
726 | + echo '</th>'; |
|
727 | + } elseif (method_exists($this, 'column_' . $column_name)) { |
|
728 | + echo "<td $attributes>"; |
|
729 | + echo apply_filters( |
|
730 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
731 | + call_user_func(array($this, 'column_' . $column_name), $item), |
|
732 | + $item, |
|
733 | + $this |
|
734 | + ); |
|
735 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
736 | + echo "</td>"; |
|
737 | + } else { |
|
738 | + echo "<td $attributes>"; |
|
739 | + echo apply_filters( |
|
740 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
741 | + $this->column_default($item, $column_name), |
|
742 | + $item, |
|
743 | + $column_name, |
|
744 | + $this |
|
745 | + ); |
|
746 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
747 | + echo "</td>"; |
|
748 | + } |
|
749 | + } |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Extra controls to be displayed between bulk actions and pagination |
|
755 | + * |
|
756 | + * @access public |
|
757 | + * @param string $which |
|
758 | + * @throws \EE_Error |
|
759 | + */ |
|
760 | + public function extra_tablenav($which) |
|
761 | + { |
|
762 | + if ($which === 'top') { |
|
763 | + $this->_filters(); |
|
764 | + echo $this->_get_hidden_fields(); |
|
765 | + } else { |
|
766 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
767 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
768 | + $route = isset($action['route']) ? $action['route'] : ''; |
|
769 | + $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
770 | + echo $this->_admin_page->get_action_link_or_button( |
|
771 | + $route, |
|
772 | + $type, |
|
773 | + $extra_request, |
|
774 | + 'button button-secondary', |
|
775 | + '', |
|
776 | + false |
|
777 | + ); |
|
778 | + } |
|
779 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
780 | + echo '</div>'; |
|
781 | + } |
|
782 | + // echo $this->_entries_per_page_dropdown; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Get an associative array ( option_name => option_title ) with the list |
|
788 | + * of bulk actions available on this table. |
|
789 | + * |
|
790 | + * @since 3.1.0 |
|
791 | + * @access protected |
|
792 | + * @return array |
|
793 | + */ |
|
794 | + public function get_bulk_actions() |
|
795 | + { |
|
796 | + return (array) $this->_get_bulk_actions(); |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Processing bulk actions. |
|
801 | + */ |
|
802 | + public function process_bulk_action() |
|
803 | + { |
|
804 | + // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
805 | + // reference in case there is a case where it gets used. |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + /** |
|
810 | + * returns the EE admin page this list table is associated with |
|
811 | + * |
|
812 | + * @return EE_Admin_Page |
|
813 | + */ |
|
814 | + public function get_admin_page() |
|
815 | + { |
|
816 | + return $this->_admin_page; |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * A "helper" function for all children to provide an html string of |
|
822 | + * actions to output in their content. It is preferable for child classes |
|
823 | + * to use this method for generating their actions content so that it's |
|
824 | + * filterable by plugins |
|
825 | + * |
|
826 | + * @param string $action_container what are the html container |
|
827 | + * elements for this actions string? |
|
828 | + * @param string $action_class What class is for the container |
|
829 | + * element. |
|
830 | + * @param string $action_items The contents for the action items |
|
831 | + * container. This is filtered before |
|
832 | + * returned. |
|
833 | + * @param string $action_id What id (optional) is used for the |
|
834 | + * container element. |
|
835 | + * @param EE_Base_Class $item The object for the column displaying |
|
836 | + * the actions. |
|
837 | + * @return string The assembled action elements container. |
|
838 | + */ |
|
839 | + protected function _action_string( |
|
840 | + $action_items, |
|
841 | + $item, |
|
842 | + $action_container = 'ul', |
|
843 | + $action_class = '', |
|
844 | + $action_id = '' |
|
845 | + ) { |
|
846 | + $content = ''; |
|
847 | + $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
848 | + $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
849 | + $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
850 | + try { |
|
851 | + $content .= apply_filters( |
|
852 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
853 | + $action_items, |
|
854 | + $item, |
|
855 | + $this |
|
856 | + ); |
|
857 | + } catch (\Exception $e) { |
|
858 | + if (WP_DEBUG) { |
|
859 | + \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
860 | + } |
|
861 | + $content .= $action_items; |
|
862 | + } |
|
863 | + $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
864 | + return $content; |
|
865 | + } |
|
866 | 866 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! class_exists('WP_List_Table')) { |
|
4 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
3 | +if ( ! class_exists('WP_List_Table')) { |
|
4 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | $this->_view = $this->_admin_page->get_view(); |
205 | 205 | $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
206 | 206 | $this->_current_page = $this->get_pagenum(); |
207 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
207 | + $this->_screen = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view(); |
|
208 | 208 | $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
209 | 209 | |
210 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 10); |
|
210 | + $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 10); |
|
211 | 211 | |
212 | 212 | $this->_setup_data(); |
213 | 213 | $this->_add_view_counts(); |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
288 | 288 | // if action is STILL empty, then we set it to default |
289 | 289 | $action = empty($action) ? 'default' : $action; |
290 | - $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
291 | - $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
292 | - $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
290 | + $field = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n"; |
|
291 | + $field .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/ |
|
292 | + $field .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n"; |
|
293 | 293 | |
294 | 294 | $bulk_actions = $this->_get_bulk_actions(); |
295 | 295 | foreach ($bulk_actions as $bulk_action => $label) { |
296 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
297 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
296 | + $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"' |
|
297 | + . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n"; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | return $field; |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | |
342 | 342 | $data = (array) $data; |
343 | 343 | |
344 | - if (! isset($data[1])) { |
|
344 | + if ( ! isset($data[1])) { |
|
345 | 345 | $_data[1] = false; |
346 | 346 | } |
347 | 347 | |
348 | - $sortable[ $id ] = $_data; |
|
348 | + $sortable[$id] = $_data; |
|
349 | 349 | } |
350 | 350 | $primary = $this->get_primary_column_name(); |
351 | 351 | $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | // for that page route and skip adding the bulk action if no access for the current logged in user. |
406 | 406 | foreach ($args['bulk_action'] as $route => $label) { |
407 | 407 | if ($this->_admin_page->check_user_access($route, true)) { |
408 | - $actions[ $route ] = $label; |
|
408 | + $actions[$route] = $label; |
|
409 | 409 | } |
410 | 410 | } |
411 | 411 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | public function display_tablenav($which) |
424 | 424 | { |
425 | 425 | if ('top' === $which) { |
426 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
426 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
427 | 427 | } |
428 | 428 | ?> |
429 | 429 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * hook prefix ("event-espresso") will be different. |
536 | 536 | */ |
537 | 537 | do_action( |
538 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
538 | + 'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id, |
|
539 | 539 | $item, |
540 | 540 | $this->_screen |
541 | 541 | ); |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * |
564 | 564 | * @var array |
565 | 565 | */ |
566 | - $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
566 | + $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen); |
|
567 | 567 | return $columns; |
568 | 568 | } |
569 | 569 | |
@@ -597,13 +597,13 @@ discard block |
||
597 | 597 | foreach ($views as $view) { |
598 | 598 | $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
599 | 599 | if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
600 | - $assembled_views[ $view['slug'] ] = "\t<li class='" . $view['class'] . "'>" |
|
601 | - . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>' |
|
602 | - . ' <span class="count">(' . $count . ')</span>'; |
|
600 | + $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>" |
|
601 | + . '<a href="'.$view['url'].'">'.$view['label'].'</a>' |
|
602 | + . ' <span class="count">('.$count.')</span>'; |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | |
606 | - echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
606 | + echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : ''; |
|
607 | 607 | echo "</ul>"; |
608 | 608 | } |
609 | 609 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | public function single_row($item) |
619 | 619 | { |
620 | 620 | $row_class = $this->_get_row_class($item); |
621 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
621 | + echo '<tr class="'.esc_attr($row_class).'">'; |
|
622 | 622 | $this->single_row_columns($item); |
623 | 623 | echo '</tr>'; |
624 | 624 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | |
639 | 639 | $new_row_class = $row_class; |
640 | 640 | |
641 | - if (! empty($this->_ajax_sorting_callback)) { |
|
641 | + if ( ! empty($this->_ajax_sorting_callback)) { |
|
642 | 642 | $new_row_class .= ' rowsortable'; |
643 | 643 | } |
644 | 644 | |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | public function get_hidden_columns() |
671 | 671 | { |
672 | 672 | $user_id = get_current_user_id(); |
673 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
673 | + $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id); |
|
674 | 674 | if (empty($has_default) && ! empty($this->_hidden_columns)) { |
675 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
676 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
675 | + update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true); |
|
676 | + update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true); |
|
677 | 677 | } |
678 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
678 | + $ref = 'manage'.$this->screen->id.'columnshidden'; |
|
679 | 679 | return (array) get_user_option($ref, $user_id); |
680 | 680 | } |
681 | 681 | |
@@ -704,12 +704,12 @@ discard block |
||
704 | 704 | $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
705 | 705 | $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
706 | 706 | |
707 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
707 | + $classes = $column_name.' column-'.$column_name.$hidden_class; |
|
708 | 708 | if ($primary === $column_name) { |
709 | 709 | $classes .= ' has-row-actions column-primary'; |
710 | 710 | } |
711 | 711 | |
712 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
712 | + $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"'; |
|
713 | 713 | |
714 | 714 | $class = "class='$classes'"; |
715 | 715 | |
@@ -724,11 +724,11 @@ discard block |
||
724 | 724 | $this |
725 | 725 | ); |
726 | 726 | echo '</th>'; |
727 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
727 | + } elseif (method_exists($this, 'column_'.$column_name)) { |
|
728 | 728 | echo "<td $attributes>"; |
729 | 729 | echo apply_filters( |
730 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
731 | - call_user_func(array($this, 'column_' . $column_name), $item), |
|
730 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content', |
|
731 | + call_user_func(array($this, 'column_'.$column_name), $item), |
|
732 | 732 | $item, |
733 | 733 | $this |
734 | 734 | ); |
@@ -844,9 +844,9 @@ discard block |
||
844 | 844 | $action_id = '' |
845 | 845 | ) { |
846 | 846 | $content = ''; |
847 | - $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
848 | - $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
849 | - $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
847 | + $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : ''; |
|
848 | + $action_id = ! empty($action_id) ? ' id="'.$action_id.'"' : ''; |
|
849 | + $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : ''; |
|
850 | 850 | try { |
851 | 851 | $content .= apply_filters( |
852 | 852 | 'FHEE__EE_Admin_List_Table___action_string__action_items', |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | } |
861 | 861 | $content .= $action_items; |
862 | 862 | } |
863 | - $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
863 | + $content .= ! empty($action_container) ? '</'.$action_container.'>' : ''; |
|
864 | 864 | return $content; |
865 | 865 | } |
866 | 866 | } |
@@ -14,43 +14,43 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - public function do_initial_loads() |
|
18 | - { |
|
19 | - // we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
|
20 | - // This is important because we have hooks that help redirect custom post type saves |
|
21 | - if (! isset($_REQUEST['page']) |
|
22 | - || (isset($_REQUEST['page']) |
|
23 | - && $_REQUEST['page'] |
|
24 | - != $this->_menu_map->menu_slug)) { |
|
25 | - $this->_routing = false; |
|
26 | - $this->_initialize_admin_page(); |
|
27 | - } else { |
|
28 | - // normal init loads |
|
29 | - $this->_initialize_admin_page(); |
|
30 | - // added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality |
|
31 | - remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization'); |
|
32 | - add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100); |
|
33 | - // end removal of autosave functionality. |
|
34 | - } |
|
35 | - } |
|
17 | + public function do_initial_loads() |
|
18 | + { |
|
19 | + // we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
|
20 | + // This is important because we have hooks that help redirect custom post type saves |
|
21 | + if (! isset($_REQUEST['page']) |
|
22 | + || (isset($_REQUEST['page']) |
|
23 | + && $_REQUEST['page'] |
|
24 | + != $this->_menu_map->menu_slug)) { |
|
25 | + $this->_routing = false; |
|
26 | + $this->_initialize_admin_page(); |
|
27 | + } else { |
|
28 | + // normal init loads |
|
29 | + $this->_initialize_admin_page(); |
|
30 | + // added for 4.1 to completely disable autosave for our pages. This can be removed once we fully enable autosave functionality |
|
31 | + remove_filter('wp_print_scripts', 'wp_just_in_time_script_localization'); |
|
32 | + add_filter('wp_print_scripts', array($this, 'wp_just_in_time_script_localization'), 100); |
|
33 | + // end removal of autosave functionality. |
|
34 | + } |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - public function wp_just_in_time_script_localization() |
|
39 | - { |
|
40 | - wp_localize_script( |
|
41 | - 'autosave', |
|
42 | - 'autosaveL10n', |
|
43 | - array( |
|
44 | - 'autosaveInterval' => 172800, |
|
45 | - 'savingText' => __('Saving Draft…', 'event_espresso'), |
|
46 | - 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.', 'event_espresso'), |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
38 | + public function wp_just_in_time_script_localization() |
|
39 | + { |
|
40 | + wp_localize_script( |
|
41 | + 'autosave', |
|
42 | + 'autosaveL10n', |
|
43 | + array( |
|
44 | + 'autosaveInterval' => 172800, |
|
45 | + 'savingText' => __('Saving Draft…', 'event_espresso'), |
|
46 | + 'saveAlert' => __('The changes you made will be lost if you navigate away from this page.', 'event_espresso'), |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - public function adjust_post_lock_window($interval) |
|
53 | - { |
|
54 | - return 172800; |
|
55 | - } |
|
52 | + public function adjust_post_lock_window($interval) |
|
53 | + { |
|
54 | + return 172800; |
|
55 | + } |
|
56 | 56 | } |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | // we want to use the corresponding admin page object (but not route it!). To do this we just set _routing to false. That way this page object is being loaded on all pages to make sure we hook into admin properly. But note... we are ONLY doing this if the given page is NOT pages we WANT to load ;) |
20 | 20 | // This is important because we have hooks that help redirect custom post type saves |
21 | - if (! isset($_REQUEST['page']) |
|
21 | + if ( ! isset($_REQUEST['page']) |
|
22 | 22 | || (isset($_REQUEST['page']) |
23 | 23 | && $_REQUEST['page'] |
24 | 24 | != $this->_menu_map->menu_slug)) { |
@@ -4,19 +4,19 @@ |
||
4 | 4 | <div class="about-text"><?php echo ! empty($admin_page_subtitle) ? $admin_page_subtitle : ''; ?></div> |
5 | 5 | <div class="ee-badge"><img class="" src=" <?php echo EE_GLOBAL_ASSETS_URL; ?>images/event-espresso-cup-90x90.png" |
6 | 6 | width="90" height="90" alt="<?php |
7 | - printf( |
|
8 | - esc_attr__('%s Logo', 'event_espresso'), |
|
9 | - 'Event Espresso' |
|
10 | - ); ?>"/> |
|
7 | + printf( |
|
8 | + esc_attr__('%s Logo', 'event_espresso'), |
|
9 | + 'Event Espresso' |
|
10 | + ); ?>"/> |
|
11 | 11 | <br/><?php printf(__('Version %s', 'event_espresso'), EVENT_ESPRESSO_VERSION); ?></div> |
12 | 12 | |
13 | 13 | <?php echo $nav_tabs; ?> |
14 | 14 | |
15 | 15 | |
16 | 16 | <?php |
17 | - do_action('AHEE__admin_wrapper__template__before_about_admin_page_content'); |
|
18 | - echo $about_admin_page_content; |
|
19 | - do_action('AHEE__admin_wrapper__template__after_about_admin_page_content'); |
|
20 | - ?> |
|
17 | + do_action('AHEE__admin_wrapper__template__before_about_admin_page_content'); |
|
18 | + echo $about_admin_page_content; |
|
19 | + do_action('AHEE__admin_wrapper__template__after_about_admin_page_content'); |
|
20 | + ?> |
|
21 | 21 | |
22 | 22 | </div> |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | <dl class="alignleft ee-list-table-legend"> |
11 | 11 | <?php foreach ($items as $item => $details) : ?> |
12 | 12 | <?php |
13 | - if ($per_col < $count) : ?> |
|
13 | + if ($per_col < $count) : ?> |
|
14 | 14 | </dl> |
15 | 15 | <dl class="alignleft ee-list-table-legend"> |
16 | 16 | <?php $count = 1; |
17 | - endif; ?> |
|
17 | + endif; ?> |
|
18 | 18 | <dt id="ee-legend-item-<?php echo $item; ?>"> |
19 | 19 | <?php $class = ! empty($details['class']) ? $details['class'] : 'ee-legend-img-container'; ?> |
20 | 20 | <?php |
21 | - if (strpos($details['class'], '<span') !== false) { |
|
22 | - echo $class; |
|
23 | - } else { ?> |
|
21 | + if (strpos($details['class'], '<span') !== false) { |
|
22 | + echo $class; |
|
23 | + } else { ?> |
|
24 | 24 | <span class="<?php echo $class; ?>"> |
25 | 25 | <?php if (! empty($details['icon'])) : ?> |
26 | 26 | <img src="<?php echo $details['icon']; ?>" class="ee-legend-icon" |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | <?php endif; ?> |
29 | 29 | </span> |
30 | 30 | <?php |
31 | - } ?> |
|
31 | + } ?> |
|
32 | 32 | <span class="ee-legend-description"><?php echo $details['desc']; ?></span> |
33 | 33 | </dt> |
34 | 34 | <?php $count++; |
35 | - endforeach; ?> |
|
35 | + endforeach; ?> |
|
36 | 36 | </dl> |
37 | 37 | <div style="clear:both"></div> |
38 | 38 | </div> |
@@ -22,7 +22,7 @@ |
||
22 | 22 | echo $class; |
23 | 23 | } else { ?> |
24 | 24 | <span class="<?php echo $class; ?>"> |
25 | - <?php if (! empty($details['icon'])) : ?> |
|
25 | + <?php if ( ! empty($details['icon'])) : ?> |
|
26 | 26 | <img src="<?php echo $details['icon']; ?>" class="ee-legend-icon" |
27 | 27 | alt="<?php echo esc_attr($details['desc']); ?>"/> |
28 | 28 | <?php endif; ?> |
@@ -7,11 +7,11 @@ |
||
7 | 7 | <?php echo $nav_tabs; ?> |
8 | 8 | |
9 | 9 | <?php |
10 | - do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
|
11 | - echo $before_admin_page_content; |
|
12 | - echo $admin_page_content; |
|
13 | - echo $after_admin_page_content; |
|
14 | - do_action('AHEE__admin_wrapper__template__after_admin_page_content'); |
|
15 | - ?> |
|
10 | + do_action('AHEE__admin_wrapper__template__before_admin_page_content'); |
|
11 | + echo $before_admin_page_content; |
|
12 | + echo $admin_page_content; |
|
13 | + echo $after_admin_page_content; |
|
14 | + do_action('AHEE__admin_wrapper__template__after_admin_page_content'); |
|
15 | + ?> |
|
16 | 16 | |
17 | 17 | </div> |
@@ -9,11 +9,11 @@ |
||
9 | 9 | </div> <!-- post-body-content --> |
10 | 10 | |
11 | 11 | <?php |
12 | - // let's loop through the columns |
|
13 | - for ($i = 1; $i <= $num_columns; $i++) { |
|
14 | - $metaref = ($i === 1) ? 'normal' : 'side'; |
|
15 | - $metaref = ($i > 2) ? 'column' . $i : $metaref; |
|
16 | - ?> |
|
12 | + // let's loop through the columns |
|
13 | + for ($i = 1; $i <= $num_columns; $i++) { |
|
14 | + $metaref = ($i === 1) ? 'normal' : 'side'; |
|
15 | + $metaref = ($i > 2) ? 'column' . $i : $metaref; |
|
16 | + ?> |
|
17 | 17 | |
18 | 18 | <div id='postbox-container-<?php echo $i; ?>' class='postbox-container'> |
19 | 19 | <?php do_meta_boxes($current_page, $metaref, null); ?> |
@@ -12,7 +12,7 @@ |
||
12 | 12 | // let's loop through the columns |
13 | 13 | for ($i = 1; $i <= $num_columns; $i++) { |
14 | 14 | $metaref = ($i === 1) ? 'normal' : 'side'; |
15 | - $metaref = ($i > 2) ? 'column' . $i : $metaref; |
|
15 | + $metaref = ($i > 2) ? 'column'.$i : $metaref; |
|
16 | 16 | ?> |
17 | 17 | |
18 | 18 | <div id='postbox-container-<?php echo $i; ?>' class='postbox-container'> |