Completed
Push — master ( 1f2dd7...f4bd49 )
by Jared
08:36
created

TimberPost::has_term()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 14
rs 8.8571
cc 5
eloc 10
nc 4
nop 2
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
	 * Enqueue the WP threaded comments javascript,
705
	 * and fetch the reply link for various comments.
706
	 * @internal
707
	 * @param int $comment_id
708
	 * @param int $post_id
709
	 * @return mixed
710
	 */
711
	function TimberComment_reply_link($comment_id, $post_id) {
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...
Coding Style introduced by
The function name TimberComment_reply_link is in camel caps, but expected _timber_comment_reply_link instead as per the coding standard.
Loading history...
712
		if (is_singular() && comments_open() && get_option('thread_comments')) {
0 ignored issues
show
introduced by
No space after opening 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...
introduced by
No space before closing parenthesis is prohibited
Loading history...
713
			wp_enqueue_script( 'comment-reply' );
714
		}
715
716
		// Get the comments depth option from the admin panel
717
		$max_depth = get_option('thread_comments_depth');
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...
718
719
		// Default args
720
		$args = array(
721
			'add_below' => 'comment',
722
			'respond_id' => 'respond',
723
			'reply_text' => 'Reply',
724
			'depth' => 1,
725
			'max_depth' => $max_depth,
726
		);
727
728
		$reply_link = get_comment_reply_link( $args, $comment_id, $post_id );
729
730
		return $reply_link;
731
	}
732
733
	/**
734
	 * Get the comments for a post
735
	 * @internal
736
	 * @see TimberPost::comments
737
	 * @param int $ct
738
	 * @param string $order
739
	 * @param string $type
740
	 * @param string $status
741
	 * @param string $CommentClass
742
	 * @return array|mixed
743
	 */
744
745
	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...
746
747
		global $overridden_cpage, $user_ID;
748
		$overridden_cpage = false;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
749
750
		$commenter = wp_get_current_commenter();
751
		$comment_author_email = $commenter['comment_author_email'];
752
753
		$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...
754
		if ( $ct > 0 ) {
755
			$args['number'] = $ct;
756
		}
757
		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...
758
			$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...
759
		}
760
761
		if ( $user_ID ) {
762
			$args['include_unapproved'] = array( $user_ID );
763
		} elseif ( ! empty( $comment_author_email ) ) {
764
			$args['include_unapproved'] = array( $comment_author_email );
765
		}
766
767
		$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...
768
		$timber_comments = array();
769
770
		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...
771
			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...
772
			$overridden_cpage = true;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
773
		}
774
775
		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...
776
			$timber_comment = new $CommentClass($comment);
777
			$timber_comment->reply_link = $this->TimberComment_reply_link($comment->comment_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...
778
			$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...
779
		}
780
781
		// Build a flattened (depth=1) comment tree
782
		$comments_tree = array();
783
		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...
784
			if ( ! $comment->is_child() ) {
785
				continue;
786
			}
787
788
			$tree_element = $comment;
789
			do {
790
				$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...
791
			} while( $tree_element->is_child() );
0 ignored issues
show
introduced by
Space after opening control structure is required
Loading history...
792
793
			$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...
794
		}
795
796
		// Add child comments to the relative "super parents"
797
		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...
798
			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...
799
				$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...
800
				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...
801
			}
802
		}
803
804
		$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...
805
806
		return $timber_comments;
807
	}
808
809
	/**
810
	 * Get the categories for a post
811
	 * @internal
812
	 * @see TimberPost::categories
813
	 * @return array of TimberTerms
814
	 */
815
	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...
816
		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...
817
	}
818
819
	/**
820
	 * @internal
821
	 * @see TimberPost::category
822
	 * @return mixed
823
	 */
824
	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...
825
		$cats = $this->get_categories();
826
		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...
827
			return $cats[0];
828
		}
829
	}
830
831
	/**
832
	 * @internal
833
	 * @param string|array $tax
834
	 * @param bool $merge
835
	 * @param string $TermClass
836
	 * @return array
837
	 */
838
	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...
839
840
		$TermClass = $TermClass ?: $this->TermClass;
841
842
		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...
843
			$TermClass = $merge;
844
		}
845
		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...
846
			$taxonomies = $tax;
847
		}
