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
advanced-custom-fields / includes / admin / admin.php

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

278 lines 8.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 * @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' ) );
28 }
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 );
49 }
50
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' );
62 }
63
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;
75
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 }
83
84 // Add browser for specific CSS.
85 $classes .= ' acf-browser-' . acf_get_browser();
86
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
272 }
273
274 // Instantiate.
275 acf_new_instance( 'ACF_Admin' );
276
277 endif; // class_exists check
278