PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.4.3
Kubio AI Page Builder v2.4.3
2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Core / Blocks / TemplatePartBlockBase.php
kubio / lib / src / Core / Blocks Last commit date
Query 1 year ago BlockBase.php 1 year ago BlockContainerBase.php 4 years ago BlockElement.php 3 years ago BlockStyle.php 4 years ago DataHelper.php 4 years ago TemplatePartBlockBase.php 1 year ago
TemplatePartBlockBase.php
148 lines
1 <?php
2
3
4 namespace Kubio\Core\Blocks;
5
6
7 use Kubio\Flags;
8
9 class TemplatePartBlockBase extends BlockBase {
10 const CONTAINER = 'container';
11
12 public function mapPropsToElements() {
13 $html_tag = esc_attr( $this->getAttribute( 'tagName', 'div' ) );
14
15 return array(
16 self::CONTAINER => array(
17 'tag' => $html_tag,
18 'innerHTML' => $this->getContent(),
19 ),
20 );
21 }
22
23 public function getContent() {
24 $content = $this->getTemplateContent();
25
26 if ( is_null( $content ) ) {
27 return __( 'Template Part Not Found', 'kubio' );
28 }
29
30 // Run through the actions that are typically taken on the_content.
31 $content = do_blocks( $content );
32 $content = wptexturize( $content );
33 $content = convert_smilies( $content );
34
35 //corrupts the html for link wrappers. It adds extra paragraphs and the html tag structure get
36 //$content = wpautop( $content );
37
38 $content = shortcode_unautop( $content );
39 if ( function_exists( 'wp_filter_content_tags' ) ) {
40 $content = wp_filter_content_tags( $content );
41 } else {
42 $content = wp_make_content_images_responsive( $content );
43 }
44 $content = do_shortcode( $content );
45
46 return str_replace( ']]>', ']]&gt;', $content );
47 }
48
49
50 private function getTemplateContent() {
51 $content = null;
52 $post_id = $this->getAttribute( 'postId' );
53 $theme = $this->getAttribute( 'theme' );
54 $slug = $this->getAttribute( 'slug' );
55
56
57 $post = null;
58 if ( ! empty( $post_id ) && get_post_status( $post_id ) && ( $post = get_post( $post_id ) ) ) {
59 $content = $post->post_content;
60 } else {
61 if ( basename( wp_get_theme()->get_stylesheet() ) === $theme ) {
62
63 $query_args = array(
64 'post_type' => 'wp_template_part',
65 'post_status' => 'publish',
66 'post_name__in' => array( $slug ),
67 'tax_query' => array(
68 array(
69 'taxonomy' => 'wp_theme',
70 'field' => 'slug',
71 'terms' => $theme,
72 ),
73 ),
74 'posts_per_page' => 1,
75 'no_found_rows' => true,
76 );
77 $template_part_query = new \WP_Query(
78 $query_args
79 );
80
81 $template_part_post = $template_part_query->have_posts() ? $template_part_query->next_post() : null;
82
83
84 if ( $template_part_post ) {
85
86
87 // A published post might already exist if this template part was customized elsewhere
88 // or if it's part of a customized template.
89 $content = $template_part_post->post_content;
90 } else {
91 // Else, if the template part was provided by the active theme,
92 // render the corresponding file content.
93 $template_part_file_paths = array(
94 get_stylesheet_directory() . '/full-site-editing/block-template-parts/' . $slug . '.html',
95 get_stylesheet_directory() . '/block-template-parts/' . $slug . '.html',
96 );
97
98 foreach ( $template_part_file_paths as $template_part_file_path ) {
99 if ( 0 === validate_file( $slug ) && file_exists( $template_part_file_path ) ) {
100 $content = file_get_contents( $template_part_file_path );
101 break;
102 }
103 }
104
105 if(!$content && kubio_wpml_is_active()) {
106 $content = $this->getWpmlContent($query_args);
107 }
108 }
109 }
110 }
111
112 return $content;
113 }
114
115 public function getWpmlContent($query_args) {
116 global $wpml_query_filter;
117 $had_filter = false;
118 if(has_filter( 'posts_join', array( $wpml_query_filter, 'posts_join_filter' ))){
119 $had_filter = true;
120 remove_filter('posts_join', array($wpml_query_filter, 'posts_join_filter'), 10);
121 remove_filter('posts_where', array($wpml_query_filter, 'posts_where_filter'), 10);
122 }
123
124
125 $slug = $this->getAttribute( 'slug' );
126 $template_part_query = new \WP_Query(array_merge(
127 $query_args, array(
128 'post_name__in' => array( $slug ),
129 ))
130 );
131
132 $content = null;
133 $template_part_post = $template_part_query->have_posts() ? $template_part_query->next_post() : null;
134 if ( $template_part_post ) {
135
136
137 // A published post might already exist if this template part was customized elsewhere
138 // or if it's part of a customized template.
139 $content = $template_part_post->post_content;
140 }
141 if($had_filter) {
142 add_filter('posts_join', array($wpml_query_filter, 'posts_join_filter'), 10, 2);
143 add_filter('posts_where', array($wpml_query_filter, 'posts_where_filter'), 10, 2);
144 }
145 return $content;
146 }
147 }
148