Revert "Revert "Restrict dynamic blocks to public
post status only""
This reverts commit 79991ae462
.
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace MailPoet\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\API\JSON\SuccessResponse;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Newsletter\AutomatedLatestContent as ALC;
|
||||
use MailPoet\Newsletter\BlockPostQuery;
|
||||
@ -77,29 +78,28 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_Post[] $posts
|
||||
* @return \WP_Post[]
|
||||
* Fetches posts for Posts static block
|
||||
*/
|
||||
private function getPermittedPosts($posts) {
|
||||
return array_filter($posts, function ($post) {
|
||||
return $this->permissionHelper->checkReadPermission($post);
|
||||
});
|
||||
}
|
||||
|
||||
public function getPosts($data = []) {
|
||||
public function getPosts(array $data = []): SuccessResponse {
|
||||
return $this->successResponse(
|
||||
$this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data])))
|
||||
$this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data, 'dynamic' => false])))
|
||||
);
|
||||
}
|
||||
|
||||
public function getTransformedPosts($data = []) {
|
||||
/**
|
||||
* Fetches products for Abandoned Cart Content dynamic block
|
||||
*/
|
||||
public function getTransformedPosts(array $data = []): SuccessResponse {
|
||||
$posts = $this->getPermittedPosts($this->ALC->getPosts(new BlockPostQuery(['args' => $data])));
|
||||
return $this->successResponse(
|
||||
$this->ALC->transformPosts($data, $posts)
|
||||
);
|
||||
}
|
||||
|
||||
public function getBulkTransformedPosts($data = []) {
|
||||
/**
|
||||
* Fetches different post types for ALC dynamic block
|
||||
*/
|
||||
public function getBulkTransformedPosts(array $data = []): SuccessResponse {
|
||||
$usedPosts = [];
|
||||
$renderedPosts = [];
|
||||
|
||||
@ -115,4 +115,14 @@ class AutomatedLatestContent extends APIEndpoint {
|
||||
|
||||
return $this->successResponse($renderedPosts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \WP_Post[] $posts
|
||||
* @return \WP_Post[]
|
||||
*/
|
||||
private function getPermittedPosts($posts) {
|
||||
return array_filter($posts, function ($post) {
|
||||
return $this->permissionHelper->checkReadPermission($post);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -29,12 +29,20 @@ class BlockPostQuery {
|
||||
public $newsletterId = false;
|
||||
|
||||
/***
|
||||
* Translates to \WP_Query::date_query => ['column' => 'post_date', 'after' => {date string}]
|
||||
* Translates to \WP_Query::date_query => array{'column': 'post_date', 'after': date string}
|
||||
*
|
||||
* @var bool|DateTimeInterface|null
|
||||
*/
|
||||
public $newerThanTimestamp = false;
|
||||
|
||||
/**
|
||||
* If it's a dynamic block
|
||||
* Dynamic blocks are not allowed to query none-public posts
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $dynamic = true;
|
||||
|
||||
/**
|
||||
* @param array{
|
||||
* args?: array{
|
||||
@ -51,6 +59,7 @@ class BlockPostQuery {
|
||||
* postsToExclude?: int[],
|
||||
* newsletterId?: int|false|null,
|
||||
* newerThanTimestamp?: bool|DateTimeInterface|null,
|
||||
* dynamic?: bool,
|
||||
* } $query
|
||||
* @return void
|
||||
*/
|
||||
@ -61,18 +70,17 @@ class BlockPostQuery {
|
||||
$this->postsToExclude = $query['postsToExclude'] ?? [];
|
||||
$this->newsletterId = $query['newsletterId'] ?? false;
|
||||
$this->newerThanTimestamp = $query['newerThanTimestamp'] ?? false;
|
||||
$this->dynamic = $query['dynamic'] ?? true;
|
||||
}
|
||||
|
||||
public function getPostType(): string {
|
||||
return $this->args['contentType'] ?? 'post';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns post status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPostStatus(): string {
|
||||
if ($this->dynamic) {
|
||||
return 'publish';
|
||||
}
|
||||
return $this->args['postStatus'] ?? 'publish';
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ class AutomatedLatestContentBlock {
|
||||
'postsToExclude' => $postsToExclude,
|
||||
'newsletterId' => $newsletterId,
|
||||
'newerThanTimestamp' => $newerThanTimestamp,
|
||||
'dynamic' => true,
|
||||
]);
|
||||
$aLCPosts = $this->ALC->getPosts($query);
|
||||
foreach ($aLCPosts as $post) {
|
||||
|
Reference in New Issue
Block a user