Completed
Push — master ( 237036...650d4b )
by Dominik
02:47
created

Bootstrap::checkPlugin()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 16
nc 2
nop 0
dl 0
loc 25
rs 8.8571
c 1
b 1
f 0
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 checkPlugin()
23
    {
24
        $pluginActive = class_exists('\\Flynt\\Render');
25
26
        if (!$pluginActive) {
27
            add_action('admin_notices', function () {
28
                echo '<div class="error"><p>Flynt Core Plugin not activated. Make sure you activate the plugin in <a href="'
29
                    . esc_url(admin_url('plugins.php#flynt')) . '">'
30
                    . esc_url(admin_url('plugins.php')) . '</a></p></div>';
31
            });
32
33
            add_filter('template_include', function () {
34
                $newTemplate = locate_template(['plugin-inactive.php']);
35
                if ('' != $newTemplate) {
36
                    return $newTemplate;
37
                } else {
38
                    return 'Flynt Core Plugin not activated! Please <a href="'
39
                        . esc_url(admin_url('plugins.php'))
40
                        . '">activate the plugin</a> and reload the page.';
41
                }
42
            });
43
        }
44
45
        return $pluginActive;
46
    }
47
}
48