Completed
Push — require-acf-plugin ( 4090ee...bc6553 )
by Doğa
05:18 queued 27s
created

Bootstrap::notifyRequiredPluginIsMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
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 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) {
0 ignored issues
show
Unused Code introduced by
The parameter $pluginName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
        add_action('admin_notices', function () {
56
            echo "<div class=\"error\"><p>${pluginName} Plugin not activated. Make sure you activate the plugin on the <a href=\""
0 ignored issues
show
Bug introduced by
The variable $pluginName does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
57
                . esc_url(admin_url('plugins.php')) . "\">plugin page</a>.</p></div>";
58
        });
59
    }
60
}
61