Make WordPress Core

Ticket #37332: 37332.3.diff

File 37332.3.diff, 3.2 KB (added by joedolson, 4 months ago)

Revised version of patch with improved accessibility

  • src/wp-includes/post-template.php

     
    17671767 * @return string HTML content for password form for password protected post.
    17681768 */
    17691769function get_the_password_form( $post = 0 ) {
    1770         $post   = get_post( $post );
    1771         $label  = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
    1772         $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form" method="post">
     1770        $post                  = get_post( $post );
     1771        $label                 = 'pwbox-' . ( empty( $post->ID ) ? rand() : $post->ID );
     1772        $invalid_password      = '';
     1773        $invalid_password_html = '';
     1774        $aria                  = '';
     1775        $class                 = '';
     1776
     1777        // If the referrer is the same as the current request, the user has entered an invalid password.
     1778        if ( ! empty( $post->ID ) && wp_get_raw_referer() === get_permalink( $post->ID ) && isset( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) ) {
     1779                /**
     1780                 * Filters the invalid password message shown on password-protected posts.
     1781                 * The filter is only applied if the post is password protected.
     1782                 *
     1783                 * @since 6.8.0
     1784                 *
     1785                 * @param string The message shown to users when entering an invalid password.
     1786                 * @param WP_Post $post   Post object.
     1787                 */
     1788                $invalid_password      = apply_filters( 'the_password_form_incorrect_password', __( 'Invalid password.' ), $post );
     1789                $invalid_password_html = '<div class="post-password-form-invalid-password" role="alert"><p id="error-' . $label . '">' . $invalid_password . '</p></div>';
     1790                $aria                  = ' aria-describedby="error-' . $label . '"';
     1791                $class                 = ' password-form-error';
     1792        }
     1793
     1794        $output = '<form action="' . esc_url( site_url( 'wp-login.php?action=postpass', 'login_post' ) ) . '" class="post-password-form' . $class . '" method="post">' . $invalid_password_html . '
    17731795        <p>' . __( 'This content is password protected. To view it please enter your password below:' ) . '</p>
    1774         <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" spellcheck="false" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
     1796        <p><label for="' . $label . '">' . __( 'Password:' ) . ' <input name="post_password" id="' . $label . '" type="password" spellcheck="false" size="20"' . $aria . ' /></label> <input type="submit" name="Submit" value="' . esc_attr_x( 'Enter', 'post password form' ) . '" /></p></form>
    17751797        ';
    17761798
    17771799        /**
     
    17841806         *
    17851807         * @since 2.7.0
    17861808         * @since 5.8.0 Added the `$post` parameter.
     1809         * @since 6.8.0 Added the `$invalid_password` parameter.
    17871810         *
    17881811         * @param string  $output The password form HTML output.
    17891812         * @param WP_Post $post   Post object.
     1813         * @param string  $invalid_password The invalid password message.
    17901814         */
    1791         return apply_filters( 'the_password_form', $output, $post );
     1815        return apply_filters( 'the_password_form', $output, $post, $invalid_password );
    17921816}
    17931817
    17941818/**