On this page
_doing_it_wrong( string $function, string $message, string $version )
Marks something as being incorrectly called.
Description
There is a hook ‘doing_it_wrong_run’ that will be called that can be used to get the backtrace up to what file and function called the deprecated function.
The current behavior is to trigger a user error if WP_DEBUG is true.
Parameters
$functionstring Required-
The function that was called.
$messagestring Required-
A message explaining what has been done incorrectly.
$versionstring Required-
The version of WordPress where the message was added.
Source
File: wp-includes/functions.php. View all references
function _doing_it_wrong( $function, $message, $version ) {
/**
* Fires when the given function is being used incorrectly.
*
* @since 3.1.0
*
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
do_action( 'doing_it_wrong_run', $function, $message, $version );
/**
* Filters whether to trigger an error for _doing_it_wrong() calls.
*
* @since 3.1.0
* @since 5.1.0 Added the $function, $message and $version parameters.
*
* @param bool $trigger Whether to trigger the error for _doing_it_wrong() calls. Default true.
* @param string $function The function that was called.
* @param string $message A message explaining what has been done incorrectly.
* @param string $version The version of WordPress where the message was added.
*/
if ( WP_DEBUG && apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) ) {
if ( function_exists( '__' ) ) {
if ( $version ) {
/* translators: %s: Version number. */
$version = sprintf( __( '(This message was added in version %s.)' ), $version );
}
$message .= ' ' . sprintf(
/* translators: %s: Documentation URL. */
__( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),
__( 'https://wordpress.org/support/article/debugging-in-wordpress/' )
);
trigger_error(
sprintf(
/* translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: WordPress version number. */
__( 'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s' ),
$function,
$message,
$version
),
E_USER_NOTICE
);
} else {
if ( $version ) {
$version = sprintf( '(This message was added in version %s.)', $version );
}
$message .= sprintf(
' Please see <a href="%s">Debugging in WordPress</a> for more information.',
'https://wordpress.org/support/article/debugging-in-wordpress/'
);
trigger_error(
sprintf(
'Function %1$s was called <strong>incorrectly</strong>. %2$s %3$s',
$function,
$message,
$version
),
E_USER_NOTICE
);
}
}
}
Hooks
- do_action( 'doing_it_wrong_run',
string $function ,string $message ,string $version ) -
Fires when the given function is being used incorrectly.
- apply_filters( 'doing_it_wrong_trigger_error',
bool $trigger ,string $function ,string $message ,string $version ) -
Filters whether to trigger an error for _doing_it_wrong() calls.
Related
Uses
| Uses | Description |
|---|---|
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| WP_Block_Type::__set() wp-includes/class-wp-block-type.php | Proxies setting values for deprecated properties for script and style handles for backward compatibility. |
| wp_cache_flush_group() wp-includes/cache-compat.php | Removes all cache items in a group, if the object cache implementation supports it. |
| WP_Style_Engine_Processor::add_store() wp-includes/style-engine/class-wp-style-engine-processor.php | Adds a store to the processor. |
| WP_Object_Cache::is_valid_key() wp-includes/class-wp-object-cache.php | Serves as a utility function to determine whether a key is valid. |
| WP_List_Table::get_views_links() wp-admin/includes/class-wp-list-table.php | Generates views links. |
| _register_theme_block_patterns() wp-includes/block-patterns.php | Register any patterns that the active theme may provide under its |
| wp_maybe_update_user_counts() wp-includes/user.php | Updates the total count of users on the site if live user counting is enabled. |
| wp_update_user_counts() wp-includes/user.php | Updates the total count of users on the site. |
| wp_is_large_user_count() wp-includes/user.php | Determines whether the site has a large number of users. |
| wp_check_widget_editor_deps() wp-includes/widgets.php | Displays a _doing_it_wrong() message for conflicting widget editor scripts. |
| WP_Theme_JSON::get_property_value() wp-includes/class-wp-theme-json.php | Returns the style property for the given path. |
| wp_migrate_old_typography_shape() wp-includes/blocks.php | Converts typography keys declared under |
| WP_Block_Patterns_Registry::unregister() wp-includes/class-wp-block-patterns-registry.php | Unregisters a block pattern. |
| WP_Block_Patterns_Registry::register() wp-includes/class-wp-block-patterns-registry.php | Registers a block pattern. |
| WP_Block_Pattern_Categories_Registry::register() wp-includes/class-wp-block-pattern-categories-registry.php | Registers a pattern category. |
| WP_Block_Pattern_Categories_Registry::unregister() wp-includes/class-wp-block-pattern-categories-registry.php | Unregisters a pattern category. |
| rest_handle_multi_type_schema() wp-includes/rest-api.php | Handles getting the best type for a multi-type schema. |
| rest_stabilize_value() wp-includes/rest-api.php | Stabilizes a value following JSON Schema semantics. |
| register_block_script_handle() wp-includes/blocks.php | Finds a script handle for the selected block metadata field. It detects when a path to file was provided and finds a corresponding asset file with details necessary to register the script under automatically generated handle name. It returns unprocessed script handle otherwise. |
| WP_Sitemaps_Renderer::get_sitemap_index_xml() wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Gets XML for a sitemap index. |
| WP_Sitemaps_Renderer::get_sitemap_xml() wp-includes/sitemaps/class-wp-sitemaps-renderer.php | Gets XML for a sitemap. |
| is_favicon() wp-includes/query.php | Is the query for the favicon.ico file? |
| WP_Block_Styles_Registry::register() wp-includes/class-wp-block-styles-registry.php | Registers a block style for the given block type. |
| WP_Block_Styles_Registry::unregister() wp-includes/class-wp-block-styles-registry.php | Unregisters a block style of the given block type. |
| is_privacy_policy() wp-includes/query.php | Determines whether the query is for the Privacy Policy page. |
| wp_ajax_health_check_get_sizes() wp-admin/includes/ajax-actions.php | Ajax handler for site health check to get directories and database sizes. |
| wp_ajax_health_check_dotorg_communication() wp-admin/includes/ajax-actions.php | Ajax handler for site health checks on server communication. |
| wp_ajax_health_check_background_updates() wp-admin/includes/ajax-actions.php | Ajax handler for site health checks on background updates. |
| wp_ajax_health_check_loopback_requests() wp-admin/includes/ajax-actions.php | Ajax handler for site health checks on loopback requests. |
| wp_check_site_meta_support_prefilter() wp-includes/ms-site.php | Aborts calls to site meta if it is not supported. |
| WP_REST_Search_Controller::__construct() wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php | Constructor. |
| WP_Block_Type_Registry::register() wp-includes/class-wp-block-type-registry.php | Registers a block type. |
| WP_Block_Type_Registry::unregister() wp-includes/class-wp-block-type-registry.php | Unregisters a block type. |
| wp_user_personal_data_exporter() wp-includes/user.php | Finds and exports personal data associated with an email address from the user and user_meta table. |
| wp_privacy_generate_personal_data_export_file() wp-admin/includes/privacy-tools.php | Generate the personal data export file. |
| wp_add_privacy_policy_content() wp-admin/includes/plugin.php | Declares a helper function for adding content to the Privacy Policy Guide. |
| wp_is_uuid() wp-includes/functions.php | Validates that a UUID is valid. |
| rest_sanitize_value_from_schema() wp-includes/rest-api.php | Sanitize a value based on a schema. |
| rest_validate_value_from_schema() wp-includes/rest-api.php | Validate a value based on a schema. |
| WP_REST_Posts_Controller::get_item_schema() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Retrieves the post’s schema, conforming to JSON Schema. |
| WP_REST_Controller::register_routes() wp-includes/rest-api/endpoints/class-wp-rest-controller.php | Registers the routes for the objects of the controller. |
| wp_add_inline_script() wp-includes/functions.wp-scripts.php | Adds extra code to a registered script. |
| WP_Customize_Partial::render() wp-includes/customize/class-wp-customize-partial.php | Renders the template partial involving the associated settings. |
| register_rest_route() wp-includes/rest-api.php | Registers a REST API route. |
| is_embed() wp-includes/query.php | Is the query for an embedded post? |
| WP_Date_Query::validate_date_values() wp-includes/class-wp-date-query.php | Validates the given date_query values and triggers errors if something is not valid. |
| WP_Customize_Manager::remove_panel() wp-includes/class-wp-customize-manager.php | Removes a customize panel. |
| register_setting() wp-includes/option.php | Registers a setting and its data. |
| add_menu_page() wp-admin/includes/plugin.php | Adds a top-level menu page. |
| add_submenu_page() wp-admin/includes/plugin.php | Adds a submenu page. |
| convert_to_screen() wp-admin/includes/template.php | Converts a screen string to a screen object. |
| map_meta_cap() wp-includes/capabilities.php | Maps a capability to the primitive capabilities required of the given user to satisfy the capability being checked. |
| add_theme_support() wp-includes/theme.php | Registers theme support for a given feature. |
| check_admin_referer() wp-includes/pluggable.php | Ensures intent by verifying that a user was referred from another admin page with the correct security nonce. |
| check_ajax_referer() wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. |
| is_preview() wp-includes/query.php | Determines whether the query is for a post or page preview. |
| is_robots() wp-includes/query.php | Is the query for the robots.txt file? |
| is_search() wp-includes/query.php | Determines whether the query is for a search. |
| is_single() wp-includes/query.php | Determines whether the query is for an existing single post. |
| is_singular() wp-includes/query.php | Determines whether the query is for an existing single post of any post type (post, attachment, page, custom post types). |
| is_time() wp-includes/query.php | Determines whether the query is for a specific time. |
| is_trackback() wp-includes/query.php | Determines whether the query is for a trackback endpoint call. |
| is_year() wp-includes/query.php | Determines whether the query is for an existing year archive. |
| is_404() wp-includes/query.php | Determines whether the query has resulted in a 404 (returns no results). |
| is_main_query() wp-includes/query.php | Determines whether the query is the main query. |
| is_attachment() wp-includes/query.php | Determines whether the query is for an existing attachment page. |
| is_author() wp-includes/query.php | Determines whether the query is for an existing author archive page. |
| is_category() wp-includes/query.php | Determines whether the query is for an existing category archive page. |
| is_tag() wp-includes/query.php | Determines whether the query is for an existing tag archive page. |
| is_date() wp-includes/query.php | Determines whether the query is for an existing date archive. |
| is_day() wp-includes/query.php | Determines whether the query is for an existing day archive. |
| is_feed() wp-includes/query.php | Determines whether the query is for a feed. |
| is_comment_feed() wp-includes/query.php | Is the query for a comments feed? |
| is_month() wp-includes/query.php | Determines whether the query is for an existing month archive. |
| is_tax() wp-includes/query.php | Determines whether the query is for an existing custom taxonomy archive page. |
| is_front_page() wp-includes/query.php | Determines whether the query is for the front page of the site. |
| is_home() wp-includes/query.php | Determines whether the query is for the blog homepage. |
| is_page() wp-includes/query.php | Determines whether the query is for an existing single page. |
| is_paged() wp-includes/query.php | Determines whether the query is for a paged result and not for the first page. |
| is_archive() wp-includes/query.php | Determines whether the query is for an existing archive page. |
| is_post_type_archive() wp-includes/query.php | Determines whether the query is for an existing post type archive page. |
| wp_deregister_script() wp-includes/functions.wp-scripts.php | Remove a registered script. |
| wp_send_json() wp-includes/functions.php | Sends a JSON response back to an Ajax request. |
| register_taxonomy() wp-includes/taxonomy.php | Creates or modifies a taxonomy object. |
| WP_Admin_Bar::add_node() wp-includes/class-wp-admin-bar.php | Adds a node to the menu. |
| wp_add_inline_style() wp-includes/functions.wp-styles.php | Add extra CSS styles to a registered stylesheet. |
| do_shortcode_tag() wp-includes/shortcodes.php | Regular Expression callable for do_shortcode() for calling shortcode hook. |
| add_shortcode() wp-includes/shortcodes.php | Adds a new shortcode. |
| register_uninstall_hook() wp-includes/plugin.php | Sets the uninstallation hook for a plugin. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| register_post_type() wp-includes/post.php | Registers a post type. |
| get_user_count() wp-includes/user.php | Returns the number of active users in your installation. |
| WP_Scripts::localize() wp-includes/class-wp-scripts.php | Localizes a script, only if the script has already been added. |
| register_nav_menus() wp-includes/nav-menu.php | Registers navigation menu locations for a theme. |
| wpdb::_real_escape() wp-includes/class-wpdb.php | Real escape, using mysqli_real_escape_string() or mysql_real_escape_string(). |
| wpdb::prepare() wp-includes/class-wpdb.php | Prepares a SQL query for safe execution. |
| the_widget() wp-includes/widgets.php | Output an arbitrary widget as a template tag. |
| register_sidebar() wp-includes/widgets.php | Builds the definition for a single sidebar and returns the ID. |
| register_meta() wp-includes/meta.php | Registers a meta key. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/_doing_it_wrong