PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.4.0-beta1
Secure Custom Fields v6.4.0-beta1
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 / pro / admin / post-types / admin-ui-options-pages.php
secure-custom-fields / pro / admin / post-types Last commit date
admin-ui-options-page.php 1 year ago admin-ui-options-pages.php 1 year ago index.php 1 year ago
admin-ui-options-pages.php
213 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 if ( ! class_exists( 'ACF_Admin_UI_Options_Pages' ) ) :
8
9 /**
10 * The ACF Post Types admin controller class
11 */
12 #[AllowDynamicProperties]
13 class ACF_Admin_UI_Options_Pages extends ACF_Admin_Internal_Post_Type_List {
14
15 /**
16 * The slug for the internal post type.
17 *
18 * @since 6.1
19 * @var string
20 */
21 public $post_type = 'acf-ui-options-page';
22
23 /**
24 * The admin body class used for the post type.
25 *
26 * @since 6.1
27 * @var string
28 */
29 public $admin_body_class = 'acf-admin-options-pages';
30
31 /**
32 * The name of the store used for the post type.
33 *
34 * @var string
35 */
36 public $store = 'options-pages';
37
38 /**
39 * If this is a pro feature or not.
40 *
41 * @var boolean
42 */
43 public $is_pro_feature = true;
44
45 /**
46 * Constructor.
47 *
48 * @since 6.2
49 */
50 public function __construct() {
51 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
52 parent::__construct();
53 }
54
55 /**
56 * Current screen actions for the post types list admin page.
57 *
58 * @since 6.1
59 */
60 public function current_screen() {
61 // Bail early if not post types admin page.
62 if ( ! acf_is_screen( "edit-{$this->post_type}" ) ) {
63 return;
64 }
65
66 parent::current_screen();
67
68 // Run a first-run routine to set some defaults which are stored in user preferences.
69 if ( ! acf_get_user_setting( 'options-pages-first-run', false ) ) {
70 $option_key = 'manageedit-' . $this->post_type . 'columnshidden';
71 $hidden_items = get_user_option( $option_key );
72
73 if ( ! is_array( $hidden_items ) ) {
74 $hidden_items = array();
75 }
76
77 if ( ! in_array( 'acf-key', $hidden_items ) ) {
78 $hidden_items[] = 'acf-key';
79 }
80 update_user_option( get_current_user_id(), $option_key, $hidden_items, true );
81
82 acf_update_user_setting( 'options-pages-first-run', true );
83 }
84 }
85
86 /**
87 * Add any menu items required for post types.
88 *
89 * @since 6.1
90 */
91 public function admin_menu() {
92 $parent_slug = 'edit.php?post_type=acf-field-group';
93 $cap = acf_get_setting( 'capability' );
94 add_submenu_page( $parent_slug, __( 'Options Pages', 'acf' ), __( 'Options Pages', 'acf' ), $cap, 'edit.php?post_type=acf-ui-options-page' );
95 }
96
97 /**
98 * Customizes the admin table columns.
99 *
100 * @date 1/4/20
101 * @since 5.9.0
102 *
103 * @param array $_columns The columns array.
104 * @return array
105 */
106 public function admin_table_columns( $_columns ) {
107 // Set the "no found" label to be our custom HTML for no results.
108 if ( empty( acf_request_arg( 's' ) ) ) {
109 global $wp_post_types;
110 $this->not_found_label = $wp_post_types[ $this->post_type ]->labels->not_found;
111 $wp_post_types[ $this->post_type ]->labels->not_found = $this->get_not_found_html();
112 }
113
114 $columns = array(
115 'cb' => $_columns['cb'],
116 'title' => $_columns['title'],
117 'acf-description' => __( 'Description', 'acf' ),
118 'acf-key' => __( 'Key', 'acf' ),
119 );
120
121 if ( acf_get_local_json_files( $this->post_type ) ) {
122 $columns['acf-json'] = __( 'Local JSON', 'acf' );
123 }
124
125 return $columns;
126 }
127
128 /**
129 * Renders a specific admin table column.
130 *
131 * @date 17/4/20
132 * @since 5.9.0
133 *
134 * @param string $column_name The name of the column to display.
135 * @param array $post The main ACF post array.
136 * @return void
137 */
138 public function render_admin_table_column( $column_name, $post ) {
139 switch ( $column_name ) {
140 case 'acf-key':
141 echo '<i class="acf-icon acf-icon-key-solid"></i>';
142 echo esc_html( $post['key'] );
143 break;
144
145 // Description.
146 case 'acf-description':
147 if ( ! empty( $post['description'] ) && ( is_string( $post['description'] ) || is_numeric( $post['description'] ) ) ) {
148 echo '<span class="acf-description">' . acf_esc_html( $post['description'] ) . '</span>';
149 } else {
150 echo '<span class="acf-emdash" aria-hidden="true">—</span>';
151 echo '<span class="screen-reader-text">' . esc_html__( 'No description', 'acf' ) . '</span>';
152 }
153 break;
154
155 // Local JSON.
156 case 'acf-json':
157 $this->render_admin_table_column_local_status( $post );
158 break;
159 }
160 }
161
162 /**
163 * Gets the translated action notice text for list table actions (activate, deactivate, sync, etc.).
164 *
165 * @since 6.1
166 *
167 * @param string $action The action being performed.
168 * @param integer $count The number of items the action was performed on.
169 * @return string
170 */
171 public function get_action_notice_text( $action, $count = 1 ) {
172 $text = '';
173 $count = (int) $count;
174
175 switch ( $action ) {
176 case 'acfactivatecomplete':
177 $text = sprintf(
178 /* translators: %s number of post types activated */
179 _n( 'Options page activated.', '%s options pages activated.', $count, 'acf' ),
180 $count
181 );
182 break;
183 case 'acfdeactivatecomplete':
184 $text = sprintf(
185 /* translators: %s number of post types deactivated */
186 _n( 'Options page deactivated.', '%s options pages deactivated.', $count, 'acf' ),
187 $count
188 );
189 break;
190 case 'acfduplicatecomplete':
191 $text = sprintf(
192 /* translators: %s number of post types duplicated */
193 _n( 'Options page duplicated.', '%s options pages duplicated.', $count, 'acf' ),
194 $count
195 );
196 break;
197 case 'acfsynccomplete':
198 $text = sprintf(
199 /* translators: %s number of post types synchronized */
200 _n( 'Options page synchronized.', '%s options pages synchronized.', $count, 'acf' ),
201 $count
202 );
203 break;
204 }
205
206 return $text;
207 }
208 }
209
210 // Instantiate.
211 acf_new_instance( 'ACF_Admin_UI_Options_Pages' );
212 endif; // Class exists check.
213