Changeset 12053 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-voting.php
- Timestamp:
- 09/05/2022 08:21:02 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content-voting.php
r10937 r12053 48 48 public static function do_init() { 49 49 // Save a non-AJAX submitted vote. 50 add_action( 'template_redirect', array( __CLASS__, 'vote_submission' ) );50 add_action( 'template_redirect', array( __CLASS__, 'vote_submission' ) ); 51 51 52 52 // Save AJAX submitted vote. 53 add_action( 'wp_ajax_note_vote', array( __CLASS__, 'ajax_vote_submission' ) );53 add_action( 'wp_ajax_note_vote', array( __CLASS__, 'ajax_vote_submission' ) ); 54 54 55 55 // Enqueue scripts and styles. … … 65 65 // Only need to enqueue voting-related resources if there are comments to vote on. 66 66 if ( self::user_can_vote() && is_singular() && '0' != get_comments_number() ) { 67 wp_register_script( 'wporg-developer-user-notes-voting', get_template_directory_uri() . '/js/user-notes-voting.js', array( 'wp-a11y' ), '20210428', true ); 68 wp_localize_script( 'wporg-developer-user-notes-voting', 'wporg_note_voting', array( 69 'ajaxurl' => admin_url( 'admin-ajax.php' ), 70 ) ); 67 wp_register_script( 68 'wporg-developer-user-notes-voting', 69 get_template_directory_uri() . '/js/user-notes-voting.js', 70 array( 'wp-a11y' ), 71 filemtime( dirname( __DIR__ ) . '/js/user-notes-voting.js' ), 72 true 73 ); 74 75 wp_localize_script( 76 'wporg-developer-user-notes-voting', 77 'wporg_note_voting', 78 array( 79 'ajaxurl' => admin_url( 'admin-ajax.php' ), 80 ) 81 ); 71 82 wp_enqueue_script( 'wporg-developer-user-notes-voting' ); 72 83 } … … 97 108 exit(); 98 109 } 99 100 110 } 101 111 … … 177 187 * @access public 178 188 * 179 * @param int $user_id Optional. The user ID. If not defined, assumes current user.180 * @param int $comment_id Optional. The comment ID. If not defined, assumes being able to comment generally.189 * @param int $user_id Optional. The user ID. If not defined, assumes current user. 190 * @param int $comment_id Optional. The comment ID. If not defined, assumes being able to comment generally. 181 191 * @return bool True if the user can vote. 182 192 */ … … 209 219 * Determines if a note was submitted by the current user. 210 220 * 211 * @param int $comment_id The comment ID, or empty to use current comment.221 * @param int $comment_id The comment ID, or empty to use current comment. 212 222 * @return bool True if the note was submitted by the current user. 213 223 */ … … 237 247 * @access public 238 248 * 239 * @param int $comment_id The comment ID240 * @param int $user_id Optional. The user ID. If not defined, assumes current user.249 * @param int $comment_id The comment ID 250 * @param int $user_id Optional. The user ID. If not defined, assumes current user. 241 251 * @return bool True if the user has upvoted the comment. 242 252 */ … … 262 272 * @access public 263 273 * 264 * @param int $comment_id The comment ID265 * @param int $user_id Optional. The user ID. If not defined, assumes current user.274 * @param int $comment_id The comment ID 275 * @param int $user_id Optional. The user ID. If not defined, assumes current user. 266 276 * @return bool True if the user has downvoted the comment. 267 277 */ … … 289 299 * @param int $comment_id The comment ID, or empty to use current comment. 290 300 */ 291 public static function show_voting( $comment_id = '' ) {301 public static function show_voting( $comment_id = '' ) { 292 302 if ( ! $comment_id ) { 293 303 global $comment; … … 330 340 if ( 'a' === $tag ) { 331 341 $up_url = $logged_in ? 332 add_query_arg( array( '_wpnonce' => $nonce , 'comment' => $comment_id, 'vote' => 'up' ), $comment_link ) : 342 add_query_arg( 343 array( 344 '_wpnonce' => $nonce, 345 'comment' => $comment_id, 346 'vote' => 'up', 347 ), 348 $comment_link 349 ) : 333 350 $log_in_url; 334 351 echo '" href="' . esc_url( $up_url ); … … 336 353 echo '">'; 337 354 echo '<span class="dashicons dashicons-arrow-up" aria-hidden="true"></span>'; 338 echo '<span class="screen-reader-text">' . $title . '</span>';355 echo '<span class="screen-reader-text">' . $title . '</span>'; 339 356 echo "</{$tag}>"; 340 357 … … 348 365 . 'class="user-note-voting-count ' . esc_attr( $class ) . '" ' 349 366 . 'title="' . esc_attr( $title ) . '">' 350 . '<span class="screen-reader-text">' . __( 'Vote results for this note: ', 'wporg' ) . '</span>'367 . '<span class="screen-reader-text">' . __( 'Vote results for this note: ', 'wporg' ) . '</span>' 351 368 . self::count_votes( $comment_id, 'difference' ) 352 369 . '</span>'; … … 371 388 if ( 'a' === $tag ) { 372 389 $down_url = $logged_in ? 373 add_query_arg( array( '_wpnonce' => $nonce , 'comment' => $comment_id, 'vote' => 'down' ), $comment_link ) : 390 add_query_arg( 391 array( 392 '_wpnonce' => $nonce, 393 'comment' => $comment_id, 394 'vote' => 'down', 395 ), 396 $comment_link 397 ) : 374 398 $log_in_url; 375 399 echo '" href="' . esc_url( $down_url ); … … 377 401 echo '">'; 378 402 echo '<span class="dashicons dashicons-arrow-down" aria-hidden="true"></span>'; 379 echo '<span class="screen-reader-text">' . $title . '</span>';403 echo '<span class="screen-reader-text">' . $title . '</span>'; 380 404 echo "</{$tag}>"; 381 405 … … 435 459 * @access public 436 460 * 437 * @param int $comment_id The comment ID438 * @param int $user_id Optional. The user ID. Default is current user.461 * @param int $comment_id The comment ID 462 * @param int $user_id Optional. The user ID. Default is current user. 439 463 * @return bool Whether the up vote succeed (a new vote or a change in vote). 440 464 */ … … 448 472 * @access public 449 473 * 450 * @param int $comment_id The comment ID451 * @param int $user_id Optional. The user ID. Default is current user.474 * @param int $comment_id The comment ID 475 * @param int $user_id Optional. The user ID. Default is current user. 452 476 * @return bool Whether the down vote succeed (a new vote or a change in vote). 453 477 */
Note: See TracChangeset
for help on using the changeset viewer.