A8C_WPCOM_Masterbar

The WordPress Core A8C WPCOM Masterbar class.

Defined (1)

The class is defined in the following location(s).

/modules/masterbar/masterbar.php  
  1. class A8C_WPCOM_Masterbar { 
  2. /** 
  3. * Use for testing changes made to remotely enqueued scripts and styles on your sandbox. 
  4. * If not set it will default to loading the ones from WordPress.com. 
  5. * @var string $sandbox_url 
  6. */ 
  7. private $sandbox_url = ''; 
  8.  
  9. private $locale; 
  10.  
  11. private $user_id; 
  12. private $user_data; 
  13. private $user_login; 
  14. private $user_email; 
  15. private $display_name; 
  16. private $primary_site_slug; 
  17. private $user_text_direction; 
  18. private $user_site_count; 
  19.  
  20. function __construct() { 
  21. $this->locale = $this->get_locale(); 
  22. $this->user_id = get_current_user_id(); 
  23.  
  24. // Limit the masterbar to be shown only to connected Jetpack users. 
  25. if ( ! Jetpack::is_user_connected( $this->user_id ) ) { 
  26. return; 
  27.  
  28. $this->user_data = Jetpack::get_connected_user_data( $this->user_id ); 
  29. $this->user_login = $this->user_data['login']; 
  30. $this->user_email = $this->user_data['email']; 
  31. $this->display_name = $this->user_data['display_name']; 
  32. $this->user_site_count = $this->user_data['site_count']; 
  33.  
  34. // Used to build menu links that point directly to Calypso. 
  35. $this->primary_site_slug = Jetpack::build_raw_urls( get_home_url() ); 
  36.  
  37. // Used for display purposes and for building WP Admin links. 
  38. $this->primary_site_url = str_replace( '::', '/', $this->primary_site_slug ); 
  39.  
  40. // We need to use user's setting here, instead of relying on current blog's text direction 
  41. $this->user_text_direction = $this->user_data['text_direction']; 
  42.  
  43. if ( $this->is_rtl() ) { 
  44. // Extend core WP_Admin_Bar class in order to add rtl styles 
  45. add_filter( 'wp_admin_bar_class', array( $this, 'get_rtl_admin_bar_class' ) ); 
  46.  
  47. add_action( 'wp_before_admin_bar_render', array( $this, 'replace_core_masterbar' ), 99999 ); 
  48.  
  49. add_action( 'wp_enqueue_scripts', array( $this, 'add_styles_and_scripts' ) ); 
  50. add_action( 'admin_enqueue_scripts', array( $this, 'add_styles_and_scripts' ) ); 
  51.  
  52. add_action( 'wp_enqueue_scripts', array( $this, 'remove_core_styles' ) ); 
  53. add_action( 'admin_enqueue_scripts', array( $this, 'remove_core_styles' ) ); 
  54.  
  55. if ( Jetpack::is_module_active( 'notes' ) && $this->is_rtl() ) { 
  56. // Override Notification module to include RTL styles 
  57. add_action( 'a8c_wpcom_masterbar_enqueue_rtl_notification_styles', '__return_true' ); 
  58.  
  59. add_action( 'wp_logout', array( $this, 'maybe_logout_user_from_wpcom' ) ); 
  60.  
  61. public function is_automated_transfer_site() { 
  62. return jetpack_is_automated_transfer_site(); 
  63.  
  64. public function maybe_logout_user_from_wpcom() { 
  65. if ( isset( $_GET['context'] ) && 'masterbar' === $_GET['context'] ) { 
  66. do_action( 'wp_masterbar_logout' ); 
  67.  
  68. public function get_rtl_admin_bar_class() { 
  69. return 'RTL_Admin_Bar'; 
  70.  
  71. public function remove_core_styles() { 
  72. wp_dequeue_style( 'admin-bar' ); 
  73.  
  74. public function is_rtl() { 
  75. return $this->user_text_direction === 'rtl' ? true : false; 
  76.  
  77. public function add_styles_and_scripts() { 
  78.  
  79. if ( $this->is_rtl() ) { 
  80. wp_enqueue_style( 'a8c-wpcom-masterbar-rtl', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/rtl/wpcom-admin-bar-rtl.css' ) ); 
  81. wp_enqueue_style( 'a8c-wpcom-masterbar-overrides-rtl', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/rtl/masterbar-rtl.css' ) ); 
  82. } else { 
  83. wp_enqueue_style( 'a8c-wpcom-masterbar', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/wpcom-admin-bar.css' ) ); 
  84. wp_enqueue_style( 'a8c-wpcom-masterbar-overrides', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/masterbar.css' ) ); 
  85.  
  86. // Local overrides 
  87. wp_enqueue_style( 'a8c_wpcom_css_override', plugins_url( 'overrides.css', __FILE__ ) ); 
  88.  
  89. if ( ! Jetpack::is_module_active( 'notes ' ) ) { 
  90. // Masterbar is relying on some icons from noticons.css 
  91. wp_enqueue_style( 'noticons', $this->wpcom_static_url( '/i/noticons/noticons.css' ), array(), JETPACK__VERSION . '-' . gmdate( 'oW' ) ); 
  92.  
  93. wp_enqueue_script( 'jetpack-accessible-focus', plugins_url( '_inc/accessible-focus.js', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION ); 
  94. wp_enqueue_script( 'a8c_wpcom_masterbar_overrides', $this->wpcom_static_url( '/wp-content/mu-plugins/admin-bar/masterbar-overrides/masterbar.js' ) ); 
  95.  
  96. function wpcom_static_url( $file ) { 
  97. if ( ! empty( $this->sandbox_url ) ) { 
  98. // For testing undeployed changes to remotely enqueued scripts and styles. 
  99. return set_url_scheme( $this->sandbox_url . $file, 'https'); 
  100.  
  101. $i = hexdec( substr( md5( $file ), - 1 ) ) % 2; 
  102. $url = 'https://s' . $i . '.wp.com' . $file; 
  103.  
  104. return set_url_scheme( $url, 'https'); 
  105.  
  106. public function replace_core_masterbar() { 
  107. global $wp_admin_bar; 
  108.  
  109. if ( ! is_object( $wp_admin_bar ) ) { 
  110. return false; 
  111.  
  112. $this->clear_core_masterbar( $wp_admin_bar ); 
  113. $this->build_wpcom_masterbar( $wp_admin_bar ); 
  114.  
  115. // Remove all existing toolbar entries from core Masterbar 
  116. public function clear_core_masterbar( $wp_admin_bar ) { 
  117. foreach ( $wp_admin_bar->get_nodes() as $node ) { 
  118. $wp_admin_bar->remove_node( $node->id ); 
  119.  
  120. // Add entries corresponding to WordPress.com Masterbar 
  121. public function build_wpcom_masterbar( $wp_admin_bar ) { 
  122. // Menu groups 
  123. $this->wpcom_adminbar_add_secondary_groups( $wp_admin_bar ); 
  124.  
  125. // Left part 
  126. $this->add_my_sites_submenu( $wp_admin_bar ); 
  127. $this->add_reader_submenu( $wp_admin_bar ); 
  128.  
  129. // Right part 
  130. if ( Jetpack::is_module_active( 'notes' ) ) { 
  131. $this->add_notifications( $wp_admin_bar ); 
  132.  
  133. $this->add_me_submenu( $wp_admin_bar ); 
  134. $this->add_write_button( $wp_admin_bar ); 
  135.  
  136. public function get_locale() { 
  137. $wpcom_locale = get_locale(); 
  138.  
  139. if ( ! class_exists( 'GP_Locales' ) ) { 
  140. if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { 
  141. require JETPACK__GLOTPRESS_LOCALES_PATH; 
  142.  
  143. if ( class_exists( 'GP_Locales' ) ) { 
  144. $wpcom_locale_object = GP_Locales::by_field( 'wp_locale', get_locale() ); 
  145. if ( $wpcom_locale_object instanceof GP_Locale ) { 
  146. $wpcom_locale = $wpcom_locale_object->slug; 
  147.  
  148. return $wpcom_locale; 
  149.  
  150. public function add_notifications( $wp_admin_bar ) { 
  151. $wp_admin_bar->add_node( array( 
  152. 'id' => 'notes',  
  153. 'title' => '<span id="wpnt-notes-unread-count" class="wpnt-loading wpn-read"></span> 
  154. <span class="screen-reader-text">' . __( 'Notifications', 'jetpack' ) . '</span> 
  155. <span class="noticon noticon-bell"></span>',  
  156. 'meta' => array( 
  157. 'html' => '<div id="wpnt-notes-panel2" style="display:none" lang="'. esc_attr( $this->locale ) . '" dir="' . ( $this->is_rtl() ? 'rtl' : 'ltr' ) . '">' . 
  158. '<div class="wpnt-notes-panel-header">' . 
  159. '<span class="wpnt-notes-header">' . 
  160. __( 'Notifications', 'jetpack' ) . 
  161. '</span>' . 
  162. '<span class="wpnt-notes-panel-link">' . 
  163. '</span>' . 
  164. '</div>' . 
  165. '</div>',  
  166. 'class' => 'menupop',  
  167. ),  
  168. 'parent' => 'top-secondary',  
  169. ) ); 
  170.  
  171. public function add_reader_submenu( $wp_admin_bar ) { 
  172. $wp_admin_bar->add_menu( array( 
  173. 'parent' => 'root-default',  
  174. 'id' => 'newdash',  
  175. 'title' => __( 'Reader', 'jetpack' ),  
  176. 'href' => '#',  
  177. ) ); 
  178.  
  179. $wp_admin_bar->add_menu( array( 
  180. 'parent' => 'newdash',  
  181. 'id' => 'streams-header',  
  182. 'title' => _x( 
  183. 'Streams',  
  184. 'Title for Reader sub-menu that contains followed sites, likes, and recommendations',  
  185. 'jetpack' 
  186. ),  
  187. 'meta' => array( 
  188. 'class' => 'ab-submenu-header',  
  189. ) ); 
  190.  
  191. $following_title = $this->create_menu_item_pair( 
  192. array( 
  193. 'url' => 'https://wordpress.com/',  
  194. 'id' => 'wp-admin-bar-followed-sites',  
  195. 'label' => __( 'Followed Sites', 'jetpack' ),  
  196. ),  
  197. array( 
  198. 'url' => 'https://wordpress.com/following/edit',  
  199. 'id' => 'wp-admin-bar-reader-followed-sites-manage',  
  200. 'label' => __( 'Manage', 'jetpack' ),  
  201. ); 
  202.  
  203. $wp_admin_bar->add_menu( array( 
  204. 'parent' => 'newdash',  
  205. 'id' => 'following',  
  206. 'title' => $following_title,  
  207. 'meta' => array( 'class' => 'inline-action' ) 
  208. ) ); 
  209.  
  210. $wp_admin_bar->add_menu( array( 
  211. 'parent' => 'newdash',  
  212. 'id' => 'discover-discover',  
  213. 'title' => __( 'Discover', 'jetpack' ),  
  214. 'href' => 'https://wordpress.com/discover',  
  215. 'meta' => array( 
  216. 'class' => 'mb-icon-spacer',  
  217. ) ); 
  218.  
  219. $wp_admin_bar->add_menu( array( 
  220. 'parent' => 'newdash',  
  221. 'id' => 'discover-search',  
  222. 'title' => __( 'Search', 'jetpack' ),  
  223. 'href' => 'https://wordpress.com/read/search',  
  224. 'meta' => array( 
  225. 'class' => 'mb-icon-spacer',  
  226. ) ); 
  227.  
  228. $wp_admin_bar->add_menu( array( 
  229. 'parent' => 'newdash',  
  230. 'id' => 'discover-recommended-blogs',  
  231. 'title' => __( 'Recommendations', 'jetpack' ),  
  232. 'href' => 'https://wordpress.com/recommendations',  
  233. 'meta' => array( 
  234. 'class' => 'mb-icon-spacer',  
  235. ) ); 
  236.  
  237. $wp_admin_bar->add_menu( array( 
  238. 'parent' => 'newdash',  
  239. 'id' => 'my-activity-my-likes',  
  240. 'title' => __( 'My Likes', 'jetpack' ),  
  241. 'href' => 'https://wordpress.com/activities/likes',  
  242. 'meta' => array( 
  243. 'class' => 'mb-icon-spacer',  
  244. ) ); 
  245.  
  246.  
  247. public function create_menu_item_pair( $primary, $secondary ) { 
  248. $primary_class = 'ab-item ab-primary mb-icon'; 
  249. $secondary_class = 'ab-secondary'; 
  250.  
  251. $primary_anchor = $this->create_menu_item_anchor( $primary_class, $primary['url'], $primary['label'], $primary['id'] ); 
  252. $secondary_anchor = $this->create_menu_item_anchor( $secondary_class, $secondary['url'], $secondary['label'], $secondary['id'] ); 
  253.  
  254. return $primary_anchor . $secondary_anchor; 
  255.  
  256. public function create_menu_item_anchor( $class, $url, $label, $id ) { 
  257. return '<a href="' . $url . '" class="' . $class . '" id="' . $id . '">' . $label . '</a>'; 
  258.  
  259. public function wpcom_adminbar_add_secondary_groups( $wp_admin_bar ) { 
  260. $wp_admin_bar->add_group( array( 
  261. 'id' => 'root-default',  
  262. 'meta' => array( 
  263. 'class' => 'ab-top-menu',  
  264. ),  
  265. ) ); 
  266.  
  267. $wp_admin_bar->add_group( array( 
  268. 'parent' => 'blog',  
  269. 'id' => 'blog-secondary',  
  270. 'meta' => array( 
  271. 'class' => 'ab-sub-secondary',  
  272. ),  
  273. ) ); 
  274.  
  275. $wp_admin_bar->add_group( array( 
  276. 'id' => 'top-secondary',  
  277. 'meta' => array( 
  278. 'class' => 'ab-top-secondary',  
  279. ),  
  280. ) ); 
  281.  
  282. public function add_me_submenu( $wp_admin_bar ) { 
  283. $user_id = get_current_user_id(); 
  284. if ( empty( $user_id ) ) { 
  285. return; 
  286.  
  287. $avatar = get_avatar( $this->user_email, 32, 'mm', '', array( 'force_display' => true ) ); 
  288. $class = empty( $avatar ) ? '' : 'with-avatar'; 
  289.  
  290. // Add the 'Me' menu 
  291. $wp_admin_bar->add_menu( array( 
  292. 'id' => 'my-account',  
  293. 'parent' => 'top-secondary',  
  294. 'title' => $avatar . '<span class="ab-text">' . __( 'Me', 'jetpack' ) . '</span>',  
  295. 'href' => '#',  
  296. 'meta' => array( 
  297. 'class' => $class,  
  298. ),  
  299. ) ); 
  300.  
  301. $id = 'user-actions'; 
  302. $wp_admin_bar->add_group( array( 
  303. 'parent' => 'my-account',  
  304. 'id' => $id,  
  305. ) ); 
  306.  
  307. $settings_url = 'https://wordpress.com/me/account'; 
  308.  
  309. $logout_url = wp_logout_url(); 
  310. $logout_url = add_query_arg( 'context', 'masterbar', $logout_url ); 
  311.  
  312. $user_info = get_avatar( $this->user_email, 128, 'mm', '', array( 'force_display' => true ) ); 
  313. $user_info .= '<span class="display-name">' . $this->display_name . '</span>'; 
  314. $user_info .= '<a class="username" href="http://gravatar.com/' . $this->user_login . '">@' . $this->user_login . '</a>'; 
  315. $user_info .= '<form action="' . $logout_url . '" method="post"><button class="ab-sign-out" type="submit">' . __( 'Sign Out', 'jetpack' ) . '</button></form>'; 
  316.  
  317. $wp_admin_bar->add_menu( array( 
  318. 'parent' => $id,  
  319. 'id' => 'user-info',  
  320. 'title' => $user_info,  
  321. 'meta' => array( 
  322. 'class' => 'user-info user-info-item',  
  323. 'tabindex' => -1,  
  324. ),  
  325. ) ); 
  326.  
  327. $wp_admin_bar->add_menu( array( 
  328. 'parent' => $id,  
  329. 'id' => 'profile-header',  
  330. 'title' => __( 'Profile', 'jetpack' ),  
  331. 'meta' => array( 
  332. 'class' => 'ab-submenu-header',  
  333. ),  
  334. ) ); 
  335.  
  336. $wp_admin_bar->add_menu( array( 
  337. 'parent' => $id,  
  338. 'id' => 'my-profile',  
  339. 'title' => __( 'My Profile', 'jetpack' ),  
  340. 'href' => 'https://wordpress.com/me',  
  341. 'meta' => array( 
  342. 'class' => 'mb-icon',  
  343. ),  
  344. ) ); 
  345.  
  346. $wp_admin_bar->add_menu( array( 
  347. 'parent' => $id,  
  348. 'id' => 'account-settings',  
  349. 'title' => __( 'Account Settings', 'jetpack' ),  
  350. 'href' => $settings_url,  
  351. 'meta' => array( 
  352. 'class' => 'mb-icon',  
  353. ),  
  354. ) ); 
  355.  
  356. $wp_admin_bar->add_menu( array( 
  357. 'parent' => $id,  
  358. 'id' => 'billing',  
  359. 'title' => __( 'Manage Purchases', 'jetpack' ),  
  360. 'href' => 'https://wordpress.com/me/purchases',  
  361. 'meta' => array( 
  362. 'class' => 'mb-icon',  
  363. ),  
  364. ) ); 
  365.  
  366. $wp_admin_bar->add_menu( array( 
  367. 'parent' => $id,  
  368. 'id' => 'security',  
  369. 'title' => __( 'Security', 'jetpack' ),  
  370. 'href' => 'https://wordpress.com/me/security',  
  371. 'meta' => array( 
  372. 'class' => 'mb-icon',  
  373. ),  
  374. ) ); 
  375.  
  376. $wp_admin_bar->add_menu( array( 
  377. 'parent' => $id,  
  378. 'id' => 'notifications',  
  379. 'title' => __( 'Notifications', 'jetpack' ),  
  380. 'href' => 'https://wordpress.com/me/notifications',  
  381. 'meta' => array( 
  382. 'class' => 'mb-icon',  
  383. ),  
  384. ) ); 
  385.  
  386. $wp_admin_bar->add_menu( array( 
  387. 'parent' => $id,  
  388. 'id' => 'special-header',  
  389. 'title' => _x( 
  390. 'Special',  
  391. 'Title for Me sub-menu that contains Get Apps, Next Steps, and Help options',  
  392. 'jetpack' 
  393. ),  
  394. 'meta' => array( 
  395. 'class' => 'ab-submenu-header',  
  396. ),  
  397. ) ); 
  398.  
  399. $wp_admin_bar->add_menu( array( 
  400. 'parent' => $id,  
  401. 'id' => 'get-apps',  
  402. 'title' => __( 'Get Apps', 'jetpack' ),  
  403. 'href' => 'https://wordpress.com/me/get-apps',  
  404. 'meta' => array( 
  405. 'class' => 'mb-icon user-info-item',  
  406. ),  
  407. ) ); 
  408.  
  409. $wp_admin_bar->add_menu( array( 
  410. 'parent' => $id,  
  411. 'id' => 'next-steps',  
  412. 'title' => __( 'Next Steps', 'jetpack' ),  
  413. 'href' => 'https://wordpress.com/me/next',  
  414. 'meta' => array( 
  415. 'class' => 'mb-icon user-info-item',  
  416. ),  
  417. ) ); 
  418.  
  419. $help_link = 'https://jetpack.com/support/'; 
  420.  
  421. if ( $this->is_automated_transfer_site() ) { 
  422. $help_link = 'https://wordpress.com/help'; 
  423.  
  424. $wp_admin_bar->add_menu( array( 
  425. 'parent' => $id,  
  426. 'id' => 'help',  
  427. 'title' => __( 'Help', 'jetpack' ),  
  428. 'href' => $help_link,  
  429. 'meta' => array( 
  430. 'class' => 'mb-icon user-info-item',  
  431. ),  
  432. ) ); 
  433.  
  434. public function add_write_button( $wp_admin_bar ) { 
  435. $current_user = wp_get_current_user(); 
  436.  
  437. $posting_blog_id = get_current_blog_id(); 
  438. if ( ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) { 
  439. $posting_blog_id = $current_user->primary_blog; 
  440.  
  441. $user_can_post = current_user_can_for_blog( $posting_blog_id, 'publish_posts' ); 
  442.  
  443. if ( ! $posting_blog_id || ! $user_can_post ) { 
  444. return; 
  445.  
  446. $blog_post_page = 'https://wordpress.com/post/' . esc_attr( $this->primary_site_slug ); 
  447.  
  448. $wp_admin_bar->add_menu( array( 
  449. 'parent' => 'top-secondary',  
  450. 'id' => 'ab-new-post',  
  451. 'href' => $blog_post_page,  
  452. 'title' => '<span>' . __( 'Write', 'jetpack' ) . '</span>',  
  453. ) ); 
  454.  
  455. public function add_my_sites_submenu( $wp_admin_bar ) { 
  456. $current_user = wp_get_current_user(); 
  457.  
  458. $blog_name = get_bloginfo( 'name' ); 
  459. if ( empty( $blog_name ) ) { 
  460. $blog_name = $this->primary_site_slug; 
  461.  
  462. if ( mb_strlen( $blog_name ) > 20 ) { 
  463. $blog_name = mb_substr( html_entity_decode( $blog_name, ENT_QUOTES ), 0, 20 ) . '…'; 
  464.  
  465. $wp_admin_bar->add_menu( array( 
  466. 'parent' => 'root-default',  
  467. 'id' => 'blog',  
  468. 'title' => _n( 'My Site', 'My Sites', $this->user_site_count, 'jetpack' ),  
  469. 'href' => '#',  
  470. 'meta' => array( 
  471. 'class' => 'my-sites',  
  472. ),  
  473. ) ); 
  474.  
  475. if ( $this->user_site_count > 1 ) { 
  476. $wp_admin_bar->add_menu( array( 
  477. 'parent' => 'blog',  
  478. 'id' => 'switch-site',  
  479. 'title' => __( 'Switch Site', 'jetpack' ),  
  480. 'href' => 'https://wordpress.com/sites',  
  481. ) ); 
  482. } else { 
  483. $wp_admin_bar->add_menu( array( 
  484. 'parent' => 'blog',  
  485. 'id' => 'new-site',  
  486. 'title' => __( '+ Add New WordPress', 'jetpack' ),  
  487. 'href' => 'https://wordpress.com/start?ref=admin-bar-logged-in',  
  488. ) ); 
  489.  
  490. if ( is_user_member_of_blog( $current_user->ID ) ) { 
  491. $blavatar = ''; 
  492. $class = 'current-site'; 
  493.  
  494. if ( has_site_icon() ) { 
  495. $src = get_site_icon_url(); 
  496. $blavatar = '<img class="avatar" src="'. esc_attr( $src ) . '" alt="Current site avatar">'; 
  497. $class = 'has-blavatar'; 
  498.  
  499. $blog_info = '<div class="ab-site-icon">' . $blavatar . '</div>'; 
  500. $blog_info .= '<span class="ab-site-title">' . esc_html( $blog_name ) . '</span>'; 
  501. $blog_info .= '<span class="ab-site-description">' . esc_html( $this->primary_site_url ) . '</span>'; 
  502.  
  503. $wp_admin_bar->add_menu( array( 
  504. 'parent' => 'blog',  
  505. 'id' => 'blog-info',  
  506. 'title' => $blog_info,  
  507. 'href' => esc_url( trailingslashit( $this->primary_site_url ) ),  
  508. 'meta' => array( 
  509. 'class' => $class,  
  510. ),  
  511. ) ); 
  512.  
  513. // Stats 
  514. if ( Jetpack::is_module_active( 'stats' ) ) { 
  515. $wp_admin_bar->add_menu( array( 
  516. 'parent' => 'blog',  
  517. 'id' => 'blog-stats',  
  518. 'title' => __( 'Stats', 'jetpack' ),  
  519. 'href' => 'https://wordpress.com/stats/' . esc_attr( $this->primary_site_slug ),  
  520. 'meta' => array( 
  521. 'class' => 'mb-icon',  
  522. ),  
  523. ) ); 
  524.  
  525. // Add Calypso plans link and plan type indicator 
  526. if ( is_user_member_of_blog( $current_user->ID ) ) { 
  527. $plans_url = 'https://wordpress.com/plans/' . esc_attr( $this->primary_site_slug ); 
  528. $label = __( 'Plan', 'jetpack' ); 
  529. $plan = Jetpack::get_active_plan(); 
  530.  
  531. $plan_title = $this->create_menu_item_pair( 
  532. array( 
  533. 'url' => $plans_url,  
  534. 'id' => 'wp-admin-bar-plan',  
  535. 'label' => $label,  
  536. ),  
  537. array( 
  538. 'url' => $plans_url,  
  539. 'id' => 'wp-admin-bar-plan-badge',  
  540. 'label' => $plan['product_name_short'] 
  541. ); 
  542.  
  543. $wp_admin_bar->add_menu( array( 
  544. 'parent' => 'blog',  
  545. 'id' => 'plan',  
  546. 'title' => $plan_title,  
  547. 'meta' => array( 
  548. 'class' => 'inline-action',  
  549. ),  
  550. ) ); 
  551.  
  552. // Publish group 
  553. $wp_admin_bar->add_group( array( 
  554. 'parent' => 'blog',  
  555. 'id' => 'publish',  
  556. ) ); 
  557.  
  558. // Publish header 
  559. $wp_admin_bar->add_menu( array( 
  560. 'parent' => 'publish',  
  561. 'id' => 'publish-header',  
  562. 'title' => _x( 'Publish', 'admin bar menu group label', 'jetpack' ),  
  563. 'meta' => array( 
  564. 'class' => 'ab-submenu-header',  
  565. ),  
  566. ) ); 
  567.  
  568. // Blog Posts 
  569. $posts_title = $this->create_menu_item_pair( 
  570. array( 
  571. 'url' => 'https://wordpress.com/posts/' . esc_attr( $this->primary_site_slug ),  
  572. 'id' => 'wp-admin-bar-edit-post',  
  573. 'label' => __( 'Blog Posts', 'jetpack' ),  
  574. ),  
  575. array( 
  576. 'url' => 'https://wordpress.com/post/' . esc_attr( $this->primary_site_slug ),  
  577. 'id' => 'wp-admin-bar-new-post',  
  578. 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ),  
  579. ); 
  580.  
  581. if ( ! current_user_can( 'edit_posts' ) ) { 
  582. $posts_title = $this->create_menu_item_anchor( 
  583. 'ab-item ab-primary mb-icon',  
  584. 'https://wordpress.com/posts/' . esc_attr( $this->primary_site_slug ),  
  585. __( 'Blog Posts', 'jetpack' ),  
  586. 'wp-admin-bar-edit-post' 
  587. ); 
  588.  
  589. $wp_admin_bar->add_menu( array( 
  590. 'parent' => 'publish',  
  591. 'id' => 'new-post',  
  592. 'title' => $posts_title,  
  593. 'meta' => array( 
  594. 'class' => 'inline-action',  
  595. ),  
  596. ) ); 
  597.  
  598. // Pages 
  599. $pages_title = $this->create_menu_item_pair( 
  600. array( 
  601. 'url' => 'https://wordpress.com/pages/' . esc_attr( $this->primary_site_slug ),  
  602. 'id' => 'wp-admin-bar-edit-page',  
  603. 'label' => __( 'Pages', 'jetpack' ),  
  604. ),  
  605. array( 
  606. 'url' => 'https://wordpress.com/page/' . esc_attr( $this->primary_site_slug ),  
  607. 'id' => 'wp-admin-bar-new-page',  
  608. 'label' => _x( 'Add', 'admin bar menu new item label', 'jetpack' ),  
  609. ); 
  610.  
  611. if ( ! current_user_can( 'edit_pages' ) ) { 
  612. $pages_title = $this->create_menu_item_anchor( 
  613. 'ab-item ab-primary mb-icon',  
  614. 'https://wordpress.com/pages/' . esc_attr( $this->primary_site_slug ),  
  615. __( 'Pages', 'jetpack' ),  
  616. 'wp-admin-bar-edit-page' 
  617. ); 
  618.  
  619. $wp_admin_bar->add_menu( array( 
  620. 'parent' => 'publish',  
  621. 'id' => 'new-page',  
  622. 'title' => $pages_title,  
  623. 'meta' => array( 
  624. 'class' => 'inline-action',  
  625. ),  
  626. ) ); 
  627.  
  628. // Testimonials 
  629. if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_testimonial' ) ) { 
  630. $testimonials_title = $this->create_menu_item_pair( 
  631. array( 
  632. 'url' => 'https://wordpress.com/types/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ),  
  633. 'id' => 'wp-admin-bar-edit-testimonial',  
  634. 'label' => __( 'Testimonials', 'jetpack' ),  
  635. ),  
  636. array( 
  637. 'url' => 'https://wordpress.com/edit/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ),  
  638. 'id' => 'wp-admin-bar-new-testimonial',  
  639. 'label' => _x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ),  
  640. ); 
  641.  
  642. if ( ! current_user_can( 'edit_pages' ) ) { 
  643. $testimonials_title = $this->create_menu_item_anchor( 
  644. 'ab-item ab-primary mb-icon',  
  645. 'https://wordpress.com/types/jetpack-testimonial/' . esc_attr( $this->primary_site_slug ),  
  646. __( 'Testimonials', 'jetpack' ),  
  647. 'wp-admin-bar-edit-testimonial' 
  648. ); 
  649.  
  650. $wp_admin_bar->add_menu( array( 
  651. 'parent' => 'publish',  
  652. 'id' => 'new-jetpack-testimonial',  
  653. 'title' => $testimonials_title,  
  654. 'meta' => array( 
  655. 'class' => 'inline-action',  
  656. ),  
  657. ) ); 
  658.  
  659. // Portfolio 
  660. if ( Jetpack::is_module_active( 'custom-content-types' ) && get_option( 'jetpack_portfolio' ) ) { 
  661. $portfolios_title = $this->create_menu_item_pair( 
  662. array( 
  663. 'url' => 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ),  
  664. 'id' => 'wp-admin-bar-edit-portfolio',  
  665. 'label' => __( 'Portfolio', 'jetpack' ),  
  666. ),  
  667. array( 
  668. 'url' => 'https://wordpress.com/edit/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ),  
  669. 'id' => 'wp-admin-bar-new-portfolio',  
  670. 'label' => _x( 'Add', 'Button label for adding a new item via the toolbar menu', 'jetpack' ),  
  671. ); 
  672.  
  673. if ( ! current_user_can( 'edit_pages' ) ) { 
  674. $portfolios_title = $this->create_menu_item_anchor( 
  675. 'ab-item ab-primary mb-icon',  
  676. 'https://wordpress.com/types/jetpack-portfolio/' . esc_attr( $this->primary_site_slug ),  
  677. __( 'Portfolio', 'jetpack' ),  
  678. 'wp-admin-bar-edit-portfolio' 
  679. ); 
  680.  
  681. $wp_admin_bar->add_menu( array( 
  682. 'parent' => 'publish',  
  683. 'id' => 'new-jetpack-portfolio',  
  684. 'title' => $portfolios_title,  
  685. 'meta' => array( 
  686. 'class' => 'inline-action',  
  687. ),  
  688. ) ); 
  689.  
  690. if ( current_user_can( 'edit_theme_options' ) ) { 
  691. // Look and Feel group 
  692. $wp_admin_bar->add_group( array( 
  693. 'parent' => 'blog',  
  694. 'id' => 'look-and-feel',  
  695. ) ); 
  696.  
  697. // Look and Feel header 
  698. $wp_admin_bar->add_menu( array( 
  699. 'parent' => 'look-and-feel',  
  700. 'id' => 'look-and-feel-header',  
  701. 'title' => _x( 'Personalize', 'admin bar menu group label', 'jetpack' ),  
  702. 'meta' => array( 
  703. 'class' => 'ab-submenu-header',  
  704. ),  
  705. ) ); 
  706.  
  707. if ( is_admin() ) { 
  708. // In wp-admin the `return` query arg will return to that page after closing the Customizer 
  709. $customizer_url = add_query_arg( array( 'return' => urlencode( site_url( $_SERVER['REQUEST_URI'] ) ) ), wp_customize_url() ); 
  710. } else { 
  711. // On the frontend the `url` query arg will load that page in the Customizer and also return to it after closing 
  712. // non-home URLs won't work unless we undo domain mapping since the Customizer preview is unmapped to always have HTTPS 
  713. $current_page = '//' . $this->primary_site_slug . $_SERVER['REQUEST_URI']; 
  714. $customizer_url = add_query_arg( array( 'url' => urlencode( $current_page ) ), wp_customize_url() ); 
  715.  
  716. $theme_title = $this->create_menu_item_pair( 
  717. array( 
  718. 'url' => 'https://wordpress.com/design/' . esc_attr( $this->primary_site_slug ),  
  719. 'id' => 'wp-admin-bar-themes',  
  720. 'label' => __( 'Themes', 'jetpack' ),  
  721. ),  
  722. array( 
  723. 'url' => $customizer_url,  
  724. 'id' => 'wp-admin-bar-cmz',  
  725. 'label' => _x( 'Customize', 'admin bar customize item label', 'jetpack' ),  
  726. ); 
  727. $meta = array( 'class' => 'mb-icon', 'class' => 'inline-action' ); 
  728. $href = false; 
  729.  
  730. $wp_admin_bar->add_menu( array( 
  731. 'parent' => 'look-and-feel',  
  732. 'id' => 'themes',  
  733. 'title' => $theme_title,  
  734. 'href' => $href,  
  735. 'meta' => $meta 
  736. ) ); 
  737.  
  738. if ( current_theme_supports( 'menus' ) ) { 
  739. $wp_admin_bar->add_menu( array( 
  740. 'parent' => 'look-and-feel',  
  741. 'id' => 'menus',  
  742. 'title' => __( 'Menus', 'jetpack' ),  
  743. 'href' => 'https://wordpress.com/menus/' . esc_attr( $this->primary_site_slug ),  
  744. 'meta' => array( 
  745. 'class' => 'mb-icon',  
  746. ),  
  747. ) ); 
  748.  
  749. if ( current_user_can( 'manage_options' ) ) { 
  750. // Configuration group 
  751. $wp_admin_bar->add_group( array( 
  752. 'parent' => 'blog',  
  753. 'id' => 'configuration',  
  754. ) ); 
  755.  
  756. // Configuration header 
  757. $wp_admin_bar->add_menu( array( 
  758. 'parent' => 'configuration',  
  759. 'id' => 'configuration-header',  
  760. 'title' => __( 'Configure', 'admin bar menu group label', 'jetpack' ),  
  761. 'meta' => array( 
  762. 'class' => 'ab-submenu-header',  
  763. ),  
  764. ) ); 
  765.  
  766. if ( Jetpack::is_module_active( 'publicize' ) || Jetpack::is_module_active( 'sharedaddy' ) ) { 
  767. $wp_admin_bar->add_menu( array( 
  768. 'parent' => 'configuration',  
  769. 'id' => 'sharing',  
  770. 'title' => __( 'Sharing', 'jetpack' ),  
  771. 'href' => 'https://wordpress.com/sharing/' . esc_attr( $this->primary_site_slug ),  
  772. 'meta' => array( 
  773. 'class' => 'mb-icon',  
  774. ),  
  775. ) ); 
  776.  
  777. $people_title = $this->create_menu_item_pair( 
  778. array( 
  779. 'url' => 'https://wordpress.com/people/team/' . esc_attr( $this->primary_site_slug ),  
  780. 'id' => 'wp-admin-bar-people',  
  781. 'label' => __( 'People', 'jetpack' ),  
  782. ),  
  783. array( 
  784. 'url' => admin_url( 'user-new.php' ),  
  785. 'id' => 'wp-admin-bar-people-add',  
  786. 'label' => _x( 'Add', 'admin bar people item label', 'jetpack' ),  
  787. ); 
  788.  
  789. $wp_admin_bar->add_menu( array( 
  790. 'parent' => 'configuration',  
  791. 'id' => 'users-toolbar',  
  792. 'title' => $people_title,  
  793. 'href' => false,  
  794. 'meta' => array( 
  795. 'class' => 'inline-action',  
  796. ),  
  797. ) ); 
  798.  
  799. $plugins_title = $this->create_menu_item_pair( 
  800. array( 
  801. 'url' => 'https://wordpress.com/plugins/' . esc_attr( $this->primary_site_slug ),  
  802. 'id' => 'wp-admin-bar-plugins',  
  803. 'label' => __( 'Plugins', 'jetpack' ),  
  804. ),  
  805. array( 
  806. 'url' => 'https://wordpress.com/plugins/browse/' . esc_attr( $this->primary_site_slug ),  
  807. 'id' => 'wp-admin-bar-plugins-add',  
  808. 'label' => _x( 'Add', 'Label for the button on the Masterbar to add a new plugin', 'jetpack' ),  
  809. ); 
  810.  
  811. $wp_admin_bar->add_menu( array( 
  812. 'parent' => 'configuration',  
  813. 'id' => 'plugins',  
  814. 'title' => $plugins_title,  
  815. 'href' => false,  
  816. 'meta' => array( 
  817. 'class' => 'inline-action',  
  818. ),  
  819. ) ); 
  820.  
  821. if ( $this->is_automated_transfer_site() ) { 
  822. $domain_title = $this->create_menu_item_pair( 
  823. array( 
  824. 'url' => 'https://wordpress.com/domains/' . esc_attr( $this->primary_site_slug ),  
  825. 'id' => 'wp-admin-bar-domains',  
  826. 'label' => __( 'Domains', 'jetpack' ),  
  827. ),  
  828. array( 
  829. 'url' => 'https://wordpress.com/domains/add/' . esc_attr( $this->primary_site_slug ),  
  830. 'id' => 'wp-admin-bar-domains-add',  
  831. 'label' => _x( 'Add', 'Label for the button on the Masterbar to add a new domain', 'jetpack' ),  
  832. ); 
  833. $wp_admin_bar->add_menu( array( 
  834. 'parent' => 'configuration',  
  835. 'id' => 'domains',  
  836. 'title' => $domain_title,  
  837. 'href' => false,  
  838. 'meta' => array( 
  839. 'class' => 'inline-action',  
  840. ),  
  841. ) ); 
  842.  
  843. $wp_admin_bar->add_menu( array( 
  844. 'parent' => 'configuration',  
  845. 'id' => 'blog-settings',  
  846. 'title' => __( 'Settings', 'jetpack' ),  
  847. 'href' => 'https://wordpress.com/settings/general/' . esc_attr( $this->primary_site_slug ),  
  848. 'meta' => array( 
  849. 'class' => 'mb-icon',  
  850. ),  
  851. ) ); 
  852.  
  853. if ( ! is_admin() ) { 
  854. $wp_admin_bar->add_menu( array( 
  855. 'parent' => 'configuration',  
  856. 'id' => 'legacy-dashboard',  
  857. 'title' => __( 'Dashboard', 'jetpack' ),  
  858. 'href' => admin_url(),  
  859. 'meta' => array( 
  860. 'class' => 'mb-icon',  
  861. ),  
  862. ) );