Admin
5 years ago
Ajax
5 years ago
Asset
5 years ago
Autoloader
5 years ago
Capabilities
5 years ago
Check
5 years ago
Column
5 years ago
Controller
5 years ago
Deprecated
5 years ago
Exception
5 years ago
Form
5 years ago
Helper
5 years ago
Integration
5 years ago
ListScreen
5 years ago
ListScreenRepository
5 years ago
ListTable
5 years ago
Message
5 years ago
Meta
5 years ago
Plugin
5 years ago
Preferences
5 years ago
Promo
5 years ago
Relation
5 years ago
Request
5 years ago
Response
5 years ago
Screen
5 years ago
Service
5 years ago
Settings
5 years ago
Storage
5 years ago
Table
5 years ago
ThirdParty
5 years ago
Transient
5 years ago
Type
5 years ago
Addon.php
5 years ago
Admin.php
5 years ago
AdminColumns.php
5 years ago
AdminFactory.php
5 years ago
ArrayIterator.php
5 years ago
Autoloader.php
5 years ago
Builder.php
5 years ago
Capabilities.php
5 years ago
Collection.php
5 years ago
Column.php
5 years ago
ColumnGroups.php
5 years ago
Config.php
5 years ago
DefaultColumnsRepository.php
5 years ago
Dependencies.php
5 years ago
EncodedListScreenData.php
5 years ago
EncodedListScreenDataFactory.php
5 years ago
Expirable.php
5 years ago
Groups.php
5 years ago
Helper.php
5 years ago
Installer.php
5 years ago
Integration.php
5 years ago
Integrations.php
5 years ago
ListScreen.php
5 years ago
ListScreenCollection.php
5 years ago
ListScreenFactory.php
5 years ago
ListScreenGroups.php
5 years ago
ListScreenPost.php
5 years ago
ListScreenRepository.php
5 years ago
ListScreenRepositoryWritable.php
5 years ago
ListScreenTypes.php
5 years ago
ListScreenWP.php
5 years ago
ListScreens.php
5 years ago
ListTable.php
5 years ago
ListTableFactory.php
5 years ago
Message.php
5 years ago
MetaType.php
5 years ago
Middleware.php
5 years ago
NoticeChecks.php
5 years ago
OpCacheInvalidateTrait.php
5 years ago
PermissionChecker.php
5 years ago
Plugin.php
5 years ago
PluginActionLinks.php
5 years ago
PluginInformation.php
5 years ago
Preferences.php
5 years ago
Promo.php
5 years ago
PromoCollection.php
5 years ago
Registrable.php
5 years ago
Relation.php
5 years ago
Renderable.php
5 years ago
Request.php
5 years ago
Screen.php
5 years ago
ScreenController.php
5 years ago
TableLoader.php
5 years ago
Transient.php
5 years ago
TypedArrayIterator.php
5 years ago
View.php
5 years ago
Screen.php
149 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC; |
| 4 | |
| 5 | use WP_Screen; |
| 6 | |
| 7 | class Screen implements Registrable { |
| 8 | |
| 9 | /** |
| 10 | * @var WP_Screen |
| 11 | */ |
| 12 | protected $screen; |
| 13 | |
| 14 | public function register() { |
| 15 | add_action( 'current_screen', [ $this, 'init' ] ); |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * @param WP_Screen $screen |
| 20 | */ |
| 21 | public function init( WP_Screen $screen ) { |
| 22 | $this->set_screen( $screen ); |
| 23 | |
| 24 | do_action( 'ac/screen', $this, $this->screen->id ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param $id |
| 29 | * |
| 30 | * @return bool |
| 31 | */ |
| 32 | public function is_screen( $id ) { |
| 33 | return $this->has_screen() && $this->get_screen()->id === $id; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param WP_Screen $screen |
| 38 | * |
| 39 | * @return $this |
| 40 | */ |
| 41 | public function set_screen( WP_Screen $screen ) { |
| 42 | $this->screen = $screen; |
| 43 | |
| 44 | return $this; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @return WP_Screen |
| 49 | */ |
| 50 | public function get_screen() { |
| 51 | return $this->screen; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return bool |
| 56 | */ |
| 57 | public function has_screen() { |
| 58 | return $this->screen instanceof WP_Screen; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return string |
| 63 | */ |
| 64 | public function get_id() { |
| 65 | return $this->screen->id; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return string |
| 70 | */ |
| 71 | public function get_base() { |
| 72 | return $this->screen->base; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return string |
| 77 | */ |
| 78 | public function get_post_type() { |
| 79 | return $this->screen->post_type; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return string|null |
| 84 | */ |
| 85 | public function get_list_screen() { |
| 86 | foreach ( ListScreenTypes::instance()->get_list_screens() as $list_screen ) { |
| 87 | if ( $list_screen->is_current_screen( $this->screen ) ) { |
| 88 | return $list_screen->get_key(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return null; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @return bool |
| 97 | */ |
| 98 | private function is_admin_network() { |
| 99 | return $this->screen->in_admin( 'network' ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @return bool |
| 104 | */ |
| 105 | public function is_list_screen() { |
| 106 | return null !== $this->get_list_screen(); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Check if current screen is plugins screen |
| 111 | * @return bool |
| 112 | */ |
| 113 | public function is_plugin_screen() { |
| 114 | $id = 'plugins'; |
| 115 | |
| 116 | if ( $this->is_admin_network() ) { |
| 117 | $id .= '-network'; |
| 118 | } |
| 119 | |
| 120 | return $this->is_screen( $id ); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * @param string|null $slug |
| 125 | * |
| 126 | * @return bool |
| 127 | */ |
| 128 | public function is_admin_screen( $slug = null ) { |
| 129 | if ( null !== $slug ) { |
| 130 | return $this->is_main_admin_screen() && $slug === filter_input( INPUT_GET, 'tab' ); |
| 131 | } |
| 132 | |
| 133 | return $this->is_main_admin_screen(); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @return bool |
| 138 | */ |
| 139 | private function is_main_admin_screen() { |
| 140 | $id = 'settings_page_' . Admin::NAME; |
| 141 | |
| 142 | if ( $this->is_admin_network() ) { |
| 143 | $id .= '-network'; |
| 144 | } |
| 145 | |
| 146 | return $this->is_screen( $id ); |
| 147 | } |
| 148 | |
| 149 | } |