Completed
Push — master ( f4bd49...2a749c )
by Jared
15:34 queued 06:31
created

TimberPost::thumbnail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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
			}
285
		}
286
		//we can skip if already is WP_Post
287
		return $pid;
288
	}
289
290
291
	/**
292
	 * helps you find the post id regardless of whether you send a string or whatever
293
	 * @param integer $pid ;
294
	 * @internal
295
	 * @return integer ID number of a post
296
	 */
297
	protected function check_post_id( $pid ) {
298
		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...
299
			$pid = get_the_ID();
300
			return $pid;
301
		}
302
		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...
303
			$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...
304
			return $pid;
305
		}
306
		if ( !$pid ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
307
			return null;
308
		}
309
		return $pid;
310
	}
311
312
313
	/**
314
	 * get_post_id_by_name($post_name)
315
	 * @internal
316
	 * @param string $post_name
317
	 * @return int
318
	 */
319
	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...
320
		global $wpdb;
321
		$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...
322
		$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...
323
		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...
324
			return null;
325
		}
326
		return $result->ID;
327
	}
328
329
	/**
330
	 * get a preview of your post, if you have an excerpt it will use that,
331
	 * otherwise it will pull from the post_content.
332
	 * If there's a <!-- more --> tag it will use that to mark where to pull through.
333
	 * @api
334
	 * @example
335
	 * ```twig
336
	 * <p>{{post.get_preview(50)}}</p>
337
	 * ```
338
	 * @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
339
	 * @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
340
	 * @param string $readmore The text you want to use on the 'readmore' link
341
	 * @param bool $strip Strip tags? yes or no. tell me!
342
	 * @return string of the post preview
343
	 */
344
	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...
345
		$text = '';
346
		$trimmed = false;
347
		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...
348
			if ( $force ) {
349
				$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...
350
				$trimmed = true;
351
			} else {
352
				$text = $this->post_excerpt;
353
			}
354
		}
355
		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...
356
			$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...
357
			$text = $pieces[0];
358
			if ( $force ) {
359
				$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...
360
				$trimmed = true;
361
			}
362
			$text = do_shortcode( $text );
363
		}
364
		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...
365
			$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...
366
			$trimmed = true;
367
		}
368
		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...
369
			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...
370
		}
371
		if ( $strip ) {
372
			$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...
373
		}
374
		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...
375
			$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...
376
			$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...
377
			if ( $last != '.' && $trimmed ) {
378
				$text .= ' &hellip;';
379
			}
380
			if ( !$strip ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
381
				$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...
382
				if ( $last_p_tag !== false ) {
0 ignored issues
show
introduced by
Found "!== false". Use Yoda Condition checks, you must
Loading history...
383
					$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...
384
				}
385
				if ( $last != '.' && $trimmed ) {
386
					$text .= ' &hellip; ';
387
				}
388
			}
389
			$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...
390
			if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
391
				$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...
392
			} elseif ( $readmore ) {
393
				$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...
394
			}
395
			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...
396
				$text .= '</p>';
397
			}
398
		}
399
		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...
400
	}
401
402
	/**
403
	 * gets the post custom and attaches it to the current object
404
	 * @internal
405
	 * @param bool|int $pid a post ID number
406
	 */
407
	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...
408
		if ( !$pid ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
409
			$pid = $this->ID;
410
		}
411
		$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...
412
		$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...
413
	}
414
415
	/**
416
	 * Used internally to fetch the metadata fields (wp_postmeta table)
417
	 * and attach them to our TimberPost object
418
	 * @internal
419
	 * @param int $pid
420
	 * @return array
421
	 */
422
	protected function get_post_custom( $pid ) {
423
		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...
424
		$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...
425
		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...
426
			return array();
427
		}
428 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...
429
			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...
430
				$value = $value[0];
431
			}
432
			$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...
433
		}
434
		$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...
435
		return $customs;
436
	}
437
438
	/**
439
	 * @internal
440
	 * @see TimberPost::thumbnail
441
	 * @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...
442
	 */
443
	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...
444
		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...
445
			$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...
446
			if ( $tid ) {
447
				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...
448
			}
449
		}
450
	}
451
452
	/**
453
	 * @internal
454
	 * @see TimberPost::link
455
	 * @return string
456
	 */
457
	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...
