Issues (311)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/timber-post.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
	 * @api
98
	 * @var string $id the numeric WordPress id of a post
99
	 */
100
	public $id;
101
102
	/**
103
	 * @var string 	$ID 			the numeric WordPress id of a post, capitalized to match WP usage
104
	 */
105
	public $ID;
106
107
	/**
108
	 * @var int 	$post_author 	the numeric ID of the a post's author corresponding to the wp_user dtable
109
	 */
110
	public $post_author;
111
112
	/**
113
	 * @var string 	$post_content 	the raw text of a WP post as stored in the database
114
	 */
115
	public $post_content;
116
117
	/**
118
	 * @var string 	$post_date 		the raw date string as stored in the WP database, ex: 2014-07-05 18:01:39
119
	 */
120
	public $post_date;
121
122
	/**
123
	 * @var string 	$post_exceprt 	the raw text of a manual post exceprt as stored in the database
124
	 */
125
	public $post_excerpt;
126
127
	/**
128
	 * @var int 		$post_parent 	the numeric ID of a post's parent post
129
	 */
130
	public $post_parent;
131
132
	/**
133
	 * @api
134
	 * @var string 		$post_status 	the status of a post ("draft", "publish", etc.)
135
	 */
136
	public $post_status;
137
138
	/**
139
	 * @var string 	$post_title 	the raw text of a post's title as stored in the database
140
	 */
141
	public $post_title;
142
143
	/**
144
	 * @api
145
	 * @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")
146
	 */
147
	public $post_type;
148
149
	/**
150
	 * @api
151
	 * @var string 	$slug 		the URL-safe slug, this corresponds to the poorly-named "post_name" in the WP database, ex: "hello-world"
152
	 */
153
	public $slug;
154
155
	/**
156
	 * If you send the constructor nothing it will try to figure out the current post id based on being inside The_Loop
157
	 * @example
158
	 * ```php
159
	 * $post = new TimberPost();
160
	 * $other_post = new TimberPost($random_post_id);
161
	 * ```
162
	 * @param mixed $pid
163
	 */
164
	public function __construct($pid = null) {
165
		$pid = $this->determine_id( $pid );
166
		$this->init($pid);
167
	}
168
169
	/**
170
	 * tries to figure out what post you want to get if not explictly defined (or if it is, allows it to be passed through)
171
	 * @internal
172
	 * @param mixed a value to test against
173
	 * @return int the numberic id we should be using for this post object
174
	 */
175
	protected function determine_id($pid) {
176
		global $wp_query;
177
		if ( $pid === null &&
178
			isset($wp_query->queried_object_id)
179
			&& $wp_query->queried_object_id
180
			&& isset($wp_query->queried_object)
181
			&& is_object($wp_query->queried_object)
182
			&& get_class($wp_query->queried_object) == 'WP_Post'
183
			) {
184
				if( isset( $_GET['preview'] ) && isset( $_GET['preview_nonce'] ) && wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $wp_query->queried_object_id ) ) {
185
					$pid = $this->get_post_preview_id( $wp_query );
186
				} else if ( !$pid ) {
187
					$pid = $wp_query->queried_object_id;
188
				}
189
		} else if ( $pid === null && $wp_query->is_home && isset($wp_query->queried_object_id) && $wp_query->queried_object_id )  {
190
			//hack for static page as home page
191
			$pid = $wp_query->queried_object_id;
192
		} else if ( $pid === null ) {
193
			$gtid = false;
194
			$maybe_post = get_post();
195
			if ( isset($maybe_post->ID) ){
196
				$gtid = true;
197
			}
198
			if ( $gtid ) {
199
				$pid = get_the_ID();
200
			}
201
			if ( !$pid ) {
202
				global $wp_query;
203
				if ( isset($wp_query->query['p']) ) {
204
					$pid = $wp_query->query['p'];
205
				}
206
			}
207
		}
208
		if ( $pid === null && ($pid_from_loop = TimberPostGetter::loop_to_id()) ) {
209
			$pid = $pid_from_loop;
210
		}
211
		return $pid;
212
	}
213
214
	/**
215
	 * Outputs the title of the post if you do something like `<h1>{{post}}</h1>`
216
	 * @return string
217
	 */
218
	public function __toString() {
219
		return $this->title();
220
	}
221
222
	protected function get_post_preview_id( $query ) {
223
		$can = array(
224
	 		'edit_' . $query->queried_object->post_type . 's',
225
	 	);
226
227
	 	if ( $query->queried_object->author_id !== get_current_user_id() ) {
228
	 		$can[] = 'edit_others_' . $query->queried_object->post_type . 's';
229
	 	}
230
231
	 	$can_preview = array();
232
233
		foreach( $can as $type ) {
234
		     if( current_user_can( $type ) ) {
235
		        $can_preview[] = true;
236
		     }
237
		}
238
239
		if ( count( $can_preview ) !== count( $can ) ) {
240
		     return;
241
		}
242
243
		$revisions = wp_get_post_revisions( $query->queried_object_id );
244
245
		if( !empty( $revisions ) ) {
246
			$last = end($revisions);
247
			return $last->ID;
248
		}
249
250
		return false;
251
	}
252
253
	/**
254
	 * Initializes a TimberPost
255
	 * @internal
256
	 * @param int|bool $pid
257
	 */
258
	protected function init($pid = false) {
259
		if ( $pid === false ) {
260
			$pid = get_the_ID();
261
		}
262
		if ( is_numeric($pid) ) {
263
			$this->ID = $pid;
264
		}
265
		$post_info = $this->get_info($pid);
266
		$this->import($post_info);
267
		//cant have a function, so gots to do it this way
268
		$post_class = $this->post_class();
269
		$this->class = $post_class;
270
	}
