WordPress.org

Making WordPress.org

Changeset 3560


Ignore:
Timestamp:
06/23/2016 04:19:52 PM (6 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Make vote arrows actual links for visistors who are not logged in.

Links to login.wordpress.org for login, with a redirect_to back to the code reference note they attempted to vote on.

Also adds a 'title' attribute string when voting is disabled.

Props keesiemeijer for initial patch.
Fixes #1649.

File:
1 edited

Legend:

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

    r929 r3560  
    264264
    265265        $can_vote     = self::user_can_vote( get_current_user_id(), $comment_id );
     266        $logged_in    = is_user_logged_in();
    266267        $comment_link = get_comment_link( $comment_id );
    267268        $nonce        = wp_create_nonce( 'user-note-vote-' . $comment_id );
     269        $disabled_str = __( 'Voting for this note is disabled', 'wporg' );
     270        $log_in_str   = __( 'You must log in to vote on the helpfulness of this note', 'wporg' );
     271        $log_in_url   = add_query_arg( 'redirect_to', urlencode( $comment_link ), 'https://login.wordpress.org' );
    268272
    269273        echo '<div class="user-note-voting" data-nonce="' . esc_attr( $nonce ) . '">';
     
    277281            $tag = $user_upvoted ? 'span' : 'a';
    278282        } else {
    279             $title = ! is_user_logged_in() ?
    280                 __( 'You must log in to vote on the helpfulness of this note', 'wporg' ) :
    281                 '';
    282             $tag = 'span';
     283            $title = ! $logged_in ? $log_in_str : $disabled_str;
     284            $tag = $logged_in ? 'span' : 'a';
    283285        }
    284286        echo "<{$tag} "
     
    287289            . '" data-id="' . esc_attr( $comment_id )
    288290            . '" data-vote="up';
    289         if ( ! $user_upvoted ) {
    290             echo '" href="'
    291                 . esc_url( add_query_arg( array( '_wpnonce' => $nonce , 'comment' => $comment_id, 'vote' => 'up' ), $comment_link ) );
     291        if ( 'a' === $tag ) {
     292            $up_url = $logged_in ?
     293                add_query_arg( array( '_wpnonce' => $nonce , 'comment' => $comment_id, 'vote' => 'up' ), $comment_link ) :
     294                $log_in_url;
     295            echo '" href="' . esc_url( $up_url );
    292296        }
    293297        echo '">';
     
    315319            $tag = $user_downvoted ? 'span' : 'a';
    316320        } else {
    317             $title = ! is_user_logged_in() ?
    318                 __( 'You must log in to vote on the helpfulness of this note', 'wporg' ) :
    319                 '';
    320             $tag = 'span';
     321            $title = ! $logged_in ? $log_in_str : $disabled_str;
     322            $tag = $logged_in ? 'span' : 'a';
    321323        }
    322324        echo "<{$tag} "
     
    325327            . '" data-id="' . esc_attr( $comment_id )
    326328            . '" data-vote="down';
    327         if ( ! $user_downvoted ) {
    328             echo '" href="'
    329                 . esc_url( add_query_arg( array( '_wpnonce' => $nonce , 'comment' => $comment_id, 'vote' => 'down' ), $comment_link ) );
     329        if ( 'a' === $tag ) {
     330            $down_url = $logged_in ?
     331                add_query_arg( array( '_wpnonce' => $nonce , 'comment' => $comment_id, 'vote' => 'down' ), $comment_link ) :
     332                $log_in_url;
     333            echo '" href="' . esc_url( $down_url );
    330334        }
    331335        echo '">';
Note: See TracChangeset for help on using the changeset viewer.