Make WordPress Core

Ticket #37522: 37522.2.diff

File 37522.2.diff, 4.2 KB (added by desrosj, 8 years ago)

Refreshed since tag in documentation.

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

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