Skip to content

Commit ecd7960

Browse files
authored
jetpack-mu-wpcom: Add new WordPRess.com site menu (#35702)
* Add the WordPress.com wp-admin sidebar menu link This commit adds a link to wordpress.com/home/:site when the nav redesign is enabled. * changelog * Version update
1 parent 2fd24df commit ecd7960

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: added
3+
4+
jetpack-mu-wpcom: Added the wpcom-site-menu feature to add a WordPress.com sidebar menu item.

projects/packages/jetpack-mu-wpcom/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@automattic/jetpack-mu-wpcom",
4-
"version": "5.12.2",
4+
"version": "5.12.3-alpha",
55
"description": "Enhances your site with features powered by WordPress.com",
66
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/jetpack-mu-wpcom/#readme",
77
"bugs": {

projects/packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Jetpack_Mu_Wpcom main class.
1414
*/
1515
class Jetpack_Mu_Wpcom {
16-
const PACKAGE_VERSION = '5.12.2';
16+
const PACKAGE_VERSION = '5.12.3-alpha';
1717
const PKG_DIR = __DIR__ . '/../';
1818
const BASE_DIR = __DIR__ . '/';
1919
const BASE_FILE = __FILE__;
@@ -76,6 +76,8 @@ public static function load_features() {
7676
require_once __DIR__ . '/features/media/heif-support.php';
7777

7878
require_once __DIR__ . '/features/block-patterns/block-patterns.php';
79+
80+
require_once __DIR__ . '/features/wpcom-site-menu/wpcom-site-menu.php';
7981
}
8082

8183
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* WordPress.com Site Menu
4+
*
5+
* Add's a WordPress.com menu item to the admin menu linking back to the sites WordPress.com home page.
6+
*
7+
* @package automattic/jetpack-mu-wpcom
8+
*/
9+
10+
/**
11+
* Add a WordPress.com menu item to the wp-admin sidebar menu.
12+
*/
13+
function wpcom_add_wpcom_menu_item() {
14+
if ( function_exists( 'wpcom_is_nav_redesign_enabled' ) && wpcom_is_nav_redesign_enabled() ) {
15+
$domain = wp_parse_url( home_url(), PHP_URL_HOST );
16+
add_menu_page(
17+
esc_attr__( 'WordPress.com', 'jetpack-mu-wpcom' ),
18+
esc_attr__( 'WordPress.com', 'jetpack-mu-wpcom' ),
19+
'manage_options',
20+
"https://wordpress.com/home/$domain",
21+
null,
22+
'dashicons-arrow-left-alt2',
23+
0
24+
);
25+
26+
// Position a separator below the WordPress.com menu item.
27+
// Inspired by https://github.com/Automattic/jetpack/blob/b6b6e86c5491869782857141ca48168dfa195635/projects/plugins/jetpack/modules/masterbar/admin-menu/class-base-admin-menu.php#L239
28+
global $menu;
29+
$separator = array(
30+
'', // Menu title (ignored).
31+
'manage_options', // Required capability.
32+
wp_unique_id( 'separator-custom-' ), // URL or file (ignored, but must be unique).
33+
'', // Page title (ignored).
34+
'wp-menu-separator', // CSS class. Identifies this item as a separator.
35+
);
36+
$position = 0;
37+
if ( isset( $menu[ "$position" ] ) ) {
38+
$position = $position + substr( base_convert( md5( $separator[2] . $separator[0] ), 16, 10 ), -5 ) * 0.00001;
39+
$menu[ "$position" ] = $separator; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
40+
} else {
41+
$menu[ "$position" ] = $separator; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
42+
}
43+
}
44+
}
45+
add_action( 'admin_menu', 'wpcom_add_wpcom_menu_item' );

0 commit comments

Comments
 (0)