1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Admin Menu file. |
4
|
|
|
* |
5
|
|
|
* @package automattic/jetpack |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Automattic\Jetpack\Dashboard_Customizations; |
9
|
|
|
|
10
|
|
|
use Automattic\Jetpack\Redirect; |
11
|
|
|
|
12
|
|
|
require_once __DIR__ . '/class-base-admin-menu.php'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Admin_Menu. |
16
|
|
|
*/ |
17
|
|
|
class Admin_Menu extends Base_Admin_Menu { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Create the desired menu output. |
21
|
|
|
*/ |
22
|
|
|
public function reregister_menu_items() { |
23
|
|
|
// Constant is not defined until parse_request. |
24
|
|
|
if ( ! $this->is_api_request ) { |
25
|
|
|
$this->is_api_request = defined( 'REST_REQUEST' ) && REST_REQUEST; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/* |
29
|
|
|
* Whether links should point to Calypso or wp-admin. |
30
|
|
|
* |
31
|
|
|
* Options: |
32
|
|
|
* false - Calypso (Default). |
33
|
|
|
* true - wp-admin. |
34
|
|
|
*/ |
35
|
|
|
$wp_admin = $this->should_link_to_wp_admin(); |
36
|
|
|
|
37
|
|
|
// Remove separators. |
38
|
|
|
remove_menu_page( 'separator1' ); |
39
|
|
|
|
40
|
|
|
$this->add_stats_menu(); |
41
|
|
|
$this->add_upgrades_menu(); |
42
|
|
|
$this->add_posts_menu( $wp_admin ); |
43
|
|
|
$this->add_media_menu( $wp_admin ); |
44
|
|
|
$this->add_page_menu( $wp_admin ); |
45
|
|
|
$this->add_testimonials_menu( $wp_admin ); |
46
|
|
|
$this->add_portfolio_menu( $wp_admin ); |
47
|
|
|
$this->add_comments_menu( $wp_admin ); |
48
|
|
|
|
49
|
|
|
// Whether Themes/Customize links should point to Calypso (false) or wp-admin (true). |
50
|
|
|
$wp_admin_themes = $wp_admin; |
51
|
|
|
$wp_admin_customize = $wp_admin; |
52
|
|
|
$this->add_appearance_menu( $wp_admin_themes, $wp_admin_customize ); |
53
|
|
|
$this->add_plugins_menu( $wp_admin ); |
54
|
|
|
$this->add_users_menu( $wp_admin ); |
55
|
|
|
|
56
|
|
|
// Whether Import/Export links should point to Calypso (false) or wp-admin (true). |
57
|
|
|
$wp_admin_import = $wp_admin; |
58
|
|
|
$wp_admin_export = $wp_admin; |
59
|
|
|
$this->add_tools_menu( $wp_admin_import, $wp_admin_export ); |
60
|
|
|
|
61
|
|
|
$this->add_options_menu( $wp_admin ); |
62
|
|
|
$this->add_jetpack_menu(); |
63
|
|
|
$this->add_gutenberg_menus( $wp_admin ); |
64
|
|
|
|
65
|
|
|
// Remove Links Manager menu since its usage is discouraged. https://github.com/Automattic/wp-calypso/issues/51188. |
66
|
|
|
// @see https://core.trac.wordpress.org/ticket/21307#comment:73. |
67
|
|
|
if ( $this->should_disable_links_manager() ) { |
68
|
|
|
remove_menu_page( 'link-manager.php' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
ksort( $GLOBALS['menu'] ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Check if Links Manager is being used. |
76
|
|
|
*/ |
77
|
|
|
public function should_disable_links_manager() { |
78
|
|
|
// The max ID number of the auto-generated links. |
79
|
|
|
// See /wp-content/mu-plugins/wpcom-wp-install-defaults.php in WP.com. |
80
|
|
|
$max_default_id = 10; |
81
|
|
|
|
82
|
|
|
// We are only checking the latest entry link_id so are limiting the query to 1. |
83
|
|
|
$link_manager_links = get_bookmarks( |
84
|
|
|
array( |
85
|
|
|
'orderby' => 'link_id', |
86
|
|
|
'order' => 'DESC', |
87
|
|
|
'limit' => 1, |
88
|
|
|
'hide_invisible' => 0, |
89
|
|
|
) |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
// Ordered links by ID descending, check if the first ID is more than $max_default_id. |
93
|
|
|
if ( count( $link_manager_links ) > 0 && $link_manager_links[0]->link_id > $max_default_id ) { |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return true; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Adds My Home menu. |
102
|
|
|
*/ |
103
|
|
|
public function add_my_home_menu() { |
104
|
|
|
$this->update_menu( 'index.php', 'https://wordpress.com/home/' . $this->domain, __( 'My Home', 'jetpack' ), 'manage_options', 'dashicons-admin-home' ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Adds Stats menu. |
109
|
|
|
*/ |
110
|
|
|
public function add_stats_menu() { |
111
|
|
|
add_menu_page( __( 'Stats', 'jetpack' ), __( 'Stats', 'jetpack' ), 'view_stats', 'https://wordpress.com/stats/day/' . $this->domain, null, 'dashicons-chart-bar', 3 ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Adds Upgrades menu. |
116
|
|
|
* |
117
|
|
|
* @param string $plan The current WPCOM plan of the blog. |
|
|
|
|
118
|
|
|
*/ |
119
|
|
|
public function add_upgrades_menu( $plan = null ) { |
120
|
|
|
global $menu; |
121
|
|
|
|
122
|
|
|
$menu_exists = false; |
123
|
|
|
foreach ( $menu as $item ) { |
124
|
|
|
if ( 'paid-upgrades.php' === $item[2] ) { |
125
|
|
|
$menu_exists = true; |
126
|
|
|
break; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
if ( ! $menu_exists ) { |
131
|
|
|
if ( $plan ) { |
|
|
|
|
132
|
|
|
// Add display:none as a default for cases when CSS is not loaded. |
133
|
|
|
$site_upgrades = '%1$s<span class="inline-text" style="display:none">%2$s</span>'; |
134
|
|
|
$site_upgrades = sprintf( |
135
|
|
|
$site_upgrades, |
136
|
|
|
__( 'Upgrades', 'jetpack' ), |
137
|
|
|
$plan |
138
|
|
|
); |
139
|
|
|
} else { |
140
|
|
|
$site_upgrades = __( 'Upgrades', 'jetpack' ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
add_menu_page( __( 'Upgrades', 'jetpack' ), $site_upgrades, 'manage_options', 'paid-upgrades.php', null, 'dashicons-cart', 4 ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
add_submenu_page( 'paid-upgrades.php', __( 'Plans', 'jetpack' ), __( 'Plans', 'jetpack' ), 'manage_options', 'https://wordpress.com/plans/my-plan/' . $this->domain, null, 1 ); |
147
|
|
|
add_submenu_page( 'paid-upgrades.php', __( 'Purchases', 'jetpack' ), __( 'Purchases', 'jetpack' ), 'manage_options', 'https://wordpress.com/purchases/subscriptions/' . $this->domain, null, 2 ); |
148
|
|
|
|
149
|
|
|
if ( ! $menu_exists ) { |
150
|
|
|
// Remove the submenu auto-created by Core. |
151
|
|
|
$this->hide_submenu_page( 'paid-upgrades.php', 'paid-upgrades.php' ); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Adds Posts menu. |
157
|
|
|
* |
158
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
159
|
|
|
*/ |
160
|
|
|
public function add_posts_menu( $wp_admin = false ) { |
161
|
|
|
if ( $wp_admin ) { |
162
|
|
|
return; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
$submenus_to_update = array( |
166
|
|
|
'edit.php' => 'https://wordpress.com/posts/' . $this->domain, |
167
|
|
|
'post-new.php' => 'https://wordpress.com/post/' . $this->domain, |
168
|
|
|
'edit-tags.php?taxonomy=category' => 'https://wordpress.com/settings/taxonomies/category/' . $this->domain, |
169
|
|
|
'edit-tags.php?taxonomy=post_tag' => 'https://wordpress.com/settings/taxonomies/post_tag/' . $this->domain, |
170
|
|
|
); |
171
|
|
|
$this->update_submenus( 'edit.php', $submenus_to_update ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Adds Media menu. |
176
|
|
|
* |
177
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
178
|
|
|
*/ |
179
|
|
|
public function add_media_menu( $wp_admin = false ) { |
180
|
|
|
if ( $wp_admin ) { |
181
|
|
|
return; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
$this->hide_submenu_page( 'upload.php', 'media-new.php' ); |
185
|
|
|
|
186
|
|
|
$this->update_menu( 'upload.php', 'https://wordpress.com/media/' . $this->domain ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Adds Page menu. |
191
|
|
|
* |
192
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
193
|
|
|
*/ |
194
|
|
|
public function add_page_menu( $wp_admin = false ) { |
195
|
|
|
if ( $wp_admin ) { |
196
|
|
|
return; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$submenus_to_update = array( |
200
|
|
|
'edit.php?post_type=page' => 'https://wordpress.com/pages/' . $this->domain, |
201
|
|
|
'post-new.php?post_type=page' => 'https://wordpress.com/page/' . $this->domain, |
202
|
|
|
); |
203
|
|
|
$this->update_submenus( 'edit.php?post_type=page', $submenus_to_update ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Adds Testimonials menu. |
208
|
|
|
* |
209
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
210
|
|
|
*/ |
211
|
|
|
public function add_testimonials_menu( $wp_admin = false ) { |
212
|
|
|
$this->add_custom_post_type_menu( 'jetpack-testimonial', $wp_admin ); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Adds Portfolio menu. |
217
|
|
|
* |
218
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
219
|
|
|
*/ |
220
|
|
|
public function add_portfolio_menu( $wp_admin = false ) { |
221
|
|
|
$this->add_custom_post_type_menu( 'jetpack-portfolio', $wp_admin ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Adds a custom post type menu. |
226
|
|
|
* |
227
|
|
|
* @param string $post_type Custom post type. |
228
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
229
|
|
|
*/ |
230
|
|
|
public function add_custom_post_type_menu( $post_type, $wp_admin = false ) { |
231
|
|
|
if ( $wp_admin ) { |
232
|
|
|
return; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
$submenus_to_update = array( |
236
|
|
|
'edit.php?post_type=' . $post_type => 'https://wordpress.com/types/' . $post_type . '/' . $this->domain, |
237
|
|
|
'post-new.php?post_type=' . $post_type => 'https://wordpress.com/edit/' . $post_type . '/' . $this->domain, |
238
|
|
|
); |
239
|
|
|
$this->update_submenus( 'edit.php?post_type=' . $post_type, $submenus_to_update ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Adds Comments menu. |
244
|
|
|
* |
245
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
246
|
|
|
*/ |
247
|
|
|
public function add_comments_menu( $wp_admin = false ) { |
248
|
|
|
if ( $wp_admin ) { |
249
|
|
|
return; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
$this->update_menu( 'edit-comments.php', 'https://wordpress.com/comments/all/' . $this->domain ); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Adds Appearance menu. |
257
|
|
|
* |
258
|
|
|
* @param bool $wp_admin_themes Optional. Whether Themes link should point to Calypso or wp-admin. Default false (Calypso). |
259
|
|
|
* @param bool $wp_admin_customize Optional. Whether Customize link should point to Calypso or wp-admin. Default false (Calypso). |
260
|
|
|
* @return string The Customizer URL. |
261
|
|
|
*/ |
262
|
|
|
public function add_appearance_menu( $wp_admin_themes = false, $wp_admin_customize = false ) { |
263
|
|
|
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
264
|
|
|
$default_customize_slug = add_query_arg( 'return', rawurlencode( remove_query_arg( wp_removable_query_args(), $request_uri ) ), 'customize.php' ); |
265
|
|
|
$default_customize_header_slug_1 = add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $default_customize_slug ); |
266
|
|
|
// TODO: Remove WPCom_Theme_Customizer::modify_header_menu_links() and WPcom_Custom_Header::modify_admin_menu_links(). |
267
|
|
|
$default_customize_header_slug_2 = admin_url( 'themes.php?page=custom-header' ); |
268
|
|
|
$default_customize_background_slug_1 = add_query_arg( array( 'autofocus' => array( 'control' => 'background_image' ) ), $default_customize_slug ); |
269
|
|
|
// TODO: Remove Colors_Manager::modify_header_menu_links() and Colors_Manager_Common::modify_header_menu_links(). |
270
|
|
|
$default_customize_background_slug_2 = add_query_arg( array( 'autofocus' => array( 'section' => 'colors_manager_tool' ) ), admin_url( 'customize.php' ) ); |
271
|
|
|
|
272
|
|
|
if ( ! $wp_admin_customize ) { |
273
|
|
|
$customize_url = 'https://wordpress.com/customize/' . $this->domain; |
274
|
|
|
} elseif ( $this->is_api_request ) { |
275
|
|
|
// In case this is an api request we will have to add the 'return' querystring via JS. |
276
|
|
|
$customize_url = 'customize.php'; |
277
|
|
|
} else { |
278
|
|
|
$customize_url = $default_customize_slug; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
$submenus_to_update = array( |
282
|
|
|
$default_customize_slug => $customize_url, |
283
|
|
|
$default_customize_header_slug_1 => add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url ), |
284
|
|
|
$default_customize_header_slug_2 => add_query_arg( array( 'autofocus' => array( 'control' => 'header_image' ) ), $customize_url ), |
285
|
|
|
$default_customize_background_slug_1 => add_query_arg( array( 'autofocus' => array( 'section' => 'colors_manager_tool' ) ), $customize_url ), |
286
|
|
|
$default_customize_background_slug_2 => add_query_arg( array( 'autofocus' => array( 'section' => 'colors_manager_tool' ) ), $customize_url ), |
287
|
|
|
); |
288
|
|
|
|
289
|
|
|
if ( ! $wp_admin_themes ) { |
290
|
|
|
$submenus_to_update['themes.php'] = 'https://wordpress.com/themes/' . $this->domain; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
if ( ! $wp_admin_customize ) { |
294
|
|
|
$submenus_to_update['widgets.php'] = add_query_arg( array( 'autofocus' => array( 'panel' => 'widgets' ) ), $customize_url ); |
295
|
|
|
$submenus_to_update['gutenberg-widgets'] = add_query_arg( array( 'autofocus' => array( 'panel' => 'widgets' ) ), $customize_url ); |
296
|
|
|
$submenus_to_update['nav-menus.php'] = add_query_arg( array( 'autofocus' => array( 'panel' => 'nav_menus' ) ), $customize_url ); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
$this->update_submenus( 'themes.php', $submenus_to_update ); |
300
|
|
|
|
301
|
|
|
$this->hide_submenu_page( 'themes.php', 'custom-header' ); |
302
|
|
|
$this->hide_submenu_page( 'themes.php', 'custom-background' ); |
303
|
|
|
|
304
|
|
|
return $customize_url; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Adds Plugins menu. |
309
|
|
|
* |
310
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
311
|
|
|
*/ |
312
|
|
|
public function add_plugins_menu( $wp_admin = false ) { |
313
|
|
|
if ( $wp_admin ) { |
314
|
|
|
return; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
$this->hide_submenu_page( 'plugins.php', 'plugin-install.php' ); |
318
|
|
|
$this->hide_submenu_page( 'plugins.php', 'plugin-editor.php' ); |
319
|
|
|
|
320
|
|
|
$this->update_menu( 'plugins.php', 'https://wordpress.com/plugins/' . $this->domain ); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Adds Users menu. |
325
|
|
|
* |
326
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
327
|
|
|
*/ |
328
|
|
|
public function add_users_menu( $wp_admin = false ) { |
329
|
|
|
if ( current_user_can( 'list_users' ) ) { |
330
|
|
|
// We shall add the Calypso user management & add new user screens at all cases ( Calypso & Atomic ). |
331
|
|
|
$submenus_to_update = array( |
332
|
|
|
'user-new.php' => 'https://wordpress.com/people/new/' . $this->domain, |
333
|
|
|
'users.php' => 'https://wordpress.com/people/team/' . $this->domain, |
334
|
|
|
); |
335
|
|
|
if ( ! $wp_admin ) { |
336
|
|
|
$submenus_to_update['profile.php'] = 'https://wordpress.com/me'; |
337
|
|
|
} |
338
|
|
|
$this->update_submenus( 'users.php', $submenus_to_update ); |
339
|
|
|
add_submenu_page( 'users.php', esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' ); |
340
|
|
|
} else { |
341
|
|
|
if ( ! $wp_admin ) { |
342
|
|
|
$submenus_to_update = array( |
343
|
|
|
'user-new.php' => 'https://wordpress.com/people/new/' . $this->domain, |
344
|
|
|
'profile.php' => 'https://wordpress.com/me', |
345
|
|
|
); |
346
|
|
|
$this->update_submenus( 'profile.php', $submenus_to_update ); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
add_submenu_page( 'profile.php', esc_attr__( 'Account Settings', 'jetpack' ), __( 'Account Settings', 'jetpack' ), 'read', 'https://wordpress.com/me/account' ); |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* Adds Tools menu. |
355
|
|
|
* |
356
|
|
|
* @param bool $wp_admin_import Optional. Whether Import link should point to Calypso or wp-admin. Default false (Calypso). |
357
|
|
|
* @param bool $wp_admin_export Optional. Whether Export link should point to Calypso or wp-admin. Default false (Calypso). |
358
|
|
|
*/ |
359
|
|
|
public function add_tools_menu( $wp_admin_import = false, $wp_admin_export = false ) { |
360
|
|
|
$submenus_to_update = array(); |
361
|
|
|
if ( ! $wp_admin_import ) { |
362
|
|
|
$submenus_to_update['import.php'] = 'https://wordpress.com/import/' . $this->domain; |
363
|
|
|
} |
364
|
|
|
if ( ! $wp_admin_export ) { |
365
|
|
|
$submenus_to_update['export.php'] = 'https://wordpress.com/export/' . $this->domain; |
366
|
|
|
} |
367
|
|
|
$this->update_submenus( 'tools.php', $submenus_to_update ); |
368
|
|
|
|
369
|
|
|
$this->hide_submenu_page( 'tools.php', 'tools.php' ); |
370
|
|
|
$this->hide_submenu_page( 'tools.php', 'delete-blog' ); |
371
|
|
|
|
372
|
|
|
add_submenu_page( 'tools.php', esc_attr__( 'Marketing', 'jetpack' ), __( 'Marketing', 'jetpack' ), 'publish_posts', 'https://wordpress.com/marketing/tools/' . $this->domain, null, 0 ); |
373
|
|
|
add_submenu_page( 'tools.php', esc_attr__( 'Earn', 'jetpack' ), __( 'Earn', 'jetpack' ), 'manage_options', 'https://wordpress.com/earn/' . $this->domain, null, 1 ); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Adds Settings menu. |
378
|
|
|
* |
379
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
380
|
|
|
*/ |
381
|
|
|
public function add_options_menu( $wp_admin = false ) { |
382
|
|
|
if ( $wp_admin ) { |
383
|
|
|
return; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
$this->update_submenus( 'options-general.php', array( 'options-general.php' => 'https://wordpress.com/settings/general/' . $this->domain ) ); |
387
|
|
|
|
388
|
|
|
$this->hide_submenu_page( 'options-general.php', 'options-discussion.php' ); |
389
|
|
|
$this->hide_submenu_page( 'options-general.php', 'options-writing.php' ); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Adds Jetpack menu. |
394
|
|
|
*/ |
395
|
|
|
public function add_jetpack_menu() { |
396
|
|
|
$this->add_admin_menu_separator( 50, 'manage_options' ); |
397
|
|
|
|
398
|
|
|
// TODO: Replace with proper SVG data url. |
399
|
|
|
$icon = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 40 40' %3E%3Cpath fill='%23a0a5aa' d='M20 0c11.046 0 20 8.954 20 20s-8.954 20-20 20S0 31.046 0 20 8.954 0 20 0zm11 17H21v19l10-19zM19 4L9 23h10V4z'/%3E%3C/svg%3E"; |
400
|
|
|
|
401
|
|
|
$is_menu_updated = $this->update_menu( 'jetpack', null, null, null, $icon, 51 ); |
402
|
|
|
if ( ! $is_menu_updated ) { |
403
|
|
|
add_menu_page( esc_attr__( 'Jetpack', 'jetpack' ), __( 'Jetpack', 'jetpack' ), 'manage_options', 'jetpack', null, $icon, 51 ); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
add_submenu_page( 'jetpack', esc_attr__( 'Activity Log', 'jetpack' ), __( 'Activity Log', 'jetpack' ), 'manage_options', 'https://wordpress.com/activity-log/' . $this->domain, null, 2 ); |
407
|
|
|
add_submenu_page( 'jetpack', esc_attr__( 'Backup', 'jetpack' ), __( 'Backup', 'jetpack' ), 'manage_options', 'https://wordpress.com/backup/' . $this->domain, null, 3 ); |
408
|
|
|
/* translators: Jetpack sidebar menu item. */ |
409
|
|
|
add_submenu_page( 'jetpack', esc_attr__( 'Search', 'jetpack' ), __( 'Search', 'jetpack' ), 'read', 'https://wordpress.com/jetpack-search/' . $this->domain, null, 4 ); |
410
|
|
|
|
411
|
|
|
$this->hide_submenu_page( 'jetpack', 'stats' ); |
412
|
|
|
$this->hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-backups' ) ) ); |
413
|
|
|
$this->hide_submenu_page( 'jetpack', esc_url( Redirect::get_url( 'calypso-scanner' ) ) ); |
414
|
|
|
|
415
|
|
|
if ( ! $is_menu_updated ) { |
416
|
|
|
// Remove the submenu auto-created by Core. |
417
|
|
|
$this->hide_submenu_page( 'jetpack', 'jetpack' ); |
418
|
|
|
} |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* Re-adds the Site Editor menu without the (beta) tag, and where we want it. |
423
|
|
|
* |
424
|
|
|
* @param bool $wp_admin Optional. Whether links should point to Calypso or wp-admin. Default false (Calypso). |
425
|
|
|
*/ |
426
|
|
|
public function add_gutenberg_menus( $wp_admin = false ) { |
427
|
|
|
// We can bail if we don't meet the conditions of the Site Editor. |
428
|
|
|
if ( ! ( function_exists( 'gutenberg_is_fse_theme' ) && gutenberg_is_fse_theme() ) ) { |
429
|
|
|
return; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
// Core Gutenberg registers without an explicit position, and we don't want the (beta) tag. |
433
|
|
|
remove_menu_page( 'gutenberg-edit-site' ); |
434
|
|
|
// Core Gutenberg tries to manage its position, foiling our best laid plans. Unfoil. |
435
|
|
|
remove_filter( 'menu_order', 'gutenberg_menu_order' ); |
436
|
|
|
|
437
|
|
|
$link = $wp_admin ? 'gutenberg-edit-site' : 'https://wordpress.com/site-editor/' . $this->domain; |
438
|
|
|
|
439
|
|
|
add_menu_page( |
440
|
|
|
__( 'Site Editor', 'jetpack' ), |
441
|
|
|
__( 'Site Editor', 'jetpack' ), |
442
|
|
|
'edit_theme_options', |
443
|
|
|
$link, |
444
|
|
|
$wp_admin ? 'gutenberg_edit_site_page' : null, |
445
|
|
|
'dashicons-layout', |
446
|
|
|
61 // Just under Appearance. |
447
|
|
|
); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Whether to use wp-admin pages rather than Calypso. |
452
|
|
|
* |
453
|
|
|
* @return bool |
454
|
|
|
*/ |
455
|
|
|
public function should_link_to_wp_admin() { |
456
|
|
|
return get_user_option( 'jetpack_admin_menu_link_destination' ); |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
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.