PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.2
EmailKit – Email Customizer for WooCommerce & WP v1.5.2
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / vendor / wpmet / utility-package / src / Plugins / Plugins.php

Plugins.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.2, at vendor/wpmet/utility-package/src/Plugins/Plugins.php

723 lines 17.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Wpmet\UtilityPackage\Plugins;
4
5 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * Description: Wpmet Apps class. This class is used to display the wpmet other plugins
9 *
10 * @package Wpmet\UtilityPackage
11 * @subpackage Wpmet\UtilityPackage\Plugins
12 * @author Wpmet
13 *
14 * @since 1.0.0
15 */
16 class Plugins {
17
18 private static $instance;
19 private $text_domain;
20 private $parent_menu_slug;
21 private $menu_slug = '_wpmet_plugins';
22 private $submenu_name = 'Our Plugins';
23 private $plugins = [];
24 public $items_per_row = 4;
25 private $section_title = 'Take your website to the next level';
26 private $section_description = 'We have some plugins you can install to get most from Wordpress. These are absolute FREE to use.';
27 private $installed_plugins = [];
28 private $activated_plugins = [];
29 /**
30 * Creates and returns an instance of the class.
31 *
32 * @return self
33 *
34 * @since 1.0.0
35 */
36 public static function instance() {
37
38 if ( !self::$instance ) {
39 self::$instance = new self();
40 }
41
42 return self::$instance;
43 }
44
45 /**
46 * Initializes the function.
47 *
48 * @param string $text_domain The text domain.
49 * @return $this
50 *
51 * @since 1.0.0
52 */
53 public function init( $text_domain ) {
54
55 $this->set_text_domain( $text_domain );
56 $this->collect_installed_plugins();
57 $this->collect_activated_plugins();
58
59 add_action('admin_head', [$this, 'enqueue_scripts']);
60
61 return $this;
62 }
63
64 /**
65 * Set the section title.
66 *
67 * @param string $title The title of the section.
68 * @return $this The current object instance.
69 *
70 * @since 1.0.0
71 */
72 public function set_section_title( $title ){
73
74 $this->section_title = $title;
75
76 return $this;
77 }
78
79 /**
80 * Sets the description for the section.
81 *
82 * @param mixed $description The description for the section.
83 * @return $this
84 *
85 * @since 1.0.0
86 */
87 public function set_section_description( $description ){
88
89 $this->section_description = $description;
90
91 return $this;
92 }
93
94 /**
95 * Sets the number of items per row.
96 *
97 * @param int $items The number of items per row.
98 * @return $this The current object instance.
99 *
100 * @since 1.0.0
101 */
102 public function set_items_per_row( $items ){
103
104 $this->items_per_row = $items;
105
106 return $this;
107 }
108
109 /**
110 * Set the text domain for the object.
111 *
112 * @param mixed $val The value to set as the text domain.
113 * @return $this The current object instance.
114 *
115 * @since 1.0.0
116 */
117 protected function set_text_domain( $val ) {
118
119 $this->text_domain = $val;
120
121 return $this;
122 }
123
124 /**
125 * Sets the submenu name.
126 *
127 * @param string $submenu_name The name of the submenu.
128 * @return $this The current instance of the class.
129 *
130 * @since 1.0.0
131 */
132 public function set_submenu_name( $submenu_name ){
133
134 $this->submenu_name = $submenu_name;
135
136 return $this;
137 }
138
139 /**
140 * Set the parent menu slug.
141 *
142 * @param string $slug The slug of the parent menu.
143 * @return $this The current object.
144 */
145 public function set_parent_menu_slug( $slug ) {
146
147 $this->parent_menu_slug = $slug;
148
149 return $this;
150 }
151
152 /**
153 * Sets the menu slug for the object.
154 *
155 * @param string $slug The slug to set for the menu.
156 * @return $this Returns the current object.
157 *
158 * @since 1.0.0
159 */
160 public function set_menu_slug( $slug ) {
161
162 $this->menu_slug = $slug;
163
164 return $this;
165 }
166
167 /**
168 * Set the plugins for the object.
169 *
170 * @param array $plugins An array of plugins.
171 * @return $this The current instance.
172 *
173 * @since 1.0.0
174 */
175 public function set_plugins( $plugins = [] ) {
176
177 $this->plugins = $plugins;
178
179 return $this;
180 }
181
182 /**
183 * Registers a menu in the WordPress admin dashboard.
184 *
185 * @return void
186 *
187 * @since 1.0.0
188 */
189 protected function register_menu() {
190
191 add_submenu_page(
192 $this->parent_menu_slug,
193 $this->submenu_name,
194 '<span style="color: #2fbf17; font-weight: bold">' . $this->submenu_name . '</span>',
195 'manage_options',
196 $this->text_domain . $this->menu_slug,
197 [$this, 'wpmet_apps_renderer']
198 );
199 }
200
201 /**
202 * Generates the menus.
203 *
204 * @return void
205 *
206 * @since 1.0.0
207 */
208 public function generate_menus() {
209
210 if( !empty($this->parent_menu_slug) ) {
211
212 $this->register_menu();
213 }
214 }
215
216 /**
217 * Admin menu registration hook.
218 *
219 * @return void
220 *
221 * @since 1.0.0
222 */
223 public function call() {
224
225 add_action('admin_menu', [$this, 'generate_menus'], 99999);
226 }
227
228 /**
229 * Activation URL
230 *
231 * @since 1.0.0
232 * @param string $pluginName The name of the plugin.
233 * @return string
234 */
235 public function activation_url( $pluginName ) {
236
237 return wp_nonce_url( add_query_arg(
238 array(
239 'action' => 'activate',
240 'plugin' => $pluginName,
241 'plugin_status' => 'all',
242 'paged' => '1&s',
243 ),
244 admin_url( 'plugins.php' )
245 ), 'activate-plugin_' . $pluginName );
246 }
247
248 /**
249 * Installation URL
250 *
251 * @since 1.0.0
252 * @param string $pluginName The name of the plugin.
253 * @return string
254 */
255 public function installation_url( $pluginName ) {
256 $action = 'install-plugin';
257 $pluginSlug = $this->get_plugin_slug( $pluginName );
258
259 return wp_nonce_url(
260 add_query_arg(
261 array(
262 'action' => $action,
263 'plugin' => $pluginSlug
264 ),
265 admin_url( 'update.php' )
266 ),
267 $action . '_' . $pluginSlug
268 );
269 }
270
271 /**
272 * Get plugin slug
273 *
274 * @since 1.0.0
275 * @param string $name The name of the plugin.
276 * @return string
277 */
278 public function get_plugin_slug( $name ) {
279
280 $split = explode( '/', $name );
281
282 return isset( $split[0] ) ? $split[0] : null;
283 }
284
285 /**
286 * Activated URL
287 *
288 * @since 1.0.0
289 * @param string $pluginName The name of the plugin.
290 * @return string
291 */
292 public function activated_url( $pluginName ) {
293 return add_query_arg(
294 array(
295 'page' => $this->get_plugin_slug( $pluginName ),
296 ),
297 admin_url( 'admin.php' ) );
298 }
299
300 /**
301 * Collect installed plugins
302 *
303 * @since 1.0.0
304 * @return void
305 */
306 private function collect_installed_plugins() {
307
308 if( !function_exists('get_plugins') ) {
309 include_once ABSPATH . 'wp-admin/includes/plugin.php';
310 }
311
312 foreach ( get_plugins() as $key => $plugin ) {
313 array_push( $this->installed_plugins, $key );
314 }
315 }
316
317 /**
318 * Collect activated plugins
319 *
320 * @since 1.0.0
321 * @return void
322 */
323 private function collect_activated_plugins() {
324 foreach ( apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) as $plugin ) {
325 array_push( $this->activated_plugins, $plugin );
326 }
327 }
328
329 /**
330 * Check installed plugin
331 *
332 * @since 1.0.0
333 * @param string $name The name of the plugin.
334 * @return bool
335 */
336 public function check_installed_plugin( $name ) {
337 return in_array( $name, $this->installed_plugins );
338 }
339
340 /**
341 * Check activated plugin
342 *
343 * @since 1.0.0
344 * @param string $name The name of the plugin.
345 * @return bool
346 */
347 public function check_activated_plugin( $name ) {
348 return in_array( $name, $this->activated_plugins );
349 }
350
351 /**
352 * Get plugin status
353 *
354 * @since 1.0.0
355 * @param string $name The name of the plugin.
356 * @return array
357 */
358 public function get_plugin_status( $name ) {
359 $data = [
360 "url" => "",
361 "activation_url" => "",
362 "installation_url" => "",
363 "title" => "",
364 "status" => "",
365 ];
366
367 if ( $this->check_installed_plugin( $name ) ) {
368 if ( $this->check_activated_plugin( $name ) ) {
369 $data['title'] = __( 'Activated', 'emailkit' );
370 $data['status'] = "activated";
371 } else {
372 $data['title'] = __( 'Activate Now', 'emailkit' );
373 $data['status'] = 'installed';
374 $data['activation_url'] = $this->activation_url( $name );
375 }
376 } else {
377 $data['title'] = __( 'Install Now', 'emailkit' );
378 $data['status'] = 'not_installed';
379 $data['installation_url'] = $this->installation_url( $name );
380 $data['activation_url'] = $this->activation_url( $name );
381 }
382
383 return $data;
384 }
385
386 /**
387 * Display the Wpmet apps section.
388 *
389 * @return void
390 *
391 * @since 1.0.0
392 */
393 public function wpmet_apps_renderer() {
394 ?>
395 <div class="wpmet-onboard-dashboard">
396 <div class="wpmet-onboard-main-header">
397 <h1 class="wpmet-onboard-main-header--title"><strong><?php echo esc_html($this->section_title); ?></strong></h1>
398 <p class="wpmet-onboard-main-header--description"><?php echo esc_html($this->section_description); ?></p>
399 </div>
400
401 <div class="wpmet-onboard-plugin-list">
402 <div class="attr-row">
403 <?php
404 foreach( $this->plugins as $key => $plugin ):
405 $img_url = isset($plugin['icon']) ? $plugin['icon'] : '#';
406 $plugin_name = isset($plugin['name']) ? $plugin['name'] : '';
407 $plugin_desc = isset($plugin['desc']) ? $plugin['desc'] : '';
408 $plugin_docs = isset($plugin['docs']) ? $plugin['docs'] : '';
409 ?>
410 <div class="attr-col-lg-4">
411 <div class="wpmet-onboard-single-plugin">
412 <label>
413 <img class="wpmet-onboard-single-plugin--logo" src="<?php echo esc_url($img_url); ?>" alt="<?php echo esc_attr($plugin_name);?>">
414 <h4 class="wpmet-single-plugin--name"><?php echo esc_html($plugin_name); ?></h4>
415 <p class="wpmet-onboard-single-plugin--description"><?php echo esc_html($plugin_desc); ?></p>
416 <?php
417 $plugin_data = $this->get_plugin_status( $key );
418 $plugin_status = isset( $plugin_data['status'] ) ? $plugin_data['status'] : '';
419 $plugin_activation_url = isset( $plugin_data['activation_url'] ) ? $plugin_data['activation_url'] : '';
420 $plugin_installation_url = isset( $plugin_data['installation_url'] ) ? $plugin_data['installation_url'] : '';
421 $plugin_status_label = isset( $plugin_data['status'] ) ? ( $plugin_data['status'] == 'activated' ? 'activated' : '' ) : '';
422 $plugin_status_title = isset( $plugin_data['title'] ) ? $plugin_data['title'] : esc_html__('Activate', 'emailkit');
423 ?>
424 <div class="wpmet-apps-footer">
425 <?php
426 echo sprintf(
427 '<a data-plugin_status="%1$s" data-activation_url="%2$s" href="%3$s" class="wpmet-pro-btn wpmet-onboard-single-plugin--install_plugin %4$s">%5$s</a>',
428 esc_attr($plugin_status),
429 esc_url($plugin_activation_url),
430 esc_url($plugin_installation_url),
431 esc_attr($plugin_status_label),
432 esc_html($plugin_status_title)
433 );
434
435 if( !empty($plugin_docs) ) :
436 echo sprintf(
437 '<a target="_blank" href="%1$s" class="">%2$s</a>',
438 esc_url($plugin_docs),
439 esc_html__('Read Docs', 'emailkit')
440 );
441 endif;
442 ?>
443 </div>
444 </label>
445 </div>
446 </div>
447 <?php endforeach; ?>
448 </div>
449 </div>
450 </div>
451 <?php
452 }
453
454 /**
455 * Enqueues scripts for the plugin.
456 *
457 * This function is responsible for enqueueing the necessary JavaScript scripts for the plugin.
458 *
459 * @return void
460 *
461 * @since 1.0.0
462 */
463 public function enqueue_scripts(){
464 ?>
465 <style>
466 .wpmet-onboard-dashboard .wpmet-onboard-plugin-list .attr-row {
467 margin-left: -11px;
468 margin-right: -11px;
469 display: -webkit-box;
470 display: grid;
471 gap: 5px;
472 grid-template-columns: repeat(<?php echo esc_attr($this->items_per_row); ?>, 1fr);
473 }
474 .wpmet-onboard-dashboard .wpmet-onboard-plugin-list .attr-row > div {
475 padding: 11px;
476 }
477 .wpmet-onboard-main-header{
478 margin-bottom: 30px;
479 }
480 .wpmet-onboard-dashboard .wpmet-onboard-main-header--title{
481 color: #021343;
482 font-size: 40px;
483 line-height: 54px;
484 font-weight: normal;
485 margin: 0 0 3px 0;
486 padding: 0;
487 }
488 .wpmet-onboard-dashboard .wpmet-onboard-main-header--title strong{
489 font-weight: 700;
490 }
491 .wpmet-onboard-dashboard .wpmet-onboard-main-header--description{
492 color: #5d5e65;
493 font-size: 16px;
494 line-height: 26px;
495 margin: 0;
496 }
497 [class^="attr"] {
498 -webkit-box-sizing: border-box;
499 box-sizing: border-box;
500 }
501 .wpmet-onboard-dashboard {
502 background-color: #F5F6F9;
503 margin-left: -20px;
504 padding: 30px;
505 position: absolute;
506 top: 0;
507 left: 0;
508 z-index: 1;
509 width: calc(100% + 20px);
510 -webkit-box-sizing: border-box;
511 box-sizing: border-box;
512 min-height: calc(100vh - 32px);
513 padding-top: 30px;
514 padding-bottom: 100px;
515 }
516 .wpmet-onboard-dashboard .wpmet-pro-btn {
517 color: #3E77FC;
518 font-size: 15px;
519 line-height: 18px;
520 background-color: transparent;
521 font-weight: 500;
522 border: 1.5px solid #3E77FC;
523 border-radius: 6px;
524 padding: 11px 32px;
525 -webkit-transition: all .4s;
526 transition: all .4s;
527 text-decoration: none;
528 display: inline-block;
529 }
530 .wpmet-onboard-dashboard .wpmet-pro-btn:hover {
531 background-color: #3E77FC;
532 color: #fff;
533 }
534 .wpmet-onboard-dashboard .wpmet-pro-btn:focus {
535 border-color: #3E77FC;
536 -webkit-box-shadow: none;
537 box-shadow: none;
538 }
539 .wpmet-onboard-dashboard .wpmet-pro-btn .icon {
540 position: relative;
541 top: 1px;
542 }
543 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin {
544 background-color: #fff;
545 border-radius: 6px;
546 -webkit-box-shadow: 0 30px 50px rgba(0, 10, 36, 0.1);
547 box-shadow: 0 30px 50px rgba(0, 10, 36, 0.1);
548 position: relative;
549 min-height: 320px;
550 }
551 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin label {
552 display: block;
553 padding: 30px 40px 36px 30px;
554 cursor: default;
555 }
556 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin .badge--featured {
557 position: absolute;
558 right: -20px;
559 top: -30px;
560 height: 100px;
561 }
562 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--install {
563 color: #021343;
564 font-size: 15px;
565 font-weight: 500;
566 display: block;
567 border: 2px solid #E4E6EE;
568 border-radius: 6px;
569 min-height: 175px;
570 line-height: 175px;
571 position: relative;
572 text-decoration: none;
573 }
574 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--install i {
575 padding-left: 9px;
576 font-weight: bold;
577 }
578 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--description {
579 color: #5D5E65;
580 font-size: 15px;
581 line-height: 22px;
582 font-weight: 400;
583 margin: 0;
584 }
585 .wpmet-onboard-dashboard .wpmet-single-plugin--name {
586 display: block;
587 font-size: 1.6rem;
588 line-height: normal;
589 text-decoration: none;
590 margin: 0px;
591 font-weight: 600;
592 color: #021343;
593 margin-top: 5px;
594 margin-bottom: 15px;
595 }
596 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--description span {
597 background: #d7a1f973;
598 color: #021343;
599 font-weight: 500;
600 }
601 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--logo {
602 max-width: 60px;
603 }
604 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--install_plugin {
605 padding: 5px 20px 7px 20px;
606 }
607 .wpmet-onboard-dashboard .wpmet-apps-footer{
608 position: absolute;
609 bottom: 30px;
610 width: 80%;
611 display: flex;
612 justify-content: space-between;
613 align-items: baseline;
614 background: #fff;
615 padding-top: 5px;
616 }
617 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--install_plugin.wpmet-plugin-install-activate {
618 cursor: no-drop;
619 background-color: #E8E9EF;
620 color: #5D5E65;
621 border-color: #E8E9EF;
622 }
623 .wpmet-onboard-dashboard .wpmet-onboard-single-plugin--install_plugin.activated {
624 cursor: default;
625 border: 1px solid #2AAE1433;
626 background: rgba(42, 174, 20, 0.1);
627 color: #2AAE14;
628 }
629 .wpmet-onboard-dashboard .wpmet-onboard-tut-term--help {
630 margin: 0;
631 color: #021343;
632 font-size: 14px;
633 font-weight: 500;
634 line-height: 26px;
635 margin-top: 10px;
636 cursor: pointer;
637 }
638 .wpmet-onboard-dashboard .wpmet-onboard-tut-term--help:hover {
639 color: #3E77FC;
640 }
641 .wpmet-onboard-dashboard .wpmet-onboard-tut-term--help.active {
642 color: #3E77FC;
643 }
644 @media (max-width: 2000px) {
645 .wpmet-onboard-dashboard .wpmet-onboard-plugin-list .attr-row {
646 grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
647 }
648 }
649 @media (max-width: 500px) {
650 .wpmet-onboard-dashboard .wpmet-onboard-plugin-list .attr-row {
651 grid-template-columns: repeat(auto-fit, minmax(100%, 1fr));
652 }
653 }
654 @media (max-width: 991px) {
655 body .wpmet-onboard-dashboard img {
656 max-width: 100%;
657 }
658 }
659 @media (max-width: 480px) {
660 body .wpmet-onboard-dashboard .wpmet-onboard-single-plugin label {
661 -webkit-box-align: center;
662 -ms-flex-align: center;
663 align-items: center;
664 }
665 }
666 </style>
667
668 <script type="text/javascript">
669 jQuery( document ).ready( function( $ ) {
670 // installing plugin
671 function wpmet_install_active_plugin(ajaxurl, success_callback, beforeText, successText){
672 $.ajax({
673 type : "GET",
674 url : ajaxurl,
675 beforeSend: () => {
676 $(this).addClass('wpmet-plugin-install-activate');
677 if(beforeText){
678 $(this).html(beforeText);
679 }
680 },
681 success: (response) => {
682 $(this).removeClass('wpmet-plugin-install-activate');
683
684 if(ajaxurl.indexOf('action=activate') >= 0){
685 $(this).addClass('activated');
686 }
687
688 $(this).html(successText);
689
690 if(success_callback){success_callback();}
691 }
692 });
693 }
694
695 $('.wpmet-onboard-single-plugin--install_plugin').on('click', function(e){
696 e.preventDefault();
697 var installation_url = $(this).attr('href'),
698 activation_url = $(this).attr('data-activation_url'),
699 plugin_status = $(this).data('plugin_status');
700
701 if($(this).hasClass('wpmet-plugin-install-activate') || $(this).hasClass('activated')){
702 return false;
703 }
704
705 if(plugin_status == 'not_installed'){
706 wpmet_install_active_plugin.call(this, installation_url, () => {
707 wpmet_install_active_plugin.call(this, activation_url, null, 'Activating...', 'Activated');
708 }, 'Installing...', 'Installed');
709 } else if (plugin_status == 'installed') {
710 wpmet_install_active_plugin.call(this, activation_url, null, 'Activating...', 'Activated');
711 }
712 });
713
714 jQuery('.wpmet-onboard-tut-term--help').on('click', function(){
715 $(this).toggleClass('active').prev().toggleClass('active');
716 });
717
718 });
719 </script>
720 <?php
721 }
722 }
723