PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.84
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.84
51.1.86 51.1.84 51.1.85 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 All 40 releases
king-addons / includes / widgets / TB_Post_Content / TB_Post_Content.php

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

327 lines 9.1 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 'king-addons-icon king-addons-tb-post-content';
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-theme-builder'];
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:[email protected]?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 'dynamic' => ['active' => true],
144 'placeholder' => esc_html__('example-anchor', 'king-addons'),
145 'description' => esc_html__('Adds an id attribute to scroll to this widget.', 'king-addons'),
146 ]
147 );
148
149 $this->add_control(
150 'kng_exclude_blocks',
151 [
152 'label' => $is_pro ?
153 esc_html__('Exclude First N Blocks', 'king-addons') :
154 sprintf(__('Exclude First N Blocks %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
155 'type' => Controls_Manager::NUMBER,
156 'min' => 0,
157 'default' => 0,
158 'classes' => $is_pro ? '' : 'king-addons-pro-control',
159 ]
160 );
161
162 $this->end_controls_section();
163 }
164
165 /**
166 * Style controls.
167 *
168 * @param bool $is_pro Whether pro controls are enabled.
169 *
170 * @return void
171 */
172 protected function register_style_controls(bool $is_pro): void
173 {
174 $this->start_controls_section(
175 'kng_style_section',
176 [
177 'label' => esc_html__('Style', 'king-addons'),
178 'tab' => Controls_Manager::TAB_STYLE,
179 ]
180 );
181
182 $this->add_group_control(
183 Group_Control_Typography::get_type(),
184 [
185 'name' => 'kng_typography',
186 'selector' => '{{WRAPPER}} .king-addons-tb-post-content',
187 ]
188 );
189
190 $this->add_control(
191 'kng_text_color',
192 [
193 'label' => esc_html__('Text Color', 'king-addons'),
194 'type' => Controls_Manager::COLOR,
195 'selectors' => [
196 '{{WRAPPER}} .king-addons-tb-post-content' => 'color: {{VALUE}};',
197 ],
198 ]
199 );
200
201 $this->add_control(
202 'kng_link_color',
203 [
204 'label' => esc_html__('Link Color', 'king-addons'),
205 'type' => Controls_Manager::COLOR,
206 'selectors' => [
207 '{{WRAPPER}} .king-addons-tb-post-content a' => 'color: {{VALUE}};',
208 ],
209 ]
210 );
211
212 $this->add_control(
213 'kng_link_color_hover',
214 [
215 'label' => esc_html__('Link Hover Color', 'king-addons'),
216 'type' => Controls_Manager::COLOR,
217 'selectors' => [
218 '{{WRAPPER}} .king-addons-tb-post-content a:hover' => 'color: {{VALUE}};',
219 ],
220 ]
221 );
222
223 $this->add_responsive_control(
224 'kng_margin',
225 [
226 'label' => esc_html__('Margin', 'king-addons'),
227 'type' => Controls_Manager::DIMENSIONS,
228 'size_units' => ['px', 'em', '%'],
229 'selectors' => [
230 '{{WRAPPER}} .king-addons-tb-post-content' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
231 ],
232 ]
233 );
234
235 $this->add_responsive_control(
236 'kng_padding',
237 [
238 'label' => esc_html__('Padding', 'king-addons'),
239 'type' => Controls_Manager::DIMENSIONS,
240 'size_units' => ['px', 'em', '%'],
241 'selectors' => [
242 '{{WRAPPER}} .king-addons-tb-post-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
243 ],
244 ]
245 );
246
247 if ($is_pro) {
248 $this->add_group_control(
249 Group_Control_Typography::get_type(),
250 [
251 'name' => 'kng_headings_typography',
252 'label' => esc_html__('Headings Typography', 'king-addons'),
253 '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',
254 ]
255 );
256 }
257
258 $this->end_controls_section();
259 }
260
261 /**
262 * Pro upsell section.
263 *
264 * @return void
265 */
266 protected function register_pro_notice_controls(): void
267 {
268 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
269 return;
270 }
271
272 Core::renderProFeaturesSection(
273 $this,
274 '',
275 Controls_Manager::RAW_HTML,
276 'tb-post-content',
277 [
278 'Exclude first blocks for advanced layouts',
279 'Dedicated heading and list typography',
280 'Enhanced blockquote and list styling',
281 ]
282 );
283 }
284
285 /**
286 * Render output helper.
287 *
288 * @param array<string, mixed> $settings Widget settings.
289 * @param bool $is_pro Whether Pro is enabled.
290 *
291 * @return void
292 */
293 protected function render_output(array $settings, bool $is_pro): void
294 {
295 $post = get_post();
296 if (!$post instanceof \WP_Post) {
297 return;
298 }
299
300 $anchor = sanitize_title($settings['kng_read_more_anchor'] ?? '');
301 $content = '';
302
303 if ($is_pro && !empty($settings['kng_exclude_blocks'])) {
304 $exclude = (int) $settings['kng_exclude_blocks'];
305 $blocks = parse_blocks((string) $post->post_content);
306 if (!empty($blocks)) {
307 $blocks = array_slice($blocks, $exclude);
308 foreach ($blocks as $block) {
309 $content .= render_block($block);
310 }
311 } else {
312 $content = (string) $post->post_content;
313 }
314 } else {
315 $content = get_the_content(null, false, $post);
316 }
317
318 $content = apply_filters('the_content', $content);
319
320 printf(
321 '<div class="king-addons-tb-post-content"%s>%s</div>',
322 $anchor ? ' id="' . esc_attr($anchor) . '"' : '',
323 $content // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
324 );
325 }
326 }
327