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-post-types.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-post-types.php
354 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 if ( ! class_exists( 'ACF_Admin_Post_Types' ) ) :
8
9 /**
10 * The ACF Post Types admin controller class
11 */
12 #[AllowDynamicProperties]
13 class ACF_Admin_Post_Types 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-post-type';
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-post-types';
31
32 /**
33 * The name of the store used for the post type.
34 *
35 * @var string
36 */
37 public $store = 'post-types';
38
39 /**
40 * Constructor.
41 *
42 * @since ACF 6.2
43 */
44 public function __construct() {
45 add_action( 'admin_menu', array( $this, 'admin_menu' ), 8 );
46 parent::__construct();
47 }
48
49 /**
50 * Current screen actions for the post types 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( 'post-type-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( 'post-type-first-run', true );
77 }
78 }
79
80 /**
81 * Add any menu items required for post types.
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, __( 'Post Types', 'secure-custom-fields' ), __( 'Post Types', 'secure-custom-fields' ), $cap, 'edit.php?post_type=acf-post-type' );
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-taxonomies' => __( 'Taxonomies', 'secure-custom-fields' ),
114 'acf-field-groups' => __( 'Field Groups', 'secure-custom-fields' ),
115 'acf-count' => __( 'Posts', '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-taxonomies':
153 $this->render_admin_table_column_taxonomies( $post );
154 break;
155
156 case 'acf-field-groups':
157 $this->render_admin_table_column_field_groups( $post );
158 break;
159
160 case 'acf-count':
161 $this->render_admin_table_column_num_posts( $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 post type in the list table.
173 *
174 * @since ACF 6.1
175 *
176 * @param array $post_type The main post type array.
177 * @return void
178 */
179 public function render_admin_table_column_field_groups( $post_type ) {
180 $field_groups = acf_get_field_groups( array( 'post_type' => $post_type['post_type'] ) );
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 taxonomies attached to the post type in the list table.
203 *
204 * @since ACF 6.1
205 *
206 * @param array $post_type The main post type array.
207 * @return void
208 */
209 public function render_admin_table_column_taxonomies( $post_type ) {
210 $taxonomies = array();
211 $labels = array();
212
213 if ( is_array( $post_type['taxonomies'] ) ) {
214 $taxonomies = $post_type['taxonomies'];
215 }
216
217 $acf_taxonomies = acf_get_internal_post_type_posts( 'acf-taxonomy' );
218
219 foreach ( $acf_taxonomies as $acf_taxonomy ) {
220 if ( is_array( $acf_taxonomy['object_type'] ) && in_array( $post_type['post_type'], $acf_taxonomy['object_type'], true ) ) {
221 $taxonomies[] = $acf_taxonomy['taxonomy'];
222 }
223 }
224
225 $taxonomies = array_unique( $taxonomies );
226
227 foreach ( $taxonomies as $tax_slug ) {
228 $taxonomy = get_taxonomy( $tax_slug );
229
230 if ( ! is_object( $taxonomy ) || empty( $taxonomy->label ) ) {
231 continue;
232 }
233
234 $labels[] = $taxonomy->label;
235 }
236
237 if ( empty( $labels ) ) {
238 echo '<span class="acf-emdash" aria-hidden="true">—</span>';
239 echo '<span class="screen-reader-text">' . esc_html__( 'No taxonomies', 'secure-custom-fields' ) . '</span>';
240 return;
241 }
242
243 $limit = 3;
244 $shown_labels = array_slice( $labels, 0, $limit );
245 $hidden_labels = array_slice( $labels, $limit );
246 $text = implode( ', ', $shown_labels );
247
248 if ( ! empty( $hidden_labels ) ) {
249 $text .= ', <span class="acf-more-items acf-js-tooltip" title="' . implode( ', ', $hidden_labels ) . '">+' . count( $hidden_labels ) . '</span>';
250 }
251
252 echo acf_esc_html( $text );
253 }
254
255 /**
256 * Renders the number of posts created for the post type in the list table.
257 *
258 * @since ACF 6.1
259 *
260 * @param array $post_type The main post type array.
261 * @return void
262 */
263 public function render_admin_table_column_num_posts( $post_type ) {
264 $no_posts = '<span class="acf-emdash" aria-hidden="true">—</span>';
265 $no_posts .= '<span class="screen-reader-text">' . esc_html__( 'No posts', 'secure-custom-fields' ) . '</span>';
266
267 // WP doesn't count posts for post types that don't exist.
268 if ( empty( $post_type['active'] ) || 'trash' === get_post_status( $post_type['ID'] ) ) {
269 echo acf_esc_html( $no_posts );
270 return;
271 }
272
273 $num_posts = wp_count_posts( $post_type['post_type'] );
274 if ( is_object( $num_posts ) && property_exists( $num_posts, 'publish' ) ) {
275 $num_posts = $num_posts->publish;
276 }
277
278 if ( ! $num_posts || ! is_numeric( $num_posts ) ) {
279 echo acf_esc_html( $no_posts );
280 return;
281 }
282
283 printf(
284 '<a href="%s">%s</a>',
285 esc_url( admin_url( 'edit.php?post_type=' . $post_type['post_type'] ) ),
286 esc_html( number_format_i18n( $num_posts ) )
287 );
288 }
289
290 /**
291 * Gets the translated action notice text for list table actions (activate, deactivate, sync, etc.).
292 *
293 * @since ACF 6.1
294 *
295 * @param string $action The action being performed.
296 * @param integer $count The number of items the action was performed on.
297 * @return string
298 */
299 public function get_action_notice_text( $action, $count = 1 ) {
300 $text = '';
301 $count = (int) $count;
302
303 switch ( $action ) {
304 case 'acfactivatecomplete':
305 $text = sprintf(
306 /* translators: %s number of post types activated */
307 _n( '%s post type activated.', '%s post types activated.', $count, 'secure-custom-fields' ),
308 $count
309 );
310 break;
311 case 'acfdeactivatecomplete':
312 $text = sprintf(
313 /* translators: %s number of post types deactivated */
314 _n( '%s post type deactivated.', '%s post types deactivated.', $count, 'secure-custom-fields' ),
315 $count
316 );
317 break;
318 case 'acfduplicatecomplete':
319 $text = sprintf(
320 /* translators: %s number of post types duplicated */
321 _n( '%s post type duplicated.', '%s post types duplicated.', $count, 'secure-custom-fields' ),
322 $count
323 );
324 break;
325 case 'acfsynccomplete':
326 $text = sprintf(
327 /* translators: %s number of post types synchronized */
328 _n( '%s post type synchronized.', '%s post types synchronized.', $count, 'secure-custom-fields' ),
329 $count
330 );
331 break;
332 }
333
334 return $text;
335 }
336
337 /**
338 * Returns the registration error state.
339 *
340 * @since ACF 6.1
341 *
342 * @return string
343 */
344 public function get_registration_error_state() {
345 return '<span class="acf-js-tooltip dashicons dashicons-warning" title="' .
346 __( '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' ) .
347 '"></span> ' . _x( 'Registration Failed', 'post status', 'secure-custom-fields' );
348 }
349 }
350
351 // Instantiate.
352 acf_new_instance( 'ACF_Admin_Post_Types' );
353 endif; // Class exists check.
354