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
368 lines (317 loc) · 10.3 KB
/
Copy pathmai-theme-engine.php
File metadata and controls
368 lines (317 loc) · 10.3 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
/**
* Plugin Name: Mai Theme Engine
* Plugin URI: https://maitheme.com/
* Description: The Mai Theme Engine plugin
*
* Version: 1.2.1
*
* 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.2.1' );
// DB version.
define( 'MAI_THEME_ENGINE_DB_VERSION', '1161' );
// 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 Includes Path.
define( 'MAI_THEME_ENGINE_INCLUDES_DIR', MAI_THEME_ENGINE_PLUGIN_DIR . 'includes/' );
// 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__ ) ) );
}
/**
* Include required files.
*
* @access private
* @since 1.0.0
* @return void
*/
private function hooks() {
// Includes (Vendor).
require_once MAI_THEME_ENGINE_INCLUDES_DIR . 'CMB2/init.php';
require_once MAI_THEME_ENGINE_INCLUDES_DIR . 'PHPColors/Color.php';
require_once MAI_THEME_ENGINE_INCLUDES_DIR . 'plugin-update-checker/plugin-update-checker.php';
// Run the updater.
add_action( 'admin_init', function() {
// Bail if current user cannot manage plugins.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
// Setup the updater.
$updater = Puc_v4_Factory::buildUpdateChecker( 'https://github.com/maithemewp/mai-theme-engine/', __FILE__, 'mai-theme-engine' );
/**
* Allow branch and updater object manipulation.
* This let's us do beta releases via a branch change,
* among other things.
*/
$updater->setBranch( apply_filters( 'mai_updater_branch', 'master' ) );
// 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 title tag support
add_theme_support( 'title-tag' );
// Add viewport meta tag for mobile browsers
add_theme_support( 'genesis-responsive-viewport' );
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 structural wraps
add_theme_support( 'genesis-structural-wraps', array(
'archive-description',
'breadcrumb',
'header',
'menu-primary',
'menu-secondary',
'footer-widgets',
'footer',
) );
// Add 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 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.
*/
remove_action( 'genesis_meta', 'genesis_load_stylesheet' );
add_action( 'wp_enqueue_scripts', 'genesis_enqueue_main_stylesheet', 999 );
// 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';
}
/**
* Create the initial image sizes.
* @link http://andrew.hedges.name/experiments/aspect_ratio/
*/
$image_sizes = array(
'banner' => array(
'width' => 1600,
'height' => 533,
'crop' => true, // 3x1
),
'featured' => array(
'width' => 800,
'height' => 600,
'crop' => true, // 4x3 (works better for no sidebar)
),
'one-half' => array(
'width' => 550,
'height' => 413,
'crop' => true, // 4x3
),
'one-third' => array(
'width' => 350,
'height' => 263,
'crop' => true, // 4x3
),
'one-fourth' => array(
'width' => 260,
'height' => 195,
'crop' => true, // 4x3
),
'tiny' => array(
'width' => 80,
'height' => 80,
'crop' => true, // square
),
);
/**
* Filter the image sizes to allow the theme to override.
*
* // Change the default Mai image sizes
* add_filter( 'mai_image_sizes', 'prefix_custom_image_sizes' );
* function prefix_custom_image_sizes( $image_sizes ) {
*
* // Change one-third image size
* $image_sizes['one-third'] = array(
* 'width' => 350,
* 'height' => 350,
* 'crop' => true,
* );
*
* // Change one-fourth image size
* $image_sizes['one-fourth'] = array(
* 'width' => 260,
* 'height' => 260,
* 'crop' => true,
* );
*
* return $image_sizes;
*
* }
*
*/
$image_sizes = apply_filters( 'mai_image_sizes', $image_sizes );
// Loop through and add the image sizes.
foreach ( $image_sizes as $name => $data ) {
add_image_size( $name, $data['width'], $data['height'], $data['crop'] );
}
}, 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 . '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; }
}, 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, this plugin 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();