PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / TB_Post_Content / TB_Post_Content.php

TB_Post_Content.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.78, at includes/widgets/TB_Post_Content/TB_Post_Content.php

326 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Post Content widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Widget_Base;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Outputs the current post content inside Theme Builder templates.
20 */
21 class TB_Post_Content extends Widget_Base
22 {
23 /**
24 * Widget slug.
25 *
26 * @return string
27 */
28 public function get_name(): string
29 {
30 return 'king-addons-tb-post-content';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Post Content', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'eicon-editor-paragraph';
51 }
52
53 /**
54 * Style dependencies.
55 *
56 * @return array<int, string>
57 */
58 public function get_style_depends(): array
59 {
60 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-post-content-style'];
61 }
62
63 /**
64 * Script dependencies.
65 *
66 * @return array<int, string>
67 */
68 public function get_script_depends(): array
69 {
70 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-post-content-script'];
71 }
72
73 /**
74 * Categories.
75 *
76 * @return array<int, string>
77 */
78 public function get_categories(): array
79 {
80 return ['king-addons'];
81 }
82
83 /**
84 * Keywords.
85 *
86 * @return array<int, string>
87 */
88 public function get_keywords(): array
89 {
90 return ['content', 'post', 'body', 'theme builder', 'king-addons'];
91 }
92
93 public function get_custom_help_url()
94 {
95 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
96 }
97
98 /**
99 * Register controls.
100 *
101 * @return void
102 */
103 public function register_controls(): void
104 {
105 $this->register_content_controls(false);
106 $this->register_style_controls(false);
107 $this->register_pro_notice_controls();
108 }
109
110 /**
111 * Render widget output.
112 *
113 * @return void
114 */
115 public function render(): void
116 {
117 $settings = $this->get_settings_for_display();
118 $this->render_output($settings, false);
119 }
120
121 /**
122 * Content controls.
123 *
124 * @param bool $is_pro Whether pro controls are enabled.
125 *
126 * @return void
127 */
128 protected function register_content_controls(bool $is_pro): void
129 {
130 $this->start_controls_section(
131 'kng_content_section',
132 [
133 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
134 'tab' => Controls_Manager::TAB_CONTENT,
135 ]
136 );
137
138 $this->add_control(
139 'kng_read_more_anchor',
140 [
141 'label' => esc_html__('Read More Anchor ID', 'king-addons'),
142 'type' => Controls_Manager::TEXT,
143 'placeholder' => esc_html__('example-anchor', 'king-addons'),
144 'description' => esc_html__('Adds an id attribute to scroll to this widget.', 'king-addons'),
145 ]
146 );
147
148 $this->add_control(
149 'kng_exclude_blocks',
150 [
151 'label' => $is_pro ?
152 esc_html__('Exclude First N Blocks', 'king-addons') :
153 sprintf(__('Exclude First N Blocks %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
154 'type' => Controls_Manager::NUMBER,
155 'min' => 0,
156 'default' => 0,
157 'classes' => $is_pro ? '' : 'king-addons-pro-control',
158 ]
159 );
160
161 $this->end_controls_section();
162 }
163
164 /**
165 * Style controls.
166 *
167 * @param bool $is_pro Whether pro controls are enabled.
168 *
169 * @return void
170 */
171 protected function register_style_controls(bool $is_pro): void
172 {
173 $this->start_controls_section(
174 'kng_style_section',
175 [
176 'label' => esc_html__('Style', 'king-addons'),
177 'tab' => Controls_Manager::TAB_STYLE,
178 ]
179 );
180
181 $this->add_group_control(
182 Group_Control_Typography::get_type(),
183 [
184 'name' => 'kng_typography',
185 'selector' => '{{WRAPPER}} .king-addons-tb-post-content',
186 ]
187 );
188
189 $this->add_control(
190 'kng_text_color',
191 [
192 'label' => esc_html__('Text Color', 'king-addons'),
193 'type' => Controls_Manager::COLOR,
194 'selectors' => [
195 '{{WRAPPER}} .king-addons-tb-post-content' => 'color: {{VALUE}};',
196 ],
197 ]
198 );
199
200 $this->add_control(
201 'kng_link_color',
202 [
203 'label' => esc_html__('Link Color', 'king-addons'),
204 'type' => Controls_Manager::COLOR,
205 'selectors' => [
206 '{{WRAPPER}} .king-addons-tb-post-content a' => 'color: {{VALUE}};',
207 ],
208 ]
209 );
210
211 $this->add_control(
212 'kng_link_color_hover',
213 [
214 'label' => esc_html__('Link Hover Color', 'king-addons'),
215 'type' => Controls_Manager::COLOR,
216 'selectors' => [
217 '{{WRAPPER}} .king-addons-tb-post-content a:hover' => 'color: {{VALUE}};',
218 ],
219 ]
220 );
221
222 $this->add_responsive_control(
223 'kng_margin',
224 [
225 'label' => esc_html__('Margin', 'king-addons'),
226 'type' => Controls_Manager::DIMENSIONS,
227 'size_units' => ['px', 'em', '%'],
228 'selectors' => [
229 '{{WRAPPER}} .king-addons-tb-post-content' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
230 ],
231 ]
232 );
233
234 $this->add_responsive_control(
235 'kng_padding',
236 [
237 'label' => esc_html__('Padding', 'king-addons'),
238 'type' => Controls_Manager::DIMENSIONS,
239 'size_units' => ['px', 'em', '%'],
240 'selectors' => [
241 '{{WRAPPER}} .king-addons-tb-post-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
242 ],
243 ]
244 );
245
246 if ($is_pro) {
247 $this->add_group_control(
248 Group_Control_Typography::get_type(),
249 [
250 'name' => 'kng_headings_typography',
251 'label' => esc_html__('Headings Typography', 'king-addons'),
252 'selector' => '{{WRAPPER}} .king-addons-tb-post-content h1, {{WRAPPER}} .king-addons-tb-post-content h2, {{WRAPPER}} .king-addons-tb-post-content h3, {{WRAPPER}} .king-addons-tb-post-content h4, {{WRAPPER}} .king-addons-tb-post-content h5, {{WRAPPER}} .king-addons-tb-post-content h6',
253 ]
254 );
255 }
256
257 $this->end_controls_section();
258 }
259
260 /**
261 * Pro upsell section.
262 *
263 * @return void
264 */
265 protected function register_pro_notice_controls(): void
266 {
267 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
268 return;
269 }
270
271 Core::renderProFeaturesSection(
272 $this,
273 '',
274 Controls_Manager::RAW_HTML,
275 'tb-post-content',
276 [
277 'Exclude first blocks for advanced layouts',
278 'Dedicated heading and list typography',
279 'Enhanced blockquote and list styling',
280 ]
281 );
282 }
283
284 /**
285 * Render output helper.
286 *
287 * @param array<string, mixed> $settings Widget settings.
288 * @param bool $is_pro Whether Pro is enabled.
289 *
290 * @return void
291 */
292 protected function render_output(array $settings, bool $is_pro): void
293 {
294 $post = get_post();
295 if (!$post instanceof \WP_Post) {
296 return;
297 }
298
299 $anchor = sanitize_title($settings['kng_read_more_anchor'] ?? '');
300 $content = '';
301
302 if ($is_pro && !empty($settings['kng_exclude_blocks'])) {
303 $exclude = (int) $settings['kng_exclude_blocks'];
304 $blocks = parse_blocks((string) $post->post_content);
305 if (!empty($blocks)) {
306 $blocks = array_slice($blocks, $exclude);
307 foreach ($blocks as $block) {
308 $content .= render_block($block);
309 }
310 } else {
311 $content = (string) $post->post_content;
312 }
313 } else {
314 $content = get_the_content(null, false, $post);
315 }
316
317 $content = apply_filters('the_content', $content);
318
319 printf(
320 '<div class="king-addons-tb-post-content"%s>%s</div>',
321 $anchor ? ' id="' . esc_attr($anchor) . '"' : '',
322 $content // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
323 );
324 }
325 }
326