builders
1 year ago
documents
1 year ago
builder-content.php
1 year ago
class-helper.php
1 year ago
class-loader.php
1 year ago
class-panel-options.php
1 year ago
conditions-file.php
1 year ago
conditions-rules.php
1 year ago
elementor-document.php
1 year ago
theme-builder.php
1 year ago
widgets-passing-lists.php
1 year ago
builder-content.php
88 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly. |
| 4 | } |
| 5 | |
| 6 | class Ec_Template_Builder_Content { |
| 7 | |
| 8 | public static $instance = null; |
| 9 | |
| 10 | public static function get_instance() { |
| 11 | if ( ! isset( self::$instance ) ) { |
| 12 | self::$instance = new self; |
| 13 | } |
| 14 | return self::$instance; |
| 15 | } |
| 16 | |
| 17 | public function ec_get_render_content( $template_ids = ''){ |
| 18 | $content = ''; |
| 19 | if( is_array($template_ids) ){ |
| 20 | foreach( $template_ids as $post_id){ |
| 21 | $content .= $this->ec_render_content($post_id); |
| 22 | } |
| 23 | }else{ |
| 24 | $content .= $this->ec_render_content( $template_ids ); |
| 25 | } |
| 26 | |
| 27 | return $content; |
| 28 | } |
| 29 | |
| 30 | public function ec_render_content( $post_id = ''){ |
| 31 | global $wp_post_types; |
| 32 | |
| 33 | // Check if the post is published |
| 34 | if ( 'publish' !== get_post_status( $post_id ) ) { |
| 35 | return esc_html__( 'Template Not Yet Published.', 'essential-classy-addons-for-elementor' ); |
| 36 | } |
| 37 | |
| 38 | //Elementor Builder |
| 39 | if ( class_exists( '\Elementor\Plugin' ) && $this->ec_is_elementor_build($post_id) ) { |
| 40 | $has_css = false; |
| 41 | if (('internal' === get_option('elementor_css_print_method')) || \Elementor\Plugin::$instance->preview->is_preview_mode()) { |
| 42 | $has_css = true; |
| 43 | } |
| 44 | $content = \Elementor\Plugin::instance()->frontend->get_builder_content_for_display( $post_id, $has_css ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 45 | if(empty($content)){ |
| 46 | $content = \Elementor\Plugin::instance()->frontend->get_builder_content( $post_id ); |
| 47 | } |
| 48 | |
| 49 | return $content; |
| 50 | } |
| 51 | |
| 52 | $has_rest_support = $wp_post_types[ ECAFE_POST ]->show_in_rest; |
| 53 | |
| 54 | if ( $has_rest_support ) { |
| 55 | $output = ''; |
| 56 | $curr_post = get_post( $post_id, OBJECT ); |
| 57 | |
| 58 | if ( has_blocks( $curr_post ) ) { |
| 59 | $blocks = parse_blocks( $curr_post->post_content ); |
| 60 | foreach ( $blocks as $block ) { |
| 61 | $output .= render_block( $block ); |
| 62 | } |
| 63 | } else if(isset($curr_post->post_content) && !empty($curr_post->post_content)) { |
| 64 | $output = $curr_post->post_content; |
| 65 | } |
| 66 | |
| 67 | ob_start(); |
| 68 | echo do_shortcode( $output ); |
| 69 | return ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Check Elementor Builder |
| 75 | */ |
| 76 | public function ec_is_elementor_build( $post_id ) { |
| 77 | if(class_exists( '\Elementor\Plugin' ) ){ |
| 78 | $document = \Elementor\Plugin::$instance->documents->get( $post_id ); |
| 79 | if ( $document ) { |
| 80 | return $document->is_built_with_elementor(); |
| 81 | } else { |
| 82 | return false; |
| 83 | } |
| 84 | }else{ |
| 85 | return false; |
| 86 | } |
| 87 | } |
| 88 | } |