PluginProbe
Advanced Custom Fields (ACF®) / 5.9.8
Advanced Custom Fields (ACF®) v5.9.8
6.8.9 6.8.8 6.8.7 6.8.6 6.8.5 6.8.4 6.8.3 6.8.2 6.8.1 5.8.5 5.8.6 5.8.7 5.8.8 5.8.9 5.9.0 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 6.0.0 All 230 releases
advanced-custom-fields / includes / admin / admin-tools.php
admin-tools.php
353 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if( ! class_exists('acf_admin_tools') ) :
6
7 class acf_admin_tools {
8
9
10 /** @var array Contains an array of admin tool instances */
11 var $tools = array();
12
13
14 /** @var string The active tool */
15 var $active = '';
16
17
18 /**
19 * __construct
20 *
21 * This function will setup the class functionality
22 *
23 * @date 10/10/17
24 * @since 5.6.3
25 *
26 * @param n/a
27 * @return n/a
28 */
29
30 function __construct() {
31
32 // actions
33 add_action('admin_menu', array($this, 'admin_menu'));
34
35 }
36
37
38 /**
39 * register_tool
40 *
41 * This function will store a tool tool class
42 *
43 * @date 10/10/17
44 * @since 5.6.3
45 *
46 * @param string $class
47 * @return n/a
48 */
49
50 function register_tool( $class ) {
51
52 $instance = new $class();
53 $this->tools[ $instance->name ] = $instance;
54
55 }
56
57
58 /**
59 * get_tool
60 *
61 * This function will return a tool tool class
62 *
63 * @date 10/10/17
64 * @since 5.6.3
65 *
66 * @param string $name
67 * @return n/a
68 */
69
70 function get_tool( $name ) {
71
72 return isset( $this->tools[$name] ) ? $this->tools[$name] : null;
73
74 }
75
76
77 /**
78 * get_tools
79 *
80 * This function will return an array of all tools
81 *
82 * @date 10/10/17
83 * @since 5.6.3
84 *
85 * @param n/a
86 * @return array
87 */
88
89 function get_tools() {
90
91 return $this->tools;
92
93 }
94
95
96 /*
97 * admin_menu
98 *
99 * This function will add the ACF menu item to the WP admin
100 *
101 * @type action (admin_menu)
102 * @date 28/09/13
103 * @since 5.0.0
104 *
105 * @param n/a
106 * @return n/a
107 */
108
109 function admin_menu() {
110
111 // bail early if no show_admin
112 if( !acf_get_setting('show_admin') ) return;
113
114
115 // add page
116 $page = add_submenu_page('edit.php?post_type=acf-field-group', __('Tools','acf'), __('Tools','acf'), acf_get_setting('capability'), 'acf-tools', array($this, 'html'));
117
118
119 // actions
120 add_action('load-' . $page, array($this, 'load'));
121
122 }
123
124
125 /**
126 * load
127 *
128 * description
129 *
130 * @date 10/10/17
131 * @since 5.6.3
132 *
133 * @param n/a
134 * @return n/a
135 */
136
137 function load() {
138
139 // disable filters (default to raw data)
140 acf_disable_filters();
141
142
143 // include tools
144 $this->include_tools();
145
146
147 // check submit
148 $this->check_submit();
149
150
151 // load acf scripts
152 acf_enqueue_scripts();
153
154 }
155
156
157 /**
158 * include_tools
159 *
160 * description
161 *
162 * @date 10/10/17
163 * @since 5.6.3
164 *
165 * @param n/a
166 * @return n/a
167 */
168
169 function include_tools() {
170
171 // include
172 acf_include('includes/admin/tools/class-acf-admin-tool.php');
173 acf_include('includes/admin/tools/class-acf-admin-tool-export.php');
174 acf_include('includes/admin/tools/class-acf-admin-tool-import.php');
175
176
177 // action
178 do_action('acf/include_admin_tools');
179
180 }
181
182
183 /**
184 * check_submit
185 *
186 * description
187 *
188 * @date 10/10/17
189 * @since 5.6.3
190 *
191 * @param n/a
192 * @return n/a
193 */
194
195 function check_submit() {
196
197 // loop
198 foreach( $this->get_tools() as $tool ) {
199
200 // load
201 $tool->load();
202
203
204 // submit
205 if( acf_verify_nonce($tool->name) ) {
206 $tool->submit();
207 }
208
209 }
210
211 }
212
213
214 /**
215 * html
216 *
217 * description
218 *
219 * @date 10/10/17
220 * @since 5.6.3
221 *
222 * @param n/a
223 * @return n/a
224 */
225
226 function html() {
227
228 // vars
229 $screen = get_current_screen();
230 $active = acf_maybe_get_GET('tool');
231
232
233 // view
234 $view = array(
235 'screen_id' => $screen->id,
236 'active' => $active
237 );
238
239
240 // register metaboxes
241 foreach( $this->get_tools() as $tool ) {
242
243 // check active
244 if( $active && $active !== $tool->name ) continue;
245
246 // add metabox
247 add_meta_box( 'acf-admin-tool-' . $tool->name, acf_esc_html( $tool->title ), array($this, 'metabox_html'), $screen->id, 'normal', 'default', array('tool' => $tool->name) );
248
249 }
250
251
252 // view
253 acf_get_view( 'html-admin-tools', $view );
254
255 }
256
257
258 /**
259 * meta_box_html
260 *
261 * description
262 *
263 * @date 10/10/17
264 * @since 5.6.3
265 *
266 * @param n/a
267 * @return n/a
268 */
269
270 function metabox_html( $post, $metabox ) {
271
272 // vars
273 $tool = $this->get_tool($metabox['args']['tool']);
274
275
276 ?>
277 <form method="post">
278 <?php $tool->html(); ?>
279 <?php acf_nonce_input( $tool->name ); ?>
280 </form>
281 <?php
282
283 }
284
285 }
286
287 // initialize
288 acf()->admin_tools = new acf_admin_tools();
289
290 endif; // class_exists check
291
292
293 /*
294 * acf_register_admin_tool
295 *
296 * alias of acf()->admin_tools->register_tool()
297 *
298 * @type function
299 * @date 31/5/17
300 * @since 5.6.0
301 *
302 * @param n/a
303 * @return n/a
304 */
305
306 function acf_register_admin_tool( $class ) {
307
308 return acf()->admin_tools->register_tool( $class );
309
310 }
311
312
313 /*
314 * acf_get_admin_tools_url
315 *
316 * This function will return the admin URL to the tools page
317 *
318 * @type function
319 * @date 31/5/17
320 * @since 5.6.0
321 *
322 * @param n/a
323 * @return n/a
324 */
325
326 function acf_get_admin_tools_url() {
327
328 return admin_url('edit.php?post_type=acf-field-group&page=acf-tools');
329
330 }
331
332
333 /*
334 * acf_get_admin_tool_url
335 *
336 * This function will return the admin URL to the tools page
337 *
338 * @type function
339 * @date 31/5/17
340 * @since 5.6.0
341 *
342 * @param n/a
343 * @return n/a
344 */
345
346 function acf_get_admin_tool_url( $tool = '' ) {
347
348 return acf_get_admin_tools_url() . '&tool='.$tool;
349
350 }
351
352
353 ?>