271
272
	/**
273
	 * Get the URL that will edit the current post/object
274
	 * @internal
275
	 * @see TimberPost::edit_link
276
	 * @return bool|string
277
	 */
278
	function get_edit_url() {
279
		if ( $this->can_edit() ) {
280
			return get_edit_post_link($this->ID);
281
		}
282
	}
283
284
	/**
285
	 * updates the post_meta of the current object with the given value
286
	 * @param string $field
287
	 * @param mixed $value
288
	 */
289
	public function update( $field, $value ) {
290
		if ( isset($this->ID) ) {
291
			update_post_meta($this->ID, $field, $value);
292
			$this->$field = $value;
293
		}
294
	}
295
296
297
	/**
298
	 * takes a mix of integer (post ID), string (post slug),
299
	 * or object to return a WordPress post object from WP's built-in get_post() function
300
	 * @internal
301
	 * @param mixed $pid
302
	 * @return WP_Post on success
303
	 */
304
	protected function prepare_post_info( $pid = 0 ) {
305
		if ( is_string($pid) || is_numeric($pid) || (is_object($pid) && !isset($pid->post_title)) || $pid === 0 ) {
306
			$pid = self::check_post_id($pid);
307
			$post = get_post($pid);
308
			if ( $post ) {
309
				return $post;
310
			}
311
		}
312
		//we can skip if already is WP_Post
313
		return $pid;
314
	}
315
316
317
	/**
318
	 * helps you find the post id regardless of whether you send a string or whatever
319
	 * @param integer $pid ;
320
	 * @internal
321
	 * @return integer ID number of a post
322
	 */
323
	protected function check_post_id( $pid ) {
324
		if ( is_numeric($pid) && $pid === 0 ) {
325
			$pid = get_the_ID();
326
			return $pid;
327
		}
328
		if ( !is_numeric($pid) && is_string($pid) ) {
329
			$pid = self::get_post_id_by_name($pid);
330
			return $pid;
331
		}
332
		if ( !$pid ) {
333
			return null;
334
		}
335
		return $pid;
336
	}
337
338
339
	/**
340
	 * get_post_id_by_name($post_name)
341
	 * @internal
342
	 * @param string $post_name
343
	 * @return int
344
	 */
345
	static function get_post_id_by_name($post_name) {
346
		global $wpdb;
347
		$query = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s LIMIT 1", $post_name);
348
		$result = $wpdb->get_row($query);
349
		if (!$result) {
350
			return null;
351
		}
352
		return $result->ID;
353
	}
354
355
	/**
356
	 * get a preview of your post, if you have an excerpt it will use that,
357
	 * otherwise it will pull from the post_content.
358
	 * If there's a <!-- more --> tag it will use that to mark where to pull through.
359
	 * @api
360
	 * @example
361
	 * ```twig
362
	 * <p>{{post.get_preview(50)}}</p>
363
	 * ```
364
	 * @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
365
	 * @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
366
	 * @param string $readmore The text you want to use on the 'readmore' link
367
	 * @param bool|string $strip true for default, false for none, string for list of custom attributes
368
	 * @param string $end The text to end the preview with (defaults to ...)
369
	 * @return string of the post preview
370
	 */
371
	function get_preview($len = 50, $force = false, $readmore = 'Read More', $strip = true, $end = '&hellip;') {
372
		$text = '';
373
		$trimmed = false;
374
		if ( isset($this->post_excerpt) && strlen($this->post_excerpt) ) {
375
			if ( $force ) {
376
				$text = TimberHelper::trim_words($this->post_excerpt, $len, false);
377
				$trimmed = true;
378
			} else {
379
				$text = $this->post_excerpt;
380
			}
381
		}
382
		if ( !strlen($text) && preg_match('/<!--\s?more(.*?)?-->/', $this->post_content, $readmore_matches) ) {
383
			$pieces = explode($readmore_matches[0], $this->post_content);
384
			$text = $pieces[0];
385
			if ( $force ) {
386
				$text = TimberHelper::trim_words($text, $len, false);
387
				$trimmed = true;
388
			}
389
			$text = do_shortcode( $text );
390
		}
391
		if ( !strlen($text) ) {
392
			$text = TimberHelper::trim_words($this->get_content(), $len, false);
393
			$trimmed = true;
394
		}
395
		if ( !strlen(trim($text)) ) {
396
			return trim($text);
397
		}
398
		if ( $strip ) {
399
			$allowable_tags = (is_string($strip)) ? $strip : null;
400
			$text = trim(strip_tags($text, $allowable_tags));
401
		}
402
		if ( strlen($text) ) {
403
			$text = trim($text);
404
			$last = $text[strlen($text) - 1];
405
			if ( $last != '.' && $trimmed ) {
406
				$text .= $end;
407
			}
408
			if ( !$strip ) {
409
				$last_p_tag = strrpos($text, '</p>');
410
				if ( $last_p_tag !== false ) {
411
					$text = substr($text, 0, $last_p_tag);
412
				}
413
				if ( $last != '.' && $trimmed ) {
414
					$text .= $end . ' ';
415
				}
416
			}
417
			$read_more_class = apply_filters('timber/post/get_preview/read_more_class', "read-more");
418
			if ( $readmore && isset($readmore_matches) && !empty($readmore_matches[1]) ) {
419
				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore_matches[1]) . '</a>';
420
			} elseif ( $readmore ) {
421
				$text .= ' <a href="' . $this->get_permalink() . '" class="'.$read_more_class .'">' . trim($readmore) . '</a>';
422
			}
423
			if ( !$strip && $last_p_tag && ( strpos($text, '<p>') || strpos($text, '<p ') ) ) {
424
				$text .= '</p>';
425
			}
426
		}
