admin-post.php 2.0 KB

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