458
		if ( isset($this->_permalink) ) {
459
			return $this->_permalink;
460
		}
461
		$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...
462
		return $this->_permalink;
463
	}
464
465
	/**
466
	 * get the permalink for a post object
467
	 * In your templates you should use link:
468
	 * <a href="{{post.link}}">Read my post</a>
469
	 * @internal
470
	 * @return string
471
	 */
472
	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...
473
		return $this->get_permalink();
474
	}
475
476
	/**
477
	 * Get the next post in WordPress's ordering
478
	 * @internal
479
	 * @param bool $taxonomy
480
	 * @return TimberPost|boolean
481
	 */
482
	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...
483
		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...
484
			global $post;
485
			$this->_next = array();
486
			$old_global = $post;
487
			$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
488
			if ( $taxonomy ) {
489
				$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...
490
			} else {
491
				$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...
492
			}
493
494
			if ( $adjacent ) {
495
				$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...
496
			} else {
497
				$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...
498
			}
499
			$post = $old_global;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
500
		}
501
		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...
502
	}
503
504
	/**
505
	 * Get a data array of pagination so you can navigate to the previous/next for a paginated post
506
	 * @return array
507
	 */
508
	public function get_pagination() {
509
		global $post, $page, $numpages, $multipage;
510
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
511
		$ret = array();
512
		if ( $multipage ) {
513
			for ( $i = 1; $i <= $numpages; $i++ ) {
514
				$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...
515
				$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...
516
				if ( $i == $page ) {
517
					$data['current'] = true;
518
				}
519
				$ret['pages'][] = $data;
520
			}
521
			$i = $page - 1;
522
			if ( $i ) {
523
				$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...
524
				$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...
525
			}
526
			$i = $page + 1;
527
			if ( $i <= $numpages ) {
528
				$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...
529
				$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...
530
			}
531
		}
532
		return $ret;
533
	}
534
535
	/**
536
	 * @param int $i
537
	 * @return string
538
	 */
539
	protected static function get_wp_link_page($i) {
540
		$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...
541
		$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...
542
		if ( isset($link['href']) ) {
543
			return $link['href'];
544
		}
545
		return '';
546
	}
547
548
	/**
549
	 * Get the permalink for a post, but as a relative path
550
	 * For example, where {{post.link}} would return "http://example.org/2015/07/04/my-cool-post"
551
	 * this will return the relative version: "/2015/07/04/my-cool-post"
552
	 * @internal
553
	 * @return string
554
	 */
555
	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...
556
		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...
557
	}
558
559
	/**
560
	 * Get the next post in WordPress's ordering
561
	 * @internal
562
	 * @param bool $taxonomy
563
	 * @return TimberPost|boolean
564
	 */
565
	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...
566
		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...
567
			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...
568
		}
569
		global $post;
570
		$old_global = $post;
571
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
572
		$within_taxonomy = ($taxonomy) ? $taxonomy : 'category';
573
		$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...
574
		$prev_in_taxonomy = false;
575
		if ( $adjacent ) {
576
			$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...
577
		}
578
		$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...
579
		$post = $old_global;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
580
		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...
581
	}
582
583
	/**
584
	 * Get the parent post of the post
585
	 * @internal
586
	 * @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...
587
	 */
588
	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...
589
		if ( !$this->post_parent ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
590
			return false;
591
		}
592
		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...
593
	}
594
595
	/**
596
	 * Gets a User object from the author of the post
597
	 * @internal
598
	 * @see TimberPost::author
599
	 * @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...
600
	 */
601
	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...
602
		if ( isset($this->post_author) ) {
603
			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...
604
		}
605
	}
606
607
	/**
608
	 * @internal
609
	 * @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...
610
	 */
611
	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...
612
		$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...
613
		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...
614
	}
615
616
	/**
617
	 * Used internally by init, etc. to build TimberPost object
618
	 * @internal
619
	 * @param  int $pid
620
	 * @return null|object|WP_Post
621
	 */
622
	protected function get_info($pid) {
623
		$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...
624
		if ( !isset($post->post_status) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
625
			return null;
626
		}
627
		$post->status = $post->post_status;
628
		$post->id = $post->ID;
629
		$post->slug = $post->post_name;
630
		$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...
631
		$post->custom = $customs;
632
		$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...
633
		return $post;
634
	}
