Decent Comments - Random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'decent_comments_comments_output', 'random_decent_comments_comments_output', 10, 3 ); | |
function random_decent_comments_comments_output ( $output, $comments, $options ) { | |
shuffle( $comments ); | |
extract( Decent_Comments_Renderer::$defaults ); | |
// display options | |
if ( isset( $options['avatar_size'] ) ) { | |
$avatar_size = intval( $options['avatar_size'] ); | |
} | |
if ( isset( $options['excerpt'] ) ) { | |
$excerpt = ( $options['excerpt'] !== 'false' && $options['excerpt'] !== false ); | |
} | |
if ( isset( $options['max_excerpt_words'] ) ) { | |
$max_excerpt_words = intval( $options['max_excerpt_words'] ); | |
} | |
if ( isset( $options['max_excerpt_characters'] ) ) { | |
$max_excerpt_characters = intval( $options['max_excerpt_characters'] ); | |
} | |
if ( isset( $options['ellipsis'] ) ) { | |
$ellipsis = $options['ellipsis']; | |
} | |
if ( isset( $options['show_author'] ) ) { | |
$show_author = ( $options['show_author'] !== 'false' && $options['show_author'] !== false ); | |
} | |
if ( isset( $options['show_date'] ) ) { | |
$show_date = ( $options['show_date'] !== 'false' && $options['show_date'] !== false ); | |
} | |
if ( isset( $options['link_author'] ) ) { | |
$link_author = ( $options['link_author'] !== 'false' && $options['link_author'] !== false ); | |
} | |
if ( isset( $options['show_avatar'] ) ) { | |
$show_avatar = ( $options['show_avatar'] !== 'false' && $options['show_avatar'] !== false ); | |
} | |
if ( isset( $options['show_link'] ) ) { | |
$show_link = ( $options['show_link'] !== 'false' && $options['show_link'] !== false ); | |
} | |
if ( isset( $options['show_comment'] ) ) { | |
$show_comment = ( $options['show_comment'] !== 'false' && $options['show_comment'] !== false ); | |
} | |
if ( isset( $options['strip_tags'] ) ) { | |
$strip_tags = ( $options['strip_tags'] !== 'false' && $options['strip_tags'] !== false ); | |
} | |
$output = '<div class="decent-comments">'; | |
$output .= '<ul>'; | |
foreach ( $comments as $comment) { | |
$output .= '<li>'; | |
$output .= '<div class="comment">'; | |
if ( $show_avatar ) { | |
$output .= '<span class="comment-avatar">'; | |
$comment_author_url = get_comment_author_url( $comment->comment_ID ); | |
if ( !empty( $comment_author_url ) && $link_author ) { | |
$output .= '<a href="'. $comment_author_url . '" rel="external">'; | |
} | |
$output .= get_avatar( $comment->comment_author_email, $avatar_size ); | |
if ( !empty( $comment_author_url ) ) { | |
$output .= '</a>'; | |
} | |
$output .= '</span>'; // .comment-avatar | |
} | |
if ( $show_author ) { | |
$output .= '<span class="comment-author">'; | |
if ( $link_author ) { | |
$output .= get_comment_author_link( $comment->comment_ID ); | |
} else { | |
$output .= get_comment_author( $comment->comment_ID ); | |
} | |
$output .= '</span>'; // .comment-author | |
} | |
if ( $show_date ) { | |
$output .= '<span class="comment-date">'; | |
$output .= sprintf( | |
_x( ' %1$s at %2$s', 'comment-date', DC_PLUGIN_DOMAIN ), // translators : the first argument is the date of the comment, the second is the time | |
mysql2date( get_option( 'date_format' ), $comment->comment_date ), | |
mysql2date( get_option( 'time_format' ), $comment->comment_date, true ) | |
); | |
$output .= '</span>'; // .comment-date | |
} | |
if ( $show_link ) { | |
$output .= '<span class="comment-link">'; | |
$output .= sprintf( | |
_x( ' on %s', 'comment-link', DC_PLUGIN_DOMAIN ), | |
'<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>' | |
); | |
$output .= '</span>'; // .comment-link | |
} | |
if ( $show_comment ) { | |
$output .= '<span class="comment-' . ( $excerpt ? "excerpt" : "body" ) . '">'; | |
$output .= Decent_Comments_Renderer::get_comment( | |
$comment, | |
array( | |
'ellipsis' => $ellipsis, | |
'excerpt' => $excerpt, | |
'max_excerpt_words' => $max_excerpt_words, | |
'max_excerpt_characters' => $max_excerpt_characters, | |
'strip_tags' => $strip_tags | |
) | |
); | |
$output .= '</span>'; // .comment-body or .comment-excerpt | |
} | |
$output .= '</div>'; // .comment | |
$output .= '</li>'; | |
} | |
$output .= '</ul>'; | |
$output .= '</div>'; // .decent-comments | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment