|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Flynt; |
|
4
|
|
|
|
|
5
|
|
|
class Bootstrap |
|
6
|
|
|
{ |
|
7
|
|
|
public static function setTemplateDirectory() |
|
8
|
|
|
{ |
|
9
|
|
|
add_action('after_switch_theme', function () { |
|
10
|
|
|
$stylesheet = get_option('stylesheet'); |
|
11
|
|
|
|
|
12
|
|
|
if (basename($stylesheet) !== 'templates') { |
|
13
|
|
|
update_option('stylesheet', $stylesheet . '/templates'); |
|
14
|
|
|
} |
|
15
|
|
|
}); |
|
16
|
|
|
|
|
17
|
|
|
add_filter('stylesheet', function ($stylesheet) { |
|
18
|
|
|
return dirname($stylesheet); |
|
19
|
|
|
}); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public static function checkRequiredPlugins() |
|
23
|
|
|
{ |
|
24
|
|
|
$flyntCoreActive = class_exists('\\Flynt\\Render'); |
|
25
|
|
|
$acfActive = class_exists('acf'); |
|
26
|
|
|
|
|
27
|
|
|
if (!$flyntCoreActive) { |
|
28
|
|
|
self::notifyRequiredPluginIsMissing('Flynt Core'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
if (!$acfActive) { |
|
32
|
|
|
self::notifyRequiredPluginIsMissing('ACF'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if (!$acfActive || !$flyntCoreActive) { |
|
36
|
|
|
add_filter('template_include', function () { |
|
37
|
|
|
$newTemplate = locate_template('plugin-inactive.php'); |
|
38
|
|
|
if ('' != $newTemplate) { |
|
39
|
|
|
return $newTemplate; |
|
40
|
|
|
} else { |
|
41
|
|
|
trigger_error( |
|
42
|
|
|
'One or more required plugins are not activated! Please <a href="' |
|
43
|
|
|
. esc_url(admin_url('plugins.php')) |
|
44
|
|
|
. '">activate or install the required plugin(s)</a> and reload the page.', |
|
45
|
|
|
E_USER_WARNING |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
}); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $acfActive && $flyntCoreActive; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected static function notifyRequiredPluginIsMissing($pluginName) |
|
55
|
|
|
{ |
|
56
|
|
|
add_action('admin_notices', function () use ($pluginName) { |
|
57
|
|
|
echo "<div class=\"error\"><p>${pluginName} Plugin not activated. Make sure you activate the plugin on the <a href=\"" |
|
58
|
|
|
. esc_url(admin_url('plugins.php')) . "\">plugin page</a>.</p></div>"; |
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|