Revert "Revert "Restrict dynamic blocks to public post status only""

This reverts commit 79991ae462.
This commit is contained in:
Sam
2022-04-12 18:22:50 +02:00
committed by Veljko V
parent c32dc0a372
commit bcae8ade3f
3 changed files with 37 additions and 18 deletions

View File

@@ -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';
}