| @@ -1,0 +1,38 @@ | ||
| 1 | +<?php | |
| 2 | +namespace ABlocksThemeBuilder; | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | + | |
| 8 | +use ABlocksThemeBuilder\Traits\RenderContent; | |
| 9 | + | |
| 10 | +class Shortcode { | |
| 11 | + use RenderContent; | |
| 12 | + | |
| 13 | + public static function init() { | |
| 14 | + $self = new self(); | |
| 15 | + add_shortcode( 'ablocks_template', [ $self, 'render_template' ] ); | |
| 16 | + } | |
| 17 | + public function render_template( $attributes ) { | |
| 18 | + $attributes = shortcode_atts( | |
| 19 | + [ | |
| 20 | + 'id' => '', | |
| 21 | + ], | |
| 22 | + $attributes, | |
| 23 | + 'ablocks_template' | |
| 24 | + ); | |
| 25 | + | |
| 26 | + $id = ! empty( $attributes['id'] ) ? apply_filters( 'ablocks/theme_builder/render_template_id', intval( $attributes['id'] ) ) : ''; | |
| 27 | + | |
| 28 | + if ( empty( $id ) ) { | |
| 29 | + return ''; | |
| 30 | + } | |
| 31 | + add_filter( 'ablocks/is_allow_block_inline_assets', '__return_true' ); | |
| 32 | + add_filter( 'ablocks/is_enabled_assets_generation', '__return_false' ); | |
| 33 | + $content = $this->get_rendered_block_content_by_id( $id ); | |
| 34 | + remove_filter( 'ablocks/is_allow_block_inline_assets', '__return_true' ); | |
| 35 | + remove_filter( 'ablocks/is_enabled_assets_generation', '__return_false' ); | |
| 36 | + return $content; | |
| 37 | + } | |
| 38 | +} | |