| 1 |
<?php |
| 2 |
/** |
| 3 |
* Comments functions |
| 4 |
* |
| 5 |
* @package wp-stream |
| 6 |
*/ |
| 7 |
|
| 8 |
add_filter( 'comment_form_defaults', 'wpstream_theme_custom_comment_title', 20 ); |
| 9 |
|
| 10 |
if ( ! function_exists( 'wpstream_theme_custom_comment_title' ) ) { |
| 11 |
/** |
| 12 |
* Customizes the comment section title to display the total number of comments. |
| 13 |
* |
| 14 |
* This function modifies the title of the comment section to display the total number |
| 15 |
* of approved comments for the current post. |
| 16 |
* |
| 17 |
* @param array $defaults The default comment section arguments. |
| 18 |
* @return array The modified comment section arguments. |
| 19 |
*/ |
| 20 |
function wpstream_theme_custom_comment_title( $defaults ) { |
| 21 |
$post_id = get_the_ID(); |
| 22 |
$comments_count = wp_count_comments( $post_id ); |
| 23 |
$total_comments = $comments_count->approved; |
| 24 |
// translators: %d is replaced with the total number of comments. |
| 25 |
$title = sprintf( __( 'Comments (%d)', 'hello-wpstream' ), $total_comments ); |
| 26 |
|
| 27 |
$defaults['title_reply'] = $title; |
| 28 |
|
| 29 |
return $defaults; |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
add_filter( 'comment_form_defaults', 'wpstream_theme_comment_button' ); |
| 35 |
|
| 36 |
if ( ! function_exists( 'wpstream_theme_comment_button' ) ) { |
| 37 |
/** |
| 38 |
* Modify the class of the comment submit button. |
| 39 |
* |
| 40 |
* @param array $args The arguments for the comment form submit button. |
| 41 |
* @return array Modified arguments for the comment form submit button. |
| 42 |
*/ |
| 43 |
function wpstream_theme_comment_button( $args ) { |
| 44 |
$args['class_submit'] = 'btn-outline'; // since WP 4.1. |
| 45 |
return $args; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
add_filter( 'comment_text', 'wpstream_bs_comment_links_in_new_tab' ); |
| 50 |
|
| 51 |
if ( ! function_exists( 'wpstream_bs_comment_links_in_new_tab' ) ) { |
| 52 |
/** |
| 53 |
* Open comment author links in new tab. |
| 54 |
* |
| 55 |
* @param string $text The comment text. |
| 56 |
* @return string Modified comment text with links opened in new tab. |
| 57 |
*/ |
| 58 |
function wpstream_bs_comment_links_in_new_tab( $text ) { |
| 59 |
return str_replace( '<a', '<a target="_blank" rel="nofollow noopener noreferrer"', $text ); |
| 60 |
} |
| 61 |
} |
| 62 |
|