@@ -5,68 +5,77 @@ function enqueue_frontend() {
5
5
6
6
$ scripts = $ wpenq ->get_option_map ('scripts ' );
7
7
if ($ scripts ) {
8
+ $ default_scripts = WP_Enqueue_Helper::get_default_scripts ();
8
9
$ index = 0 ;
9
10
10
11
foreach ((array )$ scripts as $ key => $ values ) {
11
12
foreach ((array )$ values as $ value ) {
12
13
13
- $ value = WP_Enqueue_Helper::get_full_url ($ value );
14
14
if ($ key != 'admin ' ) $ index ++; // admin scripts don't affect counter
15
- if ($ key == 'head ' ) wp_enqueue_script ("wpenq-script- $ index " , $ value );
16
- if ($ key == 'home ' && is_home ()) wp_enqueue_script ("wpenq-script- $ index " , $ value );
17
- if ($ key == 'page ' && is_page ()) wp_enqueue_script ("wpenq-script- $ index " , $ value );
18
- if ($ key == 'single ' && is_single ()) wp_enqueue_script ("wpenq-script- $ index " , $ value );
19
- if ($ key == 'archive ' && is_archive ()) wp_enqueue_script ("wpenq-script- $ index " , $ value );
20
- if ($ key == 'category ' && is_category ()) wp_enqueue_script ("wpenq-script- $ index " , $ value );
21
- if ($ key == 'footer ' ) wp_enqueue_script ("wpenq-script- $ index " , $ value , false , false , true );
15
+
16
+ if (in_array ($ value , $ default_scripts )) {
17
+ $ handle = $ value ;
18
+ $ value = false ;
19
+ } else {
20
+ $ handle = "wpenq-script- $ index " ;
21
+ $ value = WP_Enqueue_Helper::get_full_url ($ value );
22
+ }
23
+
24
+ if ($ key == 'head ' ) wp_enqueue_script ($ handle , $ value );
25
+ if ($ key == 'home ' && is_home ()) wp_enqueue_script ($ handle , $ value );
26
+ if ($ key == 'page ' && is_page ()) wp_enqueue_script ($ handle , $ value );
27
+ if ($ key == 'single ' && is_single ()) wp_enqueue_script ($ handle , $ value );
28
+ if ($ key == 'archive ' && is_archive ()) wp_enqueue_script ($ handle , $ value );
29
+ if ($ key == 'category ' && is_category ()) wp_enqueue_script ($ handle , $ value );
30
+ if ($ key == 'footer ' ) wp_enqueue_script ($ handle , $ value , false , false , true );
22
31
23
32
$ condition = explode (' ' , $ key );
24
33
if (count ($ condition ) >= 2 ) {
25
34
if (strcasecmp ($ condition [0 ], 'page ' ) === 0 ) {
26
35
if (strcasecmp ($ condition [1 ], 'footer ' ) === 0 ) {
27
- if (is_page ()) wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
36
+ if (is_page ()) wp_enqueue_script ($ handle , $ value , false , false , true );
28
37
} elseif (is_page ($ condition [1 ])) {
29
38
if (isset ($ condition [2 ]) && $ condition [2 ] == 'footer ' ) {
30
- wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
39
+ wp_enqueue_script ($ handle , $ value , false , false , true );
31
40
} else {
32
- wp_enqueue_script (" wpenq-script- $ index " , $ value );
41
+ wp_enqueue_script ($ handle , $ value );
33
42
}
34
43
}
35
44
} elseif (strcasecmp ($ condition [0 ], 'single ' ) === 0 ) {
36
45
if (strcasecmp ($ condition [1 ], 'footer ' ) === 0 ) {
37
- if (is_single ()) wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
46
+ if (is_single ()) wp_enqueue_script ($ handle , $ value , false , false , true );
38
47
} elseif (is_single ($ condition [1 ])) {
39
48
if (isset ($ condition [2 ]) && $ condition [2 ] == 'footer ' ) {
40
- wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
49
+ wp_enqueue_script ($ handle , $ value , false , false , true );
41
50
} else {
42
- wp_enqueue_script (" wpenq-script- $ index " , $ value );
51
+ wp_enqueue_script ($ handle , $ value );
43
52
}
44
53
}
45
54
} elseif (strcasecmp ($ condition [0 ], 'category ' ) === 0 ) {
46
55
if (strcasecmp ($ condition [1 ], 'footer ' ) === 0 ) {
47
- if (is_category ()) wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
56
+ if (is_category ()) wp_enqueue_script ($ handle , $ value , false , false , true );
48
57
} elseif (is_category ($ condition [1 ])) {
49
58
if (isset ($ condition [2 ]) && $ condition [2 ] == 'footer ' ) {
50
- wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
59
+ wp_enqueue_script ($ handle , $ value , false , false , true );
51
60
} else {
52
- wp_enqueue_script (" wpenq-script- $ index " , $ value );
61
+ wp_enqueue_script ($ handle , $ value );
53
62
}
54
63
}
55
64
} elseif (strcasecmp ($ condition [0 ], 'home ' ) === 0 ) {
56
65
if (strcasecmp ($ condition [1 ], 'footer ' ) === 0 && is_home ()) {
57
- wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
66
+ wp_enqueue_script ($ handle , $ value , false , false , true );
58
67
}
59
68
} elseif (strcasecmp ($ condition [0 ], 'archive ' ) === 0 ) {
60
69
if (strcasecmp ($ condition [1 ], 'footer ' ) === 0 && is_archive ()) {
61
- wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
70
+ wp_enqueue_script ($ handle , $ value , false , false , true );
62
71
}
63
72
} elseif (strcasecmp ($ condition [0 ], 'IE ' ) === 0 ) {
64
73
if (isset ($ condition [2 ]) && $ condition [2 ] == 'footer ' ) {
65
- wp_enqueue_script (" wpenq-script- $ index " , $ value , false , false , true );
74
+ wp_enqueue_script ($ handle , $ value , false , false , true );
66
75
} else {
67
- wp_enqueue_script (" wpenq-script- $ index " , $ value );
76
+ wp_enqueue_script ($ handle , $ value );
68
77
}
69
- wp_script_add_data (" wpenq-script- $ index " ,
78
+ wp_script_add_data ($ handle ,
70
79
'conditional ' , 'lt ' . $ condition [0 ] . ' ' . $ condition [1 ]);
71
80
}
72
81
}
@@ -83,32 +92,35 @@ function enqueue_frontend() {
83
92
foreach ((array )$ styles as $ key => $ values ) {
84
93
foreach ((array )$ values as $ value ) {
85
94
86
- $ value = WP_Enqueue_Helper::get_full_url ($ value );
87
95
if ($ key != 'admin ' ) $ index ++; // admin styles don't affect counter
88
- if ($ key == 'head ' ) wp_enqueue_style ("wpenq-style- $ index " , $ value );
89
- if ($ key == 'home ' && is_home ()) wp_enqueue_style ("wpenq-style- $ index " , $ value );
90
- if ($ key == 'page ' && is_page ()) wp_enqueue_style ("wpenq-style- $ index " , $ value );
91
- if ($ key == 'single ' && is_single ()) wp_enqueue_style ("wpenq-style- $ index " , $ value );
92
- if ($ key == 'archive ' && is_archive ()) wp_enqueue_style ("wpenq-style- $ index " , $ value );
93
- if ($ key == 'category ' && is_category ()) wp_enqueue_style ("wpenq-style- $ index " , $ value );
96
+
97
+ $ handle = "wpenq-style- $ index " ;
98
+ $ value = WP_Enqueue_Helper::get_full_url ($ value );
99
+
100
+ if ($ key == 'head ' ) wp_enqueue_style ($ handle , $ value );
101
+ if ($ key == 'home ' && is_home ()) wp_enqueue_style ($ handle , $ value );
102
+ if ($ key == 'page ' && is_page ()) wp_enqueue_style ($ handle , $ value );
103
+ if ($ key == 'single ' && is_single ()) wp_enqueue_style ($ handle , $ value );
104
+ if ($ key == 'archive ' && is_archive ()) wp_enqueue_style ($ handle , $ value );
105
+ if ($ key == 'category ' && is_category ()) wp_enqueue_style ($ handle , $ value );
94
106
95
107
$ condition = explode (' ' , $ key );
96
108
if (count ($ condition ) >= 2 ) {
97
109
if (strcasecmp ($ condition [0 ], 'page ' ) === 0 ) {
98
110
if (is_page ($ condition [1 ])) {
99
- wp_enqueue_style (" wpenq-style- $ index " , $ value );
111
+ wp_enqueue_style ($ handle , $ value );
100
112
}
101
113
} elseif (strcasecmp ($ condition [0 ], 'single ' ) === 0 ) {
102
114
if (is_single ($ condition [1 ])) {
103
- wp_enqueue_style (" wpenq-style- $ index " , $ value );
115
+ wp_enqueue_style ($ handle , $ value );
104
116
}
105
117
} elseif (strcasecmp ($ condition [0 ], 'category ' ) === 0 ) {
106
118
if (is_category ($ condition [1 ])) {
107
- wp_enqueue_style (" wpenq-style- $ index " , $ value );
119
+ wp_enqueue_style ($ handle , $ value );
108
120
}
109
121
} elseif (strcasecmp ($ condition [0 ], 'IE ' ) === 0 ) {
110
- wp_enqueue_style (" wpenq-style- $ index " , $ value );
111
- wp_style_add_data (" wpenq-style- $ index " ,
122
+ wp_enqueue_style ($ handle , $ value );
123
+ wp_style_add_data ($ handle ,
112
124
'conditional ' , 'lt ' . $ condition [0 ] . ' ' . $ condition [1 ]);
113
125
}
114
126
}
@@ -122,24 +134,34 @@ function enqueue_frontend() {
122
134
function enqueue_admin () {
123
135
global $ wpenq ;
124
136
125
- if ($ scripts = $ wpenq ->get_option_map ('scripts ' )) {
137
+ $ scripts = $ wpenq ->get_option_map ('scripts ' );
138
+ if ($ scripts ) {
139
+ $ default_scripts = WP_Enqueue_Helper::get_default_scripts ();
126
140
$ index = 0 ;
127
141
128
142
foreach ((array )$ scripts as $ key => $ values ) {
129
143
foreach ((array )$ values as $ value ) {
130
144
131
- $ value = WP_Enqueue_Helper::get_full_url ($ value );
145
+ // increment only for admin scripts
146
+ if (mb_stripos ($ value , 'admin ' ) === 0 ) $ index ++;
147
+
148
+ if (in_array ($ value , $ default_scripts )) {
149
+ $ handle = $ value ;
150
+ $ value = false ;
151
+ } else {
152
+ $ handle = "wpenq-admin-script- $ index " ;
153
+ $ value = WP_Enqueue_Helper::get_full_url ($ value );
154
+ }
155
+
132
156
if ($ key == 'admin ' ) {
133
- $ index ++; // increment only for admin scripts
134
- wp_enqueue_script ("wpenq-admin-script- $ index " , $ value );
157
+ wp_enqueue_script ($ handle , $ value );
135
158
}
136
159
137
160
$ condition = explode (' ' , $ key );
138
161
if (count ($ condition ) >= 2 ) {
139
162
if (strcasecmp ($ condition [0 ], 'admin ' ) === 0 ) {
140
163
if (strcasecmp ($ condition [1 ], 'footer ' ) === 0 ) {
141
- $ index ++; // increment only for admin scripts
142
- wp_enqueue_script ("wpenq-admin-script- $ index " , $ value , false , false , true );
164
+ wp_enqueue_script ($ handle , $ value , false , false , true );
143
165
}
144
166
}
145
167
}
@@ -149,16 +171,20 @@ function enqueue_admin() {
149
171
150
172
}
151
173
152
- if ($ styles = $ wpenq ->get_option_map ('styles ' )) {
174
+ $ styles = $ wpenq ->get_option_map ('styles ' );
175
+ if ($ styles ) {
153
176
$ index = 0 ;
154
177
155
178
foreach ((array )$ styles as $ key => $ values ) {
156
179
foreach ((array )$ values as $ value ) {
157
180
158
- $ value = WP_Enqueue_Helper::get_full_url ($ value );
159
181
if ($ key == 'admin ' ) {
160
182
$ index ++; // increment only for admin styles
161
- wp_enqueue_style ("wpenq-admin-style- $ index " , $ value );
183
+
184
+ $ handle = "wpenq-admin-style- $ index " ;
185
+ $ value = WP_Enqueue_Helper::get_full_url ($ value );
186
+
187
+ wp_enqueue_style ($ handle , $ value );
162
188
}
163
189
164
190
}
0 commit comments