Completed
Pull Request — master (#770)
by
unknown
04:56
created

TimberPost::get_comments()   D

Complexity

Conditions 13
Paths 192

Size

Total Lines 49
Code Lines 29

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 49
rs 4.8141
cc 13
eloc 29
nc 192
nop 5

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This is the object you use to access or extend WordPress posts. Think of it as Timber's (more accessible) version of WP_Post. This is used throughout Timber to represent posts retrieved from WordPress making them available to Twig templates. See the PHP and Twig examples for an example of what it's like to work with this object in your code.
5
 * @example
6
 * ```php
7
 * <?php
8
 * // single.php, see connected twig example
9
 * $context = Timber::get_context();
10
 * $context['post'] = new TimberPost(); // It's a new TimberPost object, but an existing post from WordPress.
11
 * Timber::render('single.twig', $context);
12
 * ?>
13
 * ```
14
 * ```twig
15
 * {# single.twig #}
16
 * <article>
17
 *     <h1 class="headline">{{post.title}}</h1>
18
 *     <div class="body">
19
 *         {{post.content}}
20
 *     </div>
21
 * </article>
22
 * ```
23
 *
24
 * ```html
25
 * <article>
26
 *     <h1 class="headline">The Empire Strikes Back</h1>
27
 *     <div class="body">
28
 *         It is a dark time for the Rebellion. Although the Death Star has been destroyed, Imperial troops have driven the Rebel forces from their hidden base and pursued them across the galaxy.
29
 *     </div>
30
 * </article>
31
 * ```
32
 *
33
 * @package Timber
34
 */
35
class TimberPost extends TimberCore implements TimberCoreInterface {
36
37
	/**
38
	 * @var string $ImageClass the name of the class to handle images by default
39
	 */
40
	public $ImageClass = 'TimberImage';
41
42
	/**
43
	 * @var string $PostClass the name of the class to handle posts by default
44
	 */
45
	public $PostClass = 'TimberPost';
46
47
	/**
48
	 * @var string $TermClass the name of the class to handle terms by default
49
	 */
50
	public $TermClass = 'TimberTerm';
51
52
	/**
53
	 * @var string $object_type what does this class represent in WordPress terms?
54
	 */
55
	public $object_type = 'post';
56
57
	/**
58
	 * @var string $representation what does this class represent in WordPress terms?
59
	 */
60
	public static $representation = 'post';
61
62
	/**
63
	 * @internal
64
	 * @var string $_content stores the processed content internally
65
	 */
66
	protected $_content;
67
68
	/**
69
	 * @internal
70
	 * @var array $_get_terms stores the results of a get_terms method call
71
	 * @deprecated
72
	 */
73
	protected $_get_terms;
74
75
	/**
76
	 * @var string $_permalink the returned permalink from WP's get_permalink function
77
	 */
78
	protected $_permalink;
79
80
	/**
81
	 * @var array $_next stores the results of the next TimberPost in a set inside an array (in order to manage by-taxonomy)
82
	 */
83
	protected $_next = array();
84
85
	/**
86
	 * @var array $_prev stores the results of the previous TimberPost in a set inside an array (in order to manage by-taxonomy)
87
	 */
88
	protected $_prev = array();
89
90
	/**
91
	 * @api
92
	 * @var string $class stores the CSS classes for the post (ex: "post post-type-book post-123")
93
	 */
94
	public $class;
95
96
	/**
97
	 * @deprecated since 0.21.7
98
	 * @var string $display_date @deprecated stores the display date (ex: "October 6, 1984"),
99
	 */
100
	public $display_date;
101
102
	/**
103
	 * @api
104
	 * @var string $id the numeric WordPress id of a post
105
	 */
106
	public $id;
107
108
	/**
109
	 * @var string 	$ID 			the numeric WordPress id of a post, capitalized to match WP usage
110
	 */
111
	public $ID;
112
113
	/**
114
	 * @var int 	$post_author 	the numeric ID of the a post's author corresponding to the wp_user dtable
115
	 */
116
	public $post_author;
117
118
	/**
119
	 * @var string 	$post_content 	the raw text of a WP post as stored in the database
120
	 */
121
	public $post_content;
122
123
	/**
124
	 * @var string 	$post_date 		the raw date string as stored in the WP database, ex: 2014-07-05 18:01:39
125
	 */
126
	public $post_date;
127
128
	/**
129
	 * @var string 	$post_exceprt 	the raw text of a manual post exceprt as stored in the database
130
	 */
131
	public $post_excerpt;
132
133
	/**
134
	 * @var int 		$post_parent 	the numeric ID of a post's parent post
135
	 */
136
	public $post_parent;
137
138
	/**
139
	 * @api
140
	 * @var string 		$post_status 	the status of a post ("draft", "publish", etc.)
141
	 */
142
	public $post_status;
143
144
	/**
145
	 * @var string 	$post_title 	the raw text of a post's title as stored in the database
146
	 */
147
	public $post_title;
148
149
	/**
150
	 * @api
151
	 * @var string 	$post_type 		the name of the post type, this is the machine name (so "my_custom_post_type" as opposed to "My Custom Post Type")
152
	 */
153
	public $post_type;
154
155
	/**
156
	 * @api
157
	 * @var string 	$slug 		the URL-safe slug, this corresponds to the poorly-named "post_name" in the WP database, ex: "hello-world"
158
	 */
159
	public $slug;
160
161
	/**
162
	 * If you send the constructor nothing it will try to figure out the current post id based on being inside The_Loop
163
	 * @example
164
	 * ```php
165
	 * $post = new TimberPost();
166
	 * $other_post = new TimberPost($random_post_id);
167
	 * ```
168
	 * @param mixed $pid
169
	 */
170
	public function __construct($pid = null) {
171
		$pid = $this->determine_id( $pid );
172
		$this->init($pid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
173
	}
174
175
	/**
176
	 * tries to figure out what post you want to get if not explictly defined (or if it is, allows it to be passed through)
177
	 * @internal
178
	 * @param mixed a value to test against
179
	 * @return int the numberic id we should be using for this post object
180
	 */
181
	protected function determine_id($pid) {
182
		global $wp_query;
183
		if ( $pid === null &&
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
184
			isset($wp_query->queried_object_id)
185
			&& $wp_query->queried_object_id
186
			&& isset($wp_query->queried_object)
187
			&& is_object($wp_query->queried_object)
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
188
			&& get_class($wp_query->queried_object) == 'WP_Post'
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
189
			) {
190
			$pid = $wp_query->queried_object_id;
191
		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id )  {
192
			//hack for static page as home page
193
			$pid = $wp_query->queried_object_id;
194
		} else if ( $pid === null ) {
195
			$gtid = false;
196
			$maybe_post = get_post();
197
			if ( isset($maybe_post->ID) ){
198
				$gtid = true;
199
			}
200
			if ( $gtid ) {
201
				$pid = get_the_ID();
202
			}
203
			if ( !$pid ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
204
				global $wp_query;
205
				if ( isset($wp_query->query['p']) ) {
206
					$pid = $wp_query->query['p'];
207
				}
208
			}
209
		}
210
		if ( $pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id()) ) {
211
			$pid = $pid_from_loop;
212
		}
213
		return $pid;
214
	}
215
216
	/**
217
	 * Outputs the title of the post if you do something like `<h1>{{post}}</h1>`
218
	 * @return string
219
	 */
220
	public function __toString() {
221
		return $this->title();
222
	}
223
224
225
	/**
226
	 * Initializes a TimberPost
227
	 * @internal
228
	 * @param int|bool $pid
229
	 */
230
	protected function init($pid = false) {
231
		if ( $pid === false ) {
0 ignored issues
show
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
232
			$pid = get_the_ID();
233
		}
234
		if ( is_numeric($pid) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
235
			$this->ID = $pid;
0 ignored issues
show
Documentation Bug introduced by
It seems like $pid can also be of type integer or double. However, the property $ID is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
236
		}
237
		$post_info = $this->get_info($pid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
238
		$this->import($post_info);
0 ignored issues
show
Bug introduced by
It seems like $post_info defined by $this->get_info($pid) on line 237 can also be of type null; however, TimberCore::import() does only seem to accept array|object, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
239
		/* deprecated, adding for support for older themes */
240
		$this->display_date = $this->date();
0 ignored issues
show
Deprecated Code introduced by
The property TimberPost::$display_date has been deprecated with message: since 0.21.7

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
241
		//cant have a function, so gots to do it this way
242
		$post_class = $this->post_class();
243
		$this->class = $post_class;
244
	}
245
246
	/**
247
	 * Get the URL that will edit the current post/object
248
	 * @internal
249
	 * @see TimberPost::edit_link
250
	 * @return bool|string
251
	 */
252
	function get_edit_url() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
253
		if ( $this->can_edit() ) {
254
			return get_edit_post_link($this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
255
		}
256
	}
257
258
	/**
259
	 * updates the post_meta of the current object with the given value
260
	 * @param string $field
261
	 * @param mixed $value
262
	 */
263
	public function update( $field, $value ) {
264
		if ( isset($this->ID) ) {
265
			update_post_meta($this->ID, $field, $value);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
266
			$this->$field = $value;
267
		}
268
	}
269
270
271
	/**
272
	 * takes a mix of integer (post ID), string (post slug),
273
	 * or object to return a WordPress post object from WP's built-in get_post() function
274
	 * @internal
275
	 * @param mixed $pid
276
	 * @return WP_Post on success
277
	 */
278
	protected function prepare_post_info( $pid = 0 ) {
279
		if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) {
0 ignored issues
show
introduced by
Found "=== 0". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
280
			$pid = self::check_post_id($pid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
281
			$post = get_post($pid);
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
282
			if ( $post ) {
283
				return $post;
284
			} else {
285
				$post = get_page($pid);
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
286
				return $post;
287
			}
288
		}
289
		//we can skip if already is WP_Post
290
		return $pid;
291
	}
292
293
294
	/**
295
	 * helps you find the post id regardless of whether you send a string or whatever
296
	 * @param integer $pid ;
297
	 * @internal
298
	 * @return integer ID number of a post
299
	 */
300
	protected function check_post_id( $pid ) {
301
		if ( is_numeric($pid) && $pid === 0 ) {
0 ignored issues
show
introduced by
Found "=== 0". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
302
			$pid = get_the_ID();
303
			return $pid;
304
		}
305
		if ( !is_numeric($pid) && is_string($pid) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
306
			$pid = self::get_post_id_by_name($pid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
307
			return $pid;
308
		}
309
		if ( !$pid ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
310
			return null;
311
		}
312
		return $pid;
313
	}
314
315
316
	/**
317
	 * get_post_id_by_name($post_name)
318
	 * @internal
319
	 * @param string $post_name
320
	 * @return int
321
	 */
322
	static function get_post_id_by_name($post_name) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
323
		global $wpdb;
324
		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
325
		$result = $wpdb->get_row($query);
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
326
		if (!$result) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
327
			return null;
328
		}
329
		return $result->ID;
330
	}
331
332
	/**
333
	 * get a preview of your post, if you have an excerpt it will use that,
334
	 * otherwise it will pull from the post_content.
335
	 * If there's a <!-- more --> tag it will use that to mark where to pull through.
336
	 * @api
337
	 * @example
338
	 * ```twig
339
	 * <p>{{post.get_preview(50)}}</p>
340
	 * ```
341
	 * @param int $len The number of words that WP should use to make the tease. (Isn't this better than [this mess](http://wordpress.org/support/topic/changing-the-default-length-of-the_excerpt-1?replies=14)?). If you've set a post_excerpt on a post, we'll use that for the preview text; otherwise the first X words of the post_content
342
	 * @param bool $force What happens if your custom post excerpt is longer then the length requested? By default (`$force = false`) it will use the full `post_excerpt`. However, you can set this to true to *force* your excerpt to be of the desired length
343
	 * @param string $readmore The text you want to use on the 'readmore' link
344
	 * @param bool $strip Strip tags? yes or no. tell me!
345
	 * @return string of the post preview
346
	 */
347
	function get_preview($len = 50, $force = false, $readmore = 'Read More', $strip = true) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
348
		$text = '';
349
		$trimmed = false;
350
		if ( isset($this->post_excerpt) && strlen($this->post_excerpt) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
351
			if ( $force ) {
352
				$text = TimberHelper::trim_words($this->post_excerpt, $len, false);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
353
				$trimmed = true;
354
			} else {
355
				$text = $this->post_excerpt;
356
			}
357
		}
358
		if ( !strlen($text) && preg_match('/<!--\s?more(.*?)?-->/', $this->post_content, $readmore_matches) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
359
			$pieces = explode($readmore_matches[0], $this->post_content);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
360
			$text = $pieces[0];
361
			if ( $force ) {
362
				$text = TimberHelper::trim_words($text, $len, false);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
363
				$trimmed = true;
364
			}
365
			$text = do_shortcode( $text );
366
		}
367
		if ( !strlen($text) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
368
			$text = TimberHelper::trim_words($this->get_content(), $len, false);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
369
			$trimmed = true;
370
		}
371
		if ( !strlen(trim($text)) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
372
			return trim($text);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
373
		}
374
		if ( $strip ) {
375
			$text = trim(strip_tags($text));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
376
		}
377
		if ( strlen($text) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
378
			$text = trim($text);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
379
			$last = $text[strlen($text) - 1];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
380
			if ( $last != '.' && $trimmed ) {
381
				$text .= ' &hellip; ';
382
			}
383
			if ( !$strip ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
384
				$last_p_tag = strrpos($text, '</p>');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
385
				if ( $last_p_tag !== false ) {
0 ignored issues
show
introduced by
Found "!== false". Use Yoda Condition checks, you must
Loading history...
386
					$text = substr($text, 0, $last_p_tag);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
387
				}
388
				if ( $last != '.' && $trimmed ) {
389
					$text .= ' &hellip; ';
390
				}
391
			}
392
			$read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more");
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
Coding Style Comprehensibility introduced by
The string literal read-more does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
393
			if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
394
				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
395
			} elseif ( $readmore ) {
396
				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
397
			}
398
			if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) {
0 ignored issues
show
Bug introduced by
The variable $last_p_tag does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
399
				$text .= '</p>';
400
			}
401
		}
