1 | <?php |
||
18 | final class Plugin { |
||
19 | |||
20 | /** |
||
21 | * Plugin name. |
||
22 | * |
||
23 | * @access public |
||
24 | * @var string |
||
25 | */ |
||
26 | public static $name = 'Simple Calendar'; |
||
27 | |||
28 | /** |
||
29 | * Plugin version. |
||
30 | * |
||
31 | * @access public |
||
32 | * @var string |
||
33 | */ |
||
34 | public static $version = SIMPLE_CALENDAR_VERSION; |
||
35 | |||
36 | /** |
||
37 | * Plugin homepage. |
||
38 | * |
||
39 | * @access public |
||
40 | * @var string |
||
41 | */ |
||
42 | protected static $homepage = 'https://simplecalendar.io'; |
||
43 | |||
44 | /** |
||
45 | * Locale. |
||
46 | * |
||
47 | * @access public |
||
48 | * @var string |
||
49 | */ |
||
50 | public $locale = 'en_US'; |
||
51 | |||
52 | /** |
||
53 | * Objects factory. |
||
54 | * |
||
55 | * @access public |
||
56 | * @var Objects |
||
57 | */ |
||
58 | public $objects = null; |
||
59 | |||
60 | /** |
||
61 | * The single instance of this class. |
||
62 | * |
||
63 | * @access protected |
||
64 | * @var Plugin |
||
65 | */ |
||
66 | protected static $_instance = null; |
||
67 | |||
68 | /** |
||
69 | * Get the plugin instance. |
||
70 | * |
||
71 | * @return Plugin |
||
72 | */ |
||
73 | public static function get_instance() { |
||
74 | if ( is_null( self::$_instance ) ) { |
||
75 | self::$_instance = new self(); |
||
76 | } |
||
77 | return self::$_instance; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Cloning is forbidden. |
||
82 | */ |
||
83 | public function __clone() { |
||
86 | |||
87 | /** |
||
88 | * Unserializing instances of this class is forbidden. |
||
89 | */ |
||
90 | public function __wakeup() { |
||
93 | |||
94 | /** |
||
95 | * Plugin constructor. |
||
96 | * |
||
97 | * @final |
||
98 | */ |
||
99 | public function __construct() { |
||
100 | |||
101 | // Load plugin. |
||
102 | require_once 'autoload.php'; |
||
103 | $this->locale = apply_filters( 'plugin_locale', get_locale(), 'google-calendar-events' ); |
||
104 | $this->load(); |
||
105 | |||
106 | // Installation hooks. |
||
107 | register_activation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'activate' ) ); |
||
108 | register_deactivation_hook( SIMPLE_CALENDAR_MAIN_FILE, array( 'SimpleCalendar\Installation', 'deactivate' ) ); |
||
109 | |||
110 | // Do update call here. |
||
111 | add_action( 'admin_init', array( $this, 'update' ), 999 ); |
||
112 | |||
113 | // Init hooks. |
||
114 | add_action( 'init', array( $this, 'init' ), 5 ); |
||
115 | add_action( 'admin_init', array( $this, 'register_settings' ), 5 ); |
||
116 | |||
117 | // Upon plugin loaded action hook. |
||
118 | do_action( 'simcal_loaded' ); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * Load plugin. |
||
123 | * |
||
124 | * @since 3.0.0 |
||
125 | */ |
||
126 | public function load() { |
||
127 | |||
128 | // Functions shared in both back end and front end. |
||
129 | include_once 'functions/shared.php'; |
||
130 | |||
131 | // Init custom post types and taxonomies. |
||
132 | new Post_Types(); |
||
133 | |||
134 | // Load back end. |
||
135 | if ( is_admin() ) { |
||
136 | $this->load_admin(); |
||
137 | } else { |
||
138 | // Load front end scripts and styles. |
||
139 | new Assets(); |
||
140 | } |
||
141 | |||
142 | // Front facing ajax callbacks. |
||
143 | new Ajax(); |
||
144 | |||
145 | // Add Shortcodes. |
||
146 | new Shortcodes(); |
||
147 | |||
148 | // Add Widgets. |
||
149 | new Widgets(); |
||
150 | |||
151 | // Deprecated functions for backwards compatibility. |
||
152 | include_once 'functions/deprecated.php'; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Load plugin admin. |
||
157 | * |
||
158 | * @since 3.0.0 |
||
159 | */ |
||
160 | public function load_admin() { |
||
182 | |||
183 | /** |
||
184 | * Init plugin when WordPress initializes. |
||
185 | * |
||
186 | * @since 3.0.0 |
||
187 | */ |
||
188 | public function init() { |
||
189 | |||
190 | // Before init action hook. |
||
191 | do_action( 'before_simcal_init' ); |
||
192 | |||
193 | // Set up localization. |
||
194 | load_plugin_textdomain( 'google-calendar-events', false, dirname( plugin_basename( SIMPLE_CALENDAR_MAIN_FILE ) ) . '/i18n/' ); |
||
195 | |||
196 | // Init objects factory. |
||
197 | $this->objects = new Objects(); |
||
198 | |||
199 | // Upon init action hook. |
||
200 | do_action( 'simcal_init' ); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Register plugin settings. |
||
205 | * |
||
206 | * @since 3.0.0 |
||
207 | */ |
||
208 | public function register_settings() { |
||
209 | if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
||
210 | $settings = new Admin\Pages(); |
||
211 | $settings->register_settings( $settings->get_settings() ); |
||
212 | } |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Get Ajax URL. |
||
217 | * |
||
218 | * @since 3.0.0 |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | public function ajax_url() { |
||
225 | |||
226 | /** |
||
227 | * Get URL. |
||
228 | * |
||
229 | * @since 3.0.0 |
||
230 | * |
||
231 | * @param string $case Requested url. |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function get_url( $case ) { |
||
257 | |||
258 | /** |
||
259 | * Run upgrade scripts. |
||
260 | * |
||
261 | * @since 3.0.0 |
||
262 | */ |
||
263 | public static function update() { |
||
266 | |||
267 | } |
||
268 | |||
279 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.