848
		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...
849
			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...
850
				$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...
851
			} else {
852
				$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...
853
			}
854
		}
855
856
		$term_class_objects = array();
857
858
		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...
859
			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...
860
				$taxonomy = 'post_tag';
861
			}
862
			if ( $taxonomy == 'categories' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
863
				$taxonomy = 'category';
864
			}
865
866
			$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...
867
868
			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...
869
				/* @var $terms WP_Error */
870
				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...
871
				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...
872
				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...
873
874
				return $term_class_objects;
875
			}
876
877
			// map over array of wordpress terms, and transform them into instances of the TermClass
878
			$terms = array_map(function($term) use ($TermClass, $taxonomy) {
879
				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...
880
			}, $terms);
881
882
			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...
883
				$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...
884
			} 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...
885
				$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...
886
			}
887
		}
888
		return $term_class_objects;
889
	}
890
891
	/**
892
	 * @param string|int $term_name_or_id
893
	 * @param string $taxonomy
894
	 * @return bool
895
	 */
896
	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...
897
		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
898
			$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...
899
			$ret = false;
900
			foreach ( $taxes as $tax ) {
901
				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...
902
					$ret = true;
903
					break;
904
				}
905
			}
906
			return $ret;
907
		}
908
		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...
909
	}
910
911
	/**
912
	 * @param string $field
913
	 * @return TimberImage
914
	 */
915
	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...
916
		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...
917
	}
918
919
	/**
920
	 * Gets an array of tags for you to use
921
	 * @internal
922
	 * @example
923
	 * ```twig
924
	 * <ul class="tags">
925
	 *     {% for tag in post.tags %}
926
	 *         <li>{{tag.name}}</li>
927
	 *     {% endfor %}
928
	 * </ul>
929
	 * ```
930
	 * @return array
931
	 */
932
	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...
933
		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...
934
	}
935
936
	/**
937
	 * Outputs the title with filters applied
938
	 * @internal
939
	 * @example
940
	 * ```twig
941
	 * <h1>{{post.get_title}}</h1>
942
	 * ```
943
	 * ```html
944
	 * <h1>Hello World!</h1>
945
	 * ```
946
	 * @return string
947
	 */
948
	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...
949
		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...
950
	}
951
952
	/**
953
	 * Displays the content of the post with filters, shortcodes and wpautop applied
954
	 * @example
955
	 * ```twig
956
	 * <div class="article-text">{{post.get_content}}</div>
957
	 * ```
958
	 * ```html
959
	 * <div class="article-text"><p>Blah blah blah</p><p>More blah blah blah.</p></div>
960
	 * ```
961
	 * @param int $len
962
	 * @param int $page
963
	 * @return string
964
	 */
965
	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...
966
		if ( $len == 0 && $page == 0 && $this->_content ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
967
			return $this->_content;
968
		}
969
		$content = $this->post_content;
970
		if ( $len ) {
971
			$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...
972
		}
973
		if ( $page ) {
974
			$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...
975
			$page--;
976
			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...
977
				$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...
978
			}
979
		}
980
		$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...
981
		if ( $len == 0 && $page == 0 ) {
0 ignored issues
show
introduced by
Found "== 0". Use Yoda Condition checks, you must
Loading history...
982
			$this->_content = $content;
983
		}
984
		return $content;
985
	}
986
987
	/**
988
	 * @return string
989
	 */
990
	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...
991
		global $page;
992
		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...
993
	}
994
	/**
995
	 *
996
	 * Here is my summary
997
	 * @example
998
	 * ```twig
999
	 * This post is from <span>{{ post.get_post_type.labels.plural }}</span>
1000
	 * ```
1001
	 *
1002
	 * ```html
1003
	 * This post is from <span>Recipes</span>
1004
	 * ```
1005
	 * @return mixed
1006
	 */
1007
	public function get_post_type() {
1008
		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...
1009
	}
1010
1011
	/**
1012
	 * @return int the number of comments on a post
1013
	 */
1014
	public function get_comment_count() {
1015
		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...
1016
	}
1017
1018
	/**
1019
	 * @param string $field_name
1020
	 * @return mixed
1021
	 */
