1
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
2
|
|
|
|
3
|
|
|
namespace Automattic\Jetpack\Dashboard_Customizations; |
4
|
|
|
|
5
|
|
|
use Automattic\Jetpack\Assets; |
6
|
|
|
use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
7
|
|
|
use Automattic\Jetpack\Device_Detection\User_Agent_Info; |
8
|
|
|
use Automattic\Jetpack\Redirect; |
9
|
|
|
use Automattic\Jetpack\Scan\Admin_Bar_Notice; |
10
|
|
|
use GP_Locale; |
11
|
|
|
use GP_Locales; |
12
|
|
|
use Jetpack; |
13
|
|
|
use Jetpack_AMP_Support; |
14
|
|
|
use Jetpack_Plan; |
15
|
|
|
use WP_Admin_Bar; |
16
|
|
|
use WP_User; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Provides custom admin bar instead of the default WordPress admin bar. |
20
|
|
|
*/ |
21
|
|
|
class Masterbar { |
22
|
|
|
/** |
23
|
|
|
* Use for testing changes made to remotely enqueued scripts and styles on your sandbox. |
24
|
|
|
* If not set it will default to loading the ones from WordPress.com. |
25
|
|
|
* |
26
|
|
|
* @var string $sandbox_url |
27
|
|
|
*/ |
28
|
|
|
private $sandbox_url = ''; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Current locale. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $locale; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Current User ID. |
39
|
|
|
* |
40
|
|
|
* @var int |
41
|
|
|
*/ |
42
|
|
|
private $user_id; |
43
|
|
|
/** |
44
|
|
|
* WordPress.com user data of the connected user. |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
private $user_data; |
49
|
|
|
/** |
50
|
|
|
* WordPress.com username for the connected user. |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private $user_login; |
55
|
|
|
/** |
56
|
|
|
* WordPress.com email address for the connected user. |
57
|
|
|
* |
58
|
|
|
* @var string |
59
|
|
|
*/ |
60
|
|
|
private $user_email; |
61
|
|
|
/** |
62
|
|
|
* WordPress.com display name for the connected user. |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
private $display_name; |
67
|
|
|
/** |
68
|
|
|
* Site URL sanitized for usage in WordPress.com slugs. |
69
|
|
|
* |
70
|
|
|
* @var string |
71
|
|
|
*/ |
72
|
|
|
private $primary_site_slug; |
73
|
|
|
/** |
74
|
|
|
* Text direction (ltr or rtl) based on connected WordPress.com user's interface settings. |
75
|
|
|
* |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
private $user_text_direction; |
79
|
|
|
/** |
80
|
|
|
* Number of sites owned by connected WordPress.com user. |
81
|
|
|
* |
82
|
|
|
* @var int |
83
|
|
|
*/ |
84
|
|
|
private $user_site_count; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Constructor |
88
|
|
|
*/ |
89
|
|
|
public function __construct() { |
90
|
|
|
add_action( 'admin_bar_init', array( $this, 'init' ) ); |
91
|
|
|
|
92
|
|
|
// Post logout on the site, also log the user out of WordPress.com. |
93
|
|
|
add_filter( 'logout_redirect', array( $this, 'maybe_logout_user_from_wpcom' ), 10, 3 ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Initialize our masterbar. |
98
|
|
|
*/ |
99
|
|
|
public function init() { |
100
|
|
|
$this->locale = $this->get_locale(); |
101
|
|
|
$this->user_id = get_current_user_id(); |
102
|
|
|
|
103
|
|
|
// Limit the masterbar to be shown only to connected Jetpack users. |
104
|
|
|
if ( ! Jetpack::is_user_connected( $this->user_id ) ) { |
105
|
|
|
return; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// Don't show the masterbar on WordPress mobile apps. |
109
|
|
|
if ( User_Agent_Info::is_mobile_app() ) { |
110
|
|
|
add_filter( 'show_admin_bar', '__return_false' ); |
111
|
|
|
return; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// Disable the Masterbar on AMP views. |
115
|
|
|
if ( |
116
|
|
|
class_exists( 'Jetpack_AMP_Support' ) |
117
|
|
|
&& Jetpack_AMP_Support::is_amp_request() |
118
|
|
|
) { |
119
|
|
|
return; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
Assets::add_resource_hint( |
123
|
|
|
array( |
124
|
|
|
'//s0.wp.com', |
125
|
|
|
'//s1.wp.com', |
126
|
|
|
'//s2.wp.com', |
127
|
|
|
'//0.gravatar.com', |
128
|
|
|
'//1.gravatar.com', |
129
|
|
|
'//2.gravatar.com', |
130
|
|
|
), |
131
|
|
|
'dns-prefetch' |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
// Atomic only. |
135
|
|
|
if ( jetpack_is_atomic_site() ) { |
136
|
|
|
/* |
137
|
|
|
* override user setting that hides masterbar from site's front. |
138
|
|
|
* https://github.com/Automattic/jetpack/issues/7667 |
139
|
|
|
*/ |
140
|
|
|
add_filter( 'show_admin_bar', '__return_true' ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$this->user_data = Jetpack::get_connected_user_data( $this->user_id ); |
144
|
|
|
$this->user_login = $this->user_data['login']; |
145
|
|
|
$this->user_email = $this->user_data['email']; |
146
|
|
|
$this->display_name = $this->user_data['display_name']; |
147
|
|
|
$this->user_site_count = $this->user_data['site_count']; |
148
|
|
|
|
149
|
|
|
// Used to build menu links that point directly to Calypso. |
150
|
|
|
$this->primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); |
151
|
|
|
|
152
|
|
|
// Used for display purposes and for building WP Admin links. |
153
|
|
|
$this->primary_site_url = str_replace( '::', '/', $this->primary_site_slug ); |
|
|
|
|
154
|
|
|
|
155
|
|
|
// We need to use user's setting here, instead of relying on current blog's text direction. |
156
|
|
|
$this->user_text_direction = $this->user_data['text_direction']; |
157
|
|
|
|
158
|
|
|
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
159
|
|
|
|
160
|
|
|
add_action( 'wp_before_admin_bar_render', array( $this, 'replace_core_masterbar' ), 99999 ); |
161
|
|
|
|
162
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'add_styles_and_scripts' ) ); |
163
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'add_styles_and_scripts' ) ); |
164
|
|
|
|
165
|
|
|
add_action( 'wp_enqueue_scripts', array( $this, 'remove_core_styles' ) ); |
166
|
|
|
add_action( 'admin_enqueue_scripts', array( $this, 'remove_core_styles' ) ); |
167
|
|
|
|
168
|
|
|
if ( Jetpack::is_module_active( 'notes' ) && $this->is_rtl() ) { |
169
|
|
|
// Override Notification module to include RTL styles. |
170
|
|
|
add_action( 'a8c_wpcom_masterbar_enqueue_rtl_notification_styles', '__return_true' ); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Log out from WordPress.com when logging out of the local site. |
176
|
|
|
* |
177
|
|
|
* @param string $redirect_to The redirect destination URL. |
178
|
|
|
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter. |
179
|
|
|
* @param WP_User $user The WP_User object for the user that's logging out. |
180
|
|
|
*/ |
181
|
|
|
public function maybe_logout_user_from_wpcom( $redirect_to, $requested_redirect_to, $user ) { |
182
|
|
|
/** |
183
|
|
|
* Whether we should sign out from wpcom too when signing out from the masterbar. |
184
|
|
|
* |
185
|
|
|
* @since 5.9.0 |
186
|
|
|
* |
187
|
|
|
* @param bool $masterbar_should_logout_from_wpcom True by default. |
188
|
|
|
*/ |
189
|
|
|
$masterbar_should_logout_from_wpcom = apply_filters( 'jetpack_masterbar_should_logout_from_wpcom', true ); |
190
|
|
|
if ( |
191
|
|
|
// No need to check for a nonce here, it happens further up. |
192
|
|
|
isset( $_GET['context'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
193
|
|
|
&& 'masterbar' === $_GET['context'] // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
194
|
|
|
&& $masterbar_should_logout_from_wpcom |
195
|
|
|
) { |
196
|
|
|
/* |
197
|
|
|
* Get the associated WordPress.com User ID, if the user is connected. |
198
|
|
|
*/ |
199
|
|
|
$connection_manager = new Connection_Manager(); |
200
|
|
|
if ( $connection_manager->is_user_connected( $user->ID ) ) { |
201
|
|
|
$wpcom_user_data = $connection_manager->get_connected_user_data( $user->ID ); |
202
|
|
|
if ( ! empty( $wpcom_user_data['ID'] ) ) { |
203
|
|
|
/** |
204
|
|
|
* Hook into the log out event happening from the Masterbar. |
205
|
|
|
* |
206
|
|
|
* @since 5.1.0 |
207
|
|
|
* @since 7.9.0 Added the $wpcom_user_id parameter to the action. |
208
|
|
|
* |
209
|
|
|
* @module masterbar |
210
|
|
|
* |
211
|
|
|
* @param int $wpcom_user_id WordPress.com User ID. |
212
|
|
|
*/ |
213
|
|
|
do_action( 'wp_masterbar_logout', $wpcom_user_data['ID'] ); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
return $redirect_to; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Adds CSS classes to admin body tag. |
223
|
|
|
* |
224
|
|
|
* @since 5.1 |
225
|
|
|
* |
226
|
|
|
* @param string $admin_body_classes CSS classes that will be added. |
227
|
|
|
* |
228
|
|
|
* @return string |
229
|
|
|
*/ |
230
|
|
|
public function admin_body_class( $admin_body_classes ) { |
231
|
|
|
return "$admin_body_classes jetpack-masterbar"; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Remove the default Admin Bar CSS. |
236
|
|
|
*/ |
237
|
|
|
public function remove_core_styles() { |
238
|
|
|
/* |
239
|
|
|
* Notifications need the admin bar styles, |
240
|
|
|
* so let's not remove them when the module is active. |
241
|
|
|
*/ |
242
|
|
|
if ( ! Jetpack::is_module_active( 'notes' ) ) { |
243
|
|
|
wp_dequeue_style( 'admin-bar' ); |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Check if the user settings are for an RTL language or not. |
249
|
|
|
*/ |
250
|
|
|
public function is_rtl() { |
251
|
|
|
return 'rtl' === $this->user_text_direction ? true : false; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Enqueue our own CSS and JS to display our custom admin bar. |
256
|
|
|
*/ |
257
|
|
|
public function add_styles_and_scripts() { |
258
|
|
|
|
259
|
|
|
if ( $this->is_rtl() ) { |
260
|
|
|
wp_enqueue_style( 'a8c-wpcom-masterbar-rtl', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/rtl/wpcom-admin-bar-rtl.css' ), array(), JETPACK__VERSION ); |
261
|
|
|
wp_enqueue_style( 'a8c-wpcom-masterbar-overrides-rtl', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/rtl/masterbar-rtl.css' ), array(), JETPACK__VERSION ); |
262
|
|
|
} else { |
263
|
|
|
wp_enqueue_style( 'a8c-wpcom-masterbar', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/wpcom-admin-bar.css' ), array(), JETPACK__VERSION ); |
264
|
|
|
wp_enqueue_style( 'a8c-wpcom-masterbar-overrides', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/masterbar.css' ), array(), JETPACK__VERSION ); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
// Local overrides. |
268
|
|
|
wp_enqueue_style( 'a8c_wpcom_css_override', plugins_url( 'overrides.css', __FILE__ ), array(), JETPACK__VERSION ); |
269
|
|
|
|
270
|
|
|
if ( ! Jetpack::is_module_active( 'notes ' ) ) { |
271
|
|
|
// Masterbar is relying on some icons from noticons.css. |
272
|
|
|
wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array(), JETPACK__VERSION . '-' . gmdate( 'oW' ) ); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
wp_enqueue_script( |
276
|
|
|
'jetpack-accessible-focus', |
277
|
|
|
Assets::get_file_url_for_environment( '_inc/build/accessible-focus.min.js', '_inc/accessible-focus.js' ), |
278
|
|
|
array(), |
279
|
|
|
JETPACK__VERSION, |
280
|
|
|
false |
281
|
|
|
); |
282
|
|
|
wp_enqueue_script( |
283
|
|
|
'a8c_wpcom_masterbar_tracks_events', |
284
|
|
|
Assets::get_file_url_for_environment( |
285
|
|
|
'_inc/build/masterbar/tracks-events.min.js', |
286
|
|
|
'modules/masterbar/tracks-events.js' |
287
|
|
|
), |
288
|
|
|
array( 'jquery' ), |
289
|
|
|
JETPACK__VERSION, |
290
|
|
|
false |
291
|
|
|
); |
292
|
|
|
|
293
|
|
|
wp_enqueue_script( |
294
|
|
|
'a8c_wpcom_masterbar_overrides', |
295
|
|
|
$this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/masterbar.js' ), |
296
|
|
|
array( 'jquery' ), |
297
|
|
|
JETPACK__VERSION, |
298
|
|
|
false |
299
|
|
|
); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* Get base URL where our CSS and JS will come from. |
304
|
|
|
* |
305
|
|
|
* @param string $file File path for a static resource. |
306
|
|
|
*/ |
307
|
|
|
private function wpcom_static_url( $file ) { |
308
|
|
|
if ( ! empty( $this->sandbox_url ) ) { |
309
|
|
|
// For testing undeployed changes to remotely enqueued scripts and styles. |
310
|
|
|
return set_url_scheme( $this->sandbox_url . $file, 'https' ); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
$i = hexdec( substr( md5( $file ), - 1 ) ) % 2; |
314
|
|
|
$url = 'https://s' . $i . '.wp.com' . $file; |
315
|
|
|
|
316
|
|
|
return set_url_scheme( $url, 'https' ); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Remove the default admin bar items and replace it with our own admin bar. |
321
|
|
|
*/ |
322
|
|
|
public function replace_core_masterbar() { |
323
|
|
|
global $wp_admin_bar; |
324
|
|
|
|
325
|
|
|
if ( ! is_object( $wp_admin_bar ) ) { |
326
|
|
|
return false; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
$this->clear_core_masterbar( $wp_admin_bar ); |
330
|
|
|
$this->build_wpcom_masterbar( $wp_admin_bar ); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* Remove all existing toolbar entries from core Masterbar |
335
|
|
|
* |
336
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
337
|
|
|
*/ |
338
|
|
|
public function clear_core_masterbar( $wp_admin_bar ) { |
339
|
|
|
foreach ( $wp_admin_bar->get_nodes() as $node ) { |
340
|
|
|
$wp_admin_bar->remove_node( $node->id ); |
341
|
|
|
} |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Add entries corresponding to WordPress.com Masterbar |
346
|
|
|
* |
347
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
348
|
|
|
*/ |
349
|
|
|
public function build_wpcom_masterbar( $wp_admin_bar ) { |
350
|
|
|
// Menu groups. |
351
|
|
|
$this->wpcom_adminbar_add_secondary_groups( $wp_admin_bar ); |
352
|
|
|
|
353
|
|
|
// Left part. |
354
|
|
|
$this->add_my_sites_submenu( $wp_admin_bar ); |
355
|
|
|
$this->add_reader_submenu( $wp_admin_bar ); |
356
|
|
|
|
357
|
|
|
// Right part. |
358
|
|
|
if ( Jetpack::is_module_active( 'notes' ) ) { |
359
|
|
|
$this->add_notifications( $wp_admin_bar ); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
$this->add_me_submenu( $wp_admin_bar ); |
363
|
|
|
$this->add_write_button( $wp_admin_bar ); |
364
|
|
|
|
365
|
|
|
// Recovery mode exit. |
366
|
|
|
if ( function_exists( 'wp_admin_bar_recovery_mode_menu' ) ) { |
367
|
|
|
wp_admin_bar_recovery_mode_menu( $wp_admin_bar ); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
if ( class_exists( 'Automattic\Jetpack\Scan\Admin_Bar_Notice' ) ) { |
371
|
|
|
$scan_admin_bar_notice = Admin_Bar_Notice::instance(); |
372
|
|
|
$scan_admin_bar_notice->add_threats_to_toolbar( $wp_admin_bar ); |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* Get WordPress.com current locale name. |
378
|
|
|
*/ |
379
|
|
|
public function get_locale() { |
380
|
|
|
$wpcom_locale = get_locale(); |
381
|
|
|
|
382
|
|
|
if ( ! class_exists( 'GP_Locales' ) ) { |
383
|
|
|
if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
384
|
|
|
require JETPACK__GLOTPRESS_LOCALES_PATH; |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
|
388
|
|
View Code Duplication |
if ( class_exists( 'GP_Locales' ) ) { |
389
|
|
|
$wpcom_locale_object = GP_Locales::by_field( 'wp_locale', get_locale() ); |
390
|
|
|
if ( $wpcom_locale_object instanceof GP_Locale ) { |
391
|
|
|
$wpcom_locale = $wpcom_locale_object->slug; |
392
|
|
|
} |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return $wpcom_locale; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Add the Notifications menu item. |
400
|
|
|
* |
401
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
402
|
|
|
*/ |
403
|
|
|
public function add_notifications( $wp_admin_bar ) { |
404
|
|
|
$wp_admin_bar->add_node( |
405
|
|
|
array( |
406
|
|
|
'id' => 'notes', |
407
|
|
|
'title' => '<span id="wpnt-notes-unread-count" class="wpnt-loading wpn-read"></span> |
408
|
|
|
<span class="screen-reader-text">' . esc_html__( 'Notifications', 'jetpack' ) . '</span> |
409
|
|
|
<span class="noticon noticon-bell"></span>', |
410
|
|
|
'meta' => array( |
411
|
|
|
'html' => '<div id="wpnt-notes-panel2" style="display:none" lang="' . esc_attr( $this->locale ) . '" dir="' . ( $this->is_rtl() ? 'rtl' : 'ltr' ) . '">' . |
412
|
|
|
'<div class="wpnt-notes-panel-header">' . |
413
|
|
|
'<span class="wpnt-notes-header">' . |
414
|
|
|
esc_html__( 'Notifications', 'jetpack' ) . |
415
|
|
|
'</span>' . |
416
|
|
|
'<span class="wpnt-notes-panel-link">' . |
417
|
|
|
'</span>' . |
418
|
|
|
'</div>' . |
419
|
|
|
'</div>', |
420
|
|
|
'class' => 'menupop mb-trackable', |
421
|
|
|
), |
422
|
|
|
'parent' => 'top-secondary', |
423
|
|
|
) |
424
|
|
|
); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* Add the "Reader" menu item in the root default group. |
429
|
|
|
* |
430
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
431
|
|
|
*/ |
432
|
|
|
public function add_reader_submenu( $wp_admin_bar ) { |
433
|
|
|
$wp_admin_bar->add_menu( |
434
|
|
|
array( |
435
|
|
|
'parent' => 'root-default', |
436
|
|
|
'id' => 'newdash', |
437
|
|
|
'title' => esc_html__( 'Reader', 'jetpack' ), |
438
|
|
|
'href' => '#', |
439
|
|
|
'meta' => array( |
440
|
|
|
'class' => 'mb-trackable', |
441
|
|
|
), |
442
|
|
|
) |
443
|
|
|
); |
444
|
|
|
|
445
|
|
|
$wp_admin_bar->add_menu( |
446
|
|
|
array( |
447
|
|
|
'parent' => 'newdash', |
448
|
|
|
'id' => 'streams-header', |
449
|
|
|
'title' => esc_html_x( |
450
|
|
|
'Streams', |
451
|
|
|
'Title for Reader sub-menu that contains followed sites, likes, and search', |
452
|
|
|
'jetpack' |
453
|
|
|
), |
454
|
|
|
'meta' => array( |
455
|
|
|
'class' => 'ab-submenu-header', |
456
|
|
|
), |
457
|
|
|
) |
458
|
|
|
); |
459
|
|
|
|
460
|
|
|
$following_title = $this->create_menu_item_pair( |
461
|
|
|
array( |
462
|
|
|
'url' => Redirect::get_url( 'calypso-read' ), |
463
|
|
|
'id' => 'wp-admin-bar-followed-sites', |
464
|
|
|
'label' => esc_html__( 'Followed Sites', 'jetpack' ), |
465
|
|
|
), |
466
|
|
|
array( |
467
|
|
|
'url' => Redirect::get_url( 'calypso-following-edit' ), |
468
|
|
|
'id' => 'wp-admin-bar-reader-followed-sites-manage', |
469
|
|
|
'label' => esc_html__( 'Manage', 'jetpack' ), |
470
|
|
|
) |
471
|
|
|
); |
472
|
|
|
|
473
|
|
|
$wp_admin_bar->add_menu( |
474
|
|
|
array( |
475
|
|
|
'parent' => 'newdash', |
476
|
|
|
'id' => 'following', |
477
|
|
|
'title' => $following_title, |
478
|
|
|
'meta' => array( 'class' => 'inline-action' ), |
479
|
|
|
) |
480
|
|
|
); |
481
|
|
|
|
482
|
|
|
$wp_admin_bar->add_menu( |
483
|
|
|
array( |
484
|
|
|
'parent' => 'newdash', |
485
|
|
|
'id' => 'discover-discover', |
486
|
|
|
'title' => esc_html__( 'Discover', 'jetpack' ), |
487
|
|
|
'href' => Redirect::get_url( 'calypso-discover' ), |
488
|
|
|
'meta' => array( |
489
|
|
|
'class' => 'mb-icon-spacer', |
490
|
|
|
), |
491
|
|
|
) |
492
|
|
|
); |
493
|
|
|
|
494
|
|
|
$wp_admin_bar->add_menu( |
495
|
|
|
array( |
496
|
|
|
'parent' => 'newdash', |
497
|
|
|
'id' => 'discover-search', |
498
|
|
|
'title' => esc_html__( 'Search', 'jetpack' ), |
499
|
|
|
'href' => Redirect::get_url( 'calypso-read-search' ), |
500
|
|
|
'meta' => array( |
501
|
|
|
'class' => 'mb-icon-spacer', |
502
|
|
|
), |
503
|
|
|
) |
504
|
|
|
); |
505
|
|
|
|
506
|
|
|
$wp_admin_bar->add_menu( |
507
|
|
|
array( |
508
|
|
|
'parent' => 'newdash', |
509
|
|
|
'id' => 'my-activity-my-likes', |
510
|
|
|
'title' => esc_html__( 'My Likes', 'jetpack' ), |
511
|
|
|
'href' => Redirect::get_url( 'calypso-activities-likes' ), |
512
|
|
|
'meta' => array( |
513
|
|
|
'class' => 'mb-icon-spacer', |
514
|
|
|
), |
515
|
|
|
) |
516
|
|
|
); |
517
|
|
|
|
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* Merge 2 menu items together into 2 link tags. |
522
|
|
|
* |
523
|
|
|
* @param array $primary Array of menu information. |
524
|
|
|
* @param array $secondary Array of menu information. |
525
|
|
|
*/ |
526
|
|
|
public function create_menu_item_pair( $primary, $secondary ) { |
527
|
|
|
$primary_class = 'ab-item ab-primary mb-icon'; |
528
|
|
|
$secondary_class = 'ab-secondary'; |
529
|
|
|
|
530
|
|
|
$primary_anchor = $this->create_menu_item_anchor( $primary_class, $primary['url'], $primary['label'], $primary['id'] ); |
531
|
|
|
$secondary_anchor = $this->create_menu_item_anchor( $secondary_class, $secondary['url'], $secondary['label'], $secondary['id'] ); |
532
|
|
|
|
533
|
|
|
return $primary_anchor . $secondary_anchor; |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/** |
537
|
|
|
* Create a link tag based on information about a menu item. |
538
|
|
|
* |
539
|
|
|
* @param string $class Menu item CSS class. |
540
|
|
|
* @param string $url URL you go to when clicking on the menu item. |
541
|
|
|
* @param string $label Menu item title. |
542
|
|
|
* @param string $id Menu item slug. |
543
|
|
|
*/ |
544
|
|
|
public function create_menu_item_anchor( $class, $url, $label, $id ) { |
545
|
|
|
return '<a href="' . $url . '" class="' . $class . '" id="' . $id . '">' . $label . '</a>'; |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Add Secondary groups for submenu items. |
550
|
|
|
* |
551
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
552
|
|
|
*/ |
553
|
|
|
public function wpcom_adminbar_add_secondary_groups( $wp_admin_bar ) { |
554
|
|
|
$wp_admin_bar->add_group( |
555
|
|
|
array( |
556
|
|
|
'id' => 'root-default', |
557
|
|
|
'meta' => array( |
558
|
|
|
'class' => 'ab-top-menu', |
559
|
|
|
), |
560
|
|
|
) |
561
|
|
|
); |
562
|
|
|
|
563
|
|
|
$wp_admin_bar->add_group( |
564
|
|
|
array( |
565
|
|
|
'parent' => 'blog', |
566
|
|
|
'id' => 'blog-secondary', |
567
|
|
|
'meta' => array( |
568
|
|
|
'class' => 'ab-sub-secondary', |
569
|
|
|
), |
570
|
|
|
) |
571
|
|
|
); |
572
|
|
|
|
573
|
|
|
$wp_admin_bar->add_group( |
574
|
|
|
array( |
575
|
|
|
'id' => 'top-secondary', |
576
|
|
|
'meta' => array( |
577
|
|
|
'class' => 'ab-top-secondary', |
578
|
|
|
), |
579
|
|
|
) |
580
|
|
|
); |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
/** |
584
|
|
|
* Add User info menu item. |
585
|
|
|
* |
586
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
587
|
|
|
*/ |
588
|
|
|
public function add_me_submenu( $wp_admin_bar ) { |
589
|
|
|
$user_id = get_current_user_id(); |
590
|
|
|
if ( empty( $user_id ) ) { |
591
|
|
|
return; |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
$avatar = get_avatar( $this->user_email, 32, 'mm', '', array( 'force_display' => true ) ); |
595
|
|
|
$class = empty( $avatar ) ? 'mb-trackable' : 'with-avatar mb-trackable'; |
596
|
|
|
|
597
|
|
|
// Add the 'Me' menu. |
598
|
|
|
$wp_admin_bar->add_menu( |
599
|
|
|
array( |
600
|
|
|
'id' => 'my-account', |
601
|
|
|
'parent' => 'top-secondary', |
602
|
|
|
'title' => $avatar . '<span class="ab-text">' . esc_html__( 'Me', 'jetpack' ) . '</span>', |
603
|
|
|
'href' => '#', |
604
|
|
|
'meta' => array( |
605
|
|
|
'class' => $class, |
606
|
|
|
), |
607
|
|
|
) |
608
|
|
|
); |
609
|
|
|
|
610
|
|
|
$id = 'user-actions'; |
611
|
|
|
$wp_admin_bar->add_group( |
612
|
|
|
array( |
613
|
|
|
'parent' => 'my-account', |
614
|
|
|
'id' => $id, |
615
|
|
|
) |
616
|
|
|
); |
617
|
|
|
|
618
|
|
|
$settings_url = Redirect::get_url( 'calypso-me-account' ); |
619
|
|
|
|
620
|
|
|
$logout_url = wp_logout_url(); |
621
|
|
|
$logout_url = add_query_arg( 'context', 'masterbar', $logout_url ); |
622
|
|
|
|
623
|
|
|
$user_info = get_avatar( $this->user_email, 128, 'mm', '', array( 'force_display' => true ) ); |
624
|
|
|
$user_info .= '<span class="display-name">' . $this->display_name . '</span>'; |
625
|
|
|
$user_info .= '<a class="username" href="https://gravatar.com/' . $this->user_login . '">@' . $this->user_login . '</a>'; |
626
|
|
|
|
627
|
|
|
$user_info .= sprintf( |
628
|
|
|
'<div><a href="%s" class="ab-sign-out">%s</a></div>', |
629
|
|
|
$logout_url, |
630
|
|
|
esc_html__( 'Sign Out', 'jetpack' ) |
631
|
|
|
); |
632
|
|
|
|
633
|
|
|
$wp_admin_bar->add_menu( |
634
|
|
|
array( |
635
|
|
|
'parent' => $id, |
636
|
|
|
'id' => 'user-info', |
637
|
|
|
'title' => $user_info, |
638
|
|
|
'meta' => array( |
639
|
|
|
'class' => 'user-info user-info-item', |
640
|
|
|
'tabindex' => -1, |
641
|
|
|
), |
642
|
|
|
) |
643
|
|
|
); |
644
|
|
|
|
645
|
|
|
$wp_admin_bar->add_menu( |
646
|
|
|
array( |
647
|
|
|
'parent' => $id, |
648
|
|
|
'id' => 'profile-header', |
649
|
|
|
'title' => esc_html__( 'Profile', 'jetpack' ), |
650
|
|
|
'meta' => array( |
651
|
|
|
'class' => 'ab-submenu-header', |
652
|
|
|
), |
653
|
|
|
) |
654
|
|
|
); |
655
|
|
|
|
656
|
|
|
$wp_admin_bar->add_menu( |
657
|
|
|
array( |
658
|
|
|
'parent' => $id, |
659
|
|
|
'id' => 'my-profile', |
660
|
|
|
'title' => esc_html__( 'My Profile', 'jetpack' ), |
661
|
|
|
'href' => Redirect::get_url( 'calypso-me' ), |
662
|
|
|
'meta' => array( |
663
|
|
|
'class' => 'mb-icon', |
664
|
|
|
), |
665
|
|
|
) |
666
|
|
|
); |
667
|
|
|
|
668
|
|
|
$wp_admin_bar->add_menu( |
669
|
|
|
array( |
670
|
|
|
'parent' => $id, |
671
|
|
|
'id' => 'account-settings', |
672
|
|
|
'title' => esc_html__( 'Account Settings', 'jetpack' ), |
673
|
|
|
'href' => $settings_url, |
674
|
|
|
'meta' => array( |
675
|
|
|
'class' => 'mb-icon', |
676
|
|
|
), |
677
|
|
|
) |
678
|
|
|
); |
679
|
|
|
|
680
|
|
|
$wp_admin_bar->add_menu( |
681
|
|
|
array( |
682
|
|
|
'parent' => $id, |
683
|
|
|
'id' => 'billing', |
684
|
|
|
'title' => esc_html__( 'Manage Purchases', 'jetpack' ), |
685
|
|
|
'href' => Redirect::get_url( 'calypso-me-purchases' ), |
686
|
|
|
'meta' => array( |
687
|
|
|
'class' => 'mb-icon', |
688
|
|
|
), |
689
|
|
|
) |
690
|
|
|
); |
691
|
|
|
|
692
|
|
|
$wp_admin_bar->add_menu( |
693
|
|
|
array( |
694
|
|
|
'parent' => $id, |
695
|
|
|
'id' => 'security', |
696
|
|
|
'title' => esc_html__( 'Security', 'jetpack' ), |
697
|
|
|
'href' => Redirect::get_url( 'calypso-me-security' ), |
698
|
|
|
'meta' => array( |
699
|
|
|
'class' => 'mb-icon', |
700
|
|
|
), |
701
|
|
|
) |
702
|
|
|
); |
703
|
|
|
|
704
|
|
|
$wp_admin_bar->add_menu( |
705
|
|
|
array( |
706
|
|
|
'parent' => $id, |
707
|
|
|
'id' => 'notifications', |
708
|
|
|
'title' => esc_html__( 'Notifications', 'jetpack' ), |
709
|
|
|
'href' => Redirect::get_url( 'calypso-me-notifications' ), |
710
|
|
|
'meta' => array( |
711
|
|
|
'class' => 'mb-icon', |
712
|
|
|
), |
713
|
|
|
) |
714
|
|
|
); |
715
|
|
|
|
716
|
|
|
$wp_admin_bar->add_menu( |
717
|
|
|
array( |
718
|
|
|
'parent' => $id, |
719
|
|
|
'id' => 'special-header', |
720
|
|
|
'title' => esc_html_x( |
721
|
|
|
'Special', |
722
|
|
|
'Title for Me sub-menu that contains Get Apps, Next Steps, and Help options', |
723
|
|
|
'jetpack' |
724
|
|
|
), |
725
|
|
|
'meta' => array( |
726
|
|
|
'class' => 'ab-submenu-header', |
727
|
|
|
), |
728
|
|
|
) |
729
|
|
|
); |
730
|
|
|
|
731
|
|
|
$wp_admin_bar->add_menu( |
732
|
|
|
array( |
733
|
|
|
'parent' => $id, |
734
|
|
|
'id' => 'get-apps', |
735
|
|
|
'title' => esc_html__( 'Get Apps', 'jetpack' ), |
736
|
|
|
'href' => Redirect::get_url( 'calypso-me-get-apps' ), |
737
|
|
|
'meta' => array( |
738
|
|
|
'class' => 'mb-icon user-info-item', |
739
|
|
|
), |
740
|
|
|
) |
741
|
|
|
); |
742
|
|
|
|
743
|
|
|
$help_link = Redirect::get_url( 'jetpack-support' ); |
744
|
|
|
|
745
|
|
|
if ( jetpack_is_atomic_site() ) { |
746
|
|
|
$help_link = Redirect::get_url( 'calypso-help' ); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
$wp_admin_bar->add_menu( |
750
|
|
|
array( |
751
|
|
|
'parent' => $id, |
752
|
|
|
'id' => 'help', |
753
|
|
|
'title' => esc_html__( 'Help', 'jetpack' ), |
754
|
|
|
'href' => $help_link, |
755
|
|
|
'meta' => array( |
756
|
|
|
'class' => 'mb-icon user-info-item', |
757
|
|
|
), |
758
|
|
|
) |
759
|
|
|
); |
760
|
|
|
} |
761
|
|
|
|
762
|
|
|
/** |
763
|
|
|
* Add Write Menu item. |
764
|
|
|
* |
765
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
766
|
|
|
*/ |
767
|
|
|
public function add_write_button( $wp_admin_bar ) { |
768
|
|
|
$current_user = wp_get_current_user(); |
769
|
|
|
|
770
|
|
|
$posting_blog_id = get_current_blog_id(); |
771
|
|
|
if ( ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) { |
772
|
|
|
$posting_blog_id = $current_user->primary_blog; |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
$user_can_post = current_user_can_for_blog( $posting_blog_id, 'publish_posts' ); |
776
|
|
|
|
777
|
|
|
if ( ! $posting_blog_id || ! $user_can_post ) { |
778
|
|
|
return; |
779
|
|
|
} |
780
|
|
|
|
781
|
|
|
$blog_post_page = Redirect::get_url( 'calypso-edit-post' ); |
782
|
|
|
|
783
|
|
|
$wp_admin_bar->add_menu( |
784
|
|
|
array( |
785
|
|
|
'parent' => 'top-secondary', |
786
|
|
|
'id' => 'ab-new-post', |
787
|
|
|
'href' => $blog_post_page, |
788
|
|
|
'title' => '<span>' . esc_html__( 'Write', 'jetpack' ) . '</span>', |
789
|
|
|
'meta' => array( |
790
|
|
|
'class' => 'mb-trackable', |
791
|
|
|
), |
792
|
|
|
) |
793
|
|
|
); |
794
|
|
|
} |
795
|
|
|
|
796
|
|
|
/** |
797
|
|
|
* Add the "My Site" menu item in the root default group. |
798
|
|
|
* |
799
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
800
|
|
|
*/ |
801
|
|
|
public function add_my_sites_submenu( $wp_admin_bar ) { |
802
|
|
|
$current_user = wp_get_current_user(); |
803
|
|
|
|
804
|
|
|
$blog_name = get_bloginfo( 'name' ); |
805
|
|
|
if ( empty( $blog_name ) ) { |
806
|
|
|
$blog_name = $this->primary_site_slug; |
807
|
|
|
} |
808
|
|
|
|
809
|
|
|
if ( mb_strlen( $blog_name ) > 20 ) { |
810
|
|
|
$blog_name = mb_substr( html_entity_decode( $blog_name, ENT_QUOTES ), 0, 20 ) . '…'; |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
$wp_admin_bar->add_menu( |
814
|
|
|
array( |
815
|
|
|
'parent' => 'root-default', |
816
|
|
|
'id' => 'blog', |
817
|
|
|
'title' => _n( 'My Site', 'My Sites', $this->user_site_count, 'jetpack' ), |
818
|
|
|
'href' => '#', |
819
|
|
|
'meta' => array( |
820
|
|
|
'class' => 'my-sites mb-trackable', |
821
|
|
|
), |
822
|
|
|
) |
823
|
|
|
); |
824
|
|
|
|
825
|
|
|
if ( $this->user_site_count > 1 ) { |
826
|
|
|
$wp_admin_bar->add_menu( |
827
|
|
|
array( |
828
|
|
|
'parent' => 'blog', |
829
|
|
|
'id' => 'switch-site', |
830
|
|
|
'title' => esc_html__( 'Switch Site', 'jetpack' ), |
831
|
|
|
'href' => Redirect::get_url( 'calypso-sites' ), |
832
|
|
|
) |
833
|
|
|
); |
834
|
|
|
} else { |
835
|
|
|
$wp_admin_bar->add_menu( |
836
|
|
|
array( |
837
|
|
|
'parent' => 'blog', |
838
|
|
|
'id' => 'new-site', |
839
|
|
|
'title' => esc_html__( '+ Add New WordPress', 'jetpack' ), |
840
|
|
|
'href' => Redirect::get_url( 'calypso-start', array( 'query' => 'ref=admin-bar-logged-in' ) ), |
841
|
|
|
) |
842
|
|
|
); |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
if ( is_user_member_of_blog( $current_user->ID ) ) { |
846
|
|
|
$blavatar = ''; |
847
|
|
|
$class = 'current-site'; |
848
|
|
|
|
849
|
|
|
if ( has_site_icon() ) { |
850
|
|
|
$src = get_site_icon_url(); |
851
|
|
|
$blavatar = '<img class="avatar" src="' . esc_attr( $src ) . '" alt="Current site avatar">'; |
852
|
|
|
$class = 'has-blavatar'; |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
$blog_info = '<div class="ab-site-icon">' . $blavatar . '</div>'; |
856
|
|
|
$blog_info .= '<span class="ab-site-title">' . esc_html( $blog_name ) . '</span>'; |
857
|
|
|
$blog_info .= '<span class="ab-site-description">' . esc_html( $this->primary_site_url ) . '</span>'; |
858
|
|
|
|
859
|
|
|
$wp_admin_bar->add_menu( |
860
|
|
|
array( |
861
|
|
|
'parent' => 'blog', |
862
|
|
|
'id' => 'blog-info', |
863
|
|
|
'title' => $blog_info, |
864
|
|
|
'href' => esc_url( trailingslashit( $this->primary_site_url ) ), |
865
|
|
|
'meta' => array( |
866
|
|
|
'class' => $class, |
867
|
|
|
), |
868
|
|
|
) |
869
|
|
|
); |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
// Site Preview. |
873
|
|
|
if ( is_admin() ) { |
874
|
|
|
$wp_admin_bar->add_menu( |
875
|
|
|
array( |
876
|
|
|
'parent' => 'blog', |
877
|
|
|
'id' => 'site-view', |
878
|
|
|
'title' => __( 'View Site', 'jetpack' ), |
879
|
|
|
'href' => home_url(), |
880
|
|
|
'meta' => array( |
881
|
|
|
'class' => 'mb-icon', |
882
|
|
|
'target' => '_blank', |
883
|
|
|
), |
884
|
|
|
) |
885
|
|
|
); |
886
|
|
|
} |
887
|
|
|
|
888
|
|
|
$this->add_my_home_submenu_item( $wp_admin_bar ); |
889
|
|
|
|
890
|
|
|
// Stats. |
891
|
|
View Code Duplication |
if ( Jetpack::is_module_active( 'stats' ) && current_user_can( 'view_stats' ) ) { |
892
|
|
|
$wp_admin_bar->add_menu( |
893
|
|
|
array( |
894
|
|
|
'parent' => 'blog', |
895
|
|
|
'id' => 'blog-stats', |
896
|
|
|
'title' => esc_html__( 'Stats', 'jetpack' ), |
897
|
|
|
'href' => Redirect::get_url( 'calypso-stats' ), |
898
|
|
|
'meta' => array( |
899
|
|
|
'class' => 'mb-icon', |
900
|
|
|
), |
901
|
|
|
) |
902
|
|
|
); |
903
|
|
|
} |
904
|
|
|
|
905
|
|
|
if ( current_user_can( 'manage_options' ) ) { |
906
|
|
|
$wp_admin_bar->add_menu( |
907
|
|
|
array( |
908
|
|
|
'parent' => 'blog', |
909
|
|
|
'id' => 'activity', |
910
|
|
|
'title' => esc_html__( 'Activity', 'jetpack' ), |
911
|
|
|
'href' => Redirect::get_url( 'calypso-activity-log' ), |
912
|
|
|
'meta' => array( |
913
|
|
|
'class' => 'mb-icon', |
914
|
|
|
), |
915
|
|
|
) |
916
|
|
|
); |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
// Add Calypso plans link and plan type indicator. |
920
|
|
|
if ( is_user_member_of_blog( $current_user->ID ) && current_user_can( 'manage_options' ) ) { |
921
|
|
|
$plans_url = Redirect::get_url( 'calypso-plans' ); |
922
|
|
|
$label = esc_html__( 'Plan', 'jetpack' ); |
923
|
|
|
$plan = Jetpack_Plan::get(); |
924
|
|
|
|
925
|
|
|
$plan_title = $this->create_menu_item_pair( |
926
|
|
|
array( |
927
|
|
|
'url' => $plans_url, |
928
|
|
|
'id' => 'wp-admin-bar-plan', |
929
|
|
|
'label' => $label, |
930
|
|
|
), |
931
|
|
|
array( |
932
|
|
|
'url' => $plans_url, |
933
|
|
|
'id' => 'wp-admin-bar-plan-badge', |
934
|
|
|
'label' => $plan['product_name_short'], |
935
|
|
|
) |
936
|
|
|
); |
937
|
|
|
|
938
|
|
|
$wp_admin_bar->add_menu( |
939
|
|
|
array( |
940
|
|
|
'parent' => 'blog', |
941
|
|
|
'id' => 'plan', |
942
|
|
|
'title' => $plan_title, |
943
|
|
|
'meta' => array( |
944
|
|
|
'class' => 'inline-action', |
945
|
|
|
), |
946
|
|
|
) |
947
|
|
|
); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
// Publish group. |
951
|
|
|
$wp_admin_bar->add_group( |
952
|
|
|
array( |
953
|
|
|
'parent' => 'blog', |
954
|
|
|
'id' => 'publish', |
955
|
|
|
) |
956
|
|
|
); |
957
|
|
|
|
958
|
|
|
// Publish header. |
959
|
|
|
$wp_admin_bar->add_menu( |
960
|
|
|
array( |
961
|
|
|
'parent' => 'publish', |
962
|
|
|
'id' => 'publish-header', |
963
|
|
|
'title' => esc_html_x( 'Manage', 'admin bar menu group label', 'jetpack' ), |
964
|
|
|
'meta' => array( |
965
|
|
|
'class' => 'ab-submenu-header', |
966
|
|
|
), |
967
|
|
|
) |
968
|
|
|
); |
969
|
|
|
|
970
|
|
|
// Pages. |
971
|
|
|
$pages_title = $this->create_menu_item_pair( |
972
|
|
|
array( |
973
|
|
|
'url' => Redirect::get_url( 'calypso-edit-pages' ), |
974
|
|
|
'id' => 'wp-admin-bar-edit-page', |
975
|
|
|
'label' => esc_html__( 'Site Pages', 'jetpack' ), |
976
|
|
|
), |
977
|
|
|
array( |
978
|
|
|
'url' => Redirect::get_url( 'calypso-edit-page' ), |
979
|
|
|
'id' => 'wp-admin-bar-new-page-badge', |
980
|
|
|
'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
981
|
|
|
) |
982
|
|
|
); |
983
|
|
|
|
984
|
|
|
if ( ! current_user_can( 'edit_pages' ) ) { |
985
|
|
|
$pages_title = $this->create_menu_item_anchor( |
986
|
|
|
'ab-item ab-primary mb-icon', |
987
|
|
|
Redirect::get_url( 'calypso-edit-pages' ), |
988
|
|
|
esc_html__( 'Site Pages', 'jetpack' ), |
989
|
|
|
'wp-admin-bar-edit-page' |
990
|
|
|
); |
991
|
|
|
} |
992
|
|
|
|
993
|
|
|
$wp_admin_bar->add_menu( |
994
|
|
|
array( |
995
|
|
|
'parent' => 'publish', |
996
|
|
|
'id' => 'new-page', |
997
|
|
|
'title' => $pages_title, |
998
|
|
|
'meta' => array( |
999
|
|
|
'class' => 'inline-action', |
1000
|
|
|
), |
1001
|
|
|
) |
1002
|
|
|
); |
1003
|
|
|
|
1004
|
|
|
// Blog Posts. |
1005
|
|
|
$posts_title = $this->create_menu_item_pair( |
1006
|
|
|
array( |
1007
|
|
|
'url' => Redirect::get_url( 'calypso-edit-posts' ), |
1008
|
|
|
'id' => 'wp-admin-bar-edit-post', |
1009
|
|
|
'label' => esc_html__( 'Blog Posts', 'jetpack' ), |
1010
|
|
|
), |
1011
|
|
|
array( |
1012
|
|
|
'url' => Redirect::get_url( 'calypso-edit-post' ), |
1013
|
|
|
'id' => 'wp-admin-bar-new-post-badge', |
1014
|
|
|
'label' => esc_html_x( 'Add', 'admin bar menu new item label', 'jetpack' ), |
1015
|
|
|
) |
1016
|
|
|
); |
1017
|
|
|
|
1018
|
|
|
if ( ! current_user_can( 'edit_posts' ) ) { |
1019
|
|
|
$posts_title = $this->create_menu_item_anchor( |
1020
|
|
|
'ab-item ab-primary mb-icon', |
1021
|
|
|
Redirect::get_url( 'calypso-edit-posts' ), |
1022
|
|
|
esc_html__( 'Blog Posts', 'jetpack' ), |
1023
|
|
|
'wp-admin-bar-edit-post' |
1024
|
|
|
); |
1025
|
|
|
} |
1026
|
|
|
|
1027
|
|
|
$wp_admin_bar->add_menu( |
1028
|
|
|
array( |
1029
|
|
|
'parent' => 'publish', |
1030
|
|
|
'id' => 'new-post', |
1031
|
|
|
'title' => $posts_title, |
1032
|
|
|
'meta' => array( |
1033
|
|
|
'class' => 'inline-action mb-trackable', |
1034
|
|
|
), |
1035
|
|
|
) |
1036
|
|
|
); |
1037
|
|
|
|
1038
|
|
|
// Comments. |
1039
|
|
|
if ( current_user_can( 'moderate_comments' ) ) { |
1040
|
|
|
$wp_admin_bar->add_menu( |
1041
|
|
|
array( |
1042
|
|
|
'parent' => 'publish', |
1043
|
|
|
'id' => 'comments', |
1044
|
|
|
'title' => __( 'Comments', 'jetpack' ), |
1045
|
|
|
'href' => Redirect::get_url( 'calypso-comments' ), |
1046
|
|
|
'meta' => array( |
1047
|
|
|
'class' => 'mb-icon', |
1048
|
|
|
), |
1049
|
|
|
) |
1050
|
|
|
); |
1051
|
|
|
} |
1052
|
|
|
|
1053
|
|
|
// Testimonials. |
1054
|
|
View Code Duplication |
if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_testimonial' ) ) { |
1055
|
|
|
$testimonials_title = $this->create_menu_item_pair( |
1056
|
|
|
array( |
1057
|
|
|
'url' => Redirect::get_url( 'calypso-list-jetpack-testimonial' ), |
1058
|
|
|
'id' => 'wp-admin-bar-edit-testimonial', |
1059
|
|
|
'label' => esc_html__( 'Testimonials', 'jetpack' ), |
1060
|
|
|
), |
1061
|
|
|
array( |
1062
|
|
|
'url' => Redirect::get_url( 'calypso-edit-jetpack-testimonial' ), |
1063
|
|
|
'id' => 'wp-admin-bar-new-testimonial', |
1064
|
|
|
'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
1065
|
|
|
) |
1066
|
|
|
); |
1067
|
|
|
|
1068
|
|
|
if ( ! current_user_can( 'edit_pages' ) ) { |
1069
|
|
|
$testimonials_title = $this->create_menu_item_anchor( |
1070
|
|
|
'ab-item ab-primary mb-icon', |
1071
|
|
|
Redirect::get_url( 'calypso-list-jetpack-testimonial' ), |
1072
|
|
|
esc_html__( 'Testimonials', 'jetpack' ), |
1073
|
|
|
'wp-admin-bar-edit-testimonial' |
1074
|
|
|
); |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
$wp_admin_bar->add_menu( |
1078
|
|
|
array( |
1079
|
|
|
'parent' => 'publish', |
1080
|
|
|
'id' => 'new-jetpack-testimonial', |
1081
|
|
|
'title' => $testimonials_title, |
1082
|
|
|
'meta' => array( |
1083
|
|
|
'class' => 'inline-action', |
1084
|
|
|
), |
1085
|
|
|
) |
1086
|
|
|
); |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
// Portfolio. |
1090
|
|
View Code Duplication |
if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_portfolio' ) ) { |
1091
|
|
|
$portfolios_title = $this->create_menu_item_pair( |
1092
|
|
|
array( |
1093
|
|
|
'url' => Redirect::get_url( 'calypso-list-jetpack-portfolio' ), |
1094
|
|
|
'id' => 'wp-admin-bar-edit-portfolio', |
1095
|
|
|
'label' => esc_html__( 'Portfolio', 'jetpack' ), |
1096
|
|
|
), |
1097
|
|
|
array( |
1098
|
|
|
'url' => Redirect::get_url( 'calypso-edit-jetpack-portfolio' ), |
1099
|
|
|
'id' => 'wp-admin-bar-new-portfolio', |
1100
|
|
|
'label' => esc_html_x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ), |
1101
|
|
|
) |
1102
|
|
|
); |
1103
|
|
|
|
1104
|
|
|
if ( ! current_user_can( 'edit_pages' ) ) { |
1105
|
|
|
$portfolios_title = $this->create_menu_item_anchor( |
1106
|
|
|
'ab-item ab-primary mb-icon', |
1107
|
|
|
Redirect::get_url( 'calypso-list-jetpack-portfolio' ), |
1108
|
|
|
esc_html__( 'Portfolio', 'jetpack' ), |
1109
|
|
|
'wp-admin-bar-edit-portfolio' |
1110
|
|
|
); |
1111
|
|
|
} |
1112
|
|
|
|
1113
|
|
|
$wp_admin_bar->add_menu( |
1114
|
|
|
array( |
1115
|
|
|
'parent' => 'publish', |
1116
|
|
|
'id' => 'new-jetpack-portfolio', |
1117
|
|
|
'title' => $portfolios_title, |
1118
|
|
|
'meta' => array( |
1119
|
|
|
'class' => 'inline-action', |
1120
|
|
|
), |
1121
|
|
|
) |
1122
|
|
|
); |
1123
|
|
|
} |
1124
|
|
|
|
1125
|
|
|
if ( current_user_can( 'edit_theme_options' ) ) { |
1126
|
|
|
// Look and Feel group. |
1127
|
|
|
$wp_admin_bar->add_group( |
1128
|
|
|
array( |
1129
|
|
|
'parent' => 'blog', |
1130
|
|
|
'id' => 'look-and-feel', |
1131
|
|
|
) |
1132
|
|
|
); |
1133
|
|
|
|
1134
|
|
|
// Look and Feel header. |
1135
|
|
|
$wp_admin_bar->add_menu( |
1136
|
|
|
array( |
1137
|
|
|
'parent' => 'look-and-feel', |
1138
|
|
|
'id' => 'look-and-feel-header', |
1139
|
|
|
'title' => esc_html_x( 'Personalize', 'admin bar menu group label', 'jetpack' ), |
1140
|
|
|
'meta' => array( |
1141
|
|
|
'class' => 'ab-submenu-header', |
1142
|
|
|
), |
1143
|
|
|
) |
1144
|
|
|
); |
1145
|
|
|
|
1146
|
|
|
if ( is_admin() ) { |
1147
|
|
|
// In wp-admin the `return` query arg will return to that page after closing the Customizer. |
1148
|
|
|
$customizer_url = add_query_arg( |
1149
|
|
|
array( |
1150
|
|
|
'return' => rawurlencode( site_url( $_SERVER['REQUEST_URI'] ) ), |
1151
|
|
|
), |
1152
|
|
|
wp_customize_url() |
1153
|
|
|
); |
1154
|
|
|
} else { |
1155
|
|
|
/* |
1156
|
|
|
* On the frontend the `url` query arg will load that page in the Customizer |
1157
|
|
|
* and also return to it after closing |
1158
|
|
|
* non-home URLs won't work unless we undo domain mapping |
1159
|
|
|
* since the Customizer preview is unmapped to always have HTTPS. |
1160
|
|
|
*/ |
1161
|
|
|
$current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; |
1162
|
|
|
$customizer_url = add_query_arg( array( 'url' => rawurlencode( $current_page ) ), wp_customize_url() ); |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
$theme_title = $this->create_menu_item_pair( |
1166
|
|
|
array( |
1167
|
|
|
'url' => $customizer_url, |
1168
|
|
|
'id' => 'wp-admin-bar-cmz', |
1169
|
|
|
'label' => esc_html_x( 'Customize', 'admin bar customize item label', 'jetpack' ), |
1170
|
|
|
), |
1171
|
|
|
array( |
1172
|
|
|
'url' => Redirect::get_url( 'calypso-themes' ), |
1173
|
|
|
'id' => 'wp-admin-bar-themes', |
1174
|
|
|
'label' => esc_html__( 'Themes', 'jetpack' ), |
1175
|
|
|
) |
1176
|
|
|
); |
1177
|
|
|
$meta = array( |
1178
|
|
|
'class' => 'mb-icon', |
1179
|
|
|
'class' => 'inline-action', |
1180
|
|
|
); |
1181
|
|
|
$href = false; |
1182
|
|
|
|
1183
|
|
|
$wp_admin_bar->add_menu( |
1184
|
|
|
array( |
1185
|
|
|
'parent' => 'look-and-feel', |
1186
|
|
|
'id' => 'themes', |
1187
|
|
|
'title' => $theme_title, |
1188
|
|
|
'href' => $href, |
1189
|
|
|
'meta' => $meta, |
1190
|
|
|
) |
1191
|
|
|
); |
1192
|
|
|
} |
1193
|
|
|
|
1194
|
|
|
if ( current_user_can( 'manage_options' ) ) { |
1195
|
|
|
// Configuration group. |
1196
|
|
|
$wp_admin_bar->add_group( |
1197
|
|
|
array( |
1198
|
|
|
'parent' => 'blog', |
1199
|
|
|
'id' => 'configuration', |
1200
|
|
|
) |
1201
|
|
|
); |
1202
|
|
|
|
1203
|
|
|
// Configuration header. |
1204
|
|
|
$wp_admin_bar->add_menu( |
1205
|
|
|
array( |
1206
|
|
|
'parent' => 'configuration', |
1207
|
|
|
'id' => 'configuration-header', |
1208
|
|
|
'title' => esc_html_x( 'Configure', 'admin bar menu group label', 'jetpack' ), |
1209
|
|
|
'meta' => array( |
1210
|
|
|
'class' => 'ab-submenu-header', |
1211
|
|
|
), |
1212
|
|
|
) |
1213
|
|
|
); |
1214
|
|
|
|
1215
|
|
View Code Duplication |
if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { |
1216
|
|
|
$wp_admin_bar->add_menu( |
1217
|
|
|
array( |
1218
|
|
|
'parent' => 'configuration', |
1219
|
|
|
'id' => 'sharing', |
1220
|
|
|
'title' => esc_html__( 'Sharing', 'jetpack' ), |
1221
|
|
|
'href' => Redirect::get_url( 'calypso-sharing' ), |
1222
|
|
|
'meta' => array( |
1223
|
|
|
'class' => 'mb-icon', |
1224
|
|
|
), |
1225
|
|
|
) |
1226
|
|
|
); |
1227
|
|
|
} |
1228
|
|
|
|
1229
|
|
|
$people_title = $this->create_menu_item_pair( |
1230
|
|
|
array( |
1231
|
|
|
'url' => Redirect::get_url( 'calypso-people-team' ), |
1232
|
|
|
'id' => 'wp-admin-bar-people', |
1233
|
|
|
'label' => esc_html__( 'People', 'jetpack' ), |
1234
|
|
|
), |
1235
|
|
|
array( |
1236
|
|
|
'url' => admin_url( 'user-new.php' ), |
1237
|
|
|
'id' => 'wp-admin-bar-people-add', |
1238
|
|
|
'label' => esc_html_x( 'Add', 'admin bar people item label', 'jetpack' ), |
1239
|
|
|
) |
1240
|
|
|
); |
1241
|
|
|
|
1242
|
|
|
$wp_admin_bar->add_menu( |
1243
|
|
|
array( |
1244
|
|
|
'parent' => 'configuration', |
1245
|
|
|
'id' => 'users-toolbar', |
1246
|
|
|
'title' => $people_title, |
1247
|
|
|
'href' => false, |
1248
|
|
|
'meta' => array( |
1249
|
|
|
'class' => 'inline-action', |
1250
|
|
|
), |
1251
|
|
|
) |
1252
|
|
|
); |
1253
|
|
|
|
1254
|
|
|
$plugins_title = $this->create_menu_item_pair( |
1255
|
|
|
array( |
1256
|
|
|
'url' => Redirect::get_url( 'calypso-plugins' ), |
1257
|
|
|
'id' => 'wp-admin-bar-plugins', |
1258
|
|
|
'label' => esc_html__( 'Plugins', 'jetpack' ), |
1259
|
|
|
), |
1260
|
|
|
array( |
1261
|
|
|
'url' => Redirect::get_url( 'calypso-plugins-manage' ), |
1262
|
|
|
'id' => 'wp-admin-bar-plugins-add', |
1263
|
|
|
'label' => esc_html_x( 'Manage', 'Label for the button on the Masterbar to manage plugins', 'jetpack' ), |
1264
|
|
|
) |
1265
|
|
|
); |
1266
|
|
|
|
1267
|
|
|
$wp_admin_bar->add_menu( |
1268
|
|
|
array( |
1269
|
|
|
'parent' => 'configuration', |
1270
|
|
|
'id' => 'plugins', |
1271
|
|
|
'title' => $plugins_title, |
1272
|
|
|
'href' => false, |
1273
|
|
|
'meta' => array( |
1274
|
|
|
'class' => 'inline-action', |
1275
|
|
|
), |
1276
|
|
|
) |
1277
|
|
|
); |
1278
|
|
|
|
1279
|
|
|
if ( jetpack_is_atomic_site() ) { |
1280
|
|
|
$domain_title = $this->create_menu_item_pair( |
1281
|
|
|
array( |
1282
|
|
|
'url' => Redirect::get_url( 'calypso-domains' ), |
1283
|
|
|
'id' => 'wp-admin-bar-domains', |
1284
|
|
|
'label' => esc_html__( 'Domains', 'jetpack' ), |
1285
|
|
|
), |
1286
|
|
|
array( |
1287
|
|
|
'url' => Redirect::get_url( 'calypso-domains-add' ), |
1288
|
|
|
'id' => 'wp-admin-bar-domains-add', |
1289
|
|
|
'label' => esc_html_x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ), |
1290
|
|
|
) |
1291
|
|
|
); |
1292
|
|
|
$wp_admin_bar->add_menu( |
1293
|
|
|
array( |
1294
|
|
|
'parent' => 'configuration', |
1295
|
|
|
'id' => 'domains', |
1296
|
|
|
'title' => $domain_title, |
1297
|
|
|
'href' => false, |
1298
|
|
|
'meta' => array( |
1299
|
|
|
'class' => 'inline-action', |
1300
|
|
|
), |
1301
|
|
|
) |
1302
|
|
|
); |
1303
|
|
|
} |
1304
|
|
|
|
1305
|
|
|
$wp_admin_bar->add_menu( |
1306
|
|
|
array( |
1307
|
|
|
'parent' => 'configuration', |
1308
|
|
|
'id' => 'blog-settings', |
1309
|
|
|
'title' => esc_html__( 'Settings', 'jetpack' ), |
1310
|
|
|
'href' => Redirect::get_url( 'calypso-settings-general' ), |
1311
|
|
|
'meta' => array( |
1312
|
|
|
'class' => 'mb-icon', |
1313
|
|
|
), |
1314
|
|
|
) |
1315
|
|
|
); |
1316
|
|
|
|
1317
|
|
|
if ( ! is_admin() ) { |
1318
|
|
|
$wp_admin_bar->add_menu( |
1319
|
|
|
array( |
1320
|
|
|
'parent' => 'configuration', |
1321
|
|
|
'id' => 'legacy-dashboard', |
1322
|
|
|
'title' => esc_html__( 'Dashboard', 'jetpack' ), |
1323
|
|
|
'href' => admin_url(), |
1324
|
|
|
'meta' => array( |
1325
|
|
|
'class' => 'mb-icon', |
1326
|
|
|
), |
1327
|
|
|
) |
1328
|
|
|
); |
1329
|
|
|
} |
1330
|
|
|
|
1331
|
|
|
// Restore dashboard menu toggle that is needed on mobile views. |
1332
|
|
|
if ( is_admin() ) { |
1333
|
|
|
$wp_admin_bar->add_menu( |
1334
|
|
|
array( |
1335
|
|
|
'id' => 'menu-toggle', |
1336
|
|
|
'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . esc_html__( 'Menu', 'jetpack' ) . '</span>', |
1337
|
|
|
'href' => '#', |
1338
|
|
|
) |
1339
|
|
|
); |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
/** |
1343
|
|
|
* Fires when menu items are added to the masterbar "My Sites" menu. |
1344
|
|
|
* |
1345
|
|
|
* @since 5.4.0 |
1346
|
|
|
*/ |
1347
|
|
|
do_action( 'jetpack_masterbar' ); |
1348
|
|
|
} |
1349
|
|
|
} |
1350
|
|
|
|
1351
|
|
|
/** |
1352
|
|
|
* Adds "My Home" submenu item to sites that are eligible. |
1353
|
|
|
* |
1354
|
|
|
* @param WP_Admin_Bar $wp_admin_bar Admin Bar instance. |
1355
|
|
|
* @return void |
1356
|
|
|
*/ |
1357
|
|
|
private function add_my_home_submenu_item( &$wp_admin_bar ) { |
1358
|
|
|
if ( ! current_user_can( 'manage_options' ) || ! jetpack_is_atomic_site() ) { |
1359
|
|
|
return; |
1360
|
|
|
} |
1361
|
|
|
|
1362
|
|
|
$wp_admin_bar->add_menu( |
1363
|
|
|
array( |
1364
|
|
|
'parent' => 'blog', |
1365
|
|
|
'id' => 'my-home', |
1366
|
|
|
'title' => __( 'My Home', 'jetpack' ), |
1367
|
|
|
'href' => Redirect::get_url( 'calypso-home' ), |
1368
|
|
|
'meta' => array( |
1369
|
|
|
'class' => 'mb-icon', |
1370
|
|
|
), |
1371
|
|
|
) |
1372
|
|
|
); |
1373
|
|
|
} |
1374
|
|
|
} |
1375
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: