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