|
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
|
|
|
// 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); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
142
|
|
|
|
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.