402
		return trim($text);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
403
	}
404
405
	/**
406
	 * gets the post custom and attaches it to the current object
407
	 * @internal
408
	 * @param bool|int $pid a post ID number
409
	 */
410
	function import_custom( $pid = false ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
411
		if ( !$pid ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
412
			$pid = $this->ID;
413
		}
414
		$customs = $this->get_post_custom($pid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
415
		$this->import($customs);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
416
	}
417
418
	/**
419
	 * Used internally to fetch the metadata fields (wp_postmeta table)
420
	 * and attach them to our TimberPost object
421
	 * @internal
422
	 * @param int $pid
423
	 * @return array
424
	 */
425
	protected function get_post_custom( $pid ) {
426
		apply_filters('timber_post_get_meta_pre', array(), $pid, $this);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
427
		$customs = get_post_custom($pid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
428
		if ( !is_array($customs) || empty($customs) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
429
			return array();
430
		}
431 View Code Duplication
		foreach ( $customs as $key => $value ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
432
			if ( is_array($value) && count($value) == 1 && isset($value[0]) ) {
0 ignored issues
show
introduced by
Found "== 1". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
433
				$value = $value[0];
434
			}
435
			$customs[$key] = maybe_unserialize($value);
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
436
		}
437
		$customs = apply_filters('timber_post_get_meta', $customs, $pid, $this);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
438
		return $customs;
439
	}
440
441
	/**
442
	 * @internal
443
	 * @see TimberPost::thumbnail
444
	 * @return null|TimberImage
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
445
	 */
446
	function get_thumbnail() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
447
		if ( function_exists('get_post_thumbnail_id') ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
448
			$tid = get_post_thumbnail_id($this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
449
			if ( $tid ) {
450
				return new $this->ImageClass($tid);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
451
			}
452
		}
453
	}
454
455
	/**
456
	 * @internal
457
	 * @see TimberPost::link
458
	 * @return string
459
	 */
460
	function get_permalink() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
461
		if ( isset($this->_permalink) ) {
462
			return $this->_permalink;
463
		}
464
		$this->_permalink = get_permalink($this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
465
		return $this->_permalink;
466
	}
467
468
	/**
469
	 * get the permalink for a post object
470
	 * In your templates you should use link:
471
	 * <a href="{{post.link}}">Read my post</a>
472
	 * @internal
473
	 * @return string
474
	 */
475
	function get_link() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
476
		return $this->get_permalink();
477
	}
478
479
	/**
480
	 * Get the next post in WordPress's ordering
481
	 * @internal
482
	 * @param bool $taxonomy
483
	 * @return TimberPost|boolean
484
	 */
485
	function get_next( $taxonomy = false ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
486
		if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
487
			global $post;
488
			$this->_next = array();
489
			$old_global = $post;
490
			$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
491
			if ( $taxonomy ) {
492
				$adjacent = get_adjacent_post(true, '', false, $taxonomy);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
493
			} else {
494
				$adjacent = get_adjacent_post(false, '', false);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
495
			}
496
497
			if ( $adjacent ) {
498
				$this->_next[$taxonomy] = new $this->PostClass($adjacent);
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
499
			} else {
500
				$this->_next[$taxonomy] = false;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
501
			}
502
			$post = $old_global;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
503
		}
504
		return $this->_next[$taxonomy];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
505
	}
