PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.1.0
Post Grid Gutenberg Blocks – PostX v5.1.0
5.1.1 5.1.0 5.0.41 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 All 240 releases
ultimate-post / addons / templates / Shortcode.php

Shortcode.php in Post Grid Gutenberg Blocks – PostX 5.1.0, at addons/templates/Shortcode.php

67 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Shortcode {
7 public function __construct() {
8 add_shortcode( 'gutenberg_post_blocks', array( $this, 'shortcode_callback' ) );
9 add_shortcode( 'postx_template', array( $this, 'shortcode_callback' ) );
10 }
11
12 // Shortcode Callback
13 function shortcode_callback( $atts = array(), $content = null ) {
14 extract(
15 shortcode_atts(
16 array(
17 'id' => '',
18 ),
19 $atts
20 )
21 );
22
23 $id = is_numeric( $id ) ? (float) $id : false;
24
25 if ( $id ) {
26 if ( class_exists( 'SitePress' ) ) {
27 $id = apply_filters( 'wpml_object_id', $id, 'ultp_templates', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook.
28 }
29 $content = '';
30 $pre_content = '';
31 $content_post = get_post( $id );
32 if ( $content_post ) {
33 if ( $content_post->post_status == 'publish' && $content_post->post_password == '' ) {
34 do_action(
35 'ultp_enqueue_postx_block_css',
36 array(
37 'post_id' => $id,
38 'css' => '',
39 )
40 );
41 // Breakdance builder support for its shortcode render
42 $current_url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
43 if ( ! empty( $_GET['_breakdance_doing_ajax'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only Breakdance editor detection.
44 strpos( $current_url, 'bricks/v1/render_element' ) !== false
45 ) {
46
47 if ( ! empty( $_GET['_breakdance_doing_ajax'] ) && get_template() == 'bricks' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only Breakdance editor detection.
48 get_header();
49 }
50 $pre_content .= ultimate_post()->build_css_for_inline_print( $id, true );
51 }
52
53 $content .= $content_post->post_content;
54 $content = do_blocks( $content );
55 $content = do_shortcode( $content );
56 $content = str_replace( ']]>', ']]&gt;', $content );
57 $content = preg_replace( '%<p>&nbsp;\s*</p>%', '', $content );
58 $content = preg_replace( '/^(?:<br\s*\/?>\s*)+/', '', $content );
59
60 return $pre_content . '<div class="ultp-shortcode" data-postid="' . $id . '">' . $content . '</div>';
61 }
62 }
63 }
64 return '';
65 }
66 }
67