Making WordPress.org

Ticket #1755: 1755.patch

File 1755.patch, 4.6 KB (added by keesiemeijer, 8 years ago)

Disable voting on your own submitted notes

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

     
    131131                function wporg_developer_user_note( $comment, $args, $depth ) {
    132132                        $GLOBALS['comment'] = $comment;
    133133                        $count = (int) DevHub_User_Contributed_Notes_Voting::count_votes( $comment->comment_ID, 'difference' );
     134                        $curr_user_note = DevHub_User_Contributed_Notes_Voting::is_current_user_note( $comment->comment_ID );
    134135                        $comment_class = ( -1 > $count ) ? 'bad-note' : '';
     136                        $comment_class .= $curr_user_note ? ' user-submitted-vote' : '';
     137                        $comment_class = trim( $comment_class );
    135138                        ?>
    136139
    137140                        <li id="comment-<?php comment_ID(); ?>" <?php comment_class( $comment_class ); ?>>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-voting.php

     
    194194                // Comment, if provided, must be approved.
    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 );
    200204        }
    201205
    202206        /**
     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
     214                if ( ! $comment_id ) {
     215                        global $comment;
     216                        $comment_id = $comment->comment_ID;
     217                }
     218
     219                $note    = get_comment( $comment_id );
     220                $user_id = get_current_user_id();
     221
     222                if ( ! $note || ! $user_id ) {
     223                        return false;
     224                }
     225
     226                if ( (int) $note->user_id === $user_id ) {
     227                        return true;
     228                }
     229
     230                return false;
     231        }
     232
     233        /**
    203234         * Has user upvoted the comment?
    204235         *
    205236         * @access public
     
    263294                }
    264295
    265296                $can_vote     = self::user_can_vote( get_current_user_id(), $comment_id );
     297                $user_note    = self::is_current_user_note( $comment_id );
    266298                $logged_in    = is_user_logged_in();
    267299                $comment_link = get_comment_link( $comment_id );
    268300                $nonce        = wp_create_nonce( 'user-note-vote-' . $comment_id );
     
    270302                $log_in_str   = __( 'You must log in to vote on the helpfulness of this note', 'wporg' );
    271303                $log_in_url   = add_query_arg( 'redirect_to', urlencode( $comment_link ), 'https://login.wordpress.org' );
    272304
     305                if ( !$can_vote && $user_note ) {
     306                        $disabled_str = __( 'Voting for your own note is disabled', 'wporg' );
     307                }
     308
    273309                echo '<div class="user-note-voting" data-nonce="' . esc_attr( $nonce ) . '">';
    274310
    275311                // Up vote link
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss

     
    14781478        .user-voted.user-note-voting-down .dashicons {
    14791479                color: red;
    14801480        }
     1481        .user-submitted-vote .dashicons {
     1482                color: grey;
     1483        }
    14811484
    14821485        .syntaxhighlighter {
    14831486                /* These are !important due to use of !important in SyntaxHighlighter Evolved plugin. */
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css

     
    15681568.devhub-wrap .user-voted.user-note-voting-down .dashicons {
    15691569  color: red;
    15701570}
     1571.devhub-wrap .user-submitted-vote .dashicons {
     1572  color: grey;
     1573}
    15711574.devhub-wrap .syntaxhighlighter {
    15721575  /* These are !important due to use of !important in SyntaxHighlighter Evolved plugin. */
    15731576  max-width: 100% !important;