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