~canonical-sysadmins/wordpress/4.7.2

« back to all changes in this revision

Viewing changes to wp-admin/admin-ajax.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * WordPress AJAX Process Execution.
 
4
 *
 
5
 * @package WordPress
 
6
 * @subpackage Administration
 
7
 *
 
8
 * @link http://codex.wordpress.org/AJAX_in_Plugins
 
9
 */
 
10
 
 
11
/**
 
12
 * Executing AJAX process.
 
13
 *
 
14
 * @since 2.1.0
 
15
 */
 
16
define( 'DOING_AJAX', true );
 
17
if ( ! defined( 'WP_ADMIN' ) ) {
 
18
        define( 'WP_ADMIN', true );
 
19
}
 
20
 
 
21
/** Load WordPress Bootstrap */
 
22
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
 
23
 
 
24
/** Allow for cross-domain requests (from the frontend). */
 
25
send_origin_headers();
 
26
 
 
27
// Require an action parameter
 
28
if ( empty( $_REQUEST['action'] ) )
 
29
        die( '0' );
 
30
 
 
31
/** Load WordPress Administration APIs */
 
32
require_once( ABSPATH . 'wp-admin/includes/admin.php' );
 
33
 
 
34
/** Load Ajax Handlers for WordPress Core */
 
35
require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );
 
36
 
 
37
@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
 
38
@header( 'X-Robots-Tag: noindex' );
 
39
 
 
40
send_nosniff_header();
 
41
nocache_headers();
 
42
 
 
43
/** This action is documented in wp-admin/admin.php */
 
44
do_action( 'admin_init' );
 
45
 
 
46
$core_actions_get = array(
 
47
        'fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache',
 
48
        'autocomplete-user', 'dashboard-widgets', 'logged-in',
 
49
);
 
50
 
 
51
$core_actions_post = array(
 
52
        'oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
 
53
        'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
 
54
        'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
 
55
        'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes',
 
56
        'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
 
57
        'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
 
58
        'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
 
59
        'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
 
60
        'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
 
61
        'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
 
62
        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
 
63
        'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
 
64
        'parse-media-shortcode'
 
65
);
 
66
 
 
67
// Register core Ajax calls.
 
68
if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) )
 
69
        add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
 
70
 
 
71
if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) )
 
72
        add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );
 
73
 
 
74
add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );
 
75
 
 
76
if ( is_user_logged_in() ) {
 
77
        /**
 
78
         * Fires authenticated AJAX actions for logged-in users.
 
79
         *
 
80
         * The dynamic portion of the hook name, $_REQUEST['action'],
 
81
         * refers to the name of the AJAX action callback being fired.
 
82
         *
 
83
         * @since 2.1.0
 
84
         */
 
85
        do_action( 'wp_ajax_' . $_REQUEST['action'] );
 
86
} else {
 
87
        /**
 
88
         * Fires non-authenticated AJAX actions for logged-out users.
 
89
         *
 
90
         * The dynamic portion of the hook name, $_REQUEST['action'],
 
91
         * refers to the name of the AJAX action callback being fired.
 
92
         *
 
93
         * @since 2.8.0
 
94
         */
 
95
        do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
 
96
}
 
97
// Default status
 
98
die( '0' );