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