506
507
	/**
508
	 * Get a data array of pagination so you can navigate to the previous/next for a paginated post
509
	 * @return array
510
	 */
511
	public function get_pagination() {
512
		global $post, $page, $numpages, $multipage;
513
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
514
		$ret = array();
515
		if ( $multipage ) {
516
			for ( $i = 1; $i <= $numpages; $i++ ) {
517
				$link = self::get_wp_link_page($i);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
518
				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
519
				if ( $i == $page ) {
520
					$data['current'] = true;
521
				}
522
				$ret['pages'][] = $data;
523
			}
524
			$i = $page - 1;
525
			if ( $i ) {
526
				$link = self::get_wp_link_page($i);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
527
				$ret['prev'] = array('link' => $link);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
528
			}
529
			$i = $page + 1;
530
			if ( $i <= $numpages ) {
531
				$link = self::get_wp_link_page($i);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
532
				$ret['next'] = array('link' => $link);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
533
			}
534
		}
535
		return $ret;
536
	}
537
538
	/**
539
	 * @param int $i
540
	 * @return string
541
	 */
542
	protected static function get_wp_link_page($i) {
543
		$link = _wp_link_page($i);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
544
		$link = new SimpleXMLElement($link . '</a>');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
545
		if ( isset($link['href']) ) {
546
			return $link['href'];
547
		}
548
		return '';
549
	}
