Completed
Pull Request — master (#876)
by
unknown
03:16
created
lib/timber-post.php 1 patch
Spacing   +68 added lines, -68 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,17 +230,17 @@  discard block
 block discarded – undo
230 230
 
231 231
 	 	$continue = true;
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
 	 			$continue = false;
236 236
 	 			break;
237 237
 	 		}
238 238
 	 	}
239 239
 		
240
-		if( $continue ) {
241
-			$revisions = wp_get_post_revisions( $query->queried_object_id );
240
+		if ( $continue ) {
241
+			$revisions = wp_get_post_revisions($query->queried_object_id);
242 242
 
243
-			if( !empty( $revisions ) ) {
243
+			if ( !empty($revisions) ) {
244 244
 				$last = end($revisions);
245 245
 				return $last->ID;
246 246
 			} else {
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 	 * @param string $field
286 286
 	 * @param mixed $value
287 287
 	 */
288
-	public function update( $field, $value ) {
288
+	public function update($field, $value) {
289 289
 		if ( isset($this->ID) ) {
290 290
 			update_post_meta($this->ID, $field, $value);
291 291
 			$this->$field = $value;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 	 * @param mixed $pid
301 301
 	 * @return WP_Post on success
302 302
 	 */
303
-	protected function prepare_post_info( $pid = 0 ) {
303
+	protected function prepare_post_info($pid = 0) {
304 304
 		if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) {
305 305
 			$pid = self::check_post_id($pid);
306 306
 			$post = get_post($pid);
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @internal
320 320
 	 * @return integer ID number of a post
321 321
 	 */
322
-	protected function check_post_id( $pid ) {
322
+	protected function check_post_id($pid) {
323 323
 		if ( is_numeric($pid) && $pid === 0 ) {
324 324
 			$pid = get_the_ID();
325 325
 			return $pid;
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 		global $wpdb;
346 346
 		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
347 347
 		$result = $wpdb->get_row($query);
348
-		if (!$result) {
348
+		if ( !$result ) {
349 349
 			return null;
350 350
 		}
351 351
 		return $result->ID;
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
 				$text = TimberHelper::trim_words($text, $len, false);
386 386
 				$trimmed = true;
387 387
 			}
388
-			$text = do_shortcode( $text );
388
+			$text = do_shortcode($text);
389 389
 		}
390 390
 		if ( !strlen($text) ) {
391 391
 			$text = TimberHelper::trim_words($this->get_content(), $len, false);
@@ -414,11 +414,11 @@  discard block
 block discarded – undo
414 414
 			}
415 415
 			$read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more");
416 416
 			if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) {
417
-				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>';
417
+				$text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore_matches[1]) . '</a>';
418 418
 			} elseif ( $readmore ) {
419
-				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>';
419
+				$text .= ' <a href="' . $this->get_permalink() . '" class="' . $read_more_class . '">' . trim($readmore) . '</a>';
420 420
 			}
421
-			if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) {
421
+			if ( !$strip && $last_p_tag && (strpos($text, '<p>') || strpos($text, '<p ')) ) {
422 422
 				$text .= '</p>';
423 423
 			}
424 424
 		}
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 * @internal
431 431
 	 * @param bool|int $pid a post ID number
432 432
 	 */
433
-	function import_custom( $pid = false ) {
433
+	function import_custom($pid = false) {
434 434
 		if ( !$pid ) {
435 435
 			$pid = $this->ID;
436 436
 		}
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
 	 * @param int $pid
446 446
 	 * @return array
447 447
 	 */
448
-	protected function get_post_custom( $pid ) {
448
+	protected function get_post_custom($pid) {
449 449
 		apply_filters('timber_post_get_meta_pre', array(), $pid, $this);
450 450
 		$customs = get_post_custom($pid);
451 451
 		if ( !is_array($customs) || empty($customs) ) {
452 452
 			return array();
453 453
 		}
454
-		foreach ( $customs as $key => $value ) {
454
+		foreach ($customs as $key => $value) {
455 455
 			if ( is_array($value) && count($value) == 1 && isset($value[0]) ) {
456 456
 				$value = $value[0];
457 457
 			}
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 	 * @param bool $taxonomy
506 506
 	 * @return TimberPost|boolean
507 507
 	 */
508
-	function get_next( $taxonomy = false ) {
508
+	function get_next($taxonomy = false) {
509 509
 		if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) {
510 510
 			global $post;
511 511
 			$this->_next = array();
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 		$post = $this;
537 537
 		$ret = array();
538 538
 		if ( $multipage ) {
539
-			for ( $i = 1; $i <= $numpages; $i++ ) {
539
+			for ($i = 1; $i <= $numpages; $i++) {
540 540
 				$link = self::get_wp_link_page($i);
541 541
 				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
542 542
 				if ( $i == $page ) {
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 	 * @param bool $taxonomy
589 589
 	 * @return TimberPost|boolean
590 590
 	 */
591
-	function get_prev( $taxonomy = false ) {
591
+	function get_prev($taxonomy = false) {
592 592
 		if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) {
593 593
 			return $this->_prev[$taxonomy];
594 594
 		}
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
 		$post->slug = $post->post_name;
656 656
 		$customs = $this->get_post_custom($post->ID);
657 657
 		$post->custom = $customs;
658
-		$post = (object) array_merge((array)$customs, (array)$post);
658
+		$post = (object) array_merge((array) $customs, (array) $post);
659 659
 		return $post;
660 660
 	}
661 661
 
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 	 * @param  string $date_format
666 666
 	 * @return string
667 667
 	 */
668
-	function get_date( $date_format = '' ) {
668
+	function get_date($date_format = '') {
669 669
 		$df = $date_format ? $date_format : get_option('date_format');
670
-		$the_date = (string)mysql2date($df, $this->post_date);
670
+		$the_date = (string) mysql2date($df, $this->post_date);
671 671
 		return apply_filters('get_the_date', $the_date, $df);
672 672
 	}
673 673
 
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
 	 * @param  string $date_format
677 677
 	 * @return string
678 678
 	 */
679
-	function get_modified_date( $date_format = '' ) {
679
+	function get_modified_date($date_format = '') {
680 680
 		$df = $date_format ? $date_format : get_option('date_format');
681 681
 		$the_time = $this->get_modified_time($df);
682 682
 		return apply_filters('get_the_modified_date', $the_time, $date_format);
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 	 * @param  string $time_format
688 688
 	 * @return string
689 689
 	 */
690
-	function get_modified_time( $time_format = '' ) {
690
+	function get_modified_time($time_format = '') {
691 691
 		$tf = $time_format ? $time_format : get_option('time_format');
692 692
 		$the_time = get_post_modified_time($tf, false, $this->ID, true);
693 693
 		return apply_filters('get_the_modified_time', $the_time, $time_format);
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 	 * @param bool|string 	$childPostClass
701 701
 	 * @return array
702 702
 	 */
703
-	function get_children( $post_type = 'any', $childPostClass = false ) {
703
+	function get_children($post_type = 'any', $childPostClass = false) {
704 704
 		if ( $childPostClass === false ) {
705 705
 			$childPostClass = $this->PostClass;
706 706
 		}
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 			$post_type = $this->post_type;
709 709
 		}
710 710
 		$children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC');
711
-		foreach ( $children as &$child ) {
711
+		foreach ($children as &$child) {
712 712
 			$child = new $childPostClass($child->ID);
713 713
 		}
714 714
 		$children = array_values($children);
@@ -745,42 +745,42 @@  discard block
 block discarded – undo
745 745
 		}
746 746
 
747 747
 		if ( $user_ID ) {
748
-			$args['include_unapproved'] = array( $user_ID );
749
-		} elseif ( ! empty( $comment_author_email ) ) {
750
-			$args['include_unapproved'] = array( $comment_author_email );
748
+			$args['include_unapproved'] = array($user_ID);
749
+		} elseif ( !empty($comment_author_email) ) {
750
+			$args['include_unapproved'] = array($comment_author_email);
751 751
 		}
752 752
 
753 753
 		$comments = get_comments($args);
754 754
 		$timber_comments = array();
755 755
 
756 756
 		if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
757
-			set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
757
+			set_query_var('cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1);
758 758
 			$overridden_cpage = true;
759 759
 		}
760 760
 
761
-		foreach($comments as $key => &$comment) {
761
+		foreach ($comments as $key => &$comment) {
762 762
 			$timber_comment = new $CommentClass($comment);
763 763
 			$timber_comments[$timber_comment->id] = $timber_comment;
764 764
 		}
765 765
 
766 766
 		// Build a flattened (depth=1) comment tree
767 767
 		$comments_tree = array();
768
-		foreach( $timber_comments as $key => $comment ) {
769
-			if ( ! $comment->is_child() ) {
768
+		foreach ($timber_comments as $key => $comment) {
769
+			if ( !$comment->is_child() ) {
770 770
 				continue;
771 771
 			}
772 772
 
773 773
 			$tree_element = $comment;
774 774
 			do {
775 775
 				$tree_element = $timber_comments[$tree_element->comment_parent];
776
-			} while( $tree_element->is_child() );
776
+			} while ($tree_element->is_child());
777 777
 
778 778
 			$comments_tree[$tree_element->id][] = $comment->id;
779 779
 		}
780 780
 
781 781
 		// Add child comments to the relative "super parents"
782
-		foreach($comments_tree as $comment_parent => $comment_children) {
783
-			foreach($comment_children as $comment_child) {
782
+		foreach ($comments_tree as $comment_parent => $comment_children) {
783
+			foreach ($comment_children as $comment_child) {
784 784
 				$timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child];
785 785
 				unset($timber_comments[$comment_child]);
786 786
 			}
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 	 * @param string $TermClass
821 821
 	 * @return array
822 822
 	 */
823
-	function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
823
+	function get_terms($tax = '', $merge = true, $TermClass = '') {
824 824
 
825 825
 		$TermClass = $TermClass ?: $this->TermClass;
826 826
 
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 			$taxonomies = $tax;
832 832
 		}
833 833
 		if ( is_string($tax) ) {
834
-			if ( in_array($tax, array('all','any','')) ) {
834
+			if ( in_array($tax, array('all', 'any', '')) ) {
835 835
 				$taxonomies = get_object_taxonomies($this->post_type);
836 836
 			} else {
837 837
 				$taxonomies = array($tax);
@@ -840,8 +840,8 @@  discard block
 block discarded – undo
840 840
 
841 841
 		$term_class_objects = array();
842 842
 
843
-		foreach ( $taxonomies as $taxonomy ) {
844
-			if ( in_array($taxonomy, array('tag','tags')) ) {
843
+		foreach ($taxonomies as $taxonomy) {
844
+			if ( in_array($taxonomy, array('tag', 'tags')) ) {
845 845
 				$taxonomy = 'post_tag';
846 846
 			}
847 847
 			if ( $taxonomy == 'categories' ) {
@@ -878,11 +878,11 @@  discard block
 block discarded – undo
878 878
 	 * @param string $taxonomy
879 879
 	 * @return bool
880 880
 	 */
881
-	function has_term( $term_name_or_id, $taxonomy = 'all' ) {
881
+	function has_term($term_name_or_id, $taxonomy = 'all') {
882 882
 		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
883 883
 			$taxes = get_object_taxonomies($this->post_type, 'names');
884 884
 			$ret = false;
885
-			foreach ( $taxes as $tax ) {
885
+			foreach ($taxes as $tax) {
886 886
 				if ( has_term($term_name_or_id, $tax, $this->ID) ) {
887 887
 					$ret = true;
888 888
 					break;
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 	 * @param string $field
898 898
 	 * @return TimberImage
899 899
 	 */
900
-	function get_image( $field ) {
900
+	function get_image($field) {
901 901
 		return new $this->ImageClass($this->$field);
902 902
 	}
903 903
 
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 	 * @param int $page
948 948
 	 * @return string
949 949
 	 */
950
-	function get_content( $len = 0, $page = 0 ) {
950
+	function get_content($len = 0, $page = 0) {
951 951
 		if ( $len == 0 && $page == 0 && $this->_content ) {
952 952
 			return $this->_content;
953 953
 		}
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
 	 * @param string $field_name
1005 1005
 	 * @return mixed
1006 1006
 	 */
1007
-	public function get_field( $field_name ) {
1007
+	public function get_field($field_name) {
1008 1008
 		$value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
1009 1009
 		if ( $value === null ) {
1010 1010
 			$value = get_post_meta($this->ID, $field_name);
@@ -1022,7 +1022,7 @@  discard block
 block discarded – undo
1022 1022
 	/**
1023 1023
 	 * @param string $field_name
1024 1024
 	 */
1025
-	function import_field( $field_name ) {
1025
+	function import_field($field_name) {
1026 1026
 		$this->$field_name = $this->get_field($field_name);
1027 1027
 	}
1028 1028
 
@@ -1053,13 +1053,13 @@  discard block
 block discarded – undo
1053 1053
 	 * ```
1054 1054
 	 * @return string a space-seperated list of classes
1055 1055
 	 */
1056
-	public function post_class( $class='' ) {
1056
+	public function post_class($class = '') {
1057 1057
 		global $post;
1058 1058
 		$old_global_post = $post;
1059 1059
 		$post = $this;
1060 1060
 		$class_array = get_post_class($class, $this->ID);
1061 1061
 		$post = $old_global_post;
1062
-		if ( is_array($class_array) ){
1062
+		if ( is_array($class_array) ) {
1063 1063
 			return implode(' ', $class_array);
1064 1064
 		}
1065 1065
 		return $class_array;
@@ -1161,8 +1161,8 @@  discard block
 block discarded – undo
1161 1161
 	 * @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.
1162 1162
 	 * @return array
1163 1163
 	 */
1164
-	public function children( $post_type = 'any', $childPostClass = false ) {
1165
-		return $this->get_children( $post_type, $childPostClass );
1164
+	public function children($post_type = 'any', $childPostClass = false) {
1165
+		return $this->get_children($post_type, $childPostClass);
1166 1166
 	}
1167 1167
 
1168 1168
 	/**
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 	 * ```
1187 1187
 	 * @return bool|array
1188 1188
 	 */
1189
-	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1189
+	public function comments($count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') {
1190 1190
 		return $this->get_comments($count, $order, $type, $status, $CommentClass);
1191 1191
 	}
1192 1192
 
@@ -1203,7 +1203,7 @@  discard block
 block discarded – undo
1203 1203
 	 * @param int $page
1204 1204
 	 * @return string
1205 1205
 	 */
1206
-	public function content( $page = 0 ) {
1206
+	public function content($page = 0) {
1207 1207
 		return $this->get_content(0, $page);
1208 1208
 	}
1209 1209
 
@@ -1232,7 +1232,7 @@  discard block
 block discarded – undo
1232 1232
 	 * @param string $date_format
1233 1233
 	 * @return string
1234 1234
 	 */
1235
-	public function date( $date_format = '' ) {
1235
+	public function date($date_format = '') {
1236 1236
 		return $this->get_date($date_format);
1237 1237
 	}
1238 1238
 
@@ -1254,9 +1254,9 @@  discard block
 block discarded – undo
1254 1254
 	 * @param string $time_format
1255 1255
 	 * @return string
1256 1256
 	 */
1257
-	public function time( $time_format = '' ) {
1257
+	public function time($time_format = '') {
1258 1258
 		$tf = $time_format ? $time_format : get_option('time_format');
1259
-	 	$the_time = (string)mysql2date($tf, $this->post_date);
1259
+	 	$the_time = (string) mysql2date($tf, $this->post_date);
1260 1260
 	 	return apply_filters('get_the_time', $the_time, $tf);
1261 1261
 	}
1262 1262
 
@@ -1292,7 +1292,7 @@  discard block
 block discarded – undo
1292 1292
 	 * @param string $field_name
1293 1293
 	 * @return mixed
1294 1294
 	 */
1295
-	public function meta( $field_name = null ) {
1295
+	public function meta($field_name = null) {
1296 1296
 		if ( $field_name === null ) {
1297 1297
 			//on the off-chance the field is actually named meta
1298 1298
 			$field_name = 'meta';
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
 	/**
1304 1304
 	 * @return string
1305 1305
 	 */
1306
-	public function name(){
1306
+	public function name() {
1307 1307
 		return $this->title();
1308 1308
 	}
1309 1309
 
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
 	 * @param string $date_format
1312 1312
 	 * @return string
1313 1313
 	 */
1314
-	public function modified_date( $date_format = '' ) {
1314
+	public function modified_date($date_format = '') {
1315 1315
 		return $this->get_modified_date($date_format);
1316 1316
 	}
1317 1317
 
@@ -1319,7 +1319,7 @@  discard block
 block discarded – undo
1319 1319
 	 * @param string $time_format
1320 1320
 	 * @return string
1321 1321
 	 */
1322
-	public function modified_time( $time_format = '' ) {
1322
+	public function modified_time($time_format = '') {
1323 1323
 		return $this->get_modified_time($time_format);
1324 1324
 	}
1325 1325
 
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
 	 * @param bool $in_same_cat
1329 1329
 	 * @return mixed
1330 1330
 	 */
1331
-	public function next( $in_same_cat = false ) {
1331
+	public function next($in_same_cat = false) {
1332 1332
 		return $this->get_next($in_same_cat);
1333 1333
 	}
1334 1334
 
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 	 * @param bool $in_same_cat
1387 1387
 	 * @return mixed
1388 1388
 	 */
1389
-	public function prev( $in_same_cat = false ) {
1389
+	public function prev($in_same_cat = false) {
1390 1390
 		return $this->get_prev($in_same_cat);
1391 1391
 	}
1392 1392
 
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
 	 * @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)?
1399 1399
 	 * @return array
1400 1400
 	 */
1401
-	public function terms( $tax = '', $merge = true ) {
1401
+	public function terms($tax = '', $merge = true) {
1402 1402
 		return $this->get_terms($tax, $merge);
1403 1403
 	}
1404 1404
 
Please login to merge, or discard this patch.