| 1 |
<?php |
| 2 |
/** |
| 3 |
* Selection Lite |
| 4 |
* Carefully selected Elementor addons bundle, for building the most awesome websites |
| 5 |
* |
| 6 |
* @encoding UTF-8 |
| 7 |
* @version 1.12 |
| 8 |
* @copyright (C) 2018-2024 Merkulove ( https://merkulov.design/ ). All rights reserved. |
| 9 |
* @license GPLv3 |
| 10 |
* @contributors merkulove, vladcherviakov, phoenixmkua, podolianochka, viktorialev01 |
| 11 |
* @support help@merkulov.design |
| 12 |
**/ |
| 13 |
|
| 14 |
namespace Merkulove\SelectionLite\Unity; |
| 15 |
|
| 16 |
/** Exit if accessed directly. */ |
| 17 |
if ( ! defined( 'ABSPATH' ) ) { |
| 18 |
header( 'Status: 403 Forbidden' ); |
| 19 |
header( 'HTTP/1.1 403 Forbidden' ); |
| 20 |
exit; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Plugin class used to prepare plugin variables. |
| 25 |
* It can be called in any time and work without any dependencies. |
| 26 |
* |
| 27 |
* @since 1.0 |
| 28 |
* |
| 29 |
**/ |
| 30 |
final class Plugin { |
| 31 |
|
| 32 |
/** |
| 33 |
* Plugin version. |
| 34 |
* |
| 35 |
* @since 1.0 |
| 36 |
* @access private |
| 37 |
* @var string |
| 38 |
**/ |
| 39 |
private static $version; |
| 40 |
|
| 41 |
/** |
| 42 |
* Plugin name. |
| 43 |
* |
| 44 |
* @since 1.0 |
| 45 |
* @access private |
| 46 |
* @var string |
| 47 |
**/ |
| 48 |
private static $name; |
| 49 |
|
| 50 |
/** |
| 51 |
* Using minified css and js files if SCRIPT_DEBUG is turned off. |
| 52 |
* |
| 53 |
* @since 1.0 |
| 54 |
* @access private |
| 55 |
* @var string |
| 56 |
**/ |
| 57 |
private static $suffix; |
| 58 |
|
| 59 |
/** |
| 60 |
* URL to plugin folder, with trailing slash. |
| 61 |
* |
| 62 |
* @since 1.0 |
| 63 |
* @access private |
| 64 |
* @var string |
| 65 |
**/ |
| 66 |
private static $url; |
| 67 |
|
| 68 |
/** |
| 69 |
* Full PATH to plugin folder, with trailing slash. |
| 70 |
* |
| 71 |
* @since 1.0 |
| 72 |
* @access private |
| 73 |
* @var string |
| 74 |
**/ |
| 75 |
private static $path; |
| 76 |
|
| 77 |
/** |
| 78 |
* Plugin base name. |
| 79 |
* |
| 80 |
* @since 1.0 |
| 81 |
* @access private |
| 82 |
* @var string |
| 83 |
**/ |
| 84 |
private static $basename; |
| 85 |
|
| 86 |
/** |
| 87 |
* Plugin admin menu bases. |
| 88 |
* |
| 89 |
* @since 1.0 |
| 90 |
* @access private |
| 91 |
* @var array |
| 92 |
**/ |
| 93 |
private static $menu_bases = []; |
| 94 |
|
| 95 |
/** |
| 96 |
* Full path to main plugin file. |
| 97 |
* |
| 98 |
* @since 1.0 |
| 99 |
* @access private |
| 100 |
* @var string |
| 101 |
**/ |
| 102 |
private static $plugin_file; |
| 103 |
|
| 104 |
/** |
| 105 |
* Plugin slug. |
| 106 |
* |
| 107 |
* @since 1.0 |
| 108 |
* @access private |
| 109 |
* @var string |
| 110 |
**/ |
| 111 |
private static $slug; |
| 112 |
|
| 113 |
/** |
| 114 |
* Plugin type. |
| 115 |
* |
| 116 |
* @since 1.0 |
| 117 |
* @access private |
| 118 |
* @var string |
| 119 |
**/ |
| 120 |
private static $type; |
| 121 |
|
| 122 |
/** |
| 123 |
* Settings Tabs. |
| 124 |
* |
| 125 |
* Holds the list of all tabs and fields with settings. |
| 126 |
* |
| 127 |
* @since 1.0 |
| 128 |
* @access private |
| 129 |
* @var array |
| 130 |
**/ |
| 131 |
private static $tabs; |
| 132 |
|
| 133 |
/** |
| 134 |
* The one true Plugin. |
| 135 |
* |
| 136 |
* @since 1.0 |
| 137 |
* @access private |
| 138 |
* @var Plugin |
| 139 |
**/ |
| 140 |
private static $instance; |
| 141 |
|
| 142 |
/** |
| 143 |
* Sets up a new Plugin instance. |
| 144 |
* |
| 145 |
* @since 1.0 |
| 146 |
* @access private |
| 147 |
* |
| 148 |
* @return void |
| 149 |
**/ |
| 150 |
private function __construct() { |
| 151 |
|
| 152 |
/** Initialize main variables. */ |
| 153 |
$this->initialization(); |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Initialize main variables. |
| 159 |
* |
| 160 |
* @since 1.0 |
| 161 |
* @access private |
| 162 |
* |
| 163 |
* @return void |
| 164 |
**/ |
| 165 |
private function initialization() { |
| 166 |
|
| 167 |
/** Full path to main plugin file. */ |
| 168 |
self::$plugin_file = dirname( dirname( dirname( __DIR__ ) ) ) . '/selection-lite.php'; |
| 169 |
|
| 170 |
/** Set Plugin version. */ |
| 171 |
self::$version = self::get_plugin_data( 'Version' ); |
| 172 |
|
| 173 |
/** Set Plugin name. */ |
| 174 |
self::$name = self::get_plugin_data( 'Name' ); |
| 175 |
|
| 176 |
/** Plugin slug. */ |
| 177 |
self::$slug = self::get_plugin_data( 'TextDomain' ); |
| 178 |
|
| 179 |
/** Plugin type. */ |
| 180 |
self::$type = self::extract_plugin_type(); |
| 181 |
|
| 182 |
/** Gets the plugin URL (with trailing slash). */ |
| 183 |
self::$url = plugin_dir_url( self::$plugin_file ); |
| 184 |
|
| 185 |
/** Gets the plugin PATH. */ |
| 186 |
self::$path = plugin_dir_path( self::$plugin_file ); |
| 187 |
|
| 188 |
/** Using minified css and js files if SCRIPT_DEBUG is turned off. */ |
| 189 |
self::$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 190 |
|
| 191 |
/** Set plugin basename. */ |
| 192 |
self::$basename = plugin_basename( self::$plugin_file ); |
| 193 |
|
| 194 |
/** Plugin settings page menu base. There may be several. */ |
| 195 |
/** For Elementor plugins. */ |
| 196 |
if ( 'elementor' === self::$type ) { |
| 197 |
|
| 198 |
self::$menu_bases[] = 'elementor_page_mdp_selection_lite_settings'; |
| 199 |
self::$menu_bases[] = 'settings_page_mdp_selection_lite_settings'; |
| 200 |
|
| 201 |
/** For general WordPress plugins. */ |
| 202 |
} else { |
| 203 |
|
| 204 |
self::$menu_bases[] = 'toplevel_page_mdp_selection_lite_settings'; |
| 205 |
self::$menu_bases[] = 'selection_lite_page_mdp_selection_lite_settings'; |
| 206 |
|
| 207 |
} |
| 208 |
|
| 209 |
/** Fill $tabs field with default settings. */ |
| 210 |
$this->default_settings(); |
| 211 |
|
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Fill $tabs field with default settings. |
| 216 |
* |
| 217 |
* @since 1.0 |
| 218 |
* @access private |
| 219 |
* |
| 220 |
* @return void |
| 221 |
**/ |
| 222 |
private function default_settings() { |
| 223 |
|
| 224 |
/** Add Status Tab. */ |
| 225 |
$this->add_status_tab(); |
| 226 |
|
| 227 |
/** Add Uninstall Tab. */ |
| 228 |
$this->add_uninstall_tab(); |
| 229 |
|
| 230 |
/** Add PRO Tab */ |
| 231 |
$this->add_pro_tab(); |
| 232 |
|
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
/** |
| 237 |
* Add Status Tab to settings page. |
| 238 |
* |
| 239 |
* @since 1.0 |
| 240 |
* @access private |
| 241 |
* |
| 242 |
* @return void |
| 243 |
**/ |
| 244 |
private function add_status_tab() { |
| 245 |
|
| 246 |
self::$tabs['status'] = [ |
| 247 |
'enabled' => true, |
| 248 |
'class' => TabStatus::class, |
| 249 |
'label' => esc_html__( 'Status', 'selection-lite' ), |
| 250 |
'title' => esc_html__( 'System Status', 'selection-lite' ), |
| 251 |
'show_title' => true, |
| 252 |
'icon' => 'info', |
| 253 |
'reports' => [ |
| 254 |
'server' => [ |
| 255 |
'enabled' => true, |
| 256 |
'os' => true, |
| 257 |
'software' => true, |
| 258 |
'mysql_version' => true, |
| 259 |
'php_version' => true, |
| 260 |
'write_permissions' => true, |
| 261 |
'zip_installed' => true, |
| 262 |
'elementor_installed' => true, |
| 263 |
], |
| 264 |
'wordpress' => [ |
| 265 |
'enabled' => true |
| 266 |
], |
| 267 |
'plugins' => [ |
| 268 |
'enabled' => true |
| 269 |
], |
| 270 |
'theme' => [ |
| 271 |
'enabled' => true |
| 272 |
], |
| 273 |
] |
| 274 |
]; |
| 275 |
|
| 276 |
} |
| 277 |
|
| 278 |
/** |
| 279 |
* Add GO PRO Tab |
| 280 |
*/ |
| 281 |
private function add_pro_tab() { |
| 282 |
|
| 283 |
self::$tabs['pro'] = [ |
| 284 |
'enabled' => true, |
| 285 |
'class' => TabPro::class, |
| 286 |
'label' => esc_html__( 'Get PRO', 'selection-lite' ), |
| 287 |
'show_title' => false, |
| 288 |
'icon' => 'info', |
| 289 |
]; |
| 290 |
|
| 291 |
} |
| 292 |
|
| 293 |
/** |
| 294 |
* Add Uninstall Tab to settings page. |
| 295 |
* |
| 296 |
* @since 1.0 |
| 297 |
* @access private |
| 298 |
* |
| 299 |
* @return void |
| 300 |
**/ |
| 301 |
private function add_uninstall_tab() { |
| 302 |
|
| 303 |
self::$tabs['uninstall'] = [ |
| 304 |
'enabled' => true, |
| 305 |
'class' => TabUninstall::class, |
| 306 |
'label' => esc_html__( 'Uninstall', 'selection-lite' ), |
| 307 |
'title' => esc_html__( 'Uninstall Settings', 'selection-lite' ), |
| 308 |
'show_title' => true, |
| 309 |
'icon' => 'delete_sweep', |
| 310 |
'fields' => [ |
| 311 |
'delete_plugin' => [ |
| 312 |
'type' => 'select', |
| 313 |
'options' => [ |
| 314 |
'plugin' => esc_html__( 'Delete plugin only', 'selection-lite' ), |
| 315 |
'plugin+settings' => esc_html__( 'Delete plugin and settings', 'selection-lite' ), |
| 316 |
], |
| 317 |
'default' => 'plugin', |
| 318 |
] |
| 319 |
] |
| 320 |
]; |
| 321 |
|
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Return current plugin metadata. |
| 326 |
* |
| 327 |
* @param string $field - Field name from plugin data. |
| 328 |
* |
| 329 |
* @since 1.0 |
| 330 |
* @access private |
| 331 |
* |
| 332 |
* @return string|array { |
| 333 |
* Plugin data. Values will be empty if not supplied by the plugin. |
| 334 |
* |
| 335 |
* @type string $Name Name of the plugin. Should be unique. |
| 336 |
* @type string $Title Title of the plugin and link to the plugin's site (if set). |
| 337 |
* @type string $Description Carefully selected Elementor addons bundle, for building the most awesome websites. |
| 338 |
* @type string $Author Author's name. |
| 339 |
* @type string $AuthorURI Author's website address (if set). |
| 340 |
* @type string $Version Plugin version. |
| 341 |
* @type string $TextDomain Plugin textdomain. |
| 342 |
* @type string $DomainPath Plugins relative directory path to .mo files. |
| 343 |
* @type bool $Network Whether the plugin can only be activated network-wide. |
| 344 |
* @type string $RequiresWP Minimum required version of WordPress. |
| 345 |
* @type string $RequiresPHP Minimum required version of PHP. |
| 346 |
* } |
| 347 |
**/ |
| 348 |
private static function get_plugin_data( $field ) { |
| 349 |
|
| 350 |
static $plugin_data; |
| 351 |
|
| 352 |
/** We already have $plugin_data. */ |
| 353 |
if ( $plugin_data !== null ) { |
| 354 |
return $plugin_data[$field]; |
| 355 |
} |
| 356 |
|
| 357 |
/** This is first time call of method, so prepare $plugin_data. */ |
| 358 |
if ( ! function_exists('get_plugin_data') ) { |
| 359 |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
| 360 |
} |
| 361 |
|
| 362 |
$plugin_data = get_plugin_data( self::get_plugin_file() ); |
| 363 |
|
| 364 |
return $plugin_data[$field]; |
| 365 |
|
| 366 |
} |
| 367 |
|
| 368 |
/** |
| 369 |
* Get Plugin version. |
| 370 |
* |
| 371 |
* @since 1.0 |
| 372 |
* @access public |
| 373 |
* |
| 374 |
* @return string |
| 375 |
**/ |
| 376 |
public static function get_version() { |
| 377 |
|
| 378 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 379 |
|
| 380 |
return self::$version; |
| 381 |
|
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Get Plugin Name. |
| 386 |
* |
| 387 |
* @since 1.0 |
| 388 |
* @access public |
| 389 |
* |
| 390 |
* @return string |
| 391 |
**/ |
| 392 |
public static function get_name() { |
| 393 |
|
| 394 |
return self::get_plugin_data( 'Name' ); |
| 395 |
|
| 396 |
} |
| 397 |
|
| 398 |
/** |
| 399 |
* Get .min suffix. |
| 400 |
* |
| 401 |
* @since 1.0 |
| 402 |
* @access public |
| 403 |
* |
| 404 |
* @return string |
| 405 |
**/ |
| 406 |
public static function get_suffix() { |
| 407 |
|
| 408 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 409 |
|
| 410 |
return self::$suffix; |
| 411 |
|
| 412 |
} |
| 413 |
|
| 414 |
/** |
| 415 |
* Get URL to plugin folder with trailing slash. |
| 416 |
* |
| 417 |
* @since 1.0 |
| 418 |
* @access public |
| 419 |
* |
| 420 |
* @return string |
| 421 |
**/ |
| 422 |
public static function get_url() { |
| 423 |
|
| 424 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 425 |
|
| 426 |
return self::$url; |
| 427 |
|
| 428 |
} |
| 429 |
|
| 430 |
/** |
| 431 |
* Get full Path to plugin folder with trailing slash. |
| 432 |
* |
| 433 |
* @since 1.0 |
| 434 |
* @access public |
| 435 |
* |
| 436 |
* @return string |
| 437 |
**/ |
| 438 |
public static function get_path() { |
| 439 |
|
| 440 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 441 |
|
| 442 |
return self::$path; |
| 443 |
|
| 444 |
} |
| 445 |
|
| 446 |
/** |
| 447 |
* Get Plugin Basename. |
| 448 |
* |
| 449 |
* @since 1.0 |
| 450 |
* @access public |
| 451 |
* |
| 452 |
* @return string |
| 453 |
**/ |
| 454 |
public static function get_basename() { |
| 455 |
|
| 456 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 457 |
|
| 458 |
return self::$basename; |
| 459 |
|
| 460 |
} |
| 461 |
|
| 462 |
/** |
| 463 |
* Get plugin menu bases. |
| 464 |
* |
| 465 |
* @since 1.0 |
| 466 |
* @access public |
| 467 |
* |
| 468 |
* @return array |
| 469 |
**/ |
| 470 |
public static function get_menu_bases() { |
| 471 |
|
| 472 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 473 |
|
| 474 |
return self::$menu_bases; |
| 475 |
|
| 476 |
} |
| 477 |
|
| 478 |
/** |
| 479 |
* Get path to plugin file. |
| 480 |
* |
| 481 |
* @since 1.0 |
| 482 |
* @access public |
| 483 |
* |
| 484 |
* @return string |
| 485 |
**/ |
| 486 |
public static function get_plugin_file() { |
| 487 |
|
| 488 |
return dirname( dirname( dirname( __DIR__ ) ) ) . '/selection-lite.php'; |
| 489 |
|
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* Get Plugin slug. |
| 494 |
* |
| 495 |
* @since 1.0 |
| 496 |
* @access public |
| 497 |
* |
| 498 |
* @return string |
| 499 |
**/ |
| 500 |
public static function get_slug() { |
| 501 |
|
| 502 |
return self::get_plugin_data( 'TextDomain' ); |
| 503 |
|
| 504 |
} |
| 505 |
|
| 506 |
/** |
| 507 |
* Get Plugin type. |
| 508 |
* |
| 509 |
* @since 1.0 |
| 510 |
* @access public |
| 511 |
* |
| 512 |
* @return string |
| 513 |
**/ |
| 514 |
public static function get_type() { |
| 515 |
|
| 516 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 517 |
|
| 518 |
return self::$type; |
| 519 |
|
| 520 |
} |
| 521 |
|
| 522 |
/** |
| 523 |
* Set Plugin type. |
| 524 |
* |
| 525 |
* @param string $type - Allow change plugin type. |
| 526 |
* |
| 527 |
* @since 1.0 |
| 528 |
* @access public |
| 529 |
* |
| 530 |
* @return void |
| 531 |
**/ |
| 532 |
public static function set_type( $type ) { |
| 533 |
|
| 534 |
if ( empty( $type ) ) { return; } |
| 535 |
|
| 536 |
self::$type = $type; |
| 537 |
|
| 538 |
} |
| 539 |
|
| 540 |
/** |
| 541 |
* Extract plugin type from slug. |
| 542 |
* |
| 543 |
* @since 1.0 |
| 544 |
* @access public |
| 545 |
* |
| 546 |
* @return string |
| 547 |
**/ |
| 548 |
private static function extract_plugin_type() { |
| 549 |
|
| 550 |
$slug = self::get_plugin_data( 'TextDomain' ); |
| 551 |
$type = 'wordpress'; |
| 552 |
|
| 553 |
if ( strpos( $slug, 'elementor' ) !== false ) { |
| 554 |
$type = 'elementor'; |
| 555 |
} |
| 556 |
|
| 557 |
if ( strpos( $slug, 'wpbakery' ) !== false ) { |
| 558 |
$type = 'wpbakery'; |
| 559 |
} |
| 560 |
|
| 561 |
return $type; |
| 562 |
|
| 563 |
} |
| 564 |
|
| 565 |
/** |
| 566 |
* Get Plugin tabs. |
| 567 |
* |
| 568 |
* @since 1.0 |
| 569 |
* @access public |
| 570 |
* |
| 571 |
* @return array |
| 572 |
**/ |
| 573 |
public static function get_tabs() { |
| 574 |
|
| 575 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { self::get_instance(); } |
| 576 |
|
| 577 |
return self::$tabs; |
| 578 |
|
| 579 |
} |
| 580 |
|
| 581 |
/** |
| 582 |
* Set Plugin tabs. |
| 583 |
* |
| 584 |
* @param array $tabs - Tabs and fields with settings. |
| 585 |
* |
| 586 |
* @since 1.0 |
| 587 |
* @access public |
| 588 |
* |
| 589 |
* @return void |
| 590 |
**/ |
| 591 |
public static function set_tabs( $tabs ) { |
| 592 |
|
| 593 |
self::$tabs = $tabs; |
| 594 |
|
| 595 |
} |
| 596 |
|
| 597 |
/** |
| 598 |
* Get instance of Plugin. |
| 599 |
* |
| 600 |
* Insures that only one instance of Plugin exists in memory at any one time. |
| 601 |
* |
| 602 |
* @static |
| 603 |
* @since 1.0 |
| 604 |
* |
| 605 |
* @return Plugin |
| 606 |
**/ |
| 607 |
public static function get_instance() { |
| 608 |
|
| 609 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) { |
| 610 |
|
| 611 |
self::$instance = new self; |
| 612 |
|
| 613 |
} |
| 614 |
|
| 615 |
return self::$instance; |
| 616 |
|
| 617 |
} |
| 618 |
|
| 619 |
} |
| 620 |
|