1 | <?php |
||
13 | class Post |
||
14 | { |
||
15 | /** |
||
16 | * The post |
||
17 | * @var WP_Post |
||
18 | */ |
||
19 | protected $post; |
||
20 | |||
21 | /** |
||
22 | * Post ID |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $id; |
||
26 | |||
27 | /** |
||
28 | * The post type of the post this model wraps |
||
29 | * @var string |
||
30 | */ |
||
31 | const POST_TYPE = 'post'; |
||
32 | |||
33 | |||
34 | /** |
||
35 | * [__construct description] |
||
36 | * @param WP_Post $post [description] |
||
37 | */ |
||
38 | public function __construct(WP_Post $post = null) |
||
48 | |||
49 | public static function fromWpPost(WP_Post $post) |
||
57 | |||
58 | /** |
||
59 | * Make new instance from a Post with the given ID |
||
60 | * |
||
61 | * @param int|string $id [description] |
||
62 | * |
||
63 | * @return static |
||
64 | */ |
||
65 | public static function fromID($id) |
||
75 | |||
76 | /** |
||
77 | * Make new instance from a Post slug |
||
78 | * |
||
79 | * @param string $slug the post slug |
||
80 | * |
||
81 | * @return static |
||
82 | */ |
||
83 | public static function fromSlug($slug) |
||
98 | |||
99 | /** |
||
100 | * Make new instance from the global $post |
||
101 | * |
||
102 | * @return static |
||
103 | */ |
||
104 | public static function fromGlobal() |
||
114 | |||
115 | /** |
||
116 | * Create a new post of the model's type |
||
117 | * |
||
118 | * @param [type] $attributes [description] |
||
119 | * @return [type] [description] |
||
120 | */ |
||
121 | public static function create($attributes = []) |
||
130 | |||
131 | /** |
||
132 | * Meta API for this post |
||
133 | * |
||
134 | * @param string $key [description] |
||
135 | * @return Meta |
||
136 | */ |
||
137 | public function meta($key = '') |
||
147 | |||
148 | /** |
||
149 | * Send the post to the trash |
||
150 | * |
||
151 | * If trash is disabled, the post or page is permanently deleted. |
||
152 | * |
||
153 | * @return false|array|WP_Post|null Post data array, otherwise false. |
||
154 | */ |
||
155 | public function trash() |
||
163 | |||
164 | /** |
||
165 | * Restore a post or page from the Trash |
||
166 | * |
||
167 | * @return WP_Post|false WP_Post object. False on failure. |
||
168 | */ |
||
169 | public function untrash() |
||
177 | |||
178 | /** |
||
179 | * Permanently deletes the post and related objects |
||
180 | * |
||
181 | * When the post and page is permanently deleted, everything that is |
||
182 | * tied to it is deleted also. This includes comments, post meta fields, |
||
183 | * and terms associated with the post. |
||
184 | * |
||
185 | * @return [type] [description] |
||
186 | */ |
||
187 | public function delete() |
||
195 | |||
196 | /** |
||
197 | * Refresh the post object from cache/database |
||
198 | * |
||
199 | * @return static |
||
200 | */ |
||
201 | public function refresh() |
||
207 | |||
208 | /** |
||
209 | * Update the post in the database |
||
210 | * |
||
211 | * @return [type] [description] |
||
212 | */ |
||
213 | public function save() |
||
229 | |||
230 | /** |
||
231 | * [__get description] |
||
232 | * @param [type] $property [description] |
||
233 | * @return [type] [description] |
||
234 | */ |
||
235 | public function __get($property) |
||
251 | |||
252 | /** |
||
253 | * [__set description] |
||
254 | * @param [type] $property [description] |
||
255 | * @param [type] $value [description] |
||
256 | */ |
||
257 | public function __set($property, $value) |
||
263 | } |
||
264 |