forked from maithemewp/mai-theme-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmai-theme-engine.php
More file actions
339 lines (283 loc) · 9.92 KB
/
Copy pathmai-theme-engine.php
File metadata and controls
339 lines (283 loc) · 9.92 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<?php
/**
* Plugin Name: Mai Theme Engine
* Plugin URI: https://maitheme.com/
* Description: The Mai Theme Engine plugin
*
* Version: 1.12.0
*
* GitHub URI: maithemewp/mai-theme-engine
*
* Author: MaiTheme.com
* Author URI: https://maitheme.com
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Main Mai_Theme_Engine Class.
*
* @since 1.0.0
*/
final class Mai_Theme_Engine {
/**
* @var Mai_Theme_Engine The one true Mai_Theme_Engine
* @since 1.0.0
*/
private static $instance;
/**
* Main Mai_Theme_Engine Instance.
*
* Insures that only one instance of Mai_Theme_Engine exists in memory at any one
* time. Also prevents needing to define globals all over the place.
*
* @since 1.0.0
* @static var array $instance
* @uses Mai_Theme_Engine::setup_constants() Setup the constants needed.
* @uses Mai_Theme_Engine::includes() Include the required files.
* @return object | Mai_Theme_Engine The one true Mai_Theme_Engine
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
// Setup the setup
self::$instance = new Mai_Theme_Engine;
// Methods
self::$instance->setup_constants();
self::$instance->hooks();
}
return self::$instance;
}
/**
* Throw error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @since 1.0.0
* @access protected
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'mai-theme-engine' ), '1.0' );
}
/**
* Disable unserializing of the class.
*
* @since 1.0.0
* @access protected
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'mai-theme-engine' ), '1.0' );
}
/**
* Setup plugin constants.
*
* @access private
* @since 1.0.0
* @return void
*/
private function setup_constants() {
// Plugin version.
define( 'MAI_THEME_ENGINE_VERSION', '1.12.0' );
// DB version.
define( 'MAI_THEME_ENGINE_DB_VERSION', '1600' );
// Plugin Folder Path.
define( 'MAI_THEME_ENGINE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
// Plugin Lib Path.
define( 'MAI_THEME_ENGINE_LIB_DIR', MAI_THEME_ENGINE_PLUGIN_DIR . 'lib/' );
// Plugin Folder URL.
define( 'MAI_THEME_ENGINE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
// Plugin Root File.
define( 'MAI_THEME_ENGINE_PLUGIN_FILE', __FILE__ );
// Plugin Base Name.
define( 'MAI_THEME_ENGINE_BASENAME', dirname( plugin_basename( __FILE__ ) ) );
}
/**
* Run the hooks.
*
* composer require yahnis-elsts/plugin-update-checker
* composer require cmb2/cmb2
*
* v2.6.0 CBM2
* v4.5.1 Plugin Update Checker
*
* @access private
* @since 1.0.0
* @return void
*/
private function hooks() {
// Include vendor libraries.
require_once __DIR__ . '/vendor/autoload.php';
// Run the updater.
add_action( 'admin_init', function() {
// Bail if current user cannot manage plugins.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
// Bail if plugin updater is not loaded.
if ( ! class_exists( 'Puc_v4_Factory' ) ) {
return;
}
// Setup the updater.
$updater = Puc_v4_Factory::buildUpdateChecker( 'https://github.com/maithemewp/mai-theme-engine/', __FILE__, 'mai-theme-engine' );
// Get the branch. If checking for beta releases.
$tester = function_exists( 'genesis_get_option' ) && genesis_get_option( 'mai_tester' );
$tester = $tester ? 'beta' : 'master';
// Allow branch and updater object manipulation.
$branch = apply_filters( 'mai_updater_branch', $tester );
// Set the branch.
$updater->setBranch( $branch );
// Allow tokens to be used to bypass GitHub rate limit.
if ( defined( 'MAI_UPDATER_TOKEN' ) ) {
$updater->setAuthentication( MAI_UPDATER_TOKEN );
}
// Add icons for Dashboard > Updates screen.
$updater->addResultFilter( function( $info, $response = null ) {
$info->icons = array(
'1x' => MAI_THEME_ENGINE_PLUGIN_URL . 'assets/images/icon-128x128.png',
'2x' => MAI_THEME_ENGINE_PLUGIN_URL . 'assets/images/icon-256x256.png',
);
return $info;
});
});
/**
* Include files after theme is loaded, to mimic being run in a child theme.
*/
add_action( 'genesis_setup', function() {
// Do not load old stuff.
add_filter( 'genesis_load_deprecated', '__return_false' );
// Add HTML5 markup structure.
add_theme_support( 'html5' );
// Add HTML5 gallery and caption support.
add_theme_support( 'html5', array( 'gallery', 'caption' ) );
// Add title tag support.
add_theme_support( 'title-tag' );
// Add viewport meta tag for mobile browsers.
add_theme_support( 'genesis-responsive-viewport' );
// Add support for Genesis menus.
add_theme_support( 'genesis-menus', array(
'primary' => __( 'Primary Menu', 'mai-theme-engine' ),
'header_left' => __( 'Header Left Menu', 'mai-theme-engine' ),
'header_right' => __( 'Header Right Menu', 'mai-theme-engine' ),
'secondary' => __( 'Footer Menu', 'mai-theme-engine' ),
'mobile' => __( 'Mobile Menu', 'mai-theme-engine' ),
) );
// Add support for Genesis structural wraps.
add_theme_support( 'genesis-structural-wraps', array(
'archive-description',
'breadcrumb',
'header',
'menu-primary',
'menu-secondary',
'footer-widgets',
'footer',
) );
// Add Genesis accessibility support.
add_theme_support( 'genesis-accessibility', array(
'404-page',
'drop-down-menu',
'headings',
'search-form',
'skip-links',
) );
// Add custom logo support.
add_theme_support( 'custom-logo', array(
'height' => 120, // Optional size
'width' => 240, // Optional size
'flex-height' => true,
'flex-width' => true,
) );
// Add alignfull and alignwide support.
add_theme_support( 'align-wide' );
// Add excerpt support for pages.
add_post_type_support( 'page', 'excerpt' );
/**
* Move Genesis child theme style sheet to a later priority
* to make sure Mai Theme Engine loads CSS first.
*
* Add file time to the version for easier cache-busting when editing files.
*/
remove_action( 'genesis_meta', 'genesis_load_stylesheet' );
add_action( 'wp_enqueue_scripts', 'mai_enqueue_main_stylesheet', 999 );
function mai_enqueue_main_stylesheet() {
$version = defined( 'CHILD_THEME_VERSION' ) && CHILD_THEME_VERSION ? CHILD_THEME_VERSION : PARENT_THEME_VERSION;
$version .= '.' . date ( 'njYHi', filemtime( get_stylesheet_directory() . '/style.css' ) );
wp_enqueue_style( mai_get_handle(), get_stylesheet_uri(), false, $version );
}
// Load default favicon.
add_filter( 'genesis_pre_load_favicon', 'mai_default_favicon' );
function mai_default_favicon( $favicon ) {
return MAI_THEME_ENGINE_PLUGIN_URL . 'assets/images/favicon.png';
}
}, 15 );
/**
* Load our files after theme setup but at an earlier hook
* so devs can override some actions/filters without needing to specific priority.
*/
add_action( 'after_setup_theme', function(){
/**
* Deactivate theme and show notice
* if Mai Theme Engine is not supported in the child theme.
* or if Mai Pro Engine is not supported in the child theme (backwards compatibility).
*
* @link https://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*/
if ( ! current_theme_supports( 'mai-theme-engine' ) && ! current_theme_supports( 'mai-pro-engine' ) ) {
add_action( 'admin_init', array( $this, 'deactivate_plugin' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
return;
}
// Lib.
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . '*.php' ) as $file ) { include_once $file; }
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . 'admin/*.php' ) as $file ) { include_once $file; }
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . 'classes/*.php' ) as $file ) { include_once $file; }
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . 'functions/*.php' ) as $file ) { include_once $file; }
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . 'settings/customizer/*.php' ) as $file ) { include_once $file; }
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . 'settings/metaboxes/*.php' ) as $file ) { include_once $file; }
foreach ( glob( MAI_THEME_ENGINE_LIB_DIR . 'structure/*.php' ) as $file ) { include_once $file; }
// Get the image sizes to register.
$image_sizes = mai_get_image_sizes();
// If image sizes.
if ( $image_sizes ) {
// Loop through and add the image sizes.
foreach ( $image_sizes as $name => $values ) {
add_image_size( $name, $values['width'], $values['height'], $values['crop'] );
}
}
}, 8 );
}
function deactivate_plugin() {
deactivate_plugins( plugin_basename( __FILE__ ) );
}
function admin_notices() {
printf( '<div class="notice notice-error is-dismissible"><p>%s</p></div>', __( '<strong>Your theme does not support the Mai Theme Engine plugin</strong>. As a result, Mai Theme Engine has been deactivated.', 'mai-theme-engine' ) );
// Remove "Plugin activated" notice.
if ( isset( $_GET['activate'] ) ) {
unset( $_GET['activate'] );
}
}
}
// This is only here for backwards compatibility with older Mai Pro themes.
final class Mai_Pro_Engine {}
/**
* The main function for that returns Mai_Theme_Engine
*
* The main function responsible for returning the one true Mai_Theme_Engine
* Instance to functions everywhere.
*
* Use this function like you would a global variable, except without needing
* to declare the global.
*
* Example: <?php $plugin = Mai_Theme_Engine(); ?>
*
* @since 1.0.0
*
* @return object|Mai_Theme_Engine The one true Mai_Theme_Engine Instance.
*/
function Mai_Theme_Engine() {
return Mai_Theme_Engine::instance();
}
// Get Mai_Theme_Engine Running.
Mai_Theme_Engine();