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