Completed
Push — componentlibrary ( c84333...cf3ef7 )
by
unknown
01:29
created

functions.php ➔ disallowRobots()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Flynt\Features\BaseStyle;
4
5
use Timber\Timber;
6
use Flynt\ComponentManager;
7
8
if (current_user_can('editor') || (WP_ENV !== 'production')) {
9
    add_filter('init', 'Flynt\Features\BaseStyle\registerRewriteRule');
10
    add_filter('template_include', 'Flynt\Features\BaseStyle\templateInclude');
11
    disallowRobots();
12
}
13
14
const ROUTENAME = 'BaseStyle';
15
16
function disallowRobots()
17
{
18
    if (defined('WPSEO_VERSION')) {
19
        add_filter('wpseo_robots', function () {
20
            return "noindex,nofollow";
21
        });
22
    } else {
23
        remove_action('wp_head', 'noindex', 1);
24
        add_action('wp_head', function () {
25
            echo "<meta name='robots' content='noindex,nofollow' />\n";
26
        });
27
    }
28
}
29
30
function registerRewriteRule()
31
{
32
    $routeName = \Flynt\Features\BaseStyle\ROUTENAME;
33
34
    add_rewrite_rule("{$routeName}/?(.*?)/?$", "index.php?{$routeName}=\$matches[1]", "top");
35
    add_rewrite_tag("%{$routeName}%", "([^&]+)");
36
37
    $rules = get_option('rewrite_rules');
38
39
    if (! isset($rules["{$routeName}/(.*?)/?$"])) {
40
        flush_rewrite_rules();
41
    }
42
}
43
44
function templateInclude($template)
45
{
46
    $routeName = \Flynt\Features\BaseStyle\ROUTENAME;
0 ignored issues
show
Unused Code introduced by
$routeName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
    global $wp_query;
48
49
    if (isset($wp_query->query_vars['BaseStyle'])) {
50
        return __DIR__ . '/template.php';
51
    }
52
53
    return $template;
54
}
55