wp/wp-admin/admin-ajax.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     3  * WordPress AJAX Process Execution.
     3  * WordPress AJAX Process Execution.
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  *
     7  *
     8  * @link http://codex.wordpress.org/AJAX_in_Plugins
     8  * @link https://codex.wordpress.org/AJAX_in_Plugins
     9  */
     9  */
    10 
    10 
    11 /**
    11 /**
    12  * Executing AJAX process.
    12  * Executing AJAX process.
    13  *
    13  *
    14  * @since 2.1.0
    14  * @since 2.1.0
    15  */
    15  */
    16 define( 'DOING_AJAX', true );
    16 define( 'DOING_AJAX', true );
    17 define( 'WP_ADMIN', true );
    17 if ( ! defined( 'WP_ADMIN' ) ) {
       
    18 	define( 'WP_ADMIN', true );
       
    19 }
    18 
    20 
    19 /** Load WordPress Bootstrap */
    21 /** Load WordPress Bootstrap */
    20 require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    22 require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );
    21 
    23 
    22 /** Allow for cross-domain requests (from the frontend). */
    24 /** Allow for cross-domain requests (from the frontend). */
    48 
    50 
    49 $core_actions_post = array(
    51 $core_actions_post = array(
    50 	'oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
    52 	'oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link',
    51 	'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
    53 	'delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment',
    52 	'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
    54 	'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment',
    53 	'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'autosave', 'closed-postboxes',
    55 	'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes',
    54 	'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
    56 	'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax',
    55 	'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
    57 	'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink',
    56 	'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
    58 	'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
    57 	'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
    59 	'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
    58 	'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    60 	'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    59 	'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    61 	'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    60 	'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
    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', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
       
    65 	'press-this-add-category',
    61 );
    66 );
    62 
    67 
    63 // Register core Ajax calls.
    68 // Register core Ajax calls.
    64 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) )
    69 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) )
    65 	add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
    70 	add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );
    71 
    76 
    72 if ( is_user_logged_in() ) {
    77 if ( is_user_logged_in() ) {
    73 	/**
    78 	/**
    74 	 * Fires authenticated AJAX actions for logged-in users.
    79 	 * Fires authenticated AJAX actions for logged-in users.
    75 	 *
    80 	 *
    76 	 * The dynamic portion of the hook name, $_REQUEST['action'],
    81 	 * The dynamic portion of the hook name, `$_REQUEST['action']`,
    77 	 * refers to the name of the AJAX action callback being fired.
    82 	 * refers to the name of the AJAX action callback being fired.
    78 	 *
    83 	 *
    79 	 * @since 2.1.0
    84 	 * @since 2.1.0
    80 	 */
    85 	 */
    81 	do_action( 'wp_ajax_' . $_REQUEST['action'] );
    86 	do_action( 'wp_ajax_' . $_REQUEST['action'] );
    82 } else {
    87 } else {
    83 	/**
    88 	/**
    84 	 * Fires non-authenticated AJAX actions for logged-out users.
    89 	 * Fires non-authenticated AJAX actions for logged-out users.
    85 	 *
    90 	 *
    86 	 * The dynamic portion of the hook name, $_REQUEST['action'],
    91 	 * The dynamic portion of the hook name, `$_REQUEST['action']`,
    87 	 * refers to the name of the AJAX action callback being fired.
    92 	 * refers to the name of the AJAX action callback being fired.
    88 	 *
    93 	 *
    89 	 * @since 2.8.0
    94 	 * @since 2.8.0
    90 	 */
    95 	 */
    91 	do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
    96 	do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );