PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.4
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 / admin / class-product-upsell-notice.php

class-product-upsell-notice.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.4, at admin/class-product-upsell-notice.php

208 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Represents the upsell notice.
10 */
11 class WPSEO_Product_Upsell_Notice {
12
13 /**
14 * Holds the name of the user meta key.
15 *
16 * The value of this database field holds whether the user has dismissed this notice or not.
17 *
18 * @var string
19 */
20 const USER_META_DISMISSED = 'wpseo-remove-upsell-notice';
21
22 /**
23 * Holds the option name.
24 *
25 * @var string
26 */
27 const OPTION_NAME = 'wpseo';
28
29 /**
30 * Holds the options.
31 *
32 * @var array
33 */
34 protected $options;
35
36 /**
37 * Sets the options, because they always have to be there on instance.
38 */
39 public function __construct() {
40 $this->options = $this->get_options();
41 }
42
43 /**
44 * Checks if the notice should be added or removed.
45 */
46 public function initialize() {
47 $this->remove_notification();
48 }
49
50 /**
51 * Sets the upgrade notice.
52 */
53 public function set_upgrade_notice() {
54
55 if ( $this->has_first_activated_on() ) {
56 return;
57 }
58
59 $this->set_first_activated_on();
60 $this->add_notification();
61 }
62
63 /**
64 * Listener for the upsell notice.
65 */
66 public function dismiss_notice_listener() {
67 if ( filter_input( INPUT_GET, 'yoast_dismiss' ) !== 'upsell' ) {
68 return;
69 }
70
71 $this->dismiss_notice();
72
73 wp_safe_redirect( admin_url( 'admin.php?page=wpseo_dashboard' ) );
74 exit;
75 }
76
77 /**
78 * When the notice should be shown.
79 *
80 * @return bool
81 */
82 protected function should_add_notification() {
83 return ( $this->options['first_activated_on'] < strtotime( '-2weeks' ) );
84 }
85
86 /**
87 * Checks if the options has a first activated on date value.
88 *
89 * @return bool
90 */
91 protected function has_first_activated_on() {
92 return $this->options['first_activated_on'] !== false;
93 }
94
95 /**
96 * Sets the first activated on.
97 */
98 protected function set_first_activated_on() {
99 $this->options['first_activated_on'] = strtotime( '-2weeks' );
100
101 $this->save_options();
102 }
103
104 /**
105 * Adds a notification to the notification center.
106 */
107 protected function add_notification() {
108 $notification_center = Yoast_Notification_Center::get();
109 $notification_center->add_notification( $this->get_notification() );
110 }
111
112 /**
113 * Removes a notification to the notification center.
114 */
115 protected function remove_notification() {
116 $notification_center = Yoast_Notification_Center::get();
117 $notification_center->remove_notification( $this->get_notification() );
118 }
119
120 /**
121 * Returns a premium upsell section if using the free plugin.
122 *
123 * @return string
124 */
125 protected function get_premium_upsell_section() {
126 if ( ! YoastSEO()->helpers->product->is_premium() ) {
127 return sprintf(
128 /* translators: %1$s expands anchor to premium plugin page, %2$s expands to </a> */
129 __( 'By the way, did you know we also have a %1$sPremium plugin%2$s? It offers advanced features, like a redirect manager and support for multiple keyphrases. It also comes with 24/7 personal support.', 'wordpress-seo' ),
130 "<a href='" . WPSEO_Shortlinker::get( 'https://yoa.st/premium-notification' ) . "'>",
131 '</a>'
132 );
133 }
134
135 return '';
136 }
137
138 /**
139 * Gets the notification value.
140 *
141 * @return Yoast_Notification
142 */
143 protected function get_notification() {
144 $message = sprintf(
145 /* translators: %1$s expands to Yoast SEO, %2$s is a link start tag to the plugin page on WordPress.org, %3$s is the link closing tag. */
146 __( 'We\'ve noticed you\'ve been using %1$s for some time now; we hope you love it! We\'d be thrilled if you could %2$sgive us a 5 stars rating on WordPress.org%3$s!', 'wordpress-seo' ),
147 'Yoast SEO',
148 '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/rate-yoast-seo' ) . '">',
149 '</a>'
150 ) . "\n\n";
151
152 $message .= sprintf(
153 /* translators: %1$s is a link start tag to the bugreport guidelines on the Yoast help center, %2$s is the link closing tag. */
154 __( 'If you are experiencing issues, %1$splease file a bug report%2$s and we\'ll do our best to help you out.', 'wordpress-seo' ),
155 '<a href="' . WPSEO_Shortlinker::get( 'https://yoa.st/bugreport' ) . '">',
156 '</a>'
157 ) . "\n\n";
158
159 $message .= $this->get_premium_upsell_section() . "\n\n";
160
161 $message .= '<a class="button" href="' . admin_url( '?page=' . WPSEO_Admin::PAGE_IDENTIFIER . '&yoast_dismiss=upsell' ) . '">' . __( 'Please don\'t show me this notification anymore', 'wordpress-seo' ) . '</a>';
162
163 $notification = new Yoast_Notification(
164 $message,
165 [
166 'type' => Yoast_Notification::WARNING,
167 'id' => 'wpseo-upsell-notice',
168 'capabilities' => 'wpseo_manage_options',
169 'priority' => 0.8,
170 ]
171 );
172
173 return $notification;
174 }
175
176 /**
177 * Dismisses the notice.
178 *
179 * @return bool
180 */
181 protected function is_notice_dismissed() {
182 return get_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true ) === '1';
183 }
184
185 /**
186 * Dismisses the notice.
187 */
188 protected function dismiss_notice() {
189 update_user_meta( get_current_user_id(), self::USER_META_DISMISSED, true );
190 }
191
192 /**
193 * Returns the set options.
194 *
195 * @return mixed
196 */
197 protected function get_options() {
198 return get_option( self::OPTION_NAME );
199 }
200
201 /**
202 * Saves the options to the database.
203 */
204 protected function save_options() {
205 update_option( self::OPTION_NAME, $this->options );
206 }
207 }
208