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.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.php
307 lines
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 SCF 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( __( 'SCF', 'acf' ), __( 'SCF', '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->maybe_show_import_from_cptui_notice();
111 }
112 }
113
114 /**
115 * Shows a notice to import post types and taxonomies from CPTUI if that plugin is active.
116 *
117 * @since 6.1
118 */
119 public function maybe_show_import_from_cptui_notice() {
120 global $plugin_page;
121
122 // Only show if CPTUI is active and post types are enabled.
123 if ( ! acf_get_setting( 'enable_post_types' ) || ! is_plugin_active( 'custom-post-type-ui/custom-post-type-ui.php' ) ) {
124 return;
125 }
126
127 // No need to show on the tools page.
128 if ( 'acf-tools' === $plugin_page ) {
129 return;
130 }
131
132 $text = sprintf(
133 /* translators: %s - URL to ACF tools page. */
134 __( 'Import Post Types and Taxonomies registered with Custom Post Type UI and manage them with ACF. <a href="%s">Get Started</a>.', 'acf' ),
135 acf_get_admin_tools_url()
136 );
137
138 acf_add_admin_notice( $text, 'success', true, true );
139 }
140
141 /**
142 * Notifies the user that fields rendered via shortcode or the_field() have
143 * had HTML removed/altered due to unsafe HTML being escaped.
144 *
145 * @since 6.2.5
146 */
147 public function maybe_show_escaped_html_notice() {
148 // Only show to editors and above.
149 if ( ! current_user_can( 'edit_others_posts' ) ) {
150 return;
151 }
152
153 // Allow opting-out of the notice.
154 if ( apply_filters( 'acf/admin/prevent_escaped_html_notice', false ) ) {
155 return;
156 }
157
158 if ( get_option( 'acf_escaped_html_notice_dismissed' ) ) {
159 return;
160 }
161
162 $escaped = _acf_get_escaped_html_log();
163
164 // Notice for when HTML has already been escaped.
165 if ( ! empty( $escaped ) ) {
166 acf_get_view( 'escaped-html-notice', array( 'acf_escaped' => $escaped ) );
167 }
168 }
169
170 /**
171 * Dismisses the escaped unsafe HTML notice.
172 *
173 * @since 6.2.5
174 */
175 public function dismiss_escaped_html_notice() {
176 if ( empty( $_GET['acf-dismiss-esc-html-notice'] ) ) {
177 return;
178 }
179
180 $nonce = sanitize_text_field( wp_unslash( $_GET['acf-dismiss-esc-html-notice'] ) );
181
182 if (
183 ! wp_verify_nonce( $nonce, 'acf/dismiss_escaped_html_notice' ) ||
184 ! current_user_can( acf_get_setting( 'capability' ) )
185 ) {
186 return;
187 }
188
189 update_option( 'acf_escaped_html_notice_dismissed', true );
190
191 _acf_delete_escaped_html_log();
192
193 wp_safe_redirect( remove_query_arg( 'acf-dismiss-esc-html-notice' ) );
194 exit;
195 }
196
197 /**
198 * Clear the escaped unsafe HTML log.
199 *
200 * @since 6.2.5
201 */
202 public function clear_escaped_html_log() {
203 if ( empty( $_GET['acf-clear-esc-html-log'] ) ) {
204 return;
205 }
206
207 $nonce = sanitize_text_field( wp_unslash( $_GET['acf-clear-esc-html-log'] ) );
208
209 if (
210 ! wp_verify_nonce( $nonce, 'acf/clear_escaped_html_log' ) ||
211 ! current_user_can( acf_get_setting( 'capability' ) )
212 ) {
213 return;
214 }
215
216 _acf_delete_escaped_html_log();
217
218 wp_safe_redirect( remove_query_arg( 'acf-clear-esc-html-log' ) );
219 exit;
220 }
221
222 /**
223 * Renders the admin navigation element.
224 *
225 * @date 27/3/20
226 * @since 5.9.0
227 *
228 * @param void
229 * @return void
230 */
231 function in_admin_header() {
232 acf_get_view( 'global/navigation' );
233
234 $screen = get_current_screen();
235
236 if ( isset( $screen->base ) && 'post' === $screen->base ) {
237 acf_get_view( 'global/form-top' );
238 }
239
240 do_action( 'acf/in_admin_header' );
241 }
242
243 /**
244 * Modifies the admin footer text.
245 *
246 * @date 7/4/20
247 * @since 5.9.0
248 *
249 * @param string $text The current admin footer text.
250 * @return string
251 */
252 public function admin_footer_text( $text ) {
253 return '';
254 }
255
256 /**
257 * Modifies the admin footer version text.
258 *
259 * @since 6.2
260 *
261 * @param string $text The current admin footer version text.
262 * @return string
263 */
264 public function admin_footer_version_text( $text ) {
265 return '';
266 }
267
268 /**
269 * Ensure the ACF parent menu is selected for add-new.php
270 *
271 * @since 6.1
272 * @param string $parent_file The parent file checked against menu activation.
273 * @return string The modified parent file
274 */
275 public function ensure_menu_selection( $parent_file ) {
276 if ( ! is_string( $parent_file ) ) {
277 return $parent_file;
278 }
279 if ( strpos( $parent_file, 'edit.php?post_type=acf-' ) === 0 ) {
280 return 'edit.php?post_type=acf-field-group';
281 }
282 return $parent_file;
283 }
284
285
286 /**
287 * Ensure the correct ACF submenu item is selected when in post-new versions of edit pages
288 *
289 * @since 6.1
290 * @param string $submenu_file The submenu filename.
291 * @return string The modified submenu filename
292 */
293 public function ensure_submenu_selection( $submenu_file ) {
294 if ( ! is_string( $submenu_file ) ) {
295 return $submenu_file;
296 }
297 if ( strpos( $submenu_file, 'post-new.php?post_type=acf-' ) === 0 ) {
298 return str_replace( 'post-new', 'edit', $submenu_file );
299 }
300 return $submenu_file;
301 }
302 }
303
304 // Instantiate.
305 acf_new_instance( 'ACF_Admin' );
306 endif; // class_exists check
307