| 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(shortcode_atts(array( |
| 15 |
'id' => '' |
| 16 |
), $atts)); |
| 17 |
|
| 18 |
$id = is_numeric( $id ) ? (float) $id : false; |
| 19 |
|
| 20 |
if ($id) { |
| 21 |
$content = ''; |
| 22 |
if (!isset($GLOBALS['wp_scripts']->registered['ultp-script'])) { |
| 23 |
ultimate_post()->register_scripts_common(); |
| 24 |
} |
| 25 |
$css = ultimate_post()->set_css_style($id, true); |
| 26 |
$content_post = get_post($id); |
| 27 |
if ($content_post) { |
| 28 |
if ($content_post->post_status == 'publish' && $content_post->post_password == '') { |
| 29 |
$content = $content_post->post_content; |
| 30 |
$content = apply_filters('the_content', $content); |
| 31 |
$content = str_replace(']]>', ']]>', $content); |
| 32 |
return $css.'<div class="ultp-shortcode" data-postid="'.$id.'">' . $content . '</div>'; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
return ''; |
| 37 |
} |
| 38 |
|
| 39 |
} |