[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> admin-post.php (source)

   1  <?php
   2  /**
   3   * WordPress Generic Request (POST/GET) Handler
   4   *
   5   * Intended for form submission handling in themes and plugins.
   6   *
   7   * @package WordPress
   8   * @subpackage Administration
   9   */
  10  
  11  /** We are located in WordPress Administration Screens */
  12  if ( ! defined( 'WP_ADMIN' ) ) {
  13      define( 'WP_ADMIN', true );
  14  }
  15  
  16  if ( defined( 'ABSPATH' ) ) {
  17      require_once ABSPATH . 'wp-load.php';
  18  } else {
  19      require_once dirname( __DIR__ ) . '/wp-load.php';
  20  }
  21  
  22  /** Allow for cross-domain requests (from the front end). */
  23  send_origin_headers();
  24  
  25  require_once  ABSPATH . 'wp-admin/includes/admin.php';
  26  
  27  nocache_headers();
  28  
  29  /** This action is documented in wp-admin/admin.php */
  30  do_action( 'admin_init' );
  31  
  32  $action = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
  33  
  34  // Reject invalid parameters.
  35  if ( ! is_scalar( $action ) ) {
  36      wp_die( '', 400 );
  37  }
  38  
  39  if ( ! is_user_logged_in() ) {
  40      if ( empty( $action ) ) {
  41          /**
  42           * Fires on a non-authenticated admin post request where no action is supplied.
  43           *
  44           * @since 2.6.0
  45           */
  46          do_action( 'admin_post_nopriv' );
  47      } else {
  48          // If no action is registered, return a Bad Request response.
  49          if ( ! has_action( "admin_post_nopriv_{$action}" ) ) {
  50              wp_die( '', 400 );
  51          }
  52  
  53          /**
  54           * Fires on a non-authenticated admin post request for the given action.
  55           *
  56           * The dynamic portion of the hook name, `$action`, refers to the given
  57           * request action.
  58           *
  59           * @since 2.6.0
  60           */
  61          do_action( "admin_post_nopriv_{$action}" );
  62      }
  63  } else {
  64      if ( empty( $action ) ) {
  65          /**
  66           * Fires on an authenticated admin post request where no action is supplied.
  67           *
  68           * @since 2.6.0
  69           */
  70          do_action( 'admin_post' );
  71      } else {
  72          // If no action is registered, return a Bad Request response.
  73          if ( ! has_action( "admin_post_{$action}" ) ) {
  74              wp_die( '', 400 );
  75          }
  76  
  77          /**
  78           * Fires on an authenticated admin post request for the given action.
  79           *
  80           * The dynamic portion of the hook name, `$action`, refers to the given
  81           * request action.
  82           *
  83           * @since 2.6.0
  84           */
  85          do_action( "admin_post_{$action}" );
  86      }
  87  }


Generated: Sat Apr 20 01:00:03 2024 Cross-referenced by PHPXref 0.7.1