WordPress.org

Make WordPress Core

Ticket #37522: 37522.diff

File 37522.diff, 4.2 KB (added by voldemortensen, 5 years ago)

Implements wp_lostpassword_form

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

     
    494494}
    495495
    496496/**
     497 * Provides a simple lostpassword form for use anywhere within WordPress.
     498 *
     499 * The lostpassword form HTML is echoed by default. Pass a false value for `$echo` to return it instead.
     500 *
     501 * @since 4.8.0
     502 *
     503 * @param array $args {
     504 *     Optional. Array of options to control the form output. Default empty array.
     505 *
     506 *     @type bool   $echo           Whether to display the lostpassword form or return the form HTML code.
     507 *                                  Default true (echo).
     508 *     @type string $redirect       URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
     509 *                                  Default is to redirect back to the request URI.
     510 *     @type string $form_id        ID attribute value for the form. Default 'lostpasswordform'.
     511 *     @type string $label_username Label for the username or email address field. Default 'Username or Email Address'.
     512 *     @type string $label_submit   Label for the submit button. Default 'Log In'.
     513 *     @type string $id_username    ID attribute value for the username field. Default 'user_login'.
     514 *     @type string $id_submit      ID attribute value for the submit button. Default 'wp-submit'.
     515 *     @type string $value_username Default value for the username field. Default empty.
     516 *
     517 * }
     518 * @return string|void String when retrieving.
     519 */
     520function wp_lostpassword_form( $args = array() ) {
     521        $defaults = array(
     522                'echo' => true,
     523                // Default 'redirect' value takes the user back to the request URI.
     524                'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
     525                'form_id' => 'lostpasswordform',
     526                'label_username' => __( 'Username or Email Address' ),
     527                'label_submit' => __( 'Get New Password' ),
     528                'id_username' => 'user_login',
     529                'id_submit' => 'wp-submit',
     530                'value_username' => '',
     531        );
     532
     533        /**
     534         * Filters the default lostpassword form output arguments.
     535         *
     536         * @since 4.8.0
     537         *
     538         * @see wp_lostpassword_form()
     539         *
     540         * @param array $defaults An array of default lostpassword form arguments.
     541         */
     542        $args = wp_parse_args( $args, apply_filters( 'lostpassword_form_defaults', $defaults ) );
     543
     544        /**
     545         * Filters content to display at the top of the lostpassword form.
     546         *
     547         * The filter evaluates just following the opening form tag element.
     548         *
     549         * @since 4.8.0
     550         *
     551         * @param string $content Content to display. Default empty.
     552         * @param array  $args    Array of lostpassword form arguments.
     553         */
     554        $lostpassword_form_top = apply_filters( 'lostpassword_form_top', '', $args );
     555
     556        /**
     557         * Filters content to display at the bottom of the lostpassword form.
     558         *
     559         * The filter evaluates just preceding the closing form tag element.
     560         *
     561         * @since 4.8.0
     562         *
     563         * @param string $content Content to display. Default empty.
     564         * @param array  $args    Array of lostpassword form arguments.
     565         */
     566        $lostpassword_form_bottom = apply_filters( 'login_form_bottom', '', $args );
     567
     568        $form = '
     569                <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( add_query_arg( 'action', 'lostpassword', site_url( 'wp-login.php') ) ) . '" method="post">
     570                        ' . $lostpassword_form_top . '
     571                        <p>
     572                                <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '
     573                                        <br>
     574                                        <input type="text" name="user_login" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20">
     575                                </label>
     576                        </p>
     577                        <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '">
     578                        <p class="submit">
     579                                <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button button-primary" value="' . esc_attr( $args['label_submit'] ) . '">
     580                        </p>
     581                        ' . $lostpassword_form_bottom . '
     582                </form>';
     583
     584        if ( $args['echo'] ) {
     585                echo $form;
     586        } else {
     587                return $form;
     588        }
     589}
     590
     591/**
    497592 * Returns the URL that allows the user to retrieve the lost password
    498593 *
    499594 * @since 2.8.0