PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.2
Secure Custom Fields v6.4.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 / post-types / admin-taxonomies.php
secure-custom-fields / includes / admin / post-types Last commit date
admin-field-group.php 1 year ago admin-field-groups.php 1 year ago admin-post-type.php 1 year ago admin-post-types.php 1 year ago admin-taxonomies.php 1 year ago admin-taxonomy.php 1 year ago class-acf-admin-ui-options-page.php 1 year ago class-acf-admin-ui-options-pages.php 1 year ago index.php 1 year ago
admin-taxonomies.php
361 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 if ( ! class_exists( 'ACF_Admin_Taxonomies' ) ) :
8
9 /**
10 * The ACF Post Types admin controller class
11 */
12 #[AllowDynamicProperties]
13 class ACF_Admin_Taxonomies extends ACF_Admin_Internal_Post_Type_List {
14
15
16 /**
17 * The slug for the internal post type.
18 *
19 * @since ACF 6.1
20 * @var string
21 */
22 public $post_type = 'acf-taxonomy';
23
24 /**
25 * The admin body class used for the post type.
26 *
27 * @since ACF 6.1
28 * @var string
29 */
30 public $admin_body_class = 'acf-admin-taxonomies';
31
32 /**
33 * The name of the store used for the post type.
34 *
35 * @var string
36 */
37 public $store = 'taxonomies';
38
39 /**
40 * Constructor.
41 *
42 * @since ACF 6.2
43 */
44 public function __construct() {
45 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
46 parent::__construct();
47 }
48
49 /**
50 * Current screen actions for the taxonomies list admin page.
51 *
52 * @since ACF 6.1
53 */
54 public function current_screen() {
55 // Bail early if not post types admin page.
56 if ( ! acf_is_screen( "edit-{$this->post_type}" ) ) {
57 return;
58 }
59
60 parent::current_screen();
61
62 // Run a first-run routine to set some defaults which are stored in user preferences.
63 if ( ! acf_get_user_setting( 'taxonomies-first-run', false ) ) {
64 $option_key = 'manageedit-' . $this->post_type . 'columnshidden';
65 $hidden_items = get_user_option( $option_key );
66
67 if ( ! is_array( $hidden_items ) ) {
68 $hidden_items = array();
69 }
70
71 if ( ! in_array( 'acf-key', $hidden_items ) ) {
72 $hidden_items[] = 'acf-key';
73 }
74 update_user_option( get_current_user_id(), $option_key, $hidden_items, true );
75
76 acf_update_user_setting( 'taxonomies-first-run', true );
77 }
78 }
79
80 /**
81 * Add any menu items required for taxonomies.
82 *
83 * @since ACF 6.1
84 */
85 public function admin_menu() {
86 $parent_slug = 'edit.php?post_type=acf-field-group';
87 $cap = acf_get_setting( 'capability' );
88 add_submenu_page( $parent_slug, __( 'Taxonomies', 'secure-custom-fields' ), __( 'Taxonomies', 'secure-custom-fields' ), $cap, 'edit.php?post_type=acf-taxonomy' );
89 }
90
91 /**
92 * Customizes the admin table columns.
93 *
94 * @date 1/4/20
95 * @since ACF 5.9.0
96 *
97 * @param array $_columns The columns array.
98 * @return array
99 */
100 public function admin_table_columns( $_columns ) {
101 // Set the "no found" label to be our custom HTML for no results.
102 if ( empty( acf_request_arg( 's' ) ) ) {
103 global $wp_post_types;
104 $this->not_found_label = $wp_post_types[ $this->post_type ]->labels->not_found;
105 $wp_post_types[ $this->post_type ]->labels->not_found = $this->get_not_found_html();
106 }
107
108 $columns = array(
109 'cb' => $_columns['cb'],
110 'title' => $_columns['title'],
111 'acf-description' => __( 'Description', 'secure-custom-fields' ),
112 'acf-key' => __( 'Key', 'secure-custom-fields' ),
113 'acf-post-types' => __( 'Post Types', 'secure-custom-fields' ),
114 'acf-field-groups' => __( 'Field Groups', 'secure-custom-fields' ),
115 'acf-count' => __( 'Terms', 'secure-custom-fields' ),
116 );
117
118 if ( acf_get_local_json_files( $this->post_type ) ) {
119 $columns['acf-json'] = __( 'Local JSON', 'secure-custom-fields' );
120 }
121
122 return $columns;
123 }
124
125 /**
126 * Renders a specific admin table column.
127 *
128 * @date 17/4/20
129 * @since ACF 5.9.0
130 *
131 * @param string $column_name The name of the column to display.
132 * @param array $post The main ACF post array.
133 * @return void
134 */
135 public function render_admin_table_column( $column_name, $post ) {
136 switch ( $column_name ) {
137 case 'acf-key':
138 echo '<i class="acf-icon acf-icon-key-solid"></i>';
139 echo esc_html( $post['key'] );
140 break;
141
142 // Description.
143 case 'acf-description':
144 if ( ( is_string( $post['description'] ) || is_numeric( $post['description'] ) ) && ! empty( $post['description'] ) ) {
145 echo '<span class="acf-description">' . acf_esc_html( $post['description'] ) . '</span>';
146 } else {
147 echo '<span class="acf-emdash" aria-hidden="true">—</span>';
148 echo '<span class="screen-reader-text">' . esc_html__( 'No description', 'secure-custom-fields' ) . '</span>';
149 }
150 break;
151
152 case 'acf-field-groups':
153 $this->render_admin_table_column_field_groups( $post );
154 break;
155
156 case 'acf-post-types':
157 $this->render_admin_table_column_post_types( $post );
158 break;
159
160 case 'acf-count':
161 $this->render_admin_table_column_num_terms( $post );
162 break;
163
164 // Local JSON.
165 case 'acf-json':
166 $this->render_admin_table_column_local_status( $post );
167 break;
168 }
169 }
170
171 /**
172 * Renders the field groups attached to the taxonomy in the list table.
173 *
174 * @since ACF 6.1
175 *
176 * @param array $taxonomy The main taxonomy array.
177 * @return void
178 */
179 public function render_admin_table_column_field_groups( $taxonomy ) {
180 $field_groups = acf_get_field_groups( array( 'taxonomy' => $taxonomy['taxonomy'] ) );
181
182 if ( empty( $field_groups ) ) {
183 echo '<span class="acf-emdash" aria-hidden="true">—</span>';
184 echo '<span class="screen-reader-text">' . esc_html__( 'No field groups', 'secure-custom-fields' ) . '</span>';
185 return;
186 }
187
188 $labels = wp_list_pluck( $field_groups, 'title' );
189 $limit = 3;
190 $shown_labels = array_slice( $labels, 0, $limit );
191 $hidden_labels = array_slice( $labels, $limit );
192 $text = implode( ', ', $shown_labels );
193
194 if ( ! empty( $hidden_labels ) ) {
195 $text .= ', <span class="acf-more-items acf-js-tooltip" title="' . implode( ', ', $hidden_labels ) . '">+' . count( $hidden_labels ) . '</span>';
196 }
197
198 echo acf_esc_html( $text );
199 }
200
201 /**
202 * Renders the post types attached to the taxonomy in the list table.
203 *
204 * @since ACF 6.1
205 *
206 * @param array $taxonomy The main taxonomy array.
207 * @return void
208 */
209 public function render_admin_table_column_post_types( $taxonomy ) {
210 $post_types = get_post_types( array(), 'objects' );
211 $labels = array();
212 $object_types = array();
213
214 if ( ! empty( $taxonomy['object_type'] ) ) {
215 $object_types = (array) $taxonomy['object_type'];
216 }
217
218 foreach ( $object_types as $post_type_slug ) {
219 if ( ! isset( $post_types[ $post_type_slug ] ) ) {
220 continue;
221 }
222
223 $post_type = $post_types[ $post_type_slug ];
224
225 if ( empty( $post_type->label ) ) {
226 continue;
227 }
228
229 $labels[] = $post_type->label;
230 }
231
232 $acf_post_types = acf_get_internal_post_type_posts( 'acf-post-type' );
233
234 foreach ( $acf_post_types as $acf_post_type ) {
235 if ( is_array( $acf_post_type['taxonomies'] ) && in_array( $taxonomy['taxonomy'], $acf_post_type['taxonomies'], true ) ) {
236 $labels[] = $acf_post_type['title'];
237 }
238 }
239
240 if ( empty( $labels ) ) {
241 echo '<span class="acf-emdash" aria-hidden="true">—</span>';
242 echo '<span class="screen-reader-text">' . esc_html__( 'No post types', 'secure-custom-fields' ) . '</span>';
243 return;
244 }
245
246 $labels = array_unique( $labels );
247 $limit = 3;
248 $shown_labels = array_slice( $labels, 0, $limit );
249 $hidden_labels = array_slice( $labels, $limit );
250 $text = implode( ', ', $shown_labels );
251
252 if ( ! empty( $hidden_labels ) ) {
253 $text .= ', <span class="acf-more-items acf-js-tooltip" title="' . implode( ', ', $hidden_labels ) . '">+' . count( $hidden_labels ) . '</span>';
254 }
255
256 echo acf_esc_html( $text );
257 }
258
259 /**
260 * Renders the number of terms created for the taxonomy in the list table.
261 *
262 * @since ACF 6.1
263 *
264 * @param array $taxonomy The main taxonomy array.
265 * @return void
266 */
267 public function render_admin_table_column_num_terms( $taxonomy ) {
268 $no_terms = '<span class="acf-emdash" aria-hidden="true">—</span>';
269 $no_terms .= '<span class="screen-reader-text">' . esc_html__( 'No terms', 'secure-custom-fields' ) . '</span>';
270
271 // WP doesn't count terms for taxonomies that don't exist and instead returns WP_Error.
272 if ( empty( $taxonomy['active'] ) || 'trash' === get_post_status( $taxonomy['ID'] ) ) {
273 echo acf_esc_html( $no_terms );
274 return;
275 }
276
277 $num_terms = wp_count_terms(
278 array(
279 'taxonomy' => $taxonomy['taxonomy'],
280 'hide_empty' => false,
281 'parent' => 0,
282 )
283 );
284
285 if ( ! $num_terms || ! is_numeric( $num_terms ) ) {
286 echo acf_esc_html( $no_terms );
287 return;
288 }
289
290 printf(
291 '<a href="%s">%s</a>',
292 esc_url( admin_url( 'edit-tags.php?taxonomy=' . $taxonomy['taxonomy'] ) ),
293 esc_html( number_format_i18n( $num_terms ) )
294 );
295 }
296
297 /**
298 * Gets the translated action notice text for list table actions (activate, deactivate, sync, etc.).
299 *
300 * @since ACF 6.1
301 *
302 * @param string $action The action being performed.
303 * @param integer $count The number of items the action was performed on.
304 * @return string
305 */
306 public function get_action_notice_text( $action, $count = 1 ) {
307 $text = '';
308 $count = (int) $count;
309
310 switch ( $action ) {
311 case 'acfactivatecomplete':
312 $text = sprintf(
313 /* translators: %s number of taxonomies activated */
314 _n( '%s taxonomy activated.', '%s taxonomies activated.', $count, 'secure-custom-fields' ),
315 $count
316 );
317 break;
318 case 'acfdeactivatecomplete':
319 $text = sprintf(
320 /* translators: %s number of taxonomies deactivated */
321 _n( '%s taxonomy deactivated.', '%s taxonomies deactivated.', $count, 'secure-custom-fields' ),
322 $count
323 );
324 break;
325 case 'acfduplicatecomplete':
326 $text = sprintf(
327 /* translators: %s number of taxonomies duplicated */
328 _n( '%s taxonomy duplicated.', '%s taxonomies duplicated.', $count, 'secure-custom-fields' ),
329 $count
330 );
331 break;
332 case 'acfsynccomplete':
333 $text = sprintf(
334 /* translators: %s number of taxonomies synchronized */
335 _n( '%s taxonomy synchronized.', '%s taxonomies synchronized.', $count, 'secure-custom-fields' ),
336 $count
337 );
338 break;
339 }
340
341 return $text;
342 }
343
344 /**
345 * Returns the registration error state.
346 *
347 * @since ACF 6.1
348 *
349 * @return string
350 */
351 public function get_registration_error_state() {
352 return '<span class="acf-js-tooltip dashicons dashicons-warning" title="' .
353 __( 'This taxonomy could not be registered because its key is in use by another taxonomy registered by another plugin or theme.', 'secure-custom-fields' ) .
354 '"></span> ' . _x( 'Registration Failed', 'post status', 'secure-custom-fields' );
355 }
356 }
357
358 // Instantiate.
359 acf_new_instance( 'ACF_Admin_Taxonomies' );
360 endif; // Class exists check.
361