1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
<?php
if ( ! function_exists( 'TotalPoll' ) ): /** * TotalPoll global function. * * @param null $component * @param array $args * * @return \TotalPollVendors\TotalCore\Application|mixed */ function TotalPoll( $component = null, $args = array() ) { $instance = $GLOBALS['TotalPollApplication'];
if ( $component !== null ): $instance = $instance->container( $component, $args ); endif;
return $instance; } endif;
if ( ! class_exists( 'TotalPollSetup' ) ): /** * Class TotalPollSetup */ class TotalPollSetup { protected $environment = array(); protected $loader; protected static $loaded = false;
/** * TotalPollSetup constructor. * * @param $env */ public function __construct( $env ) { $this->environment = $env;
$phpCompatible = version_compare( $this->environment['versions']['php'], $this->environment['requirements']['php'], '>=' ); $wpCompatible = version_compare( $this->environment['versions']['wp'], $this->environment['requirements']['wp'], '>=' ); // Check version requirements if ( $phpCompatible && $wpCompatible ): $this->load(); else: $this->disable(); endif; }
/** * Load autoloader and bootstrap plugin. */ public function load() { if ( self::$loaded ): return; endif;
$this->loader = require $this->environment['autoload']['loader']; foreach ( $this->environment['autoload']['psr4'] as $namespace => $paths ): $this->loader->addPsr4( $namespace, $paths ); endforeach;
// Quick workaround for php 5.2 syntax error $application = "{$this->environment['namespace']}Vendors\\TotalCore\\Application";
// Initiate $GLOBALS["{$this->environment['namespace']}Application"] = new $application( $this->environment );
// Let's bootstrap plugin (Quirky code to avoid php 5.2 syntax error) $plugin = "\\{$this->environment['namespace']}\\Plugin"; $GLOBALS["{$this->environment['namespace']}Application"]->bootstrap( new $plugin() );
self::$loaded = true; }
/** * Disable the plugin. */ public function disable() { // Attach to appropriate hooks. add_action( 'admin_init', array( $this, '_deactivate' ) ); add_action( 'admin_notices', array( $this, '_warning' ) ); }
// Self deactivation (to prevent any unwanted behaviors). public function _deactivate() { deactivate_plugins( $this->environment['basename'] ); }
// Warning message. public function _warning() { $message = sprintf( __( '%1$s requires PHP %2$s+ and WordPress %3$s+ to function properly. Please contact your host to upgrade PHP and WordPress. %1$s has been auto-deactivated.', $this->environment['textdomain'] ), $this->environment['name'], $this->environment['requirements']['php'], $this->environment['requirements']['wp'] ); printf( '<div class="error"><p>%s</p></div>', $message ); } } endif;
|