Test Failed
Push — develop ( 76157d...9702e2 )
by Paul
08:08
created

Hooks::hasPluginsLoaded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 1
c 2
b 0
f 2
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Breakdance;
4
5
use GeminiLabs\SiteReviews\Integrations\IntegrationHooks;
6
7
class Hooks extends IntegrationHooks
8
{
9
    public function levelPluginsLoaded(): ?int
10
    {
11
        return 5;
12
    }
13
14
    /**
15
     * The "breakdance_loaded" hook is triggered on plugins_loaded:10
16
     * so we need to load hooks earlier than that.
17
     * 
18
     * @action plugins_loaded:5
19
     */
20
    public function onPluginsLoaded(): void
21
    {
22
        if (!$this->isInstalled()) {
23
            return;
24
        }
25
        if (!$this->isVersionSupported()) {
26
            $this->notify('Breakdance');
27
            return;
28
        }
29
        $this->hook(Controller::class, [
30
            ['interceptGetPostsQuery', 'breakdance_ajax_breakdance_get_posts', 1],
31
            ['interceptGetPostsQuery', 'wp_ajax_breakdance_get_posts', 1],
32
            ['interceptGetPostsQuery', 'wp_ajax_nopriv_breakdance_get_posts', 1],
33
            ['printInlineStyles', 'unofficial_i_am_kevin_geary_master_of_all_things_css_and_html'],
34
            ['registerDesignControls', 'init'],
35
            ['registerElements', 'breakdance_loaded', 5], // run early
36
            ['registerRoutes', 'breakdance_loaded', 5], // run early
37
        ]);
38
    }
39
40
    protected function isInstalled(): bool
41
    {
42
        return class_exists('Breakdance\Elements\Element')
43
            && function_exists('Breakdance\AJAX\get_nonce_for_ajax_requests')
44
            && function_exists('Breakdance\AJAX\get_nonce_key_for_ajax_requests')
45
            && function_exists('Breakdance\AJAX\register_handler')
46
            && function_exists('Breakdance\Elements\c')
47
            && function_exists('Breakdance\Elements\PresetSections\getPresetSection')
48
            && function_exists('Breakdance\Elements\registerCategory')
49
            && function_exists('Breakdance\Permissions\hasMinimumPermission');
50
    }
51
52
    protected function supportedVersion(): string
53
    {
54
        return '2.2.0';
55
    }
56
57
    protected function version(): string
58
    {
59
        return defined('__BREAKDANCE_VERSION')
60
            ? (string) \__BREAKDANCE_VERSION
0 ignored issues
show
Bug introduced by
The constant __BREAKDANCE_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
61
            : '';
62
    }
63
}
64