635
636
	/**
637
	 * Get the human-friendly date that should actually display in a .twig template
638
	 * @deprecated since 0.20.0
639
	 * @see TimberPost::date
640
	 * @param string $use
641
	 * @return string
642
	 */
643
	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...
644
		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...
645
	}
646
647
	/**
648
	 * @internal
649
	 * @see TimberPost::date
650
	 * @param  string $date_format
651
	 * @return string
652
	 */
653
	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...
654
		$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...
655
		$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...
656
		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...
657
	}
658
659
	/**
660
	 * @internal
661
	 * @param  string $date_format
662
	 * @return string
663
	 */
664
	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...
665
		$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...
666
		$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...
667
		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...
668
	}
669
670
	/**
671
	 * @internal
672
	 * @param  string $time_format
673
	 * @return string
674
	 */
675
	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...
676
		$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...
677
		$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...
678
		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...
679
	}
680
681
	/**
682
	 * @internal
683
	 * @see TimberPost::children
684
	 * @param string 		$post_type
685
	 * @param bool|string 	$childPostClass
686
	 * @return array
687
	 */
688
	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...
689
		if ( $childPostClass === false ) {
0 ignored issues
show
introduced by
Found "=== false". Use Yoda Condition checks, you must
Loading history...
690
			$childPostClass = $this->PostClass;
691
		}
692
		if ( $post_type == 'parent' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
693
			$post_type = $this->post_type;
694
		}
695
		$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...
696
		foreach ( $children as &$child ) {
697
			$child = new $childPostClass($child->ID);
698
		}
699
		$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...
700
		return $children;
701
	}
702
703
704
	/**
705
	 * Get the comments for a post
706
	 * @internal
707
	 * @see TimberPost::comments
708
	 * @param int $ct
709
	 * @param string $order
710
	 * @param string $type
711
	 * @param string $status
712
	 * @param string $CommentClass
713
	 * @return array|mixed
714
	 */
715
716
	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...
717
718
		global $overridden_cpage, $user_ID;
719
		$overridden_cpage = false;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
720
721
		$commenter = wp_get_current_commenter();
722
		$comment_author_email = $commenter['comment_author_email'];
723
724
		$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...
725
		if ( $ct > 0 ) {
726
			$args['number'] = $ct;
727
		}
728
		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...
729
			$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...
730
		}
731
732
		if ( $user_ID ) {
733
			$args['include_unapproved'] = array( $user_ID );
734
		} elseif ( ! empty( $comment_author_email ) ) {
735
			$args['include_unapproved'] = array( $comment_author_email );
736
		}
737
738
		$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...
739
		$timber_comments = array();
740
741
		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...
742
			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...
743
			$overridden_cpage = true;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
744
		}
745
746
		foreach($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...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
747
			$timber_comment = new $CommentClass($comment);
748
			$timber_comments[$timber_comment->id] = $timber_comment;
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
749
		}
750
751
		// Build a flattened (depth=1) comment tree
752
		$comments_tree = array();
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
				continue;
756
			}
757
758
			$tree_element = $comment;
759
			do {
760
				$tree_element = $timber_comments[$tree_element->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...
761
			} while( $tree_element->is_child() );
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
762
763
			$comments_tree[$tree_element->id][] = $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...
764
		}
765
766
		// Add child comments to the relative "super parents"
767
		foreach($comments_tree as $comment_parent => $comment_children) {
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...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
768
			foreach($comment_children as $comment_child) {
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...
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
769
				$timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child];
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
770
				unset($timber_comments[$comment_child]);
0 ignored issues
show
introduced by
Array keys should be surrounded by spaces unless they contain a string or an integer.
Loading history...
771
			}
772
		}
773
774
		$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...
775
776
		return $timber_comments;
777
	}
778
779
	/**
780
	 * Get the categories for a post
781
	 * @internal
782
	 * @see TimberPost::categories
783
	 * @return array of TimberTerms
784
	 */
785
	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...
786
		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...
787
	}
788
789
	/**
790
	 * @internal
791
	 * @see TimberPost::category
792
	 * @return mixed
793
	 */
794
	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...
795
		$cats = $this->get_categories();
796
		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...
797
			return $cats[0];
798
		}
799
	}
