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