@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @param int $cid |
42 | 42 | */ |
43 | - function __construct($cid) { |
|
43 | + function __construct( $cid ) { |
|
44 | 44 | $this->init($cid); |
45 | 45 | } |
46 | 46 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @internal |
53 | 53 | * @param integer $cid |
54 | 54 | */ |
55 | - function init($cid) { |
|
55 | + function init( $cid ) { |
|
56 | 56 | $comment_data = $cid; |
57 | - if (is_integer($cid)) { |
|
57 | + if ( is_integer($cid) ) { |
|
58 | 58 | $comment_data = get_comment($cid); |
59 | 59 | } |
60 | 60 | $this->import($comment_data); |
@@ -86,11 +86,11 @@ discard block |
||
86 | 86 | * @return TimberUser |
87 | 87 | */ |
88 | 88 | public function author() { |
89 | - if ($this->user_id) { |
|
89 | + if ( $this->user_id ) { |
|
90 | 90 | return new TimberUser($this->user_id); |
91 | 91 | } else { |
92 | 92 | $author = new TimberUser(0); |
93 | - if (isset($this->comment_author) && $this->comment_author) { |
|
93 | + if ( isset($this->comment_author) && $this->comment_author ) { |
|
94 | 94 | $author->name = $this->comment_author; |
95 | 95 | } else { |
96 | 96 | $author->name = 'Anonymous'; |
@@ -113,22 +113,22 @@ discard block |
||
113 | 113 | * @param string $default |
114 | 114 | * @return bool|mixed|string |
115 | 115 | */ |
116 | - public function avatar($size = 92, $default = '') { |
|
117 | - if (!get_option('show_avatars')) { |
|
116 | + public function avatar( $size = 92, $default = '' ) { |
|
117 | + if ( !get_option('show_avatars') ) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | - if (!is_numeric($size)) { |
|
120 | + if ( !is_numeric($size) ) { |
|
121 | 121 | $size = '92'; |
122 | 122 | } |
123 | 123 | |
124 | 124 | $email = $this->avatar_email(); |
125 | 125 | $email_hash = ''; |
126 | - if (!empty($email)) { |
|
126 | + if ( !empty($email) ) { |
|
127 | 127 | $email_hash = md5(strtolower(trim($email))); |
128 | 128 | } |
129 | 129 | $host = $this->avatar_host($email_hash); |
130 | 130 | $default = $this->avatar_default($default, $email, $size, $host); |
131 | - if (!empty($email)) { |
|
131 | + if ( !empty($email) ) { |
|
132 | 132 | $avatar = $this->avatar_out($default, $host, $email_hash, $size); |
133 | 133 | } else { |
134 | 134 | $avatar = $default; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function date( $date_format = '' ) { |
183 | 183 | $df = $date_format ? $date_format : get_option('date_format'); |
184 | - $the_date = (string)mysql2date($df, $this->comment_date); |
|
184 | + $the_date = (string) mysql2date($df, $this->comment_date); |
|
185 | 185 | return apply_filters('get_comment_date ', $the_date, $df); |
186 | 186 | } |
187 | 187 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function time( $time_format = '' ) { |
208 | 208 | $tf = $time_format ? $time_format : get_option('time_format'); |
209 | - $the_time = (string)mysql2date($tf, $this->comment_date); |
|
209 | + $the_time = (string) mysql2date($tf, $this->comment_date); |
|
210 | 210 | return apply_filters('get_comment_time', $the_time, $tf); |
211 | 211 | } |
212 | 212 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | * @param string $field_name |
215 | 215 | * @return mixed |
216 | 216 | */ |
217 | - public function meta($field_name) { |
|
217 | + public function meta( $field_name ) { |
|
218 | 218 | return $this->get_meta_field($field_name); |
219 | 219 | } |
220 | 220 | |
@@ -231,15 +231,15 @@ discard block |
||
231 | 231 | * @param int $comment_id |
232 | 232 | * @return mixed |
233 | 233 | */ |
234 | - protected function get_meta_fields($comment_id = null) { |
|
235 | - if ($comment_id === null) { |
|
234 | + protected function get_meta_fields( $comment_id = null ) { |
|
235 | + if ( $comment_id === null ) { |
|
236 | 236 | $comment_id = $this->ID; |
237 | 237 | } |
238 | 238 | //Could not find a WP function to fetch all comment meta data, so I made one. |
239 | 239 | apply_filters('timber_comment_get_meta_pre', array(), $comment_id); |
240 | 240 | $comment_metas = get_comment_meta($comment_id); |
241 | - foreach ($comment_metas as &$cm) { |
|
242 | - if (is_array($cm) && count($cm) == 1) { |
|
241 | + foreach ( $comment_metas as &$cm ) { |
|
242 | + if ( is_array($cm) && count($cm) == 1 ) { |
|
243 | 243 | $cm = $cm[0]; |
244 | 244 | } |
245 | 245 | } |
@@ -252,9 +252,9 @@ discard block |
||
252 | 252 | * @param string $field_name |
253 | 253 | * @return mixed |
254 | 254 | */ |
255 | - protected function get_meta_field($field_name) { |
|
255 | + protected function get_meta_field( $field_name ) { |
|
256 | 256 | $value = apply_filters('timber_comment_get_meta_field_pre', null, $this->ID, $field_name, $this); |
257 | - if ($value === null) { |
|
257 | + if ( $value === null ) { |
|
258 | 258 | $value = get_comment_meta($this->ID, $field_name, true); |
259 | 259 | } |
260 | 260 | $value = apply_filters('timber_comment_get_meta_field', $value, $this->ID, $field_name, $this); |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function reply_link( $reply_text = 'Reply' ) { |
271 | 271 | if ( is_singular() && comments_open() && get_option('thread_comments') ) { |
272 | - wp_enqueue_script( 'comment-reply' ); |
|
272 | + wp_enqueue_script('comment-reply'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | // Get the comments depth option from the admin panel |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | 'max_depth' => $max_depth, |
285 | 285 | ); |
286 | 286 | |
287 | - return get_comment_reply_link( $args, $this->ID, $this->post_id ); |
|
287 | + return get_comment_reply_link($args, $this->ID, $this->post_id); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /* AVATAR Stuff |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | * @return string |
296 | 296 | */ |
297 | 297 | protected function avatar_email() { |
298 | - $id = (int)$this->user_id; |
|
298 | + $id = (int) $this->user_id; |
|
299 | 299 | $user = get_userdata($id); |
300 | - if ($user) { |
|
300 | + if ( $user ) { |
|
301 | 301 | $email = $user->user_email; |
302 | 302 | } else { |
303 | 303 | $email = $this->comment_author_email; |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | * @param string $email_hash |
311 | 311 | * @return string |
312 | 312 | */ |
313 | - protected function avatar_host($email_hash) { |
|
314 | - if (is_ssl()) { |
|
313 | + protected function avatar_host( $email_hash ) { |
|
314 | + if ( is_ssl() ) { |
|
315 | 315 | $host = 'https://secure.gravatar.com'; |
316 | 316 | } else { |
317 | - if (!empty($email_hash)) { |
|
317 | + if ( !empty($email_hash) ) { |
|
318 | 318 | $host = sprintf("http://%d.gravatar.com", (hexdec($email_hash[0]) % 2)); |
319 | 319 | } else { |
320 | 320 | $host = 'http://0.gravatar.com'; |
@@ -332,29 +332,29 @@ discard block |
||
332 | 332 | * @param string $host |
333 | 333 | * @return string |
334 | 334 | */ |
335 | - protected function avatar_default($default, $email, $size, $host) { |
|
336 | - if (substr($default, 0, 1) == '/') { |
|
335 | + protected function avatar_default( $default, $email, $size, $host ) { |
|
336 | + if ( substr($default, 0, 1) == '/' ) { |
|
337 | 337 | $default = home_url() . $default; |
338 | 338 | } |
339 | 339 | |
340 | - if (empty($default)) { |
|
340 | + if ( empty($default) ) { |
|
341 | 341 | $avatar_default = get_option('avatar_default'); |
342 | - if (empty($avatar_default)) { |
|
342 | + if ( empty($avatar_default) ) { |
|
343 | 343 | $default = 'mystery'; |
344 | 344 | } else { |
345 | 345 | $default = $avatar_default; |
346 | 346 | } |
347 | 347 | } |
348 | - if ('mystery' == $default) { |
|
348 | + if ( 'mystery' == $default ) { |
|
349 | 349 | $default = $host . '/avatar/ad516503a11cd5ca435acc9bb6523536?s=' . $size; |
350 | 350 | // ad516503a11cd5ca435acc9bb6523536 == md5('[email protected]') |
351 | - } else if ('blank' == $default) { |
|
351 | + } else if ( 'blank' == $default ) { |
|
352 | 352 | $default = $email ? 'blank' : includes_url('images/blank.gif'); |
353 | - } else if (!empty($email) && 'gravatar_default' == $default) { |
|
353 | + } else if ( !empty($email) && 'gravatar_default' == $default ) { |
|
354 | 354 | $default = ''; |
355 | - } else if ('gravatar_default' == $default) { |
|
355 | + } else if ( 'gravatar_default' == $default ) { |
|
356 | 356 | $default = $host . '/avatar/?s=' . $size; |
357 | - } else if (empty($email) && !strstr($default, 'http://')) { |
|
357 | + } else if ( empty($email) && !strstr($default, 'http://') ) { |
|
358 | 358 | $default = $host . '/avatar/?d=' . $default . '&s=' . $size; |
359 | 359 | } |
360 | 360 | return $default; |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | * @param string $size |
369 | 369 | * @return mixed |
370 | 370 | */ |
371 | - protected function avatar_out($default, $host, $email_hash, $size) { |
|
371 | + protected function avatar_out( $default, $host, $email_hash, $size ) { |
|
372 | 372 | $out = $host . '/avatar/' . $email_hash . '?s=' . $size . '&d=' . urlencode($default); |
373 | 373 | $rating = get_option('avatar_rating'); |
374 | - if (!empty($rating)) { |
|
374 | + if ( !empty($rating) ) { |
|
375 | 375 | $out .= '&r=' . $rating; |
376 | 376 | } |
377 | 377 | return str_replace('&', '&', esc_url($out)); |
@@ -75,18 +75,18 @@ discard block |
||
75 | 75 | /** |
76 | 76 | * @param int|string $slug |
77 | 77 | */ |
78 | - function __construct($slug = 0) { |
|
78 | + function __construct( $slug = 0 ) { |
|
79 | 79 | $locations = get_nav_menu_locations(); |
80 | - if ($slug != 0 && is_numeric($slug)) { |
|
80 | + if ( $slug != 0 && is_numeric($slug) ) { |
|
81 | 81 | $menu_id = $slug; |
82 | - } else if (is_array($locations) && count($locations)) { |
|
82 | + } else if ( is_array($locations) && count($locations) ) { |
|
83 | 83 | $menu_id = $this->get_menu_id_from_locations($slug, $locations); |
84 | - } else if ($slug === false) { |
|
84 | + } else if ( $slug === false ) { |
|
85 | 85 | $menu_id = false; |
86 | 86 | } else { |
87 | 87 | $menu_id = $this->get_menu_id_from_terms($slug); |
88 | 88 | } |
89 | - if ($menu_id) { |
|
89 | + if ( $menu_id ) { |
|
90 | 90 | $this->init($menu_id); |
91 | 91 | } else { |
92 | 92 | $this->init_as_page_menu(); |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | * @internal |
98 | 98 | * @param int $menu_id |
99 | 99 | */ |
100 | - protected function init($menu_id) { |
|
100 | + protected function init( $menu_id ) { |
|
101 | 101 | $menu = wp_get_nav_menu_items($menu_id); |
102 | - if ($menu) { |
|
102 | + if ( $menu ) { |
|
103 | 103 | _wp_menu_item_classes_by_context($menu); |
104 | - if (is_array($menu)){ |
|
104 | + if ( is_array($menu) ) { |
|
105 | 105 | $menu = self::order_children($menu); |
106 | 106 | } |
107 | 107 | $this->items = $menu; |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | */ |
119 | 119 | protected function init_as_page_menu() { |
120 | 120 | $menu = get_pages(); |
121 | - if ($menu) { |
|
122 | - foreach($menu as $mi) { |
|
121 | + if ( $menu ) { |
|
122 | + foreach ( $menu as $mi ) { |
|
123 | 123 | $mi->__title = $mi->post_title; |
124 | 124 | } |
125 | 125 | _wp_menu_item_classes_by_context($menu); |
126 | - if (is_array($menu)){ |
|
126 | + if ( is_array($menu) ) { |
|
127 | 127 | $menu = self::order_children($menu); |
128 | 128 | } |
129 | 129 | $this->items = $menu; |
@@ -136,14 +136,14 @@ discard block |
||
136 | 136 | * @param array $locations |
137 | 137 | * @return integer |
138 | 138 | */ |
139 | - protected function get_menu_id_from_locations($slug, $locations) { |
|
140 | - if ($slug === 0) { |
|
139 | + protected function get_menu_id_from_locations( $slug, $locations ) { |
|
140 | + if ( $slug === 0 ) { |
|
141 | 141 | $slug = $this->get_menu_id_from_terms($slug); |
142 | 142 | } |
143 | - if (is_numeric($slug)) { |
|
143 | + if ( is_numeric($slug) ) { |
|
144 | 144 | $slug = array_search($slug, $locations); |
145 | 145 | } |
146 | - if (isset($locations[$slug])) { |
|
146 | + if ( isset($locations[$slug]) ) { |
|
147 | 147 | $menu_id = $locations[$slug]; |
148 | 148 | return $menu_id; |
149 | 149 | } |
@@ -154,21 +154,21 @@ discard block |
||
154 | 154 | * @param int $slug |
155 | 155 | * @return int |
156 | 156 | */ |
157 | - protected function get_menu_id_from_terms($slug = 0) { |
|
158 | - if (!is_numeric($slug) && is_string($slug)) { |
|
157 | + protected function get_menu_id_from_terms( $slug = 0 ) { |
|
158 | + if ( !is_numeric($slug) && is_string($slug) ) { |
|
159 | 159 | //we have a string so lets search for that |
160 | 160 | $menu_id = get_term_by('slug', $slug, 'nav_menu'); |
161 | - if ($menu_id) { |
|
161 | + if ( $menu_id ) { |
|
162 | 162 | return $menu_id; |
163 | 163 | } |
164 | 164 | $menu_id = get_term_by('name', $slug, 'nav_menu'); |
165 | - if ($menu_id) { |
|
165 | + if ( $menu_id ) { |
|
166 | 166 | return $menu_id; |
167 | 167 | } |
168 | 168 | } |
169 | 169 | $menus = get_terms('nav_menu', array('hide_empty' => true)); |
170 | - if (is_array($menus) && count($menus)) { |
|
171 | - if (isset($menus[0]->term_id)) { |
|
170 | + if ( is_array($menus) && count($menus) ) { |
|
171 | + if ( isset($menus[0]->term_id) ) { |
|
172 | 172 | return $menus[0]->term_id; |
173 | 173 | } |
174 | 174 | } |
@@ -180,9 +180,9 @@ discard block |
||
180 | 180 | * @param int $parent_id |
181 | 181 | * @return TimberMenuItem|null |
182 | 182 | */ |
183 | - function find_parent_item_in_menu($menu_items, $parent_id) { |
|
184 | - foreach ($menu_items as &$item) { |
|
185 | - if ($item->ID == $parent_id) { |
|
183 | + function find_parent_item_in_menu( $menu_items, $parent_id ) { |
|
184 | + foreach ( $menu_items as &$item ) { |
|
185 | + if ( $item->ID == $parent_id ) { |
|
186 | 186 | return $item; |
187 | 187 | } |
188 | 188 | } |
@@ -193,29 +193,29 @@ discard block |
||
193 | 193 | * @param array $items |
194 | 194 | * @return array |
195 | 195 | */ |
196 | - protected function order_children($items) { |
|
196 | + protected function order_children( $items ) { |
|
197 | 197 | $index = array(); |
198 | 198 | $menu = array(); |
199 | - foreach ($items as $item) { |
|
200 | - if (isset($item->title)) { |
|
199 | + foreach ( $items as $item ) { |
|
200 | + if ( isset($item->title) ) { |
|
201 | 201 | //items from wp can come with a $title property which conflicts with methods |
202 | 202 | $item->__title = $item->title; |
203 | 203 | unset($item->title); |
204 | 204 | } |
205 | - if(isset($item->ID)){ |
|
206 | - if (is_object($item) && get_class($item) == 'WP_Post'){ |
|
205 | + if ( isset($item->ID) ) { |
|
206 | + if ( is_object($item) && get_class($item) == 'WP_Post' ) { |
|
207 | 207 | $old_menu_item = $item; |
208 | 208 | $item = new $this->PostClass($item); |
209 | 209 | } |
210 | 210 | $menu_item = new $this->MenuItemClass($item); |
211 | - if (isset($old_menu_item)){ |
|
211 | + if ( isset($old_menu_item) ) { |
|
212 | 212 | $menu_item->import_classes($old_menu_item); |
213 | 213 | } |
214 | 214 | $index[$item->ID] = $menu_item; |
215 | 215 | } |
216 | 216 | } |
217 | - foreach ($index as $item) { |
|
218 | - if (isset($item->menu_item_parent) && $item->menu_item_parent && isset($index[$item->menu_item_parent])) { |
|
217 | + foreach ( $index as $item ) { |
|
218 | + if ( isset($item->menu_item_parent) && $item->menu_item_parent && isset($index[$item->menu_item_parent]) ) { |
|
219 | 219 | $index[$item->menu_item_parent]->add_child($item); |
220 | 220 | } else { |
221 | 221 | $menu[] = $item; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @return array |
229 | 229 | */ |
230 | 230 | function get_items() { |
231 | - if (is_array($this->items)) { |
|
231 | + if ( is_array($this->items) ) { |
|
232 | 232 | return $this->items; |
233 | 233 | } |
234 | 234 | return array(); |
@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | * @return mixed |
27 | 27 | */ |
28 | 28 | public static function transient( $slug, $callback, $transient_time = 0, $lock_timeout = 5, $force = false ) { |
29 | - $slug = apply_filters( 'timber/transient/slug', $slug ); |
|
29 | + $slug = apply_filters('timber/transient/slug', $slug); |
|
30 | 30 | |
31 | - $enable_transients = ( $transient_time === false || ( defined( 'WP_DISABLE_TRANSIENTS' ) && WP_DISABLE_TRANSIENTS ) ) ? false : true; |
|
32 | - $data = $enable_transients ? get_transient( $slug ) : false; |
|
31 | + $enable_transients = ($transient_time === false || (defined('WP_DISABLE_TRANSIENTS') && WP_DISABLE_TRANSIENTS)) ? false : true; |
|
32 | + $data = $enable_transients ? get_transient($slug) : false; |
|
33 | 33 | |
34 | 34 | if ( false === $data ) { |
35 | 35 | |
36 | - if ( $enable_transients && self::_is_transient_locked( $slug ) ) { |
|
36 | + if ( $enable_transients && self::_is_transient_locked($slug) ) { |
|
37 | 37 | |
38 | - $force = apply_filters( 'timber_force_transients', $force ); |
|
39 | - $force = apply_filters( 'timber_force_transient_' . $slug, $force ); |
|
38 | + $force = apply_filters('timber_force_transients', $force); |
|
39 | + $force = apply_filters('timber_force_transient_' . $slug, $force); |
|
40 | 40 | |
41 | 41 | if ( !$force ) { |
42 | 42 | //the server is currently executing the process. |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | // lock timeout shouldn't be higher than 5 seconds, unless |
51 | 51 | // remote calls with high timeouts are made here |
52 | 52 | if ( $enable_transients ) |
53 | - self::_lock_transient( $slug, $lock_timeout ); |
|
53 | + self::_lock_transient($slug, $lock_timeout); |
|
54 | 54 | |
55 | 55 | $data = $callback(); |
56 | 56 | |
57 | 57 | if ( $enable_transients ) { |
58 | - set_transient( $slug, $data, $transient_time ); |
|
59 | - self::_unlock_transient( $slug ); |
|
58 | + set_transient($slug, $data, $transient_time); |
|
59 | + self::_unlock_transient($slug); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param integer $lock_timeout |
72 | 72 | */ |
73 | 73 | static function _lock_transient( $slug, $lock_timeout ) { |
74 | - set_transient( $slug . '_lock', true, $lock_timeout ); |
|
74 | + set_transient($slug . '_lock', true, $lock_timeout); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $slug |
80 | 80 | */ |
81 | 81 | static function _unlock_transient( $slug ) { |
82 | - delete_transient( $slug . '_lock', true ); |
|
82 | + delete_transient($slug . '_lock', true); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param string $slug |
88 | 88 | */ |
89 | 89 | static function _is_transient_locked( $slug ) { |
90 | - return (bool)get_transient( $slug . '_lock' ); |
|
90 | + return (bool) get_transient($slug . '_lock'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /* These are for measuring page render time */ |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public static function start_timer() { |
101 | 101 | $time = microtime(); |
102 | - $time = explode( ' ', $time ); |
|
102 | + $time = explode(' ', $time); |
|
103 | 103 | $time = $time[1] + $time[0]; |
104 | 104 | return $time; |
105 | 105 | } |
@@ -117,10 +117,10 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public static function stop_timer( $start ) { |
119 | 119 | $time = microtime(); |
120 | - $time = explode( ' ', $time ); |
|
120 | + $time = explode(' ', $time); |
|
121 | 121 | $time = $time[1] + $time[0]; |
122 | 122 | $finish = $time; |
123 | - $total_time = round( ( $finish - $start ), 4 ); |
|
123 | + $total_time = round(($finish - $start), 4); |
|
124 | 124 | return $total_time . ' seconds.'; |
125 | 125 | } |
126 | 126 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | * @param array $args |
154 | 154 | * @return string |
155 | 155 | */ |
156 | - public static function ob_function( $function, $args = array( null ) ) { |
|
156 | + public static function ob_function( $function, $args = array(null) ) { |
|
157 | 157 | ob_start(); |
158 | - call_user_func_array( $function, $args ); |
|
158 | + call_user_func_array($function, $args); |
|
159 | 159 | $data = ob_get_contents(); |
160 | 160 | ob_end_clean(); |
161 | 161 | return $data; |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | * @return TimberFunctionWrapper |
171 | 171 | */ |
172 | 172 | public static function function_wrapper( $function_name, $defaults = array(), $return_output_buffer = false ) { |
173 | - return new TimberFunctionWrapper( $function_name, $defaults, $return_output_buffer ); |
|
173 | + return new TimberFunctionWrapper($function_name, $defaults, $return_output_buffer); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | if ( !WP_DEBUG ) { |
184 | 184 | return; |
185 | 185 | } |
186 | - if ( is_object( $arg ) || is_array( $arg ) ) { |
|
187 | - $arg = print_r( $arg, true ); |
|
186 | + if ( is_object($arg) || is_array($arg) ) { |
|
187 | + $arg = print_r($arg, true); |
|
188 | 188 | } |
189 | - return error_log( $arg ); |
|
189 | + return error_log($arg); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @return string |
198 | 198 | */ |
199 | 199 | public static function get_wp_title( $separator = ' ', $seplocation = 'left' ) { |
200 | - $separator = apply_filters( 'timber_wp_title_seperator', $separator ); |
|
201 | - return trim( wp_title( $separator, false, $seplocation ) ); |
|
200 | + $separator = apply_filters('timber_wp_title_seperator', $separator); |
|
201 | + return trim(wp_title($separator, false, $seplocation)); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /* Text Utilities |
@@ -215,33 +215,33 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public static function trim_words( $text, $num_words = 55, $more = null, $allowed_tags = 'p a span b i br blockquote' ) { |
217 | 217 | if ( null === $more ) { |
218 | - $more = __( '…' ); |
|
218 | + $more = __('…'); |
|
219 | 219 | } |
220 | 220 | $original_text = $text; |
221 | 221 | $allowed_tag_string = ''; |
222 | - foreach ( explode( ' ', apply_filters( 'timber/trim_words/allowed_tags', $allowed_tags ) ) as $tag ) { |
|
222 | + foreach ( explode(' ', apply_filters('timber/trim_words/allowed_tags', $allowed_tags)) as $tag ) { |
|
223 | 223 | $allowed_tag_string .= '<' . $tag . '>'; |
224 | 224 | } |
225 | - $text = strip_tags( $text, $allowed_tag_string ); |
|
225 | + $text = strip_tags($text, $allowed_tag_string); |
|
226 | 226 | /* 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. */ |
227 | - if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) { |
|
228 | - $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); |
|
229 | - preg_match_all( '/./u', $text, $words_array ); |
|
230 | - $words_array = array_slice( $words_array[0], 0, $num_words + 1 ); |
|
227 | + if ( 'characters' == _x('words', 'word count: words or characters?') && preg_match('/^utf\-?8$/i', get_option('blog_charset')) ) { |
|
228 | + $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' '); |
|
229 | + preg_match_all('/./u', $text, $words_array); |
|
230 | + $words_array = array_slice($words_array[0], 0, $num_words + 1); |
|
231 | 231 | $sep = ''; |
232 | 232 | } else { |
233 | - $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY ); |
|
233 | + $words_array = preg_split("/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY); |
|
234 | 234 | $sep = ' '; |
235 | 235 | } |
236 | - if ( count( $words_array ) > $num_words ) { |
|
237 | - array_pop( $words_array ); |
|
238 | - $text = implode( $sep, $words_array ); |
|
236 | + if ( count($words_array) > $num_words ) { |
|
237 | + array_pop($words_array); |
|
238 | + $text = implode($sep, $words_array); |
|
239 | 239 | $text = $text . $more; |
240 | 240 | } else { |
241 | - $text = implode( $sep, $words_array ); |
|
241 | + $text = implode($sep, $words_array); |
|
242 | 242 | } |
243 | - $text = self::close_tags( $text ); |
|
244 | - return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text ); |
|
243 | + $text = self::close_tags($text); |
|
244 | + return apply_filters('wp_trim_words', $text, $num_words, $more, $original_text); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -252,27 +252,27 @@ discard block |
||
252 | 252 | */ |
253 | 253 | public static function close_tags( $html ) { |
254 | 254 | //put all opened tags into an array |
255 | - preg_match_all( '#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result ); |
|
255 | + preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result); |
|
256 | 256 | $openedtags = $result[1]; |
257 | 257 | //put all closed tags into an array |
258 | - preg_match_all( '#</([a-z]+)>#iU', $html, $result ); |
|
258 | + preg_match_all('#</([a-z]+)>#iU', $html, $result); |
|
259 | 259 | $closedtags = $result[1]; |
260 | - $len_opened = count( $openedtags ); |
|
260 | + $len_opened = count($openedtags); |
|
261 | 261 | // all tags are closed |
262 | - if ( count( $closedtags ) == $len_opened ) { |
|
262 | + if ( count($closedtags) == $len_opened ) { |
|
263 | 263 | return $html; |
264 | 264 | } |
265 | - $openedtags = array_reverse( $openedtags ); |
|
265 | + $openedtags = array_reverse($openedtags); |
|
266 | 266 | // close tags |
267 | 267 | for ( $i = 0; $i < $len_opened; $i++ ) { |
268 | - if ( !in_array( $openedtags[$i], $closedtags ) ) { |
|
268 | + if ( !in_array($openedtags[$i], $closedtags) ) { |
|
269 | 269 | $html .= '</' . $openedtags[$i] . '>'; |
270 | 270 | } else { |
271 | - unset( $closedtags[array_search( $openedtags[$i], $closedtags )] ); |
|
271 | + unset($closedtags[array_search($openedtags[$i], $closedtags)]); |
|
272 | 272 | } |
273 | 273 | } |
274 | - $html = str_replace(array('</br>','</hr>','</wbr>'), '', $html); |
|
275 | - $html = str_replace(array('<br>','<hr>','<wbr>'), array('<br />','<hr />','<wbr />'), $html); |
|
274 | + $html = str_replace(array('</br>', '</hr>', '</wbr>'), '', $html); |
|
275 | + $html = str_replace(array('<br>', '<hr>', '<wbr>'), array('<br />', '<hr />', '<wbr />'), $html); |
|
276 | 276 | return $html; |
277 | 277 | } |
278 | 278 | |
@@ -287,15 +287,15 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public static function get_posts_by_meta( $key, $value ) { |
289 | 289 | global $wpdb; |
290 | - $query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value ); |
|
291 | - $results = $wpdb->get_col( $query ); |
|
290 | + $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $key, $value); |
|
291 | + $results = $wpdb->get_col($query); |
|
292 | 292 | $pids = array(); |
293 | 293 | foreach ( $results as $result ) { |
294 | - if ( get_post( $result ) ) { |
|
294 | + if ( get_post($result) ) { |
|
295 | 295 | $pids[] = $result; |
296 | 296 | } |
297 | 297 | } |
298 | - if ( count( $pids ) ) { |
|
298 | + if ( count($pids) ) { |
|
299 | 299 | return $pids; |
300 | 300 | } |
301 | 301 | return 0; |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | */ |
312 | 312 | public static function get_post_by_meta( $key, $value ) { |
313 | 313 | global $wpdb; |
314 | - $query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ORDER BY post_id", $key, $value ); |
|
315 | - $results = $wpdb->get_col( $query ); |
|
314 | + $query = $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s ORDER BY post_id", $key, $value); |
|
315 | + $results = $wpdb->get_col($query); |
|
316 | 316 | foreach ( $results as $result ) { |
317 | - if ( $result && get_post( $result ) ) { |
|
317 | + if ( $result && get_post($result) ) { |
|
318 | 318 | return $result; |
319 | 319 | } |
320 | 320 | } |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | */ |
330 | 330 | public static function get_term_id_by_term_taxonomy_id( $ttid ) { |
331 | 331 | global $wpdb; |
332 | - $query = $wpdb->prepare( "SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %s", $ttid ); |
|
333 | - return $wpdb->get_var( $query ); |
|
332 | + $query = $wpdb->prepare("SELECT term_id FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %s", $ttid); |
|
333 | + return $wpdb->get_var($query); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /* Object Utilities |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @return void |
345 | 345 | */ |
346 | 346 | public static function osort( &$array, $prop ) { |
347 | - usort( $array, function ( $a, $b ) use ( $prop ) { |
|
347 | + usort($array, function( $a, $b ) use ($prop) { |
|
348 | 348 | return $a->$prop > $b->$prop ? 1 : -1; |
349 | 349 | } ); |
350 | 350 | } |
@@ -356,10 +356,10 @@ discard block |
||
356 | 356 | * @return bool |
357 | 357 | */ |
358 | 358 | public static function is_array_assoc( $arr ) { |
359 | - if ( !is_array( $arr ) ) { |
|
359 | + if ( !is_array($arr) ) { |
|
360 | 360 | return false; |
361 | 361 | } |
362 | - return (bool)count( array_filter( array_keys( $arr ), 'is_string' ) ); |
|
362 | + return (bool) count(array_filter(array_keys($arr), 'is_string')); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | public static function array_to_object( $array ) { |
372 | 372 | $obj = new stdClass; |
373 | 373 | foreach ( $array as $k => $v ) { |
374 | - if ( is_array( $v ) ) { |
|
375 | - $obj->{$k} = self::array_to_object( $v ); //RECURSION |
|
374 | + if ( is_array($v) ) { |
|
375 | + $obj->{$k} = self::array_to_object($v); //RECURSION |
|
376 | 376 | } else { |
377 | 377 | $obj->{$k} = $v; |
378 | 378 | } |
@@ -389,10 +389,10 @@ discard block |
||
389 | 389 | * @return bool|int |
390 | 390 | */ |
391 | 391 | public static function get_object_index_by_property( $array, $key, $value ) { |
392 | - if ( is_array( $array ) ) { |
|
392 | + if ( is_array($array) ) { |
|
393 | 393 | $i = 0; |
394 | 394 | foreach ( $array as $arr ) { |
395 | - if ( is_array( $arr ) ) { |
|
395 | + if ( is_array($arr) ) { |
|
396 | 396 | if ( $arr[$key] == $value ) { |
397 | 397 | return $i; |
398 | 398 | } |
@@ -417,15 +417,15 @@ discard block |
||
417 | 417 | * @throws Exception |
418 | 418 | */ |
419 | 419 | public static function get_object_by_property( $array, $key, $value ) { |
420 | - if ( is_array( $array ) ) { |
|
420 | + if ( is_array($array) ) { |
|
421 | 421 | foreach ( $array as $arr ) { |
422 | 422 | if ( $arr->$key == $value ) { |
423 | 423 | return $arr; |
424 | 424 | } |
425 | 425 | } |
426 | 426 | } else { |
427 | - throw new InvalidArgumentException( '$array is not an array, got:' ); |
|
428 | - TimberHelper::error_log( $array ); |
|
427 | + throw new InvalidArgumentException('$array is not an array, got:'); |
|
428 | + TimberHelper::error_log($array); |
|
429 | 429 | } |
430 | 430 | } |
431 | 431 | |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | * @return array |
438 | 438 | */ |
439 | 439 | public static function array_truncate( $array, $len ) { |
440 | - if ( sizeof( $array ) > $len ) { |
|
441 | - $array = array_splice( $array, 0, $len ); |
|
440 | + if ( sizeof($array) > $len ) { |
|
441 | + $array = array_splice($array, 0, $len); |
|
442 | 442 | } |
443 | 443 | return $array; |
444 | 444 | } |
@@ -453,11 +453,11 @@ discard block |
||
453 | 453 | * @return bool |
454 | 454 | */ |
455 | 455 | public static function is_true( $value ) { |
456 | - if ( isset( $value ) ) { |
|
457 | - if (is_string($value)) { |
|
456 | + if ( isset($value) ) { |
|
457 | + if ( is_string($value) ) { |
|
458 | 458 | $value = strtolower($value); |
459 | 459 | } |
460 | - if ( ($value == 'true' || $value === 1 || $value === '1' || $value == true) && $value !== false && $value !== 'false') { |
|
460 | + if ( ($value == 'true' || $value === 1 || $value === '1' || $value == true) && $value !== false && $value !== 'false' ) { |
|
461 | 461 | return true; |
462 | 462 | } |
463 | 463 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @return bool |
472 | 472 | */ |
473 | 473 | public static function iseven( $i ) { |
474 | - return ( $i % 2 ) == 0; |
|
474 | + return ($i % 2) == 0; |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @return bool |
482 | 482 | */ |
483 | 483 | public static function isodd( $i ) { |
484 | - return ( $i % 2 ) != 0; |
|
484 | + return ($i % 2) != 0; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /* Links, Forms, Etc. Utilities |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | * @return string |
497 | 497 | */ |
498 | 498 | public static function get_comment_form( $post_id = null, $args = array() ) { |
499 | - return self::ob_function( 'comment_form', array( $args, $post_id ) ); |
|
499 | + return self::ob_function('comment_form', array($args, $post_id)); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | /** |
@@ -513,28 +513,28 @@ discard block |
||
513 | 513 | 'current' => 0, |
514 | 514 | 'show_all' => false, |
515 | 515 | 'prev_next' => false, |
516 | - 'prev_text' => __( '« Previous' ), |
|
517 | - 'next_text' => __( 'Next »' ), |
|
516 | + 'prev_text' => __('« Previous'), |
|
517 | + 'next_text' => __('Next »'), |
|
518 | 518 | 'end_size' => 1, |
519 | 519 | 'mid_size' => 2, |
520 | 520 | 'type' => 'array', |
521 | 521 | 'add_args' => false, // array of query args to add |
522 | 522 | 'add_fragment' => '' |
523 | 523 | ); |
524 | - $args = wp_parse_args( $args, $defaults ); |
|
524 | + $args = wp_parse_args($args, $defaults); |
|
525 | 525 | // Who knows what else people pass in $args |
526 | - $args['total'] = intval( (int)$args['total'] ); |
|
526 | + $args['total'] = intval((int) $args['total']); |
|
527 | 527 | if ( $args['total'] < 2 ) { |
528 | 528 | return array(); |
529 | 529 | } |
530 | - $args['current'] = (int)$args['current']; |
|
531 | - $args['end_size'] = 0 < (int)$args['end_size'] ? (int)$args['end_size'] : 1; // Out of bounds? Make it the default. |
|
532 | - $args['mid_size'] = 0 <= (int)$args['mid_size'] ? (int)$args['mid_size'] : 2; |
|
533 | - $args['add_args'] = is_array( $args['add_args'] ) ? $args['add_args'] : false; |
|
530 | + $args['current'] = (int) $args['current']; |
|
531 | + $args['end_size'] = 0 < (int) $args['end_size'] ? (int) $args['end_size'] : 1; // Out of bounds? Make it the default. |
|
532 | + $args['mid_size'] = 0 <= (int) $args['mid_size'] ? (int) $args['mid_size'] : 2; |
|
533 | + $args['add_args'] = is_array($args['add_args']) ? $args['add_args'] : false; |
|
534 | 534 | $page_links = array(); |
535 | 535 | $dots = false; |
536 | 536 | for ( $n = 1; $n <= $args['total']; $n++ ) { |
537 | - $n_display = number_format_i18n( $n ); |
|
537 | + $n_display = number_format_i18n($n); |
|
538 | 538 | if ( $n == $args['current'] ) { |
539 | 539 | $page_links[] = array( |
540 | 540 | 'class' => 'page-number page-numbers current', |
@@ -545,18 +545,18 @@ discard block |
||
545 | 545 | ); |
546 | 546 | $dots = true; |
547 | 547 | } else { |
548 | - 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'] ) ) { |
|
549 | - $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); |
|
550 | - $link = str_replace( '%#%', $n, $link ); |
|
551 | - $link = trailingslashit( $link ) . ltrim( $args['add_fragment'], '/' ); |
|
548 | + 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']) ) { |
|
549 | + $link = str_replace('%_%', 1 == $n ? '' : $args['format'], $args['base']); |
|
550 | + $link = str_replace('%#%', $n, $link); |
|
551 | + $link = trailingslashit($link) . ltrim($args['add_fragment'], '/'); |
|
552 | 552 | if ( $args['add_args'] ) { |
553 | - $link = rtrim( add_query_arg( $args['add_args'], $link ), '/' ); |
|
553 | + $link = rtrim(add_query_arg($args['add_args'], $link), '/'); |
|
554 | 554 | } |
555 | 555 | $link = str_replace(' ', '+', $link); |
556 | - $link = untrailingslashit( $link ); |
|
556 | + $link = untrailingslashit($link); |
|
557 | 557 | $page_links[] = array( |
558 | 558 | 'class' => 'page-number page-numbers', |
559 | - 'link' => esc_url( apply_filters( 'paginate_links', $link ) ), |
|
559 | + 'link' => esc_url(apply_filters('paginate_links', $link)), |
|
560 | 560 | 'title' => $n_display, |
561 | 561 | 'name' => $n_display, |
562 | 562 | 'current' => $args['current'] == $n |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | } elseif ( $dots && !$args['show_all'] ) { |
566 | 566 | $page_links[] = array( |
567 | 567 | 'class' => 'dots', |
568 | - 'title' => __( '…' ) |
|
568 | + 'title' => __('…') |
|
569 | 569 | ); |
570 | 570 | $dots = false; |
571 | 571 | } |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | * @deprecated 0.18.0 |
586 | 586 | */ |
587 | 587 | static function is_url( $url ) { |
588 | - return TimberURLHelper::is_url( $url ); |
|
588 | + return TimberURLHelper::is_url($url); |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | /** |
@@ -599,70 +599,70 @@ discard block |
||
599 | 599 | * @deprecated 0.18.0 |
600 | 600 | */ |
601 | 601 | static function get_rel_url( $url, $force = false ) { |
602 | - return TimberURLHelper::get_rel_url( $url, $force ); |
|
602 | + return TimberURLHelper::get_rel_url($url, $force); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
606 | 606 | * @deprecated 0.18.0 |
607 | 607 | */ |
608 | 608 | static function is_local( $url ) { |
609 | - return TimberURLHelper::is_local( $url ); |
|
609 | + return TimberURLHelper::is_local($url); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
613 | 613 | * @deprecated 0.18.0 |
614 | 614 | */ |
615 | 615 | static function get_full_path( $src ) { |
616 | - return TimberURLHelper::get_full_path( $src ); |
|
616 | + return TimberURLHelper::get_full_path($src); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
620 | 620 | * @deprecated 0.18.0 |
621 | 621 | */ |
622 | 622 | static function get_rel_path( $src ) { |
623 | - return TimberURLHelper::get_rel_path( $src ); |
|
623 | + return TimberURLHelper::get_rel_path($src); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
627 | 627 | * @deprecated 0.18.0 |
628 | 628 | */ |
629 | 629 | static function remove_double_slashes( $url ) { |
630 | - return TimberURLHelper::remove_double_slashes( $url ); |
|
630 | + return TimberURLHelper::remove_double_slashes($url); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
634 | 634 | * @deprecated 0.18.0 |
635 | 635 | */ |
636 | 636 | static function prepend_to_url( $url, $path ) { |
637 | - return TimberURLHelper::prepend_to_url( $url, $path ); |
|
637 | + return TimberURLHelper::prepend_to_url($url, $path); |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | /** |
641 | 641 | * @deprecated 0.18.0 |
642 | 642 | */ |
643 | 643 | static function preslashit( $path ) { |
644 | - return TimberURLHelper::preslashit( $path ); |
|
644 | + return TimberURLHelper::preslashit($path); |
|
645 | 645 | } |
646 | 646 | |
647 | 647 | /** |
648 | 648 | * @deprecated 0.18.0 |
649 | 649 | */ |
650 | 650 | static function is_external( $url ) { |
651 | - return TimberURLHelper::is_external( $url ); |
|
651 | + return TimberURLHelper::is_external($url); |
|
652 | 652 | } |
653 | 653 | |
654 | 654 | /** |
655 | 655 | * @deprecated 0.18.0 |
656 | 656 | */ |
657 | 657 | static function download_url( $url, $timeout = 300 ) { |
658 | - return TimberURLHelper::download_url( $url, $timeout ); |
|
658 | + return TimberURLHelper::download_url($url, $timeout); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
662 | 662 | * @deprecated 0.18.0 |
663 | 663 | */ |
664 | 664 | static function get_params( $i = -1 ) { |
665 | - return TimberURLHelper::get_params( $i ); |
|
665 | + return TimberURLHelper::get_params($i); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | } |
@@ -7,20 +7,20 @@ discard block |
||
7 | 7 | * @param string $PostClass |
8 | 8 | * @return array|bool|null |
9 | 9 | */ |
10 | - static function get_post($query = false, $PostClass = 'TimberPost') { |
|
11 | - $posts = self::get_posts( $query, $PostClass ); |
|
12 | - if ( $post = reset($posts ) ) { |
|
10 | + static function get_post( $query = false, $PostClass = 'TimberPost' ) { |
|
11 | + $posts = self::get_posts($query, $PostClass); |
|
12 | + if ( $post = reset($posts) ) { |
|
13 | 13 | return $post; |
14 | 14 | } |
15 | 15 | } |
16 | 16 | |
17 | 17 | static function get_posts( $query = false, $PostClass = 'TimberPost', $return_collection = false ) { |
18 | - $posts = self::query_posts( $query, $PostClass ); |
|
19 | - return apply_filters('timber_post_getter_get_posts', $posts->get_posts( $return_collection )); |
|
18 | + $posts = self::query_posts($query, $PostClass); |
|
19 | + return apply_filters('timber_post_getter_get_posts', $posts->get_posts($return_collection)); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | static function query_post( $query = false, $PostClass = 'TimberPost' ) { |
23 | - $posts = self::query_posts( $query, $PostClass ); |
|
23 | + $posts = self::query_posts($query, $PostClass); |
|
24 | 24 | if ( method_exists($posts, 'current') && $post = $posts->current() ) { |
25 | 25 | return $post; |
26 | 26 | } |
@@ -31,32 +31,32 @@ discard block |
||
31 | 31 | * @param string $PostClass |
32 | 32 | * @return array|bool|null |
33 | 33 | */ |
34 | - static function query_posts($query = false, $PostClass = 'TimberPost' ) { |
|
35 | - if (self::is_post_class_or_class_map($query)) { |
|
34 | + static function query_posts( $query = false, $PostClass = 'TimberPost' ) { |
|
35 | + if ( self::is_post_class_or_class_map($query) ) { |
|
36 | 36 | $PostClass = $query; |
37 | 37 | $query = false; |
38 | 38 | } |
39 | 39 | |
40 | - if (is_object($query) && !is_a($query, 'WP_Query') ){ |
|
40 | + if ( is_object($query) && !is_a($query, 'WP_Query') ) { |
|
41 | 41 | // The only object other than a query is a type of post object |
42 | - $query = array( $query ); |
|
42 | + $query = array($query); |
|
43 | 43 | } |
44 | 44 | |
45 | - if ( is_array( $query ) && count( $query ) && isset( $query[0] ) && is_object( $query[0] ) ) { |
|
45 | + if ( is_array($query) && count($query) && isset($query[0]) && is_object($query[0]) ) { |
|
46 | 46 | // We have an array of post objects that already have data |
47 | - return new TimberPostsCollection( $query, $PostClass ); |
|
47 | + return new TimberPostsCollection($query, $PostClass); |
|
48 | 48 | } else { |
49 | 49 | // We have a query (of sorts) to work with |
50 | - $tqi = new TimberQueryIterator( $query, $PostClass ); |
|
50 | + $tqi = new TimberQueryIterator($query, $PostClass); |
|
51 | 51 | return $tqi; |
52 | 52 | } |
53 | 53 | } |
54 | 54 | |
55 | - static function get_pids($query){ |
|
55 | + static function get_pids( $query ) { |
|
56 | 56 | $posts = self::get_posts($query); |
57 | 57 | $pids = array(); |
58 | - foreach($posts as $post){ |
|
59 | - if (isset($post->ID)){ |
|
58 | + foreach ( $posts as $post ) { |
|
59 | + if ( isset($post->ID) ) { |
|
60 | 60 | $pids[] = $post->ID; |
61 | 61 | } |
62 | 62 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | static function loop_to_id() { |
67 | - if (!self::wp_query_has_posts()) { return false; } |
|
67 | + if ( !self::wp_query_has_posts() ) { return false; } |
|
68 | 68 | |
69 | 69 | global $wp_query; |
70 | 70 | $post_num = property_exists($wp_query, 'current_post') |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | : 0 |
73 | 73 | ; |
74 | 74 | |
75 | - if (!isset($wp_query->posts[$post_num])) { return false; } |
|
75 | + if ( !isset($wp_query->posts[$post_num]) ) { return false; } |
|
76 | 76 | |
77 | 77 | return $wp_query->posts[$post_num]->ID; |
78 | 78 | } |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | * @param string|array $arg |
90 | 90 | * @return bool |
91 | 91 | */ |
92 | - static function is_post_class_or_class_map($arg){ |
|
93 | - if (is_string($arg) && class_exists($arg)) { |
|
92 | + static function is_post_class_or_class_map( $arg ) { |
|
93 | + if ( is_string($arg) && class_exists($arg) ) { |
|
94 | 94 | return true; |
95 | 95 | } |
96 | - if (is_array($arg)) { |
|
97 | - foreach ($arg as $item) { |
|
98 | - if (is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost'))) { |
|
96 | + if ( is_array($arg) ) { |
|
97 | + foreach ( $arg as $item ) { |
|
98 | + if ( is_string($item) && (class_exists($item) && is_subclass_of($item, 'TimberPost')) ) { |
|
99 | 99 | return true; |
100 | 100 | } |
101 | 101 | } |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | * ``` |
162 | 162 | * @param mixed $pid |
163 | 163 | */ |
164 | - public function __construct($pid = null) { |
|
165 | - $pid = $this->determine_id( $pid ); |
|
164 | + public function __construct( $pid = null ) { |
|
165 | + $pid = $this->determine_id($pid); |
|
166 | 166 | $this->init($pid); |
167 | 167 | } |
168 | 168 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param mixed a value to test against |
173 | 173 | * @return int the numberic id we should be using for this post object |
174 | 174 | */ |
175 | - protected function determine_id($pid) { |
|
175 | + protected function determine_id( $pid ) { |
|
176 | 176 | global $wp_query; |
177 | 177 | if ( $pid === null && |
178 | 178 | isset($wp_query->queried_object_id) |
@@ -181,18 +181,18 @@ discard block |
||
181 | 181 | && is_object($wp_query->queried_object) |
182 | 182 | && get_class($wp_query->queried_object) == 'WP_Post' |
183 | 183 | ) { |
184 | - if( isset( $_GET['preview'] ) && isset( $_GET['preview_nonce'] ) && wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id ) ) { |
|
185 | - $pid = $this->get_post_preview_id( $wp_query ); |
|
184 | + if ( isset($_GET['preview']) && isset($_GET['preview_nonce']) && wp_verify_nonce($_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id) ) { |
|
185 | + $pid = $this->get_post_preview_id($wp_query); |
|
186 | 186 | } else if ( !$pid ) { |
187 | 187 | $pid = $wp_query->queried_object_id; |
188 | 188 | } |
189 | - } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
189 | + } else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id ) { |
|
190 | 190 | //hack for static page as home page |
191 | 191 | $pid = $wp_query->queried_object_id; |
192 | 192 | } else if ( $pid === null ) { |
193 | 193 | $gtid = false; |
194 | 194 | $maybe_post = get_post(); |
195 | - if ( isset($maybe_post->ID) ){ |
|
195 | + if ( isset($maybe_post->ID) ) { |
|
196 | 196 | $gtid = true; |
197 | 197 | } |
198 | 198 | if ( $gtid ) { |
@@ -230,19 +230,19 @@ discard block |
||
230 | 230 | |
231 | 231 | $can_preview = array(); |
232 | 232 | |
233 | - foreach( $can as $type ) { |
|
234 | - if( current_user_can( $type ) ) { |
|
233 | + foreach ( $can as $type ) { |
|
234 | + if ( current_user_can($type) ) { |
|
235 | 235 | $can_preview[] = true; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - if ( count( $can_preview ) !== count( $can ) ) { |
|
239 | + if ( count($can_preview) !== count($can) ) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
243 | - $revisions = wp_get_post_revisions( $query->queried_object_id ); |
|
243 | + $revisions = wp_get_post_revisions($query->queried_object_id); |
|
244 | 244 | |
245 | - if( !empty( $revisions ) ) { |
|
245 | + if ( !empty($revisions) ) { |
|
246 | 246 | $last = end($revisions); |
247 | 247 | return $last->ID; |
248 | 248 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @internal |
256 | 256 | * @param int|bool $pid |
257 | 257 | */ |
258 | - protected function init($pid = false) { |
|
258 | + protected function init( $pid = false ) { |
|
259 | 259 | if ( $pid === false ) { |
260 | 260 | $pid = get_the_ID(); |
261 | 261 | } |
@@ -342,11 +342,11 @@ discard block |
||
342 | 342 | * @param string $post_name |
343 | 343 | * @return int |
344 | 344 | */ |
345 | - static function get_post_id_by_name($post_name) { |
|
345 | + static function get_post_id_by_name( $post_name ) { |
|
346 | 346 | global $wpdb; |
347 | 347 | $query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name); |
348 | 348 | $result = $wpdb->get_row($query); |
349 | - if (!$result) { |
|
349 | + if ( !$result ) { |
|
350 | 350 | return null; |
351 | 351 | } |
352 | 352 | return $result->ID; |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @param string $end The text to end the preview with (defaults to ...) |
369 | 369 | * @return string of the post preview |
370 | 370 | */ |
371 | - function get_preview($len = 50, $force = false, $readmore = 'Read More', $strip = true, $end = '…') { |
|
371 | + function get_preview( $len = 50, $force = false, $readmore = 'Read More', $strip = true, $end = '…' ) { |
|
372 | 372 | $text = ''; |
373 | 373 | $trimmed = false; |
374 | 374 | if ( isset($this->post_excerpt) && strlen($this->post_excerpt) ) { |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | $text = TimberHelper::trim_words($text, $len, false); |
387 | 387 | $trimmed = true; |
388 | 388 | } |
389 | - $text = do_shortcode( $text ); |
|
389 | + $text = do_shortcode($text); |
|
390 | 390 | } |
391 | 391 | if ( !strlen($text) ) { |
392 | 392 | $text = TimberHelper::trim_words($this->get_content(), $len, false); |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | } |
417 | 417 | $read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more"); |
418 | 418 | if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) { |
419 | - $text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>'; |
|
419 | + $text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>'; |
|
420 | 420 | } elseif ( $readmore ) { |
421 | - $text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>'; |
|
421 | + $text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>'; |
|
422 | 422 | } |
423 | - if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) { |
|
423 | + if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) { |
|
424 | 424 | $text .= '</p>'; |
425 | 425 | } |
426 | 426 | } |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | * @param int $i |
565 | 565 | * @return string |
566 | 566 | */ |
567 | - protected static function get_wp_link_page($i) { |
|
567 | + protected static function get_wp_link_page( $i ) { |
|
568 | 568 | $link = _wp_link_page($i); |
569 | 569 | $link = new SimpleXMLElement($link . '</a>'); |
570 | 570 | if ( isset($link['href']) ) { |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | * @param int $pid |
648 | 648 | * @return null|object|WP_Post |
649 | 649 | */ |
650 | - protected function get_info($pid) { |
|
650 | + protected function get_info( $pid ) { |
|
651 | 651 | $post = $this->prepare_post_info($pid); |
652 | 652 | if ( !isset($post->post_status) ) { |
653 | 653 | return null; |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | $post->slug = $post->post_name; |
658 | 658 | $customs = $this->get_post_custom($post->ID); |
659 | 659 | $post->custom = $customs; |
660 | - $post = (object) array_merge((array)$customs, (array)$post); |
|
660 | + $post = (object) array_merge((array) $customs, (array) $post); |
|
661 | 661 | return $post; |
662 | 662 | } |
663 | 663 | |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | */ |
670 | 670 | function get_date( $date_format = '' ) { |
671 | 671 | $df = $date_format ? $date_format : get_option('date_format'); |
672 | - $the_date = (string)mysql2date($df, $this->post_date); |
|
672 | + $the_date = (string) mysql2date($df, $this->post_date); |
|
673 | 673 | return apply_filters('get_the_date', $the_date, $df); |
674 | 674 | } |
675 | 675 | |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @return array|mixed |
731 | 731 | */ |
732 | 732 | |
733 | - function get_comments($ct = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') { |
|
733 | + function get_comments( $ct = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) { |
|
734 | 734 | |
735 | 735 | global $overridden_cpage, $user_ID; |
736 | 736 | $overridden_cpage = false; |
@@ -747,42 +747,42 @@ discard block |
||
747 | 747 | } |
748 | 748 | |
749 | 749 | if ( $user_ID ) { |
750 | - $args['include_unapproved'] = array( $user_ID ); |
|
751 | - } elseif ( ! empty( $comment_author_email ) ) { |
|
752 | - $args['include_unapproved'] = array( $comment_author_email ); |
|
750 | + $args['include_unapproved'] = array($user_ID); |
|
751 | + } elseif ( !empty($comment_author_email) ) { |
|
752 | + $args['include_unapproved'] = array($comment_author_email); |
|
753 | 753 | } |
754 | 754 | |
755 | 755 | $comments = get_comments($args); |
756 | 756 | $timber_comments = array(); |
757 | 757 | |
758 | 758 | if ( '' == get_query_var('cpage') && get_option('page_comments') ) { |
759 | - set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 ); |
|
759 | + set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1); |
|
760 | 760 | $overridden_cpage = true; |
761 | 761 | } |
762 | 762 | |
763 | - foreach($comments as $key => &$comment) { |
|
763 | + foreach ( $comments as $key => &$comment ) { |
|
764 | 764 | $timber_comment = new $CommentClass($comment); |
765 | 765 | $timber_comments[$timber_comment->id] = $timber_comment; |
766 | 766 | } |
767 | 767 | |
768 | 768 | // Build a flattened (depth=1) comment tree |
769 | 769 | $comments_tree = array(); |
770 | - foreach( $timber_comments as $key => $comment ) { |
|
771 | - if ( ! $comment->is_child() ) { |
|
770 | + foreach ( $timber_comments as $key => $comment ) { |
|
771 | + if ( !$comment->is_child() ) { |
|
772 | 772 | continue; |
773 | 773 | } |
774 | 774 | |
775 | 775 | $tree_element = $comment; |
776 | 776 | do { |
777 | 777 | $tree_element = $timber_comments[$tree_element->comment_parent]; |
778 | - } while( $tree_element->is_child() ); |
|
778 | + } while ( $tree_element->is_child() ); |
|
779 | 779 | |
780 | 780 | $comments_tree[$tree_element->id][] = $comment->id; |
781 | 781 | } |
782 | 782 | |
783 | 783 | // Add child comments to the relative "super parents" |
784 | - foreach($comments_tree as $comment_parent => $comment_children) { |
|
785 | - foreach($comment_children as $comment_child) { |
|
784 | + foreach ( $comments_tree as $comment_parent => $comment_children ) { |
|
785 | + foreach ( $comment_children as $comment_child ) { |
|
786 | 786 | $timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child]; |
787 | 787 | unset($timber_comments[$comment_child]); |
788 | 788 | } |
@@ -833,7 +833,7 @@ discard block |
||
833 | 833 | $taxonomies = $tax; |
834 | 834 | } |
835 | 835 | if ( is_string($tax) ) { |
836 | - if ( in_array($tax, array('all','any','')) ) { |
|
836 | + if ( in_array($tax, array('all', 'any', '')) ) { |
|
837 | 837 | $taxonomies = get_object_taxonomies($this->post_type); |
838 | 838 | } else { |
839 | 839 | $taxonomies = array($tax); |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | $term_class_objects = array(); |
844 | 844 | |
845 | 845 | foreach ( $taxonomies as $taxonomy ) { |
846 | - if ( in_array($taxonomy, array('tag','tags')) ) { |
|
846 | + if ( in_array($taxonomy, array('tag', 'tags')) ) { |
|
847 | 847 | $taxonomy = 'post_tag'; |
848 | 848 | } |
849 | 849 | if ( $taxonomy == 'categories' ) { |
@@ -862,7 +862,7 @@ discard block |
||
862 | 862 | } |
863 | 863 | |
864 | 864 | // map over array of wordpress terms, and transform them into instances of the TermClass |
865 | - $terms = array_map(function($term) use ($TermClass, $taxonomy) { |
|
865 | + $terms = array_map(function( $term ) use ($TermClass, $taxonomy) { |
|
866 | 866 | return call_user_func(array($TermClass, 'from'), $term->term_id, $taxonomy); |
867 | 867 | }, $terms); |
868 | 868 | |
@@ -1055,13 +1055,13 @@ discard block |
||
1055 | 1055 | * ``` |
1056 | 1056 | * @return string a space-seperated list of classes |
1057 | 1057 | */ |
1058 | - public function post_class( $class='' ) { |
|
1058 | + public function post_class( $class = '' ) { |
|
1059 | 1059 | global $post; |
1060 | 1060 | $old_global_post = $post; |
1061 | 1061 | $post = $this; |
1062 | 1062 | $class_array = get_post_class($class, $this->ID); |
1063 | 1063 | $post = $old_global_post; |
1064 | - if ( is_array($class_array) ){ |
|
1064 | + if ( is_array($class_array) ) { |
|
1065 | 1065 | return implode(' ', $class_array); |
1066 | 1066 | } |
1067 | 1067 | return $class_array; |
@@ -1164,7 +1164,7 @@ discard block |
||
1164 | 1164 | * @return array |
1165 | 1165 | */ |
1166 | 1166 | public function children( $post_type = 'any', $childPostClass = false ) { |
1167 | - return $this->get_children( $post_type, $childPostClass ); |
|
1167 | + return $this->get_children($post_type, $childPostClass); |
|
1168 | 1168 | } |
1169 | 1169 | |
1170 | 1170 | /** |
@@ -1258,7 +1258,7 @@ discard block |
||
1258 | 1258 | */ |
1259 | 1259 | public function time( $time_format = '' ) { |
1260 | 1260 | $tf = $time_format ? $time_format : get_option('time_format'); |
1261 | - $the_time = (string)mysql2date($tf, $this->post_date); |
|
1261 | + $the_time = (string) mysql2date($tf, $this->post_date); |
|
1262 | 1262 | return apply_filters('get_the_time', $the_time, $tf); |
1263 | 1263 | } |
1264 | 1264 | |
@@ -1305,7 +1305,7 @@ discard block |
||
1305 | 1305 | /** |
1306 | 1306 | * @return string |
1307 | 1307 | */ |
1308 | - public function name(){ |
|
1308 | + public function name() { |
|
1309 | 1309 | return $this->title(); |
1310 | 1310 | } |
1311 | 1311 |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | |
10 | 10 | public function __toString() { |
11 | 11 | try { |
12 | - return (string)$this->call(); |
|
13 | - } catch (Exception $e) { |
|
12 | + return (string) $this->call(); |
|
13 | + } catch ( Exception $e ) { |
|
14 | 14 | return 'Caught exception: ' . $e->getMessage() . "\n"; |
15 | 15 | } |
16 | 16 | } |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | * @param bool $return_output_buffer |
24 | 24 | */ |
25 | 25 | public function __construct( $function, $args = array(), $return_output_buffer = false ) { |
26 | - if( is_array( $function ) ) { |
|
27 | - if( (is_string( $function[0] ) && class_exists( $function[0] ) ) || gettype( $function[0] ) === 'object' ) { |
|
26 | + if ( is_array($function) ) { |
|
27 | + if ( (is_string($function[0]) && class_exists($function[0])) || gettype($function[0]) === 'object' ) { |
|
28 | 28 | $this->_class = $function[0]; |
29 | 29 | } |
30 | 30 | |
31 | - if( is_string( $function[1] ) ) $this->_function = $function[1]; |
|
31 | + if ( is_string($function[1]) ) $this->_function = $function[1]; |
|
32 | 32 | } else { |
33 | 33 | $this->_function = $function; |
34 | 34 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | $this->_args = $args; |
37 | 37 | $this->_use_ob = $return_output_buffer; |
38 | 38 | |
39 | - add_filter( 'get_twig', array( &$this, 'add_to_twig' ) ); |
|
39 | + add_filter('get_twig', array(&$this, 'add_to_twig')); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | public function add_to_twig( $twig ) { |
49 | 49 | $wrapper = $this; |
50 | 50 | |
51 | - $twig->addFunction( new Twig_SimpleFunction( $this->_function, function () use ( $wrapper ) { |
|
52 | - return call_user_func_array( array( $wrapper, 'call' ), func_get_args() ); |
|
53 | - } ) ); |
|
51 | + $twig->addFunction(new Twig_SimpleFunction($this->_function, function() use ($wrapper) { |
|
52 | + return call_user_func_array(array($wrapper, 'call'), func_get_args()); |
|
53 | + } )); |
|
54 | 54 | |
55 | 55 | return $twig; |
56 | 56 | } |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | * @return string |
62 | 62 | */ |
63 | 63 | public function call() { |
64 | - $args = $this->_parse_args( func_get_args(), $this->_args ); |
|
65 | - $callable = ( isset( $this->_class ) ) ? array( $this->_class, $this->_function ) : $this->_function; |
|
64 | + $args = $this->_parse_args(func_get_args(), $this->_args); |
|
65 | + $callable = (isset($this->_class)) ? array($this->_class, $this->_function) : $this->_function; |
|
66 | 66 | |
67 | 67 | if ( $this->_use_ob ) { |
68 | - return TimberHelper::ob_function( $callable, $args ); |
|
68 | + return TimberHelper::ob_function($callable, $args); |
|
69 | 69 | } else { |
70 | - return call_user_func_array( $callable, $args ); |
|
70 | + return call_user_func_array($callable, $args); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | * @return array |
80 | 80 | */ |
81 | 81 | private function _parse_args( $args, $defaults ) { |
82 | - $_arg = reset( $defaults ); |
|
82 | + $_arg = reset($defaults); |
|
83 | 83 | |
84 | 84 | foreach ( $args as $index => $arg ) { |
85 | - $defaults[$index] = is_null( $arg ) ? $_arg : $arg; |
|
86 | - $_arg = next( $defaults ); |
|
85 | + $defaults[$index] = is_null($arg) ? $_arg : $arg; |
|
86 | + $_arg = next($defaults); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | return $defaults; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @param string $TermClass |
9 | 9 | * @return mixed |
10 | 10 | */ |
11 | - public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm') { |
|
11 | + public static function get_terms( $args = null, $maybe_args = array(), $TermClass = 'TimberTerm' ) { |
|
12 | 12 | if ( is_string($maybe_args) && !strstr($maybe_args, '=') ) { |
13 | 13 | //the user is sending the $TermClass in the second argument |
14 | 14 | $TermClass = $maybe_args; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @param string $TermClass |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public static function handle_term_query($taxonomies, $args, $TermClass) { |
|
56 | + public static function handle_term_query( $taxonomies, $args, $TermClass ) { |
|
57 | 57 | if ( !isset($args['hide_empty']) ) { |
58 | 58 | $args['hide_empty'] = false; |
59 | 59 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $args['include'] = $args['term_id']; |
65 | 65 | } |
66 | 66 | $terms = get_terms($taxonomies, $args); |
67 | - foreach ($terms as &$term) { |
|
67 | + foreach ( $terms as &$term ) { |
|
68 | 68 | $term = new $TermClass($term->term_id, $term->taxonomy); |
69 | 69 | } |
70 | 70 | return $terms; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string $query_string |
75 | 75 | * @return stdClass |
76 | 76 | */ |
77 | - protected static function get_term_query_from_query_string($query_string) { |
|
77 | + protected static function get_term_query_from_query_string( $query_string ) { |
|
78 | 78 | $args = array(); |
79 | 79 | parse_str($query_string, $args); |
80 | 80 | $ret = self::get_term_query_from_assoc_array($args); |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @param string $taxs |
86 | 86 | * @return stdClass |
87 | 87 | */ |
88 | - protected static function get_term_query_from_string($taxs) { |
|
88 | + protected static function get_term_query_from_string( $taxs ) { |
|
89 | 89 | $ret = new stdClass(); |
90 | 90 | $ret->args = array(); |
91 | 91 | if ( is_string($taxs) ) { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @param array $args |
100 | 100 | * @return stdClass |
101 | 101 | */ |
102 | - public static function get_term_query_from_assoc_array($args) { |
|
102 | + public static function get_term_query_from_assoc_array( $args ) { |
|
103 | 103 | $ret = new stdClass(); |
104 | 104 | $ret->args = $args; |
105 | 105 | if ( isset($ret->args['tax']) ) { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @param array $args |
127 | 127 | * @return stdClass |
128 | 128 | */ |
129 | - public static function get_term_query_from_array($args) { |
|
129 | + public static function get_term_query_from_array( $args ) { |
|
130 | 130 | if ( is_array($args) && !empty($args) ) { |
131 | 131 | //okay its an array with content |
132 | 132 | if ( is_int($args[0]) ) { |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param integer[] $args |
143 | 143 | * @return stdClass |
144 | 144 | */ |
145 | - public static function get_term_query_from_array_of_ids($args) { |
|
145 | + public static function get_term_query_from_array_of_ids( $args ) { |
|
146 | 146 | $ret = new stdClass(); |
147 | 147 | $ret->taxonomies = get_taxonomies(); |
148 | 148 | $ret->args['include'] = $args; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string[] $args |
154 | 154 | * @return stdClass |
155 | 155 | */ |
156 | - public static function get_term_query_from_array_of_strings($args) { |
|
156 | + public static function get_term_query_from_array_of_strings( $args ) { |
|
157 | 157 | $ret = new stdClass(); |
158 | 158 | $ret->taxonomies = self::correct_taxonomy_names($args); |
159 | 159 | $ret->args = array(); |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | * @param string|array $taxs |
165 | 165 | * @return array |
166 | 166 | */ |
167 | - private static function correct_taxonomy_names($taxs) { |
|
167 | + private static function correct_taxonomy_names( $taxs ) { |
|
168 | 168 | if ( is_string($taxs) ) { |
169 | 169 | $taxs = array($taxs); |
170 | 170 | } |
171 | - foreach ($taxs as &$tax) { |
|
171 | + foreach ( $taxs as &$tax ) { |
|
172 | 172 | if ( $tax == 'tags' || $tax == 'tag' ) { |
173 | 173 | $tax = 'post_tag'; |
174 | 174 | } else if ( $tax == 'categories' ) { |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param bool|string $caller the calling directory or false |
28 | 28 | */ |
29 | - function __construct($caller = false) { |
|
29 | + function __construct( $caller = false ) { |
|
30 | 30 | $this->locations = $this->get_locations($caller); |
31 | 31 | $this->cache_mode = apply_filters('timber_cache_mode', $this->cache_mode); |
32 | 32 | $this->cache_mode = apply_filters('timber/cache/mode', $this->cache_mode); |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | * @param string $cache_mode |
40 | 40 | * @return bool|string |
41 | 41 | */ |
42 | - function render($file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT) { |
|
42 | + function render( $file, $data = null, $expires = false, $cache_mode = self::CACHE_USE_DEFAULT ) { |
|
43 | 43 | // Different $expires if user is anonymous or logged in |
44 | - if (is_array($expires)) { |
|
45 | - if (is_user_logged_in() && isset($expires[1])) { |
|
44 | + if ( is_array($expires) ) { |
|
45 | + if ( is_user_logged_in() && isset($expires[1]) ) { |
|
46 | 46 | $expires = $expires[1]; |
47 | 47 | } else { |
48 | 48 | $expires = $expires[0]; |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | |
52 | 52 | $key = null; |
53 | 53 | $output = false; |
54 | - if (false !== $expires) { |
|
54 | + if ( false !== $expires ) { |
|
55 | 55 | ksort($data); |
56 | 56 | $key = md5($file . json_encode($data)); |
57 | 57 | $output = $this->get_cache($key, self::CACHEGROUP, $cache_mode); |
58 | 58 | } |
59 | 59 | |
60 | - if (false === $output || null === $output) { |
|
60 | + if ( false === $output || null === $output ) { |
|
61 | 61 | $twig = $this->get_twig(); |
62 | - if (strlen($file)) { |
|
62 | + if ( strlen($file) ) { |
|
63 | 63 | $loader = $this->get_loader(); |
64 | 64 | $result = $loader->getCacheKey($file); |
65 | 65 | do_action('timber_loader_render_file', $result); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $output = $twig->render($file, $data); |
70 | 70 | } |
71 | 71 | |
72 | - if (false !== $output && false !== $expires && null !== $key) { |
|
72 | + if ( false !== $output && false !== $expires && null !== $key ) { |
|
73 | 73 | $this->set_cache($key, $output, self::CACHEGROUP, $expires, $cache_mode); |
74 | 74 | } |
75 | 75 | $output = apply_filters('timber_output', $output); |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | * @param array $filenames |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function choose_template($filenames) { |
|
84 | - if (is_array($filenames)) { |
|
83 | + public function choose_template( $filenames ) { |
|
84 | + if ( is_array($filenames) ) { |
|
85 | 85 | /* its an array so we have to figure out which one the dev wants */ |
86 | - foreach ($filenames as $filename) { |
|
87 | - if (self::template_exists($filename)) { |
|
86 | + foreach ( $filenames as $filename ) { |
|
87 | + if ( self::template_exists($filename) ) { |
|
88 | 88 | return $filename; |
89 | 89 | } |
90 | 90 | } |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | * @param string $file |
98 | 98 | * @return bool |
99 | 99 | */ |
100 | - protected function template_exists($file) { |
|
101 | - foreach ($this->locations as $dir) { |
|
100 | + protected function template_exists( $file ) { |
|
101 | + foreach ( $this->locations as $dir ) { |
|
102 | 102 | $look_for = trailingslashit($dir) . $file; |
103 | - if (file_exists($look_for)) { |
|
103 | + if ( file_exists($look_for) ) { |
|
104 | 104 | return true; |
105 | 105 | } |
106 | 106 | } |
@@ -114,17 +114,17 @@ discard block |
||
114 | 114 | $theme_locs = array(); |
115 | 115 | $child_loc = get_stylesheet_directory(); |
116 | 116 | $parent_loc = get_template_directory(); |
117 | - if (DIRECTORY_SEPARATOR == '\\') { |
|
117 | + if ( DIRECTORY_SEPARATOR == '\\' ) { |
|
118 | 118 | $child_loc = str_replace('/', '\\', $child_loc); |
119 | 119 | $parent_loc = str_replace('/', '\\', $parent_loc); |
120 | 120 | } |
121 | 121 | $theme_locs[] = $child_loc; |
122 | - foreach ($this->get_locations_theme_dir() as $dirname) { |
|
122 | + foreach ( $this->get_locations_theme_dir() as $dirname ) { |
|
123 | 123 | $theme_locs[] = trailingslashit($child_loc) . trailingslashit($dirname); |
124 | 124 | } |
125 | - if ($child_loc != $parent_loc) { |
|
125 | + if ( $child_loc != $parent_loc ) { |
|
126 | 126 | $theme_locs[] = $parent_loc; |
127 | - foreach ($this->get_locations_theme_dir() as $dirname) { |
|
127 | + foreach ( $this->get_locations_theme_dir() as $dirname ) { |
|
128 | 128 | $theme_locs[] = trailingslashit($parent_loc) . trailingslashit($dirname); |
129 | 129 | } |
130 | 130 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @return string[] the names of directores, ie: array('templats', 'views'); |
139 | 139 | */ |
140 | 140 | private function get_locations_theme_dir() { |
141 | - if (is_string(Timber::$dirname)) { |
|
141 | + if ( is_string(Timber::$dirname) ) { |
|
142 | 142 | return array(Timber::$dirname); |
143 | 143 | } |
144 | 144 | return Timber::$dirname; |
@@ -149,13 +149,13 @@ discard block |
||
149 | 149 | */ |
150 | 150 | function get_locations_user() { |
151 | 151 | $locs = array(); |
152 | - if (isset(Timber::$locations)) { |
|
153 | - if (is_string(Timber::$locations)) { |
|
152 | + if ( isset(Timber::$locations) ) { |
|
153 | + if ( is_string(Timber::$locations) ) { |
|
154 | 154 | Timber::$locations = array(Timber::$locations); |
155 | 155 | } |
156 | - foreach (Timber::$locations as $tloc) { |
|
156 | + foreach ( Timber::$locations as $tloc ) { |
|
157 | 157 | $tloc = realpath($tloc); |
158 | - if (is_dir($tloc)) { |
|
158 | + if ( is_dir($tloc) ) { |
|
159 | 159 | $locs[] = $tloc; |
160 | 160 | } |
161 | 161 | } |
@@ -167,16 +167,16 @@ discard block |
||
167 | 167 | * @param bool|string $caller the calling directory |
168 | 168 | * @return array |
169 | 169 | */ |
170 | - function get_locations_caller($caller = false) { |
|
170 | + function get_locations_caller( $caller = false ) { |
|
171 | 171 | $locs = array(); |
172 | - if ($caller && is_string($caller)) { |
|
172 | + if ( $caller && is_string($caller) ) { |
|
173 | 173 | $caller = trailingslashit($caller); |
174 | - if (is_dir($caller)) { |
|
174 | + if ( is_dir($caller) ) { |
|
175 | 175 | $locs[] = $caller; |
176 | 176 | } |
177 | - foreach ($this->get_locations_theme_dir() as $dirname) { |
|
177 | + foreach ( $this->get_locations_theme_dir() as $dirname ) { |
|
178 | 178 | $caller_sub = $caller . trailingslashit($dirname); |
179 | - if (is_dir($caller_sub)) { |
|
179 | + if ( is_dir($caller_sub) ) { |
|
180 | 180 | $locs[] = $caller_sub; |
181 | 181 | } |
182 | 182 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param bool|string $caller the calling directory (or false) |
189 | 189 | * @return array |
190 | 190 | */ |
191 | - function get_locations($caller = false) { |
|
191 | + function get_locations( $caller = false ) { |
|
192 | 192 | //prioirty: user locations, caller (but not theme), child theme, parent theme, caller |
193 | 193 | $locs = array(); |
194 | 194 | $locs = array_merge($locs, $this->get_locations_user()); |
@@ -208,16 +208,16 @@ discard block |
||
208 | 208 | */ |
209 | 209 | function get_loader() { |
210 | 210 | $paths = array(); |
211 | - foreach ($this->locations as $loc) { |
|
211 | + foreach ( $this->locations as $loc ) { |
|
212 | 212 | $loc = realpath($loc); |
213 | - if (is_dir($loc)) { |
|
213 | + if ( is_dir($loc) ) { |
|
214 | 214 | $loc = realpath($loc); |
215 | 215 | $paths[] = $loc; |
216 | 216 | } else { |
217 | 217 | //error_log($loc.' is not a directory'); |
218 | 218 | } |
219 | 219 | } |
220 | - if (!ini_get('open_basedir')) { |
|
220 | + if ( !ini_get('open_basedir') ) { |
|
221 | 221 | $paths[] = '/'; |
222 | 222 | } else { |
223 | 223 | $paths[] = ABSPATH; |
@@ -233,15 +233,15 @@ discard block |
||
233 | 233 | function get_twig() { |
234 | 234 | $loader = $this->get_loader(); |
235 | 235 | $params = array('debug' => WP_DEBUG, 'autoescape' => false); |
236 | - if (isset(Timber::$autoescape)) { |
|
236 | + if ( isset(Timber::$autoescape) ) { |
|
237 | 237 | $params['autoescape'] = Timber::$autoescape; |
238 | 238 | } |
239 | - if (Timber::$cache === true) { |
|
239 | + if ( Timber::$cache === true ) { |
|
240 | 240 | Timber::$twig_cache = true; |
241 | 241 | } |
242 | - if (Timber::$twig_cache) { |
|
243 | - $twig_cache_loc = apply_filters( 'timber/cache/location', TIMBER_LOC . '/cache/twig' ); |
|
244 | - if (!file_exists($twig_cache_loc)) { |
|
242 | + if ( Timber::$twig_cache ) { |
|
243 | + $twig_cache_loc = apply_filters('timber/cache/location', TIMBER_LOC . '/cache/twig'); |
|
244 | + if ( !file_exists($twig_cache_loc) ) { |
|
245 | 245 | mkdir($twig_cache_loc, 0777, true); |
246 | 246 | } |
247 | 247 | $params['cache'] = $twig_cache_loc; |
@@ -258,26 +258,26 @@ discard block |
||
258 | 258 | return $twig; |
259 | 259 | } |
260 | 260 | |
261 | - public function clear_cache_timber($cache_mode = self::CACHE_USE_DEFAULT){ |
|
261 | + public function clear_cache_timber( $cache_mode = self::CACHE_USE_DEFAULT ) { |
|
262 | 262 | //_transient_timberloader |
263 | 263 | $object_cache = false; |
264 | - if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { |
|
264 | + if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) { |
|
265 | 265 | $object_cache = true; |
266 | 266 | } |
267 | 267 | $cache_mode = $this->_get_cache_mode($cache_mode); |
268 | - if (self::CACHE_TRANSIENT === $cache_mode) { |
|
268 | + if ( self::CACHE_TRANSIENT === $cache_mode ) { |
|
269 | 269 | global $wpdb; |
270 | 270 | $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%'); |
271 | - $wpdb->query( $query ); |
|
271 | + $wpdb->query($query); |
|
272 | 272 | return true; |
273 | - } else if (self::CACHE_SITE_TRANSIENT === $cache_mode) { |
|
273 | + } else if ( self::CACHE_SITE_TRANSIENT === $cache_mode ) { |
|
274 | 274 | global $wpdb; |
275 | 275 | $query = $wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE '%s'", '_transient_timberloader_%'); |
276 | - $wpdb->query( $query ); |
|
276 | + $wpdb->query($query); |
|
277 | 277 | return true; |
278 | - } else if (self::CACHE_OBJECT === $cache_mode && $object_cache) { |
|
278 | + } else if ( self::CACHE_OBJECT === $cache_mode && $object_cache ) { |
|
279 | 279 | global $wp_object_cache; |
280 | - if (isset($wp_object_cache->cache[self::CACHEGROUP])){ |
|
280 | + if ( isset($wp_object_cache->cache[self::CACHEGROUP]) ) { |
|
281 | 281 | unset($wp_object_cache->cache[self::CACHEGROUP]); |
282 | 282 | return true; |
283 | 283 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $twig = $this->get_twig(); |
290 | 290 | $twig->clearCacheFiles(); |
291 | 291 | $cache = $twig->getCache(); |
292 | - if ($cache){ |
|
292 | + if ( $cache ) { |
|
293 | 293 | self::rrmdir($twig->getCache()); |
294 | 294 | return true; |
295 | 295 | } |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | /** |
300 | 300 | * @param string|false $dirPath |
301 | 301 | */ |
302 | - public static function rrmdir($dirPath) { |
|
303 | - if (! is_dir($dirPath)) { |
|
302 | + public static function rrmdir( $dirPath ) { |
|
303 | + if ( !is_dir($dirPath) ) { |
|
304 | 304 | throw new InvalidArgumentException("$dirPath must be a directory"); |
305 | 305 | } |
306 | - if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { |
|
306 | + if ( substr($dirPath, strlen($dirPath) - 1, 1) != '/' ) { |
|
307 | 307 | $dirPath .= '/'; |
308 | 308 | } |
309 | 309 | $files = glob($dirPath . '*', GLOB_MARK); |
310 | - foreach ($files as $file) { |
|
311 | - if (is_dir($file)) { |
|
310 | + foreach ( $files as $file ) { |
|
311 | + if ( is_dir($file) ) { |
|
312 | 312 | self::rrmdir($file); |
313 | 313 | } else { |
314 | 314 | unlink($file); |
@@ -323,9 +323,9 @@ discard block |
||
323 | 323 | private function _get_cache_extension() { |
324 | 324 | |
325 | 325 | $key_generator = new \Timber\Cache\KeyGenerator(); |
326 | - $cache_provider = new \Timber\Cache\WPObjectCacheAdapter( $this ); |
|
327 | - $cache_strategy = new \Asm89\Twig\CacheExtension\CacheStrategy\GenerationalCacheStrategy( $cache_provider, $key_generator ); |
|
328 | - $cache_extension = new \Asm89\Twig\CacheExtension\Extension( $cache_strategy ); |
|
326 | + $cache_provider = new \Timber\Cache\WPObjectCacheAdapter($this); |
|
327 | + $cache_strategy = new \Asm89\Twig\CacheExtension\CacheStrategy\GenerationalCacheStrategy($cache_provider, $key_generator); |
|
328 | + $cache_extension = new \Asm89\Twig\CacheExtension\Extension($cache_strategy); |
|
329 | 329 | |
330 | 330 | return $cache_extension; |
331 | 331 | } |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | * @param string $cache_mode |
337 | 337 | * @return bool |
338 | 338 | */ |
339 | - public function get_cache($key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT) { |
|
339 | + public function get_cache( $key, $group = self::CACHEGROUP, $cache_mode = self::CACHE_USE_DEFAULT ) { |
|
340 | 340 | $object_cache = false; |
341 | 341 | |
342 | - if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { |
|
342 | + if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) { |
|
343 | 343 | $object_cache = true; |
344 | 344 | } |
345 | 345 | |
@@ -348,13 +348,13 @@ discard block |
||
348 | 348 | $value = false; |
349 | 349 | |
350 | 350 | $trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN); |
351 | - if (self::CACHE_TRANSIENT === $cache_mode) |
|
351 | + if ( self::CACHE_TRANSIENT === $cache_mode ) |
|
352 | 352 | $value = get_transient($trans_key); |
353 | 353 | |
354 | - elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) |
|
354 | + elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode ) |
|
355 | 355 | $value = get_site_transient($trans_key); |
356 | 356 | |
357 | - elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) |
|
357 | + elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache ) |
|
358 | 358 | $value = wp_cache_get($key, $group); |
359 | 359 | |
360 | 360 | return $value; |
@@ -368,26 +368,26 @@ discard block |
||
368 | 368 | * @param string $cache_mode |
369 | 369 | * @return string|boolean |
370 | 370 | */ |
371 | - public function set_cache($key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT) { |
|
371 | + public function set_cache( $key, $value, $group = self::CACHEGROUP, $expires = 0, $cache_mode = self::CACHE_USE_DEFAULT ) { |
|
372 | 372 | $object_cache = false; |
373 | 373 | |
374 | - if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { |
|
374 | + if ( isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache']) ) { |
|
375 | 375 | $object_cache = true; |
376 | 376 | } |
377 | 377 | |
378 | - if ((int)$expires < 1) |
|
378 | + if ( (int) $expires < 1 ) |
|
379 | 379 | $expires = 0; |
380 | 380 | |
381 | 381 | $cache_mode = self::_get_cache_mode($cache_mode); |
382 | 382 | $trans_key = substr($group . '_' . $key, 0, self::TRANS_KEY_LEN); |
383 | 383 | |
384 | - if (self::CACHE_TRANSIENT === $cache_mode) |
|
384 | + if ( self::CACHE_TRANSIENT === $cache_mode ) |
|
385 | 385 | set_transient($trans_key, $value, $expires); |
386 | 386 | |
387 | - elseif (self::CACHE_SITE_TRANSIENT === $cache_mode) |
|
387 | + elseif ( self::CACHE_SITE_TRANSIENT === $cache_mode ) |
|
388 | 388 | set_site_transient($trans_key, $value, $expires); |
389 | 389 | |
390 | - elseif (self::CACHE_OBJECT === $cache_mode && $object_cache) |
|
390 | + elseif ( self::CACHE_OBJECT === $cache_mode && $object_cache ) |
|
391 | 391 | wp_cache_set($key, $value, $group, $expires); |
392 | 392 | |
393 | 393 | return $value; |
@@ -397,13 +397,13 @@ discard block |
||
397 | 397 | * @param string $cache_mode |
398 | 398 | * @return string |
399 | 399 | */ |
400 | - private function _get_cache_mode($cache_mode) { |
|
401 | - if (empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode) { |
|
400 | + private function _get_cache_mode( $cache_mode ) { |
|
401 | + if ( empty($cache_mode) || self::CACHE_USE_DEFAULT === $cache_mode ) { |
|
402 | 402 | $cache_mode = $this->cache_mode; |
403 | 403 | } |
404 | 404 | |
405 | 405 | // Fallback if self::$cache_mode did not get a valid value |
406 | - if (!in_array($cache_mode, self::$cache_modes)) { |
|
406 | + if ( !in_array($cache_mode, self::$cache_modes) ) { |
|
407 | 407 | $cache_mode = self::CACHE_OBJECT; |
408 | 408 | } |
409 | 409 |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | * @param string $tax |
56 | 56 | */ |
57 | 57 | public function __construct( $tid = null, $tax = '' ) { |
58 | - if ($tid === null) { |
|
58 | + if ( $tid === null ) { |
|
59 | 59 | $tid = $this->get_term_from_query(); |
60 | 60 | } |
61 | - if (strlen($tax)) { |
|
61 | + if ( strlen($tax) ) { |
|
62 | 62 | $this->taxonomy = $tax; |
63 | 63 | } |
64 | 64 | $this->init($tid); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | global $wp_query; |
94 | 94 | if ( isset($wp_query->queried_object) ) { |
95 | 95 | $qo = $wp_query->queried_object; |
96 | - if (isset($qo->term_id)) { |
|
96 | + if ( isset($qo->term_id) ) { |
|
97 | 97 | return $qo->term_id; |
98 | 98 | } |
99 | 99 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | //echo 'bad call using '.$tid; |
117 | 117 | //TimberHelper::error_log(debug_backtrace()); |
118 | 118 | } |
119 | - if ( isset($term->ID) ){ |
|
119 | + if ( isset($term->ID) ) { |
|
120 | 120 | $term->id = $term->ID; |
121 | 121 | $this->import($term); |
122 | 122 | if ( isset($term->term_id) ) { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @param int $tid |
132 | 132 | * @return array |
133 | 133 | */ |
134 | - protected function get_term_meta($tid) { |
|
134 | + protected function get_term_meta( $tid ) { |
|
135 | 135 | $customs = array(); |
136 | 136 | $customs = apply_filters('timber_term_get_meta', $customs, $tid, $this); |
137 | 137 | return apply_filters('timber/term/meta', $customs, $tid, $this); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | global $wpdb; |
155 | 155 | $query = $wpdb->prepare("SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d LIMIT 1", $tid); |
156 | 156 | $tax = $wpdb->get_var($query); |
157 | - if (isset($tax) && strlen($tax)) { |
|
157 | + if ( isset($tax) && strlen($tax) ) { |
|
158 | 158 | $this->taxonomy = $tax; |
159 | 159 | return get_term($tid, $tax); |
160 | 160 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @return string |
207 | 207 | */ |
208 | 208 | public function get_meta_field( $field_name ) { |
209 | - if (!isset($this->$field_name)) { |
|
209 | + if ( !isset($this->$field_name) ) { |
|
210 | 210 | $field_value = ''; |
211 | 211 | $field_value = apply_filters('timber_term_get_meta_field', $field_value, $this->ID, $field_name, $this); |
212 | 212 | $field_value = apply_filters('timber/term/meta/field', $field_value, $this->ID, $field_name, $this); |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @return array|bool|null |
246 | 246 | */ |
247 | 247 | public function get_posts( $numberposts = 10, $post_type = 'any', $PostClass = '' ) { |
248 | - if (!strlen($PostClass)) { |
|
248 | + if ( !strlen($PostClass) ) { |
|
249 | 249 | $PostClass = $this->PostClass; |
250 | 250 | } |
251 | 251 | $default_tax_query = array(array( |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | parse_str($args, $new_args); |
260 | 260 | $args = $new_args; |
261 | 261 | $args['tax_query'] = $default_tax_query; |
262 | - if (!isset($args['post_type'])) { |
|
262 | + if ( !isset($args['post_type']) ) { |
|
263 | 263 | $args['post_type'] = 'any'; |
264 | 264 | } |
265 | - if (class_exists($post_type)) { |
|
265 | + if ( class_exists($post_type) ) { |
|
266 | 266 | $PostClass = $post_type; |
267 | 267 | } |
268 | 268 | } else if ( is_array($numberposts) ) { |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | public function get_children() { |
295 | 295 | if ( !isset($this->_children) ) { |
296 | 296 | $children = get_term_children($this->ID, $this->taxonomy); |
297 | - foreach ($children as &$child) { |
|
297 | + foreach ( $children as &$child ) { |
|
298 | 298 | $child = new TimberTerm($child); |
299 | 299 | } |
300 | 300 | $this->_children = $children; |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @param mixed $value |
310 | 310 | */ |
311 | 311 | function update( $key, $value ) { |
312 | - $value = apply_filters( 'timber_term_set_meta', $value, $key, $this->ID, $this ); |
|
312 | + $value = apply_filters('timber_term_set_meta', $value, $key, $this->ID, $this); |
|
313 | 313 | $this->$key = $value; |
314 | 314 | } |
315 | 315 | |
@@ -331,11 +331,11 @@ discard block |
||
331 | 331 | public function description() { |
332 | 332 | $prefix = '<p>'; |
333 | 333 | $suffix = '</p>'; |
334 | - $desc = term_description( $this->ID, $this->taxonomy ); |
|
335 | - if (substr($desc, 0, strlen($prefix)) == $prefix) { |
|
334 | + $desc = term_description($this->ID, $this->taxonomy); |
|
335 | + if ( substr($desc, 0, strlen($prefix)) == $prefix ) { |
|
336 | 336 | $desc = substr($desc, strlen($prefix)); |
337 | 337 | } |
338 | - $desc = preg_replace('/'. preg_quote('</p>', '/') . '$/', '', $desc); |
|
338 | + $desc = preg_replace('/' . preg_quote('</p>', '/') . '$/', '', $desc); |
|
339 | 339 | return trim($desc); |
340 | 340 | } |
341 | 341 |