PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.25
Post Grid Gutenberg Blocks – PostX v5.0.25
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
ultimate-post / addons / builder / Builder.php

Builder.php in Post Grid Gutenberg Blocks – PostX 5.0.25, at addons/builder/Builder.php

456 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ULTP;
4
5 use ULTP\Includes\Durbin\Xpo;
6
7 defined( 'ABSPATH' ) || exit;
8
9 class Builder {
10 private $header_id = '';
11 private $footer_id = '';
12 private $theme_name = '';
13 private $is_block_theme = '';
14
15 public function __construct() {
16 $this->builder_post_type_callback(); // Post Type Register
17 add_action( 'wp', array( $this, 'checkfor_header_footer' ), 999 );
18 add_filter( 'template_include', array( $this, 'include_builder_files' ), 100 );
19 add_action( 'add_meta_boxes', array( $this, 'init_metabox_callback' ) );
20 add_action( 'save_post', array( $this, 'metabox_save_data' ) );
21 add_action( 'save_post', array( $this, 'metabox_save_video_data' ) );
22 add_action( 'delete_post', array( $this, 'delete_option_meta_action' ) );
23 add_action( 'load-post-new.php', array( $this, 'disable_new_post_templates' ) );
24 }
25
26 public function checkfor_header_footer() {
27 $this->theme_name = get_template();
28 $this->is_block_theme = wp_is_block_theme();
29 $header_id = ultimate_post()->builder_check_conditions( 'header' );
30 $footer_id = ultimate_post()->builder_check_conditions( 'footer' );
31 global $ULTP_HEADER_ID;
32 global $ULTP_FOOTER_ID;
33
34 if ( $header_id ) {
35 $ULTP_HEADER_ID = $header_id;
36 do_action(
37 'ultp_enqueue_postx_block_css',
38 array(
39 'post_id' => $header_id,
40 'css' => '',
41 )
42 );
43 $this->header_id = $header_id;
44 if ( $this->is_block_theme ) {
45 add_action( 'wp_head', array( $this, 'ultp_header_builder_template' ) );
46 } else {
47 switch ( $this->theme_name ) {
48 case 'astra':
49 remove_all_actions( 'astra_header' );
50 add_action( 'astra_header', array( $this, 'ultp_header_builder_template' ) );
51 break;
52 default:
53 add_action( 'get_header', array( $this, 'ultp_header_builder_template' ) );
54 }
55 }
56 }
57 if ( $footer_id ) {
58 $ULTP_FOOTER_ID = $footer_id;
59 $this->footer_id = $footer_id;
60 do_action(
61 'ultp_enqueue_postx_block_css',
62 array(
63 'post_id' => $footer_id,
64 'css' => '',
65 )
66 );
67 if ( $this->is_block_theme ) {
68 add_action( 'wp_footer', array( $this, 'ultp_footer_builder_template' ) );
69 } else {
70 switch ( $this->theme_name ) {
71 case 'astra':
72 remove_all_actions( 'astra_footer' );
73 add_action( 'astra_footer', array( $this, 'ultp_footer_builder_template' ) );
74 break;
75 case 'generatepress':
76 remove_action( 'generate_footer', 'generate_construct_footer_widgets' );
77 remove_action( 'generate_footer', 'generate_construct_footer' );
78 add_action( 'generate_footer', array( $this, 'ultp_footer_builder_template' ) );
79 break;
80 default:
81 add_action( 'get_footer', array( $this, 'ultp_footer_builder_template' ) );
82 }
83 }
84 }
85 }
86
87 public function ultp_header_builder_template() {
88 if ( $this->header_id ) {
89 if ( $this->is_block_theme ) {
90 remove_action( 'wp_head', array( $this, 'ultp_header_builder_template' ) );
91 } elseif ( $this->theme_name == 'generatepress' ) {
92 require_once ULTP_PATH . 'addons/builder/templates/header.php';
93 } else {
94 if ( $this->theme_name != 'astra' ) { // Astra theme issue
95 require_once ULTP_PATH . 'addons/builder/templates/header.php';
96 }
97 $templates = array();
98 $templates[] = 'header.php';
99 remove_all_actions( 'wp_head' );
100 if ( $this->theme_name != 'bricks' ) { // Conflict with Bricks Builder Backend
101 ob_start();
102 }
103 locate_template( $templates, true );
104 if ( $this->theme_name != 'bricks' ) { // Conflict with Bricks Builder Backend
105 ob_get_clean();
106 } else {
107 wp_enqueue_style( 'wp-block-library' ); // Gutenberg CSS issue Bricks Builder frontend
108 }
109 }
110 ?>
111 <header id="ultp-header-template" class="<?php esc_html_e( 'ultp-builderid-' . $this->header_id ); ?>">
112 <?php echo ultimate_post()->get_post_content($this->header_id); //phpcs:ignore
113 ?>
114 </header>
115 <?php
116 }
117 }
118 public function ultp_footer_builder_template() {
119 if ( $this->footer_id ) {
120
121 ?>
122 <footer id="ultp-footer-template" class="<?php esc_html_e( 'ultp-builderid-' . $this->footer_id ); ?>" role="contentinfo">
123 <?php echo ultimate_post()->get_post_content($this->footer_id) //phpcs:ignore
124 ?>
125 </footer>
126 <?php
127 if ( ! $this->is_block_theme ) {
128 if ( $this->theme_name == 'astra' || $this->theme_name == 'generatepress' ) { // Astra theme issue
129 wp_footer();
130 } else {
131 require_once ULTP_PATH . 'addons/builder/templates/footer.php';
132 }
133 $templates = array();
134 $templates[] = 'footer.php';
135 remove_all_actions( 'wp_footer' );
136 if ( $this->theme_name != 'bricks' ) { // Conflict with Bricks Builder Backend
137 ob_start();
138 }
139 locate_template( $templates, true );
140 if ( $this->theme_name != 'bricks' ) { // Conflict with Bricks Builder Backend
141 ob_get_clean();
142 }
143 }
144 }
145 }
146
147 public function disable_new_post_templates() {
148 if ( get_current_screen()->post_type == 'ultp_builder' && ( ! defined( 'ULTP_PRO_VER' ) ) ) {
149 $post_count = wp_count_posts( 'ultp_builder' );
150 $post_count = $post_count->publish + $post_count->draft;
151 if ( $post_count > 0 ) {
152 wp_die(
153 'You are not allowed to do that! Only one template can be created in the free version. Please <a target="_blank" href="' . esc_url(
154 Xpo::generate_utm_link(
155 array(
156 'utmKey' => 'post_type_page',
157 )
158 )
159 ) . '">Upgrade Pro.</a>'
160 );
161 }
162 }
163 }
164
165 public function delete_option_meta_action( $post_id ) {
166 if ( get_post_type( $post_id ) != 'ultp_builder' ) {
167 return;
168 }
169
170 $conditions = get_option( 'ultp_builder_conditions', array() );
171 if ( $conditions ) {
172 $has_change = false;
173 if ( isset( $conditions['archive'][ $post_id ] ) ) {
174 $has_change = true;
175 unset( $conditions['archive'][ $post_id ] );
176 }
177 if ( isset( $conditions['singular'][ $post_id ] ) ) {
178 $has_change = true;
179 unset( $conditions['singular'][ $post_id ] );
180 }
181 if ( $has_change ) {
182 update_option( 'ultp_builder_conditions', $conditions );
183 }
184 }
185 delete_post_meta( $post_id, '_ultp_active' );
186 }
187
188
189 public function include_builder_files( $template ) {
190 $includes = ultimate_post()->builder_check_conditions( 'return' );
191
192 global $ultp_page_builder_id;
193 if ( $includes ) {
194 $ultp_page_builder_id = $includes;
195 return ULTP_PATH . 'addons/builder/templates/page.php';
196 }
197 return $template;
198 }
199
200 function init_metabox_callback() {
201 $title = '<div class="ultp-add-media-image-head"><img src="' . ULTP_URL . 'assets/img/logo-sm.svg" /><span>PostX Settings</span></div>';
202
203 add_meta_box(
204 'postx-builder-id',
205 __( 'PostX Builder Settings', 'ultimate-post' ),
206 array( $this, 'container_width_callback' ),
207 'ultp_builder',
208 'side'
209 );
210 add_meta_box(
211 'ultp-feature-video',
212 $title,
213 array( $this, 'video_source_callback' ),
214 'post',
215 'side',
216 'high'
217 );
218 }
219
220 function video_source_callback( $post ) {
221 wp_nonce_field( 'video_meta_box', 'video_meta_box_nonce' );
222 $video = get_post_meta( $post->ID, '__builder_feature_video', true );
223 $caption = get_post_meta( $post->ID, '__builder_feature_caption', true );
224 ?>
225 <div class="ultp-meta-video">
226 <?php if ( current_user_can( 'administrator' ) ) { ?>
227 <a class="ultp-dash-builder-btn" target="_blank" href="<?php echo esc_url( admin_url( 'admin.php?page=ultp-settings#builder' ) ); ?>"><?php echo esc_html__( 'Enable PostX Single Builder', 'ultimate-post' ); ?> </a>
228 <?php } ?>
229 <label><?php echo esc_html__( 'Featured Video', 'ultimate-post' ); ?></label>
230 <div class="ultp-video-input">
231 <input id="ultp-add-input" type="text" name="feature-video" value="<?php echo esc_attr( $video ); ?>" autocomplete="off" />
232 <button class="ultp-add-media"><span class="dashicons dashicons-cloud-upload"></span></button>
233 </div>
234 <span><strong><?php echo esc_html__( 'Note: ', 'ultimate-post' ); ?></strong><?php echo esc_html__( 'Enter Youtube/ Vimeo/ Self Hosted URL', 'ultimate-post' ); ?></span>
235 <label><?php echo esc_html__( 'Featured Video Caption', 'ultimate-post' ); ?></label>
236 <input id="ultp-add-caption" type="text" name="video-caption" value="<?php echo esc_attr( $caption ); ?>" autocomplete="off" />
237 </div>
238 <?php
239 }
240
241
242 function metabox_save_video_data( $post_id ) {
243 if ( ! isset( $_POST['video_meta_box_nonce'] ) ) {
244 return;
245 }
246 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['video_meta_box_nonce'] ) ), 'video_meta_box' ) ) {
247 return;
248 }
249 if ( ! isset( $_POST['feature-video'] ) ) {
250 return;
251 }
252 update_post_meta( $post_id, '__builder_feature_video', sanitize_text_field( $_POST['feature-video'] ) );
253 if ( ! isset( $_POST['video-caption'] ) ) {
254 return;
255 }
256 update_post_meta( $post_id, '__builder_feature_caption', sanitize_text_field( $_POST['video-caption'] ) );
257 }
258
259
260 function container_width_callback( $post ) {
261 wp_nonce_field( 'container_meta_box', 'container_meta_box_nonce' );
262 $width = get_post_meta( $post->ID, '__container_width', true );
263 $sidebar = get_post_meta( $post->ID, '__builder_sidebar', true );
264 $widget = get_post_meta( $post->ID, '__builder_widget_area', true );
265 $p_type = get_post_meta( $post->ID, '__ultp_builder_type', true );
266 $p_type = $p_type ? $p_type : 'archive';
267
268 $widget_area = wp_get_sidebars_widgets();
269 if ( isset( $widget_area['wp_inactive_widgets'] ) ) {
270 unset( $widget_area['wp_inactive_widgets'] );
271 }
272 if ( isset( $widget_area['array_version'] ) ) {
273 unset( $widget_area['array_version'] );
274 }
275 ?>
276
277 <input type="hidden" name="postx-type" value="<?php echo esc_attr(isset($_GET['postx_type']) ? sanitize_text_field($_GET['postx_type']) : $p_type); // @codingStandardsIgnoreLine
278 ?>
279 " />
280 <p>
281 <label><?php echo esc_html__( 'Container Width', 'ultimate-post' ); ?></label>
282 <input type="number" style="width:100%" name="container-width" value="<?php echo esc_attr( $width ? $width : 1140 ); ?>" />
283 </p>
284 <p class="postx-meta-sidebar-position">
285 <label><?php echo esc_html__( 'Sidebar', 'ultimate-post' ); ?></label>
286 <select name="builder-sidebar" style="width:88%">
287 <option <?php selected( $sidebar, '' ); ?> value=""><?php echo esc_html__( '- None -', 'ultimate-post' ); ?></option>
288 <option <?php selected( $sidebar, 'left' ); ?> value="left"><?php echo esc_html__( 'Left Sidebar', 'ultimate-post' ); ?></option>
289 <option <?php selected( $sidebar, 'right' ); ?> value="right"><?php echo esc_html__( 'Right Sidebar', 'ultimate-post' ); ?></option>
290 </select>
291 </p>
292 <p class="postx-meta-sidebar-widget">
293 <label><?php echo esc_html__( 'Select Sidebar(Widget Area)', 'ultimate-post' ); ?></label>
294 <select name="builder-widget-area" style="width:88%">
295 <option <?php selected( $sidebar, '' ); ?> value=""><?php echo esc_html__( '- None -', 'ultimate-post' ); ?></option>
296 <?php foreach ( $widget_area as $key => $val ) { ?>
297 <option <?php selected( $widget, $key ); ?> value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( ucwords( str_replace( '-', ' ', $key ) ) ); ?></option>
298 <?php } ?>
299 </select>
300 </p>
301 <?php
302 }
303
304 function metabox_save_data( $post_id ) {
305 // For Featured Video
306 if ( isset( $_POST['video_meta_box_nonce'] ) ) {
307 if ( wp_verify_nonce( sanitize_key( wp_unslash( $_POST['video_meta_box_nonce'] ) ), 'video_meta_box' ) ) {
308 if ( isset( $_POST['feature-video'] ) ) {
309 update_post_meta( $post_id, '__builder_feature_video', sanitize_text_field( $_POST['feature-video'] ) );
310 }
311 if ( ! isset( $_POST['video-caption'] ) ) {
312 update_post_meta( $post_id, '__builder_feature_caption', sanitize_text_field( $_POST['video-caption'] ) );
313 }
314 }
315 }
316
317 // For Container and Sidebar Information
318 if ( ! isset( $_POST['container_meta_box_nonce'] ) ) {
319 return;
320 }
321 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['container_meta_box_nonce'] ) ), 'container_meta_box' ) ) {
322 return;
323 }
324 if ( isset( $_POST['container-width'] ) ) {
325 update_post_meta( $post_id, '__container_width', sanitize_text_field( $_POST['container-width'] ) );
326 }
327 if ( isset( $_POST['builder-sidebar'] ) ) {
328 update_post_meta( $post_id, '__builder_sidebar', sanitize_text_field( $_POST['builder-sidebar'] ) );
329 }
330 if ( isset( $_POST['builder-widget-area'] ) ) {
331 update_post_meta( $post_id, '__builder_widget_area', sanitize_text_field( $_POST['builder-widget-area'] ) );
332 }
333
334 // Save Conditions Data
335 if ( get_post_type( $post_id ) == 'ultp_builder' ) {
336 if ( get_post_type( $post_id ) == 'ultp_builder' ) {
337 $settings = get_option( 'ultp_builder_conditions', array() );
338 $p_type = isset( $_POST['postx-type'] ) ? sanitize_text_field( $_POST['postx-type'] ) : 'singular';
339 $up_meta = '';
340 switch ( $p_type ) {
341 case 'singular':
342 if ( isset( $settings['singular'] ) ) {
343 if ( ! isset( $settings['singular'][ $post_id ] ) ) {
344 $up_meta = 'singular';
345 $settings['singular'][ $post_id ] = array( 'include/singular/post' );
346 }
347 } else {
348 $up_meta = 'singular';
349 $settings['singular'][ $post_id ] = array( 'include/singular/post' );
350 }
351 break;
352 case 'front_page':
353 if ( isset( $settings['front_page'] ) ) {
354 if ( ! isset( $settings['front_page'][ $post_id ] ) ) {
355 $up_meta = 'front_page';
356 $settings['front_page'][ $post_id ] = array( 'include/front_page' );
357 }
358 } else {
359 $up_meta = 'front_page';
360 $settings['front_page'][ $post_id ] = array( 'include/front_page' );
361 }
362 break;
363 case 'post_tag':
364 case 'date':
365 case 'search':
366 case 'author':
367 case 'archive':
368 case 'category':
369 $extra = $p_type != 'archive' ? '/' . $p_type : '';
370 if ( isset( $settings['archive'] ) ) {
371 if ( ! isset( $settings['archive'][ $post_id ] ) ) {
372 $up_meta = 'archive';
373 $settings['archive'][ $post_id ] = array( 'include/archive' . $extra );
374 }
375 } else {
376 $up_meta = 'archive';
377 $settings['archive'][ $post_id ] = array( 'include/archive' + $extra );
378 }
379 break;
380 case 'header':
381 if ( isset( $settings['header'] ) ) {
382 if ( ! isset( $settings['header'][ $post_id ] ) ) {
383 $up_meta = 'header';
384 $settings['header'][ $post_id ] = array( 'include/header/entire_site' );
385 }
386 } else {
387 $up_meta = 'header';
388 $settings['header'][ $post_id ] = array( 'include/header/entire_site' );
389 }
390 break;
391 case 'footer':
392 if ( isset( $settings['footer'] ) ) {
393 if ( ! isset( $settings['footer'][ $post_id ] ) ) {
394 $up_meta = 'footer';
395 $settings['footer'][ $post_id ] = array( 'include/footer/entire_site' );
396 }
397 } else {
398 $up_meta = 'footer';
399 $settings['footer'][ $post_id ] = array( 'include/footer/entire_site' );
400 }
401 break;
402 case '404':
403 if ( isset( $settings['404'] ) ) {
404 if ( ! isset( $settings['404'][ $post_id ] ) ) {
405 $up_meta = '404';
406 $settings['404'][ $post_id ] = array( 'include/404' );
407 }
408 } else {
409 $up_meta = '404';
410 $settings['404'][ $post_id ] = array( 'include/404' );
411 }
412 default:
413 break;
414 }
415 if ( $up_meta ) {
416 update_post_meta( $post_id, '__ultp_builder_type', $up_meta );
417 }
418 update_option( 'ultp_builder_conditions', $settings );
419 }
420 }
421 }
422
423 // Builder Post Type Register
424 public function builder_post_type_callback() {
425 $labels = array(
426 'name' => _x( 'Builder', 'Builder', 'ultimate-post' ),
427 'singular_name' => _x( 'Builder', 'Builder', 'ultimate-post' ),
428 'menu_name' => __( 'Builder', 'ultimate-post' ),
429 'parent_item_colon' => __( 'Parent Builder', 'ultimate-post' ),
430 'all_items' => __( 'Builder', 'ultimate-post' ),
431 'view_item' => __( 'View Builder', 'ultimate-post' ),
432 'add_new_item' => __( 'Add New', 'ultimate-post' ),
433 'add_new' => __( 'Add New', 'ultimate-post' ),
434 'edit_item' => __( 'Edit Builder', 'ultimate-post' ),
435 'update_item' => __( 'Update Builder', 'ultimate-post' ),
436 'search_items' => __( 'Search Builder', 'ultimate-post' ),
437 'not_found' => __( 'No Builder Found', 'ultimate-post' ),
438 'not_found_in_trash' => __( 'Not Builder found in Trash', 'ultimate-post' ),
439 );
440 $args = array(
441 'labels' => $labels,
442 'show_in_rest' => true,
443 'supports' => array( 'title', 'editor', 'comments' ),
444 'hierarchical' => false,
445 'public' => false,
446 'rewrite' => false,
447 'show_ui' => true,
448 'show_in_menu' => false,
449 'show_in_nav_menus' => false,
450 'exclude_from_search' => true,
451 'capability_type' => 'page',
452 );
453 register_post_type( 'ultp_builder', $args );
454 }
455 }
456