| 1 |
<?php |
| 2 |
|
| 3 |
namespace LearnPress\Gutenberg\Templates; |
| 4 |
|
| 5 |
use LearnPress\Helpers\Template; |
| 6 |
use WP_Block_Template; |
| 7 |
|
| 8 |
/** |
| 9 |
* Abstract_Block_Template class. |
| 10 |
* |
| 11 |
* @since 4.2.8 Convert from old class Abstract_Block_Template |
| 12 |
* @version 1.0.1 |
| 13 |
*/ |
| 14 |
abstract class AbstractBlockTemplate extends WP_Block_Template { |
| 15 |
public $theme = 'learnpress/learnpress'; |
| 16 |
public $type = 'wp_template'; |
| 17 |
/** |
| 18 |
* @var string name of the block |
| 19 |
*/ |
| 20 |
public $origin = 'plugin'; |
| 21 |
public $source = 'plugin'; // plugin|custom|theme, if custom save on db will be use 'custom'. |
| 22 |
public $content = ''; // Set content will be shown on edit block and the frontend. |
| 23 |
public $has_theme_file = true; |
| 24 |
public $is_custom = false; |
| 25 |
public $path_html_block_template_file = ''; |
| 26 |
|
| 27 |
public function __construct() { |
| 28 |
$this->id = $this->theme . '//' . $this->slug; |
| 29 |
$template_file = ''; |
| 30 |
|
| 31 |
if ( ! empty( $this->path_html_block_template_file ) ) { |
| 32 |
$template_file = Template::instance( false )->get_frontend_template_type_block( |
| 33 |
$this->path_html_block_template_file |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
// Set content from theme file. |
| 38 |
if ( file_exists( $template_file ) ) { |
| 39 |
$content = file_get_contents( $template_file ); |
| 40 |
if ( version_compare( get_bloginfo( 'version' ), '6.4-beta', '>=' ) ) { |
| 41 |
$this->content = traverse_and_serialize_blocks( parse_blocks( $content ) ); |
| 42 |
} else { |
| 43 |
$this->content = _inject_theme_attribute_in_block_template_content( $content ); |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
|