PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 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 All 112 releases
templately / modules / theme-builder / Widgets / Post_Title.php

Post_Title.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/theme-builder/Widgets/Post_Title.php

143 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Modules\ThemeBuilder\Widgets;
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Controls_Manager;
9 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
10 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Plugin;
13 use Elementor\Utils;
14 use Elementor\Widget_Base;
15
16 class Post_Title extends Widget_Base {
17
18 public function get_name() {
19 return 'tl-post-title';
20 }
21
22 public function get_title() {
23 return esc_html__( 'Post Title', 'templately' );
24 }
25
26 public function get_icon() {
27 return 'eicon-t-letter templately-widget-icon';
28 }
29
30 public function get_categories() {
31 return [ 'templately' ];
32 }
33
34 // Hidden from the widget panel by default — surfaced per-document for the
35 // templately_library CPT via ThemeBuilder::elementor_document_config().
36 public function show_in_panel() {
37 return false;
38 }
39
40 public function get_keywords() {
41 return [ 'title', 'post title', 'page title', 'heading' ];
42 }
43
44 protected function register_controls() {
45 $this->start_controls_section(
46 'section_title',
47 [
48 'label' => esc_html__( 'Heading', 'templately' ),
49 ]
50 );
51
52 $this->add_control(
53 'html_tag',
54 [
55 'label' => esc_html__( 'HTML Tag', 'templately' ),
56 'type' => Controls_Manager::SELECT,
57 'options' => [
58 'h1' => 'H1',
59 'h2' => 'H2',
60 'h3' => 'H3',
61 'h4' => 'H4',
62 'h5' => 'H5',
63 'h6' => 'H6',
64 'div' => 'div',
65 'span' => 'span',
66 'p' => 'p',
67 ],
68 'default' => 'h2',
69 ]
70 );
71
72 $this->end_controls_section();
73
74 $this->start_controls_section(
75 'section_title_style',
76 [
77 'label' => esc_html__( 'Heading', 'templately' ),
78 'tab' => Controls_Manager::TAB_STYLE,
79 ]
80 );
81
82 $this->add_control(
83 'title_color',
84 [
85 'label' => esc_html__( 'Text Color', 'templately' ),
86 'type' => Controls_Manager::COLOR,
87 'global' => [
88 'default' => Global_Colors::COLOR_PRIMARY,
89 ],
90 'selectors' => [
91 '{{WRAPPER}} .templately-heading-title' => 'color: {{VALUE}};',
92 ],
93 ]
94 );
95
96 $this->add_group_control(
97 Group_Control_Typography::get_type(),
98 [
99 'name' => 'typography',
100 'global' => [
101 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
102 ],
103 'selector' => '{{WRAPPER}} .templately-heading-title',
104 ]
105 );
106
107 $this->end_controls_section();
108 }
109
110 protected function get_dynamic_post_ID() {
111 $post_type = 'post';
112 $type = get_post_meta( get_the_ID(), '_templately_template_type', true );
113 if($type == 'single') {
114 $post_type = 'post';
115 }
116 else if($type == 'page_single') {
117 $post_type = 'page';
118 }
119 else if($type == 'product_single') {
120 $post_type = 'product';
121 }
122 $latest_cpt = get_posts( "post_type=$post_type&numberposts=1" );
123
124 return Plugin::$instance->editor->is_edit_mode() || isset($_GET['templately_library'], $_GET['preview_id']) ? $latest_cpt[0]->ID : get_the_ID();
125 }
126
127 protected function render() {
128 $settings = $this->get_settings_for_display();
129 $title = get_the_title( $this->get_dynamic_post_ID() );
130
131 $this->add_render_attribute( 'title', 'class', 'templately-heading-title' );
132
133 printf(
134 '<%1$s %2$s>%3$s</%1$s>',
135 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- validate_html_tag() whitelists the tag.
136 Utils::validate_html_tag( $settings['html_tag'] ),
137 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Elementor builds and escapes this attribute string.
138 $this->get_render_attribute_string( 'title' ),
139 esc_html( $title )
140 );
141 }
142 }
143