PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / trunk
Secure Custom Fields vtrunk
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 / post-types / admin-post-type.php
secure-custom-fields / includes / admin / post-types Last commit date
admin-field-group.php 2 months ago admin-field-groups.php 10 months ago admin-post-type.php 1 year ago admin-post-types.php 10 months ago admin-taxonomies.php 10 months ago admin-taxonomy.php 1 year ago class-acf-admin-ui-options-page.php 1 year ago class-acf-admin-ui-options-pages.php 10 months ago index.php 1 year ago
admin-post-type.php
353 lines
1 <?php
2 /**
3 * ACF Admin Post Type Class
4 *
5 * @class ACF_Admin_Post_Type
6 *
7 * @package ACF
8 * @subpackage Admin
9 */
10
11 if ( ! class_exists( 'ACF_Admin_Post_Type' ) ) :
12
13 /**
14 * ACF Admin Post Type Class
15 *
16 * All the logic for editing a post type.
17 */
18 class ACF_Admin_Post_Type extends ACF_Admin_Internal_Post_Type {
19
20 /**
21 * The slug for the internal post type.
22 *
23 * @since ACF 6.1
24 * @var string
25 */
26 public $post_type = 'acf-post-type';
27
28 /**
29 * The admin body class used for the post type.
30 *
31 * @since ACF 6.1
32 * @var string
33 */
34 public $admin_body_class = 'acf-admin-single-post-type';
35
36 /**
37 * This function will customize the message shown when editing a post type.
38 *
39 * @since ACF 5.0.0
40 *
41 * @param array $messages Post type messages.
42 * @return array
43 */
44 public function post_updated_messages( $messages ) {
45 $messages['acf-post-type'] = array(
46 0 => '', // Unused. Messages start at index 1.
47 1 => $this->post_type_created_message(), // Updated.
48 2 => $this->post_type_created_message(),
49 3 => __( 'Post type deleted.', 'secure-custom-fields' ),
50 4 => __( 'Post type updated.', 'secure-custom-fields' ),
51 5 => false, // Post type does not support revisions.
52 6 => $this->post_type_created_message( true ), // Created.
53 7 => __( 'Post type saved.', 'secure-custom-fields' ),
54 8 => __( 'Post type submitted.', 'secure-custom-fields' ),
55 9 => __( 'Post type scheduled for.', 'secure-custom-fields' ),
56 10 => __( 'Post type draft updated.', 'secure-custom-fields' ),
57 );
58
59 return $messages;
60 }
61
62 /**
63 * Renders the post type created message.
64 *
65 * @since ACF 6.1
66 *
67 * @param boolean $created True if the post was just created.
68 * @return string
69 */
70 public function post_type_created_message( $created = false ) {
71 global $post_id;
72
73 $title = get_the_title( $post_id );
74
75 /* translators: %s post type name */
76 $item_saved_text = sprintf( __( '%s post type updated', 'secure-custom-fields' ), $title );
77
78 if ( $created ) {
79 /* translators: %s post type name */
80 $item_saved_text = sprintf( __( '%s post type created', 'secure-custom-fields' ), $title );
81 }
82
83 $add_fields_link = wp_nonce_url(
84 admin_url( 'post-new.php?post_type=acf-field-group&use_post_type=' . $post_id ),
85 'add-fields-' . $post_id
86 );
87
88 $create_post_type_link = admin_url( 'post-new.php?post_type=acf-post-type' );
89 $duplicate_post_type_link = wp_nonce_url(
90 admin_url( 'post-new.php?post_type=acf-post-type&use_post_type=' . $post_id ),
91 'acfduplicate-' . $post_id
92 );
93
94 $create_taxonomy_link = wp_nonce_url(
95 admin_url( 'post-new.php?post_type=acf-taxonomy&use_post_type=' . $post_id ),
96 'create-taxonomy-' . $post_id
97 );
98
99 ob_start(); ?>
100 <p class="acf-item-saved-text"><?php echo esc_html( $item_saved_text ); ?></p>
101 <div class="acf-item-saved-links">
102 <a href="<?php echo esc_url( $add_fields_link ); ?>"><?php esc_html_e( 'Add fields', 'secure-custom-fields' ); ?></a>
103 <a class="acf-link-field-groups" href="#"><?php esc_html_e( 'Link field groups', 'secure-custom-fields' ); ?></a>
104 <a href="<?php echo esc_url( $create_post_type_link ); ?>"><?php esc_html_e( 'Create post type', 'secure-custom-fields' ); ?></a>
105 <a href="<?php echo esc_url( $duplicate_post_type_link ); ?>"><?php esc_html_e( 'Duplicate post type', 'secure-custom-fields' ); ?></a>
106 <a href="<?php echo esc_url( $create_taxonomy_link ); ?>"><?php esc_html_e( 'Create taxonomy', 'secure-custom-fields' ); ?></a>
107 </div>
108 <?php
109 return ob_get_clean();
110 }
111
112 /**
113 * Enqueues any scripts necessary for internal post type.
114 *
115 * @since ACF 5.0.0
116 */
117 public function admin_enqueue_scripts() {
118
119 wp_enqueue_style( 'acf-field-group' );
120
121 acf_localize_text(
122 array(
123 'Post' => __( 'Post', 'secure-custom-fields' ),
124 'Posts' => __( 'Posts', 'secure-custom-fields' ),
125 'Page' => __( 'Page', 'secure-custom-fields' ),
126 'Pages' => __( 'Pages', 'secure-custom-fields' ),
127 'Default' => __( 'Default', 'secure-custom-fields' ),
128 )
129 );
130
131 parent::admin_enqueue_scripts();
132
133 do_action( 'acf/post_type/admin_enqueue_scripts' );
134 }
135
136 /**
137 * Sets up all functionality for the post type edit page to work.
138 *
139 * @since ACF 3.1.8
140 */
141 public function admin_head() {
142
143 // global.
144 global $post, $acf_post_type;
145
146 // set global var.
147 $acf_post_type = acf_get_internal_post_type( $post->ID, $this->post_type );
148
149 if ( ! empty( $acf_post_type['not_registered'] ) ) {
150 acf_add_admin_notice(
151 __( 'This post type could not be registered because its key is in use by another post type registered by another plugin or theme.', 'secure-custom-fields' ),
152 'error'
153 );
154 }
155
156 // metaboxes.
157 add_meta_box( 'acf-basic-settings', __( 'Basic Settings', 'secure-custom-fields' ), array( $this, 'mb_basic_settings' ), 'acf-post-type', 'normal', 'high' );
158 add_meta_box( 'acf-advanced-settings', __( 'Advanced Settings', 'secure-custom-fields' ), array( $this, 'mb_advanced_settings' ), 'acf-post-type', 'normal', 'high' );
159
160 // actions.
161 add_action( 'post_submitbox_misc_actions', array( $this, 'post_submitbox_misc_actions' ), 10, 0 );
162 add_action( 'edit_form_after_title', array( $this, 'edit_form_after_title' ), 10, 0 );
163
164 // filters.
165 add_filter( 'screen_settings', array( $this, 'screen_settings' ), 10, 1 );
166 add_filter( 'get_user_option_screen_layout_acf-post-type', array( $this, 'screen_layout' ), 10, 1 );
167 add_filter( 'get_user_option_metaboxhidden_acf-post-type', array( $this, 'force_basic_settings' ), 10, 1 );
168 add_filter( 'get_user_option_closedpostboxes_acf-post-type', array( $this, 'force_basic_settings' ), 10, 1 );
169 add_filter( 'get_user_option_closedpostboxes_acf-post-type', array( $this, 'force_advanced_settings' ), 10, 1 );
170
171 // 3rd party hook.
172 do_action( 'acf/post_type/admin_head' );
173 }
174
175 /**
176 * This action will allow ACF to render metaboxes after the title.
177 */
178 public function edit_form_after_title() {
179
180 // globals.
181 global $post;
182
183 // render post data.
184 acf_form_data(
185 array(
186 'screen' => 'post_type',
187 'post_id' => $post->ID,
188 'delete_fields' => 0,
189 'validation' => 1,
190 )
191 );
192 }
193
194 /**
195 * This function will add extra HTML to the acf form data element
196 *
197 * @since ACF 5.3.8
198 *
199 * @param array $args Arguments array to pass through to action.
200 * @return void
201 */
202 public function form_data( $args ) {
203 do_action( 'acf/post_type/form_data', $args );
204 }
205
206 /**
207 * This function will append extra l10n strings to the acf JS object
208 *
209 * @since ACF 5.3.8
210 *
211 * @param array $l10n The array of translated strings.
212 * @return array $l10n
213 */
214 public function admin_l10n( $l10n ) {
215 return apply_filters( 'acf/post_type/admin_l10n', $l10n );
216 }
217
218 /**
219 * Admin footer third party hook support
220 *
221 * @since ACF 5.3.2
222 */
223 public function admin_footer() {
224 do_action( 'acf/post_type/admin_footer' );
225 }
226
227 /**
228 * Screen settings html output
229 *
230 * @since ACF 3.6.0
231 *
232 * @param string $html Current screen settings HTML.
233 * @return string $html
234 */
235 public function screen_settings( $html ) {
236 return $html;
237 }
238
239 /**
240 * Sets the "Edit Post Type" screen to use a one-column layout.
241 *
242 * @param integer $columns Number of columns for layout.
243 * @return integer
244 */
245 public function screen_layout( $columns = 0 ) {
246 return 1;
247 }
248
249 /**
250 * Force basic settings to always be visible
251 *
252 * @param array $hidden_metaboxes The metaboxes hidden on this page.
253 * @return array
254 */
255 public function force_basic_settings( $hidden_metaboxes ) {
256 if ( ! is_array( $hidden_metaboxes ) ) {
257 return $hidden_metaboxes;
258 }
259 return array_diff( $hidden_metaboxes, array( 'acf-basic-settings' ) );
260 }
261
262 /**
263 * Force advanced settings to be visible
264 *
265 * @param array $hidden_metaboxes The metaboxes hidden on this page.
266 * @return array
267 */
268 public function force_advanced_settings( $hidden_metaboxes ) {
269 if ( ! is_array( $hidden_metaboxes ) ) {
270 return $hidden_metaboxes;
271 }
272 return array_diff( $hidden_metaboxes, array( 'acf-advanced-settings' ) );
273 }
274
275 /**
276 * This function will customize the publish metabox
277 *
278 * @since ACF 5.2.9
279 */
280 public function post_submitbox_misc_actions() {
281 global $acf_post_type;
282 $status_label = $acf_post_type['active'] ? _x( 'Active', 'post status', 'secure-custom-fields' ) : _x( 'Inactive', 'post status', 'secure-custom-fields' );
283
284 ?>
285 <script type="text/javascript">
286 (function($) {
287 $('#post-status-display').html( '<?php echo esc_html( $status_label ); ?>' );
288 })(jQuery);
289 </script>
290 <?php
291 }
292
293 /**
294 * Saves post type data.
295 *
296 * @since ACF 1.0.0
297 *
298 * @param integer $post_id The post ID.
299 * @param WP_Post $post The post object.
300 * @return integer $post_id
301 */
302 public function save_post( $post_id, $post ) {
303 if ( ! $this->verify_save_post( $post_id, $post ) ) {
304 return $post_id;
305 }
306
307 // Disable filters to ensure ACF loads raw data from DB.
308 acf_disable_filters();
309
310 // phpcs:disable WordPress.Security.NonceVerification.Missing -- Validated in $this->verify_save_post() above.
311 // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized when saved.
312 $_POST['acf_post_type']['ID'] = $post_id;
313 $_POST['acf_post_type']['title'] = isset( $_POST['acf_post_type']['labels']['name'] ) ? $_POST['acf_post_type']['labels']['name'] : '';
314
315 // Save the post type.
316 acf_update_internal_post_type( $_POST['acf_post_type'], $this->post_type ); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Validated in verify_save_post
317 // phpcs:enable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
318 // phpcs:enable WordPress.Security.NonceVerification.Missing
319
320 return $post_id;
321 }
322
323 /**
324 * Renders HTML for the basic settings metabox.
325 *
326 * @since ACF 5.0.0
327 */
328 public function mb_basic_settings() {
329 global $acf_post_type;
330
331 if ( ! acf_is_internal_post_type_key( $acf_post_type['key'], 'acf-post-type' ) ) {
332 $acf_post_type['key'] = uniqid( 'post_type_' );
333 }
334
335 acf_get_view( $this->post_type . '/basic-settings' );
336 }
337
338
339 /**
340 * Renders the HTML for the advanced settings metabox.
341 *
342 * @since ACF 5.0.0
343 */
344 public function mb_advanced_settings() {
345 acf_get_view( $this->post_type . '/advanced-settings' );
346 }
347 }
348
349 new ACF_Admin_Post_Type();
350 endif; // Class exists check.
351
352 ?>
353