admin-ajax.php 3.71 KB
Newer Older
godog's avatar
godog committed
1
2
<?php
/**
lucha's avatar
lucha committed
3
 * WordPress Ajax Process Execution
godog's avatar
godog committed
4
5
6
 *
 * @package WordPress
 * @subpackage Administration
lechuck's avatar
lechuck committed
7
 *
ale's avatar
ale committed
8
 * @link https://codex.wordpress.org/AJAX_in_Plugins
godog's avatar
godog committed
9
10
11
 */

/**
lucha's avatar
lucha committed
12
 * Executing Ajax process.
godog's avatar
godog committed
13
 *
root's avatar
root committed
14
 * @since 2.1.0
godog's avatar
godog committed
15
 */
lechuck's avatar
lechuck committed
16
define( 'DOING_AJAX', true );
lucha's avatar
lucha committed
17
18
19
if ( ! defined( 'WP_ADMIN' ) ) {
	define( 'WP_ADMIN', true );
}
godog's avatar
godog committed
20

lechuck's avatar
lechuck committed
21
22
23
/** Load WordPress Bootstrap */
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );

lechuck's avatar
lechuck committed
24
/** Allow for cross-domain requests (from the front end). */
lechuck's avatar
lechuck committed
25
26
send_origin_headers();

lechuck's avatar
lechuck committed
27
28
// Require an action parameter
if ( empty( $_REQUEST['action'] ) )
godog's avatar
godog committed
29
30
	die( '0' );

lechuck's avatar
lechuck committed
31
32
/** Load WordPress Administration APIs */
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
godog's avatar
godog committed
33

lechuck's avatar
lechuck committed
34
35
/** Load Ajax Handlers for WordPress Core */
require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
godog's avatar
godog committed
36

lechuck's avatar
lechuck committed
37
38
@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
@header( 'X-Robots-Tag: noindex' );
godog's avatar
godog committed
39

lechuck's avatar
lechuck committed
40
send_nosniff_header();
lechuck's avatar
lechuck committed
41
nocache_headers();
root's avatar
root committed
42

lucha's avatar
lucha committed
43
/** This action is documented in wp-admin/admin.php */
lechuck's avatar
lechuck committed
44
45
46
47
48
49
50
51
52
53
54
do_action( 'admin_init' );

$core_actions_get = array(
	'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
	'autocomplete-user', 'dashboard-widgets', 'logged-in',
);

$core_actions_post = array(
	'oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
	'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
	'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
lechuck's avatar
lechuck committed
55
	'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes',
lechuck's avatar
lechuck committed
56
57
58
	'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
	'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
	'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
lechuck's avatar
lechuck committed
59
	'save-widget', 'delete-inactive-widgets', 'set-post-thumbnail', 'date_format', 'time_format',
lechuck's avatar
lechuck committed
60
61
	'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
	'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
lechuck's avatar
lechuck committed
62
	'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
lucha's avatar
lucha committed
63
	'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
ale's avatar
ale committed
64
	'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
lucha's avatar
lucha committed
65
66
67
	'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin',
	'search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme',
	'install-theme', 'get-post-thumbnail-html',
lechuck's avatar
lechuck committed
68
69
);

lechuck's avatar
lechuck committed
70
71
72
// Deprecated
$core_actions_post[] = 'wp-fullscreen-save-post';

lechuck's avatar
lechuck committed
73
74
75
76
77
78
79
// Register core Ajax calls.
if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) )
	add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );

if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) )
	add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );

lechuck's avatar
lechuck committed
80
add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
lechuck's avatar
lechuck committed
81

lucha's avatar
lucha committed
82
83
if ( is_user_logged_in() ) {
	/**
lucha's avatar
lucha committed
84
	 * Fires authenticated Ajax actions for logged-in users.
lucha's avatar
lucha committed
85
	 *
lechuck's avatar
lechuck committed
86
	 * The dynamic portion of the hook name, `$_REQUEST['action']`,
lucha's avatar
lucha committed
87
	 * refers to the name of the Ajax action callback being fired.
lucha's avatar
lucha committed
88
89
90
91
92
93
	 *
	 * @since 2.1.0
	 */
	do_action( 'wp_ajax_' . $_REQUEST['action'] );
} else {
	/**
lucha's avatar
lucha committed
94
	 * Fires non-authenticated Ajax actions for logged-out users.
lucha's avatar
lucha committed
95
	 *
lechuck's avatar
lechuck committed
96
	 * The dynamic portion of the hook name, `$_REQUEST['action']`,
lucha's avatar
lucha committed
97
	 * refers to the name of the Ajax action callback being fired.
lucha's avatar
lucha committed
98
99
100
101
102
	 *
	 * @since 2.8.0
	 */
	do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
}
lechuck's avatar
lechuck committed
103
104
// Default status
die( '0' );