| 1 |
<?php |
| 2 |
namespace ULTP\blocks; |
| 3 |
|
| 4 |
defined('ABSPATH') || exit; |
| 5 |
|
| 6 |
class Post_Comment_Count { |
| 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 |
Post Comment Count Settings |
| 17 |
============================*/ |
| 18 |
'commentLabel'=> true, |
| 19 |
'commentIconShow'=> true, |
| 20 |
|
| 21 |
/*============================ |
| 22 |
Comment Count Label Settings |
| 23 |
============================*/ |
| 24 |
'commentLabelText'=> 'comment ', |
| 25 |
"commentLabelAlign"=> "after", |
| 26 |
|
| 27 |
/*============================ |
| 28 |
Comment Count Icon Settings |
| 29 |
============================*/ |
| 30 |
'commentIconStyle'=> 'commentCount1', |
| 31 |
|
| 32 |
/*============================ |
| 33 |
Advance Setting |
| 34 |
============================*/ |
| 35 |
|
| 36 |
//-------------------------- |
| 37 |
// Advanced Settings |
| 38 |
//-------------------------- |
| 39 |
'advanceId'=> '', |
| 40 |
'advanceZindex'=> '', |
| 41 |
'hideExtraLarge'=> false, |
| 42 |
'hideDesktop'=> false, |
| 43 |
'hideTablet'=> false, |
| 44 |
'hideMobile'=> false, |
| 45 |
'advanceCss'=> '', |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
public function register() { |
| 50 |
register_block_type( 'ultimate-post/post-comment-count', |
| 51 |
array( |
| 52 |
'editor_script' => 'ultp-blocks-editor-script', |
| 53 |
'editor_style' => 'ultp-blocks-editor-css', |
| 54 |
'render_callback'=> array($this, 'content') |
| 55 |
) |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
public function content($attr, $noAjax) { |
| 60 |
$attr = wp_parse_args($attr, $this->get_attributes()); |
| 61 |
$block_name = 'post-comment-count'; |
| 62 |
$wrapper_before = $wrapper_after = $content = ''; |
| 63 |
|
| 64 |
$attr['className'] = isset($attr['className']) && $attr['className'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['className']) : ''; |
| 65 |
$attr['align'] = isset($attr['align']) && $attr['align'] ? preg_replace('/[^A-Za-z0-9_ -]/', '', $attr['align']) : ''; |
| 66 |
$attr['advanceId'] = isset($attr['advanceId']) ? sanitize_html_class( $attr['advanceId'] ) : ''; |
| 67 |
$attr['blockId'] = isset($attr['blockId']) ? sanitize_html_class( $attr['blockId'] ) : ''; |
| 68 |
$attr['commentLabelText'] = wp_kses($attr['commentLabelText'], ultimate_post()->ultp_allowed_html_tags()); |
| 69 |
|
| 70 |
$comment_count = get_post_field('comment_count' , ''); |
| 71 |
$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"]:'' ).'">'; |
| 72 |
$wrapper_before .= '<div class="ultp-block-wrapper">'; |
| 73 |
$content .= '<span class="ultp-comment-count">'; |
| 74 |
if ($attr["commentIconShow"] && ($attr["commentIconStyle"] != '')) { |
| 75 |
$content .= ultimate_post()->svg_icon($attr["commentIconStyle"]); |
| 76 |
} |
| 77 |
$content .= '<span>'.($comment_count ? $comment_count : 0).'</span>'; |
| 78 |
if ($attr["commentLabel"]) { |
| 79 |
$content .= '<span class="ultp-comment-label">'.$attr["commentLabelText"].'</span>'; |
| 80 |
} |
| 81 |
$content .= '</span>'; |
| 82 |
$wrapper_after .= '</div>'; |
| 83 |
$wrapper_after .= '</div>'; |
| 84 |
|
| 85 |
return $wrapper_before.$content.$wrapper_after; |
| 86 |
} |
| 87 |
} |