PluginProbe
HootKit / trunk
HootKit vtrunk
trunk 2.0.21 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5
hootkit / hootkit.php

hootkit.php in HootKit trunk, at hootkit.php

398 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: HootKit
4 * Description: HootKit is a great companion plugin for WordPress themes by wpHoot.
5 * Version: 3.0.6
6 * Requires at least: 6.0
7 * Requires PHP: 7.4
8 * Author: wphoot
9 * Author URI: https://wphoot.com/
10 * License: GPLv3 or later
11 * License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
12 * Text Domain: hootkit
13 * Domain Path: /languages
14 * @package Hootkit
15 */
16
17 use \HootKit\Inc\HKConfig;
18 use \HootKit\Inc\Strings;
19 use \HootKit\Inc\Manifest;
20
21 // If this file is called directly, abort.
22 if ( ! defined( 'ABSPATH' ) ) {
23 die;
24 }
25
26 /**
27 * Run in Debug mode to load unminified CSS and JS, and add other developer data to code.
28 */
29 if ( !defined( 'HKIT_DEBUG' ) && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
30 define( 'HKIT_DEBUG', true );
31
32 /**
33 * The core plugin class.
34 *
35 * @since 1.0.0
36 * @package Hootkit
37 */
38 if ( ! class_exists( 'HootKit' ) ) :
39
40 class HootKit {
41
42 /**
43 * Plugin Info
44 *
45 * @since 1.0.0
46 * @access public
47 */
48 public $version;
49 public $name;
50 public $slug;
51 public $file;
52 public $dir;
53 public $uri;
54 public $plugin_basename;
55
56 /**
57 * Constructor method.
58 *
59 * @since 1.0.0
60 * @access public
61 * @return void
62 */
63 public function __construct() {
64
65 // Plugin Info
66 $this->version = '3.0.6';
67 $this->name = 'HootKit';
68 $this->slug = 'hootkit';
69 $this->file = __FILE__;
70 $this->dir = trailingslashit( plugin_dir_path( __FILE__ ) );
71 $this->uri = trailingslashit( plugin_dir_url( __FILE__ ) );
72 $this->plugin_basename = plugin_basename(__FILE__);
73
74 // Load Text Domain
75 add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
76
77 // (De)Activation Hook
78 register_activation_hook( $this->file, array( $this, 'activate' ) );
79 register_deactivation_hook( $this->file, array( $this, 'deactivate' ) );
80
81 // Load Plugin Files and Helpers
82 $this->loader();
83 add_action( 'plugins_loaded', array( $this, 'dashboardplugs' ), 5 );
84
85 // Initiate Plugin
86 add_action( 'after_setup_theme', array( $this, 'load_deprecated' ), 89 );
87 add_action( 'after_setup_theme', array( $this, 'loadhootkit' ), 96 );
88
89 }
90
91 /**
92 * Load Plugin Text Domain
93 * @since 1.0.0
94 */
95 public function load_plugin_textdomain() {
96 $rootdir = dirname( $this->plugin_basename );
97 $lang_dir = apply_filters( 'hootkit_languages_directory', $rootdir . '/languages/' );
98 load_plugin_textdomain(
99 $this->slug,
100 false,
101 $lang_dir
102 );
103 }
104
105 /**
106 * Run when plugin is activated
107 * @since 1.1.0
108 */
109 public function activate() {
110 $activation = get_option( 'hootkit-activate' );
111 if ( !$activation ) {
112 $activation = array(
113 'time' => time(),
114 'version' => $this->version
115 );
116 add_option( 'hootkit-activate', $activation );
117 }
118 do_action( 'hootkit/activate', $activation );
119 }
120
121 /**
122 * Run when plugin is deactivated
123 * @since 2.0.0
124 */
125 public function deactivate() {
126 $activation = get_option( 'hootkit-activate' );
127 do_action( 'hootkit/deactivate', $activation );
128 }
129
130 /**
131 * Load Plugin Files and Helpers
132 *
133 * @since 2.0.0
134 * @access public
135 * @return void
136 */
137 public function loader() {
138 require_once( $this->dir . 'include/class-strings.php' );
139 require_once( $this->dir . 'include/class-config.php' );
140 require_once( $this->dir . 'include/class-manifest.php' );
141 require_once( $this->dir . 'include/class-assets.php' );
142 }
143
144 /**
145 * Load Dashboard Plug Files and Helpers
146 *
147 * @since 3.0.0
148 * @access public
149 * @return void
150 */
151 public function dashboardplugs() {
152 require_once( $this->dir . 'misc/import/class-import.php' );
153 require_once( $this->dir . 'misc/code/class-customcode.php' );
154 require_once( $this->dir . 'misc/tools/class-tools.php' );
155 if ( is_admin() ) {
156 require_once( $this->dir . 'admin/class-settings.php' );
157 require_once( $this->dir . 'admin/class-dashmenu.php' );
158 }
159 }
160
161 /**
162 * Load Deprecated functions
163 *
164 * @since 3.0.0
165 * @access public
166 * @return void
167 */
168 public function load_deprecated() {
169 require_once( $this->dir . 'include/functions-deprecated.php' );
170 }
171
172 /**
173 * Plugin Loader
174 * Load plugin and modules
175 *
176 * @since 1.0.0
177 * @access public
178 * @return void
179 */
180 public function loadhootkit() {
181 // Admin Functions and Settings
182 if ( is_admin() ) {
183 require_once( $this->dir . 'admin/functions.php' );
184 }
185
186 // Load general helper functions
187 require_once( $this->dir . 'include/functions.php' );
188
189 // Template Functions - may be required in admin for creating live preview eg. so page builder
190 require_once( $this->dir . 'include/template-functions.php' );
191
192 // Load Parts
193 $modtypes = Manifest::$modtypes;
194 $activemods = $this->get_config( 'activemods' );
195 foreach ( $modtypes as $modtype ) {
196 if ( !empty( $activemods[ $modtype ] ) ) {
197 if ( file_exists( $this->dir . "{$modtype}s/class-{$modtype}s.php" ) )
198 require_once( $this->dir . "{$modtype}s/class-{$modtype}s.php" );
199 elseif ( file_exists( $this->dir . "{$modtype}/class-{$modtype}.php" ) )
200 require_once( $this->dir . "{$modtype}/class-{$modtype}.php" );
201 elseif ( file_exists( $this->dir . "{$modtype}/init.php" ) )
202 require_once( $this->dir . "{$modtype}/init.php" );
203 }
204 }
205 $tfilters = $this->get_config( 'theme-filters' );
206 if ( !empty( $tfilters ) && is_array( $tfilters ) && !empty( $tfilters['fnspace'] ) ) {
207 require_once( $this->dir . 'include/class-themes.php' );
208 }
209 }
210
211 /**
212 * Get String values.
213 *
214 * @since 1.0.0
215 * @access public
216 * @param string $key
217 * @param string $default
218 * @return string
219 */
220 public function get_string( $key, $default = '' ) {
221 return Strings::get_string( $key, $default );
222 }
223
224 /**
225 * Get Config values.
226 *
227 * @since 1.0.0
228 * @access public
229 * @param string $key Config value to return / else return entire array
230 * @param string $subkey Check for $subkey if config value is an array
231 * @return mixed
232 */
233 public function get_config( $key = '', $subkey = '', $default = array() ) {
234 if ( empty( $key ) )
235 return HKConfig::$config;
236 if ( ! is_string( $key ) || ! isset( HKConfig::$config[ $key ] ) )
237 return $default;
238 if ( empty( $subkey ) && $subkey !== 0 )
239 return HKConfig::$config[ $key ];
240 if ( is_string( $subkey ) || is_integer( $subkey ) ) {
241 return ( isset( HKConfig::$config[ $key ][ $subkey ] ) ? HKConfig::$config[ $key ][ $subkey ] : $default );
242 }
243 if ( is_array( $subkey ) ) {
244 $arr = HKConfig::$config[ $key ];
245 foreach ( $subkey as $sub )
246 if ( isset( $arr[ $sub ] ) )
247 $arr = $arr[ $sub ];
248 else
249 return $default;
250 return $arr;
251 }
252 return $default;
253 }
254
255 /**
256 * Get Active Modules from config
257 * Shortcut for hootkit()->get_config( 'activemods', $type )
258 *
259 * @since 2.0.0
260 */
261 public function get_activemods( $type = '' ) {
262 if ( $type && is_string( $type ) )
263 return( ( isset( HKConfig::$config['activemods'][ $type ] ) ) ? HKConfig::$config['activemods'][ $type ] : array() );
264 else
265 return HKConfig::$config['activemods'];
266 }
267
268 /**
269 * Get HootKit manifest
270 *
271 * @since 1.2.0
272 * @access public
273 * @param string $key 'modules' 'supports'
274 * @param string|array $subkey Check for $subkey if $key value is an array
275 * @return mixed
276 */
277 public function get_manifest( $key = '', $subkey = '', $default = array() ) {
278 if ( empty( $key ) )
279 return Manifest::$manifest;
280 if ( ! is_string( $key ) || ! isset( Manifest::$manifest[ $key ] ) )
281 return $default;
282 if ( empty( $subkey ) && $subkey !== 0 )
283 return Manifest::$manifest[ $key ];
284 if ( is_string( $subkey ) || is_integer( $subkey ) ) {
285 return ( is_array( Manifest::$manifest[ $key ] ) && isset( Manifest::$manifest[ $key ][ $subkey ] ) ? Manifest::$manifest[ $key ][ $subkey ] : $default );
286 }
287 if ( is_array( $subkey ) ) {
288 $arr = Manifest::$manifest[ $key ];
289 foreach ( $subkey as $sub )
290 if ( is_array( $arr ) && isset( $arr[ $sub ] ) )
291 $arr = $arr[ $sub ];
292 else
293 return $default;
294 return $arr;
295 }
296 return $default;
297 }
298
299 /**
300 * Get Manifest modules info
301 * Shortcut for hootkit()->get_manifest( 'modules', array( $key, $subkey ) )
302 *
303 * @since 3.0.0
304 * @param string $key
305 * @param string $subkey
306 * @return mixed
307 */
308 public function get_mfmodules( $key = '', $subkey = '', $default = array() ) {
309 if ( ! isset( Manifest::$manifest['modules'] ) || ! is_array( Manifest::$manifest['modules'] ) )
310 return $default;
311 if ( empty( $key ) )
312 return Manifest::$manifest['modules'];
313 if ( ! is_string( $key ) || ! isset( Manifest::$manifest['modules'][ $key ] ) )
314 return $default;
315 if ( empty( $subkey ) && $subkey !== 0 )
316 return Manifest::$manifest['modules'][ $key ];
317 if ( is_string( $subkey ) || is_integer( $subkey ) ) {
318 return ( is_array( Manifest::$manifest['modules'][ $key ] ) && isset( Manifest::$manifest['modules'][ $key ][ $subkey ] ) ? Manifest::$manifest['modules'][ $key ][ $subkey ] : $default );
319 }
320 return $default;
321 }
322
323 /**
324 * Get all HootKit modules from Manifest of a specific type
325 *
326 * @since 2.0.0
327 * @param $type 'all' 'widget' 'block' 'misc'
328 * @param $list boolean
329 */
330 public function get_mfmods_oftype( $type, $list = false ) {
331 $modsoftype = array();
332 if ( is_string( $type ) && ! empty( $type ) ) {
333 foreach ( Manifest::$manifest['modules'] as $slug => $atts ) {
334 if ( $type === 'all' ||
335 ( isset( $atts['types'] ) && \in_array( $type, $atts['types'] ) )
336 ) {
337 if ( $list === false ) $modsoftype[ $slug ] = $atts;
338 else $modsoftype[] = $slug;
339 }
340 }
341 }
342 return $modsoftype;
343 }
344
345 /**
346 * Check if theme supports a feature
347 *
348 * @since 3.0.0
349 * @param string $id
350 * @param bool $iskey
351 * @return bool|mixed
352 */
353 public function supports( $id, $iskey = false ) {
354 if ( ! is_string( $id ) || empty( $id ) )
355 return false;
356 if ( $iskey ) {
357 $supports = $this->get_config( 'supports' );
358 return ( array_key_exists( $id, $supports ) ? $supports[ $id ] : false );
359 }
360 return ( in_array( $id, $this->get_config( 'supports' ) ) );
361 }
362
363 /**
364 * Returns the instance
365 *
366 * @since 1.0.0
367 * @access public
368 * @return object
369 */
370 public static function get_instance() {
371
372 static $instance = null;
373
374 if ( is_null( $instance ) ) {
375 $instance = new self;
376 }
377
378 return $instance;
379 }
380
381 }
382
383 /**
384 * Gets the instance of the `HootKit` class. This function is useful for quickly grabbing data
385 * used throughout the plugin.
386 *
387 * @since 1.0.0
388 * @access public
389 * @return object
390 */
391 function hootkit() {
392 return HootKit::get_instance();
393 }
394
395 // Lets roll!
396 hootkit();
397
398 endif;