WC_Deprecated_Hooks

WC_Deprecated_Hooks class maps old actions and filters to new ones.

Defined (1)

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

/includes/abstracts/abstract-wc-deprecated-hooks.php  
  1. abstract class WC_Deprecated_Hooks { 
  2.  
  3. /** 
  4. * Array of deprecated hooks we need to handle. 
  5. * @var array 
  6. */ 
  7. protected $deprecated_hooks = array(); 
  8.  
  9. /** 
  10. * Constructor. 
  11. */ 
  12. public function __construct() { 
  13. $new_hooks = array_keys( $this->deprecated_hooks ); 
  14. array_walk( $new_hooks, array( $this, 'hook_in' ) ); 
  15.  
  16. /** 
  17. * Hook into the new hook so we can handle deprecated hooks once fired. 
  18. * @param string $hook_name 
  19. */ 
  20. abstract function hook_in( $hook_name ); 
  21.  
  22. /** 
  23. * Get old hooks to map to new hook. 
  24. * @param string $new_hook 
  25. * @return array 
  26. */ 
  27. public function get_old_hooks( $new_hook ) { 
  28. $old_hooks = isset( $this->deprecated_hooks[ $new_hook ] ) ? $this->deprecated_hooks[ $new_hook ] : array(); 
  29. $old_hooks = is_array( $old_hooks ) ? $old_hooks : array( $old_hooks ); 
  30.  
  31. return $old_hooks; 
  32.  
  33. /** 
  34. * If the hook is Deprecated, call the old hooks here. 
  35. */ 
  36. public function maybe_handle_deprecated_hook() { 
  37. $new_hook = current_filter(); 
  38. $old_hooks = $this->get_old_hooks( $new_hook ); 
  39. $new_callback_args = func_get_args(); 
  40. $return_value = $new_callback_args[0]; 
  41.  
  42. foreach ( $old_hooks as $old_hook ) { 
  43. $return_value = $this->handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value ); 
  44.  
  45. return $return_value; 
  46.  
  47. /** 
  48. * If the old hook is in-use, trigger it. 
  49. * @param string $new_hook 
  50. * @param string $old_hook 
  51. * @param array $new_callback_args 
  52. * @param mixed $return_value 
  53. * @return mixed 
  54. */ 
  55. abstract function handle_deprecated_hook( $new_hook, $old_hook, $new_callback_args, $return_value ); 
  56.  
  57. /** 
  58. * Display a deprecated notice for old hooks. 
  59. */ 
  60. protected function display_notice( $old_hook, $new_hook ) { 
  61. wc_deprecated_function( sprintf( 'The "%s" hook uses out of date data structures and', esc_html( $old_hook ) ), WC_VERSION, esc_html( $new_hook ) ); 
  62.  
  63. /** 
  64. * Fire off a legacy hook with it's args. 
  65. * @param string $old_hook 
  66. * @param array $new_callback_args 
  67. * @return mixed 
  68. */ 
  69. abstract protected function trigger_hook( $old_hook, $new_callback_args );