From a0def8467b10513aed740e475d14034e2c44db24 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Fri, 9 Dec 2022 18:29:42 +0200 Subject: [PATCH 1/5] Make sure WordPress className initialized. --- platforms/wordpress/templates/Template_Basic_Component.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php index 620556e..3e262c6 100644 --- a/platforms/wordpress/templates/Template_Basic_Component.php +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -39,4 +39,5 @@ class <%= blockClassModel %>_Component <% if (isComponentManager) { %>extends \C } -<%= blockClassModel %>_Component::get_instance(); +<% if (isComponentManager) { %><%= blockClassModel %>_Component::get_instance();<% } else { + %>new <%= blockClassModel %>_Component();<% } %> From 4abdd297095f93633ceff20c55edb7ad6596584d Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Fri, 9 Dec 2022 19:56:49 +0200 Subject: [PATCH 2/5] Add FLAG::THIS in PHP builder. --- platforms/php/build.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/php/build.php b/platforms/php/build.php index 0e2d1d8..bb1d822 100644 --- a/platforms/php/build.php +++ b/platforms/php/build.php @@ -81,7 +81,7 @@ class Component_Builder { $template = file_get_contents( $path ); $phpStr = LightnCandy::compile( $template, [ - 'flags' => Flags::FLAG_NOESCAPE | Flags::FLAG_PARENT | Flags::FLAG_SPVARS | Flags::FLAG_ELSE | Flags::FLAG_JSLENGTH | Flags::FLAG_JSTRUE, + 'flags' => Flags::FLAG_NOESCAPE | Flags::FLAG_PARENT | Flags::FLAG_SPVARS | Flags::FLAG_ELSE | Flags::FLAG_JSLENGTH | Flags::FLAG_JSTRUE | Flags::FLAG_THIS, 'helpers' => $this->custom_handlebars ?? [], ] ); From ddbc713603c8b9a8fcba6564fa4645dabf3206fa Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Sat, 10 Dec 2022 12:59:26 +0200 Subject: [PATCH 3/5] Add scripts/styling to the page only on frontend side. (not in admin panel). --- .../wordpress/templates/Template_Basic_Component.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php index 3e262c6..ffe2cc2 100644 --- a/platforms/wordpress/templates/Template_Basic_Component.php +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -15,10 +15,12 @@ class <%= blockClassModel %>_Component <% if (isComponentManager) { %>extends \C // $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/'; // In Theme wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', [ 'assets-style' ], self::VERSION ); - wp_enqueue_style( 'block-<%= blockFilename %>' ); - wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', [ 'assets-script' ], self::VERSION, true ); - wp_enqueue_script( 'block-<%= blockFilename %>' ); + + if ( ! is_admin() ) { + wp_enqueue_style( 'block-<%= blockFilename %>' ); + wp_enqueue_script( 'block-<%= blockFilename %>' ); + } } public function get_content( $args = [] ): string { From 682299445c90f2c406dc92cb108aed92ffa75f57 Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Sun, 11 Dec 2022 09:37:16 +0200 Subject: [PATCH 4/5] Add hook_prefix to Component object. --- platforms/wordpress/templates/Template_Component.php | 1 + 1 file changed, 1 insertion(+) diff --git a/platforms/wordpress/templates/Template_Component.php b/platforms/wordpress/templates/Template_Component.php index 3e98e8d..14ab8cb 100644 --- a/platforms/wordpress/templates/Template_Component.php +++ b/platforms/wordpress/templates/Template_Component.php @@ -4,6 +4,7 @@ namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>; class <%= blockClassModel %>_Component extends \Core\Component { const VERSION = '<%= version %>'; + public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>'; public function get_content( $args = [] ): string { $default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical. From ec61e019507a934a071dc0c417a45f4e89d2082c Mon Sep 17 00:00:00 2001 From: Roman Axelrod Date: Sun, 11 Dec 2022 09:42:40 +0200 Subject: [PATCH 5/5] Add hook_prefix to Component object. --- build.js | 2 +- platforms/wordpress/templates/Template_Basic_Component.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index b656dbf..deb037d 100755 --- a/build.js +++ b/build.js @@ -9,7 +9,7 @@ const {isDev, developmentBlockName} = getConfigs(); const blockName = !isDev && config.has('blockName') ? config.get('blockName') : developmentBlockName; export const PLATFORM_OPTIONS = [{ - name: 'wordpress-blocks', + name: 'wordpress-acf-block', title: 'WordPress AFC Block' }, { name: 'wordpress', diff --git a/platforms/wordpress/templates/Template_Basic_Component.php b/platforms/wordpress/templates/Template_Basic_Component.php index ffe2cc2..3686f8f 100644 --- a/platforms/wordpress/templates/Template_Basic_Component.php +++ b/platforms/wordpress/templates/Template_Basic_Component.php @@ -3,7 +3,8 @@ namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>; class <%= blockClassModel %>_Component <% if (isComponentManager) { %>extends \Core\Component <% } %>{ - const VERSION = '<%= version %>'; + const VERSION = '<%= version %>';<% if (isComponentManager) { %> + public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';<% } %> <% if (!isComponentManager) { %>public function __construct() { // add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] );