-
Notifications
You must be signed in to change notification settings - Fork 869
Admin UI: Add Upgrade Jetpack menu item for free users #47418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
1cbc66a
cd60b97
9c736c8
fad3e8f
36d5cea
0a1cc55
7259e4d
d611f0e
a21d087
649069d
10b8090
84fc4af
be32c94
ebdfb8e
3f16dcc
657b5d6
23f24f7
eed8e20
f342bc0
d4b6491
683eba1
617ffd3
4812910
f5c0603
1653308
34cf1f0
fa2df07
de846ec
5b70ad8
dbf2f01
8e39460
7395c74
ec433d9
0b07819
bda9b52
25b78be
0cecf4d
d40e4ba
7aab45f
345ad70
676964e
8f51d33
c27bfbc
c611366
ce1b5dc
fa1702f
f49f943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Significance: patch | ||
| Type: changed | ||
| Comment: Part of admin header normalization work | ||
|
|
||
| Remove padding from admin page header subtitle for consistent spacing. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: minor | ||
| Type: added | ||
|
|
||
| Add Upgrade to Pro menu item for free users in the Jetpack admin menu. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: changed | ||
|
|
||
| Simplify Akismet admin menu title from 'Akismet Anti-spam' to 'Anti-spam'. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,20 @@ | |
|
|
||
| const PACKAGE_VERSION = '0.5.11'; | ||
|
|
||
| /** | ||
| * Redirect source slug used as the upgrade URL identifier and CSS class. | ||
| * | ||
| * @var string | ||
| */ | ||
| const UPGRADE_MENU_SLUG = 'jetpack-wpadmin-sidebar-free-plan-upsell-menu-item'; | ||
|
|
||
| /** | ||
| * Fallback upgrade URL when the Redirect class is unavailable. | ||
| * | ||
| * @var string | ||
| */ | ||
| const UPGRADE_MENU_FALLBACK_URL = 'https://jetpack.com/upgrade/'; | ||
|
|
||
| /** | ||
| * Whether this class has been initialized | ||
| * | ||
|
|
@@ -40,6 +54,7 @@ | |
| self::handle_akismet_menu(); | ||
| add_action( 'admin_menu', array( __CLASS__, 'admin_menu_hook_callback' ), 1000 ); // Jetpack uses 998. | ||
| add_action( 'network_admin_menu', array( __CLASS__, 'admin_menu_hook_callback' ), 1000 ); // Jetpack uses 998. | ||
| add_action( 'admin_head', array( __CLASS__, 'add_upgrade_menu_item_styles' ) ); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -58,7 +73,7 @@ | |
| remove_action( 'admin_menu', array( 'Akismet_Admin', 'admin_menu' ), 5 ); | ||
|
|
||
| // Add an Anti-spam menu item for Jetpack. | ||
| self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ), 6 ); | ||
| self::add_menu( __( 'Akismet Anti-spam', 'jetpack-admin-ui' ), __( 'Anti-spam', 'jetpack-admin-ui' ), 'manage_options', 'akismet-key-config', array( 'Akismet_Admin', 'display_page' ), 6 ); | ||
| }, | ||
| 4 | ||
| ); | ||
|
|
@@ -140,6 +155,8 @@ | |
| if ( ! $can_see_toplevel_menu ) { | ||
| remove_menu_page( 'jetpack' ); | ||
| } | ||
|
|
||
| self::maybe_add_upgrade_menu_item(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -225,4 +242,97 @@ | |
| $url = $fallback ? $fallback : admin_url(); | ||
| return $url; | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether the current site is on a free Jetpack plan with no active paid license. | ||
| * | ||
| * @return bool True if the site has no paid plan. | ||
| */ | ||
| private static function is_free_plan() { | ||
| if ( class_exists( '\Automattic\Jetpack\Current_Plan' ) ) { | ||
| $plan = \Automattic\Jetpack\Current_Plan::get(); | ||
| return 'free' === ( $plan['class'] ?? 'free' ); | ||
| } | ||
DevinWalker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $plan = get_option( 'jetpack_active_plan', array() ); | ||
| return 'free' === ( $plan['class'] ?? 'free' ); | ||
| } | ||
|
|
||
| /** | ||
| * Conditionally adds an "Upgrade to Pro" submenu item for free-plan sites. | ||
| * | ||
| * The item is only added when the Jetpack top-level menu is visible and the | ||
| * site has not yet purchased a paid Jetpack plan or license. | ||
| * | ||
| * @return void | ||
| */ | ||
| private static function maybe_add_upgrade_menu_item() { | ||
| if ( ! current_user_can( 'manage_options' ) ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( ! self::is_free_plan() ) { | ||
| return; | ||
| } | ||
DevinWalker marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| $upgrade_url = class_exists( '\Automattic\Jetpack\Redirect' ) | ||
| ? \Automattic\Jetpack\Redirect::get_url( self::UPGRADE_MENU_SLUG ) | ||
| : self::UPGRADE_MENU_FALLBACK_URL; | ||
|
|
||
| $menu_title = '<span class="dashicons dashicons-star-filled jetpack-upgrade-menu__icon" aria-hidden="true"></span>' | ||
| . esc_html__( 'Upgrade to Pro', 'jetpack-admin-ui' ) | ||
| . ' <span aria-hidden="true">↗</span>'; | ||
|
|
||
| add_submenu_page( | ||
| 'jetpack', | ||
| __( 'Upgrade to Pro', 'jetpack-admin-ui' ), | ||
| $menu_title, | ||
| 'manage_options', | ||
| esc_url( $upgrade_url ), | ||
| null, | ||
|
Check failure on line 292 in projects/packages/admin-ui/src/class-admin-menu.php
|
||
| 999 | ||
| ); | ||
|
|
||
| // Add a CSS class to the <li> element so styles can target it precisely. | ||
| global $submenu; | ||
| if ( ! empty( $submenu['jetpack'] ) ) { | ||
| foreach ( $submenu['jetpack'] as $index => $item ) { | ||
| if ( isset( $item[2] ) && false !== strpos( $item[2], self::UPGRADE_MENU_SLUG ) ) { | ||
| // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited | ||
| $submenu['jetpack'][ $index ][4] = ( ! empty( $item[4] ) ? $item[4] . ' ' : '' ) . self::UPGRADE_MENU_SLUG; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Outputs inline CSS to style the "Upgrade to Pro" menu item in Jetpack green. | ||
| * | ||
| * The sidebar menu is visible on every admin page, so styles must load globally. | ||
| * Only outputs for free-plan sites. | ||
| * | ||
| * @return void | ||
| */ | ||
| public static function add_upgrade_menu_item_styles() { | ||
| if ( ! self::is_free_plan() ) { | ||
| return; | ||
| } | ||
DevinWalker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ?> | ||
| <style> | ||
| #adminmenu .jetpack-upgrade-menu__icon { | ||
| color: #069e08; | ||
| font-size: 15px; | ||
| line-height: 1; | ||
| vertical-align: middle; | ||
| margin-inline-start: -3px; | ||
| } | ||
| #adminmenu li.<?php echo esc_attr( self::UPGRADE_MENU_SLUG ); ?> > a, | ||
| #adminmenu li.<?php echo esc_attr( self::UPGRADE_MENU_SLUG ); ?> > a:hover { | ||
| color: #069e08; | ||
| font-weight: 600; | ||
| } | ||
| </style> | ||
| <?php | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: changed | ||
|
|
||
| Simplify admin menu title from 'VaultPress Backup' to 'Backups'. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Significance: patch | ||
| Type: changed | ||
|
|
||
| Replace @automattic/jetpack-components Button with @wordpress/components Button in BackupNowButton component. |
Uh oh!
There was an error while loading. Please reload this page.