Making WordPress.org

Changeset 3753


Ignore:
Timestamp:
07/29/2016 11:29:18 PM (8 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Prevent user from voting on their own user contributed note.

Props keesiemeijer.
See #1755.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php

    r3664 r3753  
    132132            $GLOBALS['comment'] = $comment;
    133133            $count = (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' );
    134             $comment_class = ( -1 > $count ) ? 'bad-note' : '';
     134            $curr_user_note = DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID );
     135
     136            $comment_class = array();
     137            if ( -1 > $count ) {
     138                $comment_class[] = 'bad-note';
     139            }
     140            if ( $curr_user_note ) {
     141                $comment_class[] = 'user-submitted-note';
     142            }
    135143            ?>
    136144
    137             <li id="comment-<?php comment_ID(); ?>" <?php comment_class( $comment_class ); ?>>
     145            <li id="comment-<?php comment_ID(); ?>" <?php comment_class( implode( ' ', $comment_class ) ); ?>>
    138146            <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
    139147                <a href="#comment-content-<?php echo $comment->comment_ID; ?>" class="screen-reader-text"><?php _e( 'Skip to note content', 'wporg' ); ?></a>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-voting.php

    r3665 r3753  
    195195        if ( $comment_id ) {
    196196            $can = ( '1' == get_comment( $comment_id )->comment_approved );
     197            // Users can't vote on their own comments.
     198            if ( $can && self::is_current_user_note( $comment_id ) ) {
     199                $can = false;
     200            }
    197201        }
    198202
    199203        return apply_filters( 'devhub_user_can_vote', $can, $user_id, $comment_id );
     204    }
     205
     206    /**
     207     * Determines if a note was submitted by the current user.
     208     *
     209     * @param int   $comment_id The comment ID, or empty to use current comment.
     210     * @return bool True if the note was submitted by the current user.
     211     */
     212    public static function is_current_user_note( $comment_id = '' ) {
     213        if ( ! $comment_id ) {
     214            global $comment;
     215            $comment_id = $comment->comment_ID;
     216        }
     217
     218        $note    = get_comment( $comment_id );
     219        $user_id = get_current_user_id();
     220
     221        if ( ! $note || ! $user_id ) {
     222            return false;
     223        }
     224
     225        if ( (int) $note->user_id === $user_id ) {
     226            return true;
     227        }
     228
     229        return false;
    200230    }
    201231
     
    264294
    265295        $can_vote     = self::user_can_vote( get_current_user_id(), $comment_id );
     296        $user_note    = self::is_current_user_note( $comment_id );
    266297        $logged_in    = is_user_logged_in();
    267298        $comment_link = get_comment_link( $comment_id );
     
    270301        $log_in_str   = __( 'You must log in to vote on the helpfulness of this note', 'wporg' );
    271302        $log_in_url   = add_query_arg( 'redirect_to', urlencode( $comment_link ), 'https://login.wordpress.org' );
     303
     304        if ( ! $can_vote && $user_note ) {
     305            $disabled_str = __( 'Voting for your own note is disabled', 'wporg' );
     306        }
    272307
    273308        echo '<div class="user-note-voting" data-nonce="' . esc_attr( $nonce ) . '">';
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

    r3722 r3753  
    14831483        color: red;
    14841484    }
     1485    .user-submitted-note .dashicons {
     1486        color: grey;
     1487    }
    14851488
    14861489    .syntaxhighlighter {
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

    r3722 r3753  
    18181818}
    18191819
     1820.devhub-wrap .user-submitted-note .dashicons {
     1821  color: grey;
     1822}
     1823
    18201824.devhub-wrap .syntaxhighlighter {
    18211825  /* These are !important due to use of !important in SyntaxHighlighter Evolved plugin. */
Note: See TracChangeset for help on using the changeset viewer.