Completed
Push — master ( 074470...51e9f3 )
by Dominik
19s queued 13s
created

Init::setTemplateDirectory()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 0
1
<?php
2
3
namespace Flynt;
4
5
use Flynt\Api;
6
use Flynt\Defaults;
7
use Flynt\Utils\AdminNoticeManager;
8
use Flynt\Utils\Asset;
9
use Timber\Timber;
10
11
class Init
12
{
13
    public static function initTheme()
14
    {
15
        Api::registerHooks();
16
        Defaults::init();
17
18
        // Set to true to load all assets from a CDN if there is one specified
19
        Asset::loadFromCdn(false);
20
21
        new Timber();
22
    }
23
24
    public static function loadComponents()
25
    {
26
        $basePath = get_template_directory() . '/Components';
27
        global $flyntCurrentOptionCategory;
28
        $flyntCurrentOptionCategory = 'component';
29
        Api::registerComponentsFromPath($basePath);
30
        do_action('Flynt/afterRegisterComponents');
31
    }
32
33
    public static function checkRequiredPlugins()
34
    {
35
        $acfActive = class_exists('acf');
36
37
        if (!$acfActive) {
38
            self::notifyRequiredPluginIsMissing('ACF');
39
            add_filter('template_include', function () {
40
                die(
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
41
                    'One or more required plugins are not activated! Please <a href="'
42
                    . esc_url(admin_url('plugins.php'))
43
                    . '">activate or install the required plugin(s)</a> and reload the page.'
44
                );
45
            });
46
        }
47
48
        return $acfActive;
49
    }
50
51
    protected static function notifyRequiredPluginIsMissing($pluginName)
52
    {
53
        $manager = AdminNoticeManager::getInstance();
54
55
        $pluginUrl = esc_url(admin_url('plugins.php'));
56
        $message = ["${pluginName} Plugin not activated. Make sure you activate the plugin on the <a href=\"${pluginUrl}\">plugin page</a>."];
57
        $options = [
58
          'type' => 'error',
59
          'title' => 'Flynt is missing a required plugin',
60
          'dismissible' => false,
61
        ];
62
63
        $manager->addNotice($message, $options);
64
    }
65
}
66