427
		return trim($text);
428
	}
429
430
	/**
431
	 * gets the post custom and attaches it to the current object
432
	 * @internal
433
	 * @param bool|int $pid a post ID number
434
	 */
435
	function import_custom( $pid = false ) {
436
		if ( !$pid ) {
437
			$pid = $this->ID;
438
		}
439
		$customs = $this->get_post_custom($pid);
440
		$this->import($customs);
441
	}
442
443
	/**
444
	 * Used internally to fetch the metadata fields (wp_postmeta table)
445
	 * and attach them to our TimberPost object
446
	 * @internal
447
	 * @param int $pid
448
	 * @return array
449
	 */
450
	protected function get_post_custom( $pid ) {
451
		apply_filters('timber_post_get_meta_pre', array(), $pid, $this);
452
		$customs = get_post_custom($pid);
453
		if ( !is_array($customs) || empty($customs) ) {
454
			return array();
455
		}
456 View Code Duplication
		foreach ( $customs as $key => $value ) {
457
			if ( is_array($value) && count($value) == 1 && isset($value[0]) ) {
458
				$value = $value[0];
459
			}
460
			$customs[$key] = maybe_unserialize($value);
461
		}
462
		$customs = apply_filters('timber_post_get_meta', $customs, $pid, $this);
463
		return $customs;
464
	}
465
466
	/**
467
	 * @internal
468
	 * @see TimberPost::thumbnail
469
	 * @return null|TimberImage
470
	 */
471
	function get_thumbnail() {
472
		if ( function_exists('get_post_thumbnail_id') ) {
473
			$tid = get_post_thumbnail_id($this->ID);
474
			if ( $tid ) {
475
				return new $this->ImageClass($tid);
476
			}
477
		}
478
	}
479
480
	/**
481
	 * @internal
482
	 * @see TimberPost::link
483
	 * @return string
484
	 */
485
	function get_permalink() {
486
		if ( isset($this->_permalink) ) {
487
			return $this->_permalink;
488
		}
489
		$this->_permalink = get_permalink($this->ID);
490
		return $this->_permalink;
491
	}
492
493
	/**
494
	 * get the permalink for a post object
495
	 * In your templates you should use link:
496
	 * <a href="{{post.link}}">Read my post</a>
497
	 * @internal
498
	 * @return string
499
	 */
500
	function get_link() {
501
		return $this->get_permalink();
502
	}
503
504
	/**
505
	 * Get the next post in WordPress's ordering
506
	 * @internal
507
	 * @param bool $taxonomy
508
	 * @return TimberPost|boolean
509
	 */
510
	function get_next( $taxonomy = false ) {
511
		if ( !isset($this->_next) || !isset($this->_next[$taxonomy]) ) {
512
			global $post;
513
			$this->_next = array();
514
			$old_global = $post;
515
			$post = $this;
516
			if ( $taxonomy ) {
517
				$adjacent = get_adjacent_post(true, '', false, $taxonomy);
518
			} else {
519
				$adjacent = get_adjacent_post(false, '', false);
520
			}
521
522
			if ( $adjacent ) {
523
				$this->_next[$taxonomy] = new $this->PostClass($adjacent);
524
			} else {
525
				$this->_next[$taxonomy] = false;
526
			}
527
			$post = $old_global;
528
		}
529
		return $this->_next[$taxonomy];
530
	}
531
532
	/**
533
	 * Get a data array of pagination so you can navigate to the previous/next for a paginated post
534
	 * @return array
535
	 */
536
	public function get_pagination() {
537
		global $post, $page, $numpages, $multipage;
538
		$post = $this;
539
		$ret = array();
540
		if ( $multipage ) {
541
			for ( $i = 1; $i <= $numpages; $i++ ) {
542
				$link = self::get_wp_link_page($i);
543
				$data = array('name' => $i, 'title' => $i, 'text' => $i, 'link' => $link);
544
				if ( $i == $page ) {
545
					$data['current'] = true;
546
				}
547
				$ret['pages'][] = $data;
548
			}
549
			$i = $page - 1;
550
			if ( $i ) {
551
				$link = self::get_wp_link_page($i);
552
				$ret['prev'] = array('link' => $link);
553
			}
554
			$i = $page + 1;
555
			if ( $i <= $numpages ) {
556
				$link = self::get_wp_link_page($i);
557
				$ret['next'] = array('link' => $link);
558
			}
559
		}
560
		return $ret;
561
	}
562
563
	/**
564
	 * @param int $i
565
	 * @return string
566
	 */
567
	protected static function get_wp_link_page($i) {
568
		$link = _wp_link_page($i);
569
		$link = new SimpleXMLElement($link . '</a>');
570
		if ( isset($link['href']) ) {
571
			return $link['href'];
572
		}
573
		return '';
574
	}
575
576
	/**
577
	 * Get the permalink for a post, but as a relative path
578
	 * For example, where {{post.link}} would return "http://example.org/2015/07/04/my-cool-post"
579
	 * this will return the relative version: "/2015/07/04/my-cool-post"
580
	 * @internal
581
	 * @return string
582
	 */
583
	function get_path() {
584
		return TimberURLHelper::get_rel_url($this->get_link());
585
	}
586
587
	/**
588
	 * Get the next post in WordPress's ordering
589
	 * @internal
590
	 * @param bool $taxonomy
591
	 * @return TimberPost|boolean
592
	 */
