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: Enqueue Assets #62

Merged
merged 5 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
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
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),
);
}
}
Loading