Skip to content

Commit b4bb3ac

Browse files
committed
Refactored Post_Preview_Service to only set data on get methods. Issue is setting values in the constructor means ACF hooks have not fired.
1 parent b4c5be8 commit b4bb3ac

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

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

0 commit comments

Comments
 (0)