593
	function get_prev( $taxonomy = false ) {
594
		if ( isset($this->_prev) && isset($this->_prev[$taxonomy]) ) {
595
			return $this->_prev[$taxonomy];
596
		}
597
		global $post;
598
		$old_global = $post;
599
		$post = $this;
600
		$within_taxonomy = ($taxonomy) ? $taxonomy : 'category';
601
		$adjacent = get_adjacent_post(($taxonomy), '', true, $within_taxonomy);
602
		$prev_in_taxonomy = false;
603
		if ( $adjacent ) {
604
			$prev_in_taxonomy = new $this->PostClass($adjacent);
605
		}
606
		$this->_prev[$taxonomy] = $prev_in_taxonomy;
607
		$post = $old_global;
608
		return $this->_prev[$taxonomy];
609
	}
610
611
	/**
612
	 * Get the parent post of the post
613
	 * @internal
614
	 * @return bool|TimberPost
615
	 */
616
	function get_parent() {
617
		if ( !$this->post_parent ) {
618
			return false;
619
		}
620
		return new $this->PostClass($this->post_parent);
621
	}
622
623
	/**
624
	 * Gets a User object from the author of the post
625
	 * @internal
626
	 * @see TimberPost::author
627
	 * @return bool|TimberUser
628
	 */
629
	function get_author() {
630
		if ( isset($this->post_author) ) {
631
			return new TimberUser($this->post_author);
632
		}
633
	}
634
635
	/**
636
	 * @internal
637
	 * @return bool|TimberUser
638
	 */
639
	function get_modified_author() {
640
		$user_id = get_post_meta($this->ID, '_edit_last', true);
641
		return ($user_id ? new TimberUser($user_id) : $this->get_author());
642
	}
643
644
	/**
645
	 * Used internally by init, etc. to build TimberPost object
646
	 * @internal
647
	 * @param  int $pid
648
	 * @return null|object|WP_Post
649
	 */
650
	protected function get_info($pid) {
651
		$post = $this->prepare_post_info($pid);
652
		if ( !isset($post->post_status) ) {
653
			return null;
654
		}
655
		$post->status = $post->post_status;
656
		$post->id = $post->ID;
657
		$post->slug = $post->post_name;
658
		$customs = $this->get_post_custom($post->ID);
659
		$post->custom = $customs;
660
		$post = (object) array_merge((array)$customs, (array)$post);
661
		return $post;
662
	}
663
664
	/**
665
	 * @internal
666
	 * @see TimberPost::date
667
	 * @param  string $date_format
668
	 * @return string
669
	 */
670
	function get_date( $date_format = '' ) {
671
		$df = $date_format ? $date_format : get_option('date_format');
672
		$the_date = (string)mysql2date($df, $this->post_date);
673
		return apply_filters('get_the_date', $the_date, $df);
674
	}
675
676
	/**
677
	 * @internal
678
	 * @param  string $date_format
679
	 * @return string
680
	 */
681
	function get_modified_date( $date_format = '' ) {
682
		$df = $date_format ? $date_format : get_option('date_format');
683
		$the_time = $this->get_modified_time($df);
684
		return apply_filters('get_the_modified_date', $the_time, $date_format);
685
	}
686
687
	/**
688
	 * @internal
689
	 * @param  string $time_format
690
	 * @return string
691
	 */
692
	function get_modified_time( $time_format = '' ) {
693
		$tf = $time_format ? $time_format : get_option('time_format');
694
		$the_time = get_post_modified_time($tf, false, $this->ID, true);
695
		return apply_filters('get_the_modified_time', $the_time, $time_format);
696
	}
697
698
	/**
699
	 * @internal
700
	 * @see TimberPost::children
701
	 * @param string 		$post_type
702
	 * @param bool|string 	$childPostClass
703
	 * @return array
704
	 */
705
	function get_children( $post_type = 'any', $childPostClass = false ) {
706
		if ( $childPostClass === false ) {
707
			$childPostClass = $this->PostClass;
708
		}
709
		if ( $post_type == 'parent' ) {
710
			$post_type = $this->post_type;
711
		}
712
		$children = get_children('post_parent=' . $this->ID . '&post_type=' . $post_type . '&numberposts=-1&orderby=menu_order title&order=ASC&post_status=publish');
713
		foreach ( $children as &$child ) {
714
			$child = new $childPostClass($child->ID);
715
		}
716
		$children = array_values($children);
717
		return $children;
718
	}
719
720
721
	/**
722
	 * Get the comments for a post
723
	 * @internal
724
	 * @see TimberPost::comments
725
	 * @param int $ct
726
	 * @param string $order
727
	 * @param string $type
728
	 * @param string $status
729
	 * @param string $CommentClass
730
	 * @return array|mixed
731
	 */
732
733
	function get_comments($ct = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment') {
0 ignored issues
show
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...
734
735
		global $overridden_cpage, $user_ID;
736
		$overridden_cpage = false;
737
738
		$commenter = wp_get_current_commenter();
739
		$comment_author_email = $commenter['comment_author_email'];
740
741
		$args = array('post_id' => $this->ID, 'status' => $status, 'order' => $order);
742
		if ( $ct > 0 ) {
743
			$args['number'] = $ct;
744
		}
745
		if ( strtolower($order) == 'wp' || strtolower($order) == 'wordpress' ) {
746
			$args['order'] = get_option('comment_order');
747
		}
748
749
		if ( $user_ID ) {
750
			$args['include_unapproved'] = array( $user_ID );
751
		} elseif ( ! empty( $comment_author_email ) ) {
752
			$args['include_unapproved'] = array( $comment_author_email );
753
		}
754
755
		$comments = get_comments($args);
756
		$timber_comments = array();
757
758
		if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
759
			set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
760
			$overridden_cpage = true;
761
		}
