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