WordPress.org

Plugin Directory

Changeset 1704503


Ignore:
Timestamp:
07/28/17 13:50:27 (4 months ago)
Author:
boonebgorges
Message:

File upload for 1.2.x.

Location:
wp-grade-comments/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-grade-comments/trunk/assets/css/wp-grade-comments.css

    r1352763 r1704503  
    99#respond .olgc-checkboxes input[type="checkbox"] { 
    1010    width: auto; 
     11} 
     12 
     13#respond .olgc-checkboxes label { 
     14    display: inline; 
    1115} 
    1216 
     
    2731} 
    2832 
     33.olgc-grade-value-script { 
     34    margin-right: 4px; 
     35} 
     36 
    2937.olgc-privacy-description { 
    3038    margin: 1em 0 0; 
     
    3442} 
    3543 
     44.olgc-grade-toggle { 
     45    font-size: .9rem; 
     46    font-weight: bold; 
     47} 
     48 
     49.olgc-grade-hidden .olgc-hide-grade, 
     50.olgc-grade-hidden .olgc-grade-value-script { 
     51    display: none; 
     52} 
     53 
     54.olgc-grade-display .olgc-show-grade { 
     55    display: none; 
     56} 
     57 
     58.olgc-grade-display.olgc-grade-hidden .olgc-show-grade { 
     59    display: inline; 
     60} 
  • wp-grade-comments/trunk/assets/js/wp-grade-comments.js

    r1352763 r1704503  
    1414        $reply_to_com.on( 'click', function() { 
    1515            set_comment_visibility( $( this ) ); 
     16        } ); 
     17 
     18        $( '.olgc-grade-toggle' ).on( 'click', function( e ) { 
     19            e.preventDefault(); 
     20            toggle_single_grade_visibility( $( this ) ); 
    1621        } ); 
    1722    } ); 
     
    3843        } 
    3944    } 
     45 
     46    /** 
     47     * Toggle grade visibility. 
     48     */ 
     49    function toggle_single_grade_visibility( $clicked ) { 
     50        $clicked.closest( '.olgc-grade-display' ).toggleClass( 'olgc-grade-hidden' ); 
     51    } 
    4052}(jQuery)) 
  • wp-grade-comments/trunk/readme.txt

    r1466317 r1704503  
    22Contributors: boonebgorges 
    33Tags: comments, grade, course, privacy 
    4 Requires at least: 4.1 
    5 Tested up to: 4.6 
    6 Stable tag: 1.1.1 
     4Requires at least: 4.4 
     5Tested up to: 4.8 
     6Stable tag: 1.2.0 
    77License: GPLv3 
    88License URI: http://www.gnu.org/licenses/gpl-3.0.html 
     
    3232== Changelog == 
    3333 
     34= 1.2.0 = 
     35* Better support for query edge cases. 
     36* Now requires WP 4.4+. 
     37* On front-end, grades are now shown via show/hide toggle. 
     38* Fix bug that caused untrashed private comments to generate BuddyPress activity items. 
     39* Fix bug that prevented grades of 0 from being saved and displayed. 
     40* Fix bug that caused labels not to display properly on some themes. 
     41* Fix PHP notice. 
     42 
    3443= 1.1.1 = 
    3544* Improve compatibility with recent versions of BuddyPress. 
  • wp-grade-comments/trunk/wp-grade-comments.php

    r1466317 r1704503  
    22/* 
    33Plugin Name: WP Grade Comments 
    4 Version: 1.1.1 
     4Version: 1.2.0 
    55Description: Grades and private comments for WordPress blog posts. Built for the City Tech OpenLab. 
    66Author: Boone Gorges 
     
    9393    } 
    9494 
     95    if ( ! isset( $_POST['_olgc_nonce'] ) ) { 
     96        return; 
     97    } 
     98 
    9599    // Grade 
    96     if ( olgc_is_instructor() && wp_verify_nonce( $_POST['_olgc_nonce'], 'olgc-grade-entry-' . $comment->comment_post_ID ) && ! empty( $_POST['olgc-add-a-grade'] ) && ! empty( $_POST['olgc-grade'] ) ) { 
     100    if ( olgc_is_instructor() && wp_verify_nonce( $_POST['_olgc_nonce'], 'olgc-grade-entry-' . $comment->comment_post_ID ) && ! empty( $_POST['olgc-add-a-grade'] ) && isset( $_POST['olgc-grade'] ) ) { 
    97101        $grade = wp_unslash( $_POST['olgc-grade'] ); 
    98102        update_comment_meta( $comment_id, 'olgc_grade', $grade ); 
     
    117121    if ( 'edit-comments.php' !== $pagenow && ( olgc_is_instructor() || olgc_is_author() ) ) { 
    118122        $grade = get_comment_meta( $comment->comment_ID, 'olgc_grade', true ); 
    119         if ( $grade ) { 
    120             $text .= '<div class="olgc-grade-display"><span class="olgc-grade-label">' . __( 'Grade (Private):', 'wp-grade-comments' ) . '</span> ' . esc_html( $grade ) . '</div>'; 
     123        if ( '' !== $grade ) { 
     124            $text .= sprintf( 
     125                '<div class="olgc-grade-display olgc-grade-hidden"><span class="olgc-grade-label">%s</span> <a href="#" class="olgc-show-grade olgc-grade-toggle">%s</a><span class="olgc-grade-value-script">%s</span><noscript><span class="olgc-grade-value-noscript">%s</span></noscript><a href="#" class="olgc-hide-grade olgc-grade-toggle">%s</a></div>', 
     126                esc_html__( 'Grade (Private):', 'wp-grade-comments' ), 
     127                esc_html__( '(show)', 'wp-grade-comments' ), 
     128                esc_html( $grade ), 
     129                esc_html( $grade ), 
     130                esc_html__( '(hide)', 'wp-grade-comments' ) 
     131            ); 
    121132        } 
    122133    } 
     
    128139 
    129140    $gloss = ''; 
    130     if ( $grade && $is_private ) { 
     141    if ( '' !== $grade && $is_private ) { 
    131142        $gloss = __( 'NOTE: Private response and grade are visible only to instructors and to the post\'s author.', 'wp-grade-comments' ); 
    132     } else if ( $is_private ) { 
     143    } elseif ( $is_private ) { 
    133144        $gloss = __( 'NOTE: Private response is visible only to instructors and to the post\'s author.', 'wp-grade-comments' ); 
    134145    } 
     
    154165    if ( $is_private ) { 
    155166        $args['reply_text']    = '(Private) ' . $args['reply_text']; 
    156         $args['reply_to_text'] =  '(Private) ' . $args['reply_to_text']; 
     167        $args['reply_to_text'] = '(Private) ' . $args['reply_to_text']; 
    157168    } 
    158169 
     
    162173 
    163174/** 
    164  * Ensure that private comments are only included for the proper users. 
    165  * 
    166  * @since 1.0.0 
    167  * 
    168  * @param array            $clauses       SQL clauses from the comment query. 
    169  * @param WP_Comment_Query $comment_query Comment query object. 
    170  * @return array 
    171  */ 
    172 function olgc_filter_private_comments( $clauses, $comment_query ) { 
     175 * Remove private comments via WP_Comment_Query query args. 
     176 * 
     177 * @since 1.2.0 
     178 */ 
     179function olgc_remove_private_comments( WP_Comment_Query $comment_query ) { 
    173180    $post_id = 0; 
    174181    if ( ! empty( $comment_query->query_vars['post_id'] ) ) { 
    175182        $post_id = $comment_query->query_vars['post_id']; 
    176     } else if ( ! empty( $comment_query->query_vars['post_ID'] ) ) { 
     183    } elseif ( ! empty( $comment_query->query_vars['post_ID'] ) ) { 
    177184        $post_id = $comment_query->query_vars['post_ID']; 
    178185    } 
     
    180187    // Unfiltered 
    181188    if ( olgc_is_instructor() || olgc_is_author( $post_id ) ) { 
    182         return $clauses; 
     189        return; 
    183190    } 
    184191 
    185192    $pc_ids = olgc_get_inaccessible_comments( get_current_user_id(), $post_id ); 
    186  
    187     // WP_Comment_Query sucks 
    188     if ( ! empty( $pc_ids ) ) { 
    189         $clauses['where'] .= ' AND comment_ID NOT IN (' . implode( ',', $pc_ids ) . ')'; 
    190     } 
    191  
    192     return $clauses; 
    193 } 
    194 add_filter( 'comments_clauses', 'olgc_filter_private_comments', 10, 2 ); 
     193    if ( ! $pc_ids ) { 
     194        return; 
     195    } 
     196 
     197    $not__in = (array) $comment_query->query_vars['comment__not_in']; 
     198    $not__in = array_merge( $not__in, $pc_ids ); 
     199    $comment_query->query_vars['comment__not_in'] = $not__in; 
     200} 
     201add_action( 'pre_get_comments', 'olgc_remove_private_comments' ); 
    195202 
    196203/** 
     
    225232function olgc_get_inaccessible_comments( $user_id, $post_id = 0 ) { 
    226233    // Get a list of private comments 
    227     remove_filter( 'comments_clauses', 'olgc_filter_private_comments', 10, 2 ); 
     234    remove_action( 'pre_get_comments', 'olgc_remove_private_comments' ); 
     235 
    228236    $comment_args = array( 
    229237        'meta_query' => array( 
     
    241249 
    242250    $private_comments = get_comments( $comment_args ); 
    243     add_filter( 'comments_clauses', 'olgc_filter_private_comments', 10, 2 ); 
     251 
     252    add_action( 'pre_get_comments', 'olgc_remove_private_comments' ); 
    244253 
    245254    // Filter out the ones that are written by the logged-in user, as well 
     
    251260        } 
    252261 
    253                 if ( $user_id ) { 
    254                         $comment_post = get_post( $private_comment->comment_post_ID ); 
    255                         if ( $user_id == $comment_post->post_author ) { 
    256                                 continue; 
    257                         } 
    258                 } 
     262        if ( $user_id ) { 
     263            $comment_post = get_post( $private_comment->comment_post_ID ); 
     264            if ( $user_id == $comment_post->post_author ) { 
     265                continue; 
     266            } 
     267        } 
    259268 
    260269        $pc_ids[] = $private_comment->comment_ID; 
    261  
    262270    } 
    263271 
     
    383391        remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 
    384392        remove_action( 'comment_post', 'bp_activity_post_type_comment', 10, 2 ); 
    385     } else if ( 'edit_comment' === current_action() ) { 
     393    } elseif ( 'edit_comment' === current_action() ) { 
    386394        remove_action( 'edit_comment', 'bp_blogs_record_comment', 10 ); 
    387395        remove_action( 'edit_comment', 'bp_activity_post_type_comment', 10 ); 
     
    390398add_action( 'comment_post', 'olgc_prevent_private_comments_from_creating_bp_activity_items', 0 ); 
    391399add_action( 'edit_comment', 'olgc_prevent_private_comments_from_creating_bp_activity_items', 0 ); 
     400 
     401/** 
     402 * Prevent private comments from appearing in BuddyPress activity streams. 
     403 * 
     404 * @since 1.2.0 
     405 * 
     406 * @param string     $new_status New comment status. 
     407 * @param string     $old_status Old comment status. 
     408 * @param WP_Comment $comment    Comment object. 
     409 */ 
     410function olgc_prevent_private_comments_from_creating_bp_activity_items_on_transition( $new_staus, $old_status, $comment ) { 
     411    $is_private = get_comment_meta( $comment->comment_ID, 'olgc_is_private', true ); 
     412 
     413    if ( ! $is_private ) { 
     414        return; 
     415    } 
     416 
     417    remove_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10 ); 
     418} 
     419add_action( 'transition_comment_status', 'olgc_prevent_private_comments_from_creating_bp_activity_items_on_transition', 0, 3 ); 
Note: See TracChangeset for help on using the changeset viewer.