enqueue-scripts.php ➔ podium_scripts()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 4
nop 0
dl 0
loc 64
rs 8.4743
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
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
function podium_scripts()
11
{
12
13
    if (WP_ENV === 'production') {
14
        wp_enqueue_style(
15
            'podium-style',
16
            get_stylesheet_directory_uri() . '/dist/styles/main.min.css',
17
            false,
18
            null
19
        );
20
        wp_enqueue_script(
21
            'podium-scripts',
22
            get_stylesheet_directory_uri() . '/dist/scripts/main.min.js',
23
            null,
24
            null,
25
            true
26
        );
27
    } else {
28
        wp_enqueue_style(
29
            'podium-style',
30
            get_stylesheet_directory_uri() . '/dist/styles/main.css',
31
            false,
32
            null
33
        );
34
        wp_enqueue_script(
35
            'podium-scripts',
36
            get_stylesheet_directory_uri() . '/dist/scripts/main.js',
37
            null,
38
            null,
39
            true
40
        );
41
    }
42
43
// Add resources for individual page templates
44
    // if (is_page_template('page-contact.php')) {
45
46
    //     wp_enqueue_script(
47
    //         'contact-page-script',
48
    //         get_stylesheet_directory_uri() . '/dist/scripts/contact-page.js',
49
    //         ['jquery'],
50
    //         false,
51
    //         true
52
    //     );
53
    //     wp_enqueue_script(
54
    //         'google-recapcha-script',
55
    //         '//www.google.com/recaptcha/api.js?hl='.pll_current_language(),
56
    //         ['contact-page-script'],
57
    //         false,
58
    //         true
59
    //     );
60
61
    // }
62
63
    //remove emoji scripts
64
    remove_action('wp_head', 'print_emoji_detection_script', 7);
65
    remove_action('admin_print_scripts', 'print_emoji_detection_script');
66
    remove_action('wp_print_styles', 'print_emoji_styles');
67
    remove_action('admin_print_styles', 'print_emoji_styles');
68
69
    if (is_singular() && comments_open() && get_option('thread_comments')) {
70
        wp_enqueue_script('comment-reply');
71
    }
72
73
}
74
75
add_action('wp_enqueue_scripts', 'podium_scripts');
76
77
// Defer scripts
78
/**
79
 * @param  $tag
80
 * @param  $handle
81
 * @return mixed
82
 */
83
function podium_add_defer_attribute($tag, $handle)
84
{
85
86
    // add script handles to the array below
87
    $scripts_to_defer = [
88
        'podium-scripts'
89
        //  'more-js-handled'
90
    ];
91
92
    foreach ($scripts_to_defer as $defer_script) {
93
94
        if ($defer_script === $handle) {
95
96
            return str_replace(' src', ' defer="defer" src', $tag);
97
98
        }
99
100
    }
101
102
    return $tag;
103
}
104
105
add_filter('script_loader_tag', 'podium_add_defer_attribute', 10, 2);
106
107
// Async scripts
108
/**
109
 * @param  $tag
110
 * @param  $handle
111
 * @return mixed
112
 */
113
function podium_add_async_attribute($tag, $handle)
114
{
115
    // add script handles to the array below
116
    $scripts_to_async = [
117
118
//  'my-js-handle',
119
        //  'more-js-handled'
120
    ];
121
122
    foreach ($scripts_to_async as $async_script) {
123
124
        if ($async_script === $handle) {
125
126
            return str_replace(' src', ' async="async" src', $tag);
127
128
        }
129
130
    }
131
132
    return $tag;
133
}
134
135
// add_filter('script_loader_tag', 'podium_add_async_attribute', 10, 2);
136