1 | <?php |
||
15 | abstract class Base_Admin_Menu { |
||
16 | /** |
||
17 | * Holds class instances. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected static $instances; |
||
22 | |||
23 | /** |
||
24 | * Whether the current request is a REST API request. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | protected $is_api_request = false; |
||
29 | |||
30 | /** |
||
31 | * Domain of the current site. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $domain; |
||
36 | |||
37 | /** |
||
38 | * Base_Admin_Menu constructor. |
||
39 | */ |
||
40 | protected function __construct() { |
||
48 | |||
49 | /** |
||
50 | * Determine if the current request is from API |
||
51 | */ |
||
52 | public function set_is_api_request() { |
||
58 | |||
59 | /** |
||
60 | * Returns class instance. |
||
61 | * |
||
62 | * @return Admin_Menu |
||
63 | */ |
||
64 | public static function get_instance() { |
||
73 | |||
74 | /** |
||
75 | * Sets up class properties for REST API requests. |
||
76 | * |
||
77 | * @param \WP_REST_Response $response Response from the endpoint. |
||
78 | */ |
||
79 | public function rest_api_init( $response ) { |
||
84 | |||
85 | /** |
||
86 | * Updates the menu data of the given menu slug. |
||
87 | * |
||
88 | * @param string $slug Slug of the menu to update. |
||
89 | * @param string $url New menu URL. |
||
|
|||
90 | * @param string $title New menu title. |
||
91 | * @param string $cap New menu capability. |
||
92 | * @param string $icon New menu icon. |
||
93 | * @param int $position New menu position. |
||
94 | * @return bool Whether the menu has been updated. |
||
95 | */ |
||
96 | public function update_menu( $slug, $url = null, $title = null, $cap = null, $icon = null, $position = null ) { |
||
151 | |||
152 | /** |
||
153 | * Updates the submenus of the given menu slug. |
||
154 | * |
||
155 | * @param string $slug Menu slug. |
||
156 | * @param array $submenus_to_update Array of new submenu slugs. |
||
157 | */ |
||
158 | public function update_submenus( $slug, $submenus_to_update ) { |
||
173 | |||
174 | /** |
||
175 | * Adds a menu separator. |
||
176 | * |
||
177 | * @param int $position The position in the menu order this item should appear. |
||
178 | * @param string $cap Optional. The capability required for this menu to be displayed to the user. |
||
179 | * Default: 'read'. |
||
180 | */ |
||
181 | public function add_admin_menu_separator( $position, $cap = 'read' ) { |
||
194 | |||
195 | /** |
||
196 | * Enqueues scripts and styles. |
||
197 | */ |
||
198 | public function enqueue_scripts() { |
||
199 | $is_wpcom = defined( 'IS_WPCOM' ) && IS_WPCOM; |
||
200 | |||
201 | if ( $this->is_rtl() ) { |
||
202 | if ( $is_wpcom ) { |
||
203 | $css_path = 'rtl/admin-menu-rtl.css'; |
||
204 | } else { |
||
205 | $css_path = 'admin-menu-rtl.css'; |
||
206 | } |
||
207 | } else { |
||
208 | $css_path = 'admin-menu.css'; |
||
209 | } |
||
210 | |||
211 | wp_enqueue_style( |
||
212 | 'jetpack-admin-menu', |
||
213 | plugins_url( $css_path, __FILE__ ), |
||
214 | array(), |
||
215 | JETPACK__VERSION |
||
216 | ); |
||
217 | |||
218 | wp_enqueue_script( |
||
219 | 'jetpack-admin-menu', |
||
220 | plugins_url( 'admin-menu.js', __FILE__ ), |
||
221 | array(), |
||
222 | JETPACK__VERSION, |
||
223 | true |
||
224 | ); |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * Remove submenu items from given menu slug. |
||
229 | * |
||
230 | * @param string $slug Menu slug. |
||
231 | */ |
||
232 | public function remove_submenus( $slug ) { |
||
233 | global $submenu; |
||
234 | |||
235 | if ( isset( $submenu[ $slug ] ) ) { |
||
236 | // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
||
237 | $submenu[ $slug ] = array(); |
||
238 | } |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * Determines whether the current locale is right-to-left (RTL). |
||
243 | */ |
||
244 | public function is_rtl() { |
||
245 | return is_rtl(); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Whether to use wp-admin pages rather than Calypso. |
||
250 | * |
||
251 | * Options: |
||
252 | * false - Calypso (Default). |
||
253 | * true - wp-admin. |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | abstract public function should_link_to_wp_admin(); |
||
258 | |||
259 | /** |
||
260 | * Create the desired menu output. |
||
261 | */ |
||
262 | abstract public function reregister_menu_items(); |
||
263 | } |
||
264 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.