PluginProbe
Powerkit – Supercharge your WordPress Site / 2.8.2
Powerkit – Supercharge your WordPress Site v2.8.2
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / core / class-powerkit.php

class-powerkit.php in Powerkit – Supercharge your WordPress Site 2.8.2, at core/class-powerkit.php

371 lines 9.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * A class definition that includes attributes and functions used across both the
6 * public-facing side of the site and the admin area.
7 *
8 * @package Powerkit
9 * @subpackage Core
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // Exit if accessed directly.
14 }
15
16 if ( ! class_exists( 'Powerkit' ) ) {
17 /**
18 * Main Core Class
19 */
20 class Powerkit {
21 /**
22 * The plugin version number.
23 *
24 * @var string $data The plugin version number.
25 */
26 public $version;
27
28 /**
29 * The plugin data array.
30 *
31 * @var array $data The plugin data array.
32 */
33 public $data = array();
34
35 /**
36 * The plugin settings array.
37 *
38 * @var array $settings The plugin data array.
39 */
40 public $settings = array();
41
42 /**
43 * INIT (global theme queue)
44 */
45 public function init() {
46
47 if ( ! function_exists( 'get_plugin_data' ) ) {
48 require_once ABSPATH . 'wp-admin/includes/plugin.php';
49 }
50
51 // Get plugin data.
52 $plugin_data = get_plugin_data( POWERKIT_PATH . '/powerkit.php' );
53
54 // Vars.
55 $this->version = $plugin_data['Version'];
56
57 // Settings.
58 $this->settings = array(
59 'name' => esc_html__( 'Powerkit', 'powerkit' ),
60 'version' => $plugin_data['Version'],
61 'documentation' => $plugin_data['AuthorURI'] . '/documentation/powerkit',
62 );
63
64 // Constants.
65 $this->define( 'POWERKIT', true );
66 $this->define( 'POWERKIT_VERSION', $plugin_data['Version'] );
67
68 // Include core.
69 require_once POWERKIT_PATH . 'core/core-powerkit-api.php';
70 require_once POWERKIT_PATH . 'core/core-powerkit-functions.php';
71 require_once POWERKIT_PATH . 'core/core-powerkit-helpers.php';
72 require_once POWERKIT_PATH . 'core/core-powerkit-post-meta.php';
73
74 // Include core classes.
75 require_once POWERKIT_PATH . 'core/class-powerkit-module.php';
76 require_once POWERKIT_PATH . 'core/class-powerkit-module-admin.php';
77 require_once POWERKIT_PATH . 'core/class-powerkit-module-public.php';
78 require_once POWERKIT_PATH . 'core/class-powerkit-deprecated.php';
79
80 // Include admin classes.
81 require_once POWERKIT_PATH . 'admin/class-admin-powerkit-manager.php';
82
83 // Include modules.
84 powerkit_load_files( 'modules' );
85
86 // Include extensions.
87 powerkit_load_files( 'extensions' );
88
89 // Actions.
90 add_action( 'powerkit_plugin_activation', array( $this, 'activation' ) );
91 add_action( 'plugins_loaded', array( $this, 'check_version' ) );
92 add_action( 'amp_post_template_css', array( $this, 'amp_enqueue_styles' ) );
93 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 5 );
94 add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 5 );
95 add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
96 add_filter( 'style_loader_tag', array( $this, 'style_loader_tag' ), 10, 2 );
97 add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
98 }
99
100 /**
101 * This function will safely define a constant
102 *
103 * @param string $name The name.
104 * @param mixed $value The value.
105 */
106 public function define( $name, $value = true ) {
107
108 if ( ! defined( $name ) ) {
109 define( $name, $value );
110 }
111 }
112
113 /**
114 * Returns true if has setting.
115 *
116 * @param string $name The name.
117 */
118 public function has_setting( $name ) {
119 return isset( $this->settings[ $name ] );
120 }
121
122 /**
123 * Returns a setting.
124 *
125 * @param string $name The name.
126 */
127 public function get_setting( $name ) {
128 return isset( $this->settings[ $name ] ) ? $this->settings[ $name ] : null;
129 }
130
131 /**
132 * Updates a setting.
133 *
134 * @param string $name The name.
135 * @param mixed $value The value.
136 */
137 public function update_setting( $name, $value ) {
138 $this->settings[ $name ] = $value;
139 return true;
140 }
141
142 /**
143 * Returns data.
144 *
145 * @param string $name The name.
146 */
147 public function get_data( $name ) {
148 return isset( $this->data[ $name ] ) ? $this->data[ $name ] : null;
149 }
150
151 /**
152 * Sets data.
153 *
154 * @param string $name The name.
155 * @param mixed $value The value.
156 */
157 public function set_data( $name, $value ) {
158 $this->data[ $name ] = $value;
159 }
160
161 /**
162 * Hook activation
163 */
164 public function activation() {
165 if ( get_option( 'powerkit_db_version' ) ) {
166 return;
167 }
168
169 update_option( 'powerkit_db_version', powerkit_raw_setting( 'version' ), true );
170 }
171
172 /**
173 * Check current version
174 */
175 public function check_version() {
176
177 // Version Data.
178 $new = powerkit_raw_setting( 'version' );
179
180 // Get db version.
181 $current = get_option( 'powerkit_db_version', $new );
182
183 // If versions don't match.
184 if ( ! empty( $current ) && ! empty( $new ) && $current !== $new ) {
185 /**
186 * If different versions call a special hook.
187 *
188 * @param string $current Current version.
189 * @param string $new New version.
190 */
191 do_action( 'powerkit_plugin_upgrade', $current, $new );
192
193 update_option( 'powerkit_db_version', $new );
194
195 } elseif ( ! empty( $new ) && $current !== $new ) {
196
197 update_option( 'powerkit_db_version', $new );
198 }
199 }
200
201 /**
202 * AMP stylesheets.
203 *
204 * @since 1.0.0
205 */
206 public function amp_enqueue_styles() {
207 powerkit_amp_style( POWERKIT_PATH . 'assets/css/amp.css' );
208 }
209
210 /**
211 * This function will register scripts and styles for admin dashboard.
212 *
213 * @param string $page Current page.
214 */
215 public function admin_enqueue_scripts( $page ) {
216 wp_enqueue_style( 'powerkit', POWERKIT_URL . 'assets/css/powerkit.css', array(), powerkit_get_setting( 'version' ) );
217 }
218
219 /**
220 * This function will register scripts and styles
221 */
222 public function wp_enqueue_scripts() {
223 // Scripts.
224 if ( is_user_logged_in() ) {
225 wp_enqueue_script( 'tippy', POWERKIT_URL . 'assets/js/tippy.all.min.js', array( 'jquery' ), powerkit_get_setting( 'version' ), true );
226 }
227
228 wp_enqueue_script( 'powerkit', POWERKIT_URL . 'assets/js/_scripts.js', array( 'jquery', 'tippy' ), powerkit_get_setting( 'version' ), true );
229
230 // Icons.
231 wp_enqueue_style( 'powerkit-icons', POWERKIT_URL . 'assets/fonts/powerkit-icons.woff', array(), powerkit_get_setting( 'version' ) );
232 wp_style_add_data( 'powerkit-icons', 'alt', 'alternate' );
233
234 // Styles.
235 wp_enqueue_style( 'powerkit', powerkit_style( POWERKIT_URL . 'assets/css/powerkit.css' ), array(), powerkit_get_setting( 'version' ) );
236 wp_style_add_data( 'powerkit', 'rtl', 'replace' );
237 }
238
239 /**
240 * Filters the HTML link tag of an enqueued style.
241 *
242 * @param string $tag The link tag for the enqueued style.
243 * @param string $handle The style's registered handle.
244 */
245 public function style_loader_tag( $tag, $handle ) {
246 if ( 'powerkit-icons' === $handle ) {
247 return str_replace( "media='all'", "as='font' type='font/wof' crossorigin", $tag );
248 }
249 return $tag;
250 }
251
252 /**
253 * Sets up theme defaults and registers support for various WordPress features.
254 */
255 public function after_setup_theme() {
256 // Register custom thumbnail sizes.
257 add_image_size( 'pk-small', 80, 80, true );
258 add_image_size( 'pk-thumbnail', 300, 225, true );
259
260 // Add editor style.
261 if ( is_rtl() ) {
262 add_editor_style( powerkit_style( POWERKIT_URL . 'assets/css/powerkit-rtl.css' ) );
263 } else {
264 add_editor_style( powerkit_style( POWERKIT_URL . 'assets/css/powerkit.css' ) );
265 }
266 }
267
268 /**
269 * Filters the HTML that is allowed for a given context.
270 *
271 * @param array $tags Tags by.
272 * @param string $context Context name.
273 */
274 public function wp_kses_allowed_html( $tags, $context ) {
275 if ( 'pk-title' === $context ) {
276 $tags = array(
277 'a' => array(
278 'class' => true,
279 'href' => true,
280 'title' => true,
281 'target' => true,
282 'rel' => true,
283 ),
284 'div' => array(
285 'class' => true,
286 'id' => true,
287 'style' => true,
288 ),
289 'span' => array(
290 'class' => true,
291 'id' => true,
292 'style' => true,
293 ),
294 'img' => array(
295 'class' => true,
296 'id' => true,
297 'src' => true,
298 'rel' => true,
299 'srcset' => true,
300 'size' => true,
301 ),
302 'br' => array(),
303 'b' => array(),
304 'strong' => array(),
305 'i' => array(),
306 'p' => array(
307 'class' => true,
308 'id' => true,
309 'style' => true,
310 ),
311 'h1' => array(
312 'class' => true,
313 'id' => true,
314 'style' => true,
315 ),
316 'h2' => array(
317 'class' => true,
318 'id' => true,
319 'style' => true,
320 ),
321 'h3' => array(
322 'class' => true,
323 'id' => true,
324 'style' => true,
325 ),
326 'h4' => array(
327 'class' => true,
328 'id' => true,
329 'style' => true,
330 ),
331 'h5' => array(
332 'class' => true,
333 'id' => true,
334 'style' => true,
335 ),
336 'h6' => array(
337 'class' => true,
338 'id' => true,
339 'style' => true,
340 ),
341 );
342 }
343
344 return $tags;
345 }
346 }
347
348 /**
349 * The main function responsible for returning the one true powerkit Instance to functions everywhere.
350 * Use this function like you would a global variable, except without needing to declare the global.
351 *
352 * Example: <?php $powerkit = powerkit(); ?>
353 */
354 function powerkit() {
355
356 // Globals.
357 global $powerkit_instance;
358
359 // Init.
360 if ( ! isset( $powerkit_instance ) ) {
361 $powerkit_instance = new Powerkit();
362 $powerkit_instance->init();
363 }
364
365 return $powerkit_instance;
366 }
367
368 // Initialize.
369 powerkit();
370 }
371