wp_json_encode( mixed $data, int $options, int $depth = 512 )
Encode a variable into JSON, with some sanity checks.
Description #Description
Parameters #Parameters
- $data
-
(mixed) (Required) Variable (usually an array or object) to encode as JSON.
- $options
-
(int) (Optional) Options to be passed to json_encode(). Default 0.
- $depth
-
(int) (Optional) Maximum depth to walk through $data. Must be greater than 0.
Default value: 512
Return #Return
(string|false) The JSON encoded string, or false if it cannot be encoded.
Source #Source
File: wp-includes/functions.php
function wp_json_encode( $data, $options = 0, $depth = 512 ) { $json = json_encode( $data, $options, $depth ); // If json_encode() was successful, no need to do more sanity checking. if ( false !== $json ) { return $json; } try { $data = _wp_json_sanity_check( $data, $depth ); } catch ( Exception $e ) { return false; } return json_encode( $data, $options, $depth ); }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
5.3.0 | No longer handles support for PHP < 5.6. |
4.1.0 | Introduced. |
Related #Related
Used By #Used By
Used By | Description |
---|---|
wp-includes/script-loader.php: enqueue_editor_block_styles_assets() |
Function responsible for enqueuing the assets required for block styles functionality on the editor. |
wp-includes/functions.php: _jsonp_wp_die_handler() |
Kills WordPress execution and displays JSONP response with an error message. |
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-includes/functions.php: _json_wp_die_handler() |
Kills WordPress execution and displays JSON response with an error message. |
wp-includes/script-loader.php: wp_default_packages_vendor() |
Registers all the WordPress vendor scripts that are in the standardized |
wp-includes/script-loader.php: wp_default_packages_inline_scripts() |
Adds inline scripts required for the WordPress JavaScript packages. |
wp-includes/script-loader.php: wp_tinymce_inline_scripts() |
Adds inline scripts required for the TinyMCE in the block editor. |
wp-admin/includes/post.php: the_block_editor_meta_boxes() |
Renders the meta boxes forms. |
wp-includes/user.php: wp_create_user_request() |
Create and log a user request to perform a specific action. |
wp-admin/includes/class-wp-privacy-policy-content.php: WP_Privacy_Policy_Content::notice() |
Add a notice with a link to the guide when editing the privacy policy page. |
wp-includes/load.php: wp_start_scraping_edited_file_errors() |
Start scraping edited file errors. |
wp-includes/load.php: wp_finalize_scraping_edited_file_errors() |
Finalize scraping for edited file errors. |
wp-includes/general-template.php: wp_enqueue_code_editor() |
Enqueue assets needed by the code editor for the given settings. |
wp-includes/widgets/class-wp-widget-text.php: WP_Widget_Text::_register_one() |
Add hooks for enqueueing assets when registering all widget instances of this widget class. |
wp-includes/widgets/class-wp-widget-media-gallery.php: WP_Widget_Media_Gallery::enqueue_admin_scripts() |
Loads the required media files for the media manager and scripts for media widgets. |
wp-includes/widgets/class-wp-widget-custom-html.php: WP_Widget_Custom_HTML::_register_one() |
Add hooks for enqueueing assets when registering all widget instances of this widget class. |
wp-includes/widgets/class-wp-widget-custom-html.php: WP_Widget_Custom_HTML::enqueue_admin_scripts() |
Loads the required scripts and styles for the widget control. |
wp-includes/customize/class-wp-customize-date-time-control.php: WP_Customize_Date_Time_Control::content_template() |
Renders a JS template for the content of date time control. |
wp-includes/class-wp-editor.php: _WP_Editors::default_settings() |
Returns the default TinyMCE settings. |
wp-includes/widgets/class-wp-widget-media-audio.php: WP_Widget_Media_Audio::enqueue_admin_scripts() |
Loads the required media files for the media manager and scripts for media widgets. |
wp-includes/widgets/class-wp-widget-media-video.php: WP_Widget_Media_Video::enqueue_admin_scripts() |
Loads the required scripts and styles for the widget control. |
wp-includes/widgets/class-wp-widget-media-image.php: WP_Widget_Media_Image::enqueue_admin_scripts() |
Loads the required media files for the media manager and scripts for media widgets. |
wp-admin/includes/class-wp-community-events.php: WP_Community_Events::maybe_log_events_response() |
Logs responses to Events API requests. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post() |
Save the post for the loaded changeset. |
wp-includes/script-loader.php: wp_localize_jquery_ui_datepicker() |
Localizes the jQuery UI datepicker. |
wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::filter_dynamic_sidebar_params() |
Inject selective refresh data attributes into widget container elements. |
wp-includes/customize/class-wp-customize-selective-refresh.php: WP_Customize_Selective_Refresh::export_preview_data() |
Exports data in preview after it has finished rendering so that partials can be added at runtime. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_pane_settings() |
Print JavaScript settings for parent window. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::serve_request() |
Handles serving an API request. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::json_error() |
Retrieves an appropriate error representation in JSON. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::export_preview_data() |
Exports data from PHP to JS. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::filter_wp_nav_menu() |
Prepares wp_nav_menu() calls for partial refresh. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::enqueue_scripts() |
Enqueue scripts and styles for Customizer pane. |
wp-admin/includes/class-wp-list-table.php: WP_List_Table::ajax_response() |
Handle an incoming ajax request (called from admin-ajax.php) |
wp-admin/includes/class-wp-list-table.php: WP_List_Table::_js_vars() |
Send required variables to JavaScript land |
wp-admin/includes/misc.php: admin_color_scheme_picker() |
Display the default admin color scheme picker (Used in user-edit.php) |
wp-admin/includes/misc.php: wp_color_scheme_settings() | |
wp-admin/includes/class-wp-internal-pointers.php: WP_Internal_Pointers::print_js() |
Print the pointer JavaScript data. |
wp-admin/includes/template.php: compression_test() |
Test support for compressing JavaScript from PHP |
wp-admin/includes/class-wp-themes-list-table.php: WP_Themes_List_Table::_js_vars() |
Send required variables to JavaScript land |
wp-admin/includes/media.php: media_upload_form() |
Outputs the legacy media upload form. |
wp-admin/includes/media.php: media_send_to_editor() |
Adds image html to editor |
wp-admin/includes/ajax-actions.php: wp_ajax_upload_attachment() |
Ajax handler for uploading attachments |
wp-admin/includes/ajax-actions.php: wp_ajax_image_editor() |
Ajax handler for image editing. |
wp-admin/includes/ajax-actions.php: wp_ajax_menu_get_metabox() |
Ajax handler for retrieving menu meta boxes. |
wp-admin/includes/ajax-actions.php: wp_ajax_wp_link_ajax() |
Ajax handler for internal linking. |
wp-admin/includes/ajax-actions.php: wp_ajax_autocomplete_user() |
Ajax handler for user autocomplete. |
wp-admin/includes/nav-menu.php: _wp_ajax_menu_quick_search() |
Prints the appropriate response to a menu quick search. |
wp-admin/includes/options.php: options_general_add_js() |
Display JavaScript on the page. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_preview_settings() |
Print JavaScript settings for preview frame. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::wp_die() |
Custom wp_die wrapper. Returns either the standard message for UI or the Ajax message. |
wp-includes/theme.php: _wp_customize_loader_settings() |
Adds settings for the customize-loader script. |
wp-includes/functions.php: wp_send_json() |
Send a JSON response back to an Ajax request. |
wp-includes/update.php: wp_version_check() |
Check WordPress version against the newest version. |
wp-includes/update.php: wp_update_plugins() |
Check plugin versions against the latest versions hosted on WordPress.org. |
wp-includes/update.php: wp_update_themes() |
Check theme versions against the latest versions hosted on WordPress.org. |
wp-includes/media.php: wp_plupload_default_settings() |
Prints default Plupload arguments. |
wp-includes/media.php: wp_playlist_shortcode() |
Builds the Playlist shortcode output. |
wp-includes/class.wp-scripts.php: WP_Scripts::localize() |
Localizes a script, only if the script has already been added. |
wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::export_preview_data() |
Communicates the sidebars that appeared on the page at the very end of the page, and at the very end of the wp_footer, |
wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::enqueue_scripts() |
Enqueues scripts and styles for Customizer panel and export data to JavaScript. |
wp-includes/script-loader.php: wp_default_scripts() |
Register all WordPress scripts. |
wp-includes/class-wp-editor.php: _WP_Editors::editor_settings() | |
wp-includes/class-wp-editor.php: _WP_Editors::wp_mce_translation() |
Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(), or as JS snippet that should run after tinymce.js is loaded. |