550
551
	/**
552
	 * Get the permalink for a post, but as a relative path
553
	 * For example, where {{post.link}} would return "http://example.org/2015/07/04/my-cool-post"
554
	 * this will return the relative version: "/2015/07/04/my-cool-post"
555
	 * @internal
556
	 * @return string
557
	 */
558
	function get_path() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
559
		return TimberURLHelper::get_rel_url($this->get_link());
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
560
	}
561
562
	/**
563
	 * Get the next post in WordPress's ordering
564
	 * @internal
565
	 * @param bool $taxonomy
566
	 * @return TimberPost|boolean
567
	 */
568
	function get_prev( $taxonomy = false ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
569
		if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) {
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
570
			return $this->_prev[$taxonomy];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
571
		}
572
		global $post;
573
		$old_global = $post;
574
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
575
		$within_taxonomy = ($taxonomy) ? $taxonomy : 'category';
576
		$adjacent = get_adjacent_post(($taxonomy), '', true, $within_taxonomy);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
577
		$prev_in_taxonomy = false;
578
		if ( $adjacent ) {
579
			$prev_in_taxonomy = new $this->PostClass($adjacent);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
580
		}
581
		$this->_prev[$taxonomy] = $prev_in_taxonomy;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
582
		$post = $old_global;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
583
		return $this->_prev[$taxonomy];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
584
	}
585
586
	/**
587
	 * Get the parent post of the post
588
	 * @internal
589
	 * @return bool|TimberPost
0 ignored issues
show
Documentation introduced by
Should the return type not be false|object?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
590
	 */
591
	function get_parent() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
592
		if ( !$this->post_parent ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
593
			return false;
594
		}
595
		return new $this->PostClass($this->post_parent);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
596
	}
597
598
	/**
599
	 * Gets a User object from the author of the post
600
	 * @internal
601
	 * @see TimberPost::author
602
	 * @return bool|TimberUser
0 ignored issues
show
Documentation introduced by
Should the return type not be TimberUser|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
603
	 */
604
	function get_author() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
605
		if ( isset($this->post_author) ) {
606
			return new TimberUser($this->post_author);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
607
		}
608
	}
609
610
	/**
611
	 * @internal
612
	 * @return bool|TimberUser
0 ignored issues
show
Documentation introduced by
Should the return type not be TimberUser|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
613
	 */
614
	function get_modified_author() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
615
		$user_id = get_post_meta($this->ID, '_edit_last', true);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
616
		return ($user_id ? new TimberUser($user_id) : $this->get_author());
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
617
	}
618
619
	/**
620
	 * Used internally by init, etc. to build TimberPost object
621
	 * @internal
622
	 * @param  int $pid
623
	 * @return null|object|WP_Post
624
	 */
625
	protected function get_info($pid) {
626
		$post = $this->prepare_post_info($pid);
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
627
		if ( !isset($post->post_status) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
628
			return null;
629
		}
630
		$post->status = $post->post_status;
631
		$post->id = $post->ID;
632
		$post->slug = $post->post_name;
633
		$customs = $this->get_post_custom($post->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
634
		$post->custom = $customs;
635
		$post = (object) array_merge((array)$customs, (array)$post);
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space before opening casting parenthesis is prohibited
Loading history...
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
636
		return $post;
637
	}
638
639
	/**
640
	 * Get the human-friendly date that should actually display in a .twig template
641
	 * @deprecated since 0.20.0
642
	 * @see TimberPost::date
643
	 * @param string $use
644
	 * @return string
645
	 */
646
	function get_display_date( $use = 'post_date' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
647
		return date(get_option('date_format'), strtotime($this->$use));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
648
	}
649
650
	/**
651
	 * @internal
652
	 * @see TimberPost::date
653
	 * @param  string $date_format
654
	 * @return string
655
	 */
656
	function get_date( $date_format = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
657
		$df = $date_format ? $date_format : get_option('date_format');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
658
		$the_date = (string)mysql2date($df, $this->post_date);
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
659
		return apply_filters('get_the_date', $the_date, $df);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
660
	}
661
662
	/**
663
	 * @internal
664
	 * @param  string $date_format
665
	 * @return string
666
	 */
667
	function get_modified_date( $date_format = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
668
		$df = $date_format ? $date_format : get_option('date_format');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
669
		$the_time = $this->get_modified_time($df);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
670
		return apply_filters('get_the_modified_date', $the_time, $date_format);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
671
	}
672
673
	/**
674
	 * @internal
675
	 * @param  string $time_format
676
	 * @return string
677
	 */
678
	function get_modified_time( $time_format = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
679
		$tf = $time_format ? $time_format : get_option('time_format');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
680
		$the_time = get_post_modified_time($tf, false, $this->ID, true);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
681
		return apply_filters('get_the_modified_time', $the_time, $time_format);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
682
	}
683
684
	/**
685
	 * @internal
686
	 * @see TimberPost::children
687
	 * @param string 		$post_type
688
	 * @param bool|string 	$childPostClass
689
	 * @return array
690
	 */
691
	function get_children( $post_type = 'any', $childPostClass = false ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
692
		if ( $childPostClass === false ) {
0 ignored issues
show
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
693
			$childPostClass = $this->PostClass;
694
		}
695
		if ( $post_type == 'parent' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
696
			$post_type = $this->post_type;
697
		}
698
		$children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
699
		foreach ( $children as &$child ) {
700
			$child = new $childPostClass($child->ID);
701
		}
702
		$children = array_values($children);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
703
		return $children;
704
	}
705
706
	/**
707
	 * Get the comments for a post
708
	 * @internal
709
	 * @see TimberPost::comments
710
	 * @param int $ct
711
	 * @param string $order
712
	 * @param string $type
713
	 * @param string $status
714
	 * @param string $CommentClass
715
	 * @return array|mixed
716
	 */
717
718
	function get_comments($ct = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') {
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
719
720
		global $overridden_cpage, $user_ID;
721
		$overridden_cpage = false;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
722
723
		$commenter = wp_get_current_commenter();
724
		$comment_author_email = $commenter['comment_author_email'];
725
726
		$args = array('post_id' => $this->ID, 'status' => $status, 'order' => $order);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
727
		if ( $ct > 0 ) {
728
			$args['number'] = $ct;
729
		}
730
		if ( strtolower($order) == 'wp' || strtolower($order) == 'wordpress' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
731
			$args['order'] = get_option('comment_order');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
732
		}
733
734
		if ( $user_ID ) {
735
			$args['include_unapproved'] = array( $user_ID );
736
		} elseif ( ! empty( $comment_author_email ) ) {
737
			$args['include_unapproved'] = array( $comment_author_email );
738
		}
739
740
		$comments = get_comments($args);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
741
		$timber_comments = array();
742
743
		if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
744
			set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
745
			$overridden_cpage = true;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
746
		}
747
748
        foreach( $comments as $key => &$comment ) {
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
749
            $timber_comment = new $CommentClass($comment);
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
750
            $timber_comments[$timber_comment->id] = $timber_comment;
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
751
        }
0 ignored issues
show
Coding Style introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
752
753
		foreach( $timber_comments as $key => $comment ) {
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
introduced by
No space before opening parenthesis is prohibited
Loading history...
754
			if ( $comment->is_child() ) {
755
				unset($timber_comments[$comment->id]);
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
756
757
				if ( isset($timber_comments[$comment->comment_parent]) ) {
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
758
					$timber_comments[$comment->comment_parent]->children[] = $comment;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
759
				}
760
			}
761
		}
762
763
		$timber_comments = array_values($timber_comments);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
764
765
		return $timber_comments;
766
	}
