Make WordPress Core


Ignore:
Timestamp:
09/24/2015 09:59:39 PM (11 years ago)
Author:
wonderboymusic
Message:

Comments: In comment_form(), move the comment textarea to the top for logged-out users when replying, improves keyboard/focus navigation.

Rehabilitate errant tabbing and extra unnecessary <?php ?> toggling.

Props afercia, adamsilverstein.
Fixes #29974.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r34523 r34525  
    19751975                '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>',
    19761976                /** This filter is documented in wp-includes/link-template.php */
    1977                 'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
     1977                'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( '<a href="%1$s" aria-label="Logged in as %2$s. Edit your profile.">Logged in as %2$s</a>. <a href="%3$s">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
    19781978                'comment_notes_before' => '<p class="comment-notes"><span id="email-notes">' . __( 'Your email address will not be published.' ) . '</span>'. ( $req ? $required_text : '' ) . '</p>',
    19791979                'comment_notes_after'  => '',
    … …  
    20092009        $args = array_merge( $defaults, $args );
    20102010
    2011                 if ( comments_open( $post_id ) ) : ?>
     2011        if ( comments_open( $post_id ) ) : ?>
     2012                <?php
     2013                /**
     2014                 * Fires before the comment form.
     2015                 *
     2016                 * @since 3.0.0
     2017                 */
     2018                do_action( 'comment_form_before' );
     2019                ?>
     2020                <div id="respond" class="comment-respond">
    20122021                        <?php
    2013                         /**
    2014                          * Fires before the comment form.
    2015                          *
    2016                          * @since 3.0.0
    2017                          */
    2018                         do_action( 'comment_form_before' );
    2019                         ?>
    2020                         <div id="respond" class="comment-respond">
    2021                                 <?php
    2022                                 echo $args['title_reply_before'];
    2023 
    2024                                 comment_form_title( $args['title_reply'], $args['title_reply_to'] );
    2025 
    2026                                 echo $args['cancel_reply_before'];
    2027 
    2028                                 cancel_comment_reply_link( $args['cancel_reply_link'] );
    2029 
    2030                                 echo $args['cancel_reply_after'];
    2031 
    2032                                 echo $args['title_reply_after'];
    2033                                 ?>
    2034 
    2035                                 <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
    2036                                         <?php echo $args['must_log_in']; ?>
     2022                        echo $args['title_reply_before'];
     2023
     2024                        comment_form_title( $args['title_reply'], $args['title_reply_to'] );
     2025
     2026                        echo $args['cancel_reply_before'];
     2027
     2028                        cancel_comment_reply_link( $args['cancel_reply_link'] );
     2029
     2030                        echo $args['cancel_reply_after'];
     2031
     2032                        echo $args['title_reply_after'];
     2033
     2034                        if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) :
     2035                                echo $args['must_log_in'];
     2036                                /**
     2037                                 * Fires after the HTML-formatted 'must log in after' message in the comment form.
     2038                                 *
     2039                                 * @since 3.0.0
     2040                                 */
     2041                                do_action( 'comment_form_must_log_in_after' );
     2042                        else : ?>
     2043                                <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
    20372044                                        <?php
    20382045                                        /**
    2039                                          * Fires after the HTML-formatted 'must log in after' message in the comment form.
     2046                                         * Fires at the top of the comment form, inside the form tag.
    20402047                                         *
    20412048                                         * @since 3.0.0
    20422049                                         */
    2043                                         do_action( 'comment_form_must_log_in_after' );
    2044                                         ?>
    2045                                 <?php else : ?>
    2046                                         <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
    2047                                                 <?php
     2050                                        do_action( 'comment_form_top' );
     2051
     2052                                        if ( is_user_logged_in() ) :
    20482053                                                /**
    2049                                                  * Fires at the top of the comment form, inside the form tag.
     2054                                                 * Filter the 'logged in' message for the comment form for display.
     2055                                                 *
     2056                                                 * @since 3.0.0
     2057                                                 *
     2058                                                 * @param string $args_logged_in The logged-in-as HTML-formatted message.
     2059                                                 * @param array  $commenter      An array containing the comment author's
     2060                                                 *                               username, email, and URL.
     2061                                                 * @param string $user_identity  If the commenter is a registered user,
     2062                                                 *                               the display name, blank otherwise.
     2063                                                 */
     2064                                                echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
     2065
     2066                                                /**
     2067                                                 * Fires after the is_user_logged_in() check in the comment form.
     2068                                                 *
     2069                                                 * @since 3.0.0
     2070                                                 *
     2071                                                 * @param array  $commenter     An array containing the comment author's
     2072                                                 *                              username, email, and URL.
     2073                                                 * @param string $user_identity If the commenter is a registered user,
     2074                                                 *                              the display name, blank otherwise.
     2075                                                 */
     2076                                                do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
     2077
     2078                                        else :
     2079
     2080                                                echo $args['comment_notes_before'];
     2081
     2082                                        endif;
     2083
     2084                                        /**
     2085                                         * Filter the content of the comment textarea field for display.
     2086                                         *
     2087                                         * @since 3.0.0
     2088                                         *
     2089                                         * @param string $args_comment_field The content of the comment textarea field.
     2090                                         */
     2091                                        echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
     2092
     2093                                        echo $args['comment_notes_after'];
     2094
     2095                                        if ( ! is_user_logged_in() ) :
     2096                                                /**
     2097                                                 * Fires before the comment fields in the comment form.
    20502098                                                 *
    20512099                                                 * @since 3.0.0
    20522100                                                 */
    2053                                                 do_action( 'comment_form_top' );
    2054                                                 ?>
    2055                                                 <?php if ( is_user_logged_in() ) : ?>
    2056                                                         <?php
     2101                                                do_action( 'comment_form_before_fields' );
     2102                                                foreach ( (array) $args['fields'] as $name => $field ) {
    20572103                                                        /**
    2058                                                          * Filter the 'logged in' message for the comment form for display.
     2104                                                         * Filter a comment form field for display.
     2105                                                         *
     2106                                                         * The dynamic portion of the filter hook, `$name`, refers to the name
     2107                                                         * of the comment form field. Such as 'author', 'email', or 'url'.
    20592108                                                         *
    20602109                                                         * @since 3.0.0
    20612110                                                         *
    2062                                                          * @param string $args_logged_in The logged-in-as HTML-formatted message.
    2063                                                          * @param array  $commenter      An array containing the comment author's
    2064                                                          *                               username, email, and URL.
    2065                                                          * @param string $user_identity  If the commenter is a registered user,
    2066                                                          *                               the display name, blank otherwise.
     2111                                                         * @param string $field The HTML-formatted output of the comment form field.
    20672112                                                         */
    2068                                                         echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity );
    2069                                                         ?>
    2070                                                         <?php
    2071                                                         /**
    2072                                                          * Fires after the is_user_logged_in() check in the comment form.
    2073                                                          *
    2074                                                          * @since 3.0.0
    2075                                                          *
    2076                                                          * @param array  $commenter     An array containing the comment author's
    2077                                                          *                              username, email, and URL.
    2078                                                          * @param string $user_identity If the commenter is a registered user,
    2079                                                          *                              the display name, blank otherwise.
    2080                                                          */
    2081                                                         do_action( 'comment_form_logged_in_after', $commenter, $user_identity );
    2082                                                         ?>
    2083                                                 <?php else : ?>
    2084                                                         <?php echo $args['comment_notes_before']; ?>
    2085                                                         <?php
    2086                                                         /**
    2087                                                          * Fires before the comment fields in the comment form.
    2088                                                          *
    2089                                                          * @since 3.0.0
    2090                                                          */
    2091                                                         do_action( 'comment_form_before_fields' );
    2092                                                         foreach ( (array) $args['fields'] as $name => $field ) {
    2093                                                                 /**
    2094                                                                  * Filter a comment form field for display.
    2095                                                                  *
    2096                                                                  * The dynamic portion of the filter hook, `$name`, refers to the name
    2097                                                                  * of the comment form field. Such as 'author', 'email', or 'url'.
    2098                                                                  *
    2099                                                                  * @since 3.0.0
    2100                                                                  *
    2101                                                                  * @param string $field The HTML-formatted output of the comment form field.
    2102                                                                  */
    2103                                                                 echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
    2104                                                         }
    2105                                                         /**
    2106                                                          * Fires after the comment fields in the comment form.
    2107                                                          *
    2108                                                          * @since 3.0.0
    2109                                                          */
    2110                                                         do_action( 'comment_form_after_fields' );
    2111                                                         ?>
    2112                                                 <?php endif; ?>
    2113                                                 <?php
     2113                                                        echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
     2114                                                }
    21142115                                                /**
    2115                                                  * Filter the content of the comment textarea field for display.
     2116                                                 * Fires after the comment fields in the comment form.
    21162117                                                 *
    21172118                                                 * @since 3.0.0
    2118                                                  *
    2119                                                  * @param string $args_comment_field The content of the comment textarea field.
    21202119                                                 */
    2121                                                 echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
    2122                                                 ?>
    2123                                                 <?php echo $args['comment_notes_after']; ?>
    2124 
    2125                                                 <?php
    2126                                                 $submit_button = sprintf(
    2127                                                         $args['submit_button'],
    2128                                                         esc_attr( $args['name_submit'] ),
    2129                                                         esc_attr( $args['id_submit'] ),
    2130                                                         esc_attr( $args['class_submit'] ),
    2131                                                         esc_attr( $args['label_submit'] )
    2132                                                 );
    2133 
    2134                                                 /**
    2135                                                  * Filter the submit button for the comment form to display.
    2136                                                  *
    2137                                                  * @since 4.2.0
    2138                                                  *
    2139                                                  * @param string $submit_button HTML markup for the submit button.
    2140                                                  * @param array  $args          Arguments passed to `comment_form()`.
    2141                                                  */
    2142                                                 $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
    2143 
    2144                                                 $submit_field = sprintf(
    2145                                                         $args['submit_field'],
    2146                                                         $submit_button,
    2147                                                         get_comment_id_fields( $post_id )
    2148                                                 );
    2149 
    2150                                                 /**
    2151                                                  * Filter the submit field for the comment form to display.
    2152                                                  *
    2153                                                  * The submit field includes the submit button, hidden fields for the
    2154                                                  * comment form, and any wrapper markup.
    2155                                                  *
    2156                                                  * @since 4.2.0
    2157                                                  *
    2158                                                  * @param string $submit_field HTML markup for the submit field.
    2159                                                  * @param array  $args         Arguments passed to comment_form().
    2160                                                  */
    2161                                                 echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
    2162 
    2163                                                 /**
    2164                                                  * Fires at the bottom of the comment form, inside the closing </form> tag.
    2165                                                  *
    2166                                                  * @since 1.5.0
    2167                                                  *
    2168                                                  * @param int $post_id The post ID.
    2169                                                  */
    2170                                                 do_action( 'comment_form', $post_id );
    2171                                                 ?>
    2172                                         </form>
    2173                                 <?php endif; ?>
    2174                         </div><!-- #respond -->
    2175                         <?php
    2176                         /**
    2177                          * Fires after the comment form.
    2178                          *
    2179                          * @since 3.0.0
    2180                          */
    2181                         do_action( 'comment_form_after' );
    2182                 else :
    2183                         /**
    2184                          * Fires after the comment form if comments are closed.
    2185                          *
    2186                          * @since 3.0.0
    2187                          */
    2188                         do_action( 'comment_form_comments_closed' );
    2189                 endif;
    2190 }
     2120                                                do_action( 'comment_form_after_fields' );
     2121
     2122                                        endif;
     2123
     2124                                        $submit_button = sprintf(
     2125                                                $args['submit_button'],
     2126                                                esc_attr( $args['name_submit'] ),
     2127                                                esc_attr( $args['id_submit'] ),
     2128                                                esc_attr( $args['class_submit'] ),
     2129                                                esc_attr( $args['label_submit'] )
     2130                                        );
     2131
     2132                                        /**
     2133                                         * Filter the submit button for the comment form to display.
     2134                                         *
     2135                                         * @since 4.2.0
     2136                                         *
     2137                                         * @param string $submit_button HTML markup for the submit button.
     2138                                         * @param array  $args          Arguments passed to `comment_form()`.
     2139                                         */
     2140                                        $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
     2141
     2142                                        $submit_field = sprintf(
     2143                                                $args['submit_field'],
     2144                                                $submit_button,
     2145                                                get_comment_id_fields( $post_id )
     2146                                        );
     2147
     2148                                        /**
     2149                                         * Filter the submit field for the comment form to display.
     2150                                         *
     2151                                         * The submit field includes the submit button, hidden fields for the
     2152                                         * comment form, and any wrapper markup.
     2153                                         *
     2154                                         * @since 4.2.0
     2155                                         *
     2156                                         * @param string $submit_field HTML markup for the submit field.
     2157                                         * @param array  $args         Arguments passed to comment_form().
     2158                                         */
     2159                                        echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
     2160
     2161                                        /**
     2162                                         * Fires at the bottom of the comment form, inside the closing </form> tag.
     2163                                         *
     2164                                         * @since 1.5.0
     2165                                         *
     2166                                         * @param int $post_id The post ID.
     2167                                         */
     2168                                        do_action( 'comment_form', $post_id );
     2169                                        ?>
     2170                                </form>
     2171                        <?php endif; ?>
     2172                </div><!-- #respond -->
     2173                <?php
     2174                /**
     2175                 * Fires after the comment form.
     2176                 *
     2177                 * @since 3.0.0
     2178                 */
     2179                do_action( 'comment_form_after' );
     2180        else :
     2181                /**
     2182                 * Fires after the comment form if comments are closed.
     2183                 *
     2184                 * @since 3.0.0
     2185                 */
     2186                do_action( 'comment_form_comments_closed' );
     2187        endif;
     2188}
Note: See TracChangeset for help on using the changeset viewer.