@@ -25,17 +25,17 @@ discard block |
||
25 | 25 | * @param bool $force (optional) Force callback to be executed when transient is locked |
26 | 26 | * @return mixed |
27 | 27 | */ |
28 | - public static function transient( $slug, $callback, $transient_time = 0, $lock_timeout = 5, $force = false ) { |
|
28 | + public static function transient($slug, $callback, $transient_time = 0, $lock_timeout = 5, $force = false) { |
|
29 | 29 | |
30 | - $enable_transients = ( $transient_time === false || ( defined( 'WP_DISABLE_TRANSIENTS' ) && WP_DISABLE_TRANSIENTS ) ) ? false : true; |
|
31 | - $data = $enable_transients ? get_transient( $slug ) : false; |
|
30 | + $enable_transients = ($transient_time === false || (defined('WP_DISABLE_TRANSIENTS') && WP_DISABLE_TRANSIENTS)) ? false : true; |
|
31 | + $data = $enable_transients ? get_transient($slug) : false; |
|
32 | 32 | |
33 | 33 | if ( false === $data ) { |
34 | 34 | |
35 | - if ( $enable_transients && self::_is_transient_locked( $slug ) ) { |
|
35 | + if ( $enable_transients && self::_is_transient_locked($slug) ) { |
|
36 | 36 | |
37 | - $force = apply_filters( 'timber_force_transients', $force ); |
|
38 | - $force = apply_filters( 'timber_force_transient_' . $slug, $force ); |
|
37 | + $force = apply_filters('timber_force_transients', $force); |
|
38 | + $force = apply_filters('timber_force_transient_' . $slug, $force); |
|
39 | 39 | |
40 | 40 | if ( !$force ) { |
41 | 41 | //the server is currently executing the process. |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | // lock timeout shouldn't be higher than 5 seconds, unless |
50 | 50 | // remote calls with high timeouts are made here |
51 | 51 | if ( $enable_transients ) |
52 | - self::_lock_transient( $slug, $lock_timeout ); |
|
52 | + self::_lock_transient($slug, $lock_timeout); |
|
53 | 53 | |
54 | 54 | $data = $callback(); |
55 | 55 | |
56 | 56 | if ( $enable_transients ) { |
57 | - set_transient( $slug, $data, $transient_time ); |
|
58 | - self::_unlock_transient( $slug ); |
|
57 | + set_transient($slug, $data, $transient_time); |
|
58 | + self::_unlock_transient($slug); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | } |
@@ -69,24 +69,24 @@ discard block |
||
69 | 69 | * @param string $slug |
70 | 70 | * @param integer $lock_timeout |
71 | 71 | */ |
72 | - static function _lock_transient( $slug, $lock_timeout ) { |
|
73 | - set_transient( $slug . '_lock', true, $lock_timeout ); |
|
72 | + static function _lock_transient($slug, $lock_timeout) { |
|
73 | + set_transient($slug . '_lock', true, $lock_timeout); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * @internal |
78 | 78 | * @param string $slug |
79 | 79 | */ |
80 | - static function _unlock_transient( $slug ) { |
|
81 | - delete_transient( $slug . '_lock', true ); |
|
80 | + static function _unlock_transient($slug) { |
|
81 | + delete_transient($slug . '_lock', true); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @internal |
86 | 86 | * @param string $slug |
87 | 87 | */ |
88 | - static function _is_transient_locked( $slug ) { |
|
89 | - return (bool)get_transient( $slug . '_lock' ); |
|
88 | + static function _is_transient_locked($slug) { |
|
89 | + return (bool) get_transient($slug . '_lock'); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /* These are for measuring page render time */ |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public static function start_timer() { |
100 | 100 | $time = microtime(); |
101 | - $time = explode( ' ', $time ); |
|
101 | + $time = explode(' ', $time); |
|
102 | 102 | $time = $time[1] + $time[0]; |
103 | 103 | return $time; |
104 | 104 | } |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | * @param int $start |
115 | 115 | * @return string |
116 | 116 | */ |
117 | - public static function stop_timer( $start ) { |
|
117 | + public static function stop_timer($start) { |
|
118 | 118 | $time = microtime(); |
119 | - $time = explode( ' ', $time ); |
|
119 | + $time = explode(' ', $time); |
|
120 | 120 | $time = $time[1] + $time[0]; |
121 | 121 | $finish = $time; |
122 | - $total_time = round( ( $finish - $start ), 4 ); |
|
122 | + $total_time = round(($finish - $start), 4); |
|
123 | 123 | return $total_time . ' seconds.'; |
124 | 124 | } |
125 | 125 | |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | * @param array $args |
153 | 153 | * @return string |
154 | 154 | */ |
155 | - public static function ob_function( $function, $args = array( null ) ) { |
|
155 | + public static function ob_function($function, $args = array(null)) { |
|
156 | 156 | ob_start(); |
157 | - call_user_func_array( $function, $args ); |
|
157 | + call_user_func_array($function, $args); |
|
158 | 158 | $data = ob_get_contents(); |
159 | 159 | ob_end_clean(); |
160 | 160 | return $data; |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param bool $return_output_buffer |
169 | 169 | * @return TimberFunctionWrapper |
170 | 170 | */ |
171 | - public static function function_wrapper( $function_name, $defaults = array(), $return_output_buffer = false ) { |
|
172 | - return new TimberFunctionWrapper( $function_name, $defaults, $return_output_buffer ); |
|
171 | + public static function function_wrapper($function_name, $defaults = array(), $return_output_buffer = false) { |
|
172 | + return new TimberFunctionWrapper($function_name, $defaults, $return_output_buffer); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -178,14 +178,14 @@ discard block |
||
178 | 178 | * @param mixed $arg that you want to error_log |
179 | 179 | * @return void |
180 | 180 | */ |
181 | - public static function error_log( $arg ) { |
|
181 | + public static function error_log($arg) { |
|
182 | 182 | if ( !WP_DEBUG ) { |
183 | 183 | return; |
184 | 184 | } |
185 | - if ( is_object( $arg ) || is_array( $arg ) ) { |
|
186 | - $arg = print_r( $arg, true ); |
|
185 | + if ( is_object($arg) || is_array($arg) ) { |
|
186 | + $arg = print_r($arg, true); |
|
187 | 187 | } |
188 | - return error_log( $arg ); |
|
188 | + return error_log($arg); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | * @param string $seplocation |
196 | 196 | * @return string |
197 | 197 | */ |
198 | - public static function get_wp_title( $separator = ' ', $seplocation = 'left' ) { |
|
199 | - $separator = apply_filters( 'timber_wp_title_seperator', $separator ); |
|
200 | - return trim( wp_title( $separator, false, $seplocation ) ); |
|
198 | + public static function get_wp_title($separator = ' ', $seplocation = 'left') { |
|
199 | + $separator = apply_filters('timber_wp_title_seperator', $separator); |
|
200 | + return trim(wp_title($separator, false, $seplocation)); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | /* Text Utilities |
@@ -212,35 +212,35 @@ discard block |
||
212 | 212 | * @param string $allowed_tags |
213 | 213 | * @return string |
214 | 214 | */ |
215 | - public static function trim_words( $text, $num_words = 55, $more = null, $allowed_tags = 'p a span b i br blockquote' ) { |
|
215 | + public static function trim_words($text, $num_words = 55, $more = null, $allowed_tags = 'p a span b i br blockquote') { |
|
216 | 216 | if ( null === $more ) { |
217 | - $more = __( '…' ); |
|
217 | + $more = __('…'); |
|
218 | 218 | } |
219 | 219 | $original_text = $text; |
220 | 220 | $allowed_tag_string = ''; |
221 | - foreach ( explode( ' ', apply_filters( 'timber/trim_words/allowed_tags', $allowed_tags ) ) as $tag ) { |
|
221 | + foreach (explode(' ', apply_filters('timber/trim_words/allowed_tags', $allowed_tags)) as $tag) { |
|
222 | 222 | $allowed_tag_string .= '<' . $tag . '>'; |
223 | 223 | } |
224 | - $text = strip_tags( $text, $allowed_tag_string ); |
|
224 | + $text = strip_tags($text, $allowed_tag_string); |
|
225 | 225 | /* translators: If your word count is based on single characters (East Asian characters), enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */ |
226 | - if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { |
|
227 | - $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); |
|
228 | - preg_match_all( '/./u', $text, $words_array ); |
|
229 | - $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); |
|
226 | + if ( 'characters' == _x('words', 'word count: words or characters?') && preg_match('/^utf\-?8$/i', get_option('blog_charset')) ) { |
|
227 | + $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' '); |
|
228 | + preg_match_all('/./u', $text, $words_array); |
|
229 | + $words_array = array_slice($words_array[0], 0, $num_words + 1); |
|
230 | 230 | $sep = ''; |
231 | 231 | } else { |
232 | - $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); |
|
232 | + $words_array = preg_split("/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY); |
|
233 | 233 | $sep = ' '; |
234 | 234 | } |
235 | - if ( count( $words_array ) > $num_words ) { |
|
236 | - array_pop( $words_array ); |
|
237 | - $text = implode( $sep, $words_array ); |
|
235 | + if ( count($words_array) > $num_words ) { |
|
236 | + array_pop($words_array); |
|
237 | + $text = implode($sep, $words_array); |
|
238 | 238 | $text = $text . $more; |
239 | 239 | } else { |
240 | - $text = implode( $sep, $words_array ); |
|
240 | + $text = implode($sep, $words_array); |
|
241 | 241 | } |
242 | - $text = self::close_tags( $text ); |
|
243 | - return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); |
|
242 | + $text = self::close_tags($text); |
|
243 | + return apply_filters('wp_trim_words', $text, $num_words, $more, $original_text); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -249,29 +249,29 @@ discard block |
||
249 | 249 | * @param string $html |
250 | 250 | * @return string |
251 | 251 | */ |
252 | - public static function close_tags( $html ) { |
|
252 | + public static function close_tags($html) { |
|
253 | 253 | //put all opened tags into an array |
254 | - preg_match_all( '#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result ); |
|
254 | + preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result); |
|
255 | 255 | $openedtags = $result[1]; |
256 | 256 | //put all closed tags into an array |
257 | - preg_match_all( '#</([a-z]+)>#iU', $html, $result ); |
|
257 | + preg_match_all('#</([a-z]+)>#iU', $html, $result); |
|
258 | 258 | $closedtags = $result[1]; |
259 | - $len_opened = count( $openedtags ); |
|
259 | + $len_opened = count($openedtags); |
|
260 | 260 | // all tags are closed |
261 | - if ( count( $closedtags ) == $len_opened ) { |
|
261 | + if ( count($closedtags) == $len_opened ) { |
|
262 | 262 | return $html; |
263 | 263 | } |
264 | - $openedtags = array_reverse( $openedtags ); |
|
264 | + $openedtags = array_reverse($openedtags); |
|
265 | 265 | // close tags |
266 | - for ( $i = 0; $i < $len_opened; $i++ ) { |
|
267 | - if ( !in_array( $openedtags[$i], $closedtags ) ) { |
|
266 | + for ($i = 0; $i < $len_opened; $i++) { |
|
267 | + if ( !in_array($openedtags[$i], $closedtags) ) { |
|
268 | 268 | $html .= '</' . $openedtags[$i] . '>'; |
269 | 269 | } else { |
270 | - unset( $closedtags[array_search( $openedtags[$i], $closedtags )] ); |
|
270 | + unset($closedtags[array_search($openedtags[$i], $closedtags)]); |
|
271 | 271 | } |
272 | 272 | } |
273 | - $html = str_replace(array('</br>','</hr>','</wbr>'), '', $html); |
|
274 | - $html = str_replace(array('<br>','<hr>','<wbr>'), array('<br />','<hr />','<wbr />'), $html); |
|
273 | + $html = str_replace(array('</br>', '</hr>', '</wbr>'), '', $html); |
|
274 | + $html = str_replace(array('<br>', '<hr>', '<wbr>'), array('<br />', '<hr />', '<wbr />'), $html); |
|
275 | 275 | return $html; |
276 | 276 | } |
277 | 277 | |
@@ -284,17 +284,17 @@ discard block |
||
284 | 284 | * @return array|int |
285 | 285 | * @deprecated 0.20.0 |
286 | 286 | */ |
287 | - public static function get_posts_by_meta( $key, $value ) { |
|
287 | + public static function get_posts_by_meta($key, $value) { |
|
288 | 288 | global $wpdb; |
289 | - $query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value ); |
|
290 | - $results = $wpdb->get_col( $query ); |
|
289 | + $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value); |
|
290 | + $results = $wpdb->get_col($query); |
|
291 | 291 | $pids = array(); |
292 | - foreach ( $results as $result ) { |
|
293 | - if ( get_post( $result ) ) { |
|
292 | + foreach ($results as $result) { |
|
293 | + if ( get_post($result) ) { |
|
294 | 294 | $pids[] = $result; |
295 | 295 | } |
296 | 296 | } |
297 | - if ( count( $pids ) ) { |
|
297 | + if ( count($pids) ) { |
|
298 | 298 | return $pids; |
299 | 299 | } |
300 | 300 | return 0; |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * @return int |
309 | 309 | * @deprecated 0.20.0 |
310 | 310 | */ |
311 | - public static function get_post_by_meta( $key, $value ) { |
|
311 | + public static function get_post_by_meta($key, $value) { |
|
312 | 312 | global $wpdb; |
313 | - $query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ORDER BY post_id", $key, $value ); |
|
314 | - $results = $wpdb->get_col( $query ); |
|
315 | - foreach ( $results as $result ) { |
|
316 | - if ( $result && get_post( $result ) ) { |
|
313 | + $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ORDER BY post_id", $key, $value); |
|
314 | + $results = $wpdb->get_col($query); |
|
315 | + foreach ($results as $result) { |
|
316 | + if ( $result && get_post($result) ) { |
|
317 | 317 | return $result; |
318 | 318 | } |
319 | 319 | } |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | * @param int $ttid |
327 | 327 | * @return mixed |
328 | 328 | */ |
329 | - public static function get_term_id_by_term_taxonomy_id( $ttid ) { |
|
329 | + public static function get_term_id_by_term_taxonomy_id($ttid) { |
|
330 | 330 | global $wpdb; |
331 | - $query = $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %s", $ttid ); |
|
332 | - return $wpdb->get_var( $query ); |
|
331 | + $query = $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %s", $ttid); |
|
332 | + return $wpdb->get_var($query); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /* Object Utilities |
@@ -342,8 +342,8 @@ discard block |
||
342 | 342 | * @param string $prop |
343 | 343 | * @return void |
344 | 344 | */ |
345 | - public static function osort( &$array, $prop ) { |
|
346 | - usort( $array, function ( $a, $b ) use ( $prop ) { |
|
345 | + public static function osort(&$array, $prop) { |
|
346 | + usort($array, function($a, $b) use ($prop) { |
|
347 | 347 | return $a->$prop > $b->$prop ? 1 : -1; |
348 | 348 | } ); |
349 | 349 | } |
@@ -354,11 +354,11 @@ discard block |
||
354 | 354 | * @param array $arr |
355 | 355 | * @return bool |
356 | 356 | */ |
357 | - public static function is_array_assoc( $arr ) { |
|
358 | - if ( !is_array( $arr ) ) { |
|
357 | + public static function is_array_assoc($arr) { |
|
358 | + if ( !is_array($arr) ) { |
|
359 | 359 | return false; |
360 | 360 | } |
361 | - return (bool)count( array_filter( array_keys( $arr ), 'is_string' ) ); |
|
361 | + return (bool) count(array_filter(array_keys($arr), 'is_string')); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -367,11 +367,11 @@ discard block |
||
367 | 367 | * @param array $array |
368 | 368 | * @return stdClass |
369 | 369 | */ |
370 | - public static function array_to_object( $array ) { |
|
370 | + public static function array_to_object($array) { |
|
371 | 371 | $obj = new stdClass; |
372 | - foreach ( $array as $k => $v ) { |
|
373 | - if ( is_array( $v ) ) { |
|
374 | - $obj->{$k} = self::array_to_object( $v ); //RECURSION |
|
372 | + foreach ($array as $k => $v) { |
|
373 | + if ( is_array($v) ) { |
|
374 | + $obj->{$k} = self::array_to_object($v); //RECURSION |
|
375 | 375 | } else { |
376 | 376 | $obj->{$k} = $v; |
377 | 377 | } |
@@ -387,11 +387,11 @@ discard block |
||
387 | 387 | * @param mixed $value |
388 | 388 | * @return bool|int |
389 | 389 | */ |
390 | - public static function get_object_index_by_property( $array, $key, $value ) { |
|
391 | - if ( is_array( $array ) ) { |
|
390 | + public static function get_object_index_by_property($array, $key, $value) { |
|
391 | + if ( is_array($array) ) { |
|
392 | 392 | $i = 0; |
393 | - foreach ( $array as $arr ) { |
|
394 | - if ( is_array( $arr ) ) { |
|
393 | + foreach ($array as $arr) { |
|
394 | + if ( is_array($arr) ) { |
|
395 | 395 | if ( $arr[$key] == $value ) { |
396 | 396 | return $i; |
397 | 397 | } |
@@ -415,16 +415,16 @@ discard block |
||
415 | 415 | * @return array|null |
416 | 416 | * @throws Exception |
417 | 417 | */ |
418 | - public static function get_object_by_property( $array, $key, $value ) { |
|
419 | - if ( is_array( $array ) ) { |
|
420 | - foreach ( $array as $arr ) { |
|
418 | + public static function get_object_by_property($array, $key, $value) { |
|
419 | + if ( is_array($array) ) { |
|
420 | + foreach ($array as $arr) { |
|
421 | 421 | if ( $arr->$key == $value ) { |
422 | 422 | return $arr; |
423 | 423 | } |
424 | 424 | } |
425 | 425 | } else { |
426 | - throw new InvalidArgumentException( '$array is not an array, got:' ); |
|
427 | - TimberHelper::error_log( $array ); |
|
426 | + throw new InvalidArgumentException('$array is not an array, got:'); |
|
427 | + TimberHelper::error_log($array); |
|
428 | 428 | } |
429 | 429 | } |
430 | 430 | |
@@ -435,9 +435,9 @@ discard block |
||
435 | 435 | * @param int $len |
436 | 436 | * @return array |
437 | 437 | */ |
438 | - public static function array_truncate( $array, $len ) { |
|
439 | - if ( sizeof( $array ) > $len ) { |
|
440 | - $array = array_splice( $array, 0, $len ); |
|
438 | + public static function array_truncate($array, $len) { |
|
439 | + if ( sizeof($array) > $len ) { |
|
440 | + $array = array_splice($array, 0, $len); |
|
441 | 441 | } |
442 | 442 | return $array; |
443 | 443 | } |
@@ -451,12 +451,12 @@ discard block |
||
451 | 451 | * @param mixed $value |
452 | 452 | * @return bool |
453 | 453 | */ |
454 | - public static function is_true( $value ) { |
|
455 | - if ( isset( $value ) ) { |
|
456 | - if (is_string($value)) { |
|
454 | + public static function is_true($value) { |
|
455 | + if ( isset($value) ) { |
|
456 | + if ( is_string($value) ) { |
|
457 | 457 | $value = strtolower($value); |
458 | 458 | } |
459 | - if ( ($value == 'true' || $value === 1 || $value === '1' || $value == true) && $value !== false && $value !== 'false') { |
|
459 | + if ( ($value == 'true' || $value === 1 || $value === '1' || $value == true) && $value !== false && $value !== 'false' ) { |
|
460 | 460 | return true; |
461 | 461 | } |
462 | 462 | } |
@@ -469,8 +469,8 @@ discard block |
||
469 | 469 | * @param int $i |
470 | 470 | * @return bool |
471 | 471 | */ |
472 | - public static function iseven( $i ) { |
|
473 | - return ( $i % 2 ) == 0; |
|
472 | + public static function iseven($i) { |
|
473 | + return ($i % 2) == 0; |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -479,8 +479,8 @@ discard block |
||
479 | 479 | * @param int $i |
480 | 480 | * @return bool |
481 | 481 | */ |
482 | - public static function isodd( $i ) { |
|
483 | - return ( $i % 2 ) != 0; |
|
482 | + public static function isodd($i) { |
|
483 | + return ($i % 2) != 0; |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /* Links, Forms, Etc. Utilities |
@@ -494,8 +494,8 @@ discard block |
||
494 | 494 | * @param array $args this $args thing is a fucking mess, [fix at some point](http://codex.wordpress.org/Function_Reference/comment_form) |
495 | 495 | * @return string |
496 | 496 | */ |
497 | - public static function get_comment_form( $post_id = null, $args = array() ) { |
|
498 | - return self::ob_function( 'comment_form', array( $args, $post_id ) ); |
|
497 | + public static function get_comment_form($post_id = null, $args = array()) { |
|
498 | + return self::ob_function('comment_form', array($args, $post_id)); |
|
499 | 499 | } |
500 | 500 | |
501 | 501 | /** |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | * @param string $args |
505 | 505 | * @return array |
506 | 506 | */ |
507 | - public static function paginate_links( $args = '' ) { |
|
507 | + public static function paginate_links($args = '') { |
|
508 | 508 | $defaults = array( |
509 | 509 | 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below) |
510 | 510 | 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number |
@@ -512,42 +512,42 @@ discard block |
||
512 | 512 | 'current' => 0, |
513 | 513 | 'show_all' => false, |
514 | 514 | 'prev_next' => true, |
515 | - 'prev_text' => __( '« Previous' ), |
|
516 | - 'next_text' => __( 'Next »' ), |
|
515 | + 'prev_text' => __('« Previous'), |
|
516 | + 'next_text' => __('Next »'), |
|
517 | 517 | 'end_size' => 1, |
518 | 518 | 'mid_size' => 2, |
519 | 519 | 'type' => 'array', |
520 | 520 | 'add_args' => false, // array of query args to add |
521 | 521 | 'add_fragment' => '' |
522 | 522 | ); |
523 | - $args = wp_parse_args( $args, $defaults ); |
|
523 | + $args = wp_parse_args($args, $defaults); |
|
524 | 524 | // Who knows what else people pass in $args |
525 | - $args['total'] = intval( (int)$args['total'] ); |
|
525 | + $args['total'] = intval((int) $args['total']); |
|
526 | 526 | if ( $args['total'] < 2 ) { |
527 | 527 | return array(); |
528 | 528 | } |
529 | - $args['current'] = (int)$args['current']; |
|
530 | - $args['end_size'] = 0 < (int)$args['end_size'] ? (int)$args['end_size'] : 1; // Out of bounds? Make it the default. |
|
531 | - $args['mid_size'] = 0 <= (int)$args['mid_size'] ? (int)$args['mid_size'] : 2; |
|
532 | - $args['add_args'] = is_array( $args['add_args'] ) ? $args['add_args'] : false; |
|
529 | + $args['current'] = (int) $args['current']; |
|
530 | + $args['end_size'] = 0 < (int) $args['end_size'] ? (int) $args['end_size'] : 1; // Out of bounds? Make it the default. |
|
531 | + $args['mid_size'] = 0 <= (int) $args['mid_size'] ? (int) $args['mid_size'] : 2; |
|
532 | + $args['add_args'] = is_array($args['add_args']) ? $args['add_args'] : false; |
|
533 | 533 | $page_links = array(); |
534 | 534 | $dots = false; |
535 | 535 | if ( $args['prev_next'] && $args['current'] && 1 < $args['current'] ) { |
536 | - $link = str_replace( '%_%', 2 == $args['current'] ? '' : $args['format'], $args['base'] ); |
|
537 | - $link = str_replace( '%#%', $args['current'] - 1, $link ); |
|
536 | + $link = str_replace('%_%', 2 == $args['current'] ? '' : $args['format'], $args['base']); |
|
537 | + $link = str_replace('%#%', $args['current'] - 1, $link); |
|
538 | 538 | if ( $args['add_args'] ) { |
539 | - $link = add_query_arg( $args['add_args'], $link ); |
|
539 | + $link = add_query_arg($args['add_args'], $link); |
|
540 | 540 | } |
541 | 541 | $link .= $args['add_fragment']; |
542 | - $link = untrailingslashit( $link ); |
|
542 | + $link = untrailingslashit($link); |
|
543 | 543 | $page_links[] = array( |
544 | 544 | 'class' => 'prev page-numbers', |
545 | - 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), |
|
545 | + 'link' => esc_url(apply_filters('paginate_links', $link)), |
|
546 | 546 | 'title' => $args['prev_text'] |
547 | 547 | ); |
548 | 548 | } |
549 | - for ( $n = 1; $n <= $args['total']; $n++ ) { |
|
550 | - $n_display = number_format_i18n( $n ); |
|
549 | + for ($n = 1; $n <= $args['total']; $n++) { |
|
550 | + $n_display = number_format_i18n($n); |
|
551 | 551 | if ( $n == $args['current'] ) { |
552 | 552 | $page_links[] = array( |
553 | 553 | 'class' => 'page-number page-numbers current', |
@@ -558,18 +558,18 @@ discard block |
||
558 | 558 | ); |
559 | 559 | $dots = true; |
560 | 560 | } else { |
561 | - if ( $args['show_all'] || ( $n <= $args['end_size'] || ( $args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size'] ) || $n > $args['total'] - $args['end_size'] ) ) { |
|
562 | - $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); |
|
563 | - $link = str_replace( '%#%', $n, $link ); |
|
564 | - $link = trailingslashit( $link ) . ltrim( $args['add_fragment'], '/' ); |
|
561 | + if ( $args['show_all'] || ($n <= $args['end_size'] || ($args['current'] && $n >= $args['current'] - $args['mid_size'] && $n <= $args['current'] + $args['mid_size']) || $n > $args['total'] - $args['end_size']) ) { |
|
562 | + $link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base']); |
|
563 | + $link = str_replace('%#%', $n, $link); |
|
564 | + $link = trailingslashit($link) . ltrim($args['add_fragment'], '/'); |
|
565 | 565 | if ( $args['add_args'] ) { |
566 | - $link = rtrim( add_query_arg( $args['add_args'], $link ), '/' ); |
|
566 | + $link = rtrim(add_query_arg($args['add_args'], $link), '/'); |
|
567 | 567 | } |
568 | 568 | $link = str_replace(' ', '+', $link); |
569 | - $link = untrailingslashit( $link ); |
|
569 | + $link = untrailingslashit($link); |
|
570 | 570 | $page_links[] = array( |
571 | 571 | 'class' => 'page-number page-numbers', |
572 | - 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), |
|
572 | + 'link' => esc_url(apply_filters('paginate_links', $link)), |
|
573 | 573 | 'title' => $n_display, |
574 | 574 | 'name' => $n_display, |
575 | 575 | 'current' => $args['current'] == $n |
@@ -578,22 +578,22 @@ discard block |
||
578 | 578 | } elseif ( $dots && !$args['show_all'] ) { |
579 | 579 | $page_links[] = array( |
580 | 580 | 'class' => 'dots', |
581 | - 'title' => __( '…' ) |
|
581 | + 'title' => __('…') |
|
582 | 582 | ); |
583 | 583 | $dots = false; |
584 | 584 | } |
585 | 585 | } |
586 | 586 | } |
587 | - if ( $args['prev_next'] && $args['current'] && ( $args['current'] < $args['total'] || -1 == $args['total'] ) ) { |
|
588 | - $link = str_replace( '%_%', $args['format'], $args['base'] ); |
|
589 | - $link = str_replace( '%#%', $args['current'] + 1, $link ); |
|
587 | + if ( $args['prev_next'] && $args['current'] && ($args['current'] < $args['total'] || -1 == $args['total']) ) { |
|
588 | + $link = str_replace('%_%', $args['format'], $args['base']); |
|
589 | + $link = str_replace('%#%', $args['current'] + 1, $link); |
|
590 | 590 | if ( $args['add_args'] ) { |
591 | - $link = add_query_arg( $args['add_args'], $link ); |
|
591 | + $link = add_query_arg($args['add_args'], $link); |
|
592 | 592 | } |
593 | - $link = untrailingslashit( trailingslashit( $link ) . $args['add_fragment'] ); |
|
593 | + $link = untrailingslashit(trailingslashit($link) . $args['add_fragment']); |
|
594 | 594 | $page_links[] = array( |
595 | 595 | 'class' => 'next page-numbers', |
596 | - 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), |
|
596 | + 'link' => esc_url(apply_filters('paginate_links', $link)), |
|
597 | 597 | 'title' => $args['next_text'] |
598 | 598 | ); |
599 | 599 | } |
@@ -610,8 +610,8 @@ discard block |
||
610 | 610 | /** |
611 | 611 | * @deprecated 0.18.0 |
612 | 612 | */ |
613 | - static function is_url( $url ) { |
|
614 | - return TimberURLHelper::is_url( $url ); |
|
613 | + static function is_url($url) { |
|
614 | + return TimberURLHelper::is_url($url); |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | /** |
@@ -624,71 +624,71 @@ discard block |
||
624 | 624 | /** |
625 | 625 | * @deprecated 0.18.0 |
626 | 626 | */ |
627 | - static function get_rel_url( $url, $force = false ) { |
|
628 | - return TimberURLHelper::get_rel_url( $url, $force ); |
|
627 | + static function get_rel_url($url, $force = false) { |
|
628 | + return TimberURLHelper::get_rel_url($url, $force); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | /** |
632 | 632 | * @deprecated 0.18.0 |
633 | 633 | */ |
634 | - static function is_local( $url ) { |
|
635 | - return TimberURLHelper::is_local( $url ); |
|
634 | + static function is_local($url) { |
|
635 | + return TimberURLHelper::is_local($url); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | /** |
639 | 639 | * @deprecated 0.18.0 |
640 | 640 | */ |
641 | - static function get_full_path( $src ) { |
|
642 | - return TimberURLHelper::get_full_path( $src ); |
|
641 | + static function get_full_path($src) { |
|
642 | + return TimberURLHelper::get_full_path($src); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
646 | 646 | * @deprecated 0.18.0 |
647 | 647 | */ |
648 | - static function get_rel_path( $src ) { |
|
649 | - return TimberURLHelper::get_rel_path( $src ); |
|
648 | + static function get_rel_path($src) { |
|
649 | + return TimberURLHelper::get_rel_path($src); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
653 | 653 | * @deprecated 0.18.0 |
654 | 654 | */ |
655 | - static function remove_double_slashes( $url ) { |
|
656 | - return TimberURLHelper::remove_double_slashes( $url ); |
|
655 | + static function remove_double_slashes($url) { |
|
656 | + return TimberURLHelper::remove_double_slashes($url); |
|
657 | 657 | } |
658 | 658 | |
659 | 659 | /** |
660 | 660 | * @deprecated 0.18.0 |
661 | 661 | */ |
662 | - static function prepend_to_url( $url, $path ) { |
|
663 | - return TimberURLHelper::prepend_to_url( $url, $path ); |
|
662 | + static function prepend_to_url($url, $path) { |
|
663 | + return TimberURLHelper::prepend_to_url($url, $path); |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | /** |
667 | 667 | * @deprecated 0.18.0 |
668 | 668 | */ |
669 | - static function preslashit( $path ) { |
|
670 | - return TimberURLHelper::preslashit( $path ); |
|
669 | + static function preslashit($path) { |
|
670 | + return TimberURLHelper::preslashit($path); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
674 | 674 | * @deprecated 0.18.0 |
675 | 675 | */ |
676 | - static function is_external( $url ) { |
|
677 | - return TimberURLHelper::is_external( $url ); |
|
676 | + static function is_external($url) { |
|
677 | + return TimberURLHelper::is_external($url); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
681 | 681 | * @deprecated 0.18.0 |
682 | 682 | */ |
683 | - static function download_url( $url, $timeout = 300 ) { |
|
684 | - return TimberURLHelper::download_url( $url, $timeout ); |
|
683 | + static function download_url($url, $timeout = 300) { |
|
684 | + return TimberURLHelper::download_url($url, $timeout); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | /** |
688 | 688 | * @deprecated 0.18.0 |
689 | 689 | */ |
690 | - static function get_params( $i = -1 ) { |
|
691 | - return TimberURLHelper::get_params( $i ); |
|
690 | + static function get_params($i = -1) { |
|
691 | + return TimberURLHelper::get_params($i); |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | } |