Skip to content

Commit

Permalink
Duplicate views: Use Calypso admin menu for untangled WP-Admin screen…
Browse files Browse the repository at this point in the history
…s (#40479)

* Duplicate views: Switch to WP-Admin on specific sections

* changelog

* Fix sidebar notice and handle a few more menus

* Add changelog to packages/masterbar

* Fix Phan errors

* Fix Phan errors

* Fix test dependencies in composer.json

* Fix unit tests

* Fix the admin menu on Atomic sites

* Add changelog

* Check if the function exists, just to be on the safe side.

* Update composer.lock

* Update composer.lock

* Add changelog

* Fix an issue in wpcomsh and remove the switcher for the treatment users.

* namespace it.

* Guard behind a function_exists

* Revert the switcher changes since it requires more effort

* Set a default array value

* Fix linting

---------

Co-authored-by: mmtr <1233880+mmtr@users.noreply.github.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/12254208301

Upstream-Ref: Automattic/jetpack@15de818
  • Loading branch information
BogdanUngureanu authored and matticbot committed Dec 10, 2024
1 parent c2d06a2 commit 6e3cea0
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 104 deletions.
65 changes: 35 additions & 30 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions vendor/automattic/jetpack-masterbar/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
"changelogger": {
"link-template": "https://github.com/Automattic/jetpack-masterbar/compare/v${old}...v${new}"
},
"dependencies": {
"test-only": [
"packages/jetpack-mu-wpcom"
]
},
"mirror-repo": "Automattic/jetpack-masterbar",
"textdomain": "jetpack-masterbar",
"version-constants": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function add_tools_menu() {

// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Marketing', 'jetpack-masterbar' ), __( 'Marketing', 'jetpack-masterbar' ), 'publish_posts', 'https://wordpress.com/marketing/tools/' . $this->domain, null, 0 );
if ( ! $this->use_wp_admin_interface() ) {
if ( $this->is_using_default_admin_menu() ) {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Monetize', 'jetpack-masterbar' ), __( 'Monetize', 'jetpack-masterbar' ), 'manage_options', 'https://wordpress.com/earn/' . $this->domain, null, 1 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function reregister_menu_items() {
$this->remove_gutenberg_menu();

// We don't need the `My Mailboxes` when the interface is set to wp-admin or the site is a staging site,
if ( get_option( 'wpcom_admin_interface' ) !== 'wp-admin' && ! get_option( 'wpcom_is_staging_site' ) ) {
if ( $this->is_using_default_admin_menu() && ! get_option( 'wpcom_is_staging_site' ) ) {
$this->add_my_mailboxes_menu();
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public function add_users_menu() {
$this->update_submenus( $slug, $submenus_to_update );
}

if ( ! $this->use_wp_admin_interface() ) {
if ( $this->is_using_default_admin_menu() ) {
// The 'Subscribers' menu exists in the Jetpack menu for Classic wp-admin interface, so only add it for non-wp-admin interfaces.
// // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'users.php', esc_attr__( 'Subscribers', 'jetpack-masterbar' ), __( 'Subscribers', 'jetpack-masterbar' ), 'list_users', 'https://wordpress.com/subscribers/' . $this->domain, null );
Expand Down Expand Up @@ -322,7 +322,7 @@ public function get_upsell_nudge() {
*/
public function add_jetpack_menu() {
// This is supposed to be the same as class-admin-menu but with a different position specified for the Jetpack menu.
if ( 'wp-admin' === get_option( 'wpcom_admin_interface' ) ) {
if ( ! $this->is_using_default_admin_menu() ) {
parent::create_jetpack_menu( 2, false );
} else {
parent::add_jetpack_menu();
Expand Down Expand Up @@ -445,7 +445,7 @@ public function add_options_menu() {

// Hide Settings > Performance when the interface is set to wp-admin.
// This is due to these settings are mostly also available in Jetpack > Settings, in the Performance tab.
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
if ( ! $this->is_using_default_admin_menu() ) {
$this->hide_submenu_page( 'options-general.php', 'https://wordpress.com/settings/performance/' . $this->domain );
}
}
Expand All @@ -457,7 +457,7 @@ public function add_tools_menu() {
parent::add_tools_menu();

// Link the Tools menu to Available Tools when the interface is set to wp-admin.
if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
if ( ! $this->is_using_default_admin_menu() ) {
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- Core should ideally document null for no-callback arg. https://core.trac.wordpress.org/ticket/52539.
add_submenu_page( 'tools.php', esc_attr__( 'Available Tools', 'jetpack-masterbar' ), __( 'Available Tools', 'jetpack-masterbar' ), 'edit_posts', 'tools.php', null, 0 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,21 @@ public function use_wp_admin_interface() {
return 'wp-admin' === get_option( 'wpcom_admin_interface' );
}

/**
* Check if the user has the default (Calypso) Admin menu.
*
* @return bool
*/
public function is_using_default_admin_menu() {
remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' );
$option = get_option( 'wpcom_admin_interface' ) !== 'wp-admin';
if ( function_exists( 'wpcom_admin_interface_pre_get_option' ) ) {
add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 );
}

return $option;
}

/**
* Create the desired menu output.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function () {

remove_action( 'customize_register', 'Automattic\Jetpack\Masterbar\register_css_nudge_control' );

// @phan-suppress-next-line PhanUndeclaredClassInCallable
remove_action( 'customize_register', array( 'Jetpack_Custom_CSS_Enhancements', 'customize_register' ) );
}
}
Expand Down
8 changes: 7 additions & 1 deletion vendor/automattic/jetpack-masterbar/src/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ public static function init() {

new Admin_Color_Schemes();

if ( get_option( 'wpcom_admin_interface' ) === 'wp-admin' ) {
remove_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option' );
$is_wp_admin_interface = get_option( 'wpcom_admin_interface' ) === 'wp-admin';
if ( function_exists( 'wpcom_admin_interface_pre_get_option' ) ) {
add_filter( 'pre_option_wpcom_admin_interface', 'wpcom_admin_interface_pre_get_option', 10 );
}

if ( $is_wp_admin_interface ) {
return;
}

Expand Down
1 change: 1 addition & 0 deletions vendor/automattic/jetpack-mu-wpcom/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This is an alpha version! The changes listed here are not final.
- WordPress.com Features: add Holiday Snow functionality.

### Changed
- Switch to WP-Admin some sections while keeping some untangling changes
- Use wp_add_inline_script

### Fixed
Expand Down
Loading

0 comments on commit 6e3cea0

Please sign in to comment.