wp_json_encode( mixed $data, int $options, int $depth = 512 ): string|false
Encodes a variable into JSON, with some sanity checks.
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:
512
Return
string|false The JSON encoded string, or false if it cannot be encoded.
Source
File: wp-includes/functions.php
.
View all references
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 );
}
Related
Used By
Used By | Description |
---|---|
wp_remove_surrounding_empty_script_tags() wp-includes/script-loader.php |
Removes leading and trailing _empty_ script tags. |
_wp_filter_post_meta_footnotes() wp-includes/blocks.php |
Strips all HTML from the content of footnotes, and sanitizes the ID. |
wp_attach_theme_preview_middleware() wp-includes/theme-previews.php |
Adds a middleware to |
wp_block_theme_activate_nonce() wp-includes/theme-previews.php |
Set a JavaScript constant for theme activation. |
WP_Style_Engine_Processor::combine_rules_selectors() wp-includes/style-engine/class-wp-style-engine-processor.php |
Combines selectors from the rules store when they have the same styles. |
WP_REST_Global_Styles_Controller::prepare_item_for_database() wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php |
Prepares a single global styles config for update. |
wp_generate_block_templates_export_file() wp-includes/block-template-utils.php |
Creates an export of the current templates and template parts from the site editor at the specified path in a ZIP file. |
wp_filter_global_styles_post() wp-includes/kses.php |
Sanitizes global styles user content removing unsafe rules. |
block_editor_rest_api_preload() wp-includes/block-editor.php |
Preloads common data used with the block editor by specifying an array of REST API paths that will be preloaded for a given block editor context. |
rest_validate_enum() wp-includes/rest-api.php |
Validates that the given value is a member of the JSON Schema “enum”. |
WP_Application_Passwords_List_Table::print_js_template_row() wp-admin/includes/class-wp-application-passwords-list-table.php |
Prints the JavaScript template for the new row item. |
serialize_block_attributes() wp-includes/blocks.php |
Given an array of attributes, returns a string in the serialized attributes format prepared for post content. |
WP_Site_Health::wp_cron_scheduled_check() wp-admin/includes/class-wp-site-health.php |
Runs the scheduled event to check and update the latest site health status for the website. |
enqueue_editor_block_styles_assets() wp-includes/script-loader.php |
Function responsible for enqueuing the assets required for block styles functionality on the editor. |
_jsonp_wp_die_handler() wp-includes/functions.php |
Kills WordPress execution and displays JSONP response with an error message. |
wp_ajax_health_check_site_status_result() wp-admin/includes/ajax-actions.php |
Handles site health check to update the result status via AJAX. |
_json_wp_die_handler() wp-includes/functions.php |
Kills WordPress execution and displays JSON response with an error message. |
wp_default_packages_vendor() wp-includes/script-loader.php |
Registers all the WordPress vendor scripts that are in the standardized |
wp_default_packages_inline_scripts() wp-includes/script-loader.php |
Adds inline scripts required for the WordPress JavaScript packages. |
wp_tinymce_inline_scripts() wp-includes/script-loader.php |
Adds inline scripts required for the TinyMCE in the block editor. |
the_block_editor_meta_boxes() wp-admin/includes/post.php |
Renders the meta boxes forms. |
wp_create_user_request() wp-includes/user.php |
Creates and logs a user request to perform a specific action. |
WP_Privacy_Policy_Content::notice() wp-admin/includes/class-wp-privacy-policy-content.php |
Adds a notice with a link to the guide when editing the privacy policy page. |
wp_privacy_generate_personal_data_export_file() wp-admin/includes/privacy-tools.php |
Generate the personal data export file. |
wp_start_scraping_edited_file_errors() wp-includes/load.php |
Starts scraping edited file errors. |
wp_finalize_scraping_edited_file_errors() wp-includes/load.php |
Finalizes scraping for edited file errors. |
wp_enqueue_code_editor() wp-includes/general-template.php |
Enqueues assets needed by the code editor for the given settings. |
WP_Widget_Media_Gallery::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-media-gallery.php |
Loads the required media files for the media manager and scripts for media widgets. |
WP_Widget_Custom_HTML::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-custom-html.php |
Loads the required scripts and styles for the widget control. |
WP_Customize_Date_Time_Control::content_template() wp-includes/customize/class-wp-customize-date-time-control.php |
Renders a JS template for the content of date time control. |
_WP_Editors::default_settings() wp-includes/class-wp-editor.php |
Returns the default TinyMCE settings. |
WP_Widget_Text::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-text.php |
Loads the required scripts and styles for the widget control. |
WP_Widget_Media_Audio::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-media-audio.php |
Loads the required media files for the media manager and scripts for media widgets. |
WP_Widget_Media_Video::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-media-video.php |
Loads the required scripts and styles for the widget control. |
WP_Widget_Media_Image::enqueue_admin_scripts() wp-includes/widgets/class-wp-widget-media-image.php |
Loads the required media files for the media manager and scripts for media widgets. |
WP_Community_Events::maybe_log_events_response() wp-admin/includes/class-wp-community-events.php |
Logs responses to Events API requests. |
WP_Customize_Manager::save_changeset_post() wp-includes/class-wp-customize-manager.php |
Saves the post for the loaded changeset. |
wp_localize_jquery_ui_datepicker() wp-includes/script-loader.php |
Localizes the jQuery UI datepicker. |
WP_Customize_Widgets::filter_dynamic_sidebar_params() wp-includes/class-wp-customize-widgets.php |
Inject selective refresh data attributes into widget container elements. |
WP_Customize_Selective_Refresh::export_preview_data() wp-includes/customize/class-wp-customize-selective-refresh.php |
Exports data in preview after it has finished rendering so that partials can be added at runtime. |
WP_Customize_Manager::customize_pane_settings() wp-includes/class-wp-customize-manager.php |
Prints JavaScript settings for parent window. |
WP_REST_Server::serve_request() wp-includes/rest-api/class-wp-rest-server.php |
Handles serving a REST API request. |
WP_REST_Server::json_error() wp-includes/rest-api/class-wp-rest-server.php |
Retrieves an appropriate error representation in JSON. |
WP_Customize_Nav_Menus::export_preview_data() wp-includes/class-wp-customize-nav-menus.php |
Exports data from PHP to JS. |
WP_Customize_Nav_Menus::filter_wp_nav_menu() wp-includes/class-wp-customize-nav-menus.php |
Prepares wp_nav_menu() calls for partial refresh. |
WP_Customize_Nav_Menus::enqueue_scripts() wp-includes/class-wp-customize-nav-menus.php |
Enqueues scripts and styles for Customizer pane. |
WP_List_Table::ajax_response() wp-admin/includes/class-wp-list-table.php |
Handles an incoming ajax request (called from admin-ajax.php) |
WP_List_Table::_js_vars() wp-admin/includes/class-wp-list-table.php |
Sends required variables to JavaScript land. |
admin_color_scheme_picker() wp-admin/includes/misc.php |
Displays the default admin color scheme picker (Used in user-edit.php). |
wp_color_scheme_settings() wp-admin/includes/misc.php | |
WP_Internal_Pointers::print_js() wp-admin/includes/class-wp-internal-pointers.php |
Prints the pointer JavaScript data. |
compression_test() wp-admin/includes/template.php |
Tests support for compressing JavaScript from PHP. |
WP_Themes_List_Table::_js_vars() wp-admin/includes/class-wp-themes-list-table.php |
Send required variables to JavaScript land |
media_upload_form() wp-admin/includes/media.php |
Outputs the legacy media upload form. |
media_send_to_editor() wp-admin/includes/media.php |
Adds image HTML to editor. |
wp_ajax_upload_attachment() wp-admin/includes/ajax-actions.php |
Handles uploading attachments via AJAX. |
wp_ajax_menu_get_metabox() wp-admin/includes/ajax-actions.php |
Handles for retrieving menu meta boxes via AJAX. |
wp_ajax_wp_link_ajax() wp-admin/includes/ajax-actions.php |
Handles internal linking via AJAX. |
wp_ajax_autocomplete_user() wp-admin/includes/ajax-actions.php |
Handles user autocomplete via AJAX. |
_wp_ajax_menu_quick_search() wp-admin/includes/nav-menu.php |
Prints the appropriate response to a menu quick search. |
options_general_add_js() wp-admin/includes/options.php |
Display JavaScript on the page. |
WP_Customize_Manager::customize_preview_settings() wp-includes/class-wp-customize-manager.php |
Prints JavaScript settings for preview frame. |
WP_Customize_Manager::wp_die() wp-includes/class-wp-customize-manager.php |
Custom wp_die wrapper. Returns either the standard message for UI or the Ajax message. |
_wp_customize_loader_settings() wp-includes/theme.php |
Adds settings for the customize-loader script. |
wp_send_json() wp-includes/functions.php |
Sends a JSON response back to an Ajax request. |
wp_version_check() wp-includes/update.php |
Checks WordPress version against the newest version. |
wp_update_plugins() wp-includes/update.php |
Checks for available updates to plugins based on the latest versions hosted on WordPress.org. |
wp_update_themes() wp-includes/update.php |
Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
wp_plupload_default_settings() wp-includes/media.php |
Prints default Plupload arguments. |
wp_playlist_shortcode() wp-includes/media.php |
Builds the Playlist shortcode output. |
WP_Scripts::localize() wp-includes/class-wp-scripts.php |
Localizes a script, only if the script has already been added. |
WP_Customize_Widgets::export_preview_data() wp-includes/class-wp-customize-widgets.php |
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_Customize_Widgets::enqueue_scripts() wp-includes/class-wp-customize-widgets.php |
Enqueues scripts and styles for Customizer panel and export data to JavaScript. |
wp_default_scripts() wp-includes/script-loader.php |
Registers all WordPress scripts. |
_WP_Editors::editor_settings() wp-includes/class-wp-editor.php | |
_WP_Editors::wp_mce_translation() wp-includes/class-wp-editor.php |
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. |
Changelog
Version | Description |
---|---|
5.3.0 | No longer handles support for PHP < 5.6. |
4.1.0 | Introduced. |
User Contributed Notes
-
Skip to note 1 content You must log in to vote on the helpfulness of this noteVote results for this note: -4You must log in to vote on the helpfulness of this noteContributed by Kamal Hosen —