PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.6.9
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.6.9
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / lib / class-weforms-upsell.php

class-weforms-upsell.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.6.9, at includes/lib/class-weforms-upsell.php

415 lines 13.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! class_exists( 'WeForms_Upsell' ) ) {
4
5 /**
6 * weForms Upsell Class
7 */
8 class WeForms_Upsell {
9
10 /**
11 * Affiliate code for referal tracking
12 *
13 * @var string
14 */
15 private $affiliate;
16
17 /**
18 * Learn more link
19 *
20 * @var string
21 */
22 private $learn_more = 'https://wedevs.com/weforms-details/';
23
24 /**
25 * Instantiate the class
26 *
27 * @param string $affiliate
28 */
29 public function __construct( $affiliate = '' ) {
30 $this->affiliate = $affiliate;
31
32 add_action( 'init', [ $this, 'init_hooks' ] );
33 }
34
35 /**
36 * Initialize the hooks
37 *
38 * @return void
39 */
40 public function init_hooks() {
41 if ( class_exists( 'weForms' ) ) {
42 return;
43 }
44
45 if ( ! current_user_can( 'manage_options' ) ) {
46 return;
47 }
48
49 add_action( 'admin_notices', [ $this, 'activation_notice' ] );
50
51 add_action( 'wp_ajax_weforms_upsell_installer', [ $this, 'install_weforms' ] );
52 add_action( 'wp_ajax_weforms_upsell_dismiss', [ $this, 'dismiss_weforms_notice' ] );
53 }
54
55 /**
56 * Show the plugin installation notice
57 *
58 * @return void
59 */
60 public function activation_notice() {
61 if ( $this->is_dismissed() ) {
62 return;
63 } ?>
64 <div class="updated" id="weforms-upsell-prompt">
65 <div class="weforms-upsell-logo">
66 <img src="https://wedevs-com-wedevs.netdna-ssl.com/wp-content/uploads/2017/08/weforms-upsell.png" width="272" height="71" alt="weForms Logo">
67 </div>
68 <div class="weforms-upsell-text">
69 <h2>weForms is here!</h2>
70
71 <p>weForms is the next generation contact form plugin for WordPress.</p>
72 </div>
73 <div class="weforms-upsell-cta">
74 <button id="weforms-upsell-prompt-btn" class="button"><?php esc_html_e( 'Install Now', 'weforms' ); ?></button>
75 &nbsp;<a href="#" class="learn-more" data-tube="NJvjy9WFyAM">Learn More</a>
76 </div>
77 <button type="button" class="notice-dismiss" style="padding: 3px;" title="<?php esc_html_e( 'Dismiss this notice.' ); ?>">
78 <span class="screen-reader-text"><?php esc_html_e( 'Dismiss this notice.' ); ?></span>
79 </button>
80 </div>
81
82 <div class="weforms-upsell-modal" id="weforms-upsell-modal">
83 <a class="close">
84 &times;
85 <span class="screen-reader-text">Close modal window</span>
86 </a>
87 <div class="video-wrap">
88 <iframe id="weforms-upsell-modal-iframe" width="1280" height="720" src="" frameborder="0" allowfullscreen></iframe>
89 </div>
90
91 <div class="learn-more">
92 <a href="<?php echo esc_url( $this->learn_more_link() ); ?>" target="_blank" class="button button-primary">Learn more about weForms</a>
93 </div>
94 </div>
95 <div class="weforms-upsell-modal-backdrop" id="weforms-upsell-modal-backdrop"></div>
96
97 <style type="text/css">
98 div#weforms-upsell-prompt * {
99 box-sizing: border-box;
100 }
101
102 div#weforms-upsell-prompt {
103 display: flex;
104 flex-direction: row;
105 flex-wrap: nowrap;
106 justify-content: flex-start;
107 align-content: flex-start;
108 align-items: flex-start;
109 position: relative;
110 border: none;
111 margin: 5px 0 15px;
112 padding: 0 0 0 10px;
113 }
114
115 .weforms-upsell-logo {
116 margin: 0;
117 height: 71px;
118 order: 0;
119 flex: 0 1 272px;
120 align-self: auto;
121 padding-left: 15px;
122 }
123
124 .weforms-upsell-text {
125 background: #46b450;
126 color: #fff;
127 padding: 0;
128 height: 71px;
129 margin-left: -35px;
130 order: 0;
131 flex: 1 1 auto;
132 align-self: auto;
133 }
134
135 .weforms-upsell-text h2 {
136 color: #fff;
137 margin: 10px 0;
138 }
139
140 .weforms-upsell-cta {
141 text-align: center;
142 order: 0;
143 flex: 0 1 220px;
144 align-self: auto;
145 padding-top: 20px;
146 vertical-align: middle;
147 height: 71px;
148 line-height: 28px;
149 }
150
151 .weforms-upsell-modal {
152 background: #fff;
153 position: fixed;
154 top: 5%;
155 bottom: 5%;
156 right: 10%;
157 left: 10%;
158 display: none;
159 box-shadow: 0 1px 20px 5px rgba(0, 0, 0, 0.1);
160 z-index: 160000;
161 }
162
163 .weforms-upsell-modal .video-wrap {
164 position: relative;
165 padding-bottom: 56.25%; /* 16:9 */
166 padding-top: 25px;
167 height: 0;
168 }
169
170 .weforms-upsell-modal .video-wrap iframe {
171 position: absolute;
172 top: 0;
173 left: 0;
174 width: 100%;
175 height: 100%;
176 }
177
178 .weforms-upsell-modal .learn-more {
179 position: absolute;
180 bottom: 0;
181 right: 10px;
182 background: #fff;
183 padding: 10px;
184 border-radius: 3px;
185 }
186
187 .weforms-upsell-modal a.close {
188 position: absolute;
189 top: 20px;
190 right: -60px;
191 font: 300 1.71429em "dashicons" !important;
192 content: '\f335';
193 display: inline-block;
194 padding: 10px 20px 0 20px;
195 z-index: 5;
196 text-decoration: none;
197 height: 40px;
198 cursor: pointer;
199 background: #000;
200 color: #fff;
201 border-radius: 50%;
202 }
203
204 .weforms-upsell-modal-backdrop {
205 position: fixed;
206 z-index: 159999;
207 top: 0;
208 left: 0;
209 right: 0;
210 bottom: 0;
211 min-height: 360px;
212 background: #000;
213 opacity: .7;
214 display: none;
215 }
216
217 .weforms-upsell-modal.show,
218 .weforms-upsell-modal-backdrop.show {
219 display: block;
220 }
221 </style>
222
223 <script type="text/javascript">
224 (function ($) {
225 var wrapper = $('#weforms-upsell-prompt'),
226 modal = $('#weforms-upsell-modal'),
227 modalBackdrop = $('#weforms-upsell-modal-backdrop'),
228 iframe = $('#weforms-upsell-modal-iframe');
229
230 wrapper.on('click', '#weforms-upsell-prompt-btn', function (e) {
231 var self = $(this);
232
233 e.preventDefault();
234 self.addClass('install-now updating-message');
235 self.text('<?php echo esc_js( 'Installing...' ); ?>');
236
237 wp.ajax.send( 'weforms_upsell_installer', {
238 data: {
239 _wpnonce: '<?php echo esc_html( wp_create_nonce( 'weforms_upsell_installer' ) ); ?>'
240 },
241
242 success: function(response) {
243 self.text('<?php echo esc_js( 'Installed' ); ?>');
244 window.location.href = '<?php echo esc_url( admin_url( 'admin.php?page=weforms' ) ); ?>';
245 },
246
247 error: function(error) {
248 self.removeClass('install-now updating-message');
249 alert( error );
250 },
251
252 complete: function() {
253 self.attr('disabled', 'disabled');
254 self.removeClass('install-now updating-message');
255 }
256 });
257 });
258
259 wrapper.on('click', '.notice-dismiss', function (e) {
260 e.preventDefault();
261
262 var self = $(this);
263
264 wp.ajax.send( 'weforms_upsell_dismiss' );
265
266 self.closest('.updated').slideUp('fast', function() {
267 self.remove();
268 });
269 });
270
271 wrapper.on('click', 'a.learn-more', function(e) {
272 e.preventDefault();
273
274 modal.addClass('show');
275 modalBackdrop.addClass('show');
276
277 iframe.attr( 'src', 'https://www.youtube.com/embed/sqP-nvyqUdQ?rel=0&amp;controls=0&amp;showinfo=0&amp;autoplay=1' );
278 });
279
280 $('body').on('click', '.weforms-upsell-modal a.close', function(e) {
281 e.preventDefault();
282
283 console.log('close modal');
284
285 modal.removeClass('show');
286 modalBackdrop.removeClass('show');
287
288 iframe.attr( 'src', '' );
289 });
290 })(jQuery);
291 </script>
292 <?php
293 }
294
295 /**
296 * Check if the notice is dimissed
297 *
298 * @return bool
299 */
300 public function is_dismissed() {
301 return 'yes' == get_option( 'weforms_upsell_dismiss', 'no' );
302 }
303
304 /**
305 * Dismiss the weForms notice
306 *
307 * @return void
308 */
309 public function dismiss_notice() {
310 update_option( 'weforms_upsell_dismiss', 'yes' );
311 }
312
313 /**
314 * Learn more link, append affiliate link if present
315 *
316 * @return string
317 */
318 public function learn_more_link() {
319 $link = $this->learn_more;
320
321 if ( ! empty( $this->affiliate ) ) {
322 $link = add_query_arg( [ 'ref' => $this->affiliate ], $link );
323 }
324
325 return $link;
326 }
327
328 /**
329 * Fail if plugin installtion/activation fails
330 *
331 * @param object $thing
332 *
333 * @return void
334 */
335 public function fail_on_error( $thing ) {
336 if ( is_wp_error( $thing ) ) {
337 wp_send_json_error( $thing->get_error_message() );
338 }
339 }
340
341 /**
342 * Install weForms
343 *
344 * @return void
345 */
346 public function install_weforms() {
347 check_ajax_referer( 'weforms_upsell_installer' );
348
349 if ( ! current_user_can( 'manage_options' ) ) {
350 wp_send_json_error( __( 'You don\'t have permission to install the plugins' ) );
351 }
352
353 if ( ! class_exists( 'WP_User_Frontend' ) ) {
354 $wpuf_status = $this->install_plugin( 'wp-user-frontend', 'wpuf.php' );
355
356 $this->fail_on_error( $wpuf_status );
357 }
358
359 $weforms_status = $this->install_plugin( 'weforms', 'weforms.php' );
360 $this->fail_on_error( $weforms_status );
361
362 $this->dismiss_notice();
363
364 if ( ! empty( $this->affiliate ) ) {
365 update_option( '_weforms_aff_ref', $this->affiliate );
366 }
367
368 wp_send_json_success();
369 }
370
371 /**
372 * Install and activate a plugin
373 *
374 * @param string $slug
375 * @param string $file
376 *
377 * @return WP_Error|null
378 */
379 public function install_plugin( $slug, $file ) {
380 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
381 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
382
383 $plugin_basename = $slug . '/' . $file;
384
385 // if exists and not activated
386 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_basename ) ) {
387 return activate_plugin( $plugin_basename );
388 }
389
390 // seems like the plugin doesn't exists. Download and activate it
391 $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
392
393 $api = plugins_api( 'plugin_information', [ 'slug' => $slug, 'fields' => [ 'sections' => false ] ] );
394 $result = $upgrader->install( $api->download_link );
395
396 if ( is_wp_error( $result ) ) {
397 return $result;
398 }
399
400 return activate_plugin( $plugin_basename );
401 }
402
403 /**
404 * Dismiss the notice via Ajax
405 *
406 * @return void
407 */
408 public function dismiss_weforms_notice() {
409 $this->dismiss_notice();
410
411 wp_send_json_success();
412 }
413 }
414 }
415