Test Failed
Push — develop ( 8b2a32...47c531 )
by Paul
08:13
created

Hooks::run()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 15
rs 9.9
cc 3
nc 3
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Flatsome;
4
5
use GeminiLabs\SiteReviews\Hooks\AbstractHooks;
6
use GeminiLabs\SiteReviews\Modules\Notice;
7
8
class Hooks extends AbstractHooks
9
{
10
    public function run(): void
11
    {
12
        if (!$this->isInstalled()) {
13
            return;
14
        }
15
        if (!$this->isVersionSupported()) {
16
            $this->unsupportedVersionNotice();
17
            return;
18
        }
19
        $this->hook(Controller::class, [
20
            ['printInlineScripts', 'ux_builder_enqueue_scripts'],
21
            ['printInlineStyles', 'ux_builder_enqueue_scripts'],
22
            ['registerShortcodes', 'init'],
23
            ['searchAssignedPosts', 'wp_ajax_ux_builder_search_posts', 1],
24
            ['searchAssignedUsers', 'wp_ajax_ux_builder_search_posts', 2],
25
        ]);
26
    }
27
28
    protected function isInstalled(): bool
29
    {
30
        return 'flatsome' === wp_get_theme(get_template())->get('TextDomain');
31
    }
32
33
    protected function isVersionSupported(): bool
34
    {
35
        return version_compare(wp_get_theme(get_template())->get('Version'), '3.19.0', '>=');
1 ignored issue
show
Bug Best Practice introduced by
The expression return version_compare(w...sion'), '3.19.0', '>=') could return the type integer which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
36
    }
37
38
    protected function unsupportedVersionNotice(): void
39
    {
40
        add_action('admin_notices', function () {
41
            if (!str_starts_with(glsr_current_screen()->post_type, glsr()->post_type)) {
42
                return;
43
            }
44
            glsr(Notice::class)->addWarning(
45
                _x('Update the Flatsome theme to v3.19.0 or higher to enable integration with Site Reviews.', 'admin-text', 'site-reviews')
46
            );
47
        });
48
    }
49
}
50