WordPress.org

Make WordPress Core

Ticket #24732: wp-html5-required.patch

File wp-html5-required.patch, 3.0 KB (added by MMN-o, 9 months ago)

HTML5 patch for comment_form required fields

  • comment-template.php

     
    16111611 
    16121612        $req      = get_option( 'require_name_email' ); 
    16131613        $aria_req = ( $req ? " aria-required='true'" : '' ); 
     1614        $html_req = ( $req ? " required" : '' ); 
    16141615        $html5    = 'html5' === $args['format']; 
    16151616        $fields   =  array( 
    16161617                'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 
    1617                             '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>', 
     1618                            '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>', 
    16181619                'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 
    1619                             '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>', 
     1620                            '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . $html_req . ' /></p>', 
    16201621                'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . 
    16211622                            '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>', 
    16221623        ); 
     
    16241625        $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); 
    16251626        $defaults = array( 
    16261627                'fields'               => apply_filters( 'comment_form_default_fields', $fields ), 
    1627                 'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>', 
     1628                'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>', 
    16281629                '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>', 
    16291630                '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>', 
    16301631                'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',