Skip to content

Commit 5c58a5f

Browse files
authored
Merge pull request #22509 from Yoast/744-adapt-ads-for-new-pricing-and-packaging---upgrade-button-in-wp-sidebar-and-wp-admin-menu
Add upgrade buttons
2 parents 8b72147 + 0b67ac5 commit 5c58a5f

File tree

4 files changed

+189
-7
lines changed

4 files changed

+189
-7
lines changed

admin/class-admin-asset-manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ protected function styles_to_be_registered() {
625625
[
626626
'name' => 'admin-global',
627627
'src' => 'admin-global-' . $flat_version,
628+
'deps' => [ self::PREFIX . 'tailwind' ],
628629
],
629630
[
630631
'name' => 'filter-explanation',

css/src/adminbar.css

Lines changed: 48 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/class-wpseo-admin-bar-menu.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @package WPSEO
66
*/
77

8+
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
89
use Yoast\WP\SEO\Helpers\Product_Helper;
910
use Yoast\WP\SEO\Helpers\Score_Icon_Helper;
1011
use Yoast\WP\SEO\Integrations\Support_Integration;
@@ -590,6 +591,12 @@ protected function add_get_help_submenu( WP_Admin_Bar $wp_admin_bar ) {
590591
* @return void
591592
*/
592593
protected function add_premium_link( WP_Admin_Bar $wp_admin_bar ) {
594+
$has_woocommerce = ( new Woocommerce_Conditional() )->is_met();
595+
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium' );
596+
if ( $has_woocommerce ) {
597+
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium-woocommerce' );
598+
}
599+
593600
$sale_percentage = '';
594601
if ( YoastSEO()->classes->get( Promotion_Manager::class )->is( 'black-friday-2024-promotion' ) ) {
595602
$sale_percentage = sprintf(
@@ -603,9 +610,9 @@ protected function add_premium_link( WP_Admin_Bar $wp_admin_bar ) {
603610
'id' => 'wpseo-get-premium',
604611
// Circumvent an issue in the WP admin bar API in order to pass `data` attributes. See https://core.trac.wordpress.org/ticket/38636.
605612
'title' => sprintf(
606-
'<a href="%1$s" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2" style="padding:0;">%2$s &raquo; %3$s</a>',
607-
esc_url( $this->shortlinker->build_shortlink( 'https://yoa.st/admin-bar-get-premium' ) ),
608-
esc_html__( 'Get Yoast SEO Premium', 'wordpress-seo' ),
613+
'<a href="%1$s" target="_blank" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2">%2$s %3$s</a>',
614+
esc_url( $link ),
615+
esc_html__( 'Upgrade', 'wordpress-seo' ),
609616
$sale_percentage
610617
),
611618
'meta' => [
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
namespace Yoast\WP\SEO\Plans\User_Interface;
4+
5+
use WPSEO_Shortlinker;
6+
use Yoast\WP\SEO\Conditionals\Traits\Admin_Conditional_Trait;
7+
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
8+
use Yoast\WP\SEO\General\User_Interface\General_Page_Integration;
9+
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
10+
use Yoast\WP\SEO\Helpers\Product_Helper;
11+
use Yoast\WP\SEO\Integrations\Integration_Interface;
12+
13+
/**
14+
* Adds the plans page to the Yoast admin menu.
15+
*/
16+
class Upgrade_Sidebar_Menu_Integration implements Integration_Interface {
17+
18+
use Admin_Conditional_Trait;
19+
20+
/**
21+
* The page name.
22+
*/
23+
public const PAGE = 'wpseo_upgrade_sidebar';
24+
25+
/**
26+
* The WooCommerce conditional.
27+
*
28+
* @var WooCommerce_Conditional
29+
*/
30+
private $woocommerce_conditional;
31+
32+
/**
33+
* The shortlinker.
34+
*
35+
* @var WPSEO_Shortlinker
36+
*/
37+
private $shortlinker;
38+
39+
/**
40+
* The product helper.
41+
*
42+
* @var Product_Helper
43+
*/
44+
private $product_helper;
45+
46+
/**
47+
* The current page helper.
48+
*
49+
* @var Current_Page_Helper
50+
*/
51+
private $current_page_helper;
52+
53+
/**
54+
* Constructor.
55+
*
56+
* @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce conditional.
57+
* @param WPSEO_Shortlinker $shortlinker The shortlinker.
58+
* @param Product_Helper $product_helper The product helper.
59+
* @param Current_Page_Helper $current_page_helper The current page helper.
60+
*/
61+
public function __construct(
62+
WooCommerce_Conditional $woocommerce_conditional,
63+
WPSEO_Shortlinker $shortlinker,
64+
Product_Helper $product_helper,
65+
Current_Page_Helper $current_page_helper
66+
) {
67+
$this->woocommerce_conditional = $woocommerce_conditional;
68+
$this->shortlinker = $shortlinker;
69+
$this->product_helper = $product_helper;
70+
$this->current_page_helper = $current_page_helper;
71+
}
72+
73+
/**
74+
* Initializes the integration.
75+
*
76+
* This is the place to register hooks and filters.
77+
*
78+
* @return void
79+
*/
80+
public function register_hooks() {
81+
// Add page with PHP_INT_MAX so its always the last item.
82+
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_page' ], \PHP_INT_MAX );
83+
\add_filter( 'wpseo_network_submenu_pages', [ $this, 'add_page' ], \PHP_INT_MAX );
84+
\add_action( 'admin_init', [ $this, 'do_redirect' ], 1 );
85+
}
86+
87+
/**
88+
* Adds the page to the (currently) last position in the array.
89+
*
90+
* @param array<string, array<string, array<static|string>>> $pages The pages.
91+
*
92+
* @return array<string, array<string, array<static|string>>> The pages.
93+
*/
94+
public function add_page( $pages ) {
95+
96+
if ( ! $this->product_helper->is_premium() ) {
97+
$pages[] = [
98+
General_Page_Integration::PAGE,
99+
'',
100+
'<span class="yst-root"><span class="yst-button yst-w-full yst-button--upsell yst-button--small">' . \__( 'Upgrade', 'wordpress-seo' ) . ' </span></span>',
101+
'wpseo_manage_options',
102+
self::PAGE,
103+
static function () {
104+
echo 'redirecting...';
105+
},
106+
];
107+
}
108+
109+
return $pages;
110+
}
111+
112+
/**
113+
* Redirects to the yoast.com.
114+
*
115+
* @return void
116+
*/
117+
public function do_redirect(): void {
118+
119+
if ( $this->current_page_helper->get_current_yoast_seo_page() !== self::PAGE ) {
120+
return;
121+
}
122+
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-premium' );
123+
if ( $this->woocommerce_conditional->is_met() ) {
124+
$link = $this->shortlinker->build_shortlink( 'https://yoa.st/wordpress-menu-upgrade-woocommerce' );
125+
}
126+
127+
\wp_redirect( $link );//phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Safe redirect is used here.
128+
exit;
129+
}
130+
}

0 commit comments

Comments
 (0)