PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.8.1
Secure Custom Fields v6.8.1
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 / class-acf-admin-options-page.php
secure-custom-fields / includes / admin Last commit date
beta-features 7 months ago post-types 10 months ago tools 8 months ago views 8 months ago admin-commands.php 1 year ago admin-internal-post-type-list.php 10 months ago admin-internal-post-type.php 1 year ago admin-notices.php 1 year ago admin-tools.php 10 months ago admin-upgrade.php 1 year ago admin.php 10 months ago beta-features.php 8 months ago class-acf-admin-options-page.php 8 months ago index.php 1 year ago
class-acf-admin-options-page.php
318 lines
1 <?php
2 /**
3 * Admin Options Page Class
4 *
5 * Handles the admin interface for options pages.
6 *
7 * @package wordpress/secure-custom-fields
8 */
9
10 // phpcs:disable PEAR.NamingConventions.ValidClassName
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 if ( ! class_exists( 'acf_admin_options_page' ) ) :
16
17 /**
18 * Class for managing options pages in the WordPress admin.
19 */
20 class acf_admin_options_page {
21
22
23 /**
24 * Current options page data.
25 *
26 * @var array Contains the current options page
27 */
28 public $page;
29
30
31 /**
32 * Initialize filters, action, variables and includes
33 *
34 * @since ACF 5.0.0
35 */
36 public function __construct() {
37 // add menu items
38 add_action( 'admin_menu', array( $this, 'admin_menu' ), 99, 0 );
39 }
40
41
42 /**
43 * Adds menu items for registered options pages.
44 *
45 * @since ACF 5.0.0
46 */
47 public function admin_menu() {
48
49 // vars
50 $pages = acf_get_options_pages();
51
52 // bail early if no pages
53 if ( empty( $pages ) ) {
54 return;
55 }
56
57 // loop
58 foreach ( $pages as $page ) {
59
60 // vars
61 $slug = '';
62 // parent
63 if ( empty( $page['parent_slug'] ) ) {
64 $slug = add_menu_page( $page['page_title'], $page['menu_title'], $page['capability'], $page['menu_slug'], array( $this, 'html' ), $page['icon_url'], $page['position'] );
65 // child
66 } else {
67 $slug = add_submenu_page( $page['parent_slug'], $page['page_title'], $page['menu_title'], $page['capability'], $page['menu_slug'], array( $this, 'html' ), $page['position'] );
68 }
69
70 // actions
71 add_action( "load-{$slug}", array( $this, 'admin_load' ) );
72 }
73 }
74
75
76 /**
77 * Handles the load action for the options page.
78 *
79 * Enqueues scripts, validates saves, and sets up the options page.
80 *
81 * @since ACF 3.6.0
82 */
83 public function admin_load() {
84
85 // globals
86 global $plugin_page;
87
88 // vars
89 $this->page = acf_get_options_page( $plugin_page );
90
91 // get post_id (allow lang modification)
92 $this->page['post_id'] = acf_get_valid_post_id( $this->page['post_id'] );
93
94 // verify and remove nonce
95 if ( acf_verify_nonce( 'options' ) ) {
96
97 // save data
98 if ( acf_validate_save_post( true ) ) {
99
100 // set autoload
101 acf_update_setting( 'autoload', $this->page['autoload'] );
102
103 // save
104 acf_save_post( $this->page['post_id'] );
105
106 /**
107 * Fires after publishing a save on an options page.
108 *
109 * @since ACF 6.1.7
110 *
111 * @param string|int $post_id The current id.
112 * @param string $menu_slug The current options page menu slug.
113 */
114 do_action( 'acf/options_page/save', $this->page['post_id'], $this->page['menu_slug'] );
115
116 // redirect
117 wp_safe_redirect( add_query_arg( array( 'message' => '1' ) ) );
118 exit;
119 }
120 }
121
122 // load acf scripts
123 acf_enqueue_scripts();
124
125 // actions
126 add_action( 'acf/input/admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
127 add_action( 'acf/input/admin_head', array( $this, 'admin_head' ) );
128
129 // add columns support
130 add_screen_option(
131 'layout_columns',
132 array(
133 'max' => 2,
134 'default' => 2,
135 )
136 );
137 }
138
139
140 /**
141 * This function will enqueue the 'post.js' script which adds support for 'Screen Options' column toggle
142 *
143 * @since ACF 5.3.2
144 */
145 public function admin_enqueue_scripts() {
146
147 wp_enqueue_script( 'post' );
148 }
149
150
151 /**
152 * This action will find and add field groups to the current edit page
153 *
154 * @type action (admin_head)
155 * @since ACF 3.1.8
156 */
157 public function admin_head() {
158
159 // get field groups
160 $field_groups = acf_get_field_groups(
161 array(
162 'options_page' => $this->page['menu_slug'],
163 )
164 );
165
166 // notices
167 if ( ! empty( $_GET['message'] ) && '1' === $_GET['message'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Used to display a notice.
168 acf_add_admin_notice( $this->page['updated_message'], 'success' );
169 }
170
171 // add submit div
172 add_meta_box( 'submitdiv', __( 'Publish', 'secure-custom-fields' ), array( $this, 'postbox_submitdiv' ), 'acf_options_page', 'side', 'high' );
173
174 if ( empty( $field_groups ) ) {
175 /* translators: %s: URL to create a new field group */
176 acf_add_admin_notice( sprintf( __( 'No Custom Field Groups found for this options page. <a href="%s">Create a Custom Field Group</a>', 'secure-custom-fields' ), admin_url( 'post-new.php?post_type=acf-field-group' ) ), 'warning' );
177 } else {
178 foreach ( $field_groups as $i => $field_group ) {
179
180 // vars
181 $id = "acf-{$field_group['key']}";
182 $context = $field_group['position'];
183 $priority = 'high';
184 $args = array( 'field_group' => $field_group );
185
186 // tweaks to vars
187 if ( 'acf_after_title' === $context ) {
188 $context = 'normal';
189 } elseif ( 'side' === $context ) {
190 $priority = 'core';
191 }
192
193 // filter for 3rd party customization
194 $priority = apply_filters( 'acf/input/meta_box_priority', $priority, $field_group );
195
196 // add meta box
197 add_meta_box(
198 $id,
199 acf_esc_html( acf_get_field_group_title( $field_group ) ),
200 array( $this, 'postbox_acf' ),
201 'acf_options_page',
202 $context,
203 $priority,
204 $args
205 );
206 }
207 // foreach
208 }
209 // if
210 }
211
212
213 /**
214 * This function will render the submitdiv metabox
215 *
216 * @since ACF 5.3.2
217 */
218 public function postbox_submitdiv() {
219
220 /**
221 * Fires before the major-publishing-actions div.
222 *
223 * @date 24/9/18
224 * @since ACF 5.7.7
225 *
226 * @param array $page The current options page.
227 */
228 do_action( 'acf/options_page/submitbox_before_major_actions', $this->page );
229 ?>
230 <div id="major-publishing-actions">
231
232 <div id="publishing-action">
233 <span class="spinner"></span>
234 <input type="submit" accesskey="p" value="<?php echo esc_attr( $this->page['update_button'] ); ?>" class="button button-primary button-large" id="publish" name="publish">
235 </div>
236
237 <?php
238 /**
239 * Fires before the major-publishing-actions div.
240 *
241 * @date 24/9/18
242 * @since ACF 5.7.7
243 *
244 * @param array $page The current options page.
245 */
246 do_action( 'acf/options_page/submitbox_major_actions', $this->page );
247 ?>
248 <div class="clear"></div>
249
250 </div>
251 <?php
252 }
253
254
255 /**
256 * Renders a postbox on an ACF options page.
257 *
258 * @since ACF 5.0.0
259 *
260 * @param object $post The post object.
261 * @param array $args The metabox arguments.
262 */
263 public function postbox_acf( $post, $args ) {
264 $id = $args['id'];
265 $field_group = $args['args']['field_group'];
266
267 // vars
268 $o = array(
269 'id' => $id,
270 'key' => $field_group['key'],
271 'style' => $field_group['style'],
272 'label' => $field_group['label_placement'],
273 'editLink' => '',
274 'editTitle' => __( 'Edit field group', 'secure-custom-fields' ),
275 'visibility' => true,
276 );
277
278 // edit_url
279 if ( $field_group['ID'] && acf_current_user_can_admin() ) {
280 $o['editLink'] = admin_url( 'post.php?post=' . $field_group['ID'] . '&action=edit' );
281 }
282
283 // load fields
284 $fields = acf_get_fields( $field_group );
285
286 // render
287 acf_render_fields( $fields, $this->page['post_id'], 'div', $field_group['instruction_placement'] );
288
289 ?>
290 <script type="text/javascript">
291 if (typeof acf !== 'undefined') {
292
293 acf.newPostbox(<?php echo wp_json_encode( $o ); ?>);
294
295 }
296 </script>
297 <?php
298 }
299
300
301 /**
302 * Renders the options page HTML content.
303 *
304 * @since ACF 2.0.4
305 */
306 public function html() {
307
308 // load view
309 acf_get_view( __DIR__ . '/views/html-options-page.php', $this->page );
310 }
311 }
312
313
314 // initialize
315 new acf_admin_options_page();
316 endif;
317
318 ?>