800
801
	/**
802
	 * @internal
803
	 * @param string|array $tax
804
	 * @param bool $merge
805
	 * @param string $TermClass
806
	 * @return array
807
	 */
808
	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...
809
810
		$TermClass = $TermClass ?: $this->TermClass;
811
812
		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...
813
			$TermClass = $merge;
814
		}
815
		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...
816
			$taxonomies = $tax;
817
		}
818
		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...
819
			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...
820
				$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...
821
			} else {
822
				$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...
823
			}
824
		}
825
826
		$term_class_objects = array();
827
828
		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...
829
			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...
830
				$taxonomy = 'post_tag';
831
			}
832
			if ( $taxonomy == 'categories' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
833
				$taxonomy = 'category';
834
			}
835
836
			$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...
837
838
			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...
839
				/* @var $terms WP_Error */
840
				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...
841
				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...
842
				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...
843
844
				return $term_class_objects;
845
			}
846
847
			// map over array of wordpress terms, and transform them into instances of the TermClass
848
			$terms = array_map(function($term) use ($TermClass, $taxonomy) {
849
				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...
850
			}, $terms);
851
852
			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...
853
				$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...
854
			} 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...
855
				$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...
856
			}
857
		}
858
		return $term_class_objects;
859
	}
860
861
	/**
862
	 * @param string|int $term_name_or_id
863
	 * @param string $taxonomy
864
	 * @return bool
865
	 */
866
	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...
867
		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
868
			$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...
869
			$ret = false;
870
			foreach ( $taxes as $tax ) {
871
				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...
872
					$ret = true;
873
					break;
874
				}
875
			}
876
			return $ret;
877
		}
878
		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...
879
	}
880
881
	/**
882
	 * @param string $field
883
	 * @return TimberImage
884
	 */
885
	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...
886
		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...
887
	}
888
889
	/**
890
	 * Gets an array of tags for you to use
891
	 * @internal
892
	 * @example
893
	 * ```twig
894
	 * <ul class="tags">
895
	 *     {% for tag in post.tags %}
896
	 *         <li>{{tag.name}}</li>
897
	 *     {% endfor %}
898
	 * </ul>
899
	 * ```
900
	 * @return array
901
	 */
902
	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...
903
		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...
904
	}
905
906
	/**
907
	 * Outputs the title with filters applied
908
	 * @internal
909
	 * @example
910
	 * ```twig
911
	 * <h1>{{post.get_title}}</h1>
912
	 * ```
913
	 * ```html
914
	 * <h1>Hello World!</h1>
915
	 * ```
916
	 * @return string
917
	 */
918
	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...
919
		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...
920
	}
921
922
	/**
923
	 * Displays the content of the post with filters, shortcodes and wpautop applied
924
	 * @example
925
	 * ```twig
926
	 * <div class="article-text">{{post.get_content}}</div>
927
	 * ```
928
	 * ```html
929
	 * <div class="article-text"><p>Blah blah blah</p><p>More blah blah blah.</p></div>
930
	 * ```
931
	 * @param int $len
932
	 * @param int $page
933
	 * @return string
934
	 */
935
	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...
936
		if ( $len == 0 && $page == 0 && $this->_content ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
937
			return $this->_content;
938
		}
939
		$content = $this->post_content;
940
		if ( $len ) {
941
			$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...
942
		}
943
		if ( $page ) {
944
			$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...
945
			$page--;
946
			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...
947
				$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...
948
			}
949
		}
950
		$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...
951
		if ( $len == 0 && $page == 0 ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
952
			$this->_content = $content;
953
		}
954
		return $content;
955
	}
956
957
	/**
958
	 * @return string
959
	 */
960
	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...
961
		global $page;
962
		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...
963
	}
964
	/**
965
	 *
966
	 * Here is my summary
967
	 * @example
968
	 * ```twig
969
	 * This post is from <span>{{ post.get_post_type.labels.plural }}</span>
970
	 * ```
971
	 *
972
	 * ```html
973
	 * This post is from <span>Recipes</span>
974
	 * ```
975
	 * @return mixed
976
	 */
977
	public function get_post_type() {
978
		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...
979
	}
980
981
	/**
982
	 * @return int the number of comments on a post
983
	 */
984
	public function get_comment_count() {
985
		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...
986
	}
987
988
	/**
989
	 * @param string $field_name
990
	 * @return mixed
991
	 */
