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; |
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.