54 'add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-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', |
55 'edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes', |
56 'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax', |
56 'hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax', |
57 'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink', |
57 'menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink', |
58 'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order', |
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', |
59 'save-widget', 'delete-inactive-widgets', 'set-post-thumbnail', 'date_format', 'time_format', |
60 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', |
60 'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', |
61 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', |
61 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', |
62 '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', |
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', |
64 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'crop-image', |
65 'press-this-add-category', |
65 'generate-password', 'save-wporg-username', 'delete-plugin', 'search-plugins', |
|
66 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 'install-theme', |
|
67 'get-post-thumbnail-html', 'get-community-events', 'edit-theme-plugin-file', |
|
68 'wp-privacy-export-personal-data', |
|
69 'wp-privacy-erase-personal-data', |
|
70 'update-try-gutenberg-panel', |
66 ); |
71 ); |
|
72 |
|
73 // Deprecated |
|
74 $core_actions_post_deprecated = array( 'wp-fullscreen-save-post', 'press-this-save-post', 'press-this-add-category' ); |
|
75 $core_actions_post = array_merge( $core_actions_post, $core_actions_post_deprecated ); |
67 |
76 |
68 // Register core Ajax calls. |
77 // Register core Ajax calls. |
69 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) |
78 if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) ) |
70 add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 ); |
79 add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 ); |
71 |
80 |
73 add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 ); |
82 add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 ); |
74 |
83 |
75 add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 ); |
84 add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 ); |
76 |
85 |
77 if ( is_user_logged_in() ) { |
86 if ( is_user_logged_in() ) { |
|
87 // If no action is registered, return a Bad Request response. |
|
88 if ( ! has_action( 'wp_ajax_' . $_REQUEST['action'] ) ) { |
|
89 wp_die( '0', 400 ); |
|
90 } |
|
91 |
78 /** |
92 /** |
79 * Fires authenticated AJAX actions for logged-in users. |
93 * Fires authenticated Ajax actions for logged-in users. |
80 * |
94 * |
81 * The dynamic portion of the hook name, `$_REQUEST['action']`, |
95 * The dynamic portion of the hook name, `$_REQUEST['action']`, |
82 * refers to the name of the AJAX action callback being fired. |
96 * refers to the name of the Ajax action callback being fired. |
83 * |
97 * |
84 * @since 2.1.0 |
98 * @since 2.1.0 |
85 */ |
99 */ |
86 do_action( 'wp_ajax_' . $_REQUEST['action'] ); |
100 do_action( 'wp_ajax_' . $_REQUEST['action'] ); |
87 } else { |
101 } else { |
|
102 // If no action is registered, return a Bad Request response. |
|
103 if ( ! has_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ) ) { |
|
104 wp_die( '0', 400 ); |
|
105 } |
|
106 |
88 /** |
107 /** |
89 * Fires non-authenticated AJAX actions for logged-out users. |
108 * Fires non-authenticated Ajax actions for logged-out users. |
90 * |
109 * |
91 * The dynamic portion of the hook name, `$_REQUEST['action']`, |
110 * The dynamic portion of the hook name, `$_REQUEST['action']`, |
92 * refers to the name of the AJAX action callback being fired. |
111 * refers to the name of the Ajax action callback being fired. |
93 * |
112 * |
94 * @since 2.8.0 |
113 * @since 2.8.0 |
95 */ |
114 */ |
96 do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ); |
115 do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] ); |
97 } |
116 } |
98 // Default status |
117 // Default status |
99 die( '0' ); |
118 wp_die( '0' ); |