@@ -651,6 +651,107 @@ function wp_login_form( $args = array() ) {
651651 }
652652}
653653
654+ /**
655+ * Outputs or returns the lost password form for use anywhere on a WordPress site.
656+ *
657+ * @since 7.1.0
658+ *
659+ * @param array $args {
660+ * Optional. Array of arguments to control the form output. Default empty array.
661+ *
662+ * @type bool $echo Whether to display the form or return the output. Default true.
663+ * @type string $redirect URL to redirect to after submitting the form. Default empty string.
664+ * @type string $form_id ID attribute for the form element. Default 'lostpasswordform'.
665+ * @type string $id_username ID attribute for the username input. Default 'user_login'.
666+ * @type string $id_submit ID attribute for the submit button. Default 'wp-submit'.
667+ * @type string $label_username Label for the username input. Default 'Username or Email Address'.
668+ * @type string $label_submit Label for the submit button. Default 'Get New Password'.
669+ * }
670+ * @return void|string Void if 'echo' argument is true, lost password form HTML if 'echo' is false.
671+ */
672+ function wp_lostpassword_form ( $ args = array () ) {
673+ $ defaults = array (
674+ 'echo ' => true ,
675+ 'redirect ' => '' ,
676+ 'form_id ' => 'lostpasswordform ' ,
677+ 'id_username ' => 'user_login ' ,
678+ 'id_submit ' => 'wp-submit ' ,
679+ 'label_username ' => __ ( 'Username or Email Address ' ),
680+ 'label_submit ' => __ ( 'Get New Password ' ),
681+ );
682+
683+ /**
684+ * Filters the default lost password form arguments.
685+ *
686+ * @since 7.1.0
687+ *
688+ * @see wp_lostpassword_form()
689+ *
690+ * @param array $defaults An array of default lost password form arguments.
691+ */
692+ $ args = wp_parse_args ( $ args , apply_filters ( 'lostpassword_form_defaults ' , $ defaults ) );
693+
694+ $ user_login = '' ;
695+ if ( isset ( $ _POST ['user_login ' ] ) && is_string ( $ _POST ['user_login ' ] ) ) {
696+ $ user_login = wp_unslash ( $ _POST ['user_login ' ] );
697+ }
698+
699+ /**
700+ * Filters content to display at the top of the lost password form.
701+ *
702+ * The filter evaluates just following the opening form tag element.
703+ *
704+ * @since 7.1.0
705+ *
706+ * @param string $content Content to display. Default empty.
707+ * @param array $args Array of lost password form arguments.
708+ */
709+ $ lostpassword_form_top = apply_filters ( 'lostpassword_form_top ' , '' , $ args );
710+
711+ /**
712+ * Filters content to display at the bottom of the lost password form.
713+ *
714+ * The filter evaluates just preceding the closing form tag element.
715+ *
716+ * @since 7.1.0
717+ *
718+ * @param string $content Content to display. Default empty.
719+ * @param array $args Array of lost password form arguments.
720+ */
721+ $ lostpassword_form_bottom = apply_filters ( 'lostpassword_form_bottom ' , '' , $ args );
722+
723+ ob_start ();
724+ ?>
725+ <form name="<?php echo esc_attr ( $ args ['form_id ' ] ); ?> " id="<?php echo esc_attr ( $ args ['form_id ' ] ); ?> " action="<?php echo esc_url ( network_site_url ( 'wp-login.php?action=lostpassword ' , 'login_post ' ) ); ?> " method="post">
726+ <?php echo $ lostpassword_form_top ; ?>
727+ <p>
728+ <label for="<?php echo esc_attr ( $ args ['id_username ' ] ); ?> "><?php echo esc_html ( $ args ['label_username ' ] ); ?> </label>
729+ <input type="text" name="user_login" id="<?php echo esc_attr ( $ args ['id_username ' ] ); ?> " class="input ltr" value="<?php echo esc_attr ( $ user_login ); ?> " size="20" autocapitalize="off" autocomplete="username" required="required" />
730+ </p>
731+ <?php
732+ /**
733+ * Fires inside the lost password form tags, before the hidden fields.
734+ *
735+ * @since 2.1.0
736+ */
737+ do_action ( 'lostpassword_form ' );
738+ ?>
739+ <input type="hidden" name="redirect_to" value="<?php echo esc_attr ( $ args ['redirect ' ] ); ?> " />
740+ <p class="submit">
741+ <input type="submit" name="wp-submit" id="<?php echo esc_attr ( $ args ['id_submit ' ] ); ?> " class="button button-primary button-large" value="<?php echo esc_attr ( $ args ['label_submit ' ] ); ?> " />
742+ </p>
743+ <?php echo $ lostpassword_form_bottom ; ?>
744+ </form>
745+ <?php
746+ $ form = ob_get_clean ();
747+
748+ if ( $ args ['echo ' ] ) {
749+ echo $ form ;
750+ } else {
751+ return $ form ;
752+ }
753+ }
754+
654755/**
655756 * Returns the URL that allows the user to reset the lost password.
656757 *
0 commit comments