Completed
Push — navigationBreadcrumb ( fce018 )
by
unknown
01:53
created

functions.php ➔ checkYoastActivated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Flynt\Components\NavigationBreadcrumb;
4
5
use Flynt\Features\Components\Component;
6
use Flynt\Features\AdminNotices\AdminNoticeManager;
7
8
add_action('wp_enqueue_scripts', function () {
9
    Component::enqueueAssets('NavigationBreadcrumb');
10
});
11
12
add_action('admin_init', 'Flynt\Components\NavigationBreadcrumb\addYoastRequiredNotice');
13
14
add_filter('Flynt/addComponentData?name=NavigationBreadcrumb', function ($data) {
15
    if (checkYoastActivated()) {
16
        $data['breadcrumbs'] = getOutput('yoast_breadcrumb');
17
    }
18
    return $data;
19
});
20
21
function checkYoastActivated()
22
{
23
    return function_exists('yoast_breadcrumb');
24
}
25
26
function addYoastRequiredNotice()
27
{
28
    if (!checkYoastActivated()) {
29
        $manager = AdminNoticeManager::getInstance();
30
        $message = ["This component requires the Yoast SEO plugin. Please install and active Yoast SEO."];
31
        $options = [
32
            'type' => 'error',
33
            'title' => 'NavigationBreadcrumb Error',
34
            'dismissible' => false,
35
            'filenames' => 'functions.php'
36
        ];
37
        $manager->addNotice($message, $options);
38
    }
39
}
40
41
function getOutput($function)
42
{
43
    ob_start();
44
    $function();
45
    $output = ob_get_contents();
46
    ob_get_clean();
47
    return $output;
48
}
49