1022
	public function get_field( $field_name ) {
1023
		$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...
1024
		if ( $value === null ) {
1025
			$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...
1026
			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...
1027
				$value = $value[0];
1028
			}
1029
			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...
1030
				$value = null;
1031
			}
1032
		}
1033
		$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...
1034
		return $value;
1035
	}
1036
1037
	/**
1038
	 * @param string $field_name
1039
	 */
1040
	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...
1041
		$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...
1042
	}
1043
1044
	/**
1045
	 * @internal
1046
	 * @return mixed
1047
	 */
1048
	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...
1049
		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...
1050
	}
1051
1052
	/**
1053
	 * Get the CSS classes for a post. For usage you should use `{{post.class}}` instead of `{{post.post_class}}`
1054
	 * @internal
1055
	 * @param string $class additional classes you want to add
1056
	 * @see TimberPost::$class
1057
	 * @example
1058
	 * ```twig
1059
	 * <article class="{{ post.class }}">
1060
	 *    {# Some stuff here #}
1061
	 * </article>
1062
	 * ```
1063
	 *
1064
	 * ```html
1065
	 * <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">
1066
	 *    {# Some stuff here #}
1067
	 * </article>
1068
	 * ```
1069
	 * @return string a space-seperated list of classes
1070
	 */
1071
	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...
1072
		global $post;
1073
		$old_global_post = $post;
1074
		$post = $this;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1075
		$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...
1076
		$post = $old_global_post;
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1077
		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...
1078
			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...
1079
		}
1080
		return $class_array;
1081
	}
1082
1083
	// Docs
1084
1085
	/**
1086
	 * @return array
1087
	 * @codeCoverageIgnore
1088
	 */
1089
	public function get_method_values() {
1090
		$ret = parent::get_method_values();
1091
		$ret['author'] = $this->author();
1092
		$ret['categories'] = $this->categories();
1093
		$ret['category'] = $this->category();
1094
		$ret['children'] = $this->children();
1095
		$ret['comments'] = $this->comments();
1096
		$ret['content'] = $this->content();
1097
		$ret['edit_link'] = $this->edit_link();
1098
		$ret['format'] = $this->format();
1099
		$ret['link'] = $this->link();
1100
		$ret['next'] = $this->next();
1101
		$ret['pagination'] = $this->pagination();
1102
		$ret['parent'] = $this->parent();
1103
		$ret['path'] = $this->path();
1104
		$ret['prev'] = $this->prev();
1105
		$ret['terms'] = $this->terms();
1106
		$ret['tags'] = $this->tags();
1107
		$ret['thumbnail'] = $this->thumbnail();
1108
		$ret['title'] = $this->title();
1109
		return $ret;
1110
	}
1111
1112
	/**
1113
	 * Return the author of a post
1114
	 * @api
1115
	 * @example
1116
	 * ```twig
1117
	 * <h1>{{post.title}}</h1>
1118
	 * <p class="byline">
1119
	 *     <a href="{{post.author.link}}">{{post.author.name}}</a>
1120
	 * </p>
1121
	 * ```
1122
	 * @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...
1123
	 */
1124
	public function author() {
1125
		return $this->get_author();
1126
	}
1127
1128
	/**
1129
	 * Get the author (WordPress user) who last modified the post
1130
	 * @example
1131
	 * ```twig
1132
	 * Last updated by {{ post.modified_author.name }}
1133
	 * ```
1134
	 * ```html
1135
	 * Last updated by Harper Lee
1136
	 * ```
1137
	 * @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...
1138
	 */
1139
	public function modified_author() {
1140
		return $this->get_modified_author();
1141
	}
1142
1143
	/**
1144
	 * Get the categoires on a particular post
1145
	 * @api
1146
	 * @return array of TimberTerms
1147
	 */
1148
	public function categories() {
1149
		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...
1150
	}
1151
1152
	/**
1153
	 * Returns a category attached to a post
1154
	 * @api
1155
	 * If mulitpuile categories are set, it will return just the first one
1156
	 * @return TimberTerm|null
1157
	 */
1158
	public function category() {
1159
		return $this->get_category();
1160
	}
