PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / trunk
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! vtrunk
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_Content.php

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

177 lines 5.0 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\Widget_Base;
13 use Elementor\Plugin;
14
15 class Post_Content extends Widget_Base {
16 public function get_name() {
17 return 'tl-post-content';
18 }
19
20 public function get_title() {
21 return esc_html__( 'Post Content', 'templately' );
22 }
23
24 public function get_icon() {
25 return 'eicon-post-content templately-widget-icon';
26 }
27
28 public function get_categories() {
29 return [ 'templately' ];
30 }
31
32 // Hidden from the widget panel by default — surfaced per-document for the
33 // templately_library CPT via ThemeBuilder::elementor_document_config().
34 public function show_in_panel() {
35 return false;
36 }
37
38 public function get_keywords() {
39 return [ 'content', 'post content', 'page content' ];
40 }
41
42 protected function register_controls() {
43 $this->start_controls_section(
44 'section_content_style',
45 [
46 'label' => esc_html__( 'Content', 'templately' ),
47 'tab' => Controls_Manager::TAB_STYLE,
48 ]
49 );
50
51 $this->add_control(
52 'content_p_color',
53 [
54 'label' => esc_html__( 'Text Color', 'templately' ),
55 'type' => Controls_Manager::COLOR,
56 'global' => [
57 'default' => Global_Colors::COLOR_TEXT,
58 ],
59 'selectors' => [
60 '{{WRAPPER}} p' => 'color: {{VALUE}};',
61 ],
62 ]
63 );
64
65 $this->add_group_control(
66 Group_Control_Typography::get_type(),
67 [
68 'name' => 'typography',
69 'global' => [
70 'default' => Global_Typography::TYPOGRAPHY_TEXT,
71 ],
72 'selector' => '{{WRAPPER}} p',
73 ]
74 );
75
76 $this->end_controls_section();
77 }
78
79 protected function get_dynamic_post_ID() {
80 $post_type = 'post';
81 $type = get_post_meta( get_the_ID(), '_templately_template_type', true );
82 if($type == 'single') {
83 $post_type = 'post';
84 }
85 else if($type == 'page_single') {
86 $post_type = 'page';
87 }
88 else if($type == 'product_single') {
89 $post_type = 'product';
90 }
91 $latest_cpt = get_posts( "post_type=$post_type&numberposts=1" );
92
93 return Plugin::$instance->editor->is_edit_mode() || isset($_GET['templately_library'], $_GET['preview_id']) ? $latest_cpt[0]->ID : get_the_ID();
94 }
95
96 protected function render() {
97 static $did_posts = [];
98 static $level = 0;
99
100 $post = get_post();
101
102 // Avoid recursion
103 if ( isset($post, $post->ID) && isset( $did_posts[ $post->ID ] ) ) {
104 return;
105 }
106
107 $level ++;
108 $did_posts[ $post->ID ] = true;
109 // End avoid recursion
110 Plugin::$instance->init_common();
111 $is_edit_mode = Plugin::$instance->editor->is_edit_mode($post->ID);
112
113 if ( $is_edit_mode || isset( $_GET['preview_id'] ) || isset( $_GET['preview'] ) ) {
114 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- post content is markup by definition; core applies the_content filters.
115 echo get_the_content( null, null, $this->get_dynamic_post_ID() );
116
117 return false;
118 }
119
120 // Set edit mode as false, so don't render settings and etc. use the $is_edit_mode to indicate if we need the CSS inline
121 Plugin::$instance->editor->set_edit_mode( false );
122
123 // Print manually (and don't use `the_content()`) because it's within another `the_content` filter, and the Elementor filter has been removed to avoid recursion.
124 $content = Plugin::$instance->frontend->get_builder_content( $post->ID, false );
125
126 Plugin::$instance->frontend->remove_content_filter();
127
128 if ( empty( $content ) ) {
129 // Split to pages.
130 setup_postdata( $post );
131
132 /** This filter is documented in wp-includes/post-template.php */
133 // PHPCS - `get_the_content` is safe.
134 echo apply_filters( 'the_content', get_the_content() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
135
136 wp_link_pages( [
137 'before' => '<div class="page-links elementor-page-links"><span class="page-links-title elementor-page-links-title">' . esc_html__( 'Pages:', 'templately' ) . '</span>',
138 'after' => '</div>',
139 'link_before' => '<span>',
140 'link_after' => '</span>',
141 'pagelink' => '<span class="screen-reader-text">' . esc_html__( 'Page', 'templately' ) . ' </span>%',
142 'separator' => '<span class="screen-reader-text">, </span>',
143 ] );
144
145 Plugin::$instance->frontend->add_content_filter();
146
147 $level --;
148
149 // Restore edit mode state
150 Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
151
152 return;
153 } else {
154 Plugin::$instance->frontend->remove_content_filters();
155 $content = apply_filters( 'the_content', $content );
156 Plugin::$instance->frontend->restore_content_filters();
157 }
158
159 // Restore edit mode state
160 Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
161
162 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- rendered builder content; already passed through the content filters above.
163 echo $content;
164
165 $level --;
166
167 if ( 0 === $level ) {
168 $did_posts = [];
169 }
170 }
171
172 // getting infinite loop otherwise
173 public function render_plain_content() {
174
175 }
176 }
177