[wp-trac] [WordPress Trac] #38079: Add hooks before output for each action in wp-login.php

WordPress Trac noreply at wordpress.org
Thu May 2 17:31:41 UTC 2024


#38079: Add hooks before output for each action in wp-login.php
-------------------------------------------------+-------------------------
 Reporter:  jfarthing84                          |       Owner:
                                                 |  voldemortensen
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Login and Registration               |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch reporter-feedback          |     Focuses:
  changes-requested                              |
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch reporter-feedback => has-patch reporter-feedback
     changes-requested


Comment:

 The request is to add a hook _before_ each action's output (i.e. the HTML
 sent out to the browser).

 >Having an action that fires just before the login_header() call in each
 case of the action handler switch should be sufficient.

 Why doesn't [attachment:"38079.patch"] cover all of the actions? It's
 adding 5 pre hooks. But there are 9 output points for the actions and each
 of those invokes `login_header()`. Looking at the `switch ( $action )`
 cases:

 * 1x in `'confirm_admin_email'` action.
 * 1x in the `'lostpassword'` and `'retrievepassword'` actions.
 * 2x in the `'resetpass'` and `'rp'` actions.
 * 1x in the `'register'` action.
 * 1x in the `'checkmail'` action.
 * 1x in the `'confirmaction'` action.
 * 2x in the `'login'` and `default` actions.

 These actions do not output HTML:
 * `'postpass'`
 * `'logout'`

 Notice: `login_header()` is invoked 9 times and there 9 paths for the
 actions that output HTML.


 So I'm wondering ... instead of adding individual `do_action()` just
 before each `login_header()` instance, why not add just one `do_action()`
 at the start of function itself?

 There are a fews of ways to do this:

 **Option 1**: The new hook follows `"login_form_{$action}"` convention:
 {{{
 function login_header( $title = 'Log In', $message = '', $wp_error = null
 ) {
         global $error, $interim_login, $action;

         do_action( "pre_login_form_{$action}", $title, $message, $wp_error
 );
 }}}

 **Option 2**: The new hook uses the function's name and also passes the
 `$action`.
 {{{
 function login_header( $title = 'Log In', $message = '', $wp_error = null
 ) {
         global $error, $interim_login, $action;

         do_action( "pre_login_header", $title, $message, $wp_error,
 $action );
 }}}

 Both of the above options accomplish the ticket's request and
 @SergeyBiryukov's [comment:15 observation]:
 >On second thought, hooks before any output might indeed be helpful for
 redirects or more extensive customizations.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/38079#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list