You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.6 KiB
67 lines
2.6 KiB
<?php
|
|
|
|
namespace AXEWEB_Blocks\Blocks\<%= ownerClass %>\<%= blockClassModel %>;
|
|
|
|
class <%= blockClassModel %>_Component extends \Core\Component {
|
|
const VERSION = '<%= version %>';
|
|
public $block_project = '<%= ownerFilename %>';
|
|
public $block_name = '<%= blockFilename %>';
|
|
public $hook_prefix = 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>';
|
|
|
|
function register_assets(): void {
|
|
$base_path = plugin_dir_url( __FILE__ ); // In Plugins
|
|
// $base_path = get_template_directory_uri() . '/components/partials/<%= blockFilename %>/'; // In Theme
|
|
|
|
$style_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::style_deps', [ 'assets-style' ] );
|
|
wp_register_style( 'block-<%= blockFilename %>', $base_path . 'templates/styles/<%= blockFilename %>.min.css', $style_deps, self::VERSION );
|
|
|
|
$script_deps = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::script_deps', [ 'assets-script' ] );
|
|
wp_register_script( 'block-<%= blockFilename %>', $base_path . 'templates/scripts/<%= blockFilename %>.min.js', $script_deps, self::VERSION, true );
|
|
}
|
|
|
|
public function prepare_for_print() {
|
|
if ( ! is_admin() ) {
|
|
wp_enqueue_style( 'block-<%= blockFilename %>' );
|
|
wp_enqueue_script( 'block-<%= blockFilename %>' );
|
|
}
|
|
}
|
|
|
|
public function get_content( $args = [] ): string {
|
|
$default_args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::default_args', [] ); // Not really practical.
|
|
|
|
$args = apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::prepare_args', array_merge( $default_args, $args ) );
|
|
|
|
$output = ( include( __DIR__ . '/templates/<%= blockFilename %>.template.php' ) )( $args, self::class );
|
|
|
|
return apply_filters( 'axeweb_blocks/<%= ownerFilename %>/<%= blockFilename %>::content', $output );
|
|
}
|
|
|
|
function register_custom_logic(): void {
|
|
add_action( 'elementor/widgets/widgets_registered', [ $this, 'register_elementor_widget' ] );
|
|
}
|
|
|
|
function register_elementor_widget( $widgets_manager ): void {
|
|
require_once "helpers/<%= blockClassModel %>_Elementor_Widget.php";
|
|
$widgets_manager->register_widget_type( new Helpers\<%= blockClassModel %>_Elementor_Widget() );
|
|
}
|
|
|
|
function register_acf_block() {
|
|
$this->register_block( __DIR__ . "/<%= blockFilename %>.block.json", [
|
|
'style_assets' => [
|
|
[
|
|
'name' => 'block-<%= blockFilename %>',
|
|
'url' => null
|
|
]
|
|
],
|
|
'script_assets' => [
|
|
[
|
|
'name' => 'block-<%= blockFilename %>',
|
|
'url' => null
|
|
]
|
|
]
|
|
] );
|
|
}
|
|
}
|
|
|
|
<%= blockClassModel %>_Component::get_instance();
|
|
// new <%= blockClassModel %>_Component();
|
|
|