_deprecated_constructor

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

Description

_deprecated_constructor( (string) $class, (string) $version, (string) $parent_class = '' ); 

Similar to _deprecated_function(), but with different strings. Used to remove PHP4 style constructors.

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

This function is to be used in every PHP4 style constructor method that is deprecated.

Parameters (3)

0. $class (string)
The class containing the deprecated constructor.
1. $version (string)
The version of WordPress that deprecated the function.
2. $parent_class — Optional. (string) => ''
The parent class calling the deprecated constructor. Default empty string.

Usage

  1. if ( !function_exists( '_deprecated_constructor' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // The class containing the deprecated constructor. 
  5. $class = ''; 
  6.  
  7. // The version of WordPress that deprecated the function. 
  8. $version = ''; 
  9.  
  10. // Optional. The parent class calling the deprecated constructor. 
  11. // Default empty string. 
  12. $parent_class = ''; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = _deprecated_constructor($class, $version, $parent_class); 
  16.  

Defined (1)

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

/wp-includes/functions.php  
  1. function _deprecated_constructor( $class, $version, $parent_class = '' ) { 
  2.  
  3. /** 
  4. * Fires when a deprecated constructor is called. 
  5. * @since 4.3.0 
  6. * @since 4.5.0 Added the `$parent_class` parameter. 
  7. * @param string $class The class containing the deprecated constructor. 
  8. * @param string $version The version of WordPress that deprecated the function. 
  9. * @param string $parent_class The parent class calling the deprecated constructor. 
  10. */ 
  11. do_action( 'deprecated_constructor_run', $class, $version, $parent_class ); 
  12.  
  13. /** 
  14. * Filters whether to trigger anerrorfor deprecated functions. 
  15. * `WP_DEBUG` must be true in addition to the filter evaluating to true. 
  16. * @since 4.3.0 
  17. * @param bool $trigger Whether to trigger theerrorfor deprecated functions. Default true. 
  18. */ 
  19. if ( function_exists( '__' ) ) { 
  20. if ( ! empty( $parent_class ) ) { 
  21. /** translators: 1: PHP class name, 2: PHP parent class name, 3: version number, 4: __construct() method */ 
  22. trigger_error( sprintf( __( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.' ),  
  23. $class, $parent_class, $version, '<pre>__construct()</pre>' ) ); 
  24. } else { 
  25. /** translators: 1: PHP class name, 2: version number, 3: __construct() method */ 
  26. trigger_error( sprintf( __( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ),  
  27. $class, $version, '<pre>__construct()</pre>' ) ); 
  28. } else { 
  29. if ( ! empty( $parent_class ) ) { 
  30. trigger_error( sprintf( 'The called constructor method for %1$s in %2$s is <strong>deprecated</strong> since version %3$s! Use %4$s instead.',  
  31. $class, $parent_class, $version, '<pre>__construct()</pre>' ) ); 
  32. } else { 
  33. trigger_error( sprintf( 'The called constructor method for %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.',  
  34. $class, $version, '<pre>__construct()</pre>' ) ); 
  35.