PluginProbe
Advanced Custom Fields (ACF®) / 6.1.0
Advanced Custom Fields (ACF®) v6.1.0
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
← All changes | includes/admin/admin.php +261 -191 5.9.46.1.0 View file →
@@ -1,207 +1,277 @@
1 -<?php
1 +<?php
2 2
3 -if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit; // Exit if accessed directly
5 +}
4 6
5 -if( ! class_exists('ACF_Admin') ) :
7 +if ( ! class_exists( 'ACF_Admin' ) ) :
6 8
7 -class ACF_Admin {
8 -
9 - /**
10 - * Constructor.
11 - *
12 - * @date 23/06/12
13 - * @since 5.0.0
14 - *
15 - * @param void
16 - * @return void
17 - */
18 - function __construct() {
9 + class ACF_Admin {
19 10
20 - // Add actions.
21 - add_action( 'admin_menu', array( $this, 'admin_menu' ) );
22 - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
23 - add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
24 - add_action( 'current_screen', array( $this, 'current_screen' ) );
25 - }
26 -
27 - /**
28 - * Adds the ACF menu item.
29 - *
30 - * @date 28/09/13
31 - * @since 5.0.0
32 - *
33 - * @param void
34 - * @return void
35 - */
36 - function admin_menu() {
37 -
38 - // Bail early if ACF is hidden.
39 - if( !acf_get_setting('show_admin') ) {
40 - return;
11 + /**
12 + * Constructor.
13 + *
14 + * @date 23/06/12
15 + * @since 5.0.0
16 + *
17 + * @param void
18 + * @return void
19 + */
20 + function __construct() {
21 + // Add actions.
22 + add_action( 'admin_menu', array( $this, 'admin_menu' ) );
23 + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
24 + add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
25 + add_action( 'current_screen', array( $this, 'current_screen' ) );
26 + add_filter( 'parent_file', array( $this, 'ensure_menu_selection' ) );
27 + add_filter( 'submenu_file', array( $this, 'ensure_submenu_selection' ) );
41 28 }
42 -
43 - // Vars.
44 - $slug = 'edit.php?post_type=acf-field-group';
45 - $cap = acf_get_setting('capability');
46 -
47 - // Add menu items.
48 - add_menu_page( __("Custom Fields",'acf'), __("Custom Fields",'acf'), $cap, $slug, false, 'dashicons-welcome-widgets-menus', '80.025' );
49 - add_submenu_page( $slug, __('Field Groups','acf'), __('Field Groups','acf'), $cap, $slug );
50 - add_submenu_page( $slug, __('Add New','acf'), __('Add New','acf'), $cap, 'post-new.php?post_type=acf-field-group' );
51 - }
52 -
53 - /**
54 - * Enqueues global admin styling.
55 - *
56 - * @date 28/09/13
57 - * @since 5.0.0
58 - *
59 - * @param void
60 - * @return void
61 - */
62 - function admin_enqueue_scripts() {
63 - wp_enqueue_style( 'acf-global' );
64 - }
65 -
66 - /**
67 - * Appends custom admin body classes.
68 - *
69 - * @date 5/11/19
70 - * @since 5.8.7
71 - *
72 - * @param string $classes Space-separated list of CSS classes.
73 - * @return string
74 - */
75 - function admin_body_class( $classes ) {
76 - global $wp_version;
77 -
78 - // Determine body class version.
79 - $wp_minor_version = floatval( $wp_version );
80 - if( $wp_minor_version >= 5.3 ) {
81 - $classes .= ' acf-admin-5-3';
82 - } else {
83 - $classes .= ' acf-admin-3-8';
29 +
30 + /**
31 + * Adds the ACF menu item.
32 + *
33 + * @date 28/09/13
34 + * @since 5.0.0
35 + */
36 + public function admin_menu() {
37 +
38 + // Bail early if ACF is hidden.
39 + if ( ! acf_get_setting( 'show_admin' ) ) {
40 + return;
41 + }
42 +
43 + // Vars.
44 + $cap = acf_get_setting( 'capability' );
45 + $parent_slug = 'edit.php?post_type=acf-field-group';
46 +
47 + // Add menu items.
48 + add_menu_page( __( 'ACF', 'acf' ), __( 'ACF', 'acf' ), $cap, $parent_slug, false, 'dashicons-welcome-widgets-menus', 80 );
84 49 }
85 -
86 - // Add browser for specific CSS.
87 - $classes .= ' acf-browser-' . acf_get_browser();
88 50
89 - // Return classes.
90 - return $classes;
91 - }
92 -
93 - /**
94 - * Adds custom functionality to "ACF" admin pages.
95 - *
96 - * @date 7/4/20
97 - * @since 5.9.0
98 - *
99 - * @param void
100 - * @return void
101 - */
102 - function current_screen( $screen ) {
103 -
104 - // Determine if the current page being viewed is "ACF" related.
105 - if( isset( $screen->post_type ) && $screen->post_type === 'acf-field-group' ) {
106 - add_action( 'in_admin_header', array( $this, 'in_admin_header' ) );
107 - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
108 - $this->setup_help_tab();
51 + /**
52 + * Enqueues global admin styling.
53 + *
54 + * @date 28/09/13
55 + * @since 5.0.0
56 + *
57 + * @param void
58 + * @return void
59 + */
60 + function admin_enqueue_scripts() {
61 + wp_enqueue_style( 'acf-global' );
109 62 }
110 - }
111 63
112 - /**
113 - * Sets up the admin help tab.
114 - *
115 - * @date 20/4/20
116 - * @since 5.9.0
117 - *
118 - * @param void
119 - * @return void
120 - */
121 - public function setup_help_tab() {
122 - $screen = get_current_screen();
64 + /**
65 + * Appends custom admin body classes.
66 + *
67 + * @date 5/11/19
68 + * @since 5.8.7
69 + *
70 + * @param string $classes Space-separated list of CSS classes.
71 + * @return string
72 + */
73 + function admin_body_class( $classes ) {
74 + global $wp_version;
123 75
124 - // Overview tab.
125 - $screen->add_help_tab(
126 - array(
127 - 'id' => 'overview',
128 - 'title' => __( 'Overview', 'acf' ),
129 - 'content' =>
130 - '<p><strong>' . __( 'Overview', 'acf' ) . '</strong></p>' .
131 - '<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>' .
132 - '<p>' . sprintf(
133 - __( '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' ),
134 - 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/'
135 - ) . '</p>' .
136 - '<p>' . __( 'Please use the Help & Support tab to get in touch should you find yourself requiring assistance.', 'acf' ) . '</p>' .
137 - ''
138 - )
139 - );
76 + // Determine body class version.
77 + $wp_minor_version = floatval( $wp_version );
78 + if ( $wp_minor_version >= 5.3 ) {
79 + $classes .= ' acf-admin-5-3';
80 + } else {
81 + $classes .= ' acf-admin-3-8';
82 + }
140 83
141 - // Help tab.
142 - $screen->add_help_tab(
143 - array(
144 - 'id' => 'help',
145 - 'title' => __( 'Help & Support', 'acf' ),
146 - 'content' =>
147 - '<p><strong>' . __( 'Help & Support', 'acf' ) . '</strong></p>' .
148 - '<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>' .
149 - '<ul>' .
150 - '<li>' . sprintf(
151 - __( '<a href="%s" target="_blank">Documentation</a>. Our extensive documentation contains references and guides for most situations you may encounter.', 'acf' ),
152 - 'https://www.advancedcustomfields.com/resources/'
153 - ) . '</li>' .
154 - '<li>' . sprintf(
155 - __( '<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' ),
156 - 'https://support.advancedcustomfields.com/'
157 - ) . '</li>' .
158 - '<li>' . sprintf(
159 - __( '<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' ),
160 - 'https://www.advancedcustomfields.com/support/'
161 - ) . '</li>' .
162 - '</ul>'
163 - )
164 - );
84 + // Add browser for specific CSS.
85 + $classes .= ' acf-browser-' . acf_get_browser();
165 86
166 - // Sidebar.
167 - $screen->set_help_sidebar(
168 - '<p><strong>' . __( 'Information', 'acf' ) . '</strong></p>' .
169 - '<p><span class="dashicons dashicons-admin-plugins"></span> ' . sprintf( __( 'Version %s', 'acf' ), ACF_VERSION ) . '</p>' .
170 - '<p><span class="dashicons dashicons-wordpress"></span> <a href="https://wordpress.org/plugins/advanced-custom-fields/" target="_blank">' . __( 'View details', 'acf' ) . '</a></p>' .
171 - '<p><span class="dashicons dashicons-admin-home"></span> <a href="https://www.advancedcustomfields.com/" target="_blank" target="_blank">' . __( 'Visit website', 'acf' ) . '</a></p>' .
172 - ''
173 - );
87 + // Return classes.
88 + return $classes;
89 + }
90 +
91 + /**
92 + * Adds custom functionality to "ACF" admin pages.
93 + *
94 + * @date 7/4/20
95 + * @since 5.9.0
96 + *
97 + * @param void
98 + * @return void
99 + */
100 + public function current_screen( $screen ) {
101 + // Determine if the current page being viewed is "ACF" related.
102 + if ( isset( $screen->post_type ) && in_array( $screen->post_type, acf_get_internal_post_types(), true ) ) {
103 + add_action( 'in_admin_header', array( $this, 'in_admin_header' ) );
104 + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
105 + $this->setup_help_tab();
106 + $this->maybe_show_import_from_cptui_notice();
107 + }
108 + }
109 +
110 + /**
111 + * Sets up the admin help tab.
112 + *
113 + * @date 20/4/20
114 + * @since 5.9.0
115 + *
116 + * @param void
117 + * @return void
118 + */
119 + public function setup_help_tab() {
120 + $screen = get_current_screen();
121 +
122 + // Overview tab.
123 + $screen->add_help_tab(
124 + array(
125 + 'id' => 'overview',
126 + 'title' => __( 'Overview', 'acf' ),
127 + 'content' =>
128 + '<p><strong>' . __( 'Overview', 'acf' ) . '</strong></p>' .
129 + '<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>' .
130 + '<p>' . sprintf(
131 + __( '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' ),
132 + acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/getting-started-with-acf/', 'docs', 'help-tab' )
133 + ) . '</p>' .
134 + '<p>' . __( 'Please use the Help & Support tab to get in touch should you find yourself requiring assistance.', 'acf' ) . '</p>' .
135 + '',
136 + )
137 + );
138 +
139 + // Help tab.
140 + $screen->add_help_tab(
141 + array(
142 + 'id' => 'help',
143 + 'title' => __( 'Help & Support', 'acf' ),
144 + 'content' =>
145 + '<p><strong>' . __( 'Help & Support', 'acf' ) . '</strong></p>' .
146 + '<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>' .
147 + '<ul>' .
148 + '<li>' . sprintf(
149 + __( '<a href="%s" target="_blank">Documentation</a>. Our extensive documentation contains references and guides for most situations you may encounter.', 'acf' ),
150 + acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/', 'docs', 'help-tab' )
151 + ) . '</li>' .
152 + '<li>' . sprintf(
153 + __( '<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' ),
154 + acf_add_url_utm_tags( 'https://support.advancedcustomfields.com/', 'docs', 'help-tab' )
155 + ) . '</li>' .
156 + '<li>' . sprintf(
157 + __( '<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' ),
158 + acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/support/', 'docs', 'help-tab' )
159 + ) . '</li>' .
160 + '</ul>',
161 + )
162 + );
163 +
164 + // Sidebar.
165 + $screen->set_help_sidebar(
166 + '<p><strong>' . __( 'Information', 'acf' ) . '</strong></p>' .
167 + '<p><span class="dashicons dashicons-admin-plugins"></span> ' . sprintf( __( 'Version %s', 'acf' ), ACF_VERSION ) . '</p>' .
168 + '<p><span class="dashicons dashicons-wordpress"></span> <a href="https://wordpress.org/plugins/advanced-custom-fields/" target="_blank">' . __( 'View details', 'acf' ) . '</a></p>' .
169 + '<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>' .
170 + ''
171 + );
172 + }
173 +
174 + /**
175 + * Shows a notice to import post types and taxonomies from CPTUI if that plugin is active.
176 + *
177 + * @since 6.1
178 + */
179 + public function maybe_show_import_from_cptui_notice() {
180 + global $plugin_page;
181 +
182 + // Only show if CPTUI is active and post types are enabled.
183 + if ( ! acf_get_setting( 'enable_post_types' ) || ! is_plugin_active( 'custom-post-type-ui/custom-post-type-ui.php' ) ) {
184 + return;
185 + }
186 +
187 + // No need to show on the tools page.
188 + if ( 'acf-tools' === $plugin_page ) {
189 + return;
190 + }
191 +
192 + $text = sprintf(
193 + /* translators: %s - URL to ACF tools page. */
194 + __( 'Import Post Types and Taxonomies registered with Custom Post Type UI and manage them with ACF. <a href="%s">Get Started</a>.', 'acf' ),
195 + acf_get_admin_tools_url()
196 + );
197 +
198 + acf_add_admin_notice( $text, 'success', true, true );
199 + }
200 +
201 + /**
202 + * Renders the admin navigation element.
203 + *
204 + * @date 27/3/20
205 + * @since 5.9.0
206 + *
207 + * @param void
208 + * @return void
209 + */
210 + function in_admin_header() {
211 + acf_get_view( 'global/navigation' );
212 +
213 + $screen = get_current_screen();
214 +
215 + if ( isset( $screen->base ) && 'post' === $screen->base ) {
216 + acf_get_view( 'global/form-top' );
217 + }
218 + }
219 +
220 + /**
221 + * Modifies the admin footer text.
222 + *
223 + * @date 7/4/20
224 + * @since 5.9.0
225 + *
226 + * @param string $text The admin footer text.
227 + * @return string
228 + */
229 + function admin_footer_text( $text ) {
230 + if ( null === $text ) {
231 + $text = '';
232 + }
233 + // Use RegExp to append "ACF" after the <a> element allowing translations to read correctly.
234 + return preg_replace( '/(<a[\S\s]+?\/a>)/', '$1 ' . __( 'and', 'acf' ) . ' <a href="' . acf_add_url_utm_tags( 'https://www.advancedcustomfields.com', 'footer', 'footer' ) . '" target="_blank">ACF</a>', $text, 1 );
235 + }
236 +
237 + /**
238 + * Ensure the ACF parent menu is selected for add-new.php
239 + *
240 + * @since 6.1
241 + * @param string $parent_file The parent file checked against menu activation.
242 + * @return string The modified parent file
243 + */
244 + public function ensure_menu_selection( $parent_file ) {
245 + if ( ! is_string( $parent_file ) ) {
246 + return $parent_file;
247 + }
248 + if ( strpos( $parent_file, 'edit.php?post_type=acf-' ) === 0 ) {
249 + return 'edit.php?post_type=acf-field-group';
250 + }
251 + return $parent_file;
252 + }
253 +
254 +
255 + /**
256 + * Ensure the correct ACF submenu item is selected when in post-new versions of edit pages
257 + *
258 + * @since 6.1
259 + * @param string $submenu_file The submenu filename.
260 + * @return string The modified submenu filename
261 + */
262 + public function ensure_submenu_selection( $submenu_file ) {
263 + if ( ! is_string( $submenu_file ) ) {
264 + return $submenu_file;
265 + }
266 + if ( strpos( $submenu_file, 'post-new.php?post_type=acf-' ) === 0 ) {
267 + return str_replace( 'post-new', 'edit', $submenu_file );
268 + }
269 + return $submenu_file;
270 + }
271 +
174 272 }
175 -
176 - /**
177 - * Renders the admin navigation element.
178 - *
179 - * @date 27/3/20
180 - * @since 5.9.0
181 - *
182 - * @param void
183 - * @return void
184 - */
185 - function in_admin_header() {
186 - acf_get_view( 'html-admin-navigation' );
187 - }
188 -
189 - /**
190 - * Modifies the admin footer text.
191 - *
192 - * @date 7/4/20
193 - * @since 5.9.0
194 - *
195 - * @param string $text The admin footer text.
196 - * @return string
197 - */
198 - function admin_footer_text( $text ) {
199 - // Use RegExp to append "ACF" after the <a> element allowing translations to read correctly.
200 - return preg_replace( '/(<a[\S\s]+?\/a>)/', '$1 ' . __('and', 'acf') . ' <a href="https://www.advancedcustomfields.com" target="_blank">ACF</a>', $text, 1 );
201 - }
202 -}
203 273
204 -// Instantiate.
205 -acf_new_instance('ACF_Admin');
274 + // Instantiate.
275 + acf_new_instance( 'ACF_Admin' );
206 276
207 277 endif; // class_exists check