| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if( ! class_exists( 'MywpShortcodeAbstractModule' ) ) { |
| 8 |
return false; |
| 9 |
} |
| 10 |
|
| 11 |
if ( ! class_exists( 'MywpShortcodeModuleCommentCount' ) ) : |
| 12 |
|
| 13 |
final class MywpShortcodeModuleCommentCount extends MywpShortcodeAbstractModule { |
| 14 |
|
| 15 |
protected static $id = 'mywp_comment_count'; |
| 16 |
|
| 17 |
public static function do_shortcode( $atts = false , $content = false , $tag = false ) { |
| 18 |
|
| 19 |
$status = 'moderated'; |
| 20 |
|
| 21 |
if( ! empty( $atts['status'] ) ) { |
| 22 |
|
| 23 |
$status = strip_tags( $atts['status'] ); |
| 24 |
|
| 25 |
} |
| 26 |
|
| 27 |
$comments_count = self::get_comments_count( $status ); |
| 28 |
|
| 29 |
if( ! empty( $atts['tag'] ) ) { |
| 30 |
|
| 31 |
if( ! empty( $comments_count ) ) { |
| 32 |
|
| 33 |
$content = sprintf( |
| 34 |
'<span class="awaiting-mod count-%d"><span class="%s-count">%s</span></span>', |
| 35 |
$comments_count, |
| 36 |
$status, |
| 37 |
number_format_i18n( $comments_count ) |
| 38 |
); |
| 39 |
|
| 40 |
} |
| 41 |
|
| 42 |
} else { |
| 43 |
|
| 44 |
$content = $comments_count; |
| 45 |
|
| 46 |
} |
| 47 |
|
| 48 |
$content = apply_filters( 'mywp_shortcode_comment_count' , $content , $atts ); |
| 49 |
|
| 50 |
return $content; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
private static function get_comments_count( $status = '' ) { |
| 55 |
|
| 56 |
if( empty( $status ) ) { |
| 57 |
|
| 58 |
return false; |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
$comments_counts = wp_count_comments(); |
| 63 |
|
| 64 |
if( empty( $comments_counts->$status ) ) { |
| 65 |
|
| 66 |
return 0; |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
return (int) $comments_counts->$status; |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
MywpShortcodeModuleCommentCount::init(); |
| 77 |
|
| 78 |
endif; |
| 79 |
|