PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.4.0
ShopBuilder – WooCommerce Builder For Elementor v2.4.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Controllers / Admin / Notice / Review.php

Review.php in ShopBuilder – WooCommerce Builder For Elementor 2.4.0, at app/Controllers/Admin/Notice/Review.php

320 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Review class.
4 *
5 * @package RadiusTheme\SB
6 */
7
8 namespace RadiusTheme\SB\Controllers\Admin\Notice;
9
10 use RadiusTheme\SB\Models\ExtraSettings;
11 use RadiusTheme\SB\Traits\SingletonTrait;
12
13 /**
14 * Review class.
15 */
16 class Review {
17 /**
18 * Singleton
19 */
20 use SingletonTrait;
21
22 /**
23 * Class constructor.
24 */
25 private function __construct() {
26 add_action( 'admin_init', [ $this, 'check_installation_time' ], 10 );
27 add_action( 'admin_init', [ $this, 'notice_actions' ], 5 );
28
29 $this->remove_all_notices();
30 }
31
32 /**
33 * Check if review notice should be shown or not
34 *
35 * @return void
36 */
37 public function check_installation_time() {
38 $nobug = get_option( 'rtsb_admin_review_spare_me' );
39 $rated = get_option( 'rtsb_admin_review_rated' );
40
41 if ( '1' == $nobug || 'yes' == $rated ) {
42 return;
43 }
44
45 $now = strtotime( 'now' );
46
47 $install_date = ExtraSettings::instance()->get_option( 'rtsb_plugin_activation_time', false );
48 $showing_date = strtotime( '+15 days', $install_date );
49 $remind_time = get_option( 'rtsb_admin_review_remind_me' );
50
51 if ( ! $remind_time ) {
52 $remind_time = $install_date;
53 }
54
55 $remind_due = strtotime( '+20 days', $remind_time );
56
57 if ( ! $now > $showing_date || $now < $remind_due ) {
58 return;
59 }
60
61 add_action( 'admin_notices', [ $this, 'display_admin_notice' ] );
62 }
63
64 /**
65 * Remove the notice for the user if review already done or if the user does not want to
66 *
67 * @return void
68 */
69 public function notice_actions() {
70 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
71 if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'rtsb_notice_nonce' ) ) {
72 return;
73 }
74
75 if ( ! empty( $_GET['rtsb_admin_review_spare_me'] ) ) {
76 $spare_me = absint( $_GET['rtsb_admin_review_spare_me'] );
77
78 if ( 1 == $spare_me ) {
79 update_option( 'rtsb_admin_review_spare_me', '1' );
80 }
81 }
82
83 if ( ! empty( $_GET['rtsb_admin_review_remind_me'] ) ) {
84 $remind_me = absint( $_GET['rtsb_admin_review_remind_me'] );
85
86 if ( 1 == $remind_me ) {
87 $get_activation_time = strtotime( 'now' );
88
89 update_option( 'rtsb_admin_review_remind_me', $get_activation_time );
90 }
91 }
92
93 if ( ! empty( $_GET['rtsb_admin_review_rated'] ) ) {
94 $rtsb_admin_review_rated = absint( $_GET['rtsb_admin_review_rated'] );
95
96 if ( 1 == $rtsb_admin_review_rated ) {
97 update_option( 'rtsb_admin_review_rated', 'yes' );
98 }
99 }
100 }
101
102 /**
103 * @return false|string
104 */
105 protected function rtsb_current_admin_url() {
106 $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
107 $uri = preg_replace( '|^.*/wp-admin/|i', '', $uri );
108
109 if ( ! $uri ) {
110 return '';
111 }
112
113 return remove_query_arg(
114 [
115 '_wpnonce',
116 '_wc_notice_nonce',
117 'wc_db_update',
118 'wc_db_update_nonce',
119 'wc-hide-notice',
120 'rtsb_admin_review_spare_me',
121 'rtsb_admin_review_remind_me',
122 'rtsb_admin_review_rated',
123 ],
124 admin_url( $uri )
125 );
126 }
127 /**
128 * Display Admin Notice, asking for a review
129 **/
130 public function display_admin_notice() {
131 global $pagenow;
132
133 $exclude = [
134 'themes.php',
135 'users.php',
136 'tools.php',
137 'options-general.php',
138 'options-writing.php',
139 'options-reading.php',
140 'options-discussion.php',
141 'options-media.php',
142 'options-permalink.php',
143 'options-privacy.php',
144 'admin.php',
145 'import.php',
146 'export.php',
147 'site-health.php',
148 'export-personal-data.php',
149 'erase-personal-data.php',
150 ];
151
152 if ( ! in_array( $pagenow, $exclude, true ) ) {
153 $args = [ '_wpnonce' => wp_create_nonce( 'rtsb_notice_nonce' ) ];
154 $dont_disturb = add_query_arg( $args + [ 'rtsb_admin_review_spare_me' => '1' ], $this->rtsb_current_admin_url() );
155 $remind_me = add_query_arg( $args + [ 'rtsb_admin_review_remind_me' => '1' ], $this->rtsb_current_admin_url() );
156 $rated = add_query_arg( $args + [ 'rtsb_admin_review_rated' => '1' ], $this->rtsb_current_admin_url() );
157 $reviewurl = 'https://wordpress.org/support/plugin/shopbuilder/reviews/?filter=5#new-post';
158 $plugin_name = 'ShopBuilder – Elementor WooCommerce Builder Addons';
159 ?>
160 <div class="notice rtsb-review-notice rtsb-review-notice--extended">
161 <div class="rtsb-review-notice_content">
162 <h3>Enjoying <?php echo esc_html( $plugin_name ); ?>? </h3>
163 <p>Thank you for choosing <strong>ShopBuilder</strong>. If you have found our plugin useful and makes you smile, please consider giving us a 5-star rating on WordPress.org. It will help us to grow.</p>
164 <div class="rtsb-review-notice_actions">
165 <a href="<?php echo esc_url( $reviewurl ); ?>"
166 class="rtsb-review-button rtsb-review-button--cta" target="_blank"><span> Yes, You Deserve It!</span></a>
167 <a href="<?php echo esc_url( $rated ); ?>"
168 class="rtsb-review-button rtsb-review-button--cta rtsb-review-button--outline"><span>😀 Already Rated!</span></a>
169 <a href="<?php echo esc_url( $remind_me ); ?>"
170 class="rtsb-review-button rtsb-review-button--cta rtsb-review-button--outline"><span>🔔 Remind Me Later</span></a>
171 <a href="<?php echo esc_url( $dont_disturb ); ?>"
172 class="rtsb-review-button rtsb-review-button--cta rtsb-review-button--error rtsb-review-button--outline"><span>😐 No Thanks </span></a>
173 </div>
174 </div>
175 </div>
176 <style>
177 .rtsb-review-button--cta {
178 --e-button-context-color: #4360ef;
179 --e-button-context-color-dark: #1f3edc;
180 --e-button-context-tint: rgb(75 47 157/4%);
181 --e-focus-color: rgb(75 47 157/40%);
182 }
183
184 .rtsb-review-notice {
185 position: relative;
186 margin: 5px 20px 5px 2px;
187 border: 1px solid #ccd0d4;
188 background: #fff;
189 box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
190 font-family: Roboto, Arial, Helvetica, Verdana, sans-serif;
191 border-inline-start-width: 4px;
192 }
193 .rtsb-review-notice.notice {
194 padding: 0;
195 }
196 .rtsb-review-notice:before {
197 position: absolute;
198 top: -1px;
199 bottom: -1px;
200 left: -4px;
201 display: block;
202 width: 4px;
203 background: -webkit-linear-gradient(0deg, #5d3dfd 0%, #6939c6 100%);
204 background: linear-gradient(0deg, #5d3dfd 0%, #6939c6 100%);
205 content: "";
206 }
207
208 .rtsb-review-notice_content {
209 padding: 20px;
210 }
211
212 .rtsb-review-notice_actions > * + * {
213 margin-inline-start: 8px;
214 -webkit-margin-start: 8px;
215 -moz-margin-start: 8px;
216 }
217
218 .rtsb-review-notice p {
219 margin: 0;
220 padding: 0;
221 line-height: 1.5;
222 }
223
224 p + .rtsb-review-notice_actions {
225 margin-top: 1rem;
226 }
227
228 .rtsb-review-notice h3 {
229 margin: 0;
230 font-size: 1.0625rem;
231 line-height: 1.2;
232 }
233
234 .rtsb-review-notice h3 + p {
235 margin-top: 8px;
236 }
237
238 .rtsb-review-button {
239 display: inline-block;
240 padding: 0.4375rem 0.75rem;
241 border: 0;
242 border-radius: 3px;;
243 background: var(--e-button-context-color);
244 color: #fff;
245 vertical-align: middle;
246 text-align: center;
247 text-decoration: none;
248 white-space: nowrap;
249 }
250
251 .rtsb-review-button:active {
252 background: var(--e-button-context-color-dark);
253 color: #fff;
254 text-decoration: none;
255 }
256
257 .rtsb-review-button:focus {
258 outline: 0;
259 background: var(--e-button-context-color-dark);
260 box-shadow: 0 0 0 2px var(--e-focus-color);
261 color: #fff;
262 text-decoration: none;
263 }
264
265 .rtsb-review-button:hover {
266 background: var(--e-button-context-color-dark);
267 color: #fff;
268 text-decoration: none;
269 }
270
271 .rtsb-review-button.focus {
272 outline: 0;
273 box-shadow: 0 0 0 2px var(--e-focus-color);
274 }
275
276 .rtsb-review-button--error {
277 --e-button-context-color: #d72b3f;
278 --e-button-context-color-dark: #ae2131;
279 --e-button-context-tint: rgba(215, 43, 63, 0.04);
280 --e-focus-color: rgba(215, 43, 63, 0.4);
281 }
282
283 .rtsb-review-button.rtsb-review-button--outline {
284 border: 1px solid;
285 background: 0 0;
286 color: var(--e-button-context-color);
287 }
288
289 .rtsb-review-button.rtsb-review-button--outline:focus {
290 background: var(--e-button-context-tint);
291 color: var(--e-button-context-color-dark);
292 }
293
294 .rtsb-review-button.rtsb-review-button--outline:hover {
295 background: var(--e-button-context-tint);
296 color: var(--e-button-context-color-dark);
297 }
298 </style>
299 <?php
300 }
301 }
302
303 /**
304 * Remove admin notices
305 */
306 public function remove_all_notices() {
307 add_action(
308 'in_admin_header',
309 function () {
310 $screen = get_current_screen();
311 if ( in_array( $screen->base, [ 'shopbuilder_page_rtsb-get-help' ], true ) ) {
312 remove_all_actions( 'admin_notices' );
313 remove_all_actions( 'all_admin_notices' );
314 }
315 },
316 1000
317 );
318 }
319 }
320