PluginProbe
ShiftController Employee Shift Scheduling / 4.9.97
ShiftController Employee Shift Scheduling v4.9.97
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / hc3 / _wordpress / hooks.php

hooks.php in ShiftController Employee Shift Scheduling 4.9.97, at hc3/_wordpress/hooks.php

96 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 interface HC3_Wordpress_IHooks extends HC3_IHooks
3 {
4 public function getPrefix();
5 }
6
7 class HC3_Hooks implements HC3_Wordpress_IHooks
8 {
9 protected $pluginName = 'hitcode';
10 protected $pluginPrefix = 'hc3';
11
12 protected $_notInstantiated = array();
13
14 public $dic;
15
16 public function __construct( HC3_Dic $dic, $pluginName, $pluginPrefix )
17 {
18 $this->dic = $dic;
19 $this->pluginName = $pluginName;
20 $this->pluginPrefix = $pluginPrefix;
21 }
22
23 public function getPrefix()
24 {
25 return $this->pluginPrefix;
26 }
27
28 public function wrap( $obj )
29 {
30 $return = new HC3_HooksWrapper( $obj, $this );
31 return $return;
32 }
33
34 public function apply( $hook, $thing, $args = NULL )
35 {
36 $hook = strtolower( $hook );
37 if( isset($this->_notInstantiated[$hook]) ){
38 foreach( $this->_notInstantiated[$hook] as $callable ){
39 $callable[0] = $this->dic->make( $callable[0] );
40 $this->add( $hook, $callable );
41 }
42 unset( $this->_notInstantiated[$hook] );
43 }
44
45 $wpHookName = $this->_prepareHookName( $hook );
46
47 // echo "FILTER: '$wpHookName'<br>";
48
49 $thing = apply_filters( $wpHookName, $thing, $args );
50 return $thing;
51 }
52
53 public function exists( $hook )
54 {
55 $return = FALSE;
56
57 $wpHookName = $this->_prepareHookName( $hook );
58
59 if( has_filter($wpHookName) ){
60 $return = TRUE;
61 }
62 else {
63 $hook = strtolower( $hook );
64 if( array_key_exists($hook, $this->_notInstantiated) ){
65 $return = TRUE;
66 }
67 }
68
69 return $return;
70 }
71
72 public function add( $hook, $callable )
73 {
74 $wpHookName = $this->_prepareHookName( $hook );
75
76 if( is_array($callable) && (! is_object($callable[0])) ){
77 if( ! isset($this->_notInstantiated[$hook]) ){
78 $this->_notInstantiated[$hook] = array();
79 }
80 $this->_notInstantiated[$hook][] = $callable;
81 }
82 else {
83 add_filter( $wpHookName, $callable, 10, 3 );
84 }
85
86 return $this;
87 }
88
89 protected function _prepareHookName( $hook )
90 {
91 $hook = strtolower( $hook );
92 // $hook = str_replace( '_', '/', $hook );
93 $wpHookName = $this->pluginName . '/' . $hook;
94 return $wpHookName;
95 }
96 }