767
768
	/**
769
	 * Get the categories for a post
770
	 * @internal
771
	 * @see TimberPost::categories
772
	 * @return array of TimberTerms
773
	 */
774
	function get_categories() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
775
		return $this->get_terms('category');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
776
	}
777
778
	/**
779
	 * @internal
780
	 * @see TimberPost::category
781
	 * @return mixed
782
	 */
783
	function get_category( ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
784
		$cats = $this->get_categories();
785
		if ( count($cats) && isset($cats[0]) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
786
			return $cats[0];
787
		}
788
	}
789
790
	/**
791
	 * @internal
792
	 * @param string|array $tax
793
	 * @param bool $merge
794
	 * @param string $TermClass
795
	 * @return array
796
	 */
797
	function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
798
799
		$TermClass = $TermClass ?: $this->TermClass;
800
801
		if ( is_string($merge) && class_exists($merge) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
802
			$TermClass = $merge;
803
		}
804
		if ( is_array($tax) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
805
			$taxonomies = $tax;
806
		}
807
		if ( is_string($tax) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
808
			if ( in_array($tax, array('all','any','')) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
Expected 1 space between comma and "'any'"; 0 found
Loading history...
introduced by
Expected 1 space between comma and "''"; 0 found
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
809
				$taxonomies = get_object_taxonomies($this->post_type);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
810
			} else {
811
				$taxonomies = array($tax);
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
812
			}
813
		}
814
815
		$term_class_objects = array();
816
817
		foreach ( $taxonomies as $taxonomy ) {
0 ignored issues
show
Bug introduced by
The variable $taxonomies does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
818
			if ( in_array($taxonomy, array('tag','tags')) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
Expected 1 space between comma and "'tags'"; 0 found
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
819
				$taxonomy = 'post_tag';
820
			}
821
			if ( $taxonomy == 'categories' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
822
				$taxonomy = 'category';
823
			}
824
825
			$terms = wp_get_post_terms($this->ID, $taxonomy);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
826
827
			if ( is_wp_error($terms) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
828
				/* @var $terms WP_Error */
829
				TimberHelper::error_log("Error retrieving terms for taxonomy '$taxonomy' on a post in timber-post.php");
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
830
				TimberHelper::error_log('tax = ' . print_r($tax, true));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
The use of function print_r() is discouraged
Loading history...
831
				TimberHelper::error_log('WP_Error: ' . $terms->get_error_message());
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
832
833
				return $term_class_objects;
834
			}
835
836
			// map over array of wordpress terms, and transform them into instances of the TermClass
837
			$terms = array_map(function($term) use ($TermClass, $taxonomy) {
838
				return call_user_func(array($TermClass, 'from'), $term->term_id, $taxonomy);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
839
			}, $terms);
840
841
			if ( $merge && is_array($terms) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
842
				$term_class_objects = array_merge($term_class_objects, $terms);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
843
			} else if ( count($terms) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
844
				$term_class_objects[$taxonomy] = $terms;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
845
			}
846
		}
847
		return $term_class_objects;
848
	}
849
850
	/**
851
	 * @param string|int $term_name_or_id
852
	 * @param string $taxonomy
853
	 * @return bool
854
	 */
855
	function has_term( $term_name_or_id, $taxonomy = 'all' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
856
		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
857
			$taxes = get_object_taxonomies($this->post_type, 'names');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
858
			$ret = false;
859
			foreach ( $taxes as $tax ) {
860
				if ( has_term($term_name_or_id, $tax, $this->ID) ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
861
					$ret = true;
862
					break;
863
				}
864
			}
865
			return $ret;
866
		}
867
		return has_term($term_name_or_id, $taxonomy, $this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
868
	}
869
870
	/**
871
	 * @param string $field
872
	 * @return TimberImage
873
	 */
874
	function get_image( $field ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
875
		return new $this->ImageClass($this->$field);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
876
	}
877
878
	/**
879
	 * Gets an array of tags for you to use
880
	 * @internal
881
	 * @example
882
	 * ```twig
883
	 * <ul class="tags">
884
	 *     {% for tag in post.tags %}
885
	 *         <li>{{tag.name}}</li>
886
	 *     {% endfor %}
887
	 * </ul>
888
	 * ```
889
	 * @return array
890
	 */
