PluginProbe
Advanced Custom Fields (ACF®) / 6.2.8
Advanced Custom Fields (ACF®) v6.2.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.php
admin.php
355 lines 11.7 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( 'wp_ajax_acf/dismiss_escaped_html_notice', array( $this, 'dismiss_escaped_html_notice' ) );
23 add_filter( 'parent_file', array( $this, 'ensure_menu_selection' ) );
24 add_filter( 'submenu_file', array( $this, 'ensure_submenu_selection' ) );
25 }
26
27 /**
28 * Adds the ACF menu item.
29 *
30 * @date 28/09/13
31 * @since 5.0.0
32 */
33 public function admin_menu() {
34
35 // Bail early if ACF is hidden.
36 if ( ! acf_get_setting( 'show_admin' ) ) {
37 return;
38 }
39
40 // Vars.
41 $cap = acf_get_setting( 'capability' );
42 $parent_slug = 'edit.php?post_type=acf-field-group';
43
44 // Add menu items.
45 add_menu_page( __( 'ACF', 'acf' ), __( 'ACF', 'acf' ), $cap, $parent_slug, false, 'dashicons-welcome-widgets-menus', 80 );
46 }
47
48 /**
49 * Enqueues global admin styling.
50 *
51 * @since 5.0.0
52 */
53 public function admin_enqueue_scripts() {
54 wp_enqueue_style( 'acf-global' );
55 wp_enqueue_script( 'acf-escaped-html-notice' );
56
57 wp_localize_script(
58 'acf-escaped-html-notice',
59 'acf_escaped_html_notice',
60 array(
61 'nonce' => wp_create_nonce( 'acf/dismiss_escaped_html_notice' ),
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', false ) ) {
220 return;
221 }
222
223 $escaped = _acf_get_escaped_html_log();
224
225 // Notice for when HTML has already been escaped.
226 if ( ! empty( $escaped ) ) {
227 acf_get_view( 'escaped-html-notice', array( 'acf_escaped' => $escaped ) );
228 }
229 }
230
231 /**
232 * Dismisses the escaped unsafe HTML notice by clearing the stored log.
233 *
234 * @since 6.2.5
235 */
236 public function dismiss_escaped_html_notice() {
237 if (
238 ! check_admin_referer( 'acf/dismiss_escaped_html_notice', 'nonce' ) ||
239 ! current_user_can( acf_get_setting( 'capability' ) ) ) {
240 return;
241 }
242
243 _acf_delete_escaped_html_log();
244 }
245
246 /**
247 * Renders the admin navigation element.
248 *
249 * @date 27/3/20
250 * @since 5.9.0
251 *
252 * @param void
253 * @return void
254 */
255 function in_admin_header() {
256 acf_get_view( 'global/navigation' );
257
258 $screen = get_current_screen();
259
260 if ( isset( $screen->base ) && 'post' === $screen->base ) {
261 acf_get_view( 'global/form-top' );
262 }
263
264 do_action( 'acf/in_admin_header' );
265 }
266
267 /**
268 * Modifies the admin footer text.
269 *
270 * @date 7/4/20
271 * @since 5.9.0
272 *
273 * @param string $text The current admin footer text.
274 * @return string
275 */
276 public function admin_footer_text( $text ) {
277 $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' );
278 $acf_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/', 'footer', 'footer' );
279
280 return sprintf(
281 /* translators: This text is prepended by a link to ACF's website, and appended by a link to WP Engine's website. */
282 '<a href="%1$s" target="_blank">' . ( acf_is_pro() ? 'ACF PRO' : 'ACF' ) . '</a> ' . __( 'is developed and maintained by', 'acf' ) . ' <a href="%2$s" target="_blank">WP Engine</a>.',
283 $acf_link,
284 $wp_engine_link
285 );
286 }
287
288 /**
289 * Modifies the admin footer version text.
290 *
291 * @since 6.2
292 *
293 * @param string $text The current admin footer version text.
294 * @return string
295 */
296 public function admin_footer_version_text( $text ) {
297 $documentation_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/resources/', 'footer', 'footer' );
298 $support_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/support/', 'footer', 'footer' );
299 $feedback_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/feedback/', 'footer', 'footer' );
300 $version_link = acf_add_url_utm_tags( 'https://www.advancedcustomfields.com/changelog/', 'footer', 'footer' );
301
302 return sprintf(
303 '<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>',
304 $documentation_link,
305 __( 'Documentation', 'acf' ),
306 $support_link,
307 __( 'Support', 'acf' ),
308 $feedback_link,
309 __( 'Feedback', 'acf' ),
310 $version_link,
311 acf_is_pro() ? __( 'ACF PRO', 'acf' ) : __( 'ACF', 'acf' ),
312 ACF_VERSION
313 );
314 }
315
316 /**
317 * Ensure the ACF parent menu is selected for add-new.php
318 *
319 * @since 6.1
320 * @param string $parent_file The parent file checked against menu activation.
321 * @return string The modified parent file
322 */
323 public function ensure_menu_selection( $parent_file ) {
324 if ( ! is_string( $parent_file ) ) {
325 return $parent_file;
326 }
327 if ( strpos( $parent_file, 'edit.php?post_type=acf-' ) === 0 ) {
328 return 'edit.php?post_type=acf-field-group';
329 }
330 return $parent_file;
331 }
332
333
334 /**
335 * Ensure the correct ACF submenu item is selected when in post-new versions of edit pages
336 *
337 * @since 6.1
338 * @param string $submenu_file The submenu filename.
339 * @return string The modified submenu filename
340 */
341 public function ensure_submenu_selection( $submenu_file ) {
342 if ( ! is_string( $submenu_file ) ) {
343 return $submenu_file;
344 }
345 if ( strpos( $submenu_file, 'post-new.php?post_type=acf-' ) === 0 ) {
346 return str_replace( 'post-new', 'edit', $submenu_file );
347 }
348 return $submenu_file;
349 }
350 }
351
352 // Instantiate.
353 acf_new_instance( 'ACF_Admin' );
354 endif; // class_exists check
355