Skip to content

Commit 1664da1

Browse files
committed
If no post ID is provided we now set it to -1 which can never exist
1 parent d74aad6 commit 1664da1

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Posts/Post.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ class Post
1212
*
1313
* @param integer $id
1414
*/
15-
public function __construct(int $id = 0)
15+
public function __construct(int $id)
1616
{
17-
$this->id = $id;
18-
19-
if (!$this->getPost()) {
20-
throw new \Exception('Post not found.');
21-
}
17+
$this->id = ($id ?: -1);
2218

2319
$this->date_format = \get_option('date_format');
2420
}
@@ -112,8 +108,6 @@ public function content()
112108
*/
113109
public function parent()
114110
{
115-
$parent_id = $this->getPost()->post_parent;
116-
117-
return ($parent_id ? new Post($parent_id) : null);
111+
return new Post($this->getPost()->post_parent);
118112
}
119113
}

0 commit comments

Comments
 (0)