WordPress.org

Make WordPress Core

Ticket #26869: 26869.2.diff

File 26869.2.diff, 2.2 KB (added by DrewAPicture, 4 years ago)

Four hooks for admin_post

  • src/wp-admin/admin-post.php

     
    2626/** This action is documented in wp-admin/admin.php */
    2727do_action( 'admin_init' );
    2828
    29 $action = '';
     29$action = empty( $_REQUEST['action'] ) ? '' : $_REQUEST['action'];
    3030
    31 if ( !wp_validate_auth_cookie() )
    32         $action .= '_nopriv';
    33 
    34 if ( !empty($_REQUEST['action']) )
    35         $action .= '_' . $_REQUEST['action'];
    36 
    37 /**
    38  * Fires the requested handler action.
    39  *
    40  * The dynamic portion of the hook name, $action, refers to a combination
    41  * of whether the user is logged-in or not, and the requested handler action.
    42  *
    43  * If the user is logged-out, '_nopriv' will be affixed to the
    44  * base "admin_post" hook name. If a handler action was passed, that action
    45  * will also be affixed.
    46  *
    47  * For example:
    48  * Hook combinations fired for logged-out users:
    49  * `admin_post_nopriv_{$action}` and `admin_post_nopriv` (no action supplied).
    50  *
    51  * Hook combinations fired for logged-in users:
    52  * `admin_post_{$action}` and `admin_post` (no action supplied).
    53  *
    54  * @since 2.6.0
    55  */
    56 do_action( "admin_post{$action}" );
     31if ( wp_validate_auth_cookie() ) {
     32        if ( empty( $action ) ) {
     33                /**
     34                 * Fires on an authenticated admin POST request where no action was supplied.
     35                 *
     36                 * @since 2.6.0
     37                 */
     38                do_action( 'admin_post' );
     39        } else {
     40                /**
     41                 * Fires on an authenticated admin POST request for the given action.
     42                 *
     43                 * The dynamic portion of the hook name, $action, refers to the requested
     44                 * handler action.
     45                 *
     46                 * @since 2.6.0
     47                 */
     48                do_action( "admin_post_{$action}" );
     49        }
     50} else {
     51        if ( empty( $action ) ) {
     52                /**
     53                 * Fires on a non-authenticated admin POST request where no action was supplied.
     54                 *
     55                 * @since 2.6.0
     56                 */
     57                do_action( 'admin_post_nopriv' );
     58        } else {
     59                /**
     60                 * Fires on a non-authenticated admin POST request for the given action.
     61                 *
     62                 * The dynamic portion of the hook name, $action, refers to the requested
     63                 * handler action.
     64                 *
     65                 * @since 2.6.0
     66                 */
     67                do_action( "admin_post_nopriv_{$action}" );
     68        }
     69}