992
	public function get_field( $field_name ) {
993
		$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...
994
		if ( $value === null ) {
995
			$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...
996
			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...
997
				$value = $value[0];
998
			}
999
			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...
1000
				$value = null;
1001
			}
1002
		}
1003
		$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...
1004
		return $value;
1005
	}
1006
1007
	/**
1008
	 * @param string $field_name
1009
	 */
1010
	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...
1011
		$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...
1012
	}
1013
1014
	/**
1015
	 * @internal
1016
	 * @return mixed
1017
	 */
1018
	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...
1019
		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...
1020
	}
1021
1022
	/**
1023
	 * Get the CSS classes for a post. For usage you should use `{{post.class}}` instead of `{{post.post_class}}`
1024
	 * @internal
1025
	 * @param string $class additional classes you want to add
1026
	 * @see TimberPost::$class
1027
	 * @example
1028
	 * ```twig
1029
	 * <article class="{{ post.class }}">
1030
	 *    {# Some stuff here #}
1031
	 * </article>
1032
	 * ```
1033
	 *
1034
	 * ```html
1035
	 * <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">
1036
	 *    {# Some stuff here #}
1037
	 * </article>
1038
	 * ```
1039
	 * @return string a space-seperated list of classes
1040
	 */
1041
	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...
1042
		global $post;
1043
		$old_global_post = $post;
1044
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1045
		$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...
1046
		$post = $old_global_post;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1047
		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...
1048
			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...
1049
		}
1050
		return $class_array;
1051
	}
1052
1053
	// Docs
1054
1055
	/**
1056
	 * @return array
1057
	 * @codeCoverageIgnore
1058
	 */
1059
	public function get_method_values() {
1060
		$ret = parent::get_method_values();
1061
		$ret['author'] = $this->author();
1062
		$ret['categories'] = $this->categories();
1063
		$ret['category'] = $this->category();
1064
		$ret['children'] = $this->children();
1065
		$ret['comments'] = $this->comments();
1066
		$ret['content'] = $this->content();
1067
		$ret['edit_link'] = $this->edit_link();
1068
		$ret['format'] = $this->format();
1069
		$ret['link'] = $this->link();
1070
		$ret['next'] = $this->next();
1071
		$ret['pagination'] = $this->pagination();
1072
		$ret['parent'] = $this->parent();
1073
		$ret['path'] = $this->path();
1074
		$ret['prev'] = $this->prev();
1075
		$ret['terms'] = $this->terms();
1076
		$ret['tags'] = $this->tags();
1077
		$ret['thumbnail'] = $this->thumbnail();
1078
		$ret['title'] = $this->title();
1079
		return $ret;
1080
	}
1081
1082
	/**
1083
	 * Return the author of a post
1084
	 * @api
1085
	 * @example
1086
	 * ```twig
1087
	 * <h1>{{post.title}}</h1>
1088
	 * <p class="byline">
1089
	 *     <a href="{{post.author.link}}">{{post.author.name}}</a>
1090
	 * </p>
1091
	 * ```
1092
	 * @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...
1093
	 */
1094
	public function author() {
1095
		return $this->get_author();
1096
	}
1097
1098
	/**
1099
	 * Get the author (WordPress user) who last modified the post
1100
	 * @example
1101
	 * ```twig
1102
	 * Last updated by {{ post.modified_author.name }}
1103
	 * ```
1104
	 * ```html
1105
	 * Last updated by Harper Lee
1106
	 * ```
1107
	 * @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...
1108
	 */
1109
	public function modified_author() {
1110
		return $this->get_modified_author();
1111
	}
1112
1113
	/**
1114
	 * Get the categoires on a particular post
1115
	 * @api
1116
	 * @return array of TimberTerms
1117
	 */
1118
	public function categories() {
1119
		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...
1120
	}
1121
1122
	/**
1123
	 * Returns a category attached to a post
1124
	 * @api
1125
	 * If mulitpuile categories are set, it will return just the first one
1126
	 * @return TimberTerm|null
1127
	 */
1128
	public function category() {
1129
		return $this->get_category();
1130
	}
