Passed
Push — master ( 50adea...d5902b )
by Amit
02:19
created

enqueue-scripts.php ➔ podium_scripts()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 2
nop 0
dl 0
loc 13
rs 9.2
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 26 and the first side effect is on line 30.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * WordPress.com-specific functions and definitions.
4
 *
5
 * This file is centrally included from `wp-content/mu-plugins/wpcom-theme-compat.php`.
6
 *
7
 * @package podium
8
 */
9
10
// Set host name
11
$host = $_SERVER['SERVER_NAME'];
12
13
// List of our development domains
14
$dev_domains = [
15
    'dev.win-site.co.il',
16
    'win-sites.co.il',
17
    'win-site.info',
18
    'localhost',
19
    'devurl.net'
20
];
21
22
if (in_array($host, $dev_domains)) {
23
24
// Set development ENV
25
    if (!defined('WP_ENV')) {
26
        define('WP_ENV', 'development');
27
    }
28
29
    // Hide admin bar
30
    show_admin_bar(false);
31
32
    // Enable strict error reporting
33
    error_reporting(E_ALL | E_STRICT);
34
    @ini_set('display_errors', 1);
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
35
36
} else {
37
38
// Set production ENV
39
    if (!defined('WP_ENV')) {
40
        define('WP_ENV', 'production');
41
    }
42
43
// Limit post revisions to 5.
44
    if (!defined('WP_POST_REVISIONS')) {
45
        define('WP_POST_REVISIONS', 5);
46
    }
47
48
// disallow wp files editor.
49
    if (!defined('DISALLOW_FILE_EDIT')) {
50
        define('DISALLOW_FILE_EDIT', true);
51
    }
52
53
}
54
55
if (!defined('WP_ENV')) {
56
57
// Fallback if WP_ENV isn't defined in your WordPress config
58
59
// Used to check for 'development' or 'production'
60
    if (!defined('WP_ENV')) {
61
        define('WP_ENV', 'production');
62
    }
63
64
}
65
66
// TODO move to seperate files
67
function podium_scripts()
68
{
69
70
    wp_enqueue_style('podium-style', get_stylesheet_directory_uri() . '/dist/styles/main.css', false, null);
71
    wp_enqueue_script('podium-scripts', get_stylesheet_directory_uri() . '/dist/scripts/main.js', ['jquery'], null, true);
72
73
    if (is_singular() && comments_open() && get_option('thread_comments')) {
74
75
        wp_enqueue_script('comment-reply');
76
77
    }
78
79
}
80
81
add_action('wp_enqueue_scripts', 'podium_scripts');
82
83
// Defer scripts
84
/**
85
 * @param  $tag
86
 * @param  $handle
87
 * @return mixed
88
 */
89
function podium_add_defer_attribute($tag, $handle)
90
{
91
92
    // add script handles to the array below
93
    $scripts_to_defer = [
94
        'podium-scripts'
95
        //  'more-js-handled'
96
    ];
97
98
    foreach ($scripts_to_defer as $defer_script) {
99
100
        if ($defer_script === $handle) {
101
102
            return str_replace(' src', ' defer="defer" src', $tag);
103
104
        }
105
106
    }
107
108
    return $tag;
109
}
110
111
add_filter('script_loader_tag', 'podium_add_defer_attribute', 10, 2);
112
113
// Async scripts
114
/**
115
 * @param  $tag
116
 * @param  $handle
117
 * @return mixed
118
 */
119
function podium_add_async_attribute($tag, $handle)
120
{
121
    // add script handles to the array below
122
    $scripts_to_async = [
123
124
//  'my-js-handle',
125
        //  'more-js-handled'
126
    ];
127
128
    foreach ($scripts_to_async as $async_script) {
129
130
        if ($async_script === $handle) {
131
132
            return str_replace(' src', ' async="async" src', $tag);
133
134
        }
135
136
    }
137
138
    return $tag;
139
}
140
141
// add_filter('script_loader_tag', 'podium_add_async_attribute', 10, 2);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
142