| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Post_Content { |
| 7 |
public function __construct() { |
| 8 |
add_action('init', array($this, 'register')); |
| 9 |
} |
| 10 |
public function get_attributes() { |
| 11 |
|
| 12 |
return array( |
| 13 |
'blockId' => '', |
| 14 |
|
| 15 |
//-------------------------- |
| 16 |
// Advanced Settings |
| 17 |
//-------------------------- |
| 18 |
'advanceId' => '', |
| 19 |
'advanceZindex' => '', |
| 20 |
'hideExtraLarge' => false, |
| 21 |
'hideDesktop' => false, |
| 22 |
'hideTablet' => false, |
| 23 |
'hideMobile' => false, |
| 24 |
'advanceCss' => '', |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
public function register() { |
| 29 |
register_block_type( 'ultimate-post/post-content', |
| 30 |
array( |
| 31 |
'editor_script' => 'ultp-blocks-editor-script', |
| 32 |
'editor_style' => 'ultp-blocks-editor-css', |
| 33 |
'render_callback' => array($this, 'content') |
| 34 |
) |
| 35 |
); |
| 36 |
} |
| 37 |
public function content($attr, $noAjax) { |
| 38 |
$attr = wp_parse_args($attr, $this->get_attributes()); |
| 39 |
|
| 40 |
$post_id = get_the_ID(); |
| 41 |
$block_name = 'post-content'; |
| 42 |
$wrapper_before = $wrapper_after = $content = ''; |
| 43 |
$post_content = get_the_content(); |
| 44 |
$post_type = get_post_type(); |
| 45 |
if ($post_type != 'ultp_builder' && $post_type != 'revision' && $post_type != 'premade') { // premade used for ultp.wpxpo.com |
| 46 |
$post_content = apply_filters('the_content', $post_content); |
| 47 |
$post_content = str_replace(']]>', ']]>', $post_content); |
| 48 |
} |
| 49 |
if ($post_content) { |
| 50 |
|
| 51 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 52 |
$attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; |
| 53 |
$attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 54 |
$attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 55 |
|
| 56 |
// from v.2.9.7 for Loading Post Content Css |
| 57 |
ultimate_post()->set_css_style( $post_id ); |
| 58 |
|
| 59 |
$wrapper_before .= '<div '.($attr['advanceId'] ? 'id="'.$attr['advanceId'].'" ':'').' class="wp-block-ultimate-post-'.$block_name.' ultp-block-'.$attr["blockId"].( $attr["className"] ?' '.$attr["className"]:'' ).''.( $attr["align"] ? ' align' .$attr["align"]:'' ).'">'; |
| 60 |
$wrapper_before .= '<div class="ultp-block-wrapper">'; |
| 61 |
$content .= '<div class="ultp-builder-content" data-postid="'.$post_id.'">'; |
| 62 |
$content .= $post_content; |
| 63 |
$content .= '</div>'; |
| 64 |
$wrapper_after .= '</div>'; |
| 65 |
$wrapper_after .= '</div>'; |
| 66 |
} |
| 67 |
return $wrapper_before.$content.$wrapper_after; |
| 68 |
} |
| 69 |
} |