1131
1132
	/**
1133
	 * Returns an array of children on the post as TimberPosts
1134
	 * (or other claass as you define).
1135
	 * @api
1136
	 * @example
1137
	 * ```twig
1138
	 * {% if post.children %}
1139
	 *     Here are the child pages:
1140
	 *     {% for child in page.children %}
1141
	 *         <a href="{{ child.link }}">{{ child.title }}</a>
1142
	 *     {% endfor %}
1143
	 * {% endif %}
1144
	 * ```
1145
	 * @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
1146
	 * @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.
1147
	 * @return array
1148
	 */
1149
	public function children( $post_type = 'any', $childPostClass = false ) {
1150
		return $this->get_children( $post_type, $childPostClass );
1151
	}
1152
1153
	/**
1154
	 * Gets the comments on a TimberPost and returns them as an array of [TimberComments](#TimberComment) (or whatever comment class you set).
1155
	 * @api
1156
	 * @param int $count Set the number of comments you want to get. `0` is analogous to "all"
1157
	 * @param string $order use ordering set in WordPress admin, or a different scheme
1158
	 * @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
1159
	 * @param string $status Could be 'pending', etc.
1160
	 * @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)
1161
	 * @example
1162
	 * ```twig
1163
	 * {# single.twig #}
1164
	 * <h4>Comments:</h4>
1165
	 * {% for comment in post.comments %}
1166
	 * 	<div class="comment-{{comment.ID}} comment-order-{{loop.index}}">
1167
	 * 		<p>{{comment.author.name}} said:</p>
1168
	 * 		<p>{{comment.content}}</p>
1169
	 * 	</div>
1170
	 * {% endfor %}
1171
	 * ```
1172
	 * @return bool|array
1173
	 */
1174
	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1175
		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...
1176
	}
1177
1178
	/**
1179
	 * 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).
1180
	 * @api
1181
	 * @example
1182
	 * ```twig
1183
	 * <div class="article">
1184
	 *     <h2>{{post.title}}</h2>
1185
	 *     <div class="content">{{ post.content }}</div>
1186
	 * </div>
1187
	 * ```
1188
	 * @param int $page
1189
	 * @return string
1190
	 */
1191
	public function content( $page = 0 ) {
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1192
		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...
1193
	}
1194
1195
	/**
1196
	 * @return string
1197
	 */
1198
	public function paged_content() {
1199
		return $this->get_paged_content();
1200
	}
1201
1202
	/**
1203
	 * Get the date to use in your template!
1204
	 * @api
1205
	 * @example
1206
	 * ```twig
1207
	 * Published on {{ post.date }} // Uses WP's formatting set in Admin
1208
	 * OR
1209
	 * Published on {{ post.date | date('F jS') }} // Jan 12th
1210
	 * ```
1211
	 *
1212
	 * ```html
1213
	 * Published on January 12, 2015
1214
	 * OR
1215
	 * Published on Jan 12th
1216
	 * ```
1217
	 * @param string $date_format
1218
	 * @return string
1219
	 */
1220
	public function date( $date_format = '' ) {
1221
		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...
1222
	}
1223
1224
	/**
1225
	 * Get the time to use in your template
1226
	 * @api
1227
	 * @example
1228
	 * ```twig
1229
	 * Published at {{ post.time }} // Uses WP's formatting set in Admin
1230
	 * OR
1231
	 * Published at {{ post.time | time('G:i') }} // 13:25
1232
	 * ```
1233
	 *
1234
	 * ```html
1235
	 * Published at 1:25 pm
1236
	 * OR
1237
	 * Published at 13:25
1238
	 * ```
1239
	 * @param string $time_format
1240
	 * @return string
1241
	 */
1242
	public function time( $time_format = '' ) {
1243
		$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...
1244
	 	$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...
1245
	 	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...
1246
	}
1247
1248
	/**
1249
	 * @return bool|string
1250
	 */
1251
	public function edit_link() {
1252
		return $this->get_edit_url();
1253
	}
1254
1255
	/**
1256
	 * @api
1257
	 * @return mixed
1258
	 */
1259
	public function format() {
1260
		return $this->get_format();
1261
	}
1262
1263
	/**
1264
	 * get the permalink for a post object
1265
	 * @api
1266
	 * @example
1267
	 * ```twig
1268
	 * <a href="{{post.link}}">Read my post</a>
1269
	 * ```
1270
	 * @return string ex: http://example.org/2015/07/my-awesome-post
1271
	 */
