forked from wearenolte/lean-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetup.php
More file actions
93 lines (78 loc) · 2.35 KB
/
Setup.php
File metadata and controls
93 lines (78 loc) · 2.35 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
<?php namespace LeanNs;
/**
* Main class loader for initializing and setting up the plugin.
*
* @since 0.1.0
*/
class ThemeSetup {
/**
* Initialise the program after everything is ready.
*
* @since 0.1.0
*/
public static function init() {
add_action( 'switch_theme', [ __CLASS__, 'flush_rewrite_rules' ] );
add_action( 'after_switch_theme', [ __CLASS__, 'activate' ] );
$inc_dir = get_template_directory() . '/src';
$modules_dir = get_template_directory() . '/src/Modules';
// Run the init() function for any inc classes which have it.
foreach ( glob( $inc_dir . '/*.php' ) as $file ) {
$class = '\\' . __NAMESPACE__ . '\\' . basename( $file, '.php' );
if ( method_exists( $class, 'init' ) ) {
call_user_func( [ $class, 'init' ] );
}
}
// Run the Module::init() function for any modules which have it.
foreach ( glob( $modules_dir . '/*', GLOB_ONLYDIR ) as $dir ) {
$module_name = basename( $dir );
$module = '\\' . __NAMESPACE__ . '\\Modules\\' . $module_name . '\\' . $module_name;
if ( method_exists( $module, 'init' ) ) {
call_user_func( [ $module, 'init' ] );
}
}
}
/**
* Checks program environment to see if all dependencies are available. If at least one
* dependency is absent, deactivate the theme.
*
* @since 0.1.0
*/
public static function activate() {
global $wp_version;
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( version_compare( $wp_version, LEANP_MINIMUM_WP_VERSION, '<' ) ) {
$format = 'Plugin %1$s requires WordPress %2$s or higher.';
$msg = sprintf( $format, LEANP_THEME_VERSION, LEANP_MINIMUM_WP_VERSION );
trigger_error( esc_html( $msg ), E_USER_ERROR );
}
self::check_dependencies();
self::flush_rewrite_rules();
}
/**
* Dependency checks
*/
public static function check_dependencies() {
if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
return;
}
error_log( 'The ACF plugin is not active!' );
if ( is_admin() ) :
add_action( 'admin_notices', function() {
?>
<div class="notice notice-error">
<p><?php echo esc_html( 'The ACF plugin is not active!' ); ?></p>
</div>
<?php
});
endif;
}
/**
* Register the CPTs and flush the rewrite rules in order to have correct permalinks.
*
* @since 0.1.0
*/
public static function flush_rewrite_rules() {
self::init();
flush_rewrite_rules();
}
}