Skip to content

Commit 2d49bf0

Browse files
authored
Merge pull request #370 from wpengine/bug-fix-acf-post-types-for-previews
fix: Fixed post type initialisation before ACF hooks
2 parents b4c5be8 + fc66722 commit 2d49bf0

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

.changeset/olive-queens-look.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wpengine/hwp-previews-wordpress-plugin": patch
3+
---
4+
5+
bug: Fixed issue with retrieving post types before ACF hook initialisation.

plugins/hwp-previews/src/Preview/Post/Post_Preview_Service.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,11 @@ class Post_Preview_Service {
3535
*/
3636
protected $parent_post_statuses = [];
3737

38-
/**
39-
* Constructor for the Post_Preview_Service class.
40-
*
41-
* Initializes the allowed post-types and statuses for previews.
42-
*/
43-
public function __construct() {
44-
$this->set_post_types();
45-
$this->set_post_statuses();
46-
$this->set_post_parent_statuses();
47-
}
48-
4938
/**
5039
* @return array<string>
5140
*/
5241
public function get_allowed_post_types(): array {
53-
return $this->post_types;
42+
return $this->get_post_types();
5443
}
5544

5645
/**
@@ -59,6 +48,11 @@ public function get_allowed_post_types(): array {
5948
* @return array<string>
6049
*/
6150
public function get_post_statuses(): array {
51+
$post_statuses = $this->post_statuses;
52+
if ([] !== $post_statuses) {
53+
return $post_statuses;
54+
}
55+
$this->set_post_statuses();
6256
return $this->post_statuses;
6357
}
6458

@@ -68,6 +62,11 @@ public function get_post_statuses(): array {
6862
* @return array<string>
6963
*/
7064
public function get_post_types(): array {
65+
$post_types = $this->post_types;
66+
if ([] !== $post_types) {
67+
return $post_types;
68+
}
69+
$this->set_post_types();
7170
return $this->post_types;
7271
}
7372

@@ -77,6 +76,11 @@ public function get_post_types(): array {
7776
* @return array<string>
7877
*/
7978
public function get_parent_post_statuses(): array {
79+
$parent_post_statuses = $this->parent_post_statuses;
80+
if ([] !== $parent_post_statuses) {
81+
return $parent_post_statuses;
82+
}
83+
$this->set_post_parent_statuses();
8084
return $this->parent_post_statuses;
8185
}
8286

pnpm-lock.yaml

Lines changed: 32 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)