762
763
		foreach($comments as $key => &$comment) {
764
			$timber_comment = new $CommentClass($comment);
765
			$timber_comments[$timber_comment->id] = $timber_comment;
766
		}
767
768
		// Build a flattened (depth=1) comment tree
769
		$comments_tree = array();
770
		foreach( $timber_comments as $key => $comment ) {
771
			if ( ! $comment->is_child() ) {
772
				continue;
773
			}
774
775
			$tree_element = $comment;
776
			do {
777
				$tree_element = $timber_comments[$tree_element->comment_parent];
778
			} while( $tree_element->is_child() );
779
780
			$comments_tree[$tree_element->id][] = $comment->id;
781
		}
782
783
		// Add child comments to the relative "super parents"
784
		foreach($comments_tree as $comment_parent => $comment_children) {
785
			foreach($comment_children as $comment_child) {
786
				$timber_comments[$comment_parent]->children[] = $timber_comments[$comment_child];
787
				unset($timber_comments[$comment_child]);
788
			}
789
		}
790
791
		$timber_comments = array_values($timber_comments);
792
793
		return $timber_comments;
794
	}
795
796
	/**
797
	 * Get the categories for a post
798
	 * @internal
799
	 * @see TimberPost::categories
800
	 * @return array of TimberTerms
801
	 */
802
	function get_categories() {
803
		return $this->get_terms('category');
804
	}
805
806
	/**
807
	 * @internal
808
	 * @see TimberPost::category
809
	 * @return mixed
810
	 */
811
	function get_category( ) {
812
		$cats = $this->get_categories();
813
		if ( count($cats) && isset($cats[0]) ) {
814
			return $cats[0];
815
		}
816
	}
817
818
	/**
819
	 * @internal
820
	 * @param string|array $tax
821
	 * @param bool $merge
822
	 * @param string $TermClass
823
	 * @return array
824
	 */
825
	function get_terms( $tax = '', $merge = true, $TermClass = '' ) {
826
827
		$TermClass = $TermClass ?: $this->TermClass;
828
829
		if ( is_string($merge) && class_exists($merge) ) {
830
			$TermClass = $merge;
831
		}
832
		if ( is_array($tax) ) {
833
			$taxonomies = $tax;
834
		}
835
		if ( is_string($tax) ) {
836
			if ( in_array($tax, array('all','any','')) ) {
837
				$taxonomies = get_object_taxonomies($this->post_type);
838
			} else {
839
				$taxonomies = array($tax);
840
			}
841
		}
842
843
		$term_class_objects = array();
844
845
		foreach ( $taxonomies as $taxonomy ) {
846
			if ( in_array($taxonomy, array('tag','tags')) ) {
847
				$taxonomy = 'post_tag';
848
			}
849
			if ( $taxonomy == 'categories' ) {
850
				$taxonomy = 'category';
851
			}
852
853
			$terms = wp_get_post_terms($this->ID, $taxonomy);
854
855
			if ( is_wp_error($terms) ) {
856
				/* @var $terms WP_Error */
857
				TimberHelper::error_log("Error retrieving terms for taxonomy '$taxonomy' on a post in timber-post.php");
858
				TimberHelper::error_log('tax = ' . print_r($tax, true));
859
				TimberHelper::error_log('WP_Error: ' . $terms->get_error_message());
860
861
				return $term_class_objects;
862
			}
863
864
			// map over array of wordpress terms, and transform them into instances of the TermClass
865
			$terms = array_map(function($term) use ($TermClass, $taxonomy) {
866
				return call_user_func(array($TermClass, 'from'), $term->term_id, $taxonomy);
867
			}, $terms);
868
869
			if ( $merge && is_array($terms) ) {
870
				$term_class_objects = array_merge($term_class_objects, $terms);
871
			} else if ( count($terms) ) {
872
				$term_class_objects[$taxonomy] = $terms;
873
			}
874
		}
875
		return $term_class_objects;
876
	}
877
878
	/**
879
	 * @param string|int $term_name_or_id
880
	 * @param string $taxonomy
881
	 * @return bool
882
	 */
883
	function has_term( $term_name_or_id, $taxonomy = 'all' ) {
884
		if ( $taxonomy == 'all' || $taxonomy == 'any' ) {
885
			$taxes = get_object_taxonomies($this->post_type, 'names');
886
			$ret = false;
887
			foreach ( $taxes as $tax ) {
888
				if ( has_term($term_name_or_id, $tax, $this->ID) ) {
889
					$ret = true;
890
					break;
891
				}
892
			}
893
			return $ret;
894
		}
895
		return has_term($term_name_or_id, $taxonomy, $this->ID);
896
	}
897
898
	/**
899
	 * @param string $field
900
	 * @return TimberImage
901
	 */
902
	function get_image( $field ) {
903
		return new $this->ImageClass($this->$field);
904
	}
905
906
	/**
907
	 * Gets an array of tags for you to use
908
	 * @internal
909
	 * @example
910
	 * ```twig
911
	 * <ul class="tags">
912
	 *     {% for tag in post.tags %}
913
	 *         <li>{{tag.name}}</li>
914
	 *     {% endfor %}
915
	 * </ul>
916
	 * ```
917
	 * @return array
918
	 */
919
	function get_tags() {
920
		return $this->get_terms('post_tag');
921
	}
