Skip to content

Commit

Permalink
Hide the plugin banner on non-wpcom-connected users or agency-managed…
Browse files Browse the repository at this point in the history
… users
  • Loading branch information
okmttdhr committed Jul 25, 2024
1 parent 991bb5f commit edc4cf7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static function load_wpcom_user_features() {
require_once __DIR__ . '/features/wpcom-admin-interface/wpcom-admin-interface.php';
require_once __DIR__ . '/features/wpcom-admin-menu/wpcom-admin-menu.php';
require_once __DIR__ . '/features/wpcom-command-palette/wpcom-command-palette.php';
require_once __DIR__ . '/features/wpcom-plugins/wpcom-plugins.php';
require_once __DIR__ . '/features/wpcom-sidebar-notice/wpcom-sidebar-notice.php';
require_once __DIR__ . '/features/wpcom-site-management-widget/class-wpcom-site-management-widget.php';
require_once __DIR__ . '/features/wpcom-themes/wpcom-themes.php';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Adds a tiny WordPress.com Plugins integration to the plugin list.
*
* @package automattic/jetpack-mu-wpcom
*/

/**
* Displays a banner before the plugin browser that links to the WP.com Plugins Marketplace.
*/
function wpcom_plugins_show_banner() {

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['tab'] ) && 'favorites' === $_GET['tab'] ) {
// no banner on the favorites tab, it's a bit overbearing given they presumably want
// something specific.
return;
}

// No banner for agency-managed sites.
if ( ! empty( get_option( 'is_fully_managed_agency_site' ) ) ) {
return;
}
if ( function_exists( 'current_user_has_wpcom_account' ) && ! current_user_has_wpcom_account() ) {
return;
}

$site_slug = wp_parse_url( home_url(), PHP_URL_HOST );
$wpcom_logo = plugins_url( 'images/wpcom-logo.svg', __FILE__ );
$background_image = plugins_url( 'images/banner-background.webp', __FILE__ );

wp_enqueue_script(
'wpcom-plugins-banner',
plugins_url( 'js/banner.js', __FILE__ ),
array(),
WPCOMSH_VERSION,
array(
'strategy' => 'defer',
'in_footer' => true,
)
);
wp_localize_script(
'wpcom-plugins-banner',
'wpcomPluginsBanner',
array(
'logo' => esc_url( $wpcom_logo ),
'title' => esc_html__( "Flex your site's features with plugins", 'jetpack-mu-wpcom' ),
'description' => esc_html__( "Access a variety of free and paid plugins that can enhance your site's functionality and features.", 'jetpack-mu-wpcom' ),
'actionUrl' => esc_url( "https://wordpress.com/plugins/$site_slug?ref=woa-plugin-banner" ),
'actionText' => esc_html__( 'Explore plugins', 'jetpack-mu-wpcom' ),
'bannerBackground' => esc_url( $background_image ),
)
);
wp_enqueue_style(
'wpcom-plugins-banner',
plugins_url( 'css/banner.css', __FILE__ ),
array(),
WPCOMSH_VERSION
);
}
add_action( 'load-plugin-install.php', 'wpcom_plugins_show_banner' );
1 change: 0 additions & 1 deletion projects/plugins/wpcomsh/wpcom-plugins/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,3 @@ function wpcomsh_plugins_show_banner() {
WPCOMSH_VERSION,
);
}
add_action( 'load-plugin-install.php', 'wpcomsh_plugins_show_banner' );

0 comments on commit edc4cf7

Please sign in to comment.