PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / integrations / admin / deactivated-premium-integration.php

deactivated-premium-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/integrations/admin/deactivated-premium-integration.php

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