wp_send_json_success( mixed $data = null, int $status_code = null )
Send a JSON response back to an Ajax request, indicating success.
Description #Description
Parameters #Parameters
- $data
-
(mixed) (Optional) Data to encode as JSON, then print and die.
Default value: null
- $status_code
-
(int) (Optional) The HTTP status code to output.
Default value: null
Source #Source
File: wp-includes/functions.php
function wp_send_json_success( $data = null, $status_code = null ) { $response = array( 'success' => true ); if ( isset( $data ) ) { $response['data'] = $data; } wp_send_json( $response, $status_code ); }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
4.7.0 | The $status_code parameter was added. |
3.5.0 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/functions.php: wp_send_json() |
Send a JSON response back to an Ajax request. |
Used By #Used By
Used By | Description |
---|---|
wp-admin/includes/ajax-actions.php: wp_ajax_media_create_image_subsizes() |
Ajax handler for creating missing image sub-sizes for just uploaded images. |
wp-admin/includes/ajax-actions.php: wp_ajax_health_check_get_sizes() |
Ajax handler for site health check to get directories and database sizes. |
wp-admin/includes/ajax-actions.php: wp_ajax_health_check_dotorg_communication() |
Ajax handler for site health checks on server communication. |
wp-admin/includes/ajax-actions.php: wp_ajax_health_check_is_in_debug_mode() |
Ajax handler for site health checks on debug mode. |
wp-admin/includes/ajax-actions.php: wp_ajax_health_check_background_updates() |
Ajax handler for site health checks on background updates. |
wp-admin/includes/ajax-actions.php: wp_ajax_health_check_loopback_requests() |
Ajax handler for site health checks on loopback requests. |
wp-admin/includes/ajax-actions.php: wp_ajax_health_check_site_status_result() |
Ajax handler for site health check to update the result status. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_privacy_export_personal_data() |
Ajax handler for exporting a user’s personal data. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_privacy_erase_personal_data() |
Ajax handler for erasing personal data. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::handle_load_themes_request() |
Load themes into the theme browsing/installation UI. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::handle_override_changeset_lock_request() |
Removes changeset lock when take over request is sent via Ajax. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::handle_dismiss_autosave_or_lock_request() |
Delete a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::handle_changeset_trash_request() |
Handle request to trash a changeset. |
wp-admin/includes/ajax-actions.php: wp_ajax_edit_theme_plugin_file() |
Ajax handler for editing a theme or plugin file. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_community_events() |
Handles AJAX requests for community events |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::ajax_insert_auto_draft_post() |
Ajax handler for adding a new auto-draft post. |
wp-admin/includes/ajax-actions.php: wp_ajax_search_install_plugins() |
Ajax handler for searching plugins to install. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_plugin() |
Ajax handler for deleting a plugin. |
wp-admin/includes/ajax-actions.php: wp_ajax_search_plugins() |
Ajax handler for searching plugins. |
wp-admin/includes/ajax-actions.php: wp_ajax_install_theme() |
Ajax handler for installing a theme. |
wp-admin/includes/ajax-actions.php: wp_ajax_update_theme() |
Ajax handler for updating a theme. |
wp-admin/includes/ajax-actions.php: wp_ajax_delete_theme() |
Ajax handler for deleting a theme. |
wp-admin/includes/ajax-actions.php: wp_ajax_install_plugin() |
Ajax handler for installing a plugin. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_post_thumbnail_html() |
Ajax handler for retrieving HTML for the featured image. |
wp-includes/customize/class-wp-customize-selective-refresh.php: WP_Customize_Selective_Refresh::handle_render_partials_request() |
Handles the Ajax request to return the rendered partials for the requested placements. |
wp-admin/includes/ajax-actions.php: wp_ajax_generate_password() |
Ajax handler for generating a password. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_wporg_username() |
Ajax handler for saving the user’s WordPress.org username. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::ajax_load_available_items() |
Ajax handler for loading available menu items. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::ajax_search_available_items() |
Ajax handler for searching available menu items. |
wp-admin/includes/ajax-actions.php: wp_ajax_crop_image() |
Ajax handler for cropping an image. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::refresh_nonces() |
Refresh nonces for the current preview. |
wp-admin/includes/ajax-actions.php: wp_ajax_update_plugin() |
Ajax handler for updating a plugin. |
wp-admin/includes/ajax-actions.php: wp_ajax_destroy_sessions() |
Ajax handler for destroying multiple open sessions for a user. |
wp-admin/includes/class-custom-background.php: Custom_Background::ajax_background_add() |
Ajax handler for adding custom background context to an attachment. |
wp-admin/includes/ajax-actions.php: wp_ajax_parse_embed() |
Apply [embed] Ajax handlers to a string. |
wp-admin/includes/ajax-actions.php: wp_ajax_parse_media_shortcode() | |
wp-admin/includes/ajax-actions.php: wp_ajax_set_attachment_thumbnail() |
Ajax handler for setting the featured image for an attachment. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment_order() |
Ajax handler for saving the attachment order. |
wp-admin/includes/ajax-actions.php: wp_ajax_send_attachment_to_editor() |
Ajax handler for sending an attachment to the editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_send_link_to_editor() |
Ajax handler for sending a link to the editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_revision_diffs() |
Ajax handler for getting revision diffs. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_user_color_scheme() |
Ajax handler for auto-saving the selected color scheme for a user’s own profile. |
wp-admin/includes/ajax-actions.php: wp_ajax_query_themes() |
Ajax handler for getting themes from themes_api(). |
wp-admin/includes/ajax-actions.php: wp_ajax_set_post_thumbnail() |
Ajax handler for setting the featured image. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_fullscreen_save_post() |
Ajax handler for saving posts from the fullscreen editor. |
wp-admin/includes/ajax-actions.php: wp_ajax_get_attachment() |
Ajax handler for getting an attachment. |
wp-admin/includes/ajax-actions.php: wp_ajax_query_attachments() |
Ajax handler for querying attachments. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment() |
Ajax handler for updating attachment attributes. |
wp-admin/includes/ajax-actions.php: wp_ajax_save_attachment_compat() |
Ajax handler for saving backward compatible attachment attributes. |
wp-admin/includes/ajax-actions.php: wp_ajax_find_posts() |
Ajax handler for querying posts for the Find Posts modal. |
wp-admin/includes/class-custom-image-header.php: Custom_Image_Header::ajax_header_crop() |
Gets attachment uploaded by Media Manager, crops it, then saves it as a new object. Returns JSON-encoded object details. |
wp-admin/includes/class-custom-image-header.php: Custom_Image_Header::ajax_header_add() |
Given an attachment ID for a header image, updates its “last used” timestamp to now. |
wp-admin/includes/class-custom-image-header.php: Custom_Image_Header::ajax_header_remove() |
Given an attachment ID for a header image, unsets it as a user-uploaded header image for the current theme. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save() |
Handle customize_save WP Ajax request to save/update a changeset. |
wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::wp_ajax_update_widget() |
Updates widget settings asynchronously. |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Example
save_field.php: