PluginProbe
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables / 2.2.2
TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables v2.2.2
2.2.14 2.2.13 2.2.12 2.2.11 2.2.10 2.2.9 2.2.8 2.2.7 2.2.6 2.2.5 2.2.4 2.2.3 trunk 1.0.0 1.0.1 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2
table-builder-block / scoped / vendor / wpmet / utility-package / src / Plugins / Plugins.php

Plugins.php in TableKit – WordPress Table Builder for Data Tables, WooCommerce Product Tables & Post Tables 2.2.2, at scoped/vendor/wpmet/utility-package/src/Plugins/Plugins.php

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