Acf
1 month ago
Admin
1 month ago
Ajax
1 month ago
ApplyFilter
1 month ago
Asset
1 month ago
Capabilities
1 month ago
Check
1 month ago
Collection
1 month ago
Column
1 month ago
ColumnFactories
1 month ago
ColumnFactory
1 month ago
ColumnIterator
1 month ago
ColumnRepository
1 month ago
ColumnSize
1 month ago
DI
1 month ago
Deprecated
1 month ago
Entity
1 month ago
Exception
1 month ago
Expression
1 month ago
Form
1 month ago
Formatter
1 month ago
Helper
1 month ago
Integration
1 month ago
ListScreenRepository
1 month ago
ListTable
1 month ago
Message
1 month ago
Meta
1 month ago
Nonce
1 month ago
Notice
1 month ago
Plugin
1 month ago
Preferences
1 month ago
Promo
1 month ago
Request
1 month ago
RequestHandler
1 month ago
Response
1 month ago
Sanitize
1 month ago
Service
1 month ago
Setting
1 month ago
Settings
1 month ago
Storage
1 month ago
Table
1 month ago
TableIdsFactory
1 month ago
TableScreen
1 month ago
TableScreenFactory
1 month ago
ThirdParty
1 month ago
Type
1 month ago
Value
1 month ago
View
1 month ago
Acf.php
1 month ago
AdminColumns.php
1 month ago
ArrayIterator.php
1 month ago
Capabilities.php
1 month ago
Collection.php
1 month ago
CollectionFormatter.php
1 month ago
Column.php
1 month ago
ColumnCollection.php
1 month ago
ColumnFactoryCollectionFactory.php
1 month ago
ColumnFactoryDefinitionCollection.php
1 month ago
ColumnGroups.php
1 month ago
ColumnIterator.php
1 month ago
ColumnNamesTrait.php
1 month ago
ColumnRepository.php
1 month ago
ColumnTypeRepository.php
1 month ago
Config.php
1 month ago
Container.php
1 month ago
DateFormats.php
1 month ago
Expirable.php
1 month ago
Formatter.php
1 month ago
FormatterCollection.php
1 month ago
Helper.php
1 month ago
ListScreen.php
1 month ago
ListScreenCollection.php
1 month ago
ListScreenRepository.php
1 month ago
ListScreenRepositoryWritable.php
1 month ago
ListTable.php
1 month ago
ListTableFactory.php
1 month ago
Loader.php
1 month ago
Message.php
1 month ago
MetaType.php
1 month ago
Middleware.php
1 month ago
OpCacheInvalidateTrait.php
1 month ago
PluginActionLinks.php
1 month ago
PluginActionUpgrade.php
1 month ago
PostType.php
1 month ago
PostTypeRepository.php
1 month ago
Registerable.php
1 month ago
Registry.php
1 month ago
Renderable.php
1 month ago
Request.php
1 month ago
RequestAjaxHandler.php
1 month ago
RequestAjaxHandlers.php
1 month ago
RequestAjaxParser.php
1 month ago
RequestHandler.php
1 month ago
RequestHandlerFactory.php
1 month ago
Screen.php
1 month ago
Services.php
1 month ago
TableIdsFactory.php
1 month ago
TableScreen.php
1 month ago
TableScreenFactory.php
1 month ago
Taxonomy.php
1 month ago
Transient.php
1 month ago
TypedArrayIterator.php
1 month ago
View.php
1 month ago
WooCommerce.php
1 month ago
WpListTableFactory.php
1 month ago
Screen.php
120 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC; |
| 4 | |
| 5 | use AC\Admin\Page\Columns; |
| 6 | use AC\Admin\RequestHandlerInterface; |
| 7 | use WP_Screen; |
| 8 | |
| 9 | class Screen implements Registerable |
| 10 | { |
| 11 | |
| 12 | protected ?WP_Screen $screen = null; |
| 13 | |
| 14 | private TableScreenFactory $table_screen_factory; |
| 15 | |
| 16 | public function __construct(TableScreenFactory $table_screen_factory) |
| 17 | { |
| 18 | $this->table_screen_factory = $table_screen_factory; |
| 19 | } |
| 20 | |
| 21 | public function register(): void |
| 22 | { |
| 23 | add_action('current_screen', [$this, 'init']); |
| 24 | } |
| 25 | |
| 26 | public function init(WP_Screen $screen): void |
| 27 | { |
| 28 | $this->set_screen($screen); |
| 29 | |
| 30 | do_action('ac/screen', $this, $this->screen->id); |
| 31 | } |
| 32 | |
| 33 | public function is_screen(string $id): bool |
| 34 | { |
| 35 | return $this->has_screen() && $this->get_screen()->id === $id; |
| 36 | } |
| 37 | |
| 38 | public function set_screen(WP_Screen $screen): self |
| 39 | { |
| 40 | $this->screen = $screen; |
| 41 | |
| 42 | return $this; |
| 43 | } |
| 44 | |
| 45 | public function get_screen(): WP_Screen |
| 46 | { |
| 47 | return $this->screen; |
| 48 | } |
| 49 | |
| 50 | public function has_screen(): bool |
| 51 | { |
| 52 | return $this->screen instanceof WP_Screen; |
| 53 | } |
| 54 | |
| 55 | public function get_id(): string |
| 56 | { |
| 57 | return $this->screen->id; |
| 58 | } |
| 59 | |
| 60 | public function get_base(): string |
| 61 | { |
| 62 | return $this->screen->base; |
| 63 | } |
| 64 | |
| 65 | public function get_post_type(): string |
| 66 | { |
| 67 | return $this->screen->post_type; |
| 68 | } |
| 69 | |
| 70 | private function is_admin_network(): bool |
| 71 | { |
| 72 | return $this->screen->in_admin('network'); |
| 73 | } |
| 74 | |
| 75 | public function is_table_screen(): bool |
| 76 | { |
| 77 | return $this->table_screen_factory->can_create_from_wp_screen($this->screen); |
| 78 | } |
| 79 | |
| 80 | public function is_plugin_screen(): bool |
| 81 | { |
| 82 | $screen = $this->is_admin_network() |
| 83 | ? 'plugins-network' |
| 84 | : 'plugins'; |
| 85 | |
| 86 | return $this->is_screen($screen); |
| 87 | } |
| 88 | |
| 89 | public function is_admin_screen(?string $slug = null): bool |
| 90 | { |
| 91 | if (null !== $slug) { |
| 92 | $tabs = [$slug]; |
| 93 | |
| 94 | // When the column page is requested from the setting menu the 'tab' querystring is not set. |
| 95 | if (Columns::NAME === $slug) { |
| 96 | $tabs[] = null; |
| 97 | } |
| 98 | |
| 99 | return $this->is_main_admin_screen() && in_array( |
| 100 | filter_input(INPUT_GET, RequestHandlerInterface::PARAM_TAB), |
| 101 | $tabs, |
| 102 | true |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | return $this->is_main_admin_screen(); |
| 107 | } |
| 108 | |
| 109 | private function is_main_admin_screen(): bool |
| 110 | { |
| 111 | $id = 'settings_page_' . Admin\Admin::NAME; |
| 112 | |
| 113 | if ($this->is_admin_network()) { |
| 114 | $id .= '-network'; |
| 115 | } |
| 116 | |
| 117 | return $this->is_screen($id); |
| 118 | } |
| 119 | |
| 120 | } |