1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flynt; |
4
|
|
|
|
5
|
|
|
use Flynt\Api; |
6
|
|
|
use Flynt\Utils\Asset; |
7
|
|
|
use Timber\Timber; |
8
|
|
|
|
9
|
|
|
class Init |
10
|
|
|
{ |
11
|
|
|
public static function initTheme() |
12
|
|
|
{ |
13
|
|
|
Api::registerHooks(); |
14
|
|
|
Api::initDefaults(); |
15
|
|
|
|
16
|
|
|
// Set to true to load all assets from a CDN if there is one specified |
17
|
|
|
Asset::loadFromCdn(false); |
18
|
|
|
|
19
|
|
|
new Timber(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public static function loadFeatures() |
23
|
|
|
{ |
24
|
|
|
$basePath = get_template_directory() . '/dist/Features'; |
25
|
|
|
global $flyntCurrentOptionCategory; |
26
|
|
|
$flyntCurrentOptionCategory = 'feature'; |
27
|
|
|
Api::registerFeaturesFromPath($basePath); |
28
|
|
|
do_action('Flynt/afterRegisterFeatures'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public static function loadComponents() |
32
|
|
|
{ |
33
|
|
|
$basePath = get_template_directory() . '/dist/Components'; |
34
|
|
|
global $flyntCurrentOptionCategory; |
35
|
|
|
$flyntCurrentOptionCategory = 'component'; |
36
|
|
|
Api::registerComponentsFromPath($basePath); |
37
|
|
|
do_action('Flynt/afterRegisterComponents'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function setTemplateDirectory() |
41
|
|
|
{ |
42
|
|
|
add_action('after_switch_theme', function () { |
43
|
|
|
$stylesheet = get_option('stylesheet'); |
44
|
|
|
|
45
|
|
|
if (basename($stylesheet) !== 'templates') { |
46
|
|
|
update_option('stylesheet', $stylesheet . '/templates'); |
47
|
|
|
} |
48
|
|
|
}); |
49
|
|
|
|
50
|
|
|
add_filter('stylesheet', function ($stylesheet) { |
51
|
|
|
return dirname($stylesheet); |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function checkRequiredPlugins() |
56
|
|
|
{ |
57
|
|
|
$acfActive = class_exists('acf'); |
58
|
|
|
|
59
|
|
|
if (!$acfActive) { |
60
|
|
|
self::notifyRequiredPluginIsMissing('ACF'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (!$acfActive) { |
64
|
|
|
add_filter('template_include', function () { |
65
|
|
|
die( |
66
|
|
|
'One or more required plugins are not activated! Please <a href="' |
67
|
|
|
. esc_url(admin_url('plugins.php')) |
68
|
|
|
. '">activate or install the required plugin(s)</a> and reload the page.' |
69
|
|
|
); |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $acfActive; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected static function notifyRequiredPluginIsMissing($pluginName) |
77
|
|
|
{ |
78
|
|
|
add_action('admin_notices', function () use ($pluginName) { |
79
|
|
|
echo "<div class=\"error\"><p>${pluginName} Plugin not activated. Make sure you activate the plugin on the <a href=\"" |
80
|
|
|
. esc_url(admin_url('plugins.php')) . "\">plugin page</a>.</p></div>"; |
81
|
|
|
}); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|