922
923
	/**
924
	 * Outputs the title with filters applied
925
	 * @internal
926
	 * @example
927
	 * ```twig
928
	 * <h1>{{post.get_title}}</h1>
929
	 * ```
930
	 * ```html
931
	 * <h1>Hello World!</h1>
932
	 * ```
933
	 * @return string
934
	 */
935
	function get_title() {
936
		return apply_filters('the_title', $this->post_title, $this->ID);
937
	}
938
939
	/**
940
	 * Displays the content of the post with filters, shortcodes and wpautop applied
941
	 * @example
942
	 * ```twig
943
	 * <div class="article-text">{{post.get_content}}</div>
944
	 * ```
945
	 * ```html
946
	 * <div class="article-text"><p>Blah blah blah</p><p>More blah blah blah.</p></div>
947
	 * ```
948
	 * @param int $len
949
	 * @param int $page
950
	 * @return string
951
	 */
952
	function get_content( $len = 0, $page = 0 ) {
953
		if ( $len == 0 && $page == 0 && $this->_content ) {
954
			return $this->_content;
955
		}
956
		$content = $this->post_content;
957
		if ( $len ) {
958
			$content = wp_trim_words($content, $len);
959
		}
960
		if ( $page ) {
961
			$contents = explode('<!--nextpage-->', $content);
962
			$page--;
963
			if ( count($contents) > $page ) {
964
				$content = $contents[$page];
965
			}
966
		}
967
		$content = apply_filters('the_content', ($content));
968
		if ( $len == 0 && $page == 0 ) {
969
			$this->_content = $content;
970
		}
971
		return $content;
972
	}
973
974
	/**
975
	 * @return string
976
	 */
977
	function get_paged_content() {
978
		global $page;
979
		return $this->get_content(0, $page);
980
	}
981
	/**
982
	 *
983
	 * Here is my summary
984
	 * @example
985
	 * ```twig
986
	 * This post is from <span>{{ post.get_post_type.labels.plural }}</span>
987
	 * ```
988
	 *
989
	 * ```html
990
	 * This post is from <span>Recipes</span>
991
	 * ```
992
	 * @return mixed
993
	 */
994
	public function get_post_type() {
995
		return get_post_type_object($this->post_type);
996
	}
997
998
	/**
999
	 * @return int the number of comments on a post
1000
	 */
1001
	public function get_comment_count() {
1002
		return get_comments_number($this->ID);
1003
	}
1004
1005
	/**
1006
	 * @param string $field_name
1007
	 * @return mixed
1008
	 */
1009
	public function get_field( $field_name ) {
1010
		$value = apply_filters('timber_post_get_meta_field_pre', null, $this->ID, $field_name, $this);
1011
		if ( $value === null ) {
1012
			$value = get_post_meta($this->ID, $field_name);
1013
			if ( is_array($value) && count($value) == 1 ) {
1014
				$value = $value[0];
1015
			}
1016
			if ( is_array($value) && count($value) == 0 ) {
1017
				$value = null;
1018
			}
1019
		}
1020
		$value = apply_filters('timber_post_get_meta_field', $value, $this->ID, $field_name, $this);
1021
		return $value;
1022
	}
1023
1024
	/**
1025
	 * @param string $field_name
1026
	 */
1027
	function import_field( $field_name ) {
1028
		$this->$field_name = $this->get_field($field_name);
1029
	}
1030
1031
	/**
1032
	 * @internal
1033
	 * @return mixed
1034
	 */
1035
	function get_format() {
1036
		return get_post_format($this->ID);
1037
	}
1038
1039
	/**
1040
	 * Get the CSS classes for a post. For usage you should use `{{post.class}}` instead of `{{post.post_class}}`
1041
	 * @internal
1042
	 * @param string $class additional classes you want to add
1043
	 * @see TimberPost::$class
1044
	 * @example
1045
	 * ```twig
1046
	 * <article class="{{ post.class }}">
1047
	 *    {# Some stuff here #}
1048
	 * </article>
1049
	 * ```
1050
	 *
1051
	 * ```html
1052
	 * <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">
1053
	 *    {# Some stuff here #}
1054
	 * </article>
1055
	 * ```
1056
	 * @return string a space-seperated list of classes
1057
	 */
1058
	public function post_class( $class='' ) {
1059
		global $post;
1060
		$old_global_post = $post;
1061
		$post = $this;
1062
		$class_array = get_post_class($class, $this->ID);
1063
		$post = $old_global_post;
1064
		if ( is_array($class_array) ){
1065
			return implode(' ', $class_array);
1066
		}
1067
		return $class_array;
1068
	}
1069
1070
	// Docs
1071
1072
	/**
1073
	 * @return array
1074
	 * @codeCoverageIgnore
1075
	 */
1076
	public function get_method_values() {
1077
		$ret = parent::get_method_values();
1078
		$ret['author'] = $this->author();
1079
		$ret['categories'] = $this->categories();
1080
		$ret['category'] = $this->category();
1081
		$ret['children'] = $this->children();
1082
		$ret['comments'] = $this->comments();
1083
		$ret['content'] = $this->content();
1084
		$ret['edit_link'] = $this->edit_link();
1085
		$ret['format'] = $this->format();
1086
		$ret['link'] = $this->link();
1087
		$ret['next'] = $this->next();
1088
		$ret['pagination'] = $this->pagination();
1089
		$ret['parent'] = $this->parent();
1090
		$ret['path'] = $this->path();
1091
		$ret['prev'] = $this->prev();
1092
		$ret['terms'] = $this->terms();
1093
		$ret['tags'] = $this->tags();
1094
		$ret['thumbnail'] = $this->thumbnail();
1095
		$ret['title'] = $this->title();
1096
		return $ret;
1097
	}