1272
	public function link() {
1273
		return $this->get_permalink();
1274
	}
1275
1276
	/**
1277
	 * @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...
1278
	 * @return mixed
1279
	 */
1280
	public function meta( $field_name = null ) {
1281
		if ( $field_name === null ) {
1282
			//on the off-chance the field is actually named meta
1283
			$field_name = 'meta';
1284
		}
1285
		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...
1286
	}
1287
1288
	/**
1289
	 * @return string
1290
	 */
1291
	public function name(){
1292
		return $this->title();
1293
	}
1294
1295
	/**
1296
	 * @param string $date_format
1297
	 * @return string
1298
	 */
1299
	public function modified_date( $date_format = '' ) {
1300
		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...
1301
	}
1302
1303
	/**
1304
	 * @param string $time_format
1305
	 * @return string
1306
	 */
1307
	public function modified_time( $time_format = '' ) {
1308
		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...
1309
	}
1310
1311
	/**
1312
	 * @api
1313
	 * @param bool $in_same_cat
1314
	 * @return mixed
1315
	 */
1316
	public function next( $in_same_cat = false ) {
1317
		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...
1318
	}
1319
1320
	/**
1321
	 * @return array
1322
	 */
1323
	public function pagination() {
1324
		return $this->get_pagination();
1325
	}
1326
1327
	/**
1328
	 * Gets the parent (if one exists) from a post as a TimberPost object (or whatever is set in TimberPost::$PostClass)
1329
	 * @api
1330
	 * @example
1331
	 * ```twig
1332
	 * Parent page: <a href="{{ post.parent.link }}">{{ post.parent.title }}</a>
1333
	 * ```
1334
	 * @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...
1335
	 */
1336
	public function parent() {
1337
		return $this->get_parent();
1338
	}
1339
1340
	/**
1341
	 * Gets the relative path of a WP Post, so while link() will return http://example.org/2015/07/my-cool-post
1342
	 * this will return just /2015/07/my-cool-post
1343
	 * @api
1344
	 * @example
1345
	 * ```twig
1346
	 * <a href="{{post.path}}">{{post.title}}</a>
1347
	 * ```
1348
	 * @return string
1349
	 */
1350
	public function path() {
1351
		return $this->get_path();
1352
	}
1353
1354
	/**
1355
	 * @deprecated 0.20.0 use link() instead
1356
	 * @return string
1357
	 */
1358
	public function permalink() {
1359
		return $this->get_permalink();
1360
	}
1361
1362
	/**
1363
	 * Get the previous post in a set
1364
	 * @api
1365
	 * @example
1366
	 * ```twig
1367
	 * <h4>Prior Entry:</h4>
1368
	 * <h3>{{post.prev.title}}</h3>
1369
	 * <p>{{post.prev.get_preview(25)}}</p>
1370
	 * ```
1371
	 * @param bool $in_same_cat
1372
	 * @return mixed
1373
	 */
1374
	public function prev( $in_same_cat = false ) {
1375
		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...
1376
	}
1377
1378
	/**
1379
	 * Get the terms associated with the post
1380
	 * This goes across all taxonomies by default
1381
	 * @api
1382
	 * @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.
1383
	 * @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)?
1384
	 * @return array
1385
	 */
1386
	public function terms( $tax = '', $merge = true ) {
1387
		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...
1388
	}
1389
1390
	/**
1391
	 * Gets the tags on a post, uses WP's post_tag taxonomy
1392
	 * @api
1393
	 * @return array
1394
	 */
1395
	public function tags() {
1396
		return $this->get_tags();
1397
	}
1398
1399
	/**
1400
	 * get the featured image as a TimberImage
1401
	 * @api
1402
	 * @example
1403
	 * ```twig
1404
	 * <img src="{{post.thumbnail.src}}" />
1405
	 * ```
1406
	 * @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...
1407
	 */
1408
	public function thumbnail() {
1409
		return $this->get_thumbnail();
1410
	}
1411
1412
	/**
1413
	 * 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.
1414
	 * @api
1415
	 * @example
1416
	 * ```twig
1417
	 * <h1>{{ post.title }}</h1>
1418
	 * ```
1419
	 * @return string
1420
	 */
1421
	public function title() {
1422
		return $this->get_title();
1423
	}
1424
1425
}
1426