PluginProbe
HootKit / 2.0.21
HootKit v2.0.21
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 2.0.21, at hootkit.php

295 lines 7.8 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: 2.0.21
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\Helper_Config;
18 use \HootKit\Inc\Helper_Strings;
19 use \HootKit\Inc\Helper_Mods;
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 = '2.0.21';
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 Plugin Files and Helpers
75 $this->loader();
76
77 // Plugin Loader - Load config, and modules based on config
78 // -> Register HootKit configuration after theme has loaded (so that theme can hook in to alter Hootkit config)
79 // -> init hook may be a bit late for us to load since 'widgets_init' is used to intialize widgets (unless we hook into init at 0, which is a bit messy)
80 add_action( 'after_setup_theme', array( $this, 'loadhootkit' ), 96 );
81
82 }
83
84 /**
85 * Load Plugin Files and Helpers
86 *
87 * @since 2.0.0
88 * @access public
89 * @return void
90 */
91 public function loader() {
92
93 require_once( $this->dir . 'include/class-activation.php' );
94 require_once( $this->dir . 'include/class-config.php' );
95 require_once( $this->dir . 'include/class-helper-strings.php' );
96 require_once( $this->dir . 'include/class-helper-mods.php' );
97 require_once( $this->dir . 'include/class-helper-assets.php' );
98
99 }
100
101 /**
102 * Plugin Loader
103 * Load plugin and modules
104 *
105 * @since 1.0.0
106 * @access public
107 * @return void
108 */
109 public function loadhootkit() {
110
111 // Load plugin parts
112 $loadhootkit = array();
113 $thememods = hootkit()->get_config( 'modules' );
114 foreach ( array( 'widget', 'block', 'misc' ) as $check )
115 if ( !empty( $thememods[ $check ] ) )
116 $loadhootkit[ $check ] = true;
117
118 if ( !empty( $loadhootkit ) ) {
119
120 // Load Limited Core/Helper Functions
121 // Template Functions - may be required in admin for creating live preview eg. so page builder
122 require_once( $this->dir . 'include/template-functions.php' );
123
124 // Load Limited Library for Non Hoot themes :: some deprecated theme versions 'may' have nohoot set to true
125 if ( $this->get_config( 'nohoot' ) ) {
126 require_once( $this->dir . 'include/hoot-library.php' );
127 require_once( $this->dir . 'include/hoot-library-icons.php' );
128 }
129
130 // Admin Functions
131 if ( is_admin() ) {
132 require_once( $this->dir . 'admin/functions.php' );
133 require_once( $this->dir . 'admin/class-settings.php' );
134 }
135
136 // Modules
137 if ( !empty( $loadhootkit['widget'] ) )
138 require_once( $this->dir . 'widgets/class-widgets.php' );
139 if ( !empty( $loadhootkit['misc'] ) )
140 require_once( $this->dir . 'misc/class-miscmods.php' );
141
142 }
143
144 }
145
146 /**
147 * Get String values.
148 *
149 * @since 1.0.0
150 * @access public
151 * @param string $key
152 * @param string $default
153 * @return string
154 */
155 public function get_string( $key, $default = '' ) {
156 $return = '';
157 if ( !is_array( Helper_Strings::$strings ) ) {
158 Helper_Strings::set_strings();
159 }
160 if ( !is_array( Helper_Strings::$strings ) ) {
161 $return = '';
162 } else {
163 $return = ( !empty( Helper_Strings::$strings[ $key ] ) ? Helper_Strings::$strings[ $key ] : '' );
164 }
165 if ( !empty( $return ) && is_string( $return ) )
166 return esc_html( $return );
167 elseif ( !empty( $default ) && is_string( $default ) )
168 return esc_html( $default );
169 else return esc_html( ucwords( str_replace( array( '-', '_' ), ' ' , $key ) ) );
170 }
171
172 /**
173 * Get Config values.
174 *
175 * @since 1.0.0
176 * @access public
177 * @param string $key Config value to return / else return entire array
178 * @param string $subkey Check for $subkey if config value is an array
179 * @return mixed
180 */
181 public function get_config( $key = '', $subkey = '', $default = array() ) {
182
183 // Early Check in case config has changed
184 // Now redundant since config is loaded within this->loader
185 if ( empty( Helper_Config::$config ) )
186 return $default;
187
188 // Return the value
189 if ( $key && is_string( $key ) ) {
190 if ( isset( Helper_Config::$config[ $key ] ) ) {
191 if ( $subkey && ( is_string( $subkey ) || is_integer( $subkey ) ) ) {
192 return ( isset( Helper_Config::$config[ $key ][ $subkey] ) ) ? Helper_Config::$config[ $key ][ $subkey ] : $default;
193 } else {
194 return Helper_Config::$config[ $key ];
195 }
196 } else {
197 return $default;
198 }
199 } else {
200 return Helper_Config::$config;
201 }
202
203 }
204
205 /**
206 * Get Active Modules from config
207 *
208 * @since 2.0.0
209 */
210 public function get_activemods( $type = '' ) {
211 if ( $type && is_string( $type ) )
212 retrun( ( isset( Helper_Config::$config['activemods'][ $type ] ) ) ? Helper_Config::$config['activemods'][ $type ] : array() );
213 else
214 return Helper_Config::$config['activemods'];
215 }
216
217 /**
218 * Get HootKit modules
219 *
220 * @since 1.2.0
221 * @access public
222 * @param string $key 'modules' 'supports'
223 * @param string $subkey Check for $subkey if $key value is an array
224 * @return mixed
225 */
226 public function get_mods( $key = '', $subkey = '', $default = array() ) {
227 if ( $key && is_string( $key ) ) {
228 if ( isset( Helper_Mods::$mods[ $key ] ) ) {
229 if ( $subkey && ( is_string( $subkey ) || is_integer( $subkey ) ) ) {
230 return ( isset( Helper_Mods::$mods[ $key ][ $subkey] ) ) ? Helper_Mods::$mods[ $key ][ $subkey ] : $default;
231 } else {
232 return Helper_Mods::$mods[ $key ];
233 }
234 } else {
235 return array();
236 }
237 } else {
238 return Helper_Mods::$mods;
239 }
240 }
241
242 /**
243 * Fitler and Get HootKit modules of specific type
244 *
245 * @since 2.0.0
246 * @param $type 'widget' 'block' 'misc'
247 * @param $keys boolean
248 */
249 public function get_modtype( $type, $keys = false ) {
250 static $modtypes = array();
251 if ( !isset( $modtypes[ $type ] ) ) {
252 $modtypes[ $type ] = array();
253 foreach ( Helper_Mods::$mods['modules'] as $slug => $atts )
254 if ( isset( $atts['types'] ) && \in_array( $type, $atts['types'] ) )
255 $modtypes[ $type ][ $slug ] = $atts;
256 }
257 return ( ( $keys === false ) ? $modtypes[ $type ] : array_keys( $modtypes[ $type ] ) );
258 }
259
260 /**
261 * Returns the instance
262 *
263 * @since 1.0.0
264 * @access public
265 * @return object
266 */
267 public static function get_instance() {
268
269 static $instance = null;
270
271 if ( is_null( $instance ) ) {
272 $instance = new self;
273 }
274
275 return $instance;
276 }
277
278 }
279
280 /**
281 * Gets the instance of the `HootKit` class. This function is useful for quickly grabbing data
282 * used throughout the plugin.
283 *
284 * @since 1.0.0
285 * @access public
286 * @return object
287 */
288 function hootkit() {
289 return HootKit::get_instance();
290 }
291
292 // Lets roll!
293 hootkit();
294
295 endif;