@@ -95,26 +95,26 @@ discard block |
||
95 | 95 | * @param mixed $group Group level: level (int), no groups (false). |
96 | 96 | * @return array Handles of items that have been processed. |
97 | 97 | */ |
98 | - public function do_items( $handles = false, $group = false ) { |
|
98 | + public function do_items($handles = false, $group = false) { |
|
99 | 99 | /* |
100 | 100 | * If nothing is passed, print the queue. If a string is passed, |
101 | 101 | * print that item. If an array is passed, print those items. |
102 | 102 | */ |
103 | 103 | $handles = false === $handles ? $this->queue : (array) $handles; |
104 | - $this->all_deps( $handles ); |
|
104 | + $this->all_deps($handles); |
|
105 | 105 | |
106 | - foreach ( $this->to_do as $key => $handle ) { |
|
107 | - if ( !in_array($handle, $this->done, true) && isset($this->registered[$handle]) ) { |
|
106 | + foreach ($this->to_do as $key => $handle) { |
|
107 | + if ( ! in_array($handle, $this->done, true) && isset($this->registered[$handle])) { |
|
108 | 108 | /* |
109 | 109 | * Attempt to process the item. If successful, |
110 | 110 | * add the handle to the done array. |
111 | 111 | * |
112 | 112 | * Unset the item from the to_do array. |
113 | 113 | */ |
114 | - if ( $this->do_item( $handle, $group ) ) |
|
114 | + if ($this->do_item($handle, $group)) |
|
115 | 115 | $this->done[] = $handle; |
116 | 116 | |
117 | - unset( $this->to_do[$key] ); |
|
117 | + unset($this->to_do[$key]); |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $handle Name of the item. Should be unique. |
131 | 131 | * @return bool True on success, false if not set. |
132 | 132 | */ |
133 | - public function do_item( $handle ) { |
|
133 | + public function do_item($handle) { |
|
134 | 134 | return isset($this->registered[$handle]); |
135 | 135 | } |
136 | 136 | |
@@ -150,43 +150,43 @@ discard block |
||
150 | 150 | * @param int|false $group Group level: (int) level, (false) no groups. |
151 | 151 | * @return bool True on success, false on failure. |
152 | 152 | */ |
153 | - public function all_deps( $handles, $recursion = false, $group = false ) { |
|
154 | - if ( !$handles = (array) $handles ) |
|
153 | + public function all_deps($handles, $recursion = false, $group = false) { |
|
154 | + if ( ! $handles = (array) $handles) |
|
155 | 155 | return false; |
156 | 156 | |
157 | - foreach ( $handles as $handle ) { |
|
157 | + foreach ($handles as $handle) { |
|
158 | 158 | $handle_parts = explode('?', $handle); |
159 | 159 | $handle = $handle_parts[0]; |
160 | 160 | $queued = in_array($handle, $this->to_do, true); |
161 | 161 | |
162 | - if ( in_array($handle, $this->done, true) ) // Already done |
|
162 | + if (in_array($handle, $this->done, true)) // Already done |
|
163 | 163 | continue; |
164 | 164 | |
165 | - $moved = $this->set_group( $handle, $recursion, $group ); |
|
166 | - $new_group = $this->groups[ $handle ]; |
|
165 | + $moved = $this->set_group($handle, $recursion, $group); |
|
166 | + $new_group = $this->groups[$handle]; |
|
167 | 167 | |
168 | - if ( $queued && !$moved ) // already queued and in the right group |
|
168 | + if ($queued && ! $moved) // already queued and in the right group |
|
169 | 169 | continue; |
170 | 170 | |
171 | 171 | $keep_going = true; |
172 | - if ( !isset($this->registered[$handle]) ) |
|
172 | + if ( ! isset($this->registered[$handle])) |
|
173 | 173 | $keep_going = false; // Item doesn't exist. |
174 | - elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) |
|
174 | + elseif ($this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered))) |
|
175 | 175 | $keep_going = false; // Item requires dependencies that don't exist. |
176 | - elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) ) |
|
176 | + elseif ($this->registered[$handle]->deps && ! $this->all_deps($this->registered[$handle]->deps, true, $new_group)) |
|
177 | 177 | $keep_going = false; // Item requires dependencies that don't exist. |
178 | 178 | |
179 | - if ( ! $keep_going ) { // Either item or its dependencies don't exist. |
|
180 | - if ( $recursion ) |
|
179 | + if ( ! $keep_going) { // Either item or its dependencies don't exist. |
|
180 | + if ($recursion) |
|
181 | 181 | return false; // Abort this branch. |
182 | 182 | else |
183 | 183 | continue; // We're at the top level. Move on to the next one. |
184 | 184 | } |
185 | 185 | |
186 | - if ( $queued ) // Already grabbed it and its dependencies. |
|
186 | + if ($queued) // Already grabbed it and its dependencies. |
|
187 | 187 | continue; |
188 | 188 | |
189 | - if ( isset($handle_parts[1]) ) |
|
189 | + if (isset($handle_parts[1])) |
|
190 | 190 | $this->args[$handle] = $handle_parts[1]; |
191 | 191 | |
192 | 192 | $this->to_do[] = $handle; |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | * @param mixed $args Optional. Custom property of the item. NOT the class property $args. Examples: $media, $in_footer. |
215 | 215 | * @return bool Whether the item has been registered. True on success, false on failure. |
216 | 216 | */ |
217 | - public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { |
|
218 | - if ( isset($this->registered[$handle]) ) |
|
217 | + public function add($handle, $src, $deps = array(), $ver = false, $args = null) { |
|
218 | + if (isset($this->registered[$handle])) |
|
219 | 219 | return false; |
220 | - $this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); |
|
220 | + $this->registered[$handle] = new _WP_Dependency($handle, $src, $deps, $ver, $args); |
|
221 | 221 | return true; |
222 | 222 | } |
223 | 223 | |
@@ -234,11 +234,11 @@ discard block |
||
234 | 234 | * @param mixed $value The data value. |
235 | 235 | * @return bool True on success, false on failure. |
236 | 236 | */ |
237 | - public function add_data( $handle, $key, $value ) { |
|
238 | - if ( !isset( $this->registered[$handle] ) ) |
|
237 | + public function add_data($handle, $key, $value) { |
|
238 | + if ( ! isset($this->registered[$handle])) |
|
239 | 239 | return false; |
240 | 240 | |
241 | - return $this->registered[$handle]->add_data( $key, $value ); |
|
241 | + return $this->registered[$handle]->add_data($key, $value); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -253,11 +253,11 @@ discard block |
||
253 | 253 | * @param string $key The data key. |
254 | 254 | * @return mixed Extra item data (string), false otherwise. |
255 | 255 | */ |
256 | - public function get_data( $handle, $key ) { |
|
257 | - if ( !isset( $this->registered[$handle] ) ) |
|
256 | + public function get_data($handle, $key) { |
|
257 | + if ( ! isset($this->registered[$handle])) |
|
258 | 258 | return false; |
259 | 259 | |
260 | - if ( !isset( $this->registered[$handle]->extra[$key] ) ) |
|
260 | + if ( ! isset($this->registered[$handle]->extra[$key])) |
|
261 | 261 | return false; |
262 | 262 | |
263 | 263 | return $this->registered[$handle]->extra[$key]; |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings). |
274 | 274 | * @return void |
275 | 275 | */ |
276 | - public function remove( $handles ) { |
|
277 | - foreach ( (array) $handles as $handle ) |
|
276 | + public function remove($handles) { |
|
277 | + foreach ((array) $handles as $handle) |
|
278 | 278 | unset($this->registered[$handle]); |
279 | 279 | } |
280 | 280 | |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings). |
294 | 294 | */ |
295 | - public function enqueue( $handles ) { |
|
296 | - foreach ( (array) $handles as $handle ) { |
|
295 | + public function enqueue($handles) { |
|
296 | + foreach ((array) $handles as $handle) { |
|
297 | 297 | $handle = explode('?', $handle); |
298 | - if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) { |
|
298 | + if ( ! in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]])) { |
|
299 | 299 | $this->queue[] = $handle[0]; |
300 | - if ( isset($handle[1]) ) |
|
300 | + if (isset($handle[1])) |
|
301 | 301 | $this->args[$handle[0]] = $handle[1]; |
302 | 302 | } |
303 | 303 | } |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | * |
316 | 316 | * @param mixed $handles Item handle and argument (string) or item handles and arguments (array of strings). |
317 | 317 | */ |
318 | - public function dequeue( $handles ) { |
|
319 | - foreach ( (array) $handles as $handle ) { |
|
318 | + public function dequeue($handles) { |
|
319 | + foreach ((array) $handles as $handle) { |
|
320 | 320 | $handle = explode('?', $handle); |
321 | 321 | $key = array_search($handle[0], $this->queue); |
322 | - if ( false !== $key ) { |
|
322 | + if (false !== $key) { |
|
323 | 323 | unset($this->queue[$key]); |
324 | 324 | unset($this->args[$handle[0]]); |
325 | 325 | } |
@@ -335,15 +335,15 @@ discard block |
||
335 | 335 | * @param string $handle Name of the item. Should be unique. |
336 | 336 | * @return bool Whether the handle is found after recursively searching the dependency tree. |
337 | 337 | */ |
338 | - protected function recurse_deps( $queue, $handle ) { |
|
339 | - foreach ( $queue as $queued ) { |
|
340 | - if ( ! isset( $this->registered[ $queued ] ) ) { |
|
338 | + protected function recurse_deps($queue, $handle) { |
|
339 | + foreach ($queue as $queued) { |
|
340 | + if ( ! isset($this->registered[$queued])) { |
|
341 | 341 | continue; |
342 | 342 | } |
343 | 343 | |
344 | - if ( in_array( $handle, $this->registered[ $queued ]->deps ) ) { |
|
344 | + if (in_array($handle, $this->registered[$queued]->deps)) { |
|
345 | 345 | return true; |
346 | - } elseif ( $this->recurse_deps( $this->registered[ $queued ]->deps, $handle ) ) { |
|
346 | + } elseif ($this->recurse_deps($this->registered[$queued]->deps, $handle)) { |
|
347 | 347 | return true; |
348 | 348 | } |
349 | 349 | } |
@@ -362,28 +362,28 @@ discard block |
||
362 | 362 | * @param string $list Property name of list array. |
363 | 363 | * @return bool|_WP_Dependency Found, or object Item data. |
364 | 364 | */ |
365 | - public function query( $handle, $list = 'registered' ) { |
|
366 | - switch ( $list ) { |
|
365 | + public function query($handle, $list = 'registered') { |
|
366 | + switch ($list) { |
|
367 | 367 | case 'registered' : |
368 | 368 | case 'scripts': // back compat |
369 | - if ( isset( $this->registered[ $handle ] ) ) |
|
370 | - return $this->registered[ $handle ]; |
|
369 | + if (isset($this->registered[$handle])) |
|
370 | + return $this->registered[$handle]; |
|
371 | 371 | return false; |
372 | 372 | |
373 | 373 | case 'enqueued' : |
374 | 374 | case 'queue' : |
375 | - if ( in_array( $handle, $this->queue ) ) { |
|
375 | + if (in_array($handle, $this->queue)) { |
|
376 | 376 | return true; |
377 | 377 | } |
378 | - return $this->recurse_deps( $this->queue, $handle ); |
|
378 | + return $this->recurse_deps($this->queue, $handle); |
|
379 | 379 | |
380 | 380 | case 'to_do' : |
381 | 381 | case 'to_print': // back compat |
382 | - return in_array( $handle, $this->to_do ); |
|
382 | + return in_array($handle, $this->to_do); |
|
383 | 383 | |
384 | 384 | case 'done' : |
385 | 385 | case 'printed': // back compat |
386 | - return in_array( $handle, $this->done ); |
|
386 | + return in_array($handle, $this->done); |
|
387 | 387 | } |
388 | 388 | return false; |
389 | 389 | } |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | * @param mixed $group Group level. |
400 | 400 | * @return bool Not already in the group or a lower group |
401 | 401 | */ |
402 | - public function set_group( $handle, $recursion, $group ) { |
|
402 | + public function set_group($handle, $recursion, $group) { |
|
403 | 403 | $group = (int) $group; |
404 | 404 | |
405 | - if ( isset( $this->groups[ $handle ] ) && $this->groups[ $handle ] <= $group ) { |
|
405 | + if (isset($this->groups[$handle]) && $this->groups[$handle] <= $group) { |
|
406 | 406 | return false; |
407 | 407 | } |
408 | 408 | |
409 | - $this->groups[ $handle ] = $group; |
|
409 | + $this->groups[$handle] = $group; |
|
410 | 410 | |
411 | 411 | return true; |
412 | 412 | } |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * @since 2.6.0 |
468 | 468 | * @var null |
469 | 469 | */ |
470 | - public $args = null; // Custom property, such as $in_footer or $media. |
|
470 | + public $args = null; // Custom property, such as $in_footer or $media. |
|
471 | 471 | |
472 | 472 | /** |
473 | 473 | * Extra data to supply to the handle. |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | * @since 2.6.0 |
485 | 485 | */ |
486 | 486 | public function __construct() { |
487 | - @list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args(); |
|
488 | - if ( ! is_array($this->deps) ) |
|
487 | + @list($this->handle, $this->src, $this->deps, $this->ver, $this->args) = func_get_args(); |
|
488 | + if ( ! is_array($this->deps)) |
|
489 | 489 | $this->deps = array(); |
490 | 490 | } |
491 | 491 | |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | * @param mixed $data The data value to add. |
500 | 500 | * @return bool False if not scalar, true otherwise. |
501 | 501 | */ |
502 | - public function add_data( $name, $data ) { |
|
503 | - if ( !is_scalar($name) ) |
|
502 | + public function add_data($name, $data) { |
|
503 | + if ( ! is_scalar($name)) |
|
504 | 504 | return false; |
505 | 505 | $this->extra[$name] = $data; |
506 | 506 | return true; |
@@ -111,8 +111,9 @@ discard block |
||
111 | 111 | * |
112 | 112 | * Unset the item from the to_do array. |
113 | 113 | */ |
114 | - if ( $this->do_item( $handle, $group ) ) |
|
115 | - $this->done[] = $handle; |
|
114 | + if ( $this->do_item( $handle, $group ) ) { |
|
115 | + $this->done[] = $handle; |
|
116 | + } |
|
116 | 117 | |
117 | 118 | unset( $this->to_do[$key] ); |
118 | 119 | } |
@@ -151,43 +152,61 @@ discard block |
||
151 | 152 | * @return bool True on success, false on failure. |
152 | 153 | */ |
153 | 154 | public function all_deps( $handles, $recursion = false, $group = false ) { |
154 | - if ( !$handles = (array) $handles ) |
|
155 | - return false; |
|
155 | + if ( !$handles = (array) $handles ) { |
|
156 | + return false; |
|
157 | + } |
|
156 | 158 | |
157 | 159 | foreach ( $handles as $handle ) { |
158 | 160 | $handle_parts = explode('?', $handle); |
159 | 161 | $handle = $handle_parts[0]; |
160 | 162 | $queued = in_array($handle, $this->to_do, true); |
161 | 163 | |
162 | - if ( in_array($handle, $this->done, true) ) // Already done |
|
164 | + if ( in_array($handle, $this->done, true) ) { |
|
165 | + // Already done |
|
163 | 166 | continue; |
167 | + } |
|
164 | 168 | |
165 | 169 | $moved = $this->set_group( $handle, $recursion, $group ); |
166 | 170 | $new_group = $this->groups[ $handle ]; |
167 | 171 | |
168 | - if ( $queued && !$moved ) // already queued and in the right group |
|
172 | + if ( $queued && !$moved ) { |
|
173 | + // already queued and in the right group |
|
169 | 174 | continue; |
175 | + } |
|
170 | 176 | |
171 | 177 | $keep_going = true; |
172 | - if ( !isset($this->registered[$handle]) ) |
|
173 | - $keep_going = false; // Item doesn't exist. |
|
174 | - elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) |
|
175 | - $keep_going = false; // Item requires dependencies that don't exist. |
|
176 | - elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) ) |
|
177 | - $keep_going = false; // Item requires dependencies that don't exist. |
|
178 | + if ( !isset($this->registered[$handle]) ) { |
|
179 | + $keep_going = false; |
|
180 | + } |
|
181 | + // Item doesn't exist. |
|
182 | + elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) ) { |
|
183 | + $keep_going = false; |
|
184 | + } |
|
185 | + // Item requires dependencies that don't exist. |
|
186 | + elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true, $new_group ) ) { |
|
187 | + $keep_going = false; |
|
188 | + } |
|
189 | + // Item requires dependencies that don't exist. |
|
178 | 190 | |
179 | 191 | if ( ! $keep_going ) { // Either item or its dependencies don't exist. |
180 | - if ( $recursion ) |
|
181 | - return false; // Abort this branch. |
|
182 | - else |
|
183 | - continue; // We're at the top level. Move on to the next one. |
|
192 | + if ( $recursion ) { |
|
193 | + return false; |
|
194 | + } |
|
195 | + // Abort this branch. |
|
196 | + else { |
|
197 | + continue; |
|
198 | + } |
|
199 | + // We're at the top level. Move on to the next one. |
|
184 | 200 | } |
185 | 201 | |
186 | - if ( $queued ) // Already grabbed it and its dependencies. |
|
202 | + if ( $queued ) { |
|
203 | + // Already grabbed it and its dependencies. |
|
187 | 204 | continue; |
205 | + } |
|
188 | 206 | |
189 | - if ( isset($handle_parts[1]) ) |
|
190 | - $this->args[$handle] = $handle_parts[1]; |
|
207 | + if ( isset($handle_parts[1]) ) { |
|
208 | + $this->args[$handle] = $handle_parts[1]; |
|
209 | + } |
|
191 | 210 | |
192 | 211 | $this->to_do[] = $handle; |
193 | 212 | } |
@@ -215,8 +234,9 @@ discard block |
||
215 | 234 | * @return bool Whether the item has been registered. True on success, false on failure. |
216 | 235 | */ |
217 | 236 | public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) { |
218 | - if ( isset($this->registered[$handle]) ) |
|
219 | - return false; |
|
237 | + if ( isset($this->registered[$handle]) ) { |
|
238 | + return false; |
|
239 | + } |
|
220 | 240 | $this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args ); |
221 | 241 | return true; |
222 | 242 | } |
@@ -235,8 +255,9 @@ discard block |
||
235 | 255 | * @return bool True on success, false on failure. |
236 | 256 | */ |
237 | 257 | public function add_data( $handle, $key, $value ) { |
238 | - if ( !isset( $this->registered[$handle] ) ) |
|
239 | - return false; |
|
258 | + if ( !isset( $this->registered[$handle] ) ) { |
|
259 | + return false; |
|
260 | + } |
|
240 | 261 | |
241 | 262 | return $this->registered[$handle]->add_data( $key, $value ); |
242 | 263 | } |
@@ -254,11 +275,13 @@ discard block |
||
254 | 275 | * @return mixed Extra item data (string), false otherwise. |
255 | 276 | */ |
256 | 277 | public function get_data( $handle, $key ) { |
257 | - if ( !isset( $this->registered[$handle] ) ) |
|
258 | - return false; |
|
278 | + if ( !isset( $this->registered[$handle] ) ) { |
|
279 | + return false; |
|
280 | + } |
|
259 | 281 | |
260 | - if ( !isset( $this->registered[$handle]->extra[$key] ) ) |
|
261 | - return false; |
|
282 | + if ( !isset( $this->registered[$handle]->extra[$key] ) ) { |
|
283 | + return false; |
|
284 | + } |
|
262 | 285 | |
263 | 286 | return $this->registered[$handle]->extra[$key]; |
264 | 287 | } |
@@ -274,8 +297,9 @@ discard block |
||
274 | 297 | * @return void |
275 | 298 | */ |
276 | 299 | public function remove( $handles ) { |
277 | - foreach ( (array) $handles as $handle ) |
|
278 | - unset($this->registered[$handle]); |
|
300 | + foreach ( (array) $handles as $handle ) { |
|
301 | + unset($this->registered[$handle]); |
|
302 | + } |
|
279 | 303 | } |
280 | 304 | |
281 | 305 | /** |
@@ -297,8 +321,9 @@ discard block |
||
297 | 321 | $handle = explode('?', $handle); |
298 | 322 | if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) { |
299 | 323 | $this->queue[] = $handle[0]; |
300 | - if ( isset($handle[1]) ) |
|
301 | - $this->args[$handle[0]] = $handle[1]; |
|
324 | + if ( isset($handle[1]) ) { |
|
325 | + $this->args[$handle[0]] = $handle[1]; |
|
326 | + } |
|
302 | 327 | } |
303 | 328 | } |
304 | 329 | } |
@@ -366,8 +391,9 @@ discard block |
||
366 | 391 | switch ( $list ) { |
367 | 392 | case 'registered' : |
368 | 393 | case 'scripts': // back compat |
369 | - if ( isset( $this->registered[ $handle ] ) ) |
|
370 | - return $this->registered[ $handle ]; |
|
394 | + if ( isset( $this->registered[ $handle ] ) ) { |
|
395 | + return $this->registered[ $handle ]; |
|
396 | + } |
|
371 | 397 | return false; |
372 | 398 | |
373 | 399 | case 'enqueued' : |
@@ -485,8 +511,9 @@ discard block |
||
485 | 511 | */ |
486 | 512 | public function __construct() { |
487 | 513 | @list( $this->handle, $this->src, $this->deps, $this->ver, $this->args ) = func_get_args(); |
488 | - if ( ! is_array($this->deps) ) |
|
489 | - $this->deps = array(); |
|
514 | + if ( ! is_array($this->deps) ) { |
|
515 | + $this->deps = array(); |
|
516 | + } |
|
490 | 517 | } |
491 | 518 | |
492 | 519 | /** |
@@ -500,8 +527,9 @@ discard block |
||
500 | 527 | * @return bool False if not scalar, true otherwise. |
501 | 528 | */ |
502 | 529 | public function add_data( $name, $data ) { |
503 | - if ( !is_scalar($name) ) |
|
504 | - return false; |
|
530 | + if ( !is_scalar($name) ) { |
|
531 | + return false; |
|
532 | + } |
|
505 | 533 | $this->extra[$name] = $data; |
506 | 534 | return true; |
507 | 535 | } |
@@ -498,7 +498,7 @@ |
||
498 | 498 | |
499 | 499 | /** |
500 | 500 | * Determines script dependencies. |
501 | - * |
|
501 | + * |
|
502 | 502 | * @since 2.1.0 |
503 | 503 | * @access public |
504 | 504 | * |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | */ |
152 | 152 | public function __construct() { |
153 | 153 | $this->init(); |
154 | - add_action( 'init', array( $this, 'init' ), 0 ); |
|
154 | + add_action('init', array($this, 'init'), 0); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @param WP_Scripts &$this WP_Scripts instance, passed by reference. |
170 | 170 | */ |
171 | - do_action_ref_array( 'wp_default_scripts', array(&$this) ); |
|
171 | + do_action_ref_array('wp_default_scripts', array(&$this)); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * Default false. |
187 | 187 | * @return array Scripts that have been printed. |
188 | 188 | */ |
189 | - public function print_scripts( $handles = false, $group = false ) { |
|
190 | - return $this->do_items( $handles, $group ); |
|
189 | + public function print_scripts($handles = false, $group = false) { |
|
190 | + return $this->do_items($handles, $group); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
@@ -205,9 +205,9 @@ discard block |
||
205 | 205 | * Default true. |
206 | 206 | * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise. |
207 | 207 | */ |
208 | - public function print_scripts_l10n( $handle, $echo = true ) { |
|
209 | - _deprecated_function( __FUNCTION__, '3.3', 'print_extra_script()' ); |
|
210 | - return $this->print_extra_script( $handle, $echo ); |
|
208 | + public function print_scripts_l10n($handle, $echo = true) { |
|
209 | + _deprecated_function(__FUNCTION__, '3.3', 'print_extra_script()'); |
|
210 | + return $this->print_extra_script($handle, $echo); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -221,11 +221,11 @@ discard block |
||
221 | 221 | * Default true. |
222 | 222 | * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise. |
223 | 223 | */ |
224 | - public function print_extra_script( $handle, $echo = true ) { |
|
225 | - if ( !$output = $this->get_data( $handle, 'data' ) ) |
|
224 | + public function print_extra_script($handle, $echo = true) { |
|
225 | + if ( ! $output = $this->get_data($handle, 'data')) |
|
226 | 226 | return; |
227 | 227 | |
228 | - if ( !$echo ) |
|
228 | + if ( ! $echo) |
|
229 | 229 | return $output; |
230 | 230 | |
231 | 231 | echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5 |
@@ -250,50 +250,50 @@ discard block |
||
250 | 250 | * @param int|false $group Optional. Group level: (int) level, (false) no groups. Default false. |
251 | 251 | * @return bool True on success, false on failure. |
252 | 252 | */ |
253 | - public function do_item( $handle, $group = false ) { |
|
254 | - if ( !parent::do_item($handle) ) |
|
253 | + public function do_item($handle, $group = false) { |
|
254 | + if ( ! parent::do_item($handle)) |
|
255 | 255 | return false; |
256 | 256 | |
257 | - if ( 0 === $group && $this->groups[$handle] > 0 ) { |
|
257 | + if (0 === $group && $this->groups[$handle] > 0) { |
|
258 | 258 | $this->in_footer[] = $handle; |
259 | 259 | return false; |
260 | 260 | } |
261 | 261 | |
262 | - if ( false === $group && in_array($handle, $this->in_footer, true) ) |
|
263 | - $this->in_footer = array_diff( $this->in_footer, (array) $handle ); |
|
262 | + if (false === $group && in_array($handle, $this->in_footer, true)) |
|
263 | + $this->in_footer = array_diff($this->in_footer, (array) $handle); |
|
264 | 264 | |
265 | 265 | $obj = $this->registered[$handle]; |
266 | 266 | |
267 | - if ( null === $obj->ver ) { |
|
267 | + if (null === $obj->ver) { |
|
268 | 268 | $ver = ''; |
269 | 269 | } else { |
270 | 270 | $ver = $obj->ver ? $obj->ver : $this->default_version; |
271 | 271 | } |
272 | 272 | |
273 | - if ( isset($this->args[$handle]) ) |
|
274 | - $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
273 | + if (isset($this->args[$handle])) |
|
274 | + $ver = $ver ? $ver.'&'.$this->args[$handle] : $this->args[$handle]; |
|
275 | 275 | |
276 | 276 | $src = $obj->src; |
277 | 277 | $cond_before = $cond_after = ''; |
278 | - $conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : ''; |
|
278 | + $conditional = isset($obj->extra['conditional']) ? $obj->extra['conditional'] : ''; |
|
279 | 279 | |
280 | - if ( $conditional ) { |
|
280 | + if ($conditional) { |
|
281 | 281 | $cond_before = "<!--[if {$conditional}]>\n"; |
282 | 282 | $cond_after = "<![endif]-->\n"; |
283 | 283 | } |
284 | 284 | |
285 | - $before_handle = $this->print_inline_script( $handle, 'before', false ); |
|
286 | - $after_handle = $this->print_inline_script( $handle, 'after', false ); |
|
285 | + $before_handle = $this->print_inline_script($handle, 'before', false); |
|
286 | + $after_handle = $this->print_inline_script($handle, 'after', false); |
|
287 | 287 | |
288 | - if ( $before_handle ) { |
|
289 | - $before_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $before_handle ); |
|
288 | + if ($before_handle) { |
|
289 | + $before_handle = sprintf("<script type='text/javascript'>\n%s\n</script>\n", $before_handle); |
|
290 | 290 | } |
291 | 291 | |
292 | - if ( $after_handle ) { |
|
293 | - $after_handle = sprintf( "<script type='text/javascript'>\n%s\n</script>\n", $after_handle ); |
|
292 | + if ($after_handle) { |
|
293 | + $after_handle = sprintf("<script type='text/javascript'>\n%s\n</script>\n", $after_handle); |
|
294 | 294 | } |
295 | 295 | |
296 | - if ( $this->do_concat ) { |
|
296 | + if ($this->do_concat) { |
|
297 | 297 | /** |
298 | 298 | * Filter the script loader source. |
299 | 299 | * |
@@ -302,14 +302,14 @@ discard block |
||
302 | 302 | * @param string $src Script loader source path. |
303 | 303 | * @param string $handle Script handle. |
304 | 304 | */ |
305 | - $srce = apply_filters( 'script_loader_src', $src, $handle ); |
|
305 | + $srce = apply_filters('script_loader_src', $src, $handle); |
|
306 | 306 | |
307 | - if ( $before_handle && ! $conditional ) { |
|
307 | + if ($before_handle && ! $conditional) { |
|
308 | 308 | $this->print_html_before .= $before_handle; |
309 | 309 | } |
310 | 310 | |
311 | - if ( $this->in_default_dir( $srce ) && ! $conditional && ! $after_handle ) { |
|
312 | - $this->print_code .= $this->print_extra_script( $handle, false ); |
|
311 | + if ($this->in_default_dir($srce) && ! $conditional && ! $after_handle) { |
|
312 | + $this->print_code .= $this->print_extra_script($handle, false); |
|
313 | 313 | $this->concat .= "$handle,"; |
314 | 314 | $this->concat_version .= "$handle$ver"; |
315 | 315 | return true; |
@@ -319,34 +319,34 @@ discard block |
||
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
322 | - $has_conditional_data = $conditional && $this->get_data( $handle, 'data' ); |
|
322 | + $has_conditional_data = $conditional && $this->get_data($handle, 'data'); |
|
323 | 323 | |
324 | - if ( $has_conditional_data ) { |
|
324 | + if ($has_conditional_data) { |
|
325 | 325 | echo $cond_before; |
326 | 326 | } |
327 | 327 | |
328 | - $this->print_extra_script( $handle ); |
|
328 | + $this->print_extra_script($handle); |
|
329 | 329 | |
330 | - if ( $has_conditional_data ) { |
|
330 | + if ($has_conditional_data) { |
|
331 | 331 | echo $cond_after; |
332 | 332 | } |
333 | 333 | |
334 | 334 | // A single item may alias a set of items, by having dependencies, but no source. |
335 | - if ( ! $obj->src ) { |
|
335 | + if ( ! $obj->src) { |
|
336 | 336 | return true; |
337 | 337 | } |
338 | 338 | |
339 | - if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && 0 === strpos( $src, $this->content_url ) ) ) { |
|
340 | - $src = $this->base_url . $src; |
|
339 | + if ( ! preg_match('|^(https?:)?//|', $src) && ! ($this->content_url && 0 === strpos($src, $this->content_url))) { |
|
340 | + $src = $this->base_url.$src; |
|
341 | 341 | } |
342 | 342 | |
343 | - if ( ! empty( $ver ) ) |
|
344 | - $src = add_query_arg( 'ver', $ver, $src ); |
|
343 | + if ( ! empty($ver)) |
|
344 | + $src = add_query_arg('ver', $ver, $src); |
|
345 | 345 | |
346 | 346 | /** This filter is documented in wp-includes/class.wp-scripts.php */ |
347 | - $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); |
|
347 | + $src = esc_url(apply_filters('script_loader_src', $src, $handle)); |
|
348 | 348 | |
349 | - if ( ! $src ) |
|
349 | + if ( ! $src) |
|
350 | 350 | return true; |
351 | 351 | |
352 | 352 | $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}"; |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * @param string $handle The script's registered handle. |
361 | 361 | * @param string $src The script's source URL. |
362 | 362 | */ |
363 | - $tag = apply_filters( 'script_loader_tag', $tag, $handle, $src ); |
|
363 | + $tag = apply_filters('script_loader_tag', $tag, $handle, $src); |
|
364 | 364 | |
365 | - if ( $this->do_concat ) { |
|
366 | - if ( $after_handle ) { |
|
365 | + if ($this->do_concat) { |
|
366 | + if ($after_handle) { |
|
367 | 367 | $this->print_html_before .= $tag; |
368 | 368 | } else { |
369 | 369 | $this->print_html .= $tag; |
@@ -387,19 +387,19 @@ discard block |
||
387 | 387 | * or after. Default 'after'. |
388 | 388 | * @return bool True on success, false on failure. |
389 | 389 | */ |
390 | - public function add_inline_script( $handle, $data, $position = 'after' ) { |
|
391 | - if ( ! $data ) { |
|
390 | + public function add_inline_script($handle, $data, $position = 'after') { |
|
391 | + if ( ! $data) { |
|
392 | 392 | return false; |
393 | 393 | } |
394 | 394 | |
395 | - if ( 'after' !== $position ) { |
|
395 | + if ('after' !== $position) { |
|
396 | 396 | $position = 'before'; |
397 | 397 | } |
398 | 398 | |
399 | - $script = (array) $this->get_data( $handle, $position ); |
|
399 | + $script = (array) $this->get_data($handle, $position); |
|
400 | 400 | $script[] = $data; |
401 | 401 | |
402 | - return $this->add_data( $handle, $position, $script ); |
|
402 | + return $this->add_data($handle, $position, $script); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -415,17 +415,17 @@ discard block |
||
415 | 415 | * Default true. |
416 | 416 | * @return string|false Script on success, false otherwise. |
417 | 417 | */ |
418 | - public function print_inline_script( $handle, $position = 'after', $echo = true ) { |
|
419 | - $output = $this->get_data( $handle, $position ); |
|
418 | + public function print_inline_script($handle, $position = 'after', $echo = true) { |
|
419 | + $output = $this->get_data($handle, $position); |
|
420 | 420 | |
421 | - if ( empty( $output ) ) { |
|
421 | + if (empty($output)) { |
|
422 | 422 | return false; |
423 | 423 | } |
424 | 424 | |
425 | - $output = trim( implode( "\n", $output ), "\n" ); |
|
425 | + $output = trim(implode("\n", $output), "\n"); |
|
426 | 426 | |
427 | - if ( $echo ) { |
|
428 | - printf( "<script type='text/javascript'>\n%s\n</script>\n", $output ); |
|
427 | + if ($echo) { |
|
428 | + printf("<script type='text/javascript'>\n%s\n</script>\n", $output); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | return $output; |
@@ -442,33 +442,33 @@ discard block |
||
442 | 442 | * @param array $l10n |
443 | 443 | * @return bool |
444 | 444 | */ |
445 | - public function localize( $handle, $object_name, $l10n ) { |
|
446 | - if ( $handle === 'jquery' ) |
|
445 | + public function localize($handle, $object_name, $l10n) { |
|
446 | + if ($handle === 'jquery') |
|
447 | 447 | $handle = 'jquery-core'; |
448 | 448 | |
449 | - if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present |
|
449 | + if (is_array($l10n) && isset($l10n['l10n_print_after'])) { // back compat, preserve the code in 'l10n_print_after' if present |
|
450 | 450 | $after = $l10n['l10n_print_after']; |
451 | 451 | unset($l10n['l10n_print_after']); |
452 | 452 | } |
453 | 453 | |
454 | - foreach ( (array) $l10n as $key => $value ) { |
|
455 | - if ( !is_scalar($value) ) |
|
454 | + foreach ((array) $l10n as $key => $value) { |
|
455 | + if ( ! is_scalar($value)) |
|
456 | 456 | continue; |
457 | 457 | |
458 | - $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); |
|
458 | + $l10n[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
459 | 459 | } |
460 | 460 | |
461 | - $script = "var $object_name = " . wp_json_encode( $l10n ) . ';'; |
|
461 | + $script = "var $object_name = ".wp_json_encode($l10n).';'; |
|
462 | 462 | |
463 | - if ( !empty($after) ) |
|
463 | + if ( ! empty($after)) |
|
464 | 464 | $script .= "\n$after;"; |
465 | 465 | |
466 | - $data = $this->get_data( $handle, 'data' ); |
|
466 | + $data = $this->get_data($handle, 'data'); |
|
467 | 467 | |
468 | - if ( !empty( $data ) ) |
|
468 | + if ( ! empty($data)) |
|
469 | 469 | $script = "$data\n$script"; |
470 | 470 | |
471 | - return $this->add_data( $handle, 'data', $script ); |
|
471 | + return $this->add_data($handle, 'data', $script); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
@@ -484,16 +484,16 @@ discard block |
||
484 | 484 | * @param int|false $group Optional. Group level: (int) level, (false) no groups. Default false. |
485 | 485 | * @return bool Not already in the group or a lower group |
486 | 486 | */ |
487 | - public function set_group( $handle, $recursion, $group = false ) { |
|
488 | - if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 ) |
|
487 | + public function set_group($handle, $recursion, $group = false) { |
|
488 | + if (isset($this->registered[$handle]->args) && $this->registered[$handle]->args === 1) |
|
489 | 489 | $grp = 1; |
490 | 490 | else |
491 | - $grp = (int) $this->get_data( $handle, 'group' ); |
|
491 | + $grp = (int) $this->get_data($handle, 'group'); |
|
492 | 492 | |
493 | - if ( false !== $group && $grp > $group ) |
|
493 | + if (false !== $group && $grp > $group) |
|
494 | 494 | $grp = $group; |
495 | 495 | |
496 | - return parent::set_group( $handle, $recursion, $grp ); |
|
496 | + return parent::set_group($handle, $recursion, $grp); |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | /** |
@@ -509,9 +509,9 @@ discard block |
||
509 | 509 | * @param int|false $group Optional. Group level: (int) level, (false) no groups. Default false. |
510 | 510 | * @return bool True on success, false on failure. |
511 | 511 | */ |
512 | - public function all_deps( $handles, $recursion = false, $group = false ) { |
|
513 | - $r = parent::all_deps( $handles, $recursion, $group ); |
|
514 | - if ( ! $recursion ) { |
|
512 | + public function all_deps($handles, $recursion = false, $group = false) { |
|
513 | + $r = parent::all_deps($handles, $recursion, $group); |
|
514 | + if ( ! $recursion) { |
|
515 | 515 | /** |
516 | 516 | * Filter the list of script dependencies left to print. |
517 | 517 | * |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @param array $to_do An array of script dependencies. |
521 | 521 | */ |
522 | - $this->to_do = apply_filters( 'print_scripts_array', $this->to_do ); |
|
522 | + $this->to_do = apply_filters('print_scripts_array', $this->to_do); |
|
523 | 523 | } |
524 | 524 | return $r; |
525 | 525 | } |
@@ -563,17 +563,17 @@ discard block |
||
563 | 563 | * @param string $src The source of the enqueued script. |
564 | 564 | * @return bool True if found, false if not. |
565 | 565 | */ |
566 | - public function in_default_dir( $src ) { |
|
567 | - if ( ! $this->default_dirs ) { |
|
566 | + public function in_default_dir($src) { |
|
567 | + if ( ! $this->default_dirs) { |
|
568 | 568 | return true; |
569 | 569 | } |
570 | 570 | |
571 | - if ( 0 === strpos( $src, '/' . WPINC . '/js/l10n' ) ) { |
|
571 | + if (0 === strpos($src, '/'.WPINC.'/js/l10n')) { |
|
572 | 572 | return false; |
573 | 573 | } |
574 | 574 | |
575 | - foreach ( (array) $this->default_dirs as $test ) { |
|
576 | - if ( 0 === strpos( $src, $test ) ) { |
|
575 | + foreach ((array) $this->default_dirs as $test) { |
|
576 | + if (0 === strpos($src, $test)) { |
|
577 | 577 | return true; |
578 | 578 | } |
579 | 579 | } |
@@ -222,11 +222,13 @@ discard block |
||
222 | 222 | * @return bool|string|void Void if no data exists, extra scripts if `$echo` is true, true otherwise. |
223 | 223 | */ |
224 | 224 | public function print_extra_script( $handle, $echo = true ) { |
225 | - if ( !$output = $this->get_data( $handle, 'data' ) ) |
|
226 | - return; |
|
225 | + if ( !$output = $this->get_data( $handle, 'data' ) ) { |
|
226 | + return; |
|
227 | + } |
|
227 | 228 | |
228 | - if ( !$echo ) |
|
229 | - return $output; |
|
229 | + if ( !$echo ) { |
|
230 | + return $output; |
|
231 | + } |
|
230 | 232 | |
231 | 233 | echo "<script type='text/javascript'>\n"; // CDATA and type='text/javascript' is not needed for HTML 5 |
232 | 234 | echo "/* <![CDATA[ */\n"; |
@@ -251,16 +253,18 @@ discard block |
||
251 | 253 | * @return bool True on success, false on failure. |
252 | 254 | */ |
253 | 255 | public function do_item( $handle, $group = false ) { |
254 | - if ( !parent::do_item($handle) ) |
|
255 | - return false; |
|
256 | + if ( !parent::do_item($handle) ) { |
|
257 | + return false; |
|
258 | + } |
|
256 | 259 | |
257 | 260 | if ( 0 === $group && $this->groups[$handle] > 0 ) { |
258 | 261 | $this->in_footer[] = $handle; |
259 | 262 | return false; |
260 | 263 | } |
261 | 264 | |
262 | - if ( false === $group && in_array($handle, $this->in_footer, true) ) |
|
263 | - $this->in_footer = array_diff( $this->in_footer, (array) $handle ); |
|
265 | + if ( false === $group && in_array($handle, $this->in_footer, true) ) { |
|
266 | + $this->in_footer = array_diff( $this->in_footer, (array) $handle ); |
|
267 | + } |
|
264 | 268 | |
265 | 269 | $obj = $this->registered[$handle]; |
266 | 270 | |
@@ -270,8 +274,9 @@ discard block |
||
270 | 274 | $ver = $obj->ver ? $obj->ver : $this->default_version; |
271 | 275 | } |
272 | 276 | |
273 | - if ( isset($this->args[$handle]) ) |
|
274 | - $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
277 | + if ( isset($this->args[$handle]) ) { |
|
278 | + $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
279 | + } |
|
275 | 280 | |
276 | 281 | $src = $obj->src; |
277 | 282 | $cond_before = $cond_after = ''; |
@@ -340,14 +345,16 @@ discard block |
||
340 | 345 | $src = $this->base_url . $src; |
341 | 346 | } |
342 | 347 | |
343 | - if ( ! empty( $ver ) ) |
|
344 | - $src = add_query_arg( 'ver', $ver, $src ); |
|
348 | + if ( ! empty( $ver ) ) { |
|
349 | + $src = add_query_arg( 'ver', $ver, $src ); |
|
350 | + } |
|
345 | 351 | |
346 | 352 | /** This filter is documented in wp-includes/class.wp-scripts.php */ |
347 | 353 | $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) ); |
348 | 354 | |
349 | - if ( ! $src ) |
|
350 | - return true; |
|
355 | + if ( ! $src ) { |
|
356 | + return true; |
|
357 | + } |
|
351 | 358 | |
352 | 359 | $tag = "{$cond_before}{$before_handle}<script type='text/javascript' src='$src'></script>\n{$after_handle}{$cond_after}"; |
353 | 360 | |
@@ -443,8 +450,9 @@ discard block |
||
443 | 450 | * @return bool |
444 | 451 | */ |
445 | 452 | public function localize( $handle, $object_name, $l10n ) { |
446 | - if ( $handle === 'jquery' ) |
|
447 | - $handle = 'jquery-core'; |
|
453 | + if ( $handle === 'jquery' ) { |
|
454 | + $handle = 'jquery-core'; |
|
455 | + } |
|
448 | 456 | |
449 | 457 | if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present |
450 | 458 | $after = $l10n['l10n_print_after']; |
@@ -452,21 +460,24 @@ discard block |
||
452 | 460 | } |
453 | 461 | |
454 | 462 | foreach ( (array) $l10n as $key => $value ) { |
455 | - if ( !is_scalar($value) ) |
|
456 | - continue; |
|
463 | + if ( !is_scalar($value) ) { |
|
464 | + continue; |
|
465 | + } |
|
457 | 466 | |
458 | 467 | $l10n[$key] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8'); |
459 | 468 | } |
460 | 469 | |
461 | 470 | $script = "var $object_name = " . wp_json_encode( $l10n ) . ';'; |
462 | 471 | |
463 | - if ( !empty($after) ) |
|
464 | - $script .= "\n$after;"; |
|
472 | + if ( !empty($after) ) { |
|
473 | + $script .= "\n$after;"; |
|
474 | + } |
|
465 | 475 | |
466 | 476 | $data = $this->get_data( $handle, 'data' ); |
467 | 477 | |
468 | - if ( !empty( $data ) ) |
|
469 | - $script = "$data\n$script"; |
|
478 | + if ( !empty( $data ) ) { |
|
479 | + $script = "$data\n$script"; |
|
480 | + } |
|
470 | 481 | |
471 | 482 | return $this->add_data( $handle, 'data', $script ); |
472 | 483 | } |
@@ -485,13 +496,15 @@ discard block |
||
485 | 496 | * @return bool Not already in the group or a lower group |
486 | 497 | */ |
487 | 498 | public function set_group( $handle, $recursion, $group = false ) { |
488 | - if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 ) |
|
489 | - $grp = 1; |
|
490 | - else |
|
491 | - $grp = (int) $this->get_data( $handle, 'group' ); |
|
499 | + if ( isset( $this->registered[$handle]->args ) && $this->registered[$handle]->args === 1 ) { |
|
500 | + $grp = 1; |
|
501 | + } else { |
|
502 | + $grp = (int) $this->get_data( $handle, 'group' ); |
|
503 | + } |
|
492 | 504 | |
493 | - if ( false !== $group && $grp > $group ) |
|
494 | - $grp = $group; |
|
505 | + if ( false !== $group && $grp > $group ) { |
|
506 | + $grp = $group; |
|
507 | + } |
|
495 | 508 | |
496 | 509 | return parent::set_group( $handle, $recursion, $grp ); |
497 | 510 | } |
@@ -22,9 +22,9 @@ discard block |
||
22 | 22 | * @param int $priority Optional. Used to specify the order in which the registered handlers will |
23 | 23 | * be tested. Default 10. |
24 | 24 | */ |
25 | -function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) { |
|
25 | +function wp_embed_register_handler($id, $regex, $callback, $priority = 10) { |
|
26 | 26 | global $wp_embed; |
27 | - $wp_embed->register_handler( $id, $regex, $callback, $priority ); |
|
27 | + $wp_embed->register_handler($id, $regex, $callback, $priority); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * @param string $id The handler ID that should be removed. |
38 | 38 | * @param int $priority Optional. The priority of the handler to be removed. Default 10. |
39 | 39 | */ |
40 | -function wp_embed_unregister_handler( $id, $priority = 10 ) { |
|
40 | +function wp_embed_unregister_handler($id, $priority = 10) { |
|
41 | 41 | global $wp_embed; |
42 | - $wp_embed->unregister_handler( $id, $priority ); |
|
42 | + $wp_embed->unregister_handler($id, $priority); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * |
61 | 61 | * @return array Default embed parameters. |
62 | 62 | */ |
63 | -function wp_embed_defaults( $url = '' ) { |
|
64 | - if ( ! empty( $GLOBALS['content_width'] ) ) |
|
63 | +function wp_embed_defaults($url = '') { |
|
64 | + if ( ! empty($GLOBALS['content_width'])) |
|
65 | 65 | $width = (int) $GLOBALS['content_width']; |
66 | 66 | |
67 | - if ( empty( $width ) ) |
|
67 | + if (empty($width)) |
|
68 | 68 | $width = 500; |
69 | 69 | |
70 | - $height = min( ceil( $width * 1.5 ), 1000 ); |
|
70 | + $height = min(ceil($width * 1.5), 1000); |
|
71 | 71 | |
72 | 72 | /** |
73 | 73 | * Filter the default array of embed dimensions. |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * in pixels (in that order). |
79 | 79 | * @param string $url The URL that should be embedded. |
80 | 80 | */ |
81 | - return apply_filters( 'embed_defaults', compact( 'width', 'height' ), $url ); |
|
81 | + return apply_filters('embed_defaults', compact('width', 'height'), $url); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | * Default empty. |
94 | 94 | * @return false|string False on failure or the embed HTML on success. |
95 | 95 | */ |
96 | -function wp_oembed_get( $url, $args = '' ) { |
|
97 | - require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
|
96 | +function wp_oembed_get($url, $args = '') { |
|
97 | + require_once(ABSPATH.WPINC.'/class-oembed.php'); |
|
98 | 98 | $oembed = _wp_oembed_get_object(); |
99 | - return $oembed->get_html( $url, $args ); |
|
99 | + return $oembed->get_html($url, $args); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | * @param string $provider The URL to the oEmbed provider. |
112 | 112 | * @param boolean $regex Optional. Whether the `$format` parameter is in a RegEx format. Default false. |
113 | 113 | */ |
114 | -function wp_oembed_add_provider( $format, $provider, $regex = false ) { |
|
115 | - require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
|
114 | +function wp_oembed_add_provider($format, $provider, $regex = false) { |
|
115 | + require_once(ABSPATH.WPINC.'/class-oembed.php'); |
|
116 | 116 | |
117 | - if ( did_action( 'plugins_loaded' ) ) { |
|
117 | + if (did_action('plugins_loaded')) { |
|
118 | 118 | $oembed = _wp_oembed_get_object(); |
119 | - $oembed->providers[$format] = array( $provider, $regex ); |
|
119 | + $oembed->providers[$format] = array($provider, $regex); |
|
120 | 120 | } else { |
121 | - WP_oEmbed::_add_provider_early( $format, $provider, $regex ); |
|
121 | + WP_oEmbed::_add_provider_early($format, $provider, $regex); |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
@@ -132,18 +132,18 @@ discard block |
||
132 | 132 | * @param string $format The URL format for the oEmbed provider to remove. |
133 | 133 | * @return bool Was the provider removed successfully? |
134 | 134 | */ |
135 | -function wp_oembed_remove_provider( $format ) { |
|
136 | - require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
|
135 | +function wp_oembed_remove_provider($format) { |
|
136 | + require_once(ABSPATH.WPINC.'/class-oembed.php'); |
|
137 | 137 | |
138 | - if ( did_action( 'plugins_loaded' ) ) { |
|
138 | + if (did_action('plugins_loaded')) { |
|
139 | 139 | $oembed = _wp_oembed_get_object(); |
140 | 140 | |
141 | - if ( isset( $oembed->providers[ $format ] ) ) { |
|
142 | - unset( $oembed->providers[ $format ] ); |
|
141 | + if (isset($oembed->providers[$format])) { |
|
142 | + unset($oembed->providers[$format]); |
|
143 | 143 | return true; |
144 | 144 | } |
145 | 145 | } else { |
146 | - WP_oEmbed::_remove_provider_early( $format ); |
|
146 | + WP_oEmbed::_remove_provider_early($format); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return false; |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @param bool $maybe_load_embeds Whether to load the embeds library. Default true. |
171 | 171 | */ |
172 | - if ( ! apply_filters( 'load_default_embeds', true ) ) { |
|
172 | + if ( ! apply_filters('load_default_embeds', true)) { |
|
173 | 173 | return; |
174 | 174 | } |
175 | 175 | |
176 | - wp_embed_register_handler( 'youtube_embed_url', '#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i', 'wp_embed_handler_youtube' ); |
|
176 | + wp_embed_register_handler('youtube_embed_url', '#https?://(www.)?youtube\.com/(?:v|embed)/([^/]+)#i', 'wp_embed_handler_youtube'); |
|
177 | 177 | |
178 | - wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' ); |
|
178 | + wp_embed_register_handler('googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo'); |
|
179 | 179 | |
180 | 180 | /** |
181 | 181 | * Filter the audio embed handler callback. |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | * |
185 | 185 | * @param callable $handler Audio embed handler callback function. |
186 | 186 | */ |
187 | - wp_embed_register_handler( 'audio', '#^https?://.+?\.(' . join( '|', wp_get_audio_extensions() ) . ')$#i', apply_filters( 'wp_audio_embed_handler', 'wp_embed_handler_audio' ), 9999 ); |
|
187 | + wp_embed_register_handler('audio', '#^https?://.+?\.('.join('|', wp_get_audio_extensions()).')$#i', apply_filters('wp_audio_embed_handler', 'wp_embed_handler_audio'), 9999); |
|
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Filter the video embed handler callback. |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @param callable $handler Video embed handler callback function. |
195 | 195 | */ |
196 | - wp_embed_register_handler( 'video', '#^https?://.+?\.(' . join( '|', wp_get_video_extensions() ) . ')$#i', apply_filters( 'wp_video_embed_handler', 'wp_embed_handler_video' ), 9999 ); |
|
196 | + wp_embed_register_handler('video', '#^https?://.+?\.('.join('|', wp_get_video_extensions()).')$#i', apply_filters('wp_video_embed_handler', 'wp_embed_handler_video'), 9999); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
@@ -210,13 +210,13 @@ discard block |
||
210 | 210 | * @param array $rawattr The original unmodified attributes. |
211 | 211 | * @return string The embed HTML. |
212 | 212 | */ |
213 | -function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) { |
|
213 | +function wp_embed_handler_googlevideo($matches, $attr, $url, $rawattr) { |
|
214 | 214 | // If the user supplied a fixed width AND height, use it |
215 | - if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) { |
|
215 | + if ( ! empty($rawattr['width']) && ! empty($rawattr['height'])) { |
|
216 | 216 | $width = (int) $rawattr['width']; |
217 | 217 | $height = (int) $rawattr['height']; |
218 | 218 | } else { |
219 | - list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] ); |
|
219 | + list($width, $height) = wp_expand_dimensions(425, 344, $attr['width'], $attr['height']); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @param string $url The original URL that was matched by the regex. |
231 | 231 | * @param array $rawattr The original unmodified attributes. |
232 | 232 | */ |
233 | - return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&hl=en&fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr ); |
|
233 | + return apply_filters('embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid='.esc_attr($matches[2]).'&hl=en&fs=true" style="width:'.esc_attr($width).'px;height:'.esc_attr($height).'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | * @param array $rawattr The original unmodified attributes. |
250 | 250 | * @return string The embed HTML. |
251 | 251 | */ |
252 | -function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) { |
|
252 | +function wp_embed_handler_youtube($matches, $attr, $url, $rawattr) { |
|
253 | 253 | global $wp_embed; |
254 | - $embed = $wp_embed->autoembed( "https://youtube.com/watch?v={$matches[2]}" ); |
|
254 | + $embed = $wp_embed->autoembed("https://youtube.com/watch?v={$matches[2]}"); |
|
255 | 255 | |
256 | 256 | /** |
257 | 257 | * Filter the YoutTube embed output. |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * @param string $url The original URL that was matched by the regex. |
266 | 266 | * @param array $rawattr The original unmodified attributes. |
267 | 267 | */ |
268 | - return apply_filters( 'wp_embed_handler_youtube', $embed, $attr, $url, $rawattr ); |
|
268 | + return apply_filters('wp_embed_handler_youtube', $embed, $attr, $url, $rawattr); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | * @param array $rawattr The original unmodified attributes. |
280 | 280 | * @return string The embed HTML. |
281 | 281 | */ |
282 | -function wp_embed_handler_audio( $matches, $attr, $url, $rawattr ) { |
|
283 | - $audio = sprintf( '[audio src="%s" /]', esc_url( $url ) ); |
|
282 | +function wp_embed_handler_audio($matches, $attr, $url, $rawattr) { |
|
283 | + $audio = sprintf('[audio src="%s" /]', esc_url($url)); |
|
284 | 284 | |
285 | 285 | /** |
286 | 286 | * Filter the audio embed output. |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @param string $url The original URL that was matched by the regex. |
293 | 293 | * @param array $rawattr The original unmodified attributes. |
294 | 294 | */ |
295 | - return apply_filters( 'wp_embed_handler_audio', $audio, $attr, $url, $rawattr ); |
|
295 | + return apply_filters('wp_embed_handler_audio', $audio, $attr, $url, $rawattr); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | * @param array $rawattr The original unmodified attributes. |
307 | 307 | * @return string The embed HTML. |
308 | 308 | */ |
309 | -function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) { |
|
309 | +function wp_embed_handler_video($matches, $attr, $url, $rawattr) { |
|
310 | 310 | $dimensions = ''; |
311 | - if ( ! empty( $rawattr['width'] ) && ! empty( $rawattr['height'] ) ) { |
|
312 | - $dimensions .= sprintf( 'width="%d" ', (int) $rawattr['width'] ); |
|
313 | - $dimensions .= sprintf( 'height="%d" ', (int) $rawattr['height'] ); |
|
311 | + if ( ! empty($rawattr['width']) && ! empty($rawattr['height'])) { |
|
312 | + $dimensions .= sprintf('width="%d" ', (int) $rawattr['width']); |
|
313 | + $dimensions .= sprintf('height="%d" ', (int) $rawattr['height']); |
|
314 | 314 | } |
315 | - $video = sprintf( '[video %s src="%s" /]', $dimensions, esc_url( $url ) ); |
|
315 | + $video = sprintf('[video %s src="%s" /]', $dimensions, esc_url($url)); |
|
316 | 316 | |
317 | 317 | /** |
318 | 318 | * Filter the video embed output. |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * @param string $url The original URL that was matched by the regex. |
325 | 325 | * @param array $rawattr The original unmodified attributes. |
326 | 326 | */ |
327 | - return apply_filters( 'wp_embed_handler_video', $video, $attr, $url, $rawattr ); |
|
327 | + return apply_filters('wp_embed_handler_video', $video, $attr, $url, $rawattr); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -345,11 +345,11 @@ discard block |
||
345 | 345 | function wp_oembed_add_discovery_links() { |
346 | 346 | $output = ''; |
347 | 347 | |
348 | - if ( is_singular() ) { |
|
349 | - $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink() ) ) . '" />' . "\n"; |
|
348 | + if (is_singular()) { |
|
349 | + $output .= '<link rel="alternate" type="application/json+oembed" href="'.esc_url(get_oembed_endpoint_url(get_permalink())).'" />'."\n"; |
|
350 | 350 | |
351 | - if ( class_exists( 'SimpleXMLElement' ) ) { |
|
352 | - $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url( get_oembed_endpoint_url( get_permalink(), 'xml' ) ) . '" />' . "\n"; |
|
351 | + if (class_exists('SimpleXMLElement')) { |
|
352 | + $output .= '<link rel="alternate" type="text/xml+oembed" href="'.esc_url(get_oembed_endpoint_url(get_permalink(), 'xml')).'" />'."\n"; |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param string $output HTML of the discovery links. |
362 | 362 | */ |
363 | - echo apply_filters( 'oembed_discovery_links', $output ); |
|
363 | + echo apply_filters('oembed_discovery_links', $output); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @since 4.4.0 |
370 | 370 | */ |
371 | 371 | function wp_oembed_add_host_js() { |
372 | - wp_enqueue_script( 'wp-embed' ); |
|
372 | + wp_enqueue_script('wp-embed'); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -380,18 +380,18 @@ discard block |
||
380 | 380 | * @param int|WP_Post $post Optional. Post ID or object. Defaults to the current post. |
381 | 381 | * @return string|false The post embed URL on success, false if the post doesn't exist. |
382 | 382 | */ |
383 | -function get_post_embed_url( $post = null ) { |
|
384 | - $post = get_post( $post ); |
|
383 | +function get_post_embed_url($post = null) { |
|
384 | + $post = get_post($post); |
|
385 | 385 | |
386 | - if ( ! $post ) { |
|
386 | + if ( ! $post) { |
|
387 | 387 | return false; |
388 | 388 | } |
389 | 389 | |
390 | - $embed_url = trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' ); |
|
391 | - $path_conflict = get_page_by_path( str_replace( home_url(), '', $embed_url ), OBJECT, get_post_types( array( 'public' => true ) ) ); |
|
390 | + $embed_url = trailingslashit(get_permalink($post)).user_trailingslashit('embed'); |
|
391 | + $path_conflict = get_page_by_path(str_replace(home_url(), '', $embed_url), OBJECT, get_post_types(array('public' => true))); |
|
392 | 392 | |
393 | - if ( ! get_option( 'permalink_structure' ) || $path_conflict ) { |
|
394 | - $embed_url = add_query_arg( array( 'embed' => 'true' ), get_permalink( $post ) ); |
|
393 | + if ( ! get_option('permalink_structure') || $path_conflict) { |
|
394 | + $embed_url = add_query_arg(array('embed' => 'true'), get_permalink($post)); |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | /** |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | * @param string $embed_url The post embed URL. |
403 | 403 | * @param WP_Post $post The corresponding post object. |
404 | 404 | */ |
405 | - return esc_url_raw( apply_filters( 'post_embed_url', $embed_url, $post ) ); |
|
405 | + return esc_url_raw(apply_filters('post_embed_url', $embed_url, $post)); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | /** |
@@ -416,18 +416,18 @@ discard block |
||
416 | 416 | * @param string $format Optional. The requested response format. Default 'json'. |
417 | 417 | * @return string The oEmbed endpoint URL. |
418 | 418 | */ |
419 | -function get_oembed_endpoint_url( $permalink = '', $format = 'json' ) { |
|
420 | - $url = rest_url( 'oembed/1.0/embed' ); |
|
419 | +function get_oembed_endpoint_url($permalink = '', $format = 'json') { |
|
420 | + $url = rest_url('oembed/1.0/embed'); |
|
421 | 421 | |
422 | - if ( 'json' === $format ) { |
|
422 | + if ('json' === $format) { |
|
423 | 423 | $format = false; |
424 | 424 | } |
425 | 425 | |
426 | - if ( '' !== $permalink ) { |
|
427 | - $url = add_query_arg( array( |
|
428 | - 'url' => urlencode( $permalink ), |
|
426 | + if ('' !== $permalink) { |
|
427 | + $url = add_query_arg(array( |
|
428 | + 'url' => urlencode($permalink), |
|
429 | 429 | 'format' => $format, |
430 | - ), $url ); |
|
430 | + ), $url); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | * @param string $permalink The permalink used for the `url` query arg. |
440 | 440 | * @param string $format The requested response format. |
441 | 441 | */ |
442 | - return apply_filters( 'oembed_endpoint_url', $url, $permalink, $format ); |
|
442 | + return apply_filters('oembed_endpoint_url', $url, $permalink, $format); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -452,21 +452,21 @@ discard block |
||
452 | 452 | * @param int|WP_Post $post Optional. Post ID or object. Default is global `$post`. |
453 | 453 | * @return string|false Embed code on success, false if post doesn't exist. |
454 | 454 | */ |
455 | -function get_post_embed_html( $width, $height, $post = null ) { |
|
456 | - $post = get_post( $post ); |
|
455 | +function get_post_embed_html($width, $height, $post = null) { |
|
456 | + $post = get_post($post); |
|
457 | 457 | |
458 | - if ( ! $post ) { |
|
458 | + if ( ! $post) { |
|
459 | 459 | return false; |
460 | 460 | } |
461 | 461 | |
462 | - $embed_url = get_post_embed_url( $post ); |
|
462 | + $embed_url = get_post_embed_url($post); |
|
463 | 463 | |
464 | - $output = '<blockquote class="wp-embedded-content"><a href="' . esc_url( get_permalink( $post ) ) . '">' . get_the_title( $post ) . "</a></blockquote>\n"; |
|
464 | + $output = '<blockquote class="wp-embedded-content"><a href="'.esc_url(get_permalink($post)).'">'.get_the_title($post)."</a></blockquote>\n"; |
|
465 | 465 | |
466 | 466 | $output .= "<script type='text/javascript'>\n"; |
467 | 467 | $output .= "<!--//--><![CDATA[//><!--\n"; |
468 | - if ( SCRIPT_DEBUG ) { |
|
469 | - $output .= file_get_contents( ABSPATH . WPINC . '/js/wp-embed.js' ); |
|
468 | + if (SCRIPT_DEBUG) { |
|
469 | + $output .= file_get_contents(ABSPATH.WPINC.'/js/wp-embed.js'); |
|
470 | 470 | } else { |
471 | 471 | /* |
472 | 472 | * If you're looking at a src version of this file, you'll see an "include" |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | * minified JavaScript. If you need to debug it, please turn on SCRIPT_DEBUG |
479 | 479 | * and edit wp-embed.js directly. |
480 | 480 | */ |
481 | - $output .=<<<JS |
|
481 | + $output .= <<<JS |
|
482 | 482 | include "js/wp-embed.min.js" |
483 | 483 | JS; |
484 | 484 | } |
@@ -487,15 +487,15 @@ discard block |
||
487 | 487 | |
488 | 488 | $output .= sprintf( |
489 | 489 | '<iframe sandbox="allow-scripts" security="restricted" src="%1$s" width="%2$d" height="%3$d" title="%4$s" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" class="wp-embedded-content"></iframe>', |
490 | - esc_url( $embed_url ), |
|
491 | - absint( $width ), |
|
492 | - absint( $height ), |
|
490 | + esc_url($embed_url), |
|
491 | + absint($width), |
|
492 | + absint($height), |
|
493 | 493 | esc_attr( |
494 | 494 | sprintf( |
495 | 495 | /* translators: 1: post title, 2: site name */ |
496 | - __( '“%1$s” — %2$s' ), |
|
497 | - get_the_title( $post ), |
|
498 | - get_bloginfo( 'name' ) |
|
496 | + __('“%1$s” — %2$s'), |
|
497 | + get_the_title($post), |
|
498 | + get_bloginfo('name') |
|
499 | 499 | ) |
500 | 500 | ) |
501 | 501 | ); |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @param int $width Width of the response. |
511 | 511 | * @param int $height Height of the response. |
512 | 512 | */ |
513 | - return apply_filters( 'embed_html', $output, $post, $width, $height ); |
|
513 | + return apply_filters('embed_html', $output, $post, $width, $height); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | * @param int $width The requested width. |
523 | 523 | * @return array|false Response data on success, false if post doesn't exist. |
524 | 524 | */ |
525 | -function get_oembed_response_data( $post, $width ) { |
|
526 | - $post = get_post( $post ); |
|
525 | +function get_oembed_response_data($post, $width) { |
|
526 | + $post = get_post($post); |
|
527 | 527 | |
528 | - if ( ! $post ) { |
|
528 | + if ( ! $post) { |
|
529 | 529 | return false; |
530 | 530 | } |
531 | 531 | |
532 | - if ( 'publish' !== get_post_status( $post ) ) { |
|
532 | + if ('publish' !== get_post_status($post)) { |
|
533 | 533 | return false; |
534 | 534 | } |
535 | 535 | |
@@ -545,29 +545,29 @@ discard block |
||
545 | 545 | * @type int $max Maximum width. Default 600. |
546 | 546 | * } |
547 | 547 | */ |
548 | - $min_max_width = apply_filters( 'oembed_min_max_width', array( |
|
548 | + $min_max_width = apply_filters('oembed_min_max_width', array( |
|
549 | 549 | 'min' => 200, |
550 | 550 | 'max' => 600 |
551 | - ) ); |
|
551 | + )); |
|
552 | 552 | |
553 | - $width = min( max( $min_max_width['min'], $width ), $min_max_width['max'] ); |
|
554 | - $height = max( ceil( $width / 16 * 9 ), 200 ); |
|
553 | + $width = min(max($min_max_width['min'], $width), $min_max_width['max']); |
|
554 | + $height = max(ceil($width / 16 * 9), 200); |
|
555 | 555 | |
556 | 556 | $data = array( |
557 | 557 | 'version' => '1.0', |
558 | - 'provider_name' => get_bloginfo( 'name' ), |
|
558 | + 'provider_name' => get_bloginfo('name'), |
|
559 | 559 | 'provider_url' => get_home_url(), |
560 | - 'author_name' => get_bloginfo( 'name' ), |
|
560 | + 'author_name' => get_bloginfo('name'), |
|
561 | 561 | 'author_url' => get_home_url(), |
562 | 562 | 'title' => $post->post_title, |
563 | 563 | 'type' => 'link', |
564 | 564 | ); |
565 | 565 | |
566 | - $author = get_userdata( $post->post_author ); |
|
566 | + $author = get_userdata($post->post_author); |
|
567 | 567 | |
568 | - if ( $author ) { |
|
568 | + if ($author) { |
|
569 | 569 | $data['author_name'] = $author->display_name; |
570 | - $data['author_url'] = get_author_posts_url( $author->ID ); |
|
570 | + $data['author_url'] = get_author_posts_url($author->ID); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | /** |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @param int $width The requested width. |
581 | 581 | * @param int $height The calculated height. |
582 | 582 | */ |
583 | - return apply_filters( 'oembed_response_data', $data, $post, $width, $height ); |
|
583 | + return apply_filters('oembed_response_data', $data, $post, $width, $height); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -594,30 +594,30 @@ discard block |
||
594 | 594 | * @param int $height The calculated height. |
595 | 595 | * @return array The modified response data. |
596 | 596 | */ |
597 | -function get_oembed_response_data_rich( $data, $post, $width, $height ) { |
|
598 | - $data['width'] = absint( $width ); |
|
599 | - $data['height'] = absint( $height ); |
|
597 | +function get_oembed_response_data_rich($data, $post, $width, $height) { |
|
598 | + $data['width'] = absint($width); |
|
599 | + $data['height'] = absint($height); |
|
600 | 600 | $data['type'] = 'rich'; |
601 | - $data['html'] = get_post_embed_html( $width, $height, $post ); |
|
601 | + $data['html'] = get_post_embed_html($width, $height, $post); |
|
602 | 602 | |
603 | 603 | // Add post thumbnail to response if available. |
604 | 604 | $thumbnail_id = false; |
605 | 605 | |
606 | - if ( has_post_thumbnail( $post->ID ) ) { |
|
607 | - $thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
606 | + if (has_post_thumbnail($post->ID)) { |
|
607 | + $thumbnail_id = get_post_thumbnail_id($post->ID); |
|
608 | 608 | } |
609 | 609 | |
610 | - if ( 'attachment' === get_post_type( $post ) ) { |
|
611 | - if ( wp_attachment_is_image( $post ) ) { |
|
610 | + if ('attachment' === get_post_type($post)) { |
|
611 | + if (wp_attachment_is_image($post)) { |
|
612 | 612 | $thumbnail_id = $post->ID; |
613 | - } else if ( wp_attachment_is( 'video', $post ) ) { |
|
614 | - $thumbnail_id = get_post_thumbnail_id( $post ); |
|
613 | + } else if (wp_attachment_is('video', $post)) { |
|
614 | + $thumbnail_id = get_post_thumbnail_id($post); |
|
615 | 615 | $data['type'] = 'video'; |
616 | 616 | } |
617 | 617 | } |
618 | 618 | |
619 | - if ( $thumbnail_id ) { |
|
620 | - list( $thumbnail_url, $thumbnail_width, $thumbnail_height ) = wp_get_attachment_image_src( $thumbnail_id, array( $width, 99999 ) ); |
|
619 | + if ($thumbnail_id) { |
|
620 | + list($thumbnail_url, $thumbnail_width, $thumbnail_height) = wp_get_attachment_image_src($thumbnail_id, array($width, 99999)); |
|
621 | 621 | $data['thumbnail_url'] = $thumbnail_url; |
622 | 622 | $data['thumbnail_width'] = $thumbnail_width; |
623 | 623 | $data['thumbnail_height'] = $thumbnail_height; |
@@ -634,8 +634,8 @@ discard block |
||
634 | 634 | * @param string $format The oEmbed response format. Accepts 'json' or 'xml'. |
635 | 635 | * @return string The format, either 'xml' or 'json'. Default 'json'. |
636 | 636 | */ |
637 | -function wp_oembed_ensure_format( $format ) { |
|
638 | - if ( ! in_array( $format, array( 'json', 'xml' ), true ) ) { |
|
637 | +function wp_oembed_ensure_format($format) { |
|
638 | + if ( ! in_array($format, array('json', 'xml'), true)) { |
|
639 | 639 | return 'json'; |
640 | 640 | } |
641 | 641 | |
@@ -657,35 +657,35 @@ discard block |
||
657 | 657 | * @param WP_REST_Server $server Server instance. |
658 | 658 | * @return true |
659 | 659 | */ |
660 | -function _oembed_rest_pre_serve_request( $served, $result, $request, $server ) { |
|
660 | +function _oembed_rest_pre_serve_request($served, $result, $request, $server) { |
|
661 | 661 | $params = $request->get_params(); |
662 | 662 | |
663 | - if ( '/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method() ) { |
|
663 | + if ('/oembed/1.0/embed' !== $request->get_route() || 'GET' !== $request->get_method()) { |
|
664 | 664 | return $served; |
665 | 665 | } |
666 | 666 | |
667 | - if ( ! isset( $params['format'] ) || 'xml' !== $params['format'] ) { |
|
667 | + if ( ! isset($params['format']) || 'xml' !== $params['format']) { |
|
668 | 668 | return $served; |
669 | 669 | } |
670 | 670 | |
671 | 671 | // Embed links inside the request. |
672 | - $data = $server->response_to_data( $result, false ); |
|
672 | + $data = $server->response_to_data($result, false); |
|
673 | 673 | |
674 | - if ( ! class_exists( 'SimpleXMLElement' ) ) { |
|
675 | - status_header( 501 ); |
|
676 | - die( get_status_header_desc( 501 ) ); |
|
674 | + if ( ! class_exists('SimpleXMLElement')) { |
|
675 | + status_header(501); |
|
676 | + die(get_status_header_desc(501)); |
|
677 | 677 | } |
678 | 678 | |
679 | - $result = _oembed_create_xml( $data ); |
|
679 | + $result = _oembed_create_xml($data); |
|
680 | 680 | |
681 | 681 | // Bail if there's no XML. |
682 | - if ( ! $result ) { |
|
683 | - status_header( 501 ); |
|
684 | - return get_status_header_desc( 501 ); |
|
682 | + if ( ! $result) { |
|
683 | + status_header(501); |
|
684 | + return get_status_header_desc(501); |
|
685 | 685 | } |
686 | 686 | |
687 | - if ( ! headers_sent() ) { |
|
688 | - $server->send_header( 'Content-Type', 'text/xml; charset=' . get_option( 'blog_charset' ) ); |
|
687 | + if ( ! headers_sent()) { |
|
688 | + $server->send_header('Content-Type', 'text/xml; charset='.get_option('blog_charset')); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | echo $result; |
@@ -703,25 +703,25 @@ discard block |
||
703 | 703 | * @param SimpleXMLElement $node Optional. XML node to append the result to recursively. |
704 | 704 | * @return string|false XML string on success, false on error. |
705 | 705 | */ |
706 | -function _oembed_create_xml( $data, $node = null ) { |
|
707 | - if ( ! is_array( $data ) || empty( $data ) ) { |
|
706 | +function _oembed_create_xml($data, $node = null) { |
|
707 | + if ( ! is_array($data) || empty($data)) { |
|
708 | 708 | return false; |
709 | 709 | } |
710 | 710 | |
711 | - if ( null === $node ) { |
|
712 | - $node = new SimpleXMLElement( '<oembed></oembed>' ); |
|
711 | + if (null === $node) { |
|
712 | + $node = new SimpleXMLElement('<oembed></oembed>'); |
|
713 | 713 | } |
714 | 714 | |
715 | - foreach ( $data as $key => $value ) { |
|
716 | - if ( is_numeric( $key ) ) { |
|
715 | + foreach ($data as $key => $value) { |
|
716 | + if (is_numeric($key)) { |
|
717 | 717 | $key = 'oembed'; |
718 | 718 | } |
719 | 719 | |
720 | - if ( is_array( $value ) ) { |
|
721 | - $item = $node->addChild( $key ); |
|
722 | - _oembed_create_xml( $value, $item ); |
|
720 | + if (is_array($value)) { |
|
721 | + $item = $node->addChild($key); |
|
722 | + _oembed_create_xml($value, $item); |
|
723 | 723 | } else { |
724 | - $node->addChild( $key, esc_html( $value ) ); |
|
724 | + $node->addChild($key, esc_html($value)); |
|
725 | 725 | } |
726 | 726 | } |
727 | 727 | |
@@ -743,16 +743,16 @@ discard block |
||
743 | 743 | * @param string $url The URL of the content to be embedded. |
744 | 744 | * @return string The filtered and sanitized oEmbed result. |
745 | 745 | */ |
746 | -function wp_filter_oembed_result( $result, $data, $url ) { |
|
747 | - if ( false === $result || ! in_array( $data->type, array( 'rich', 'video' ) ) ) { |
|
746 | +function wp_filter_oembed_result($result, $data, $url) { |
|
747 | + if (false === $result || ! in_array($data->type, array('rich', 'video'))) { |
|
748 | 748 | return $result; |
749 | 749 | } |
750 | 750 | |
751 | - require_once( ABSPATH . WPINC . '/class-oembed.php' ); |
|
751 | + require_once(ABSPATH.WPINC.'/class-oembed.php'); |
|
752 | 752 | $wp_oembed = _wp_oembed_get_object(); |
753 | 753 | |
754 | 754 | // Don't modify the HTML for trusted providers. |
755 | - if ( false !== $wp_oembed->get_provider( $url, array( 'discover' => false ) ) ) { |
|
755 | + if (false !== $wp_oembed->get_provider($url, array('discover' => false))) { |
|
756 | 756 | return $result; |
757 | 757 | } |
758 | 758 | |
@@ -773,32 +773,32 @@ discard block |
||
773 | 773 | ), |
774 | 774 | ); |
775 | 775 | |
776 | - $html = wp_kses( $result, $allowed_html ); |
|
776 | + $html = wp_kses($result, $allowed_html); |
|
777 | 777 | |
778 | - preg_match( '|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content ); |
|
778 | + preg_match('|(<blockquote>.*?</blockquote>)?.*(<iframe.*?></iframe>)|ms', $html, $content); |
|
779 | 779 | // We require at least the iframe to exist. |
780 | - if ( empty( $content[2] ) ) { |
|
780 | + if (empty($content[2])) { |
|
781 | 781 | return false; |
782 | 782 | } |
783 | - $html = $content[1] . $content[2]; |
|
783 | + $html = $content[1].$content[2]; |
|
784 | 784 | |
785 | - if ( ! empty( $content[1] ) ) { |
|
785 | + if ( ! empty($content[1])) { |
|
786 | 786 | // We have a blockquote to fall back on. Hide the iframe by default. |
787 | - $html = str_replace( '<iframe', '<iframe style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', $html ); |
|
788 | - $html = str_replace( '<blockquote', '<blockquote class="wp-embedded-content"', $html ); |
|
787 | + $html = str_replace('<iframe', '<iframe style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', $html); |
|
788 | + $html = str_replace('<blockquote', '<blockquote class="wp-embedded-content"', $html); |
|
789 | 789 | } |
790 | 790 | |
791 | - $html = str_replace( '<iframe', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $html ); |
|
791 | + $html = str_replace('<iframe', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $html); |
|
792 | 792 | |
793 | - preg_match( '/ src=[\'"]([^\'"]*)[\'"]/', $html, $results ); |
|
793 | + preg_match('/ src=[\'"]([^\'"]*)[\'"]/', $html, $results); |
|
794 | 794 | |
795 | - if ( ! empty( $results ) ) { |
|
796 | - $secret = wp_generate_password( 10, false ); |
|
795 | + if ( ! empty($results)) { |
|
796 | + $secret = wp_generate_password(10, false); |
|
797 | 797 | |
798 | - $url = esc_url( "{$results[1]}#?secret=$secret" ); |
|
798 | + $url = esc_url("{$results[1]}#?secret=$secret"); |
|
799 | 799 | |
800 | - $html = str_replace( $results[0], " src=\"$url\" data-secret=\"$secret\"", $html ); |
|
801 | - $html = str_replace( '<blockquote', "<blockquote data-secret=\"$secret\"", $html ); |
|
800 | + $html = str_replace($results[0], " src=\"$url\" data-secret=\"$secret\"", $html); |
|
801 | + $html = str_replace('<blockquote', "<blockquote data-secret=\"$secret\"", $html); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | return $html; |
@@ -815,17 +815,17 @@ discard block |
||
815 | 815 | * @param string $more_string Default 'more' string. |
816 | 816 | * @return string 'Continue reading' link prepended with an ellipsis. |
817 | 817 | */ |
818 | -function wp_embed_excerpt_more( $more_string ) { |
|
819 | - if ( ! is_embed() ) { |
|
818 | +function wp_embed_excerpt_more($more_string) { |
|
819 | + if ( ! is_embed()) { |
|
820 | 820 | return $more_string; |
821 | 821 | } |
822 | 822 | |
823 | - $link = sprintf( '<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>', |
|
824 | - esc_url( get_permalink() ), |
|
823 | + $link = sprintf('<a href="%1$s" class="wp-embed-more" target="_top">%2$s</a>', |
|
824 | + esc_url(get_permalink()), |
|
825 | 825 | /* translators: %s: Name of current post */ |
826 | - sprintf( __( 'Continue reading %s' ), '<span class="screen-reader-text">' . get_the_title() . '</span>' ) |
|
826 | + sprintf(__('Continue reading %s'), '<span class="screen-reader-text">'.get_the_title().'</span>') |
|
827 | 827 | ); |
828 | - return ' … ' . $link; |
|
828 | + return ' … '.$link; |
|
829 | 829 | } |
830 | 830 | |
831 | 831 | /** |
@@ -845,7 +845,7 @@ discard block |
||
845 | 845 | * |
846 | 846 | * @param string $output The current post excerpt. |
847 | 847 | */ |
848 | - echo apply_filters( 'the_excerpt_embed', $output ); |
|
848 | + echo apply_filters('the_excerpt_embed', $output); |
|
849 | 849 | } |
850 | 850 | |
851 | 851 | /** |
@@ -858,9 +858,9 @@ discard block |
||
858 | 858 | * @param string $content The current post excerpt. |
859 | 859 | * @return string The modified post excerpt. |
860 | 860 | */ |
861 | -function wp_embed_excerpt_attachment( $content ) { |
|
862 | - if ( is_attachment() ) { |
|
863 | - return prepend_attachment( '' ); |
|
861 | +function wp_embed_excerpt_attachment($content) { |
|
862 | + if (is_attachment()) { |
|
863 | + return prepend_attachment(''); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | return $content; |
@@ -877,15 +877,15 @@ discard block |
||
877 | 877 | * @since 4.4.0 |
878 | 878 | */ |
879 | 879 | function enqueue_embed_scripts() { |
880 | - wp_enqueue_style( 'open-sans' ); |
|
881 | - wp_enqueue_style( 'wp-embed-template-ie' ); |
|
880 | + wp_enqueue_style('open-sans'); |
|
881 | + wp_enqueue_style('wp-embed-template-ie'); |
|
882 | 882 | |
883 | 883 | /** |
884 | 884 | * Fires when scripts and styles are enqueued for the embed iframe. |
885 | 885 | * |
886 | 886 | * @since 4.4.0 |
887 | 887 | */ |
888 | - do_action( 'enqueue_embed_scripts' ); |
|
888 | + do_action('enqueue_embed_scripts'); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -897,8 +897,8 @@ discard block |
||
897 | 897 | ?> |
898 | 898 | <style type="text/css"> |
899 | 899 | <?php |
900 | - if ( SCRIPT_DEBUG ) { |
|
901 | - readfile( ABSPATH . WPINC . "/css/wp-embed-template.css" ); |
|
900 | + if (SCRIPT_DEBUG) { |
|
901 | + readfile(ABSPATH.WPINC."/css/wp-embed-template.css"); |
|
902 | 902 | } else { |
903 | 903 | /* |
904 | 904 | * If you're looking at a src version of this file, you'll see an "include" |
@@ -928,8 +928,8 @@ discard block |
||
928 | 928 | ?> |
929 | 929 | <script type="text/javascript"> |
930 | 930 | <?php |
931 | - if ( SCRIPT_DEBUG ) { |
|
932 | - readfile( ABSPATH . WPINC . "/js/wp-embed-template.js" ); |
|
931 | + if (SCRIPT_DEBUG) { |
|
932 | + readfile(ABSPATH.WPINC."/js/wp-embed-template.js"); |
|
933 | 933 | } else { |
934 | 934 | /* |
935 | 935 | * If you're looking at a src version of this file, you'll see an "include" |
@@ -959,8 +959,8 @@ discard block |
||
959 | 959 | * @param string $content The content to filter. |
960 | 960 | * @return string The filtered content. |
961 | 961 | */ |
962 | -function _oembed_filter_feed_content( $content ) { |
|
963 | - return str_replace( '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content ); |
|
962 | +function _oembed_filter_feed_content($content) { |
|
963 | + return str_replace('<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);"', '<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"', $content); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | /** |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | * @since 4.4.0 |
970 | 970 | */ |
971 | 971 | function print_embed_comments_button() { |
972 | - if ( is_404() || ! ( get_comments_number() || comments_open() ) ) { |
|
972 | + if (is_404() || ! (get_comments_number() || comments_open())) { |
|
973 | 973 | return; |
974 | 974 | } |
975 | 975 | ?> |
@@ -983,7 +983,7 @@ discard block |
||
983 | 983 | '%s <span class="screen-reader-text">Comments</span>', |
984 | 984 | get_comments_number() |
985 | 985 | ), |
986 | - number_format_i18n( get_comments_number() ) |
|
986 | + number_format_i18n(get_comments_number()) |
|
987 | 987 | ); |
988 | 988 | ?> |
989 | 989 | </a> |
@@ -997,12 +997,12 @@ discard block |
||
997 | 997 | * @since 4.4.0 |
998 | 998 | */ |
999 | 999 | function print_embed_sharing_button() { |
1000 | - if ( is_404() ) { |
|
1000 | + if (is_404()) { |
|
1001 | 1001 | return; |
1002 | 1002 | } |
1003 | 1003 | ?> |
1004 | 1004 | <div class="wp-embed-share"> |
1005 | - <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e( 'Open sharing dialog' ); ?>"> |
|
1005 | + <button type="button" class="wp-embed-share-dialog-open" aria-label="<?php esc_attr_e('Open sharing dialog'); ?>"> |
|
1006 | 1006 | <span class="dashicons dashicons-share"></span> |
1007 | 1007 | </button> |
1008 | 1008 | </div> |
@@ -1015,38 +1015,38 @@ discard block |
||
1015 | 1015 | * @since 4.4.0 |
1016 | 1016 | */ |
1017 | 1017 | function print_embed_sharing_dialog() { |
1018 | - if ( is_404() ) { |
|
1018 | + if (is_404()) { |
|
1019 | 1019 | return; |
1020 | 1020 | } |
1021 | 1021 | ?> |
1022 | - <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e( 'Sharing options' ); ?>"> |
|
1022 | + <div class="wp-embed-share-dialog hidden" role="dialog" aria-label="<?php esc_attr_e('Sharing options'); ?>"> |
|
1023 | 1023 | <div class="wp-embed-share-dialog-content"> |
1024 | 1024 | <div class="wp-embed-share-dialog-text"> |
1025 | 1025 | <ul class="wp-embed-share-tabs" role="tablist"> |
1026 | 1026 | <li class="wp-embed-share-tab-button wp-embed-share-tab-button-wordpress" role="presentation"> |
1027 | - <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e( 'WordPress Embed' ); ?></button> |
|
1027 | + <button type="button" role="tab" aria-controls="wp-embed-share-tab-wordpress" aria-selected="true" tabindex="0"><?php esc_html_e('WordPress Embed'); ?></button> |
|
1028 | 1028 | </li> |
1029 | 1029 | <li class="wp-embed-share-tab-button wp-embed-share-tab-button-html" role="presentation"> |
1030 | - <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e( 'HTML Embed' ); ?></button> |
|
1030 | + <button type="button" role="tab" aria-controls="wp-embed-share-tab-html" aria-selected="false" tabindex="-1"><?php esc_html_e('HTML Embed'); ?></button> |
|
1031 | 1031 | </li> |
1032 | 1032 | </ul> |
1033 | 1033 | <div id="wp-embed-share-tab-wordpress" class="wp-embed-share-tab" role="tabpanel" aria-hidden="false"> |
1034 | 1034 | <input type="text" value="<?php the_permalink(); ?>" class="wp-embed-share-input" aria-describedby="wp-embed-share-description-wordpress" tabindex="0" readonly/> |
1035 | 1035 | |
1036 | 1036 | <p class="wp-embed-share-description" id="wp-embed-share-description-wordpress"> |
1037 | - <?php _e( 'Copy and paste this URL into your WordPress site to embed' ); ?> |
|
1037 | + <?php _e('Copy and paste this URL into your WordPress site to embed'); ?> |
|
1038 | 1038 | </p> |
1039 | 1039 | </div> |
1040 | 1040 | <div id="wp-embed-share-tab-html" class="wp-embed-share-tab" role="tabpanel" aria-hidden="true"> |
1041 | - <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea( get_post_embed_html( 600, 400 ) ); ?></textarea> |
|
1041 | + <textarea class="wp-embed-share-input" aria-describedby="wp-embed-share-description-html" tabindex="0" readonly><?php echo esc_textarea(get_post_embed_html(600, 400)); ?></textarea> |
|
1042 | 1042 | |
1043 | 1043 | <p class="wp-embed-share-description" id="wp-embed-share-description-html"> |
1044 | - <?php _e( 'Copy and paste this code into your site to embed' ); ?> |
|
1044 | + <?php _e('Copy and paste this code into your site to embed'); ?> |
|
1045 | 1045 | </p> |
1046 | 1046 | </div> |
1047 | 1047 | </div> |
1048 | 1048 | |
1049 | - <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e( 'Close sharing dialog' ); ?>"> |
|
1049 | + <button type="button" class="wp-embed-share-dialog-close" aria-label="<?php esc_attr_e('Close sharing dialog'); ?>"> |
|
1050 | 1050 | <span class="dashicons dashicons-no"></span> |
1051 | 1051 | </button> |
1052 | 1052 | </div> |
@@ -1062,13 +1062,13 @@ discard block |
||
1062 | 1062 | function the_embed_site_title() { |
1063 | 1063 | $site_title = sprintf( |
1064 | 1064 | '<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon"/><span>%s</span></a>', |
1065 | - esc_url( home_url() ), |
|
1066 | - esc_url( get_site_icon_url( 32, admin_url( 'images/w-logo-blue.png' ) ) ), |
|
1067 | - esc_url( get_site_icon_url( 64, admin_url( 'images/w-logo-blue.png' ) ) ), |
|
1068 | - esc_html( get_bloginfo( 'name' ) ) |
|
1065 | + esc_url(home_url()), |
|
1066 | + esc_url(get_site_icon_url(32, admin_url('images/w-logo-blue.png'))), |
|
1067 | + esc_url(get_site_icon_url(64, admin_url('images/w-logo-blue.png'))), |
|
1068 | + esc_html(get_bloginfo('name')) |
|
1069 | 1069 | ); |
1070 | 1070 | |
1071 | - $site_title = '<div class="wp-embed-site-title">' . $site_title . '</div>'; |
|
1071 | + $site_title = '<div class="wp-embed-site-title">'.$site_title.'</div>'; |
|
1072 | 1072 | |
1073 | 1073 | /** |
1074 | 1074 | * Filter the site title HTML in the embed footer. |
@@ -1077,5 +1077,5 @@ discard block |
||
1077 | 1077 | * |
1078 | 1078 | * @param string $site_title The site title HTML. |
1079 | 1079 | */ |
1080 | - echo apply_filters( 'embed_site_title_html', $site_title ); |
|
1080 | + echo apply_filters('embed_site_title_html', $site_title); |
|
1081 | 1081 | } |
@@ -61,11 +61,13 @@ |
||
61 | 61 | * @return array Default embed parameters. |
62 | 62 | */ |
63 | 63 | function wp_embed_defaults( $url = '' ) { |
64 | - if ( ! empty( $GLOBALS['content_width'] ) ) |
|
65 | - $width = (int) $GLOBALS['content_width']; |
|
64 | + if ( ! empty( $GLOBALS['content_width'] ) ) { |
|
65 | + $width = (int) $GLOBALS['content_width']; |
|
66 | + } |
|
66 | 67 | |
67 | - if ( empty( $width ) ) |
|
68 | - $width = 500; |
|
68 | + if ( empty( $width ) ) { |
|
69 | + $width = 500; |
|
70 | + } |
|
69 | 71 | |
70 | 72 | $height = min( ceil( $width * 1.5 ), 1000 ); |
71 | 73 |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @since 3.7.0 |
111 | 111 | */ |
112 | -define( 'EP_ALL_ARCHIVES', EP_DATE | EP_YEAR | EP_MONTH | EP_DAY | EP_CATEGORIES | EP_TAGS | EP_AUTHORS ); |
|
112 | +define('EP_ALL_ARCHIVES', EP_DATE | EP_YEAR | EP_MONTH | EP_DAY | EP_CATEGORIES | EP_TAGS | EP_AUTHORS); |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Endpoint Mask for everything. |
116 | 116 | * |
117 | 117 | * @since 2.1.0 |
118 | 118 | */ |
119 | -define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_PAGES | EP_ALL_ARCHIVES ); |
|
119 | +define('EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_PAGES | EP_ALL_ARCHIVES); |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Adds a rewrite rule that transforms a URL structure to a set of query vars. |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | * @param string $after Optional. Priority of the new rule. Accepts 'top' |
135 | 135 | * or 'bottom'. Default 'bottom'. |
136 | 136 | */ |
137 | -function add_rewrite_rule( $regex, $query, $after = 'bottom' ) { |
|
137 | +function add_rewrite_rule($regex, $query, $after = 'bottom') { |
|
138 | 138 | global $wp_rewrite; |
139 | 139 | |
140 | - $wp_rewrite->add_rule( $regex, $query, $after ); |
|
140 | + $wp_rewrite->add_rule($regex, $query, $after); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -156,20 +156,20 @@ discard block |
||
156 | 156 | * @param string $regex Regular expression to substitute the tag for in rewrite rules. |
157 | 157 | * @param string $query Optional. String to append to the rewritten query. Must end in '='. Default empty. |
158 | 158 | */ |
159 | -function add_rewrite_tag( $tag, $regex, $query = '' ) { |
|
159 | +function add_rewrite_tag($tag, $regex, $query = '') { |
|
160 | 160 | // validate the tag's name |
161 | - if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' ) |
|
161 | + if (strlen($tag) < 3 || $tag[0] != '%' || $tag[strlen($tag) - 1] != '%') |
|
162 | 162 | return; |
163 | 163 | |
164 | 164 | global $wp_rewrite, $wp; |
165 | 165 | |
166 | - if ( empty( $query ) ) { |
|
167 | - $qv = trim( $tag, '%' ); |
|
168 | - $wp->add_query_var( $qv ); |
|
169 | - $query = $qv . '='; |
|
166 | + if (empty($query)) { |
|
167 | + $qv = trim($tag, '%'); |
|
168 | + $wp->add_query_var($qv); |
|
169 | + $query = $qv.'='; |
|
170 | 170 | } |
171 | 171 | |
172 | - $wp_rewrite->add_rewrite_tag( $tag, $regex, $query ); |
|
172 | + $wp_rewrite->add_rewrite_tag($tag, $regex, $query); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @param string $tag Name of the rewrite tag. |
183 | 183 | */ |
184 | -function remove_rewrite_tag( $tag ) { |
|
184 | +function remove_rewrite_tag($tag) { |
|
185 | 185 | global $wp_rewrite; |
186 | - $wp_rewrite->remove_rewrite_tag( $tag ); |
|
186 | + $wp_rewrite->remove_rewrite_tag($tag); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -199,16 +199,16 @@ discard block |
||
199 | 199 | * @param array $args Optional. Arguments for building the rules from the permalink structure, |
200 | 200 | * see WP_Rewrite::add_permastruct() for full details. Default empty array. |
201 | 201 | */ |
202 | -function add_permastruct( $name, $struct, $args = array() ) { |
|
202 | +function add_permastruct($name, $struct, $args = array()) { |
|
203 | 203 | global $wp_rewrite; |
204 | 204 | |
205 | 205 | // backwards compatibility for the old parameters: $with_front and $ep_mask |
206 | - if ( ! is_array( $args ) ) |
|
207 | - $args = array( 'with_front' => $args ); |
|
208 | - if ( func_num_args() == 4 ) |
|
209 | - $args['ep_mask'] = func_get_arg( 3 ); |
|
206 | + if ( ! is_array($args)) |
|
207 | + $args = array('with_front' => $args); |
|
208 | + if (func_num_args() == 4) |
|
209 | + $args['ep_mask'] = func_get_arg(3); |
|
210 | 210 | |
211 | - $wp_rewrite->add_permastruct( $name, $struct, $args ); |
|
211 | + $wp_rewrite->add_permastruct($name, $struct, $args); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
@@ -224,10 +224,10 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @param string $name Name for permalink structure. |
226 | 226 | */ |
227 | -function remove_permastruct( $name ) { |
|
227 | +function remove_permastruct($name) { |
|
228 | 228 | global $wp_rewrite; |
229 | 229 | |
230 | - $wp_rewrite->remove_permastruct( $name ); |
|
230 | + $wp_rewrite->remove_permastruct($name); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -241,19 +241,19 @@ discard block |
||
241 | 241 | * @param callable $function Callback to run on feed display. |
242 | 242 | * @return string Feed action name. |
243 | 243 | */ |
244 | -function add_feed( $feedname, $function ) { |
|
244 | +function add_feed($feedname, $function) { |
|
245 | 245 | global $wp_rewrite; |
246 | 246 | |
247 | - if ( ! in_array( $feedname, $wp_rewrite->feeds ) ) { |
|
247 | + if ( ! in_array($feedname, $wp_rewrite->feeds)) { |
|
248 | 248 | $wp_rewrite->feeds[] = $feedname; |
249 | 249 | } |
250 | 250 | |
251 | - $hook = 'do_feed_' . $feedname; |
|
251 | + $hook = 'do_feed_'.$feedname; |
|
252 | 252 | |
253 | 253 | // Remove default function hook |
254 | - remove_action( $hook, $hook ); |
|
254 | + remove_action($hook, $hook); |
|
255 | 255 | |
256 | - add_action( $hook, $function, 10, 2 ); |
|
256 | + add_action($hook, $function, 10, 2); |
|
257 | 257 | |
258 | 258 | return $hook; |
259 | 259 | } |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * @param bool $hard Whether to update .htaccess (hard flush) or just update |
269 | 269 | * rewrite_rules transient (soft flush). Default is true (hard). |
270 | 270 | */ |
271 | -function flush_rewrite_rules( $hard = true ) { |
|
271 | +function flush_rewrite_rules($hard = true) { |
|
272 | 272 | global $wp_rewrite; |
273 | - $wp_rewrite->flush_rules( $hard ); |
|
273 | + $wp_rewrite->flush_rules($hard); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | * @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering a query_var |
306 | 306 | * for this endpoint. Defaults to the value of `$name`. |
307 | 307 | */ |
308 | -function add_rewrite_endpoint( $name, $places, $query_var = true ) { |
|
308 | +function add_rewrite_endpoint($name, $places, $query_var = true) { |
|
309 | 309 | global $wp_rewrite; |
310 | - $wp_rewrite->add_endpoint( $name, $places, $query_var ); |
|
310 | + $wp_rewrite->add_endpoint($name, $places, $query_var); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | * @param string $base The taxonomy base that we're going to filter |
322 | 322 | * @return string |
323 | 323 | */ |
324 | -function _wp_filter_taxonomy_base( $base ) { |
|
325 | - if ( !empty( $base ) ) { |
|
326 | - $base = preg_replace( '|^/index\.php/|', '', $base ); |
|
327 | - $base = trim( $base, '/' ); |
|
324 | +function _wp_filter_taxonomy_base($base) { |
|
325 | + if ( ! empty($base)) { |
|
326 | + $base = preg_replace('|^/index\.php/|', '', $base); |
|
327 | + $base = trim($base, '/'); |
|
328 | 328 | } |
329 | 329 | return $base; |
330 | 330 | } |
@@ -351,16 +351,16 @@ discard block |
||
351 | 351 | * WP::parse_request(). Default empty array. |
352 | 352 | * @return array Returns the original array of query vars, with date/post conflicts resolved. |
353 | 353 | */ |
354 | -function wp_resolve_numeric_slug_conflicts( $query_vars = array() ) { |
|
355 | - if ( ! isset( $query_vars['year'] ) && ! isset( $query_vars['monthnum'] ) && ! isset( $query_vars['day'] ) ) { |
|
354 | +function wp_resolve_numeric_slug_conflicts($query_vars = array()) { |
|
355 | + if ( ! isset($query_vars['year']) && ! isset($query_vars['monthnum']) && ! isset($query_vars['day'])) { |
|
356 | 356 | return $query_vars; |
357 | 357 | } |
358 | 358 | |
359 | 359 | // Identify the 'postname' position in the permastruct array. |
360 | - $permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) ); |
|
361 | - $postname_index = array_search( '%postname%', $permastructs ); |
|
360 | + $permastructs = array_values(array_filter(explode('/', get_option('permalink_structure')))); |
|
361 | + $postname_index = array_search('%postname%', $permastructs); |
|
362 | 362 | |
363 | - if ( false === $postname_index ) { |
|
363 | + if (false === $postname_index) { |
|
364 | 364 | return $query_vars; |
365 | 365 | } |
366 | 366 | |
@@ -371,35 +371,35 @@ discard block |
||
371 | 371 | * for month-slug clashes when `is_month` *or* `is_day`. |
372 | 372 | */ |
373 | 373 | $compare = ''; |
374 | - if ( 0 === $postname_index && ( isset( $query_vars['year'] ) || isset( $query_vars['monthnum'] ) ) ) { |
|
374 | + if (0 === $postname_index && (isset($query_vars['year']) || isset($query_vars['monthnum']))) { |
|
375 | 375 | $compare = 'year'; |
376 | - } elseif ( '%year%' === $permastructs[ $postname_index - 1 ] && ( isset( $query_vars['monthnum'] ) || isset( $query_vars['day'] ) ) ) { |
|
376 | + } elseif ('%year%' === $permastructs[$postname_index - 1] && (isset($query_vars['monthnum']) || isset($query_vars['day']))) { |
|
377 | 377 | $compare = 'monthnum'; |
378 | - } elseif ( '%monthnum%' === $permastructs[ $postname_index - 1 ] && isset( $query_vars['day'] ) ) { |
|
378 | + } elseif ('%monthnum%' === $permastructs[$postname_index - 1] && isset($query_vars['day'])) { |
|
379 | 379 | $compare = 'day'; |
380 | 380 | } |
381 | 381 | |
382 | - if ( ! $compare ) { |
|
382 | + if ( ! $compare) { |
|
383 | 383 | return $query_vars; |
384 | 384 | } |
385 | 385 | |
386 | 386 | // This is the potentially clashing slug. |
387 | - $value = $query_vars[ $compare ]; |
|
387 | + $value = $query_vars[$compare]; |
|
388 | 388 | |
389 | - $post = get_page_by_path( $value, OBJECT, 'post' ); |
|
390 | - if ( ! ( $post instanceof WP_Post ) ) { |
|
389 | + $post = get_page_by_path($value, OBJECT, 'post'); |
|
390 | + if ( ! ($post instanceof WP_Post)) { |
|
391 | 391 | return $query_vars; |
392 | 392 | } |
393 | 393 | |
394 | 394 | // If the date of the post doesn't match the date specified in the URL, resolve to the date archive. |
395 | - if ( preg_match( '/^([0-9]{4})\-([0-9]{2})/', $post->post_date, $matches ) && isset( $query_vars['year'] ) && ( 'monthnum' === $compare || 'day' === $compare ) ) { |
|
395 | + if (preg_match('/^([0-9]{4})\-([0-9]{2})/', $post->post_date, $matches) && isset($query_vars['year']) && ('monthnum' === $compare || 'day' === $compare)) { |
|
396 | 396 | // $matches[1] is the year the post was published. |
397 | - if ( intval( $query_vars['year'] ) !== intval( $matches[1] ) ) { |
|
397 | + if (intval($query_vars['year']) !== intval($matches[1])) { |
|
398 | 398 | return $query_vars; |
399 | 399 | } |
400 | 400 | |
401 | 401 | // $matches[2] is the month the post was published. |
402 | - if ( 'day' === $compare && isset( $query_vars['monthnum'] ) && intval( $query_vars['monthnum'] ) !== intval( $matches[2] ) ) { |
|
402 | + if ('day' === $compare && isset($query_vars['monthnum']) && intval($query_vars['monthnum']) !== intval($matches[2])) { |
|
403 | 403 | return $query_vars; |
404 | 404 | } |
405 | 405 | } |
@@ -409,35 +409,35 @@ discard block |
||
409 | 409 | * intended as the page number. Verify that it's a valid page before resolving to it. |
410 | 410 | */ |
411 | 411 | $maybe_page = ''; |
412 | - if ( 'year' === $compare && isset( $query_vars['monthnum'] ) ) { |
|
412 | + if ('year' === $compare && isset($query_vars['monthnum'])) { |
|
413 | 413 | $maybe_page = $query_vars['monthnum']; |
414 | - } elseif ( 'monthnum' === $compare && isset( $query_vars['day'] ) ) { |
|
414 | + } elseif ('monthnum' === $compare && isset($query_vars['day'])) { |
|
415 | 415 | $maybe_page = $query_vars['day']; |
416 | 416 | } |
417 | 417 | // Bug found in #11694 - 'page' was returning '/4' |
418 | - $maybe_page = (int) trim( $maybe_page, '/' ); |
|
418 | + $maybe_page = (int) trim($maybe_page, '/'); |
|
419 | 419 | |
420 | - $post_page_count = substr_count( $post->post_content, '<!--nextpage-->' ) + 1; |
|
420 | + $post_page_count = substr_count($post->post_content, '<!--nextpage-->') + 1; |
|
421 | 421 | |
422 | 422 | // If the post doesn't have multiple pages, but a 'page' candidate is found, resolve to the date archive. |
423 | - if ( 1 === $post_page_count && $maybe_page ) { |
|
423 | + if (1 === $post_page_count && $maybe_page) { |
|
424 | 424 | return $query_vars; |
425 | 425 | } |
426 | 426 | |
427 | 427 | // If the post has multiple pages and the 'page' number isn't valid, resolve to the date archive. |
428 | - if ( $post_page_count > 1 && $maybe_page > $post_page_count ) { |
|
428 | + if ($post_page_count > 1 && $maybe_page > $post_page_count) { |
|
429 | 429 | return $query_vars; |
430 | 430 | } |
431 | 431 | |
432 | 432 | // If we've gotten to this point, we have a slug/date clash. First, adjust for nextpage. |
433 | - if ( '' !== $maybe_page ) { |
|
434 | - $query_vars['page'] = intval( $maybe_page ); |
|
433 | + if ('' !== $maybe_page) { |
|
434 | + $query_vars['page'] = intval($maybe_page); |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | // Next, unset autodetected date-related query vars. |
438 | - unset( $query_vars['year'] ); |
|
439 | - unset( $query_vars['monthnum'] ); |
|
440 | - unset( $query_vars['day'] ); |
|
438 | + unset($query_vars['year']); |
|
439 | + unset($query_vars['monthnum']); |
|
440 | + unset($query_vars['day']); |
|
441 | 441 | |
442 | 442 | // Then, set the identified post. |
443 | 443 | $query_vars['name'] = $post->post_name; |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * @param string $url Permalink to check. |
460 | 460 | * @return int Post ID, or 0 on failure. |
461 | 461 | */ |
462 | -function url_to_postid( $url ) { |
|
462 | +function url_to_postid($url) { |
|
463 | 463 | global $wp_rewrite; |
464 | 464 | |
465 | 465 | /** |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | * |
470 | 470 | * @param string $url The URL to derive the post ID from. |
471 | 471 | */ |
472 | - $url = apply_filters( 'url_to_postid', $url ); |
|
472 | + $url = apply_filters('url_to_postid', $url); |
|
473 | 473 | |
474 | 474 | // First, check to see if there is a 'p=N' or 'page_id=N' to match against |
475 | - if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) { |
|
475 | + if (preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values)) { |
|
476 | 476 | $id = absint($values[2]); |
477 | - if ( $id ) |
|
477 | + if ($id) |
|
478 | 478 | return $id; |
479 | 479 | } |
480 | 480 | |
@@ -487,21 +487,21 @@ discard block |
||
487 | 487 | $url = $url_split[0]; |
488 | 488 | |
489 | 489 | // Set the correct URL scheme. |
490 | - $scheme = parse_url( home_url(), PHP_URL_SCHEME ); |
|
491 | - $url = set_url_scheme( $url, $scheme ); |
|
490 | + $scheme = parse_url(home_url(), PHP_URL_SCHEME); |
|
491 | + $url = set_url_scheme($url, $scheme); |
|
492 | 492 | |
493 | 493 | // Add 'www.' if it is absent and should be there |
494 | - if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) |
|
494 | + if (false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.')) |
|
495 | 495 | $url = str_replace('://', '://www.', $url); |
496 | 496 | |
497 | 497 | // Strip 'www.' if it is present and shouldn't be |
498 | - if ( false === strpos(home_url(), '://www.') ) |
|
498 | + if (false === strpos(home_url(), '://www.')) |
|
499 | 499 | $url = str_replace('://www.', '://', $url); |
500 | 500 | |
501 | - if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) { |
|
502 | - $page_on_front = get_option( 'page_on_front' ); |
|
501 | + if (trim($url, '/') === home_url() && 'page' == get_option('show_on_front')) { |
|
502 | + $page_on_front = get_option('page_on_front'); |
|
503 | 503 | |
504 | - if ( $page_on_front && get_post( $page_on_front ) instanceof WP_Post ) { |
|
504 | + if ($page_on_front && get_post($page_on_front) instanceof WP_Post) { |
|
505 | 505 | return (int) $page_on_front; |
506 | 506 | } |
507 | 507 | } |
@@ -510,21 +510,21 @@ discard block |
||
510 | 510 | $rewrite = $wp_rewrite->wp_rewrite_rules(); |
511 | 511 | |
512 | 512 | // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options |
513 | - if ( empty($rewrite) ) |
|
513 | + if (empty($rewrite)) |
|
514 | 514 | return 0; |
515 | 515 | |
516 | 516 | // Strip 'index.php/' if we're not using path info permalinks |
517 | - if ( !$wp_rewrite->using_index_permalinks() ) |
|
518 | - $url = str_replace( $wp_rewrite->index . '/', '', $url ); |
|
517 | + if ( ! $wp_rewrite->using_index_permalinks()) |
|
518 | + $url = str_replace($wp_rewrite->index.'/', '', $url); |
|
519 | 519 | |
520 | - if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) { |
|
520 | + if (false !== strpos(trailingslashit($url), home_url('/'))) { |
|
521 | 521 | // Chop off http://domain.com/[path] |
522 | 522 | $url = str_replace(home_url(), '', $url); |
523 | 523 | } else { |
524 | 524 | // Chop off /path/to/blog |
525 | - $home_path = parse_url( home_url( '/' ) ); |
|
526 | - $home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ; |
|
527 | - $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) ); |
|
525 | + $home_path = parse_url(home_url('/')); |
|
526 | + $home_path = isset($home_path['path']) ? $home_path['path'] : ''; |
|
527 | + $url = preg_replace(sprintf('#^%s#', preg_quote($home_path)), '', trailingslashit($url)); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | // Trim leading and lagging slashes |
@@ -533,32 +533,32 @@ discard block |
||
533 | 533 | $request = $url; |
534 | 534 | $post_type_query_vars = array(); |
535 | 535 | |
536 | - foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) { |
|
537 | - if ( ! empty( $t->query_var ) ) |
|
538 | - $post_type_query_vars[ $t->query_var ] = $post_type; |
|
536 | + foreach (get_post_types(array(), 'objects') as $post_type => $t) { |
|
537 | + if ( ! empty($t->query_var)) |
|
538 | + $post_type_query_vars[$t->query_var] = $post_type; |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | // Look for matches. |
542 | 542 | $request_match = $request; |
543 | - foreach ( (array)$rewrite as $match => $query) { |
|
543 | + foreach ((array) $rewrite as $match => $query) { |
|
544 | 544 | |
545 | 545 | // If the requesting file is the anchor of the match, prepend it |
546 | 546 | // to the path info. |
547 | - if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) ) |
|
548 | - $request_match = $url . '/' . $request; |
|
547 | + if ( ! empty($url) && ($url != $request) && (strpos($match, $url) === 0)) |
|
548 | + $request_match = $url.'/'.$request; |
|
549 | 549 | |
550 | - if ( preg_match("#^$match#", $request_match, $matches) ) { |
|
550 | + if (preg_match("#^$match#", $request_match, $matches)) { |
|
551 | 551 | |
552 | - if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { |
|
552 | + if ($wp_rewrite->use_verbose_page_rules && preg_match('/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch)) { |
|
553 | 553 | // This is a verbose page match, let's check to be sure about it. |
554 | - $page = get_page_by_path( $matches[ $varmatch[1] ] ); |
|
555 | - if ( ! $page ) { |
|
554 | + $page = get_page_by_path($matches[$varmatch[1]]); |
|
555 | + if ( ! $page) { |
|
556 | 556 | continue; |
557 | 557 | } |
558 | 558 | |
559 | - $post_status_obj = get_post_status_object( $page->post_status ); |
|
559 | + $post_status_obj = get_post_status_object($page->post_status); |
|
560 | 560 | if ( ! $post_status_obj->public && ! $post_status_obj->protected |
561 | - && ! $post_status_obj->private && $post_status_obj->exclude_from_search ) { |
|
561 | + && ! $post_status_obj->private && $post_status_obj->exclude_from_search) { |
|
562 | 562 | continue; |
563 | 563 | } |
564 | 564 | } |
@@ -572,12 +572,12 @@ discard block |
||
572 | 572 | |
573 | 573 | // Filter out non-public query vars |
574 | 574 | global $wp; |
575 | - parse_str( $query, $query_vars ); |
|
575 | + parse_str($query, $query_vars); |
|
576 | 576 | $query = array(); |
577 | - foreach ( (array) $query_vars as $key => $value ) { |
|
578 | - if ( in_array( $key, $wp->public_query_vars ) ){ |
|
577 | + foreach ((array) $query_vars as $key => $value) { |
|
578 | + if (in_array($key, $wp->public_query_vars)) { |
|
579 | 579 | $query[$key] = $value; |
580 | - if ( isset( $post_type_query_vars[$key] ) ) { |
|
580 | + if (isset($post_type_query_vars[$key])) { |
|
581 | 581 | $query['post_type'] = $post_type_query_vars[$key]; |
582 | 582 | $query['name'] = $value; |
583 | 583 | } |
@@ -585,11 +585,11 @@ discard block |
||
585 | 585 | } |
586 | 586 | |
587 | 587 | // Resolve conflicts between posts with numeric slugs and date archive queries. |
588 | - $query = wp_resolve_numeric_slug_conflicts( $query ); |
|
588 | + $query = wp_resolve_numeric_slug_conflicts($query); |
|
589 | 589 | |
590 | 590 | // Do the query |
591 | - $query = new WP_Query( $query ); |
|
592 | - if ( ! empty( $query->posts ) && $query->is_singular ) |
|
591 | + $query = new WP_Query($query); |
|
592 | + if ( ! empty($query->posts) && $query->is_singular) |
|
593 | 593 | return $query->post->ID; |
594 | 594 | else |
595 | 595 | return 0; |
@@ -158,8 +158,9 @@ discard block |
||
158 | 158 | */ |
159 | 159 | function add_rewrite_tag( $tag, $regex, $query = '' ) { |
160 | 160 | // validate the tag's name |
161 | - if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' ) |
|
162 | - return; |
|
161 | + if ( strlen( $tag ) < 3 || $tag[0] != '%' || $tag[ strlen($tag) - 1 ] != '%' ) { |
|
162 | + return; |
|
163 | + } |
|
163 | 164 | |
164 | 165 | global $wp_rewrite, $wp; |
165 | 166 | |
@@ -203,10 +204,12 @@ discard block |
||
203 | 204 | global $wp_rewrite; |
204 | 205 | |
205 | 206 | // backwards compatibility for the old parameters: $with_front and $ep_mask |
206 | - if ( ! is_array( $args ) ) |
|
207 | - $args = array( 'with_front' => $args ); |
|
208 | - if ( func_num_args() == 4 ) |
|
209 | - $args['ep_mask'] = func_get_arg( 3 ); |
|
207 | + if ( ! is_array( $args ) ) { |
|
208 | + $args = array( 'with_front' => $args ); |
|
209 | + } |
|
210 | + if ( func_num_args() == 4 ) { |
|
211 | + $args['ep_mask'] = func_get_arg( 3 ); |
|
212 | + } |
|
210 | 213 | |
211 | 214 | $wp_rewrite->add_permastruct( $name, $struct, $args ); |
212 | 215 | } |
@@ -474,8 +477,9 @@ discard block |
||
474 | 477 | // First, check to see if there is a 'p=N' or 'page_id=N' to match against |
475 | 478 | if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) { |
476 | 479 | $id = absint($values[2]); |
477 | - if ( $id ) |
|
478 | - return $id; |
|
480 | + if ( $id ) { |
|
481 | + return $id; |
|
482 | + } |
|
479 | 483 | } |
480 | 484 | |
481 | 485 | // Get rid of the #anchor |
@@ -491,12 +495,14 @@ discard block |
||
491 | 495 | $url = set_url_scheme( $url, $scheme ); |
492 | 496 | |
493 | 497 | // Add 'www.' if it is absent and should be there |
494 | - if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) |
|
495 | - $url = str_replace('://', '://www.', $url); |
|
498 | + if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') ) { |
|
499 | + $url = str_replace('://', '://www.', $url); |
|
500 | + } |
|
496 | 501 | |
497 | 502 | // Strip 'www.' if it is present and shouldn't be |
498 | - if ( false === strpos(home_url(), '://www.') ) |
|
499 | - $url = str_replace('://www.', '://', $url); |
|
503 | + if ( false === strpos(home_url(), '://www.') ) { |
|
504 | + $url = str_replace('://www.', '://', $url); |
|
505 | + } |
|
500 | 506 | |
501 | 507 | if ( trim( $url, '/' ) === home_url() && 'page' == get_option( 'show_on_front' ) ) { |
502 | 508 | $page_on_front = get_option( 'page_on_front' ); |
@@ -510,12 +516,14 @@ discard block |
||
510 | 516 | $rewrite = $wp_rewrite->wp_rewrite_rules(); |
511 | 517 | |
512 | 518 | // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options |
513 | - if ( empty($rewrite) ) |
|
514 | - return 0; |
|
519 | + if ( empty($rewrite) ) { |
|
520 | + return 0; |
|
521 | + } |
|
515 | 522 | |
516 | 523 | // Strip 'index.php/' if we're not using path info permalinks |
517 | - if ( !$wp_rewrite->using_index_permalinks() ) |
|
518 | - $url = str_replace( $wp_rewrite->index . '/', '', $url ); |
|
524 | + if ( !$wp_rewrite->using_index_permalinks() ) { |
|
525 | + $url = str_replace( $wp_rewrite->index . '/', '', $url ); |
|
526 | + } |
|
519 | 527 | |
520 | 528 | if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) { |
521 | 529 | // Chop off http://domain.com/[path] |
@@ -534,8 +542,9 @@ discard block |
||
534 | 542 | $post_type_query_vars = array(); |
535 | 543 | |
536 | 544 | foreach ( get_post_types( array() , 'objects' ) as $post_type => $t ) { |
537 | - if ( ! empty( $t->query_var ) ) |
|
538 | - $post_type_query_vars[ $t->query_var ] = $post_type; |
|
545 | + if ( ! empty( $t->query_var ) ) { |
|
546 | + $post_type_query_vars[ $t->query_var ] = $post_type; |
|
547 | + } |
|
539 | 548 | } |
540 | 549 | |
541 | 550 | // Look for matches. |
@@ -544,8 +553,9 @@ discard block |
||
544 | 553 | |
545 | 554 | // If the requesting file is the anchor of the match, prepend it |
546 | 555 | // to the path info. |
547 | - if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) ) |
|
548 | - $request_match = $url . '/' . $request; |
|
556 | + if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) ) { |
|
557 | + $request_match = $url . '/' . $request; |
|
558 | + } |
|
549 | 559 | |
550 | 560 | if ( preg_match("#^$match#", $request_match, $matches) ) { |
551 | 561 | |
@@ -589,10 +599,11 @@ discard block |
||
589 | 599 | |
590 | 600 | // Do the query |
591 | 601 | $query = new WP_Query( $query ); |
592 | - if ( ! empty( $query->posts ) && $query->is_singular ) |
|
593 | - return $query->post->ID; |
|
594 | - else |
|
595 | - return 0; |
|
602 | + if ( ! empty( $query->posts ) && $query->is_singular ) { |
|
603 | + return $query->post->ID; |
|
604 | + } else { |
|
605 | + return 0; |
|
606 | + } |
|
596 | 607 | } |
597 | 608 | } |
598 | 609 | return 0; |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Taxonomy API: Core category-specific functionality |
|
4 | - * |
|
5 | - * @package WordPress |
|
6 | - * @subpackage Taxonomy |
|
7 | - */ |
|
3 | + * Taxonomy API: Core category-specific functionality |
|
4 | + * |
|
5 | + * @package WordPress |
|
6 | + * @subpackage Taxonomy |
|
7 | + */ |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Retrieve list of category objects. |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | * } |
24 | 24 | * @return array List of categories. |
25 | 25 | */ |
26 | -function get_categories( $args = '' ) { |
|
27 | - $defaults = array( 'taxonomy' => 'category' ); |
|
28 | - $args = wp_parse_args( $args, $defaults ); |
|
26 | +function get_categories($args = '') { |
|
27 | + $defaults = array('taxonomy' => 'category'); |
|
28 | + $args = wp_parse_args($args, $defaults); |
|
29 | 29 | |
30 | 30 | $taxonomy = $args['taxonomy']; |
31 | 31 | |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | * @param string $taxonomy Taxonomy to retrieve terms from. |
38 | 38 | * @param array $args An array of arguments. See {@see get_terms()}. |
39 | 39 | */ |
40 | - $taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args ); |
|
40 | + $taxonomy = apply_filters('get_categories_taxonomy', $taxonomy, $args); |
|
41 | 41 | |
42 | 42 | // Back compat |
43 | - if ( isset($args['type']) && 'link' == $args['type'] ) { |
|
43 | + if (isset($args['type']) && 'link' == $args['type']) { |
|
44 | 44 | /* translators: 1: "type => link", 2: "taxonomy => link_category" alternative */ |
45 | - _deprecated_argument( __FUNCTION__, '3.0', |
|
46 | - sprintf( __( '%1$s is deprecated. Use %2$s instead.' ), |
|
45 | + _deprecated_argument(__FUNCTION__, '3.0', |
|
46 | + sprintf(__('%1$s is deprecated. Use %2$s instead.'), |
|
47 | 47 | '<code>type => link</code>', |
48 | 48 | '<code>taxonomy => link_category</code>' |
49 | 49 | ) |
@@ -51,14 +51,14 @@ discard block |
||
51 | 51 | $taxonomy = $args['taxonomy'] = 'link_category'; |
52 | 52 | } |
53 | 53 | |
54 | - $categories = get_terms( $taxonomy, $args ); |
|
54 | + $categories = get_terms($taxonomy, $args); |
|
55 | 55 | |
56 | - if ( is_wp_error( $categories ) ) { |
|
56 | + if (is_wp_error($categories)) { |
|
57 | 57 | $categories = array(); |
58 | 58 | } else { |
59 | 59 | $categories = (array) $categories; |
60 | - foreach ( array_keys( $categories ) as $k ) { |
|
61 | - _make_cat_compat( $categories[ $k ] ); |
|
60 | + foreach (array_keys($categories) as $k) { |
|
61 | + _make_cat_compat($categories[$k]); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | * @return object|array|WP_Error|null Category data in type defined by $output parameter. |
88 | 88 | * WP_Error if $category is empty, null if it does not exist. |
89 | 89 | */ |
90 | -function get_category( $category, $output = OBJECT, $filter = 'raw' ) { |
|
91 | - $category = get_term( $category, 'category', $output, $filter ); |
|
90 | +function get_category($category, $output = OBJECT, $filter = 'raw') { |
|
91 | + $category = get_term($category, 'category', $output, $filter); |
|
92 | 92 | |
93 | - if ( is_wp_error( $category ) ) |
|
93 | + if (is_wp_error($category)) |
|
94 | 94 | return $category; |
95 | 95 | |
96 | - _make_cat_compat( $category ); |
|
96 | + _make_cat_compat($category); |
|
97 | 97 | |
98 | 98 | return $category; |
99 | 99 | } |
@@ -117,45 +117,45 @@ discard block |
||
117 | 117 | * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N |
118 | 118 | * @return object|array|WP_Error|void Type is based on $output value. |
119 | 119 | */ |
120 | -function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) { |
|
121 | - $category_path = rawurlencode( urldecode( $category_path ) ); |
|
122 | - $category_path = str_replace( '%2F', '/', $category_path ); |
|
123 | - $category_path = str_replace( '%20', ' ', $category_path ); |
|
124 | - $category_paths = '/' . trim( $category_path, '/' ); |
|
125 | - $leaf_path = sanitize_title( basename( $category_paths ) ); |
|
126 | - $category_paths = explode( '/', $category_paths ); |
|
120 | +function get_category_by_path($category_path, $full_match = true, $output = OBJECT) { |
|
121 | + $category_path = rawurlencode(urldecode($category_path)); |
|
122 | + $category_path = str_replace('%2F', '/', $category_path); |
|
123 | + $category_path = str_replace('%20', ' ', $category_path); |
|
124 | + $category_paths = '/'.trim($category_path, '/'); |
|
125 | + $leaf_path = sanitize_title(basename($category_paths)); |
|
126 | + $category_paths = explode('/', $category_paths); |
|
127 | 127 | $full_path = ''; |
128 | - foreach ( (array) $category_paths as $pathdir ) { |
|
129 | - $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir ); |
|
128 | + foreach ((array) $category_paths as $pathdir) { |
|
129 | + $full_path .= ($pathdir != '' ? '/' : '').sanitize_title($pathdir); |
|
130 | 130 | } |
131 | - $categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) ); |
|
131 | + $categories = get_terms('category', array('get' => 'all', 'slug' => $leaf_path)); |
|
132 | 132 | |
133 | - if ( empty( $categories ) ) { |
|
133 | + if (empty($categories)) { |
|
134 | 134 | return; |
135 | 135 | } |
136 | 136 | |
137 | - foreach ( $categories as $category ) { |
|
138 | - $path = '/' . $leaf_path; |
|
137 | + foreach ($categories as $category) { |
|
138 | + $path = '/'.$leaf_path; |
|
139 | 139 | $curcategory = $category; |
140 | - while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) { |
|
141 | - $curcategory = get_term( $curcategory->parent, 'category' ); |
|
142 | - if ( is_wp_error( $curcategory ) ) { |
|
140 | + while (($curcategory->parent != 0) && ($curcategory->parent != $curcategory->term_id)) { |
|
141 | + $curcategory = get_term($curcategory->parent, 'category'); |
|
142 | + if (is_wp_error($curcategory)) { |
|
143 | 143 | return $curcategory; |
144 | 144 | } |
145 | - $path = '/' . $curcategory->slug . $path; |
|
145 | + $path = '/'.$curcategory->slug.$path; |
|
146 | 146 | } |
147 | 147 | |
148 | - if ( $path == $full_path ) { |
|
149 | - $category = get_term( $category->term_id, 'category', $output ); |
|
150 | - _make_cat_compat( $category ); |
|
148 | + if ($path == $full_path) { |
|
149 | + $category = get_term($category->term_id, 'category', $output); |
|
150 | + _make_cat_compat($category); |
|
151 | 151 | return $category; |
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
155 | 155 | // If full matching is not required, return the first cat that matches the leaf. |
156 | - if ( ! $full_match ) { |
|
157 | - $category = get_term( reset( $categories )->term_id, 'category', $output ); |
|
158 | - _make_cat_compat( $category ); |
|
156 | + if ( ! $full_match) { |
|
157 | + $category = get_term(reset($categories)->term_id, 'category', $output); |
|
158 | + _make_cat_compat($category); |
|
159 | 159 | return $category; |
160 | 160 | } |
161 | 161 | } |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | * @param string $slug The category slug. |
169 | 169 | * @return object Category data object |
170 | 170 | */ |
171 | -function get_category_by_slug( $slug ) { |
|
172 | - $category = get_term_by( 'slug', $slug, 'category' ); |
|
173 | - if ( $category ) |
|
174 | - _make_cat_compat( $category ); |
|
171 | +function get_category_by_slug($slug) { |
|
172 | + $category = get_term_by('slug', $slug, 'category'); |
|
173 | + if ($category) |
|
174 | + _make_cat_compat($category); |
|
175 | 175 | |
176 | 176 | return $category; |
177 | 177 | } |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | * @param string $cat_name Category name. |
185 | 185 | * @return int 0, if failure and ID of category on success. |
186 | 186 | */ |
187 | -function get_cat_ID( $cat_name ) { |
|
188 | - $cat = get_term_by( 'name', $cat_name, 'category' ); |
|
189 | - if ( $cat ) |
|
187 | +function get_cat_ID($cat_name) { |
|
188 | + $cat = get_term_by('name', $cat_name, 'category'); |
|
189 | + if ($cat) |
|
190 | 190 | return $cat->term_id; |
191 | 191 | return 0; |
192 | 192 | } |
@@ -199,10 +199,10 @@ discard block |
||
199 | 199 | * @param int $cat_id Category ID |
200 | 200 | * @return string Category name, or an empty string if category doesn't exist. |
201 | 201 | */ |
202 | -function get_cat_name( $cat_id ) { |
|
202 | +function get_cat_name($cat_id) { |
|
203 | 203 | $cat_id = (int) $cat_id; |
204 | - $category = get_term( $cat_id, 'category' ); |
|
205 | - if ( ! $category || is_wp_error( $category ) ) |
|
204 | + $category = get_term($cat_id, 'category'); |
|
205 | + if ( ! $category || is_wp_error($category)) |
|
206 | 206 | return ''; |
207 | 207 | return $category->name; |
208 | 208 | } |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @param int|object $cat2 The child category. |
220 | 220 | * @return bool Whether $cat2 is child of $cat1 |
221 | 221 | */ |
222 | -function cat_is_ancestor_of( $cat1, $cat2 ) { |
|
223 | - return term_is_ancestor_of( $cat1, $cat2, 'category' ); |
|
222 | +function cat_is_ancestor_of($cat1, $cat2) { |
|
223 | + return term_is_ancestor_of($cat1, $cat2, 'category'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | * @param string $context Optional. Default is 'display'. |
233 | 233 | * @return object|array Same type as $category with sanitized data for safe use. |
234 | 234 | */ |
235 | -function sanitize_category( $category, $context = 'display' ) { |
|
236 | - return sanitize_term( $category, 'category', $context ); |
|
235 | +function sanitize_category($category, $context = 'display') { |
|
236 | + return sanitize_term($category, 'category', $context); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * @param string $context What filter to use, 'raw', 'display', etc. |
248 | 248 | * @return mixed Same type as $value after $value has been sanitized. |
249 | 249 | */ |
250 | -function sanitize_category_field( $field, $value, $cat_id, $context ) { |
|
251 | - return sanitize_term_field( $field, $value, $cat_id, 'category', $context ); |
|
250 | +function sanitize_category_field($field, $value, $cat_id, $context) { |
|
251 | + return sanitize_term_field($field, $value, $cat_id, 'category', $context); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | /* Tags */ |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | * @param string|array $args Tag arguments to use when retrieving tags. |
263 | 263 | * @return array List of tags. |
264 | 264 | */ |
265 | -function get_tags( $args = '' ) { |
|
266 | - $tags = get_terms( 'post_tag', $args ); |
|
265 | +function get_tags($args = '') { |
|
266 | + $tags = get_terms('post_tag', $args); |
|
267 | 267 | |
268 | - if ( empty( $tags ) ) { |
|
268 | + if (empty($tags)) { |
|
269 | 269 | $return = array(); |
270 | 270 | return $return; |
271 | 271 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @param array $tags Array of 'post_tag' term objects. |
279 | 279 | * @param array $args An array of arguments. @see get_terms() |
280 | 280 | */ |
281 | - $tags = apply_filters( 'get_tags', $tags, $args ); |
|
281 | + $tags = apply_filters('get_tags', $tags, $args); |
|
282 | 282 | return $tags; |
283 | 283 | } |
284 | 284 | |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. |
302 | 302 | * @return object|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist. |
303 | 303 | */ |
304 | -function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { |
|
305 | - return get_term( $tag, 'post_tag', $output, $filter ); |
|
304 | +function get_tag($tag, $output = OBJECT, $filter = 'raw') { |
|
305 | + return get_term($tag, 'post_tag', $output, $filter); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /* Cache */ |
@@ -314,8 +314,8 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @param int $id Category ID |
316 | 316 | */ |
317 | -function clean_category_cache( $id ) { |
|
318 | - clean_term_cache( $id, 'category' ); |
|
317 | +function clean_category_cache($id) { |
|
318 | + clean_term_cache($id, 'category'); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -338,15 +338,15 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @param array|object|WP_Term $category Category Row object or array |
340 | 340 | */ |
341 | -function _make_cat_compat( &$category ) { |
|
342 | - if ( is_object( $category ) && ! is_wp_error( $category ) ) { |
|
341 | +function _make_cat_compat(&$category) { |
|
342 | + if (is_object($category) && ! is_wp_error($category)) { |
|
343 | 343 | $category->cat_ID = $category->term_id; |
344 | 344 | $category->category_count = $category->count; |
345 | 345 | $category->category_description = $category->description; |
346 | 346 | $category->cat_name = $category->name; |
347 | 347 | $category->category_nicename = $category->slug; |
348 | 348 | $category->category_parent = $category->parent; |
349 | - } elseif ( is_array( $category ) && isset( $category['term_id'] ) ) { |
|
349 | + } elseif (is_array($category) && isset($category['term_id'])) { |
|
350 | 350 | $category['cat_ID'] = &$category['term_id']; |
351 | 351 | $category['category_count'] = &$category['count']; |
352 | 352 | $category['category_description'] = &$category['description']; |
@@ -90,8 +90,9 @@ discard block |
||
90 | 90 | function get_category( $category, $output = OBJECT, $filter = 'raw' ) { |
91 | 91 | $category = get_term( $category, 'category', $output, $filter ); |
92 | 92 | |
93 | - if ( is_wp_error( $category ) ) |
|
94 | - return $category; |
|
93 | + if ( is_wp_error( $category ) ) { |
|
94 | + return $category; |
|
95 | + } |
|
95 | 96 | |
96 | 97 | _make_cat_compat( $category ); |
97 | 98 | |
@@ -170,8 +171,9 @@ discard block |
||
170 | 171 | */ |
171 | 172 | function get_category_by_slug( $slug ) { |
172 | 173 | $category = get_term_by( 'slug', $slug, 'category' ); |
173 | - if ( $category ) |
|
174 | - _make_cat_compat( $category ); |
|
174 | + if ( $category ) { |
|
175 | + _make_cat_compat( $category ); |
|
176 | + } |
|
175 | 177 | |
176 | 178 | return $category; |
177 | 179 | } |
@@ -186,8 +188,9 @@ discard block |
||
186 | 188 | */ |
187 | 189 | function get_cat_ID( $cat_name ) { |
188 | 190 | $cat = get_term_by( 'name', $cat_name, 'category' ); |
189 | - if ( $cat ) |
|
190 | - return $cat->term_id; |
|
191 | + if ( $cat ) { |
|
192 | + return $cat->term_id; |
|
193 | + } |
|
191 | 194 | return 0; |
192 | 195 | } |
193 | 196 | |
@@ -202,8 +205,9 @@ discard block |
||
202 | 205 | function get_cat_name( $cat_id ) { |
203 | 206 | $cat_id = (int) $cat_id; |
204 | 207 | $category = get_term( $cat_id, 'category' ); |
205 | - if ( ! $category || is_wp_error( $category ) ) |
|
206 | - return ''; |
|
208 | + if ( ! $category || is_wp_error( $category ) ) { |
|
209 | + return ''; |
|
210 | + } |
|
207 | 211 | return $category->name; |
208 | 212 | } |
209 | 213 |