891
	function get_tags() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
892
		return $this->get_terms('post_tag');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
893
	}
894
895
	/**
896
	 * Outputs the title with filters applied
897
	 * @internal
898
	 * @example
899
	 * ```twig
900
	 * <h1>{{post.get_title}}</h1>
901
	 * ```
902
	 * ```html
903
	 * <h1>Hello World!</h1>
904
	 * ```
905
	 * @return string
906
	 */
907
	function get_title() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
908
		return apply_filters('the_title', $this->post_title, $this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
909
	}
910
911
	/**
912
	 * Displays the content of the post with filters, shortcodes and wpautop applied
913
	 * @example
914
	 * ```twig
915
	 * <div class="article-text">{{post.get_content}}</div>
916
	 * ```
917
	 * ```html
918
	 * <div class="article-text"><p>Blah blah blah</p><p>More blah blah blah.</p></div>
919
	 * ```
920
	 * @param int $len
921
	 * @param int $page
922
	 * @return string
923
	 */
924
	function get_content( $len = 0, $page = 0 ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
introduced by
Overridding WordPress globals is prohibited
Loading history...
925
		if ( $len == 0 && $page == 0 && $this->_content ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
926
			return $this->_content;
927
		}
928
		$content = $this->post_content;
929
		if ( $len ) {
930
			$content = wp_trim_words($content, $len);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
931
		}
932
		if ( $page ) {
933
			$contents = explode('<!--nextpage-->', $content);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
934
			$page--;
935
			if ( count($contents) > $page ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
936
				$content = $contents[$page];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
937
			}
938
		}
939
		$content = apply_filters('the_content', ($content));
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
940
		if ( $len == 0 && $page == 0 ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
941
			$this->_content = $content;
942
		}
943
		return $content;
944
	}
945
946
	/**
947
	 * @return string
948
	 */
949
	function get_paged_content() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
950
		global $page;
951
		return $this->get_content(0, $page);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
952
	}
953
	/**
954
	 *
955
	 * Here is my summary
956
	 * @example
957
	 * ```twig
958
	 * This post is from <span>{{ post.get_post_type.labels.plural }}</span>
959
	 * ```
960
	 *
961
	 * ```html
962
	 * This post is from <span>Recipes</span>
963
	 * ```
964
	 * @return mixed
965
	 */
966
	public function get_post_type() {
967
		return get_post_type_object($this->post_type);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
968
	}
969
970
	/**
971
	 * @return int the number of comments on a post
972
	 */
