PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta2
Secure Custom Fields v6.4.0-beta2
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / admin / admin-tools.php
secure-custom-fields / includes / admin Last commit date
post-types 1 year ago tools 1 year ago views 1 year ago admin-internal-post-type-list.php 1 year ago admin-internal-post-type.php 1 year ago admin-notices.php 1 year ago admin-tools.php 1 year ago admin-upgrade.php 1 year ago admin.php 1 year ago index.php 1 year ago
admin-tools.php
319 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'acf_admin_tools' ) ) :
8 #[AllowDynamicProperties]
9 class acf_admin_tools {
10
11
12 /** @var array Contains an array of admin tool instances */
13 var $tools = array();
14
15
16 /** @var string The active tool */
17 var $active = '';
18
19
20 /**
21 * __construct
22 *
23 * This function will setup the class functionality
24 *
25 * @date 10/10/17
26 * @since 5.6.3
27 *
28 * @param n/a
29 * @return n/a
30 */
31 function __construct() {
32
33 // actions
34 add_action( 'admin_menu', array( $this, 'admin_menu' ), 15 );
35 }
36
37 /**
38 * register_tool
39 *
40 * This function will store a tool tool class
41 *
42 * @date 10/10/17
43 * @since 5.6.3
44 *
45 * @param string $class
46 * @return n/a
47 */
48 function register_tool( $class ) {
49
50 $instance = new $class();
51 $this->tools[ $instance->name ] = $instance;
52 }
53
54
55 /**
56 * get_tool
57 *
58 * This function will return a tool tool class
59 *
60 * @date 10/10/17
61 * @since 5.6.3
62 *
63 * @param string $name
64 * @return n/a
65 */
66 function get_tool( $name ) {
67
68 return isset( $this->tools[ $name ] ) ? $this->tools[ $name ] : null;
69 }
70
71
72 /**
73 * get_tools
74 *
75 * This function will return an array of all tools
76 *
77 * @date 10/10/17
78 * @since 5.6.3
79 *
80 * @param n/a
81 * @return array
82 */
83 function get_tools() {
84
85 return $this->tools;
86 }
87
88
89 /**
90 * This function will add the ACF menu item to the WP admin
91 *
92 * @type action (admin_menu)
93 * @date 28/09/13
94 * @since 5.0.0
95 *
96 * @param n/a
97 * @return n/a
98 */
99 function admin_menu() {
100
101 // bail early if no show_admin
102 if ( ! acf_get_setting( 'show_admin' ) ) {
103 return;
104 }
105
106 // add page
107 $page = add_submenu_page( 'edit.php?post_type=acf-field-group', __( 'Tools', 'acf' ), __( 'Tools', 'acf' ), acf_get_setting( 'capability' ), 'acf-tools', array( $this, 'html' ) );
108
109 // actions
110 add_action( 'load-' . $page, array( $this, 'load' ) );
111 }
112
113
114 /**
115 * load
116 *
117 * description
118 *
119 * @date 10/10/17
120 * @since 5.6.3
121 *
122 * @param n/a
123 * @return n/a
124 */
125 function load() {
126
127 add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
128
129 // disable filters (default to raw data)
130 acf_disable_filters();
131
132 // include tools
133 $this->include_tools();
134
135 // check submit
136 $this->check_submit();
137
138 // load acf scripts
139 acf_enqueue_scripts();
140 }
141
142 /**
143 * Modifies the admin body class.
144 *
145 * @since 6.0.0
146 *
147 * @param string $classes Space-separated list of CSS classes.
148 * @return string
149 */
150 public function admin_body_class( $classes ) {
151 $classes .= ' acf-admin-page';
152 return $classes;
153 }
154
155 /**
156 * include_tools
157 *
158 * description
159 *
160 * @date 10/10/17
161 * @since 5.6.3
162 *
163 * @param n/a
164 * @return n/a
165 */
166 function include_tools() {
167
168 // include
169 acf_include( 'includes/admin/tools/class-acf-admin-tool.php' );
170 acf_include( 'includes/admin/tools/class-acf-admin-tool-export.php' );
171 acf_include( 'includes/admin/tools/class-acf-admin-tool-import.php' );
172
173 // action
174 do_action( 'acf/include_admin_tools' );
175 }
176
177
178 /**
179 * check_submit
180 *
181 * description
182 *
183 * @date 10/10/17
184 * @since 5.6.3
185 *
186 * @param n/a
187 * @return n/a
188 */
189 function check_submit() {
190
191 // loop
192 foreach ( $this->get_tools() as $tool ) {
193
194 // load
195 $tool->load();
196
197 // submit
198 if ( acf_verify_nonce( $tool->name ) ) {
199 $tool->submit();
200 }
201 }
202 }
203
204
205 /**
206 * html
207 *
208 * description
209 *
210 * @date 10/10/17
211 * @since 5.6.3
212 *
213 * @param n/a
214 * @return n/a
215 */
216 function html() {
217
218 // vars
219 $screen = get_current_screen();
220 $active = acf_maybe_get_GET( 'tool' );
221
222 // view
223 $view = array(
224 'screen_id' => $screen->id,
225 'active' => $active,
226 );
227
228 // register metaboxes
229 foreach ( $this->get_tools() as $tool ) {
230
231 // check active
232 if ( $active && $active !== $tool->name ) {
233 continue;
234 }
235
236 // add metabox
237 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 ) );
238 }
239
240 // view
241 acf_get_view( 'tools/tools', $view );
242 }
243
244
245 /**
246 * Output the metabox HTML for specific tools
247 *
248 * @since 5.6.3
249 *
250 * @param mixed $post The post this metabox is being displayed on, should be an empty string always for us on a tools page.
251 * @param array $metabox An array of the metabox attributes.
252 */
253 public function metabox_html( $post, $metabox ) {
254 $tool = $this->get_tool( $metabox['args']['tool'] );
255 $form_attrs = array( 'method' => 'post' );
256
257 if ( $metabox['args']['tool'] === 'import' ) {
258 $form_attrs['onsubmit'] = 'acf.disableForm(event)';
259 }
260
261 printf( '<form %s>', acf_esc_attrs( $form_attrs ) );
262 $tool->html();
263 acf_nonce_input( $tool->name );
264 echo '</form>';
265 }
266 }
267
268 // initialize
269 acf()->admin_tools = new acf_admin_tools();
270 endif; // class_exists check
271
272
273 /**
274 * alias of acf()->admin_tools->register_tool()
275 *
276 * @type function
277 * @date 31/5/17
278 * @since 5.6.0
279 *
280 * @param n/a
281 * @return n/a
282 */
283 function acf_register_admin_tool( $class ) {
284
285 return acf()->admin_tools->register_tool( $class );
286 }
287
288
289 /**
290 * This function will return the admin URL to the tools page
291 *
292 * @type function
293 * @date 31/5/17
294 * @since 5.6.0
295 *
296 * @param n/a
297 * @return n/a
298 */
299 function acf_get_admin_tools_url() {
300
301 return admin_url( 'edit.php?post_type=acf-field-group&page=acf-tools' );
302 }
303
304
305 /**
306 * This function will return the admin URL to the tools page
307 *
308 * @type function
309 * @date 31/5/17
310 * @since 5.6.0
311 *
312 * @param n/a
313 * @return n/a
314 */
315 function acf_get_admin_tool_url( $tool = '' ) {
316
317 return acf_get_admin_tools_url() . '&tool=' . $tool;
318 }
319