PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.1.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.1.1
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Builder / TemplateLoader.php

TemplateLoader.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.1.1, at includes/Builder/TemplateLoader.php

123 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Builder;
4
5 use Elementor\Plugin;
6 use Templately\Builder\Managers\LocationManager;
7 use Templately\Builder\Managers\ThemeCompatibility;
8 use Templately\Builder\Types\BaseTemplate;
9 use Templately\Utils\Views;
10 use ElementorPro\Modules\ThemeBuilder\Module;
11
12 class TemplateLoader {
13 /**
14 * @var Views
15 */
16 private $views;
17
18 public function __construct( $builder, $views ) {
19 $this->views = $views;
20
21 // new ThemeCompatibility();
22
23 add_action( 'get_header', [ $this, 'get_header' ], 0 );
24 add_action( 'get_footer', [ $this, 'get_footer' ], 0 );
25 add_action( 'elementor/document/wrapper_attributes', [ $this, 'wrapper_attributes' ], 10, 2 );
26
27 /**
28 * Only for Development Mode.
29 */
30 if ( defined( 'TEMPLATELY_DEV_VIEWS' ) && TEMPLATELY_DEV_VIEWS ) {
31 add_action( 'templately_builder_header_before', [ $this, 'header_helper' ], 0 );
32 add_action( 'templately_builder_footer_before', [ $this, 'footer_helper' ], 0 );
33 }
34 }
35
36 public function header_helper() {
37 echo '<small>Header</small>';
38 }
39
40 public function footer_helper() {
41 echo '<small>Footer</small>';
42 }
43
44 public function get_header() {
45 if(!$this->is_header_footer()){
46 return;
47 }
48 $this->views->get_header();
49
50 $templates = [];
51 $templates[] = 'header.php';
52
53 remove_all_actions( 'wp_head' );
54
55 ob_start();
56 locate_template( $templates, true );
57 ob_get_clean();
58 }
59
60 public function get_footer( $name ) {
61 if(!$this->is_header_footer()){
62 return;
63 }
64 $this->views->get_footer();
65
66 $templates = [];
67 $name = (string) $name;
68 if ( '' !== $name ) {
69 $templates[] = "footer-{$name}.php";
70 }
71
72 $templates[] = 'footer.php';
73
74 // remove_all_actions( 'wp_footer' );
75
76 ob_start();
77 locate_template( $templates, true );
78 ob_get_clean();
79 }
80
81 public function is_header_footer(){
82 if(class_exists( 'Elementor\Plugin' )){
83 $pid = get_the_ID();
84 $post_type = get_post_type($pid);
85 $document = Plugin::$instance->documents->get( $pid );
86
87 if(
88 $post_type === 'elementor_library' &&
89 (
90 $document->get_type() === 'header' ||
91 $document->get_type() === 'footer')
92 ){
93 return false;
94 }
95 }
96
97 $header = templately()->theme_builder::$conditions_manager->get_templates_by_location( 'header' );
98 $footer = templately()->theme_builder::$conditions_manager->get_templates_by_location( 'footer' );
99
100 if(!empty($header) || !empty($footer)){
101 return true;
102 }
103 return false;
104 }
105
106 public function wrapper_attributes( $attributes, $document ) {
107 $post_type = get_post_type($document->get_main_id());
108
109 if( $post_type === 'templately_library' ){
110 $template = templately()->theme_builder->get_template( $document->get_main_id() );
111 if($template){
112 $attributes['data-elementor-type'] = 'templately-' . $template->get_type();
113 $attributes['data-elementor-id'] = $template->get_main_id();
114 $attributes['data-elementor-post-type'] = 'templately_library';
115 $attributes['data-elementor-title'] = $template->get_title();
116 $attributes['class'] .= ' ' . implode( ' ', get_post_class() );
117 }
118 }
119
120 return $attributes;
121 }
122
123 }