← All changes
|
php/Admin/Menus/Manage/Manage_Menu_Screen_Options.php
+46
-4
3.10.0-beta.2
→
trunk
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Code_Snippets\Admin\Menus\Manage; |
| 4 | 4 | |
| 5 | +use WP_Screen; | |
| 5 | 6 | use function Code_Snippets\code_snippets; |
| 6 | 7 | |
| 7 | 8 | /** |
| 8 | 9 | * Provides Screen Options for the manage snippets table. |
| @@ -12,9 +13,9 @@ | ||
| 12 | 13 | /** |
| 13 | 14 | * Register hooks this class. |
| 14 | 15 | */ |
| 15 | 16 | public function __construct() { |
| 16 | - add_action( 'admin_init', [ $this, 'save_truncation_preference' ] ); | |
| 17 | + add_action( 'wp_loaded', [ $this, 'save_truncation_preference' ] ); | |
| 17 | 18 | add_filter( 'set-screen-option', [ $this, 'save_per_page_option' ], 10, 3 ); |
| 18 | 19 | } |
| 19 | 20 | |
| 20 | 21 | /** |
| @@ -33,8 +34,9 @@ | ||
| 33 | 34 | } |
| 34 | 35 | |
| 35 | 36 | if ( $screen && ! $this->is_cloud_community_view() ) { |
| 36 | 37 | add_filter( "manage_{$screen->id}_columns", [ $this, 'get_columns' ] ); |
| 38 | + add_filter( 'default_hidden_columns', [ $this, 'get_default_hidden_columns' ], 10, 2 ); | |
| 37 | 39 | add_filter( 'screen_settings', [ $this, 'render' ] ); |
| 38 | 40 | } |
| 39 | 41 | |
| 40 | 42 | add_screen_option( |
| @@ -59,8 +61,9 @@ | ||
| 59 | 61 | $columns, |
| 60 | 62 | [ |
| 61 | 63 | '_title' => __( 'Columns', 'code-snippets' ), |
| 62 | 64 | 'activate' => __( 'Active', 'code-snippets' ), |
| 65 | + 'id' => __( 'ID', 'code-snippets' ), | |
| 63 | 66 | 'name' => __( 'Name', 'code-snippets' ), |
| 64 | 67 | 'type' => __( 'Type', 'code-snippets' ), |
| 65 | 68 | 'desc' => __( 'Description', 'code-snippets' ), |
| 66 | 69 | 'tags' => __( 'Tags', 'code-snippets' ), |
| @@ -65,13 +68,29 @@ | ||
| 65 | 68 | 'desc' => __( 'Description', 'code-snippets' ), |
| 66 | 69 | 'tags' => __( 'Tags', 'code-snippets' ), |
| 67 | 70 | 'date' => __( 'Modified', 'code-snippets' ), |
| 68 | 71 | 'priority' => __( 'Priority', 'code-snippets' ), |
| 72 | + 'author' => __( 'Author', 'code-snippets' ), | |
| 73 | + 'insights' => __( 'Insights', 'code-snippets' ), | |
| 69 | 74 | ] |
| 70 | 75 | ); |
| 71 | 76 | } |
| 72 | 77 | |
| 73 | 78 | /** |
| 79 | + * Hide the optional ID column until a user enables it. | |
| 80 | + * | |
| 81 | + * @param string[] $hidden_columns Column identifiers hidden by default. | |
| 82 | + * @param WP_Screen $screen Current admin screen. | |
| 83 | + * | |
| 84 | + * @return string[] | |
| 85 | + */ | |
| 86 | + public function get_default_hidden_columns( array $hidden_columns, WP_Screen $screen ): array { | |
| 87 | + return get_current_screen() === $screen | |
| 88 | + ? array_merge( $hidden_columns, [ 'id' ] ) | |
| 89 | + : $hidden_columns; | |
| 90 | + } | |
| 91 | + | |
| 92 | + /** | |
| 74 | 93 | * Get the columns hidden for the current user. |
| 75 | 94 | * |
| 76 | 95 | * @return string[] |
| 77 | 96 | */ |
| @@ -106,12 +125,25 @@ | ||
| 106 | 125 | * |
| 107 | 126 | * @return bool |
| 108 | 127 | */ |
| 109 | 128 | public function is_manage_table_view(): bool { |
| 110 | - return ! $this->get_current_subpage(); | |
| 129 | + return in_array( $this->get_current_subpage(), [ '', 'snippets' ], true ); | |
| 111 | 130 | } |
| 112 | 131 | |
| 113 | 132 | /** |
| 133 | + * Whether the current request renders the AI Agent. | |
| 134 | + * | |
| 135 | + * The subpage has no screen options or help tabs of its own, so it remains | |
| 136 | + * an upsell view for {@see load()}; this detection exists only so its | |
| 137 | + * runtime data can be localized on the subpage that uses it. | |
| 138 | + * | |
| 139 | + * @return bool | |
| 140 | + */ | |
| 141 | + public function is_ai_agent_view(): bool { | |
| 142 | + return 'ai-agent' === $this->get_current_subpage(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + /** | |
| 114 | 146 | * Whether the current request renders Community Cloud. |
| 115 | 147 | * |
| 116 | 148 | * The "Bundles" tab within Community Cloud is a Pro-only upsell rather than |
| 117 | 149 | * genuine Community Cloud content, so it is excluded here and picked up by |
| @@ -146,13 +178,23 @@ | ||
| 146 | 178 | |
| 147 | 179 | /** |
| 148 | 180 | * Render the manage table controls. |
| 149 | 181 | * |
| 150 | - * @param string $screen_settings Existing screen settings HTML. | |
| 182 | + * Anything may filter `screen_settings` before this runs, and a callback | |
| 183 | + * that forgets to return its value hands the next one null. Declaring the | |
| 184 | + * parameter as a string turned that into a fatal error, and because it is | |
| 185 | + * raised while the screen meta is being rendered, the page dies after the | |
| 186 | + * admin chrome but before any content: the snippets screen appears blank | |
| 187 | + * while the rest of the admin looks fine. | |
| 151 | 188 | * |
| 189 | + * @param mixed $screen_settings Existing screen settings HTML, from an | |
| 190 | + * unknown number of earlier callbacks. | |
| 191 | + * | |
| 152 | 192 | * @return string |
| 153 | 193 | */ |
| 154 | - public function render( string $screen_settings ): string { | |
| 194 | + public function render( $screen_settings ): string { | |
| 195 | + $screen_settings = is_string( $screen_settings ) ? $screen_settings : ''; | |
| 196 | + | |
| 155 | 197 | if ( $this->is_cloud_community_view() ) { |
| 156 | 198 | return $screen_settings; |
| 157 | 199 | } |
| 158 | 200 | |