1161
1162
	/**
1163
	 * Returns an array of children on the post as TimberPosts
1164
	 * (or other claass as you define).
1165
	 * @api
1166
	 * @example
1167
	 * ```twig
1168
	 * {% if post.children %}
1169
	 *     Here are the child pages:
1170
	 *     {% for child in page.children %}
1171
	 *         <a href="{{ child.link }}">{{ child.title }}</a>
1172
	 *     {% endfor %}
1173
	 * {% endif %}
1174
	 * ```
1175
	 * @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
1176
	 * @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.
1177
	 * @return array
1178
	 */
1179
	public function children( $post_type = 'any', $childPostClass = false ) {
1180
		return $this->get_children( $post_type, $childPostClass );
1181
	}
1182
1183
	/**
1184
	 * Gets the comments on a TimberPost and returns them as an array of [TimberComments](#TimberComment) (or whatever comment class you set).
1185
	 * @api
1186
	 * @param int $count Set the number of comments you want to get. `0` is analogous to "all"
1187
	 * @param string $order use ordering set in WordPress admin, or a different scheme
1188
	 * @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
1189
	 * @param string $status Could be 'pending', etc.
1190
	 * @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)
1191
	 * @example
1192
	 * ```twig
1193
	 * {# single.twig #}
1194
	 * <h4>Comments:</h4>
1195
	 * {% for comment in post.comments %}
1196
	 * 	<div class="comment-{{comment.ID}} comment-order-{{loop.index}}">
1197
	 * 		<p>{{comment.author.name}} said:</p>
1198
	 * 		<p>{{comment.content}}</p>
1199
	 * 	</div>
1200
	 * {% endfor %}
1201
	 * ```
1202
	 * @return bool|array
1203
	 */
1204
	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1205
		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...
1206
	}
1207
1208
	/**
1209
	 * 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).
1210
	 * @api
1211
	 * @example
1212
	 * ```twig
1213
	 * <div class="article">
1214
	 *     <h2>{{post.title}}</h2>
1215
	 *     <div class="content">{{ post.content }}</div>
1216
	 * </div>
1217
	 * ```
1218
	 * @param int $page
1219
	 * @return string
1220
	 */
1221
	public function content( $page = 0 ) {
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
1222
		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...
1223
	}
1224
1225
	/**
1226
	 * @return string
1227
	 */
1228
	public function paged_content() {
1229
		return $this->get_paged_content();
1230
	}
1231
1232
	/**
1233
	 * Get the date to use in your template!
1234
	 * @api
1235
	 * @example
1236
	 * ```twig
1237
	 * Published on {{ post.date }} // Uses WP's formatting set in Admin
1238
	 * OR
1239
	 * Published on {{ post.date | date('F jS') }} // Jan 12th
1240
	 * ```
1241
	 *
1242
	 * ```html
1243
	 * Published on January 12, 2015
1244
	 * OR
1245
	 * Published on Jan 12th
1246
	 * ```
1247
	 * @param string $date_format
1248
	 * @return string
1249
	 */
1250
	public function date( $date_format = '' ) {
1251
		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...
1252
	}
1253
1254
	/**
1255
	 * Get the time to use in your template
1256
	 * @api
1257
	 * @example
1258
	 * ```twig
1259
	 * Published at {{ post.time }} // Uses WP's formatting set in Admin
1260
	 * OR
1261
	 * Published at {{ post.time | time('G:i') }} // 13:25
1262
	 * ```
1263
	 *
1264
	 * ```html
1265
	 * Published at 1:25 pm
1266
	 * OR
1267
	 * Published at 13:25
1268
	 * ```
1269
	 * @param string $time_format
1270
	 * @return string
1271
	 */
1272
	public function time( $time_format = '' ) {
1273
		$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...
1274
	 	$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...
1275
	 	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...
1276
	}
1277
1278
	/**
1279
	 * @return bool|string
1280
	 */
1281
	public function edit_link() {
1282
		return $this->get_edit_url();
1283
	}
1284
1285
	/**
1286
	 * @api
1287
	 * @return mixed
1288
	 */
1289
	public function format() {
1290
		return $this->get_format();
1291
	}
1292
1293
	/**
1294
	 * get the permalink for a post object
1295
	 * @api
1296
	 * @example
1297
	 * ```twig
1298
	 * <a href="{{post.link}}">Read my post</a>
1299
	 * ```
1300
	 * @return string ex: http://example.org/2015/07/my-awesome-post
1301
	 */
