Completed
Push — master ( 28f9cf...d6e32e )
by Jared
05:25 queued 02:39
created
lib/timber-post.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param mixed $pid
163 163
 	 */
164 164
 	public function __construct($pid = null) {
165
-		$pid = $this->determine_id( $pid );
165
+		$pid = $this->determine_id($pid);
166 166
 		$this->init($pid);
167 167
 	}
168 168
 
@@ -181,18 +181,18 @@  discard block
 block discarded – undo
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 ) {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 		return $this->title();
220 220
 	}
221 221
 
222
-	protected function get_post_preview_id( $query ) {
222
+	protected function get_post_preview_id($query) {
223 223
 		$can = array(
224 224
 	 		'edit_' . $query->queried_object->post_type . 's',
225 225
 	 	);
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 
231 231
 	 	$can_preview = false;
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
 	 			break;
237 237
 	 		}
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 	 		return;
242 242
 	 	}
243 243
 
244
-		$revisions = wp_get_post_revisions( $query->queried_object_id );
244
+		$revisions = wp_get_post_revisions($query->queried_object_id);
245 245
 
246
-		if( !empty( $revisions ) ) {
246
+		if ( !empty($revisions) ) {
247 247
 			$last = end($revisions);
248 248
 			return $last->ID;
249 249
 		}
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 	 * @param string $field
288 288
 	 * @param mixed $value
289 289
 	 */
290
-	public function update( $field, $value ) {
290
+	public function update($field, $value) {
291 291
 		if ( isset($this->ID) ) {
292 292
 			update_post_meta($this->ID, $field, $value);
293 293
 			$this->$field = $value;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $pid
303 303
 	 * @return WP_Post on success
304 304
 	 */
305
-	protected function prepare_post_info( $pid = 0 ) {
305
+	protected function prepare_post_info($pid = 0) {
306 306
 		if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) {
307 307
 			$pid = self::check_post_id($pid);
308 308
 			$post = get_post($pid);
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 	 * @internal
322 322
 	 * @return integer ID number of a post
323 323
 	 */
324
-	protected function check_post_id( $pid ) {
324
+	protected function check_post_id($pid) {
325 325
 		if ( is_numeric($pid) && $pid === 0 ) {
326 326
 			$pid = get_the_ID();
327 327
 			return $pid;
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 		global $wpdb;
348 348
 		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
349 349
 		$result = $wpdb->get_row($query);
350
-		if (!$result) {
350
+		if ( !$result ) {
351 351
 			return null;
352 352
 		}
353 353
 		return $result->ID;
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
 				$text = TimberHelper::trim_words($text, $len, false);
388 388
 				$trimmed = true;
389 389
 			}
390
-			$text = do_shortcode( $text );
390
+			$text = do_shortcode($text);
391 391
 		}
392 392
 		if ( !strlen($text) ) {
393 393
 			$text = TimberHelper::trim_words($this->get_content(), $len, false);
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
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
 		}
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 	 * @internal
433 433
 	 * @param bool|int $pid a post ID number
434 434
 	 */
435
-	function import_custom( $pid = false ) {
435
+	function import_custom($pid = false) {
436 436
 		if ( !$pid ) {
437 437
 			$pid = $this->ID;
438 438
 		}
@@ -447,13 +447,13 @@  discard block
 block discarded – undo
447 447
 	 * @param int $pid
448 448
 	 * @return array
449 449
 	 */
450
-	protected function get_post_custom( $pid ) {
450
+	protected function get_post_custom($pid) {
451 451
 		apply_filters('timber_post_get_meta_pre', array(), $pid, $this);
452 452
 		$customs = get_post_custom($pid);
453 453
 		if ( !is_array($customs) || empty($customs) ) {
454 454
 			return array();
455 455
 		}
456
-		foreach ( $customs as $key => $value ) {
456
+		foreach ($customs as $key => $value) {
457 457
 			if ( is_array($value) && count($value) == 1 && isset($value[0]) ) {
458 458
 				$value = $value[0];
459 459
 			}
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 	 * @param bool $taxonomy
508 508
 	 * @return TimberPost|boolean
509 509
 	 */
510
-	function get_next( $taxonomy = false ) {
510
+	function get_next($taxonomy = false) {
511 511
 		if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) {
512 512
 			global $post;
513 513
 			$this->_next = array();
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 		$post = $this;
539 539
 		$ret = array();
540 540
 		if ( $multipage ) {
541
-			for ( $i = 1; $i <= $numpages; $i++ ) {
541
+			for ($i = 1; $i <= $numpages; $i++) {
542 542
 				$link = self::get_wp_link_page($i);
543 543
 				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
544 544
 				if ( $i == $page ) {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 	 * @param bool $taxonomy
591 591
 	 * @return TimberPost|boolean
592 592
 	 */
593
-	function get_prev( $taxonomy = false ) {
593
+	function get_prev($taxonomy = false) {
594 594
 		if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) {
595 595
 			return $this->_prev[$taxonomy];
596 596
 		}
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
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
 
@@ -667,9 +667,9 @@  discard block
 block discarded – undo
667 667
 	 * @param  string $date_format
668 668
 	 * @return string
669 669
 	 */
670
-	function get_date( $date_format = '' ) {
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
 
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
 	 * @param  string $date_format
679 679
 	 * @return string
680 680
 	 */
681
-	function get_modified_date( $date_format = '' ) {
681
+	function get_modified_date($date_format = '') {
682 682
 		$df = $date_format ? $date_format : get_option('date_format');
683 683
 		$the_time = $this->get_modified_time($df);
684 684
 		return apply_filters('get_the_modified_date', $the_time, $date_format);
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
 	 * @param  string $time_format
690 690
 	 * @return string
691 691
 	 */
692
-	function get_modified_time( $time_format = '' ) {
692
+	function get_modified_time($time_format = '') {
693 693
 		$tf = $time_format ? $time_format : get_option('time_format');
694 694
 		$the_time = get_post_modified_time($tf, false, $this->ID, true);
695 695
 		return apply_filters('get_the_modified_time', $the_time, $time_format);
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
 	 * @param bool|string 	$childPostClass
703 703
 	 * @return array
704 704
 	 */
705
-	function get_children( $post_type = 'any', $childPostClass = false ) {
705
+	function get_children($post_type = 'any', $childPostClass = false) {
706 706
 		if ( $childPostClass === false ) {
707 707
 			$childPostClass = $this->PostClass;
708 708
 		}
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 			$post_type = $this->post_type;
711 711
 		}
712 712
 		$children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC');
713
-		foreach ( $children as &$child ) {
713
+		foreach ($children as &$child) {
714 714
 			$child = new $childPostClass($child->ID);
715 715
 		}
716 716
 		$children = array_values($children);
@@ -747,42 +747,42 @@  discard block
 block discarded – undo
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
 			}
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 	 * @param string $TermClass
823 823
 	 * @return array
824 824
 	 */
825
-	function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
825
+	function get_terms($tax = '', $merge = true, $TermClass = '') {
826 826
 
827 827
 		$TermClass = $TermClass ?: $this->TermClass;
828 828
 
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
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);
@@ -842,8 +842,8 @@  discard block
 block discarded – undo
842 842
 
843 843
 		$term_class_objects = array();
844 844
 
845
-		foreach ( $taxonomies as $taxonomy ) {
846
-			if ( in_array($taxonomy, array('tag','tags')) ) {
845
+		foreach ($taxonomies as $taxonomy) {
846
+			if ( in_array($taxonomy, array('tag', 'tags')) ) {
847 847
 				$taxonomy = 'post_tag';
848 848
 			}
849 849
 			if ( $taxonomy == 'categories' ) {
@@ -880,11 +880,11 @@  discard block
 block discarded – undo
880 880
 	 * @param string $taxonomy
881 881
 	 * @return bool
882 882
 	 */
883
-	function has_term( $term_name_or_id, $taxonomy = 'all' ) {
883
+	function has_term($term_name_or_id, $taxonomy = 'all') {
884 884
 		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
885 885
 			$taxes = get_object_taxonomies($this->post_type, 'names');
886 886
 			$ret = false;
887
-			foreach ( $taxes as $tax ) {
887
+			foreach ($taxes as $tax) {
888 888
 				if ( has_term($term_name_or_id, $tax, $this->ID) ) {
889 889
 					$ret = true;
890 890
 					break;
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 	 * @param string $field
900 900
 	 * @return TimberImage
901 901
 	 */
902
-	function get_image( $field ) {
902
+	function get_image($field) {
903 903
 		return new $this->ImageClass($this->$field);
904 904
 	}
905 905
 
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
 	 * @param int $page
950 950
 	 * @return string
951 951
 	 */
952
-	function get_content( $len = 0, $page = 0 ) {
952
+	function get_content($len = 0, $page = 0) {
953 953
 		if ( $len == 0 && $page == 0 && $this->_content ) {
954 954
 			return $this->_content;
955 955
 		}
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
 	 * @param string $field_name
1007 1007
 	 * @return mixed
1008 1008
 	 */
1009
-	public function get_field( $field_name ) {
1009
+	public function get_field($field_name) {
1010 1010
 		$value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
1011 1011
 		if ( $value === null ) {
1012 1012
 			$value = get_post_meta($this->ID, $field_name);
@@ -1024,7 +1024,7 @@  discard block
 block discarded – undo
1024 1024
 	/**
1025 1025
 	 * @param string $field_name
1026 1026
 	 */
1027
-	function import_field( $field_name ) {
1027
+	function import_field($field_name) {
1028 1028
 		$this->$field_name = $this->get_field($field_name);
1029 1029
 	}
1030 1030
 
@@ -1055,13 +1055,13 @@  discard block
 block discarded – undo
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;
@@ -1163,8 +1163,8 @@  discard block
 block discarded – undo
1163 1163
 	 * @param string|bool $childPostClass _optional_ a custom post class (ex: 'MyTimberPost') to return the objects as. By default (false) it will use TimberPost::$post_class value.
1164 1164
 	 * @return array
1165 1165
 	 */
1166
-	public function children( $post_type = 'any', $childPostClass = false ) {
1167
-		return $this->get_children( $post_type, $childPostClass );
1166
+	public function children($post_type = 'any', $childPostClass = false) {
1167
+		return $this->get_children($post_type, $childPostClass);
1168 1168
 	}
1169 1169
 
1170 1170
 	/**
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
 	 * ```
1189 1189
 	 * @return bool|array
1190 1190
 	 */
1191
-	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1191
+	public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') {
1192 1192
 		return $this->get_comments($count, $order, $type, $status, $CommentClass);
1193 1193
 	}
1194 1194
 
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
 	 * @param int $page
1206 1206
 	 * @return string
1207 1207
 	 */
1208
-	public function content( $page = 0 ) {
1208
+	public function content($page = 0) {
1209 1209
 		return $this->get_content(0, $page);
1210 1210
 	}
1211 1211
 
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
 	 * @param string $date_format
1235 1235
 	 * @return string
1236 1236
 	 */
1237
-	public function date( $date_format = '' ) {
1237
+	public function date($date_format = '') {
1238 1238
 		return $this->get_date($date_format);
1239 1239
 	}
1240 1240
 
@@ -1256,9 +1256,9 @@  discard block
 block discarded – undo
1256 1256
 	 * @param string $time_format
1257 1257
 	 * @return string
1258 1258
 	 */
1259
-	public function time( $time_format = '' ) {
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
 
@@ -1294,7 +1294,7 @@  discard block
 block discarded – undo
1294 1294
 	 * @param string $field_name
1295 1295
 	 * @return mixed
1296 1296
 	 */
1297
-	public function meta( $field_name = null ) {
1297
+	public function meta($field_name = null) {
1298 1298
 		if ( $field_name === null ) {
1299 1299
 			//on the off-chance the field is actually named meta
1300 1300
 			$field_name = 'meta';
@@ -1305,7 +1305,7 @@  discard block
 block discarded – undo
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
 
@@ -1313,7 +1313,7 @@  discard block
 block discarded – undo
1313 1313
 	 * @param string $date_format
1314 1314
 	 * @return string
1315 1315
 	 */
1316
-	public function modified_date( $date_format = '' ) {
1316
+	public function modified_date($date_format = '') {
1317 1317
 		return $this->get_modified_date($date_format);
1318 1318
 	}
1319 1319
 
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
 	 * @param string $time_format
1322 1322
 	 * @return string
1323 1323
 	 */
1324
-	public function modified_time( $time_format = '' ) {
1324
+	public function modified_time($time_format = '') {
1325 1325
 		return $this->get_modified_time($time_format);
1326 1326
 	}
1327 1327
 
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
 	 * @param bool $in_same_cat
1331 1331
 	 * @return mixed
1332 1332
 	 */
1333
-	public function next( $in_same_cat = false ) {
1333
+	public function next($in_same_cat = false) {
1334 1334
 		return $this->get_next($in_same_cat);
1335 1335
 	}
1336 1336
 
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
 	 * @param bool $in_same_cat
1389 1389
 	 * @return mixed
1390 1390
 	 */
1391
-	public function prev( $in_same_cat = false ) {
1391
+	public function prev($in_same_cat = false) {
1392 1392
 		return $this->get_prev($in_same_cat);
1393 1393
 	}
1394 1394
 
@@ -1400,7 +1400,7 @@  discard block
 block discarded – undo
1400 1400
 	 * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
1401 1401
 	 * @return array
1402 1402
 	 */
1403
-	public function terms( $tax = '', $merge = true ) {
1403
+	public function terms($tax = '', $merge = true) {
1404 1404
 		return $this->get_terms($tax, $merge);
1405 1405
 	}
1406 1406
 
Please login to merge, or discard this patch.