Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions source/php/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Module
* A place to store the id of a module instance.
* Adds block support, which dosen't require a ID (works well with null).
*
* @var int|null
* @var int|string|null
*/
public $ID = null;

Expand Down Expand Up @@ -188,6 +188,7 @@ public function __construct(
$this->args = $args;

$this->ID = $post->ID ?? null;

$this->postStatus = $post->post_status ?? 'publish';

$this->init();
Expand Down Expand Up @@ -326,16 +327,28 @@ public function collectViewData()
$this->data = array_merge($this->data, $this->data());
}

/**
* Get the ID of the module or block
* @return int|string|null
*/
protected function getID(): int|string|null
{
if ($this->ID) {
$id = $this->ID;
} else {
$id = acf_get_valid_post_id( false );
}

return $this->ID = $id ?: null;
}

/**
* Get metadata for block or module.
* @return array
*/
protected function getFields() {
$this->dataFetched = true;
if(is_numeric($this->ID)) {
return AcfService::get()->getFields($this->ID) ?: [];
}
return AcfService::get()->getFields() ?: []; //Blocks
return AcfService::get()->getFields($this->getID()) ?: [];
}

private function getBlockNamesFromPage(): array
Expand Down