PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.3.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.3.2
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 3.1.10 All 111 releases
templately / includes / Builder / Widgets / Post_Content.php

Post_Content.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.3.2, at includes/Builder/Widgets/Post_Content.php

169 lines 4.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\Builder\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 [ 'theme-elements-single' ];
30 }
31
32 public function get_keywords() {
33 return [ 'content', 'post content', 'page content' ];
34 }
35
36 protected function register_controls() {
37 $this->start_controls_section(
38 'section_content_style',
39 [
40 'label' => esc_html__( 'Content', 'templately' ),
41 'tab' => Controls_Manager::TAB_STYLE,
42 ]
43 );
44
45 $this->add_control(
46 'content_p_color',
47 [
48 'label' => esc_html__( 'Text Color', 'templately' ),
49 'type' => Controls_Manager::COLOR,
50 'global' => [
51 'default' => Global_Colors::COLOR_TEXT,
52 ],
53 'selectors' => [
54 '{{WRAPPER}} p' => 'color: {{VALUE}};',
55 ],
56 ]
57 );
58
59 $this->add_group_control(
60 Group_Control_Typography::get_type(),
61 [
62 'name' => 'typography',
63 'global' => [
64 'default' => Global_Typography::TYPOGRAPHY_TEXT,
65 ],
66 'selector' => '{{WRAPPER}} p',
67 ]
68 );
69
70 $this->end_controls_section();
71 }
72
73 protected function get_dynamic_post_ID() {
74 $post_type = 'post';
75 $type = get_post_meta( get_the_ID(), '_templately_template_type', true );
76 if($type == 'single') {
77 $post_type = 'post';
78 }
79 else if($type == 'page_single') {
80 $post_type = 'page';
81 }
82 else if($type == 'product_single') {
83 $post_type = 'product';
84 }
85 $latest_cpt = get_posts( "post_type=$post_type&numberposts=1" );
86
87 return Plugin::$instance->editor->is_edit_mode() || isset($_GET['templately_library'], $_GET['preview_id']) ? $latest_cpt[0]->ID : get_the_ID();
88 }
89
90 protected function render() {
91 static $did_posts = [];
92 static $level = 0;
93
94 $post = get_post();
95
96 // Avoid recursion
97 if ( isset($post, $post->ID) && isset( $did_posts[ $post->ID ] ) ) {
98 return;
99 }
100
101 $level ++;
102 $did_posts[ $post->ID ] = true;
103 // End avoid recursion
104 Plugin::$instance->init_common();
105 $is_edit_mode = Plugin::$instance->editor->is_edit_mode($post->ID);
106
107 if ( $is_edit_mode || isset( $_GET['preview_id'] ) || isset( $_GET['preview'] ) ) {
108 echo get_the_content( null, null, $this->get_dynamic_post_ID() );
109
110 return false;
111 }
112
113 // 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
114 Plugin::$instance->editor->set_edit_mode( false );
115
116 // 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.
117 $content = Plugin::$instance->frontend->get_builder_content( $post->ID, false );
118
119 Plugin::$instance->frontend->remove_content_filter();
120
121 if ( empty( $content ) ) {
122 // Split to pages.
123 setup_postdata( $post );
124
125 /** This filter is documented in wp-includes/post-template.php */
126 // PHPCS - `get_the_content` is safe.
127 echo apply_filters( 'the_content', get_the_content() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
128
129 wp_link_pages( [
130 'before' => '<div class="page-links elementor-page-links"><span class="page-links-title elementor-page-links-title">' . esc_html__( 'Pages:', 'templately' ) . '</span>',
131 'after' => '</div>',
132 'link_before' => '<span>',
133 'link_after' => '</span>',
134 'pagelink' => '<span class="screen-reader-text">' . esc_html__( 'Page', 'templately' ) . ' </span>%',
135 'separator' => '<span class="screen-reader-text">, </span>',
136 ] );
137
138 Plugin::$instance->frontend->add_content_filter();
139
140 $level --;
141
142 // Restore edit mode state
143 Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
144
145 return;
146 } else {
147 Plugin::$instance->frontend->remove_content_filters();
148 $content = apply_filters( 'the_content', $content );
149 Plugin::$instance->frontend->restore_content_filters();
150 }
151
152 // Restore edit mode state
153 Plugin::$instance->editor->set_edit_mode( $is_edit_mode );
154
155 echo $content; // XSS ok.
156
157 $level --;
158
159 if ( 0 === $level ) {
160 $did_posts = [];
161 }
162 }
163
164 // getting infinite loop otherwise
165 public function render_plain_content() {
166
167 }
168 }
169