_monsterinsights_deprecated_function

Marks a function as deprecated and informs when it has been used.

Description

_monsterinsights_deprecated_function( (string) $function, (string) $version, (null) $backtrace = null ); 

There is a hook monsterinsights_deprecated_function_run that will be called that can be used to get the backtrace up to what file and function called the deprecated function. Based on the one in EDD core.

The current behavior is to trigger a user error if WP_DEBUG is true.

This function is to be used in every function that is deprecated.

Parameters (3)

0. $function (string)
The function that was called
1. $version (string)
The version of WordPress that deprecated the function
2. $backtrace — Optional. (null) => null
Contains stack backtrace of deprecated function

Usage

  1. if ( !function_exists( '_monsterinsights_deprecated_function' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/deprecated.php'; 
  3.  
  4. // The function that was called 
  5. $function = ''; 
  6.  
  7. // The version of WordPress that deprecated the function 
  8. $version = ''; 
  9.  
  10. // Optional. Contains stack backtrace of deprecated function 
  11. $backtrace = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _monsterinsights_deprecated_function($function, $version, $backtrace); 
  15.  

Defined (1)

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

/includes/deprecated.php  
  1. function _monsterinsights_deprecated_function( $function, $version, $backtrace = null ) { 
  2.  
  3. /** 
  4. * Deprecated Function Action. 
  5. * Allow plugin run an action on the use of a  
  6. * deprecated function. This could be used to 
  7. * feed into anerrorlogging program or file. 
  8. * @since 6.0.0 
  9. *  
  10. * @param string $function The function that was called. 
  11. * @param string $version The version of WordPress that deprecated the function. 
  12. * @param array $backtrace Optional. Contains stack backtrace of deprecated function. 
  13. */  
  14. do_action( 'deprecated_function_run', $function, $version, $backtrace ); 
  15.  
  16. /** 
  17. * Filters whether to trigger anerrorfor deprecated functions. 
  18. * @since 6.0.0 
  19. * @param bool $trigger Whether to trigger theerrorfor deprecated functions. Default true. 
  20. */ 
  21. if ( ( WP_DEBUG && apply_filters( 'deprecated_function_trigger_error', true ) ) || monsterinsights_is_debug_mode() ) { 
  22. trigger_error( sprintf( esc_html__( '%1$s is %3$sdeprecated%4$s since MonsterInsights version %2$s.', 'google-analytics-for-wordpress' ), $function, $version, '<strong>', '</strong>' ) ); 
  23. trigger_error( print_r( $backtrace, 1 ) );// Limited to previous 1028 characters, but since we only need to move back 1 in stack that should be fine. 
  24. // Alternatively we could dump this to a file.