1098
1099
	/**
1100
	 * Return the author of a post
1101
	 * @api
1102
	 * @example
1103
	 * ```twig
1104
	 * <h1>{{post.title}}</h1>
1105
	 * <p class="byline">
1106
	 *     <a href="{{post.author.link}}">{{post.author.name}}</a>
1107
	 * </p>
1108
	 * ```
1109
	 * @return TimberUser|bool A TimberUser object if found, false if not
1110
	 */
1111
	public function author() {
1112
		return $this->get_author();
1113
	}
1114
1115
	/**
1116
	 * Get the author (WordPress user) who last modified the post
1117
	 * @example
1118
	 * ```twig
1119
	 * Last updated by {{ post.modified_author.name }}
1120
	 * ```
1121
	 * ```html
1122
	 * Last updated by Harper Lee
1123
	 * ```
1124
	 * @return TimberUser|bool A TimberUser object if found, false if not
1125
	 */
1126
	public function modified_author() {
1127
		return $this->get_modified_author();
1128
	}
1129
1130
	/**
1131
	 * Get the categoires on a particular post
1132
	 * @api
1133
	 * @return array of TimberTerms
1134
	 */
1135
	public function categories() {
1136
		return $this->get_terms('category');
1137
	}
1138
1139
	/**
1140
	 * Returns a category attached to a post
1141
	 * @api
1142
	 * If mulitpuile categories are set, it will return just the first one
1143
	 * @return TimberTerm|null
1144
	 */
1145
	public function category() {
1146
		return $this->get_category();
1147
	}
1148
1149
	/**
1150
	 * Returns an array of children on the post as TimberPosts
1151
	 * (or other claass as you define).
1152
	 * @api
1153
	 * @example
1154
	 * ```twig
1155
	 * {% if post.children %}
1156
	 *     Here are the child pages:
1157
	 *     {% for child in page.children %}
1158
	 *         <a href="{{ child.link }}">{{ child.title }}</a>
1159
	 *     {% endfor %}
1160
	 * {% endif %}
1161
	 * ```
1162
	 * @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
1163
	 * @param string|bool $childPostClass _optional_ a custom post class (ex: 'MyTimberPost') to return the objects as. By default (false) it will use TimberPost::$post_class value.
1164
	 * @return array
1165
	 */
1166
	public function children( $post_type = 'any', $childPostClass = false ) {
1167
		return $this->get_children( $post_type, $childPostClass );
1168
	}
1169
1170
	/**
1171
	 * Gets the comments on a TimberPost and returns them as an array of [TimberComments](#TimberComment) (or whatever comment class you set).
1172
	 * @api
1173
	 * @param int $count Set the number of comments you want to get. `0` is analogous to "all"
1174
	 * @param string $order use ordering set in WordPress admin, or a different scheme
1175
	 * @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
1176
	 * @param string $status Could be 'pending', etc.
1177
	 * @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)
1178
	 * @example
1179
	 * ```twig
1180
	 * {# single.twig #}
1181
	 * <h4>Comments:</h4>
1182
	 * {% for comment in post.comments %}
1183
	 * 	<div class="comment-{{comment.ID}} comment-order-{{loop.index}}">
1184
	 * 		<p>{{comment.author.name}} said:</p>
1185
	 * 		<p>{{comment.content}}</p>
1186
	 * 	</div>
1187
	 * {% endfor %}
1188
	 * ```
1189
	 * @return bool|array
1190
	 */
1191
	public function comments( $count = 0, $order = 'wp', $type = 'comment', $status = 'approve', $CommentClass = 'TimberComment' ) {
1192
		return $this->get_comments($count, $order, $type, $status, $CommentClass);
1193
	}
1194
1195
	/**
1196
	 * 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).
1197
	 * @api
1198
	 * @example
1199
	 * ```twig
1200
	 * <div class="article">
1201
	 *     <h2>{{post.title}}</h2>
1202
	 *     <div class="content">{{ post.content }}</div>
1203
	 * </div>
1204
	 * ```
1205
	 * @param int $page
1206
	 * @return string
1207
	 */
1208
	public function content( $page = 0 ) {
1209
		return $this->get_content(0, $page);
1210
	}
1211
1212
	/**
1213
	 * @return string
1214
	 */
1215
	public function paged_content() {
1216
		return $this->get_paged_content();
1217
	}
1218
1219
	/**
1220
	 * Get the date to use in your template!
1221
	 * @api
1222
	 * @example
1223
	 * ```twig
1224
	 * Published on {{ post.date }} // Uses WP's formatting set in Admin
1225
	 * OR
1226
	 * Published on {{ post.date | date('F jS') }} // Jan 12th
1227
	 * ```
1228
	 *
1229
	 * ```html
1230
	 * Published on January 12, 2015
1231
	 * OR
1232
	 * Published on Jan 12th
1233
	 * ```
1234
	 * @param string $date_format
1235
	 * @return string
1236
	 */
1237
	public function date( $date_format = '' ) {
1238
		return $this->get_date($date_format);
1239
	}
1240
1241
	/**
1242
	 * Get the time to use in your template
1243
	 * @api
1244
	 * @example
1245
	 * ```twig
1246
	 * Published at {{ post.time }} // Uses WP's formatting set in Admin
1247
	 * OR
1248
	 * Published at {{ post.time | time('G:i') }} // 13:25
1249
	 * ```
1250
	 *
1251
	 * ```html
1252
	 * Published at 1:25 pm
1253
	 * OR
1254
	 * Published at 13:25
1255
	 * ```
1256
	 * @param string $time_format
1257
	 * @return string
1258
	 */
