WordPress.org

Plugin Directory

Changeset 1719818


Ignore:
Timestamp:
08/26/17 14:48:19 (2 months ago)
Author:
hlashbrooke
Message:

v1.0.2 - Adding top_commment_label filter

Location:
the-final-word
Files:
8 added
2 edited

Legend:

Unmodified
Added
Removed
  • the-final-word/trunk/readme.txt

    r1718052 r1719818  
    44Requires at least: 4.7 
    55Tested up to: 4.8.1 
    6 Stable tag: 1.0.1 
     6Stable tag: 1.0.2 
    77License: GPLv2 or later 
    88 
     
    2424* Only users who are able to edit the post can select a top comment 
    2525* Includes basic styling for top comments 
     26* 'Top comment' label can be translated and/or filtered 
    2627 
    2728[Contribute on GitHub](https://github.com/hlashbrooke/The-Final-Word). 
     
    4344== Changelog == 
    4445 
     46= 1.0.2 = 
     47* 2017-08-26 
     48* Adding `top_comment_label` filter to top comment label display 
     49* Improving code styling 
     50 
    4551= 1.0.1 = 
    4652* 2017-08-23 
     
    5460== Upgrade Notice == 
    5561 
    56 = 1.0.1 = 
    57 * Adding security with nonce and permission checks 
     62= 1.0.2 = 
     63* Adding `top_comment_label` filter to top comment label display 
  • the-final-word/trunk/the-final-word.php

    r1718052 r1719818  
    22/* 
    33 * Plugin Name: The Final Word 
    4  * Version: 1.0.1 
     4 * Version: 1.0.2 
    55 * Plugin URI: https://github.com/hlashbrooke/The-Final-Word 
    66 * Description: Have the final word in a comment thread by marking a chosen comment as the 'top comment'. 
     
    7676        $top_comment = get_comment_meta( $comment->comment_ID, 'top_comment', true ); 
    7777 
     78        // Allow the top  comment label to be filtered 
     79        $top_comment_label = apply_filters( 'top_comment_label', __( 'Top comment', 'the-final-word' ) ); 
     80 
    7881        // Display top comment add/remove actions depending on context 
    7982        if ( $top_comment && 'top' == $top_comment ) { 
     
    8386 
    8487            // Add action to dropdown 
    85             $actions[] = "<a class='o2-comment-top-remove o2-actions-border-top o2-warning-hover genericon genericon-close' data-comment_id='" . esc_attr( $comment->comment_ID ) . "' data-nonce='" . esc_attr( $nonce ) . "' href='#'>" . esc_html__( 'Top comment', 'the-final-word' ) . "</a>"; 
     88            $actions[] = "<a class='o2-comment-top-remove o2-actions-border-top o2-warning-hover genericon genericon-close' data-comment_id='" . esc_attr( $comment->comment_ID ) . "' data-nonce='" . esc_attr( $nonce ) . "' href='#'>" . $top_comment_label . "</a>"; 
    8689        } else { 
    8790 
     
    9093 
    9194            // Add action to dropdown 
    92             $actions[] = "<a class='o2-comment-top o2-actions-border-top genericon genericon-checkmark' data-comment_id='" . esc_attr( $comment->comment_ID ) . "' data-nonce='" . esc_attr( $nonce ) . "' href='#'>" . esc_html__( 'Top comment', 'the-final-word' ) . "</a>"; 
     95            $actions[] = "<a class='o2-comment-top o2-actions-border-top genericon genericon-checkmark' data-comment_id='" . esc_attr( $comment->comment_ID ) . "' data-nonce='" . esc_attr( $nonce ) . "' href='#'>" . $top_comment_label . "</a>"; 
    9396        } 
    9497    } 
     
    225228 
    226229/** 
    227  * Modify the O2 post fragment 
     230 * Modify the O2 post fragment - this duplicates the 'top comment' and adds it to the top of the comment thread 
    228231 * @param  array   $fragment The fragment data for the current post 
    229232 * @param  integer $post_id  The ID of the current post 
     
    235238    $post_top_comment = intval( get_post_meta( $post_id, 'post_top_comment', true ) ); 
    236239 
    237     // If we have a valid commment ID, then continue 
     240    // If we have a valid commment ID, then continue with duplicating it to the top of the thread 
    238241    if ( $post_top_comment ) { 
    239242 
     
    241244        $top_comment = get_comment( $post_top_comment ); 
    242245 
    243         // Modify the top comment ID so that it will actually display (duplicate IDs are ignore when generating the thread) 
     246        // Modify the duplicated top comment ID so that it will actually display (duplicate IDs are ignore when generating the thread) 
    244247        $top_comment->comment_ID = 'display-top'; 
    245248 
    246         // Top comment won't display correctly for child comments, so ensuring it has no parent in this instance 
     249        // Duplicated top comment won't display correctly for child comments, so ensuring it has no parent in this instance 
    247250        $top_comment->comment_parent = 0; 
    248251 
    249         // Set the date to 1 January 1970 to ensure that top comment displays at the opt of the list 
     252        // Set the date to 1 January 1970 to ensure that the duplicated top comment displays at the top of the list 
    250253        $top_comment->comment_date = '1970-01-01 00:00:00'; 
    251254        $top_comment->comment_date_gmt = '1970-01-01 00:00:00'; 
    252255 
    253         // Get the comment fragment for the top comment using the modified data 
     256        // Get the comment fragment for the duplicated top comment using the modified data 
    254257        $comment_fragment = o2_Fragment::get_fragment( $top_comment ); 
    255258 
    256         // Add the top comment fragment to the top of the comment thread 
     259        // Add the duplicated top comment fragment to the top of the comment thread 
    257260        array_unshift( $fragment['comments'], $comment_fragment ); 
    258261    } 
    259262 
    260     // Return the post fragment 
     263    // Return the post fragment with the duplicated top comment added 
    261264    return $fragment; 
    262265} 
     
    280283        $top_comment_id = intval( get_post_meta( $fragment['postID'], 'post_top_comment', true ) ); 
    281284 
     285        // Allow the top  comment label to be filtered 
     286        $top_comment_label = apply_filters( 'top_comment_label', __( 'Top comment', 'the-final-word' ) ); 
     287 
    282288        // Add the 'Top comment' label with a 'View in context' link 
    283         $comment_label = '<p class="top-comment-label">' . __( 'Top comment', 'the-final-word' ) . '<br/><a href="#comment-' . $top_comment_id . '" data-comment_anchor="comment-' . $top_comment_id . '">' . __( 'View in context', 'the-final-word' ) . '</a></p>'; 
     289        $comment_label = '<p class="top-comment-label">' . $top_comment_label . '<br/><a href="#comment-' . $top_comment_id . '" data-comment_anchor="comment-' . $top_comment_id . '">' . __( 'View in context', 'the-final-word' ) . '</a></p>'; 
    284290 
    285291        // Update the comment content to include the label 
Note: See TracChangeset for help on using the changeset viewer.