templates_manager->get_source('local')->get_items($args);
}
protected static function empty_templates_message($template_type = '')
{
return '
';
}
public static function add_controls($object, $args = [])
{
$defaults = [
'type' => ['section', 'page', 'widget', 'master_template'],
'condition' => [],
'prefix' => '',
];
$args = wp_parse_args($args, $defaults);
self::add_types_control($object, $args);
if (!empty($args['type'])) {
if (is_array($args['type'])) {
foreach ($args['type'] as $type) {
self::add_control($object, $args, $type);
}
} else {
self::add_control($object, $args, $args['type']);
}
}
}
protected static function add_types_control($object, $args = [])
{
if (!$object)
return;
$object->add_control(
$args['prefix'] . 'template_type',
[
'label' => esc_html__('Template Type', 'master-addons' ),
'type' => Controls_Manager::SELECT,
'default' => 'section',
'options' => [
'section' => esc_html__('Section', 'master-addons' ),
'page' => esc_html__('Page', 'master-addons' ),
'widget' => esc_html__('Widget', 'master-addons' ),
],
'condition' => $args['condition'],
]
);
}
protected static function add_control($object, $args = [], $type = 'section')
{
$defaults = [];
$args = wp_parse_args($args, $defaults);
$templates = self::get_templates(['type' => $type]);
$options = [];
$types = [];
$prefix = $args['prefix'];
$no_templates_key = $prefix . 'no_' . $type . '_templates';
$templates_key = $prefix . $type . '_template_id';
if (empty($templates)) {
$object->add_control(
$no_templates_key,
[
'label' => false,
'type' => Controls_Manager::RAW_HTML,
'raw' => self::empty_templates_message($type),
'condition' => array_merge($args['condition'], [
$args['prefix'] . 'template_type' => $type
]),
]
);
return;
}
$options['0'] = '— ' . /* translators: %s: Select Type */ sprintf(__('Select %s', 'master-addons' ), $type) . ' —';
foreach ($templates as $template) {
$options[$template['template_id']] = $template['title'] . ' (' . $template['type'] . ')';
}
$object->add_control(
$templates_key,
[
'label' => /* translators: %s: Choose Type */ sprintf(__('Choose %s', 'master-addons' ), $type),
'type' => Controls_Manager::SELECT,
'default' => '0',
'options' => $options,
'condition' => array_merge($args['condition'], [
$prefix . 'template_type' => $type,
]),
]
);
}
public static function render_template_content($id)
{
// Double check required method and template_id
if (!$id || !method_exists('\Elementor\Frontend', 'get_builder_content_for_display'))
return;
if ('publish' !== get_post_status($id))
return;
$template = Helper::jltma_elementor()->frontend->get_builder_content_for_display($id);
if ($template) {
?>