deactivated-premium-integration.php
4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
namespace Yoast\WP\SEO\Integrations\Admin;
use WPSEO_Admin_Asset_Manager;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Conditionals\Non_Multisite_Conditional;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
use Yoast\WP\SEO\Presenters\Admin\Notice_Presenter;
/**
* Deactivated_Premium_Integration class
*/
class Deactivated_Premium_Integration implements Integration_Interface {
/**
* The options' helper.
*
* @var Options_Helper
*/
private $options_helper;
/**
* The admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $admin_asset_manager;
/**
* {@inheritDoc}
*/
public static function get_conditionals() {
return [ Admin_Conditional::class, Non_Multisite_Conditional::class ];
}
/**
* First_Time_Configuration_Notice_Integration constructor.
*
* @param Options_Helper $options_helper The options helper.
* @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
*/
public function __construct(
Options_Helper $options_helper,
WPSEO_Admin_Asset_Manager $admin_asset_manager
) {
$this->options_helper = $options_helper;
$this->admin_asset_manager = $admin_asset_manager;
}
/**
* {@inheritDoc}
*/
public function register_hooks() {
\add_action( 'admin_notices', [ $this, 'premium_deactivated_notice' ] );
\add_action( 'wp_ajax_dismiss_premium_deactivated_notice', [ $this, 'dismiss_premium_deactivated_notice' ] );
}
/**
* Shows a notice if premium is installed but not activated.
*
* @return void
*/
public function premium_deactivated_notice() {
global $pagenow;
if ( $pagenow === 'update.php' ) {
return;
}
if ( $this->options_helper->get( 'dismiss_premium_deactivated_notice', false ) === true ) {
return;
}
$premium_file = 'wordpress-seo-premium/wp-seo-premium.php';
if ( ! \current_user_can( 'activate_plugin', $premium_file ) ) {
return;
}
if ( $this->premium_is_installed_not_activated( $premium_file ) ) {
$this->admin_asset_manager->enqueue_style( 'monorepo' );
$content = \sprintf(
/* translators: 1: Yoast SEO Premium 2: Link start tag to activate premium, 3: Link closing tag. */
\__( 'You\'ve installed %1$s but it\'s not activated yet. %2$sActivate %1$s now!%3$s', 'wordpress-seo' ),
'Yoast SEO Premium',
'<a href="' . \esc_url(
\wp_nonce_url(
\self_admin_url( 'plugins.php?action=activate&plugin=' . $premium_file ),
'activate-plugin_' . $premium_file
)
) . '">',
'</a>'
);
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped above.
echo new Notice_Presenter(
/* translators: 1: Yoast SEO Premium */
\sprintf( \__( 'Activate %1$s!', 'wordpress-seo' ), 'Yoast SEO Premium' ),
$content,
'support-team.svg',
null,
true,
'yoast-premium-deactivated-notice'
);
// phpcs:enable
// Enable permanently dismissing the notice.
echo "<script>
function dismiss_premium_deactivated_notice(){
var data = {
'action': 'dismiss_premium_deactivated_notice',
};
jQuery.post( ajaxurl, data, function( response ) {
jQuery( '#yoast-premium-deactivated-notice' ).hide();
});
}
jQuery( document ).ready( function() {
jQuery( 'body' ).on( 'click', '#yoast-premium-deactivated-notice .notice-dismiss', function() {
dismiss_premium_deactivated_notice();
} );
} );
</script>";
}
}
/**
* Dismisses the premium deactivated notice.
*
* @return bool
*/
public function dismiss_premium_deactivated_notice() {
return $this->options_helper->set( 'dismiss_premium_deactivated_notice', true );
}
/**
* Returns whether or not premium is installed and not activated.
*
* @param string $premium_file The premium file.
*
* @return bool Whether or not premium is installed and not activated.
*/
protected function premium_is_installed_not_activated( $premium_file ) {
return (
! \defined( 'WPSEO_PREMIUM_FILE' )
&& \file_exists( \WP_PLUGIN_DIR . '/' . $premium_file )
);
}
}