Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get default WP block attributes #1

Merged
merged 1 commit into from
Jan 22, 2024
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
17 changes: 17 additions & 0 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ class Block implements BlockInterface
*/
public array $classes;

/**
* Array of native Wordpress block HTML attributes. Can be added to the block
* @var array
*/
protected array $blockAttributes;


public function __construct()
{
if (is_admin()) {
$this->isAdmin = true;
}

$this->classes = $this->getClasses();
$this->blockAttributes = $this->getWpAttributes();
}

/**
Expand Down Expand Up @@ -81,6 +89,15 @@ public static function display(): void
{
}

private static function getWpAttributes(): array
{
$attrString = get_block_wrapper_attributes();
$attrArray = current((array) new \SimpleXMLElement("<element " . $attrString. " />"));
$attrArray['raw'] = $attrString;

return $attrArray;
}

private static function getBlockNameFromDir(): string
{
$reflector = new \ReflectionClass(get_called_class());
Expand Down