Making WordPress.org


Ignore:
Timestamp:
08/09/2016 03:44:26 PM (8 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Implement Reddit-style voting changes to user contributed notes.

Permits user to un-cast their vote by clicking their vote arrow a second time. Previously a vote could only be changed but not unset.

Props keesiemeijer.
Fixes #1755.

File:
1 edited

Legend:

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

    r3753 r3786  
    299299        $nonce        = wp_create_nonce( 'user-note-vote-' . $comment_id );
    300300        $disabled_str = __( 'Voting for this note is disabled', 'wporg' );
     301        $cancel_str   = __( 'Click to cancel your vote', 'wporg' );
    301302        $log_in_str   = __( 'You must log in to vote on the helpfulness of this note', 'wporg' );
    302303        $log_in_url   = add_query_arg( 'redirect_to', urlencode( $comment_link ), 'https://login.wordpress.org' );
     
    311312        $user_upvoted = self::has_user_upvoted_comment( $comment_id );
    312313        if ( $can_vote ) {
     314            $cancel = $user_upvoted ? '. ' . $cancel_str . '.' : '';
    313315            $title = $user_upvoted ?
    314                 __( 'You have voted to indicate this note was helpful', 'wporg' ) :
     316                __( 'You have voted to indicate this note was helpful', 'wporg' ) . $cancel :
    315317                __( 'Vote up if this note was helpful', 'wporg' );
    316             $tag = $user_upvoted ? 'span' : 'a';
     318            $tag = 'a';
    317319        } else {
    318320            $title = ! $logged_in ? $log_in_str : $disabled_str;
     
    351353        $user_downvoted = ( $user_upvoted ? false : self::has_user_downvoted_comment( $comment_id ) );
    352354        if ( $can_vote ) {
     355            $cancel = $user_downvoted ? '. ' . $cancel_str . '.' : '';
    353356            $title = $user_downvoted ?
    354                 __( 'You have voted to indicate this note was not helpful', 'wporg' ) :
     357                __( 'You have voted to indicate this note was not helpful', 'wporg' ) . $cancel :
    355358                __( 'Vote down if this note was not helpful', 'wporg' );
    356             $tag = $user_downvoted ? 'span' : 'a';
     359            $tag = 'a';
    357360        } else {
    358361            $title = ! $logged_in ? $log_in_str : $disabled_str;
     
    486489        $add_to_list = get_comment_meta( $comment_id, $add_to, true );
    487490
    488         // Don't do anything if user is recasting the same vote as before.
     491        // Remove user from list if recasting the same vote as before.
    489492        if ( in_array( $user_id, (array) $add_to_list ) ) {
    490             return false;
     493            unset( $add_to_list[ array_search( $user_id, $add_to_list ) ] );
     494            update_comment_meta( $comment_id, $add_to, $add_to_list );
     495            return true;
    491496        }
    492497
Note: See TracChangeset for help on using the changeset viewer.