PluginProbe
Advanced Custom Fields (ACF®) / 6.4.1
Advanced Custom Fields (ACF®) v6.4.1
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.php

admin.php in Advanced Custom Fields (ACF®) 6.4.1, at includes/admin/admin.php

405 lines 13.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Admin' ) ) :
8
9 class ACF_Admin {
10
11 /**
12 * Constructor.
13 *
14 * @since 5.0.0
15 */
16 public function __construct() {
17 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
18 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
19 add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
20 add_action( 'current_screen', array( $this, 'current_screen' ) );
21 add_action( 'admin_notices', array( $this, 'maybe_show_escaped_html_notice' ) );
22 add_action( 'admin_init', array( $this, 'dismiss_escaped_html_notice' ) );
23 add_action( 'admin_init', array( $this, 'clear_escaped_html_log' ) );
24 add_filter( 'parent_file', array( $this, 'ensure_menu_selection' ) );
25 add_filter( 'submenu_file', array( $this, 'ensure_submenu_selection' ) );
26 }
27
28 /**
29 * Adds the ACF menu item.
30 *
31 * @date 28/09/13
32 * @since 5.0.0
33 */
34 public function admin_menu() {
35
36 // Bail early if ACF is hidden.
37 if ( ! acf_get_setting( 'show_admin' ) ) {
38 return;
39 }
40
41 // Vars.
42 $cap = acf_get_setting( 'capability' );
43 $parent_slug = 'edit.php?post_type=acf-field-group';
44
45 // Add menu items.
46 add_menu_page( __( 'ACF', 'acf' ), __( 'ACF', 'acf' ), $cap, $parent_slug, false, 'dashicons-welcome-widgets-menus', 80 );
47 }
48
49 /**
50 * Enqueues global admin styling.
51 *
52 * @since 5.0.0
53 */
54 public function admin_enqueue_scripts() {
55 wp_enqueue_style( 'acf-global' );
56 wp_enqueue_script( 'acf-escaped-html-notice' );
57
58 wp_localize_script(
59 'acf-escaped-html-notice',
60 'acf_escaped_html_notice',
61 array(
62 'show_details' => __( 'Show&nbsp;details', 'acf' ),
63 'hide_details' => __( 'Hide&nbsp;details', 'acf' ),
64 )
65 );
66 }
67
68 /**
69 * Appends custom admin body classes.
70 *
71 * @date 5/11/19
72 * @since 5.8.7
73 *
74 * @param string $classes Space-separated list of CSS classes.
75 * @return string
76 */
77 public function admin_body_class( $classes ) {
78 global $wp_version;
79
80 // Determine body class version.
81 $wp_minor_version = floatval( $wp_version );
82 if ( $wp_minor_version >= 5.3 ) {
83 $classes .= ' acf-admin-5-3';
84 } else {
85 $classes .= ' acf-admin-3-8';
86 }
87
88 // Add browser for specific CSS.
89 $classes .= ' acf-browser-' . esc_attr( acf_get_browser() );
90
91 // Return classes.
92 return $classes;
93 }
94
95 /**
96 * Adds custom functionality to "ACF" admin pages.
97 *
98 * @date 7/4/20
99 * @since 5.9.0
100 *
101 * @param void
102 * @return void
103 */
104 public function current_screen( $screen ) {
105 // Determine if the current page being viewed is "ACF" related.
106 if ( isset( $screen->post_type ) && in_array( $screen->post_type, acf_get_internal_post_types(), true ) ) {
107 add_action( 'in_admin_header', array( $this, 'in_admin_header' ) );
108 add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
109 add_filter( 'update_footer', array( $this, 'admin_footer_version_text' ) );
110 $this->setup_help_tab();
111 $this->maybe_show_import_from_cptui_notice();
112 }
113 }
114
115 /**
116 * Sets up the admin help tab.
117 *
118 * @date 20/4/20
119 * @since 5.9.0
120 *
121 * @param void
122 * @return void
123 */
124 public function setup_help_tab() {
125 $screen = get_current_screen();
126
127 // Overview tab.
128 $screen->add_help_tab(
129 array(
130 'id' => 'overview',
131 'title' => __( 'Overview', 'acf' ),
132 'content' =>
133 '<p><strong>' . __( 'Overview', 'acf' ) . '</strong></p>' .
134 '<p>' . __( 'The Advanced Custom Fields plugin provides a visual form builder to customize WordPress edit screens with extra fields, and an intuitive API to display custom field values in any theme template file.', 'acf' ) . '</p>' .
135 '<p>' . sprintf(
136 __( 'Before creating your first Field Group, we recommend first reading our <a href="%s" target="_blank">Getting started</a> guide to familiarize yourself with the plugin\'s philosophy and best practises.', 'acf' ),
137 acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/', 'docs', 'help-tab' )
138 ) . '</p>' .
139 '<p>' . __( 'Please use the Help & Support tab to get in touch should you find yourself requiring assistance.', 'acf' ) . '</p>' .
140 '',
141 )
142 );
143
144 // Help tab.
145 $screen->add_help_tab(
146 array(
147 'id' => 'help',
148 'title' => __( 'Help & Support', 'acf' ),
149 'content' =>
150 '<p><strong>' . __( 'Help & Support', 'acf' ) . '</strong></p>' .
151 '<p>' . __( 'We are fanatical about support, and want you to get the best out of your website with ACF. If you run into any difficulties, there are several places you can find help:', 'acf' ) . '</p>' .
152 '<ul>' .
153 '<li>' . sprintf(
154 __( '<a href="%s" target="_blank">Documentation</a>. Our extensive documentation contains references and guides for most situations you may encounter.', 'acf' ),
155 acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/', 'docs', 'help-tab' )
156 ) . '</li>' .
157 '<li>' . sprintf(
158 __( '<a href="%s" target="_blank">Discussions</a>. We have an active and friendly community on our Community Forums who may be able to help you figure out the \'how-tos\' of the ACF world.', 'acf' ),
159 acf_add_url_utm_tags( 'https://support.advancedcustomfields.com/', 'docs', 'help-tab' )
160 ) . '</li>' .
161 '<li>' . sprintf(
162 __( '<a href="%s" target="_blank">Help Desk</a>. The support professionals on our Help Desk will assist with your more in depth, technical challenges.', 'acf' ),
163 acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/support/', 'docs', 'help-tab' )
164 ) . '</li>' .
165 '</ul>',
166 )
167 );
168
169 // Sidebar.
170 $screen->set_help_sidebar(
171 '<p><strong>' . __( 'Information', 'acf' ) . '</strong></p>' .
172 '<p><span class="dashicons dashicons-admin-plugins"></span> ' . sprintf( __( 'Version %s', 'acf' ), ACF_VERSION ) . '</p>' .
173 '<p><span class="dashicons dashicons-wordpress"></span> <a href="https://wordpress.org/plugins/advanced-custom-fields/" target="_blank">' . __( 'View details', 'acf' ) . '</a></p>' .
174 '<p><span class="dashicons dashicons-admin-home"></span> <a href="' . acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/', 'docs', 'help-tab' ) . '" target="_blank" target="_blank">' . __( 'Visit website', 'acf' ) . '</a></p>' .
175 ''
176 );
177 }
178
179 /**
180 * Shows a notice to import post types and taxonomies from CPTUI if that plugin is active.
181 *
182 * @since 6.1
183 */
184 public function maybe_show_import_from_cptui_notice() {
185 global $plugin_page;
186
187 // Only show if CPTUI is active and post types are enabled.
188 if ( ! acf_get_setting( 'enable_post_types' ) || ! is_plugin_active( 'custom-post-type-ui/custom-post-type-ui.php' ) ) {
189 return;
190 }
191
192 // No need to show on the tools page.
193 if ( 'acf-tools' === $plugin_page ) {
194 return;
195 }
196
197 $text = sprintf(
198 /* translators: %s - URL to ACF tools page. */
199 __( 'Import Post Types and Taxonomies registered with Custom Post Type UI and manage them with ACF. <a href="%s">Get Started</a>.', 'acf' ),
200 acf_get_admin_tools_url()
201 );
202
203 acf_add_admin_notice( $text, 'success', true, true );
204 }
205
206 /**
207 * Notifies the user that fields rendered via shortcode or the_field() have
208 * had HTML removed/altered due to unsafe HTML being escaped.
209 *
210 * @since 6.2.5
211 */
212 public function maybe_show_escaped_html_notice() {
213 // Only show to editors and above.
214 if ( ! current_user_can( 'edit_others_posts' ) ) {
215 return;
216 }
217
218 // Allow opting-out of the notice.
219 if ( apply_filters( 'acf/admin/prevent_escaped_html_notice', true ) ) {
220 return;
221 }
222
223 if ( get_option( 'acf_escaped_html_notice_dismissed' ) ) {
224 return;
225 }
226
227 $escaped = _acf_get_escaped_html_log();
228
229 // Notice for when HTML has already been escaped.
230 if ( ! empty( $escaped ) ) {
231 acf_get_view( 'escaped-html-notice', array( 'acf_escaped' => $escaped ) );
232 }
233 }
234
235 /**
236 * Dismisses the escaped unsafe HTML notice.
237 *
238 * @since 6.2.5
239 */
240 public function dismiss_escaped_html_notice() {
241 if ( empty( $_GET['acf-dismiss-esc-html-notice'] ) ) {
242 return;
243 }
244
245 $nonce = sanitize_text_field( wp_unslash( $_GET['acf-dismiss-esc-html-notice'] ) );
246
247 if (
248 ! wp_verify_nonce( $nonce, 'acf/dismiss_escaped_html_notice' ) ||
249 ! current_user_can( acf_get_setting( 'capability' ) )
250 ) {
251 return;
252 }
253
254 update_option( 'acf_escaped_html_notice_dismissed', true );
255
256 _acf_delete_escaped_html_log();
257
258 wp_safe_redirect( remove_query_arg( 'acf-dismiss-esc-html-notice' ) );
259 exit;
260 }
261
262 /**
263 * Clear the escaped unsafe HTML log.
264 *
265 * @since 6.2.5
266 */
267 public function clear_escaped_html_log() {
268 if ( empty( $_GET['acf-clear-esc-html-log'] ) ) {
269 return;
270 }
271
272 $nonce = sanitize_text_field( wp_unslash( $_GET['acf-clear-esc-html-log'] ) );
273
274 if (
275 ! wp_verify_nonce( $nonce, 'acf/clear_escaped_html_log' ) ||
276 ! current_user_can( acf_get_setting( 'capability' ) )
277 ) {
278 return;
279 }
280
281 _acf_delete_escaped_html_log();
282
283 wp_safe_redirect( remove_query_arg( 'acf-clear-esc-html-log' ) );
284 exit;
285 }
286
287 /**
288 * Renders the admin navigation element.
289 *
290 * @date 27/3/20
291 * @since 5.9.0
292 *
293 * @param void
294 * @return void
295 */
296 function in_admin_header() {
297 acf_get_view( 'global/navigation' );
298
299 $screen = get_current_screen();
300
301 if ( isset( $screen->base ) && 'post' === $screen->base ) {
302 acf_get_view( 'global/form-top' );
303 }
304
305 do_action( 'acf/in_admin_header' );
306 }
307
308 /**
309 * Modifies the admin footer text.
310 *
311 * @date 7/4/20
312 * @since 5.9.0
313 *
314 * @param string $text The current admin footer text.
315 * @return string
316 */
317 public function admin_footer_text( $text ) {
318 $wp_engine_link = acf_add_url_utm_tags( 'https://wpengine.com/', 'bx_prod_referral', acf_is_pro() ? 'acf_pro_plugin_footer_text' : 'acf_free_plugin_footer_text', false, 'acf_plugin', 'referral' );
319 $acf_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/', 'footer', 'footer' );
320
321 if ( acf_is_pro() ) {
322 return sprintf(
323 /* translators: This text is prepended by a link to ACF's website, and appended by a link to WP Engine's website. */
324 '<a href="%1$s" target="_blank">ACF&#174;</a> and <a href="%1$s" target="_blank">ACF&#174; PRO</a> ' . __( 'are developed and maintained by', 'acf' ) . ' <a href="%2$s" target="_blank">WP Engine</a>.',
325 $acf_link,
326 $wp_engine_link
327 );
328 }
329
330 return sprintf(
331 /* translators: This text is prepended by a link to ACF's website, and appended by a link to WP Engine's website. */
332 '<a href="%1$s" target="_blank">ACF&#174;</a> ' . __( 'is developed and maintained by', 'acf' ) . ' <a href="%2$s" target="_blank">WP Engine</a>.',
333 $acf_link,
334 $wp_engine_link
335 );
336 }
337
338 /**
339 * Modifies the admin footer version text.
340 *
341 * @since 6.2
342 *
343 * @param string $text The current admin footer version text.
344 * @return string
345 */
346 public function admin_footer_version_text( $text ) {
347 $documentation_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/', 'footer', 'footer' );
348 $support_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/support/', 'footer', 'footer' );
349 $feedback_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/feedback/', 'footer', 'footer' );
350 $version_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/changelog/', 'footer', 'footer' );
351
352 return sprintf(
353 '<a href="%s" target="_blank">%s</a> &#8729; <a href="%s" target="_blank">%s</a> &#8729; <a href="%s" target="_blank">%s</a> &#8729; <a href="%s" target="_blank">%s %s</a>',
354 $documentation_link,
355 __( 'Documentation', 'acf' ),
356 $support_link,
357 __( 'Support', 'acf' ),
358 $feedback_link,
359 __( 'Feedback', 'acf' ),
360 $version_link,
361 acf_is_pro() ? __( 'ACF PRO', 'acf' ) : __( 'ACF', 'acf' ),
362 ACF_VERSION
363 );
364 }
365
366 /**
367 * Ensure the ACF parent menu is selected for add-new.php
368 *
369 * @since 6.1
370 * @param string $parent_file The parent file checked against menu activation.
371 * @return string The modified parent file
372 */
373 public function ensure_menu_selection( $parent_file ) {
374 if ( ! is_string( $parent_file ) ) {
375 return $parent_file;
376 }
377 if ( strpos( $parent_file, 'edit.php?post_type=acf-' ) === 0 ) {
378 return 'edit.php?post_type=acf-field-group';
379 }
380 return $parent_file;
381 }
382
383
384 /**
385 * Ensure the correct ACF submenu item is selected when in post-new versions of edit pages
386 *
387 * @since 6.1
388 * @param string $submenu_file The submenu filename.
389 * @return string The modified submenu filename
390 */
391 public function ensure_submenu_selection( $submenu_file ) {
392 if ( ! is_string( $submenu_file ) ) {
393 return $submenu_file;
394 }
395 if ( strpos( $submenu_file, 'post-new.php?post_type=acf-' ) === 0 ) {
396 return str_replace( 'post-new', 'edit', $submenu_file );
397 }
398 return $submenu_file;
399 }
400 }
401
402 // Instantiate.
403 acf_new_instance( 'ACF_Admin' );
404 endif; // class_exists check
405