wp/wp-admin/admin-ajax.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    17 if ( ! defined( 'WP_ADMIN' ) ) {
    17 if ( ! defined( 'WP_ADMIN' ) ) {
    18 	define( 'WP_ADMIN', true );
    18 	define( 'WP_ADMIN', true );
    19 }
    19 }
    20 
    20 
    21 /** Load WordPress Bootstrap */
    21 /** Load WordPress Bootstrap */
    22 require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    22 require_once dirname( __DIR__ ) . '/wp-load.php';
    23 
    23 
    24 /** Allow for cross-domain requests (from the front end). */
    24 /** Allow for cross-domain requests (from the front end). */
    25 send_origin_headers();
    25 send_origin_headers();
    26 
    26 
    27 // Require an action parameter
    27 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
       
    28 header( 'X-Robots-Tag: noindex' );
       
    29 
       
    30 // Require an action parameter.
    28 if ( empty( $_REQUEST['action'] ) ) {
    31 if ( empty( $_REQUEST['action'] ) ) {
    29 	wp_die( '0', 400 );
    32 	wp_die( '0', 400 );
    30 }
    33 }
    31 
    34 
    32 /** Load WordPress Administration APIs */
    35 /** Load WordPress Administration APIs */
    33 require_once( ABSPATH . 'wp-admin/includes/admin.php' );
    36 require_once ABSPATH . 'wp-admin/includes/admin.php';
    34 
    37 
    35 /** Load Ajax Handlers for WordPress Core */
    38 /** Load Ajax Handlers for WordPress Core */
    36 require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
    39 require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
    37 
       
    38 @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
       
    39 @header( 'X-Robots-Tag: noindex' );
       
    40 
    40 
    41 send_nosniff_header();
    41 send_nosniff_header();
    42 nocache_headers();
    42 nocache_headers();
    43 
    43 
    44 /** This action is documented in wp-admin/admin.php */
    44 /** This action is documented in wp-admin/admin.php */
    51 	'imgedit-preview',
    51 	'imgedit-preview',
    52 	'oembed-cache',
    52 	'oembed-cache',
    53 	'autocomplete-user',
    53 	'autocomplete-user',
    54 	'dashboard-widgets',
    54 	'dashboard-widgets',
    55 	'logged-in',
    55 	'logged-in',
       
    56 	'rest-nonce',
    56 );
    57 );
    57 
    58 
    58 $core_actions_post = array(
    59 $core_actions_post = array(
    59 	'oembed-cache',
    60 	'oembed-cache',
    60 	'image-editor',
    61 	'image-editor',
   103 	'save-attachment',
   104 	'save-attachment',
   104 	'save-attachment-compat',
   105 	'save-attachment-compat',
   105 	'send-link-to-editor',
   106 	'send-link-to-editor',
   106 	'send-attachment-to-editor',
   107 	'send-attachment-to-editor',
   107 	'save-attachment-order',
   108 	'save-attachment-order',
       
   109 	'media-create-image-subsizes',
   108 	'heartbeat',
   110 	'heartbeat',
   109 	'get-revision-diffs',
   111 	'get-revision-diffs',
   110 	'save-user-color-scheme',
   112 	'save-user-color-scheme',
   111 	'update-widget',
   113 	'update-widget',
   112 	'query-themes',
   114 	'query-themes',
   135 	'health-check-dotorg-communication',
   137 	'health-check-dotorg-communication',
   136 	'health-check-is-in-debug-mode',
   138 	'health-check-is-in-debug-mode',
   137 	'health-check-background-updates',
   139 	'health-check-background-updates',
   138 	'health-check-loopback-requests',
   140 	'health-check-loopback-requests',
   139 	'health-check-get-sizes',
   141 	'health-check-get-sizes',
       
   142 	'toggle-auto-updates',
   140 );
   143 );
   141 
   144 
   142 // Deprecated
   145 // Deprecated.
   143 $core_actions_post_deprecated = array( 'wp-fullscreen-save-post', 'press-this-save-post', 'press-this-add-category' );
   146 $core_actions_post_deprecated = array( 'wp-fullscreen-save-post', 'press-this-save-post', 'press-this-add-category' );
   144 $core_actions_post            = array_merge( $core_actions_post, $core_actions_post_deprecated );
   147 $core_actions_post            = array_merge( $core_actions_post, $core_actions_post_deprecated );
   145 
   148 
   146 // Register core Ajax calls.
   149 // Register core Ajax calls.
   147 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) {
   150 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get, true ) ) {
   148 	add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
   151 	add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
   149 }
   152 }
   150 
   153 
   151 if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) ) {
   154 if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post, true ) ) {
   152 	add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
   155 	add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
   153 }
   156 }
   154 
   157 
   155 add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
   158 add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
   156 
   159 
   185 	 *
   188 	 *
   186 	 * @since 2.8.0
   189 	 * @since 2.8.0
   187 	 */
   190 	 */
   188 	do_action( "wp_ajax_nopriv_{$action}" );
   191 	do_action( "wp_ajax_nopriv_{$action}" );
   189 }
   192 }
   190 // Default status
   193 // Default status.
   191 wp_die( '0' );
   194 wp_die( '0' );