]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/comment-template.php
WordPress 4.2
[autoinstalls/wordpress.git] / wp-includes / comment-template.php
index 4e75e7bca8e5fa2d859be977ddf338d23e1563bd..7af2f3b1b1a1b90d333d32844d40bf3b29177421 100644 (file)
@@ -420,15 +420,15 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
        // Get the comment type (comment, trackback),
        $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
 
-       // If the comment author has an id (registered), then print the log in name
-       if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
-               // For all registered users, 'byuser'
+       // Add classes for comment authors that are registered users.
+       if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
                $classes[] = 'byuser';
-               $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
+               $classes[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
                // For comment authors who are the author of the post
                if ( $post = get_post($post_id) ) {
-                       if ( $comment->user_id === $post->post_author )
+                       if ( $comment->user_id === $post->post_author ) {
                                $classes[] = 'bypostauthor';
+                       }
                }
        }
 
@@ -658,7 +658,7 @@ function get_comment_link( $comment = null, $args = array() ) {
                        $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
 
                if ( $wp_rewrite->using_permalinks() )
-                       $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
+                       $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' );
                else
                        $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
        } else {
@@ -1138,7 +1138,6 @@ function comments_template( $file = '/comments.php', $separate_comments = false
 
        /*
         * Comment author information fetched from the comment cookies.
-        * Uuses wp_get_current_commenter().
         */
        $commenter = wp_get_current_commenter();
 
@@ -1168,7 +1167,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false
 
        if ( $user_ID ) {
                $comment_args['include_unapproved'] = array( $user_ID );
-       } else if ( ! empty( $comment_author_email ) ) {
+       } elseif ( ! empty( $comment_author_email ) ) {
                $comment_args['include_unapproved'] = array( $comment_author_email );
        }
 
@@ -1275,13 +1274,29 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
        global $wpcommentspopupfile, $wpcommentsjavascript;
 
        $id = get_the_ID();
+       $title = get_the_title();
+       $number = get_comments_number( $id );
 
-       if ( false === $zero ) $zero = __( 'No Comments' );
-       if ( false === $one ) $one = __( '1 Comment' );
-       if ( false === $more ) $more = __( '% Comments' );
-       if ( false === $none ) $none = __( 'Comments Off' );
+       if ( false === $zero ) {
+               /* translators: %s: post title */
+               $zero = sprintf( __( 'No Comments<span class="screen-reader-text"> on %s</span>' ), $title );
+       }
 
-       $number = get_comments_number( $id );
+       if ( false === $one ) {
+               /* translators: %s: post title */
+               $one = sprintf( __( '1 Comment<span class="screen-reader-text"> on %s</span>' ), $title );
+       }
+
+       if ( false === $more ) {
+               /* translators: 1: Number of comments 2: post title */
+               $more = _n( '%1$s Comment<span class="screen-reader-text"> on %2$s</span>', '%1$s Comments<span class="screen-reader-text"> on %2$s</span>', $number );
+               $more = sprintf( $more, number_format_i18n( $number ), $title );
+       }
+
+       if ( false === $none ) {
+               /* translators: %s: post title */
+               $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title );
+       }
 
        if ( 0 == $number && !comments_open() && !pings_open() ) {
                echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
@@ -1312,7 +1327,6 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
        if ( !empty( $css_class ) ) {
                echo ' class="'.$css_class.'" ';
        }
-       $title = the_title_attribute( array('echo' => 0 ) );
 
        $attributes = '';
        /**
@@ -1324,7 +1338,7 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
         */
        echo apply_filters( 'comments_popup_link_attributes', $attributes );
 
-       echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
+       echo '>';
        comments_number( $zero, $one, $more );
        echo '</a>';
 }
@@ -1487,7 +1501,7 @@ function get_post_reply_link($args = array(), $post = null) {
        }
 
        if ( get_option('comment_registration') && ! is_user_logged_in() ) {
-               $link = sprintf( '<a rel="nofollow" href="%s">%s</a>',
+               $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
                        wp_login_url( get_permalink() ),
                        $args['login_text']
                );
@@ -2132,6 +2146,8 @@ function wp_list_comments( $args = array(), $comments = null ) {
  * in the array of fields.
  *
  * @since 3.0.0
+ * @since 4.1.0 Introduced the 'class_submit' argument.
+ * @since 4.2.0 Introduced 'submit_button' and 'submit_fields' arguments.
  *
  * @param array       $args {
  *     Optional. Default arguments and form fields to override.
@@ -2159,6 +2175,11 @@ function wp_list_comments( $args = array(), $comments = null ) {
  *                                        where %s is the author of the comment being replied to.
  *     @type string $cancel_reply_link    The translatable 'cancel reply' button label. Default 'Cancel reply'.
  *     @type string $label_submit         The translatable 'submit' button label. Default 'Post a comment'.
+ *     @type string $submit_button        HTML format for the Submit button.
+ *                                        Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'.
+ *     @type string $submit_field         HTML format for the markup surrounding the Submit button and comment hidden
+ *                                        fields. Default: '<p class="form-submit">%1$s %2$s</a>', where %1$s is the
+ *                                        submit button markup and %2$s is the comment hidden fields.
  *     @type string $format               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
  * }
  * @param int|WP_Post $post_id Post ID or WP_Post object to generate the form for. Default current post.
@@ -2177,12 +2198,13 @@ function comment_form( $args = array(), $post_id = null ) {
 
        $req      = get_option( 'require_name_email' );
        $aria_req = ( $req ? " aria-required='true'" : '' );
+       $html_req = ( $req ? " required='required'" : '' );
        $html5    = 'html5' === $args['format'];
        $fields   =  array(
                'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
-                           '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
+                           '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>',
                'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
-                           '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . ' /></p>',
+                           '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req  . ' /></p>',
                'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
                            '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
        );
@@ -2199,7 +2221,7 @@ function comment_form( $args = array(), $post_id = null ) {
        $fields = apply_filters( 'comment_form_default_fields', $fields );
        $defaults = array(
                'fields'               => $fields,
-               'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true"></textarea></p>',
+               'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-describedby="form-allowed-tags" aria-required="true" required="required"></textarea></p>',
                /** This filter is documented in wp-includes/link-template.php */
                'must_log_in'          => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
                /** This filter is documented in wp-includes/link-template.php */
@@ -2214,6 +2236,8 @@ function comment_form( $args = array(), $post_id = null ) {
                'title_reply_to'       => __( 'Leave a Reply to %s' ),
                'cancel_reply_link'    => __( 'Cancel reply' ),
                'label_submit'         => __( 'Post Comment' ),
+               'submit_button'        => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
+               'submit_field'         => '<p class="form-submit">%1$s %2$s</p>',
                'format'               => 'xhtml',
        );
 
@@ -2228,8 +2252,7 @@ function comment_form( $args = array(), $post_id = null ) {
         */
        $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
 
-       ?>
-               <?php if ( comments_open( $post_id ) ) : ?>
+               if ( comments_open( $post_id ) ) : ?>
                        <?php
                        /**
                         * Fires before the comment form.
@@ -2329,11 +2352,45 @@ function comment_form( $args = array(), $post_id = null ) {
                                                echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
                                                ?>
                                                <?php echo $args['comment_notes_after']; ?>
-                                               <p class="form-submit">
-                                                       <input name="<?php echo esc_attr( $args['name_submit'] ); ?>" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" class="<?php echo esc_attr( $args['class_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
-                                                       <?php comment_id_fields( $post_id ); ?>
-                                               </p>
+
                                                <?php
+                                               $submit_button = sprintf(
+                                                       $args['submit_button'],
+                                                       esc_attr( $args['name_submit'] ),
+                                                       esc_attr( $args['id_submit'] ),
+                                                       esc_attr( $args['class_submit'] ),
+                                                       esc_attr( $args['label_submit'] )
+                                               );
+
+                                               /**
+                                                * Filter the submit button for the comment form to display.
+                                                *
+                                                * @since 4.2.0
+                                                *
+                                                * @param string $submit_button HTML markup for the submit button.
+                                                * @param array  $args          Arguments passed to `comment_form()`.
+                                                */
+                                               $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
+
+                                               $submit_field = sprintf(
+                                                       $args['submit_field'],
+                                                       $submit_button,
+                                                       get_comment_id_fields( $post_id )
+                                               );
+
+                                               /**
+                                                * Filter the submit field for the comment form to display.
+                                                *
+                                                * The submit field includes the submit button, hidden fields for the
+                                                * comment form, and any wrapper markup.
+                                                *
+                                                * @since 4.2.0
+                                                *
+                                                * @param string $submit_field HTML markup for the submit field.
+                                                * @param array  $args         Arguments passed to comment_form().
+                                                */
+                                               echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
+
                                                /**
                                                 * Fires at the bottom of the comment form, inside the closing </form> tag.
                                                 *