973
	public function get_comment_count() {
974
		if ( isset($this->ID) ) {
975
			return get_comments_number($this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
976
		}
977
		return 0;
978
	}
979
980
	/**
981
	 * @param string $field_name
982
	 * @return mixed
983
	 */
984
	public function get_field( $field_name ) {
985
		$value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
986
		if ( $value === null ) {
987
			$value = get_post_meta($this->ID, $field_name);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
988
			if ( is_array($value) && count($value) == 1 ) {
0 ignored issues
show
introduced by
Found "== 1". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
989
				$value = $value[0];
990
			}
991
			if ( is_array($value) && count($value) == 0 ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
992
				$value = null;
993
			}
994
		}
995
		$value = apply_filters('timber_post_get_meta_field', $value, $this->ID, $field_name, $this);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
996
		return $value;
997
	}
998
999
	/**
1000
	 * @param string $field_name
1001
	 */
1002
	function import_field( $field_name ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1003
		$this->$field_name = $this->get_field($field_name);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1004
	}
1005
1006
	/**
1007
	 * @internal
1008
	 * @return mixed
1009
	 */
1010
	function get_format() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1011
		return get_post_format($this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1012
	}
1013
1014
	/**
1015
	 * Get the CSS classes for a post. For usage you should use `{{post.class}}` instead of `{{post.post_class}}`
1016
	 * @internal
1017
	 * @param string $class additional classes you want to add
1018
	 * @see TimberPost::$class
1019
	 * @example
1020
	 * ```twig
1021
	 * <article class="{{ post.class }}">
1022
	 *    {# Some stuff here #}
1023
	 * </article>
1024
	 * ```
1025
	 *
1026
	 * ```html
1027
	 * <article class="post-2612 post type-post status-publish format-standard has-post-thumbnail hentry category-data tag-charleston-church-shooting tag-dylann-roof tag-gun-violence tag-hate-crimes tag-national-incident-based-reporting-system">
1028
	 *    {# Some stuff here #}
1029
	 * </article>
1030
	 * ```
1031
	 * @return string a space-seperated list of classes
1032
	 */
1033
	public function post_class( $class='' ) {
0 ignored issues
show
introduced by
Expected 1 space between argument "$class" and equals sign; 0 found
Loading history...
introduced by
Expected 1 space between default value and equals sign for argument "$class";
Loading history...
1034
		global $post;
1035
		$old_global_post = $post;
1036
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1037
		$class_array = get_post_class($class, $this->ID);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1038
		$post = $old_global_post;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1039
		if ( is_array($class_array) ){
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1040
			return implode(' ', $class_array);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1041
		}
1042
		return $class_array;
1043
	}
1044
1045
	// Docs
1046
1047
	/**
1048
	 * @return array
1049
	 * @codeCoverageIgnore
1050
	 */
1051
	public function get_method_values() {
1052
		$ret = parent::get_method_values();
1053
		$ret['author'] = $this->author();
1054
		$ret['categories'] = $this->categories();
1055
		$ret['category'] = $this->category();
1056
		$ret['children'] = $this->children();
1057
		$ret['comments'] = $this->comments();
1058
		$ret['content'] = $this->content();
1059
		$ret['edit_link'] = $this->edit_link();
1060
		$ret['format'] = $this->format();
1061
		$ret['link'] = $this->link();
1062
		$ret['next'] = $this->next();
1063
		$ret['pagination'] = $this->pagination();
1064
		$ret['parent'] = $this->parent();
1065
		$ret['path'] = $this->path();
1066
		$ret['prev'] = $this->prev();
1067
		$ret['terms'] = $this->terms();
1068
		$ret['tags'] = $this->tags();
1069
		$ret['thumbnail'] = $this->thumbnail();
1070
		$ret['title'] = $this->title();
1071
		return $ret;
1072
	}
1073
1074
	/**
1075
	 * Return the author of a post
1076
	 * @api
1077
	 * @example
1078
	 * ```twig
1079
	 * <h1>{{post.title}}</h1>
1080
	 * <p class="byline">
1081
	 *     <a href="{{post.author.link}}">{{post.author.name}}</a>
1082
	 * </p>
1083
	 * ```
1084
	 * @return TimberUser|bool A TimberUser object if found, false if not
0 ignored issues
show
Documentation introduced by
Should the return type not be TimberUser|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1085
	 */
1086
	public function author() {
1087
		return $this->get_author();
1088
	}
1089
1090
	/**
1091
	 * Get the author (WordPress user) who last modified the post
1092
	 * @example
1093
	 * ```twig
1094
	 * Last updated by {{ post.modified_author.name }}
1095
	 * ```
1096
	 * ```html
1097
	 * Last updated by Harper Lee
1098
	 * ```
1099
	 * @return TimberUser|bool A TimberUser object if found, false if not
0 ignored issues
show
Documentation introduced by
Should the return type not be TimberUser|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1100
	 */
1101
	public function modified_author() {
1102
		return $this->get_modified_author();
1103
	}
1104
1105
	/**
1106
	 * Get the categoires on a particular post
1107
	 * @api
1108
	 * @return array of TimberTerms
1109
	 */
1110
	public function categories() {
1111
		return $this->get_terms('category');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1112
	}
1113
1114
	/**
1115
	 * Returns a category attached to a post
1116
	 * @api
1117
	 * If mulitpuile categories are set, it will return just the first one
1118
	 * @return TimberTerm|null
1119
	 */
1120
	public function category() {
1121
		return $this->get_category();
1122
	}
1123
1124
	/**
1125
	 * Returns an array of children on the post as TimberPosts
1126
	 * (or other claass as you define).
1127
	 * @api
1128
	 * @example
1129
	 * ```twig
1130
	 * {% if post.children %}
1131
	 *     Here are the child pages:
1132
	 *     {% for child in page.children %}
1133
	 *         <a href="{{ child.link }}">{{ child.title }}</a>
1134
	 *     {% endfor %}
1135
	 * {% endif %}
1136
	 * ```
1137
	 * @param string $post_type _optional_ use to find children of a particular post type (attachment vs. page for example). You might want to restrict to certain types of children in case other stuff gets all mucked in there. You can use 'parent' to use the parent's post type
1138
	 * @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.
1139
	 * @return array
1140
	 */
1141
	public function children( $post_type = 'any', $childPostClass = false ) {
1142
		return $this->get_children( $post_type, $childPostClass );
1143
	}
1144
1145
	/**
1146
	 * Gets the comments on a TimberPost and returns them as an array of [TimberComments](#TimberComment) (or whatever comment class you set).
1147
	 * @api
1148
	 * @param int $count Set the number of comments you want to get. `0` is analogous to "all"
1149
	 * @param string $order use ordering set in WordPress admin, or a different scheme
1150
	 * @param string $type For when other plugins use the comments table for their own special purposes, might be set to 'liveblog' or other depending on what's stored in yr comments table
1151
	 * @param string $status Could be 'pending', etc.
1152
	 * @param string $CommentClass What class to use when returning Comment objects. As you become a Timber pro, you might find yourself extending TimberComment for your site or app (obviously, totally optional)
1153
	 * @example
1154
	 * ```twig
1155
	 * {# single.twig #}
1156
	 * <h4>Comments:</h4>
1157
	 * {% for comment in post.comments %}
1158
	 * 	<div class="comment-{{comment.ID}} comment-order-{{loop.index}}">
1159
	 * 		<p>{{comment.author.name}} said:</p>
1160
	 * 		<p>{{comment.content}}</p>
1161
	 * 	</div>
1162
	 * {% endfor %}
1163
	 * ```
1164
	 * @return bool|array
1165
	 */
1166
	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1167
		return $this->get_comments($count, $order, $type, $status, $CommentClass);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1168
	}
1169
1170
	/**
1171
	 * Gets the actual content of a WP Post, as opposed to post_content this will run the hooks/filters attached to the_content. \This guy will return your posts content with WordPress filters run on it (like for shortcodes and wpautop).
1172
	 * @api
1173
	 * @example
1174
	 * ```twig
1175
	 * <div class="article">
1176
	 *     <h2>{{post.title}}</h2>
1177
	 *     <div class="content">{{ post.content }}</div>
1178
	 * </div>
1179
	 * ```
1180
	 * @param int $page
1181
	 * @return string
1182
	 */
1183
	public function content( $page = 0 ) {
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1184
		return $this->get_content(0, $page);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1185
	}
1186
1187
	/**
1188
	 * @return string
1189
	 */
1190
	public function paged_content() {
1191
		return $this->get_paged_content();
1192
	}
1193
1194
	/**
1195
	 * Get the date to use in your template!
1196
	 * @api
1197
	 * @example
1198
	 * ```twig
1199
	 * Published on {{ post.date }} // Uses WP's formatting set in Admin
1200
	 * OR
1201
	 * Published on {{ post.date | date('F jS') }} // Jan 12th
1202
	 * ```
1203
	 *
1204
	 * ```html
1205
	 * Published on January 12, 2015
1206
	 * OR
1207
	 * Published on Jan 12th
1208
	 * ```
1209
	 * @param string $date_format
1210
	 * @return string
1211
	 */
1212
	public function date( $date_format = '' ) {
1213
		return $this->get_date($date_format);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1214
	}
1215
1216
	/**
1217
	 * Get the time to use in your template
1218
	 * @api
1219
	 * @example
1220
	 * ```twig
1221
	 * Published at {{ post.time }} // Uses WP's formatting set in Admin
1222
	 * OR
1223
	 * Published at {{ post.time | time('G:i') }} // 13:25
1224
	 * ```
1225
	 *
1226
	 * ```html
1227
	 * Published at 1:25 pm
1228
	 * OR
1229
	 * Published at 13:25
1230
	 * ```
1231
	 * @param string $time_format
1232
	 * @return string
1233
	 */
