Skip to content

Commit

Permalink
Themes: Hide "Theme Showcase" broken action (#36986)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtr authored and matticbot committed Apr 19, 2024
1 parent a990f2f commit ce426b7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 23 deletions.
16 changes: 8 additions & 8 deletions composer.lock

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

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 @@ -15,6 +15,7 @@ This is an alpha version! The changes listed here are not final.
### Fixed
- Added completed callback for site_launched task
- Fixed a WP.com only issue that forced the Themes menu to always point to Calypso even when the classic interface was set
- Themes: Fixed an issue that was showing a broken Theme Showcase action in the active theme details

## [5.24.0] - 2024-04-15
### Added
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const wpcomThemesRemoveWpcomActions = () => {
const themeOverlay = document.querySelector( '.theme-overlay' );
if ( ! themeOverlay ) {
return;
}

const observer = new MutationObserver( mutations => {
for ( const mutation of mutations ) {
for ( const node of mutation.addedNodes ) {
// If this is not an overlay for the active theme, bail and check the next node.
if (
! node.classList.contains( 'theme-overlay' ) ||
! node.classList.contains( 'active' )
) {
continue;
}

const themeActions = node.querySelector( '.theme-actions .active-theme' );
for ( const action of themeActions?.children ?? [] ) {
if ( action.getAttribute( 'href' )?.includes( 'https://wordpress.com' ) ) {
themeActions.removeChild( action );
}
}
return;
}
}
} );

observer.observe( themeOverlay, { childList: true } );
};

document.addEventListener( 'DOMContentLoaded', wpcomThemesRemoveWpcomActions );
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@ function wpcom_themes_add_theme_showcase_menu() {
}

$site_slug = wp_parse_url( home_url(), PHP_URL_HOST );
add_submenu_page( 'themes.php', esc_attr__( 'Theme Showcase', 'jetpack-mu-wpcom' ), __( 'Theme Showcase', 'jetpack-mu-wpcom' ), 'read', "https://wordpress.com/themes/$site_slug?ref=wpcom-themes-menu" );
add_submenu_page(
'themes.php',
esc_attr__( 'Theme Showcase', 'jetpack-mu-wpcom' ),
__( 'Theme Showcase', 'jetpack-mu-wpcom' ),
current_user_can( 'switch_themes' ) ? 'switch_themes' : 'edit_theme_options',
"https://wordpress.com/themes/$site_slug?ref=wpcom-themes-menu"
);
}
add_action( 'admin_menu', 'wpcom_themes_add_theme_showcase_menu' );

/**
* Removes actions from the active theme details added by Core to replicate our custom WP.com submenus.
*
* Core expect the menus to link to WP Admin, but our submenus point to wordpress.com so the actions won't work.
*
* @see https://github.com/WordPress/wordpress-develop/blob/80096ddf29d3ffa4d5654f5f788df7f598b48756/src/wp-admin/themes.php#L356-L412
*/
function wpcom_themes_remove_wpcom_actions() {
wp_enqueue_script(
'wpcom-theme-actions',
plugins_url( 'js/theme-actions.js', __FILE__ ),
array(),
Jetpack_Mu_Wpcom::PACKAGE_VERSION,
array(
'strategy' => 'defer',
'in_footer' => true,
)
);
}
add_action( 'load-themes.php', 'wpcom_themes_remove_wpcom_actions' );
14 changes: 7 additions & 7 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-assets",
"reference": "5f17c10bbd1d0f176d894bc889c96e4200553a5c"
"reference": "3c0124efb5ee2eac5b0c87e75036989e79e7a3eb"
},
"require": {
"automattic/jetpack-constants": "^2.0.1",
Expand Down Expand Up @@ -76,7 +76,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-constants",
"reference": "9e3bf8d3fe4382735ff05400812bdd9b34fa4939"
"reference": "f63ddaa6f9e6fde9bf7cd91876b100d7f570316f"
},
"require": {
"php": ">=7.0"
Expand Down Expand Up @@ -125,12 +125,12 @@
},
{
"name": "automattic/jetpack-mu-wpcom",
"version": "5.24.1-alpha.1713457240",
"version_normalized": "5.24.1.0-alpha1713457240",
"version": "5.24.1-alpha.1713532538",
"version_normalized": "5.24.1.0-alpha1713532538",
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-mu-wpcom",
"reference": "2d95f252426bcf8f874e6a2936cd7fe81f12bc87"
"reference": "683395924ad39c5afc96607c8ed44d72ef679910"
},
"require": {
"automattic/jetpack-assets": "^2.1.8-alpha",
Expand Down Expand Up @@ -203,7 +203,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/jetpack-status",
"reference": "9a58d377206b15c7c28ebc8c4c5a7c8b8ea46718"
"reference": "0d76dd85400bd23638a5dcb0783697e3886ede67"
},
"require": {
"automattic/jetpack-constants": "^2.0.1",
Expand Down Expand Up @@ -259,7 +259,7 @@
"dist": {
"type": "path",
"url": "/tmp/jetpack-build/Automattic/scheduled-updates",
"reference": "71fed9c3eac31b6b764f98ff1ca1581cb1032482"
"reference": "b647fda6da312f086e0f790b8239556f7290a0e1"
},
"require": {
"php": ">=7.0"
Expand Down
14 changes: 7 additions & 7 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'automattic/jetpack-assets' => array(
'pretty_version' => '2.1.8-alpha.1713286100',
'version' => '2.1.8.0-alpha1713286100',
'reference' => '5f17c10bbd1d0f176d894bc889c96e4200553a5c',
'reference' => '3c0124efb5ee2eac5b0c87e75036989e79e7a3eb',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-assets',
'aliases' => array(),
Expand All @@ -22,16 +22,16 @@
'automattic/jetpack-constants' => array(
'pretty_version' => '2.0.1',
'version' => '2.0.1.0',
'reference' => '9e3bf8d3fe4382735ff05400812bdd9b34fa4939',
'reference' => 'f63ddaa6f9e6fde9bf7cd91876b100d7f570316f',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-constants',
'aliases' => array(),
'dev_requirement' => false,
),
'automattic/jetpack-mu-wpcom' => array(
'pretty_version' => '5.24.1-alpha.1713457240',
'version' => '5.24.1.0-alpha1713457240',
'reference' => '2d95f252426bcf8f874e6a2936cd7fe81f12bc87',
'pretty_version' => '5.24.1-alpha.1713532538',
'version' => '5.24.1.0-alpha1713532538',
'reference' => '683395924ad39c5afc96607c8ed44d72ef679910',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-mu-wpcom',
'aliases' => array(),
Expand All @@ -49,7 +49,7 @@
'automattic/jetpack-status' => array(
'pretty_version' => '2.2.2-alpha.1713286100',
'version' => '2.2.2.0-alpha1713286100',
'reference' => '9a58d377206b15c7c28ebc8c4c5a7c8b8ea46718',
'reference' => '0d76dd85400bd23638a5dcb0783697e3886ede67',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/jetpack-status',
'aliases' => array(),
Expand All @@ -58,7 +58,7 @@
'automattic/scheduled-updates' => array(
'pretty_version' => '0.8.0-alpha.1713517576',
'version' => '0.8.0.0-alpha1713517576',
'reference' => '71fed9c3eac31b6b764f98ff1ca1581cb1032482',
'reference' => 'b647fda6da312f086e0f790b8239556f7290a0e1',
'type' => 'jetpack-library',
'install_path' => __DIR__ . '/../automattic/scheduled-updates',
'aliases' => array(),
Expand Down

0 comments on commit ce426b7

Please sign in to comment.