Completed
Push — require-acf-plugin ( 5037e1 )
by Doğa
09:43 queued 04:24
created

Bootstrap::setTemplateDirectory()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 7
nc 1
nop 0
dl 0
loc 14
rs 9.4285
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
        $flyntCoreActive = class_exists('\\Flynt\\Render');
25
        $acfActive = class_exists('acf');
26
27 View Code Duplication
        if (!$flyntCoreActive) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
            add_action('admin_notices', function () {
29
                echo '<div class="error"><p>Flynt Core Plugin not activated. Make sure you activate the plugin on the <a href="'
30
                    . esc_url(admin_url('plugins.php')) . '">plugin page</a>.</p></div>';
31
            });
32
        }
33
34 View Code Duplication
        if (!$acfActive) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
            add_action('admin_notices', function () {
36
                echo '<div class="error"><p>ACF Plugin not activated. Make sure you activate the plugin on the <a href="'
37
                    . esc_url(admin_url('plugins.php')) . '">plugin page</a>.</p></div>';
38
            });
39
        }
40
41
        if (!$acfActive || !$flyntCoreActive) {
42
            add_filter('template_include', function () {
43
                $newTemplate = locate_template('plugin-inactive.php');
44
                if ('' != $newTemplate) {
45
                    return $newTemplate;
46
                } else {
47
                    return 'One or more required Plugins are not active! Please <a href="'
48
                        . esc_url(admin_url('plugins.php'))
49
                        . '">activate all required plugins</a> and reload the page.';
50
                }
51
            });
52
        }
53
54
        return $acfActive && $flyntCoreActive;
55
    }
56
}
57