CMB2_Hookup_Base

Base class for hooking CMB2 into WordPress.

Defined (1)

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

/includes/CMB2_Hookup_Base.php  
  1. abstract class CMB2_Hookup_Base { 
  2.  
  3. /** 
  4. * @var CMB2 object 
  5. * @since 2.0.2 
  6. */ 
  7. protected $cmb; 
  8.  
  9. /** 
  10. * The object type we are performing the hookup for 
  11. * @var string 
  12. * @since 2.0.9 
  13. */ 
  14. protected $object_type = 'post'; 
  15.  
  16. /** 
  17. * Constructor 
  18. * @since 2.0.0 
  19. * @param CMB2 $cmb The CMB2 object to hookup 
  20. */ 
  21. public function __construct( CMB2 $cmb ) { 
  22. $this->cmb = $cmb; 
  23. $this->object_type = $this->cmb->mb_object_type(); 
  24.  
  25. abstract public function universal_hooks(); 
  26.  
  27. /** 
  28. * Ensures WordPress hook only gets fired once per object. 
  29. * @since 2.0.0 
  30. * @param string $action The name of the filter to hook the $hook callback to. 
  31. * @param callback $hook The callback to be run when the filter is applied. 
  32. * @param integer $priority Order the functions are executed 
  33. * @param int $accepted_args The number of arguments the function accepts. 
  34. */ 
  35. public function once( $action, $hook, $priority = 10, $accepted_args = 1 ) { 
  36. static $hooks_completed = array(); 
  37.  
  38. $key = md5( serialize( func_get_args() ) ); 
  39.  
  40. if ( in_array( $key, $hooks_completed ) ) { 
  41. return; 
  42.  
  43. $hooks_completed[] = $key; 
  44. add_filter( $action, $hook, $priority, $accepted_args ); 
  45.