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

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