← All changes
|
php/Admin/Menus/Manage/Manage_Menu_Screen_Options.php
+33
-1
3.10.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. |
| @@ -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,9 +125,22 @@ | ||
| 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 ); | |
| 130 | + } | |
| 131 | + | |
| 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(); | |
| 111 | 143 | } |
| 112 | 144 | |
| 113 | 145 | /** |
| 114 | 146 | * Whether the current request renders Community Cloud. |