@@ -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,28 +512,28 @@ discard block |
||
| 512 | 512 | 'current' => 0, |
| 513 | 513 | 'show_all' => false, |
| 514 | 514 | 'prev_next' => false, |
| 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 | - for ( $n = 1; $n <= $args['total']; $n++ ) { |
|
| 536 | - $n_display = number_format_i18n( $n ); |
|
| 535 | + for ($n = 1; $n <= $args['total']; $n++) { |
|
| 536 | + $n_display = number_format_i18n($n); |
|
| 537 | 537 | if ( $n == $args['current'] ) { |
| 538 | 538 | $page_links[] = array( |
| 539 | 539 | 'class' => 'page-number page-numbers current', |
@@ -544,18 +544,18 @@ discard block |
||
| 544 | 544 | ); |
| 545 | 545 | $dots = true; |
| 546 | 546 | } else { |
| 547 | - 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'] ) ) { |
|
| 548 | - $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); |
|
| 549 | - $link = str_replace( '%#%', $n, $link ); |
|
| 550 | - $link = trailingslashit( $link ) . ltrim( $args['add_fragment'], '/' ); |
|
| 547 | + 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']) ) { |
|
| 548 | + $link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base']); |
|
| 549 | + $link = str_replace('%#%', $n, $link); |
|
| 550 | + $link = trailingslashit($link) . ltrim($args['add_fragment'], '/'); |
|
| 551 | 551 | if ( $args['add_args'] ) { |
| 552 | - $link = rtrim( add_query_arg( $args['add_args'], $link ), '/' ); |
|
| 552 | + $link = rtrim(add_query_arg($args['add_args'], $link), '/'); |
|
| 553 | 553 | } |
| 554 | 554 | $link = str_replace(' ', '+', $link); |
| 555 | - $link = untrailingslashit( $link ); |
|
| 555 | + $link = untrailingslashit($link); |
|
| 556 | 556 | $page_links[] = array( |
| 557 | 557 | 'class' => 'page-number page-numbers', |
| 558 | - 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), |
|
| 558 | + 'link' => esc_url(apply_filters('paginate_links', $link)), |
|
| 559 | 559 | 'title' => $n_display, |
| 560 | 560 | 'name' => $n_display, |
| 561 | 561 | 'current' => $args['current'] == $n |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | } elseif ( $dots && !$args['show_all'] ) { |
| 565 | 565 | $page_links[] = array( |
| 566 | 566 | 'class' => 'dots', |
| 567 | - 'title' => __( '…' ) |
|
| 567 | + 'title' => __('…') |
|
| 568 | 568 | ); |
| 569 | 569 | $dots = false; |
| 570 | 570 | } |
@@ -583,8 +583,8 @@ discard block |
||
| 583 | 583 | /** |
| 584 | 584 | * @deprecated 0.18.0 |
| 585 | 585 | */ |
| 586 | - static function is_url( $url ) { |
|
| 587 | - return TimberURLHelper::is_url( $url ); |
|
| 586 | + static function is_url($url) { |
|
| 587 | + return TimberURLHelper::is_url($url); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -597,71 +597,71 @@ discard block |
||
| 597 | 597 | /** |
| 598 | 598 | * @deprecated 0.18.0 |
| 599 | 599 | */ |
| 600 | - static function get_rel_url( $url, $force = false ) { |
|
| 601 | - return TimberURLHelper::get_rel_url( $url, $force ); |
|
| 600 | + static function get_rel_url($url, $force = false) { |
|
| 601 | + return TimberURLHelper::get_rel_url($url, $force); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
| 605 | 605 | * @deprecated 0.18.0 |
| 606 | 606 | */ |
| 607 | - static function is_local( $url ) { |
|
| 608 | - return TimberURLHelper::is_local( $url ); |
|
| 607 | + static function is_local($url) { |
|
| 608 | + return TimberURLHelper::is_local($url); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | /** |
| 612 | 612 | * @deprecated 0.18.0 |
| 613 | 613 | */ |
| 614 | - static function get_full_path( $src ) { |
|
| 615 | - return TimberURLHelper::get_full_path( $src ); |
|
| 614 | + static function get_full_path($src) { |
|
| 615 | + return TimberURLHelper::get_full_path($src); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
| 619 | 619 | * @deprecated 0.18.0 |
| 620 | 620 | */ |
| 621 | - static function get_rel_path( $src ) { |
|
| 622 | - return TimberURLHelper::get_rel_path( $src ); |
|
| 621 | + static function get_rel_path($src) { |
|
| 622 | + return TimberURLHelper::get_rel_path($src); |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
| 626 | 626 | * @deprecated 0.18.0 |
| 627 | 627 | */ |
| 628 | - static function remove_double_slashes( $url ) { |
|
| 629 | - return TimberURLHelper::remove_double_slashes( $url ); |
|
| 628 | + static function remove_double_slashes($url) { |
|
| 629 | + return TimberURLHelper::remove_double_slashes($url); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
| 633 | 633 | * @deprecated 0.18.0 |
| 634 | 634 | */ |
| 635 | - static function prepend_to_url( $url, $path ) { |
|
| 636 | - return TimberURLHelper::prepend_to_url( $url, $path ); |
|
| 635 | + static function prepend_to_url($url, $path) { |
|
| 636 | + return TimberURLHelper::prepend_to_url($url, $path); |
|
| 637 | 637 | } |
| 638 | 638 | |
| 639 | 639 | /** |
| 640 | 640 | * @deprecated 0.18.0 |
| 641 | 641 | */ |
| 642 | - static function preslashit( $path ) { |
|
| 643 | - return TimberURLHelper::preslashit( $path ); |
|
| 642 | + static function preslashit($path) { |
|
| 643 | + return TimberURLHelper::preslashit($path); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | /** |
| 647 | 647 | * @deprecated 0.18.0 |
| 648 | 648 | */ |
| 649 | - static function is_external( $url ) { |
|
| 650 | - return TimberURLHelper::is_external( $url ); |
|
| 649 | + static function is_external($url) { |
|
| 650 | + return TimberURLHelper::is_external($url); |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
| 654 | 654 | * @deprecated 0.18.0 |
| 655 | 655 | */ |
| 656 | - static function download_url( $url, $timeout = 300 ) { |
|
| 657 | - return TimberURLHelper::download_url( $url, $timeout ); |
|
| 656 | + static function download_url($url, $timeout = 300) { |
|
| 657 | + return TimberURLHelper::download_url($url, $timeout); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
| 661 | 661 | * @deprecated 0.18.0 |
| 662 | 662 | */ |
| 663 | - static function get_params( $i = -1 ) { |
|
| 664 | - return TimberURLHelper::get_params( $i ); |
|
| 663 | + static function get_params($i = -1) { |
|
| 664 | + return TimberURLHelper::get_params($i); |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | } |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | // we look for Composer files first in the plugins dir. |
| 15 | 15 | // then in the wp-content dir (site install). |
| 16 | 16 | // and finally in the current themes directories. |
| 17 | -if ( file_exists( $composer_autoload = __DIR__ . '/vendor/autoload.php' ) /* check in self */ |
|
| 18 | - || file_exists( $composer_autoload = WP_CONTENT_DIR.'/vendor/autoload.php') /* check in wp-content */ |
|
| 19 | - || file_exists( $composer_autoload = plugin_dir_path( __FILE__ ).'vendor/autoload.php') /* check in plugin directory */ |
|
| 20 | - || file_exists( $composer_autoload = get_stylesheet_directory().'/vendor/autoload.php') /* check in child theme */ |
|
| 21 | - || file_exists( $composer_autoload = get_template_directory().'/vendor/autoload.php') /* check in parent theme */ |
|
| 17 | +if ( file_exists($composer_autoload = __DIR__ . '/vendor/autoload.php') /* check in self */ |
|
| 18 | + || file_exists($composer_autoload = WP_CONTENT_DIR . '/vendor/autoload.php') /* check in wp-content */ |
|
| 19 | + || file_exists($composer_autoload = plugin_dir_path(__FILE__) . 'vendor/autoload.php') /* check in plugin directory */ |
|
| 20 | + || file_exists($composer_autoload = get_stylesheet_directory() . '/vendor/autoload.php') /* check in child theme */ |
|
| 21 | + || file_exists($composer_autoload = get_template_directory() . '/vendor/autoload.php') /* check in parent theme */ |
|
| 22 | 22 | ) { |
| 23 | 23 | require_once $composer_autoload; |
| 24 | 24 | } |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | if ( is_admin() || $_SERVER['PHP_SELF'] == '/wp-login.php' ) { |
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | - if ( version_compare( phpversion(), '5.3.0', '<' ) && !is_admin() ) { |
|
| 75 | - trigger_error( 'Timber requires PHP 5.3.0 or greater. You have '.phpversion(), E_USER_ERROR ); |
|
| 74 | + if ( version_compare(phpversion(), '5.3.0', '<') && !is_admin() ) { |
|
| 75 | + trigger_error('Timber requires PHP 5.3.0 or greater. You have ' . phpversion(), E_USER_ERROR); |
|
| 76 | 76 | } |
| 77 | - if ( !class_exists( 'Twig_Autoloader' ) ) { |
|
| 78 | - trigger_error( 'You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR ); |
|
| 77 | + if ( !class_exists('Twig_Autoloader') ) { |
|
| 78 | + trigger_error('You have not run "composer install" to download required dependencies for Timber, you can read more on https://github.com/jarednova/timber#installation', E_USER_ERROR); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | function init_constants() { |
| 83 | - defined( "TIMBER_LOC" ) or define( "TIMBER_LOC", realpath( __DIR__ ) ); |
|
| 83 | + defined("TIMBER_LOC") or define("TIMBER_LOC", realpath(__DIR__)); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | protected function init() { |
| 90 | 90 | TimberTwig::init(); |
| 91 | - TimberRoutes::init( $this ); |
|
| 91 | + TimberRoutes::init($this); |
|
| 92 | 92 | TimberImageHelper::init(); |
| 93 | 93 | TimberAdmin::init(); |
| 94 | 94 | TimberIntegrations::init(); |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * @param string $PostClass |
| 105 | 105 | * @return array|bool|null |
| 106 | 106 | */ |
| 107 | - public static function get_post( $query = false, $PostClass = 'TimberPost' ) { |
|
| 108 | - return TimberPostGetter::get_post( $query, $PostClass ); |
|
| 107 | + public static function get_post($query = false, $PostClass = 'TimberPost') { |
|
| 108 | + return TimberPostGetter::get_post($query, $PostClass); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | * @param string $PostClass |
| 116 | 116 | * @return array|bool|null |
| 117 | 117 | */ |
| 118 | - public static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
|
| 119 | - return TimberPostGetter::get_posts( $query, $PostClass, $return_collection ); |
|
| 118 | + public static function get_posts($query = false, $PostClass = 'TimberPost', $return_collection = false) { |
|
| 119 | + return TimberPostGetter::get_posts($query, $PostClass, $return_collection); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param string $PostClass |
| 127 | 127 | * @return array|bool|null |
| 128 | 128 | */ |
| 129 | - public static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
|
| 130 | - return TimberPostGetter::query_post( $query, $PostClass ); |
|
| 129 | + public static function query_post($query = false, $PostClass = 'TimberPost') { |
|
| 130 | + return TimberPostGetter::query_post($query, $PostClass); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | * @param string $PostClass |
| 138 | 138 | * @return array|bool|null |
| 139 | 139 | */ |
| 140 | - public static function query_posts( $query = false, $PostClass = 'TimberPost' ) { |
|
| 141 | - return TimberPostGetter::query_posts( $query, $PostClass ); |
|
| 140 | + public static function query_posts($query = false, $PostClass = 'TimberPost') { |
|
| 141 | + return TimberPostGetter::query_posts($query, $PostClass); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | * @return array |
| 149 | 149 | * @deprecated since 0.20.0 |
| 150 | 150 | */ |
| 151 | - static function get_pids( $query = null ) { |
|
| 152 | - return TimberPostGetter::get_pids( $query ); |
|
| 151 | + static function get_pids($query = null) { |
|
| 152 | + return TimberPostGetter::get_pids($query); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * @return array |
| 160 | 160 | * @deprecated since 0.20.0 |
| 161 | 161 | */ |
| 162 | - static function get_posts_from_loop( $PostClass ) { |
|
| 163 | - return TimberPostGetter::get_posts( $PostClass ); |
|
| 162 | + static function get_posts_from_loop($PostClass) { |
|
| 163 | + return TimberPostGetter::get_posts($PostClass); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | * @return array |
| 172 | 172 | * @deprecated since 0.20.0 |
| 173 | 173 | */ |
| 174 | - static function get_posts_from_slug( $slug, $PostClass = 'TimberPost' ) { |
|
| 175 | - return TimberPostGetter::get_posts( $slug, $PostClass ); |
|
| 174 | + static function get_posts_from_slug($slug, $PostClass = 'TimberPost') { |
|
| 175 | + return TimberPostGetter::get_posts($slug, $PostClass); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -183,8 +183,8 @@ discard block |
||
| 183 | 183 | * @return array |
| 184 | 184 | * @deprecated since 0.20.0 |
| 185 | 185 | */ |
| 186 | - static function get_posts_from_wp_query( $query = array(), $PostClass = 'TimberPost' ) { |
|
| 187 | - return TimberPostGetter::query_posts( $query, $PostClass ); |
|
| 186 | + static function get_posts_from_wp_query($query = array(), $PostClass = 'TimberPost') { |
|
| 187 | + return TimberPostGetter::query_posts($query, $PostClass); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * @return array|null |
| 196 | 196 | * @deprecated since 0.20.0 |
| 197 | 197 | */ |
| 198 | - static function get_posts_from_array_of_ids( $query = array(), $PostClass = 'TimberPost' ) { |
|
| 199 | - return TimberPostGetter::get_posts( $query, $PostClass ); |
|
| 198 | + static function get_posts_from_array_of_ids($query = array(), $PostClass = 'TimberPost') { |
|
| 199 | + return TimberPostGetter::get_posts($query, $PostClass); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @return int |
| 207 | 207 | * @deprecated since 0.20.0 |
| 208 | 208 | */ |
| 209 | - static function get_pid( $query ) { |
|
| 210 | - $pids = TimberPostGetter::get_pids( $query ); |
|
| 211 | - if ( is_array( $pids ) && count( $pids ) ) { |
|
| 209 | + static function get_pid($query) { |
|
| 210 | + $pids = TimberPostGetter::get_pids($query); |
|
| 211 | + if ( is_array($pids) && count($pids) ) { |
|
| 212 | 212 | return $pids[0]; |
| 213 | 213 | } |
| 214 | 214 | } |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * @param string $TermClass |
| 235 | 235 | * @return mixed |
| 236 | 236 | */ |
| 237 | - public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
|
| 238 | - return TimberTermGetter::get_terms( $args, $maybe_args, $TermClass ); |
|
| 237 | + public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
| 238 | + return TimberTermGetter::get_terms($args, $maybe_args, $TermClass); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /* Site Retrieval |
@@ -247,14 +247,14 @@ discard block |
||
| 247 | 247 | * @param array|bool $blog_ids |
| 248 | 248 | * @return array |
| 249 | 249 | */ |
| 250 | - public static function get_sites( $blog_ids = false ) { |
|
| 251 | - if ( !is_array( $blog_ids ) ) { |
|
| 250 | + public static function get_sites($blog_ids = false) { |
|
| 251 | + if ( !is_array($blog_ids) ) { |
|
| 252 | 252 | global $wpdb; |
| 253 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" ); |
|
| 253 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC"); |
|
| 254 | 254 | } |
| 255 | 255 | $return = array(); |
| 256 | - foreach ( $blog_ids as $blog_id ) { |
|
| 257 | - $return[] = new TimberSite( $blog_id ); |
|
| 256 | + foreach ($blog_ids as $blog_id) { |
|
| 257 | + $return[] = new TimberSite($blog_id); |
|
| 258 | 258 | } |
| 259 | 259 | return $return; |
| 260 | 260 | } |
@@ -272,29 +272,29 @@ discard block |
||
| 272 | 272 | $data = array(); |
| 273 | 273 | $data['http_host'] = 'http://' . TimberURLHelper::get_host(); |
| 274 | 274 | $data['wp_title'] = TimberHelper::get_wp_title(); |
| 275 | - $data['wp_head'] = TimberHelper::function_wrapper( 'wp_head' ); |
|
| 276 | - $data['wp_footer'] = TimberHelper::function_wrapper( 'wp_footer' ); |
|
| 277 | - $data['body_class'] = implode( ' ', get_body_class() ); |
|
| 275 | + $data['wp_head'] = TimberHelper::function_wrapper('wp_head'); |
|
| 276 | + $data['wp_footer'] = TimberHelper::function_wrapper('wp_footer'); |
|
| 277 | + $data['body_class'] = implode(' ', get_body_class()); |
|
| 278 | 278 | |
| 279 | 279 | $data['site'] = new TimberSite(); |
| 280 | 280 | $data['theme'] = $data['site']->theme; |
| 281 | 281 | //deprecated, these should be fetched via TimberSite or TimberTheme |
| 282 | - $data['theme_dir'] = WP_CONTENT_SUBDIR.str_replace( WP_CONTENT_DIR, '', get_stylesheet_directory() ); |
|
| 283 | - $data['language_attributes'] = TimberHelper::function_wrapper( 'language_attributes' ); |
|
| 282 | + $data['theme_dir'] = WP_CONTENT_SUBDIR . str_replace(WP_CONTENT_DIR, '', get_stylesheet_directory()); |
|
| 283 | + $data['language_attributes'] = TimberHelper::function_wrapper('language_attributes'); |
|
| 284 | 284 | $data['stylesheet_uri'] = get_stylesheet_uri(); |
| 285 | 285 | $data['template_uri'] = get_template_directory_uri(); |
| 286 | 286 | |
| 287 | 287 | $data['posts'] = Timber::query_posts(); |
| 288 | 288 | |
| 289 | 289 | //deprecated, this should be fetched via TimberMenu |
| 290 | - if ( function_exists( 'wp_nav_menu' ) ) { |
|
| 290 | + if ( function_exists('wp_nav_menu') ) { |
|
| 291 | 291 | $locations = get_nav_menu_locations(); |
| 292 | - if ( count( $locations ) ) { |
|
| 293 | - $data['wp_nav_menu'] = wp_nav_menu( array( 'container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu' ) ); |
|
| 292 | + if ( count($locations) ) { |
|
| 293 | + $data['wp_nav_menu'] = wp_nav_menu(array('container_class' => 'menu-header', 'echo' => false, 'menu_class' => 'nav-menu')); |
|
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | - $data = apply_filters( 'timber_context', $data ); |
|
| 297 | - $data = apply_filters( 'timber/context', $data ); |
|
| 296 | + $data = apply_filters('timber_context', $data); |
|
| 297 | + $data = apply_filters('timber/context', $data); |
|
| 298 | 298 | return $data; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -308,27 +308,27 @@ discard block |
||
| 308 | 308 | * @param bool $via_render |
| 309 | 309 | * @return bool|string |
| 310 | 310 | */ |
| 311 | - public static function compile( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false ) { |
|
| 311 | + public static function compile($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT, $via_render = false) { |
|
| 312 | 312 | $caller = self::get_calling_script_dir(); |
| 313 | 313 | $caller_file = self::get_calling_script_file(); |
| 314 | - $caller_file = apply_filters( 'timber_calling_php_file', $caller_file ); |
|
| 315 | - $loader = new TimberLoader( $caller ); |
|
| 316 | - $file = $loader->choose_template( $filenames ); |
|
| 314 | + $caller_file = apply_filters('timber_calling_php_file', $caller_file); |
|
| 315 | + $loader = new TimberLoader($caller); |
|
| 316 | + $file = $loader->choose_template($filenames); |
|
| 317 | 317 | $output = ''; |
| 318 | - if ( is_null( $data ) ) { |
|
| 318 | + if ( is_null($data) ) { |
|
| 319 | 319 | $data = array(); |
| 320 | 320 | } |
| 321 | - if ( strlen( $file ) ) { |
|
| 321 | + if ( strlen($file) ) { |
|
| 322 | 322 | if ( $via_render ) { |
| 323 | - $file = apply_filters( 'timber_render_file', $file ); |
|
| 324 | - $data = apply_filters( 'timber_render_data', $data ); |
|
| 323 | + $file = apply_filters('timber_render_file', $file); |
|
| 324 | + $data = apply_filters('timber_render_data', $data); |
|
| 325 | 325 | } else { |
| 326 | - $file = apply_filters( 'timber_compile_file', $file ); |
|
| 327 | - $data = apply_filters( 'timber_compile_data', $data ); |
|
| 326 | + $file = apply_filters('timber_compile_file', $file); |
|
| 327 | + $data = apply_filters('timber_compile_data', $data); |
|
| 328 | 328 | } |
| 329 | - $output = $loader->render( $file, $data, $expires, $cache_mode ); |
|
| 329 | + $output = $loader->render($file, $data, $expires, $cache_mode); |
|
| 330 | 330 | } |
| 331 | - do_action( 'timber_compile_done' ); |
|
| 331 | + do_action('timber_compile_done'); |
|
| 332 | 332 | return $output; |
| 333 | 333 | } |
| 334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
| 339 | 339 | * @param array $data an array with data in it. |
| 340 | 340 | * @return bool|string |
| 341 | 341 | */ |
| 342 | - public static function compile_string( $string, $data = array() ) { |
|
| 342 | + public static function compile_string($string, $data = array()) { |
|
| 343 | 343 | $dummy_loader = new TimberLoader(); |
| 344 | 344 | $dummy_loader->get_twig(); |
| 345 | 345 | $loader = new Twig_Loader_String(); |
| 346 | - $twig = new Twig_Environment( $loader ); |
|
| 347 | - $twig = apply_filters( 'timber/twig/filters', $twig ); |
|
| 348 | - $twig = apply_filters( 'twig_apply_filters', $twig ); |
|
| 349 | - return $twig->render( $string, $data ); |
|
| 346 | + $twig = new Twig_Environment($loader); |
|
| 347 | + $twig = apply_filters('timber/twig/filters', $twig); |
|
| 348 | + $twig = apply_filters('twig_apply_filters', $twig); |
|
| 349 | + return $twig->render($string, $data); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -358,15 +358,15 @@ discard block |
||
| 358 | 358 | * @param string $cache_mode |
| 359 | 359 | * @return bool|string |
| 360 | 360 | */ |
| 361 | - public static function fetch( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
| 361 | + public static function fetch($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
| 362 | 362 | if ( $expires === true ) { |
| 363 | 363 | //if this is reading as true; the user probably is using the old $echo param |
| 364 | 364 | //so we should move all vars up by a spot |
| 365 | 365 | $expires = $cache_mode; |
| 366 | 366 | $cache_mode = TimberLoader::CACHE_USE_DEFAULT; |
| 367 | 367 | } |
| 368 | - $output = self::compile( $filenames, $data, $expires, $cache_mode, true ); |
|
| 369 | - $output = apply_filters( 'timber_compile_result', $output ); |
|
| 368 | + $output = self::compile($filenames, $data, $expires, $cache_mode, true); |
|
| 369 | + $output = apply_filters('timber_compile_result', $output); |
|
| 370 | 370 | return $output; |
| 371 | 371 | } |
| 372 | 372 | |
@@ -379,8 +379,8 @@ discard block |
||
| 379 | 379 | * @param string $cache_mode |
| 380 | 380 | * @return bool|string |
| 381 | 381 | */ |
| 382 | - public static function render( $filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT ) { |
|
| 383 | - $output = static::fetch( $filenames, $data, $expires, $cache_mode ); |
|
| 382 | + public static function render($filenames, $data = array(), $expires = false, $cache_mode = TimberLoader::CACHE_USE_DEFAULT) { |
|
| 383 | + $output = static::fetch($filenames, $data, $expires, $cache_mode); |
|
| 384 | 384 | echo $output; |
| 385 | 385 | return $output; |
| 386 | 386 | } |
@@ -392,8 +392,8 @@ discard block |
||
| 392 | 392 | * @param array $data an array with data in it. |
| 393 | 393 | * @return bool|string |
| 394 | 394 | */ |
| 395 | - public static function render_string( $string, $data = array() ) { |
|
| 396 | - $compiled = self::compile_string( $string, $data ); |
|
| 395 | + public static function render_string($string, $data = array()) { |
|
| 396 | + $compiled = self::compile_string($string, $data); |
|
| 397 | 397 | echo $compiled; |
| 398 | 398 | return $compiled; |
| 399 | 399 | } |
@@ -409,14 +409,14 @@ discard block |
||
| 409 | 409 | * @param array $data |
| 410 | 410 | * @return bool|string |
| 411 | 411 | */ |
| 412 | - public static function get_sidebar( $sidebar = '', $data = array() ) { |
|
| 412 | + public static function get_sidebar($sidebar = '', $data = array()) { |
|
| 413 | 413 | if ( $sidebar == '' ) { |
| 414 | 414 | $sidebar = 'sidebar.php'; |
| 415 | 415 | } |
| 416 | - if ( strstr( strtolower( $sidebar ), '.php' ) ) { |
|
| 417 | - return self::get_sidebar_from_php( $sidebar, $data ); |
|
| 416 | + if ( strstr(strtolower($sidebar), '.php') ) { |
|
| 417 | + return self::get_sidebar_from_php($sidebar, $data); |
|
| 418 | 418 | } |
| 419 | - return self::compile( $sidebar, $data ); |
|
| 419 | + return self::compile($sidebar, $data); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -426,21 +426,21 @@ discard block |
||
| 426 | 426 | * @param array $data |
| 427 | 427 | * @return string |
| 428 | 428 | */ |
| 429 | - public static function get_sidebar_from_php( $sidebar = '', $data ) { |
|
| 429 | + public static function get_sidebar_from_php($sidebar = '', $data) { |
|
| 430 | 430 | $caller = self::get_calling_script_dir(); |
| 431 | 431 | $loader = new TimberLoader(); |
| 432 | - $uris = $loader->get_locations( $caller ); |
|
| 432 | + $uris = $loader->get_locations($caller); |
|
| 433 | 433 | ob_start(); |
| 434 | 434 | $found = false; |
| 435 | - foreach ( $uris as $uri ) { |
|
| 436 | - if ( file_exists( trailingslashit( $uri ) . $sidebar ) ) { |
|
| 437 | - include trailingslashit( $uri ) . $sidebar; |
|
| 435 | + foreach ($uris as $uri) { |
|
| 436 | + if ( file_exists(trailingslashit($uri) . $sidebar) ) { |
|
| 437 | + include trailingslashit($uri) . $sidebar; |
|
| 438 | 438 | $found = true; |
| 439 | 439 | break; |
| 440 | 440 | } |
| 441 | 441 | } |
| 442 | 442 | if ( !$found ) { |
| 443 | - TimberHelper::error_log( 'error loading your sidebar, check to make sure the file exists' ); |
|
| 443 | + TimberHelper::error_log('error loading your sidebar, check to make sure the file exists'); |
|
| 444 | 444 | } |
| 445 | 445 | $ret = ob_get_contents(); |
| 446 | 446 | ob_end_clean(); |
@@ -456,8 +456,8 @@ discard block |
||
| 456 | 456 | * @param int $widget_id |
| 457 | 457 | * @return TimberFunctionWrapper |
| 458 | 458 | */ |
| 459 | - public static function get_widgets( $widget_id ) { |
|
| 460 | - return TimberHelper::function_wrapper( 'dynamic_sidebar', array( $widget_id ), true ); |
|
| 459 | + public static function get_widgets($widget_id) { |
|
| 460 | + return TimberHelper::function_wrapper('dynamic_sidebar', array($widget_id), true); |
|
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | |
@@ -472,15 +472,15 @@ discard block |
||
| 472 | 472 | * @param array $args |
| 473 | 473 | * @deprecated since 0.20.0 |
| 474 | 474 | */ |
| 475 | - public static function add_route( $route, $callback, $args = array() ) { |
|
| 476 | - Routes::map( $route, $callback, $args ); |
|
| 475 | + public static function add_route($route, $callback, $args = array()) { |
|
| 476 | + Routes::map($route, $callback, $args); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
| 480 | 480 | * @deprecated since 0.22.2 |
| 481 | 481 | */ |
| 482 | 482 | public function cancel_query() { |
| 483 | - add_action( 'posts_request', array( $this, 'cancel_query_posts_request' ) ); |
|
| 483 | + add_action('posts_request', array($this, 'cancel_query_posts_request')); |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
@@ -497,8 +497,8 @@ discard block |
||
| 497 | 497 | * |
| 498 | 498 | * @deprecated since 0.20.0 |
| 499 | 499 | */ |
| 500 | - public static function load_template( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
| 501 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
| 500 | + public static function load_template($template, $query = false, $status_code = 200, $tparams = false) { |
|
| 501 | + return Routes::load($template, $tparams, $query, $status_code); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | /** |
@@ -506,8 +506,8 @@ discard block |
||
| 506 | 506 | * |
| 507 | 507 | * @deprecated since 0.20.2 |
| 508 | 508 | */ |
| 509 | - public static function load_view( $template, $query = false, $status_code = 200, $tparams = false ) { |
|
| 510 | - return Routes::load( $template, $tparams, $query, $status_code ); |
|
| 509 | + public static function load_view($template, $query = false, $status_code = 200, $tparams = false) { |
|
| 510 | + return Routes::load($template, $tparams, $query, $status_code); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | |
@@ -520,43 +520,43 @@ discard block |
||
| 520 | 520 | * @param array $prefs |
| 521 | 521 | * @return array mixed |
| 522 | 522 | */ |
| 523 | - public static function get_pagination( $prefs = array() ) { |
|
| 523 | + public static function get_pagination($prefs = array()) { |
|
| 524 | 524 | global $wp_query; |
| 525 | 525 | global $paged; |
| 526 | 526 | global $wp_rewrite; |
| 527 | 527 | $args = array(); |
| 528 | - $args['total'] = ceil( $wp_query->found_posts / $wp_query->query_vars['posts_per_page'] ); |
|
| 528 | + $args['total'] = ceil($wp_query->found_posts / $wp_query->query_vars['posts_per_page']); |
|
| 529 | 529 | if ( $wp_rewrite->using_permalinks() ) { |
| 530 | - $url = explode( '?', get_pagenum_link( 0 ) ); |
|
| 531 | - if ( isset( $url[1] ) ) { |
|
| 532 | - parse_str( $url[1], $query ); |
|
| 530 | + $url = explode('?', get_pagenum_link(0)); |
|
| 531 | + if ( isset($url[1]) ) { |
|
| 532 | + parse_str($url[1], $query); |
|
| 533 | 533 | $args['add_args'] = $query; |
| 534 | 534 | } |
| 535 | 535 | $args['format'] = 'page/%#%'; |
| 536 | - $args['base'] = trailingslashit( $url[0] ).'%_%'; |
|
| 536 | + $args['base'] = trailingslashit($url[0]) . '%_%'; |
|
| 537 | 537 | } else { |
| 538 | 538 | $big = 999999999; |
| 539 | - $args['base'] = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ); |
|
| 539 | + $args['base'] = str_replace($big, '%#%', esc_url(get_pagenum_link($big))); |
|
| 540 | 540 | } |
| 541 | 541 | $args['type'] = 'array'; |
| 542 | - $args['current'] = max( 1, get_query_var( 'paged' ) ); |
|
| 543 | - $args['mid_size'] = max( 9 - $args['current'], 3 ); |
|
| 544 | - if ( is_int( $prefs ) ) { |
|
| 542 | + $args['current'] = max(1, get_query_var('paged')); |
|
| 543 | + $args['mid_size'] = max(9 - $args['current'], 3); |
|
| 544 | + if ( is_int($prefs) ) { |
|
| 545 | 545 | $args['mid_size'] = $prefs - 2; |
| 546 | 546 | } else { |
| 547 | - $args = array_merge( $args, $prefs ); |
|
| 547 | + $args = array_merge($args, $prefs); |
|
| 548 | 548 | } |
| 549 | 549 | $data = array(); |
| 550 | 550 | $data['current'] = $args['current']; |
| 551 | 551 | $data['total'] = $args['total']; |
| 552 | - $data['pages'] = TimberHelper::paginate_links( $args ); |
|
| 553 | - $next = get_next_posts_page_link( $args['total'] ); |
|
| 552 | + $data['pages'] = TimberHelper::paginate_links($args); |
|
| 553 | + $next = get_next_posts_page_link($args['total']); |
|
| 554 | 554 | if ( $next ) { |
| 555 | - $data['next'] = array( 'link' => untrailingslashit( $next ), 'class' => 'page-numbers next' ); |
|
| 555 | + $data['next'] = array('link' => untrailingslashit($next), 'class' => 'page-numbers next'); |
|
| 556 | 556 | } |
| 557 | - $prev = previous_posts( false ); |
|
| 557 | + $prev = previous_posts(false); |
|
| 558 | 558 | if ( $prev ) { |
| 559 | - $data['prev'] = array( 'link' => untrailingslashit( $prev ), 'class' => 'page-numbers prev' ); |
|
| 559 | + $data['prev'] = array('link' => untrailingslashit($prev), 'class' => 'page-numbers prev'); |
|
| 560 | 560 | } |
| 561 | 561 | if ( $paged < 2 ) { |
| 562 | 562 | $data['prev'] = ''; |
@@ -574,9 +574,9 @@ discard block |
||
| 574 | 574 | * @return string |
| 575 | 575 | * @deprecated since 0.20.0 |
| 576 | 576 | */ |
| 577 | - public static function get_calling_script_path( $offset = 0 ) { |
|
| 578 | - $dir = self::get_calling_script_dir( $offset ); |
|
| 579 | - return str_replace( ABSPATH, '', realpath( $dir ) ); |
|
| 577 | + public static function get_calling_script_path($offset = 0) { |
|
| 578 | + $dir = self::get_calling_script_dir($offset); |
|
| 579 | + return str_replace(ABSPATH, '', realpath($dir)); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -584,10 +584,10 @@ discard block |
||
| 584 | 584 | * |
| 585 | 585 | * @return string |
| 586 | 586 | */ |
| 587 | - public static function get_calling_script_dir( $offset = 0 ) { |
|
| 588 | - $caller = self::get_calling_script_file( $offset ); |
|
| 589 | - if ( !is_null( $caller ) ) { |
|
| 590 | - $pathinfo = pathinfo( $caller ); |
|
| 587 | + public static function get_calling_script_dir($offset = 0) { |
|
| 588 | + $caller = self::get_calling_script_file($offset); |
|
| 589 | + if ( !is_null($caller) ) { |
|
| 590 | + $pathinfo = pathinfo($caller); |
|
| 591 | 591 | $dir = $pathinfo['dirname']; |
| 592 | 592 | return $dir; |
| 593 | 593 | } |
@@ -600,11 +600,11 @@ discard block |
||
| 600 | 600 | * @return string|null |
| 601 | 601 | * @deprecated since 0.20.0 |
| 602 | 602 | */ |
| 603 | - public static function get_calling_script_file( $offset = 0 ) { |
|
| 603 | + public static function get_calling_script_file($offset = 0) { |
|
| 604 | 604 | $caller = null; |
| 605 | 605 | $backtrace = debug_backtrace(); |
| 606 | 606 | $i = 0; |
| 607 | - foreach ( $backtrace as $trace ) { |
|
| 607 | + foreach ($backtrace as $trace) { |
|
| 608 | 608 | if ( $trace['file'] != __FILE__ ) { |
| 609 | 609 | $caller = $trace['file']; |
| 610 | 610 | break; |
@@ -624,8 +624,8 @@ discard block |
||
| 624 | 624 | * @return bool |
| 625 | 625 | * @deprecated since 0.20.0 |
| 626 | 626 | */ |
| 627 | - public static function is_post_class_or_class_map( $args ) { |
|
| 628 | - return TimberPostGetter::is_post_class_or_class_map( $args ); |
|
| 627 | + public static function is_post_class_or_class_map($args) { |
|
| 628 | + return TimberPostGetter::is_post_class_or_class_map($args); |
|
| 629 | 629 | } |
| 630 | 630 | |
| 631 | 631 | } |