1234
	public function time( $time_format = '' ) {
1235
		$tf = $time_format ? $time_format : get_option('time_format');
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1236
	 	$the_time = (string)mysql2date($tf, $this->post_date);
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1237
	 	return apply_filters('get_the_time', $the_time, $tf);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1238
	}
1239
1240
	/**
1241
	 * @return bool|string
1242
	 */
1243
	public function edit_link() {
1244
		return $this->get_edit_url();
1245
	}
1246
1247
	/**
1248
	 * @api
1249
	 * @return mixed
1250
	 */
1251
	public function format() {
1252
		return $this->get_format();
1253
	}
1254
1255
	/**
1256
	 * get the permalink for a post object
1257
	 * @api
1258
	 * @example
1259
	 * ```twig
1260
	 * <a href="{{post.link}}">Read my post</a>
1261
	 * ```
1262
	 * @return string ex: http://example.org/2015/07/my-awesome-post
1263
	 */
1264
	public function link() {
1265
		return $this->get_permalink();
1266
	}
1267
1268
	/**
1269
	 * @param string $field_name
0 ignored issues
show
Documentation introduced by
Should the type for parameter $field_name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
1270
	 * @return mixed
1271
	 */
1272
	public function meta( $field_name = null ) {
1273
		if ( $field_name === null ) {
1274
			//on the off-chance the field is actually named meta
1275
			$field_name = 'meta';
1276
		}
1277
		return $this->get_field($field_name);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1278
	}
1279
1280
	/**
1281
	 * @return string
1282
	 */
1283
	public function name(){
1284
		return $this->title();
1285
	}
1286
1287
	/**
1288
	 * @param string $date_format
1289
	 * @return string
1290
	 */
1291
	public function modified_date( $date_format = '' ) {
1292
		return $this->get_modified_date($date_format);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1293
	}
1294
1295
	/**
1296
	 * @param string $time_format
1297
	 * @return string
1298
	 */
1299
	public function modified_time( $time_format = '' ) {
1300
		return $this->get_modified_time($time_format);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1301
	}
1302
1303
	/**
1304
	 * @api
1305
	 * @param bool $in_same_cat
1306
	 * @return mixed
1307
	 */
1308
	public function next( $in_same_cat = false ) {
1309
		return $this->get_next($in_same_cat);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1310
	}
1311
1312
	/**
1313
	 * @return array
1314
	 */
1315
	public function pagination() {
1316
		return $this->get_pagination();
1317
	}
1318
1319
	/**
1320
	 * Gets the parent (if one exists) from a post as a TimberPost object (or whatever is set in TimberPost::$PostClass)
1321
	 * @api
1322
	 * @example
1323
	 * ```twig
1324
	 * Parent page: <a href="{{ post.parent.link }}">{{ post.parent.title }}</a>
1325
	 * ```
1326
	 * @return bool|TimberPost
0 ignored issues
show
Documentation introduced by
Should the return type not be false|object?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1327
	 */
1328
	public function parent() {
1329
		return $this->get_parent();
1330
	}
1331
1332
	/**
1333
	 * Gets the relative path of a WP Post, so while link() will return http://example.org/2015/07/my-cool-post
1334
	 * this will return just /2015/07/my-cool-post
1335
	 * @api
1336
	 * @example
1337
	 * ```twig
1338
	 * <a href="{{post.path}}">{{post.title}}</a>
1339
	 * ```
1340
	 * @return string
1341
	 */
1342
	public function path() {
1343
		return $this->get_path();
1344
	}
1345
1346
	/**
1347
	 * @deprecated 0.20.0 use link() instead
1348
	 * @return string
1349
	 */
1350
	public function permalink() {
1351
		return $this->get_permalink();
1352
	}
1353
1354
	/**
1355
	 * Get the previous post in a set
1356
	 * @api
1357
	 * @example
1358
	 * ```twig
1359
	 * <h4>Prior Entry:</h4>
1360
	 * <h3>{{post.prev.title}}</h3>
1361
	 * <p>{{post.prev.get_preview(25)}}</p>
1362
	 * ```
1363
	 * @param bool $in_same_cat
1364
	 * @return mixed
1365
	 */
1366
	public function prev( $in_same_cat = false ) {
1367
		return $this->get_prev($in_same_cat);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1368
	}
1369
1370
	/**
1371
	 * Get the terms associated with the post
1372
	 * This goes across all taxonomies by default
1373
	 * @api
1374
	 * @param string|array $tax What taxonom(y|ies) to pull from. Defaults to all registered taxonomies for the post type. You can use custom ones, or built-in WordPress taxonomies (category, tag). Timber plays nice and figures out that tag/tags/post_tag are all the same (and categories/category), for custom taxonomies you're on your own.
1375
	 * @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)?
1376
	 * @return array
1377
	 */
1378
	public function terms( $tax = '', $merge = true ) {
1379
		return $this->get_terms($tax, $merge);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1380
	}
1381
1382
	/**
1383
	 * Gets the tags on a post, uses WP's post_tag taxonomy
1384
	 * @api
1385
	 * @return array
1386
	 */
1387
	public function tags() {
1388
		return $this->get_tags();
1389
	}
1390
1391
	/**
1392
	 * get the featured image as a TimberImage
1393
	 * @api
1394
	 * @example
1395
	 * ```twig
1396
	 * <img src="{{post.thumbnail.src}}" />
1397
	 * ```
1398
	 * @return TimberImage|null of your thumbnail
0 ignored issues
show
Documentation introduced by
Should the return type not be object|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1399
	 */
1400
	public function thumbnail() {
1401
		return $this->get_thumbnail();
1402
	}
1403
1404
	/**
1405
	 * Returns the processed title to be used in templates. This returns the title of the post after WP's filters have run. This is analogous to `the_title()` in standard WP template tags.
1406
	 * @api
1407
	 * @example
1408
	 * ```twig
1409
	 * <h1>{{ post.title }}</h1>
1410
	 * ```
1411
	 * @return string
1412
	 */
1413
	public function title() {
1414
		return $this->get_title();
1415
	}
1416
1417
}
1418