wp_json_encode( mixed $data, int $options, int $depth = 512 )
Encode a variable into JSON, with some sanity checks.
Parameters
- $data
-
(Required) Variable (usually an array or object) to encode as JSON.
- $options
-
(Optional) Options to be passed to json_encode(). Default 0.
- $depth
-
(Optional) Maximum depth to walk through $data. Must be greater than 0.
Default value: 512
Return
(string|false) The JSON encoded string, or false if it cannot be encoded.
Source
File: wp-includes/functions.php
function wp_json_encode( $data, $options = 0, $depth = 512 ) {
$args = array( $data, $options, $depth );
// Prepare the data for JSON serialization.
$args[0] = _wp_json_prepare_data( $data );
$json = @call_user_func_array( 'json_encode', $args );
// If json_encode() was successful, no need to do more sanity checking.
if ( false !== $json ) {
return $json;
}
try {
$args[0] = _wp_json_sanity_check( $data, $depth );
} catch ( Exception $e ) {
return false;
}
return call_user_func_array( 'json_encode', $args );
}
Related
Used By
Used By | Description |
---|---|
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/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/general-template.php: wp_enqueue_code_editor() |
Enqueue assets needed by the code editor for the given settings. |
wp-includes/script-loader.php: wp_default_scripts() |
Register all ClassicPress scripts. |
wp-includes/script-loader.php: wp_localize_jquery_ui_datepicker() |
Localizes the jQuery UI datepicker. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::json_error() |
Retrieves an appropriate error representation in JSON. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::serve_request() |
Handles serving an API request. |
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-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-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-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/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-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-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::filter_dynamic_sidebar_params() |
Inject selective refresh data attributes into widget container elements. |
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/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/media.php: wp_plupload_default_settings() |
Prints default Plupload arguments. |
wp-includes/media.php: wp_playlist_shortcode() |
Builds the Playlist shortcode output. |
wp-includes/user.php: wp_create_user_request() |
Create and log a user request to perform a specific action. |
wp-includes/theme.php: _wp_customize_loader_settings() |
Adds settings for the customize-loader script. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_pane_settings() |
Print JavaScript settings for parent window. |
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/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::save_changeset_post() |
Save the post for the loaded changeset. |
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::export_preview_data() |
Exports data from PHP to JS. |
wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::enqueue_scripts() |
Enqueue scripts and styles for Customizer pane. |
wp-includes/class.wp-scripts.php: WP_Scripts::localize() |
Localizes a script, only if the script has already been added. |
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/class-wp-editor.php: _WP_Editors::editor_settings() | |
wp-includes/class-wp-editor.php: _WP_Editors::default_settings() |
Returns the default TinyMCE 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. |
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/functions.php: wp_send_json() |
Send a JSON response back to an Ajax request. |
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-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/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/template.php: compression_test() |
Test support for compressing JavaScript from PHP |
wp-admin/includes/options.php: options_general_add_js() |
Display JavaScript on the page. |
wp-admin/includes/nav-menu.php: _wp_ajax_menu_quick_search() |
Prints the appropriate response to a menu quick search. |
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/class-wp-internal-pointers.php: WP_Internal_Pointers::print_js() |
Print the pointer JavaScript data. |
wp-admin/includes/class-wp-themes-list-table.php: WP_Themes_List_Table::_js_vars() |
Send required variables to JavaScript land |
Changelog
Version | Description |
---|---|
WP-4.1.0 | Introduced. |