1259
	public function time( $time_format = '' ) {
1260
		$tf = $time_format ? $time_format : get_option('time_format');
1261
	 	$the_time = (string)mysql2date($tf, $this->post_date);
1262
	 	return apply_filters('get_the_time', $the_time, $tf);
1263
	}
1264
1265
	/**
1266
	 * @return bool|string
1267
	 */
1268
	public function edit_link() {
1269
		return $this->get_edit_url();
1270
	}
1271
1272
	/**
1273
	 * @api
1274
	 * @return mixed
1275
	 */
1276
	public function format() {
1277
		return $this->get_format();
1278
	}
1279
1280
	/**
1281
	 * get the permalink for a post object
1282
	 * @api
1283
	 * @example
1284
	 * ```twig
1285
	 * <a href="{{post.link}}">Read my post</a>
1286
	 * ```
1287
	 * @return string ex: http://example.org/2015/07/my-awesome-post
1288
	 */
1289
	public function link() {
1290
		return $this->get_permalink();
1291
	}
1292
1293
	/**
1294
	 * @param string $field_name
1295
	 * @return mixed
1296
	 */
1297
	public function meta( $field_name = null ) {
1298
		if ( $field_name === null ) {
1299
			//on the off-chance the field is actually named meta
1300
			$field_name = 'meta';
1301
		}
1302
		return $this->get_field($field_name);
1303
	}
1304
1305
	/**
1306
	 * @return string
1307
	 */
1308
	public function name(){
1309
		return $this->title();
1310
	}
1311
1312
	/**
1313
	 * @param string $date_format
1314
	 * @return string
1315
	 */
1316
	public function modified_date( $date_format = '' ) {
1317
		return $this->get_modified_date($date_format);
1318
	}
1319
1320
	/**
1321
	 * @param string $time_format
1322
	 * @return string
1323
	 */
1324
	public function modified_time( $time_format = '' ) {
1325
		return $this->get_modified_time($time_format);
1326
	}
1327
1328
	/**
1329
	 * @api
1330
	 * @param bool $in_same_cat
1331
	 * @return mixed
1332
	 */
1333
	public function next( $in_same_cat = false ) {
1334
		return $this->get_next($in_same_cat);
1335
	}
1336
1337
	/**
1338
	 * @return array
1339
	 */
1340
	public function pagination() {
1341
		return $this->get_pagination();
1342
	}
1343
1344
	/**
1345
	 * Gets the parent (if one exists) from a post as a TimberPost object (or whatever is set in TimberPost::$PostClass)
1346
	 * @api
1347
	 * @example
1348
	 * ```twig
1349
	 * Parent page: <a href="{{ post.parent.link }}">{{ post.parent.title }}</a>
1350
	 * ```
1351
	 * @return bool|TimberPost
1352
	 */
1353
	public function parent() {
1354
		return $this->get_parent();
1355
	}
1356
1357
	/**
1358
	 * Gets the relative path of a WP Post, so while link() will return http://example.org/2015/07/my-cool-post
1359
	 * this will return just /2015/07/my-cool-post
1360
	 * @api
1361
	 * @example
1362
	 * ```twig
1363
	 * <a href="{{post.path}}">{{post.title}}</a>
1364
	 * ```
1365
	 * @return string
1366
	 */
1367
	public function path() {
1368
		return $this->get_path();
1369
	}
1370
1371
	/**
1372
	 * @deprecated 0.20.0 use link() instead
1373
	 * @return string
1374
	 */
1375
	public function permalink() {
1376
		return $this->get_permalink();
1377
	}
1378
1379
	/**
1380
	 * Get the previous post in a set
1381
	 * @api
1382
	 * @example
1383
	 * ```twig
1384
	 * <h4>Prior Entry:</h4>
1385
	 * <h3>{{post.prev.title}}</h3>
1386
	 * <p>{{post.prev.get_preview(25)}}</p>
1387
	 * ```
1388
	 * @param bool $in_same_cat
1389
	 * @return mixed
1390
	 */
1391
	public function prev( $in_same_cat = false ) {
1392
		return $this->get_prev($in_same_cat);
1393
	}
1394
1395
	/**
1396
	 * Get the terms associated with the post
1397
	 * This goes across all taxonomies by default
1398
	 * @api
1399
	 * @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.
1400
	 * @param bool $merge Should the resulting array be one big one (true)? Or should it be an array of sub-arrays for each taxonomy (false)?
1401
	 * @return array
1402
	 */
1403
	public function terms( $tax = '', $merge = true ) {
1404
		return $this->get_terms($tax, $merge);
1405
	}
1406
1407
	/**
1408
	 * Gets the tags on a post, uses WP's post_tag taxonomy
1409
	 * @api
1410
	 * @return array
1411
	 */
1412
	public function tags() {
1413
		return $this->get_tags();
1414
	}
1415
1416
	/**
1417
	 * get the featured image as a TimberImage
1418
	 * @api
1419
	 * @example
1420
	 * ```twig
1421
	 * <img src="{{post.thumbnail.src}}" />
1422
	 * ```
1423
	 * @return TimberImage|null of your thumbnail
1424
	 */
1425
	public function thumbnail() {
1426
		return $this->get_thumbnail();
1427
	}
1428
1429
	/**
1430
	 * 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.
1431
	 * @api
1432
	 * @example
1433
	 * ```twig
1434
	 * <h1>{{ post.title }}</h1>
1435
	 * ```
1436
	 * @return string
1437
	 */
1438
	public function title() {
1439
		return $this->get_title();
1440
	}
1441
1442
}
1443