PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.9
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.9
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / controls / templates / template-controls.php

template-controls.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.9, at inc/controls/templates/template-controls.php

167 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Controls\Templates;
4
5 use MasterAddons\Inc\Classes\Helper;
6
7 // Elementor Classes
8 use Elementor\Controls_Manager;
9
10 /**
11 * Author Name: Liton Arefin
12 * Author URL: https://jeweltheme.com
13 * Date: 1/6/20
14 */
15
16 if (!defined('ABSPATH')) exit; // Exit if accessed directly
17
18 class JLTMA_Template_Controls
19 {
20
21 protected static function get_templates($args = [])
22 {
23
24 if (
25 !method_exists('\Elementor\TemplateLibrary\Manager', 'get_source') ||
26 !method_exists('\Elementor\TemplateLibrary\Source_Local', 'get_items')
27 )
28 return;
29
30 return Helper::jltma_elementor()->templates_manager->get_source('local')->get_items($args);
31 }
32
33
34 protected static function empty_templates_message($template_type = '')
35 {
36 return '<div id="elementor-widget-template-empty-templates">
37 <div class="elementor-widget-template-empty-templates-icon"><i class="eicon-nerd"></i></div>
38 <div class="elementor-widget-template-empty-templates-title">' . /* translators: %s: Template Type */ sprintf(esc_html__('You Haven\'t Saved %sTemplates Yet.', 'master-addons' ), ucfirst($template_type) . ' ') . '</div>
39 <div class="elementor-widget-template-empty-templates-footer">' . esc_html__('Want to learn more about Elementor library?', 'master-addons' ) . ' <a class="elementor-widget-template-empty-templates-footer-url" href="https://go.elementor.com/docs-library/" target="_blank">' . esc_html__('Click Here', 'master-addons' ) . '</a>
40 </div>
41 </div>';
42 }
43
44
45 public static function add_controls($object, $args = [])
46 {
47
48 $defaults = [
49 'type' => ['section', 'page', 'widget', 'master_template'],
50 'condition' => [],
51 'prefix' => '',
52 ];
53
54 $args = wp_parse_args($args, $defaults);
55
56 self::add_types_control($object, $args);
57
58 if (!empty($args['type'])) {
59 if (is_array($args['type'])) {
60 foreach ($args['type'] as $type) {
61 self::add_control($object, $args, $type);
62 }
63 } else {
64 self::add_control($object, $args, $args['type']);
65 }
66 }
67 }
68
69
70 protected static function add_types_control($object, $args = [])
71 {
72
73 if (!$object)
74 return;
75
76 $object->add_control(
77 $args['prefix'] . 'template_type',
78 [
79 'label' => esc_html__('Template Type', 'master-addons' ),
80 'type' => Controls_Manager::SELECT,
81 'default' => 'section',
82 'options' => [
83 'section' => esc_html__('Section', 'master-addons' ),
84 'page' => esc_html__('Page', 'master-addons' ),
85 'widget' => esc_html__('Widget', 'master-addons' ),
86 ],
87 'condition' => $args['condition'],
88 ]
89 );
90 }
91
92 protected static function add_control($object, $args = [], $type = 'section')
93 {
94 $defaults = [];
95
96 $args = wp_parse_args($args, $defaults);
97
98 $templates = self::get_templates(['type' => $type]);
99 $options = [];
100 $types = [];
101
102 $prefix = $args['prefix'];
103 $no_templates_key = $prefix . 'no_' . $type . '_templates';
104 $templates_key = $prefix . $type . '_template_id';
105
106 if (empty($templates)) {
107
108 $object->add_control(
109 $no_templates_key,
110 [
111 'label' => false,
112 'type' => Controls_Manager::RAW_HTML,
113 'raw' => self::empty_templates_message($type),
114 'condition' => array_merge($args['condition'], [
115 $args['prefix'] . 'template_type' => $type
116 ]),
117 ]
118 );
119
120 return;
121 }
122
123 $options['0'] = '— ' . /* translators: %s: Select Type */ sprintf(__('Select %s', 'master-addons' ), $type) . ' —';
124
125 foreach ($templates as $template) {
126 $options[$template['template_id']] = $template['title'] . ' (' . $template['type'] . ')';
127 }
128
129 $object->add_control(
130 $templates_key,
131 [
132 'label' => /* translators: %s: Choose Type */ sprintf(__('Choose %s', 'master-addons' ), $type),
133 'type' => Controls_Manager::SELECT,
134 'default' => '0',
135 'options' => $options,
136 'condition' => array_merge($args['condition'], [
137 $prefix . 'template_type' => $type,
138 ]),
139 ]
140 );
141 }
142
143
144 public static function render_template_content($id)
145 {
146
147 // Double check required method and template_id
148 if (!$id || !method_exists('\Elementor\Frontend', 'get_builder_content_for_display'))
149 return;
150
151 if ('publish' !== get_post_status($id))
152 return;
153
154 $template = Helper::jltma_elementor()->frontend->get_builder_content_for_display($id);
155
156 if ($template) {
157 ?>
158 <div class="elementor-template jltma-template">
159 <?php echo $template; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output of Elementor get_builder_content_for_display(), already sanitized HTML ?>
160 </div>
161 <?php
162 } else {
163 esc_html_e('No template selected.', 'master-addons' );
164 }
165 }
166 }
167