Skip to content

Commit

Permalink
Merge pull request #62 from ItinerisLtd/assets
Browse files Browse the repository at this point in the history
feat: Enqueue Assets
  • Loading branch information
codepuncher committed Jun 19, 2024
2 parents 0d8a2a6 + e2f9cdb commit 7fb99d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/AbstractBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,12 @@ public function renderBlockCallback(array $block): void
ob_start();

// TODO: Check for remote file inclusion (WP VIP).
// phpcs:disable WordPressVIPMinimum.Files.IncludingFile.IncludingFile
// phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.IncludingFile
include apply_filters('acf_gutenblocks/render_block_html', $path, $controller);
// phpcs:enable

$html = ob_get_clean();

// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo apply_filters('acf_gutenblocks/render_block_html_output', $html, $controller);
// phpcs:enable
}
}
14 changes: 12 additions & 2 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Itineris\AcfGutenblocks;

use ReflectionClass;

class Block
{
/**
Expand Down Expand Up @@ -101,12 +103,11 @@ class Block
* Begin block construction!
*
* @since 0.10
* @param array $settings The block definitions.
*/
public function __construct(array $settings)
{
// Path related definitions.
$reflection = new \ReflectionClass($this);
$reflection = new ReflectionClass($this);
$block_path = $reflection->getFileName();
$directory_path = dirname($block_path);
$this->name = Util::camelToKebab(basename($block_path, '.php'));
Expand Down Expand Up @@ -287,11 +288,20 @@ public function getBlockData(): array
];
}

/**
* Callback method to enqueue block assets
*
* @since 0.6.0
*/
public function enqueueAssets(): void
{
}

public function init(): void
{
$block_data = $this->getBlockData();
$block_data['render_callback'] = [$this, 'renderBlockCallback'];
$block_data['enqueue_assets'] = $this->enqueueAssets();
$fields = $this->getFields();

acf_register_block($block_data);
Expand Down
7 changes: 4 additions & 3 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public static function camelToKebab(string $string): string

public static function sanitizeHtmlClasses(array $classes): string
{
return implode(' ', array_map(function ($class): string {
return sanitize_html_class((string) $class);
}, $classes));
return implode(
' ',
array_map(fn ($class): string => sanitize_html_class((string) $class), $classes),
);
}
}

0 comments on commit 7fb99d5

Please sign in to comment.