_doing_it_wrong

Mark something as being incorrectly called.

Description

_doing_it_wrong( (string) $function, (string) $message, (string) $version ); 

There is a hook 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 (3)

0. $function (string)
The function that was called.
1. $message (string)
A message explaining what has been done incorrectly.
2. $version (string)
The version of WordPress where the message was added.

Usage

  1. if ( !function_exists( '_doing_it_wrong' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // The function that was called. 
  5. $function = ''; 
  6.  
  7. // A message explaining what has been done incorrectly. 
  8. $message = ''; 
  9.  
  10. // The version of WordPress where the message was added. 
  11. $version = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _doing_it_wrong($function, $message, $version); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function _doing_it_wrong( $function, $message, $version ) { 
  2.  
  3. /** 
  4. * Fires when the given function is being used incorrectly. 
  5. * @since 3.1.0 
  6. * @param string $function The function that was called. 
  7. * @param string $message A message explaining what has been done incorrectly. 
  8. * @param string $version The version of WordPress where the message was added. 
  9. */ 
  10. do_action( 'doing_it_wrong_run', $function, $message, $version ); 
  11.  
  12. /** 
  13. * Filters whether to trigger anerrorfor _doing_it_wrong() calls. 
  14. * @since 3.1.0 
  15. * @param bool $trigger Whether to trigger theerrorfor _doing_it_wrong() calls. Default true. 
  16. */ 
  17. if ( function_exists( '__' ) ) { 
  18. if ( is_null( $version ) ) { 
  19. $version = ''; 
  20. } else { 
  21. /** translators: %s: version number */ 
  22. $version = sprintf( __( '(This message was added in version %s.)' ), $version ); 
  23. /** translators: %s: Codex URL */ 
  24. $message .= ' ' . sprintf( __( 'Please see <a href="%s">Debugging in WordPress</a> for more information.' ),  
  25. __( 'https://codex.wordpress.org/Debugging_in_WordPress' ) 
  26. ); 
  27. /** translators: Developer debugging message. 1: PHP function name, 2: Explanatory message, 3: Version information message */ 
  28. trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s' ), $function, $message, $version ) ); 
  29. } else { 
  30. if ( is_null( $version ) ) { 
  31. $version = ''; 
  32. } else { 
  33. $version = sprintf( '(This message was added in version %s.)', $version ); 
  34. $message .= sprintf( ' Please see <a href="%s">Debugging in WordPress</a> for more information.',  
  35. 'https://codex.wordpress.org/Debugging_in_WordPress' 
  36. ); 
  37. trigger_error( sprintf( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', $function, $message, $version ) );