Skip to content

Commit 1bd2cd5

Browse files
committed
Added more helper methods for Post
1 parent 1664da1 commit 1bd2cd5

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

src/Posts/Post.php

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,34 @@ public function __construct(int $id)
1919
$this->date_format = \get_option('date_format');
2020
}
2121

22+
/**
23+
* The ID
24+
*
25+
* @return int
26+
*/
27+
public function id()
28+
{
29+
return $this->id;
30+
}
31+
2232
/**
2333
* Get WP_Post object
2434
*
2535
* @return WP_Post
2636
*/
2737
protected function getPost()
2838
{
29-
return \get_post($this->id);
39+
return \get_post($this->id());
40+
}
41+
42+
/**
43+
* The url
44+
*
45+
* @return string
46+
*/
47+
public function url()
48+
{
49+
return \get_permalink($this->id());
3050
}
3151

3252
/**
@@ -39,24 +59,44 @@ public function slug()
3959
return ($this->getPost()->post_name ?? null);
4060
}
4161

62+
/**
63+
* The status
64+
*
65+
* @return string
66+
*/
67+
public function status()
68+
{
69+
return \get_post_status($this->id());
70+
}
71+
72+
/**
73+
* The format
74+
*
75+
* @return string
76+
*/
77+
public function format()
78+
{
79+
return \get_post_format($this->id());
80+
}
81+
4282
/**
4383
* The title
4484
*
4585
* @return string
4686
*/
4787
public function title()
4888
{
49-
return \get_the_title($this->id);
89+
return \get_the_title($this->id());
5090
}
5191

5292
/**
53-
* The exceprt
93+
* The excerpt
5494
*
5595
* @return string
5696
*/
5797
public function excerpt()
5898
{
59-
return \get_the_excerpt($this->id);
99+
return \get_the_excerpt($this->id());
60100
}
61101

62102
/**
@@ -69,7 +109,7 @@ public function publishDate($format = null)
69109
{
70110
$format = ($format ?: $this->date_format);
71111

72-
return \get_the_date($format, $this->id);
112+
return \get_the_date($format, $this->id());
73113
}
74114

75115
/**
@@ -82,7 +122,7 @@ public function modifiedDate($format = null)
82122
{
83123
$format = ($format ?: $this->date_format);
84124

85-
return \get_the_modified_time($format, $this->id);
125+
return \get_the_modified_time($format, $this->id());
86126
}
87127

88128
/**

0 commit comments

Comments
 (0)