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