PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.5.0
ShopBuilder – WooCommerce Builder For Elementor v2.5.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.5.0, at app/Controllers/Admin/Notice/Review.php

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