1302
	public function link() {
1303
		return $this->get_permalink();
1304
	}
1305
1306
	/**
1307
	 * @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...
1308
	 * @return mixed
1309
	 */
1310
	public function meta( $field_name = null ) {
1311
		if ( $field_name === null ) {
1312
			//on the off-chance the field is actually named meta
1313
			$field_name = 'meta';
1314
		}
1315
		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...
1316
	}
1317
1318
	/**
1319
	 * @return string
1320
	 */
1321
	public function name() {
1322
		return $this->title();
1323
	}
1324
1325
	/**
1326
	 * @param string $date_format
1327
	 * @return string
1328
	 */
1329
	public function modified_date( $date_format = '' ) {
1330
		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...
1331
	}
1332
1333
	/**
1334
	 * @param string $time_format
1335
	 * @return string
1336
	 */
1337
	public function modified_time( $time_format = '' ) {
1338
		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...
1339
	}
1340
1341
	/**
1342
	 * @api
1343
	 * @param bool $in_same_cat
1344
	 * @return mixed
1345
	 */
1346
	public function next( $in_same_cat = false ) {
1347
		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...
1348
	}
1349
1350
	/**
1351
	 * @return array
1352
	 */
1353
	public function pagination() {
1354
		return $this->get_pagination();
1355
	}
1356
1357
	/**
1358
	 * Gets the parent (if one exists) from a post as a TimberPost object (or whatever is set in TimberPost::$PostClass)
1359
	 * @api
1360
	 * @example
1361
	 * ```twig
1362
	 * Parent page: <a href="{{ post.parent.link }}">{{ post.parent.title }}</a>
1363
	 * ```
1364
	 * @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...
1365
	 */
1366
	public function parent() {
1367
		return $this->get_parent();
1368
	}
1369
1370
	/**
1371
	 * Gets the relative path of a WP Post, so while link() will return http://example.org/2015/07/my-cool-post
1372
	 * this will return just /2015/07/my-cool-post
1373
	 * @api
1374
	 * @example
1375
	 * ```twig
1376
	 * <a href="{{post.path}}">{{post.title}}</a>
1377
	 * ```
1378
	 * @return string
1379
	 */
1380
	public function path() {
1381
		return $this->get_path();
1382
	}
1383
1384
	/**
1385
	 * @deprecated 0.20.0 use link() instead
1386
	 * @return string
1387
	 */
1388
	public function permalink() {
1389
		return $this->get_permalink();
1390
	}
1391
1392
	/**
1393
	 * Get the previous post in a set
1394
	 * @api
1395
	 * @example
1396
	 * ```twig
1397
	 * <h4>Prior Entry:</h4>
1398
	 * <h3>{{post.prev.title}}</h3>
1399
	 * <p>{{post.prev.get_preview(25)}}</p>
1400
	 * ```
1401
	 * @param bool $in_same_cat
1402
	 * @return mixed
1403
	 */
1404
	public function prev( $in_same_cat = false ) {
1405
		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...
1406
	}
1407
1408
	/**
1409
	 * Get the terms associated with the post
1410
	 * This goes across all taxonomies by default
1411
	 * @api
1412
	 * @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.
1413
	 * @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)?
1414
	 * @return array
1415
	 */
1416
	public function terms( $tax = '', $merge = true ) {
1417
		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...
1418
	}
1419
1420
	/**
1421
	 * Gets the tags on a post, uses WP's post_tag taxonomy
1422
	 * @api
1423
	 * @return array
1424
	 */
1425
	public function tags() {
1426
		return $this->get_tags();
1427
	}
1428
1429
	/**
1430
	 * get the featured image as a TimberImage
1431
	 * @api
1432
	 * @example
1433
	 * ```twig
1434
	 * <img src="{{post.thumbnail.src}}" />
1435
	 * ```
1436
	 * @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...
1437
	 */
1438
	public function thumbnail() {
1439
		return $this->get_thumbnail();
1440
	}
1441
1442
	/**
1443
	 * 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.
1444
	 * @api
1445
	 * @example
1446
	 * ```twig
1447
	 * <h1>{{ post.title }}</h1>
1448
	 * ```
1449
	 * @return string
1450
	 */
1451
	public function title() {
1452
		return $this->get_title();
1453
	}
1454
1455
}
1456