PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.1-beta6
Secure Custom Fields v6.4.1-beta6
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 / class-acf-admin-options-page.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 class-acf-admin-options-page.php 1 year ago index.php 1 year ago
class-acf-admin-options-page.php
311 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 $title = $field_group['title'];
183 $context = $field_group['position'];
184 $priority = 'high';
185 $args = array( 'field_group' => $field_group );
186
187 // tweaks to vars
188 if ( 'acf_after_title' === $context ) {
189 $context = 'normal';
190 } elseif ( 'side' === $context ) {
191 $priority = 'core';
192 }
193
194 // filter for 3rd party customization
195 $priority = apply_filters( 'acf/input/meta_box_priority', $priority, $field_group );
196
197 // add meta box
198 add_meta_box( $id, acf_esc_html( $title ), array( $this, 'postbox_acf' ), 'acf_options_page', $context, $priority, $args );
199 }
200 // foreach
201 }
202 // if
203 }
204
205
206 /**
207 * This function will render the submitdiv metabox
208 *
209 * @since ACF 5.3.2
210 */
211 public function postbox_submitdiv() {
212
213 /**
214 * Fires before the major-publishing-actions div.
215 *
216 * @date 24/9/18
217 * @since ACF 5.7.7
218 *
219 * @param array $page The current options page.
220 */
221 do_action( 'acf/options_page/submitbox_before_major_actions', $this->page );
222 ?>
223 <div id="major-publishing-actions">
224
225 <div id="publishing-action">
226 <span class="spinner"></span>
227 <input type="submit" accesskey="p" value="<?php echo esc_attr( $this->page['update_button'] ); ?>" class="button button-primary button-large" id="publish" name="publish">
228 </div>
229
230 <?php
231 /**
232 * Fires before the major-publishing-actions div.
233 *
234 * @date 24/9/18
235 * @since ACF 5.7.7
236 *
237 * @param array $page The current options page.
238 */
239 do_action( 'acf/options_page/submitbox_major_actions', $this->page );
240 ?>
241 <div class="clear"></div>
242
243 </div>
244 <?php
245 }
246
247
248 /**
249 * Renders a postbox on an ACF options page.
250 *
251 * @since ACF 5.0.0
252 *
253 * @param object $post The post object.
254 * @param array $args The metabox arguments.
255 */
256 public function postbox_acf( $post, $args ) {
257 $id = $args['id'];
258 $field_group = $args['args']['field_group'];
259
260 // vars
261 $o = array(
262 'id' => $id,
263 'key' => $field_group['key'],
264 'style' => $field_group['style'],
265 'label' => $field_group['label_placement'],
266 'editLink' => '',
267 'editTitle' => __( 'Edit field group', 'secure-custom-fields' ),
268 'visibility' => true,
269 );
270
271 // edit_url
272 if ( $field_group['ID'] && acf_current_user_can_admin() ) {
273 $o['editLink'] = admin_url( 'post.php?post=' . $field_group['ID'] . '&action=edit' );
274 }
275
276 // load fields
277 $fields = acf_get_fields( $field_group );
278
279 // render
280 acf_render_fields( $fields, $this->page['post_id'], 'div', $field_group['instruction_placement'] );
281
282 ?>
283 <script type="text/javascript">
284 if (typeof acf !== 'undefined') {
285
286 acf.newPostbox(<?php echo wp_json_encode( $o ); ?>);
287
288 }
289 </script>
290 <?php
291 }
292
293
294 /**
295 * Renders the options page HTML content.
296 *
297 * @since ACF 2.0.4
298 */
299 public function html() {
300
301 // load view
302 acf_get_view( __DIR__ . '/views/html-options-page.php', $this->page );
303 }
304 }
305
306
307 // initialize
308 new acf_admin_options_page();
309 endif;
310
311 ?>