1: <?php
2:
3: class RESTian_Base {
4:
5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22:
23: function add_filter( $filter_name, $callable_object_or_priority = null, $priority = null ) {
24: list( $callable, $priority ) = $this->_parse_callable_args( $filter_name, $callable_object_or_priority, $priority );
25: if ( defined( 'WP_CONTENT_DIR') ) {
26: $filter_name = spl_object_hash( $this ) . "->{$filter_name}()";
27: add_filter( $filter_name, $callable, $priority, 99 );
28: } else {
29: RESTian::add_filter( $filter_name, $callable, $priority );
30: }
31: return true;
32: }
33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
51: function add_action( $action_name, $callable_object_or_priority = null, $priority = null ) {
52: list( $callable, $priority ) = $this->_parse_callable_args( $action_name, $callable_object_or_priority, $priority );
53: if ( defined( 'WP_CONTENT_DIR') ) {
54: add_action( $this->_hash_hook_name( $action_name ), $callable, $priority, 99 );
55: } else {
56: RESTian::add_action( $action_name, $callable, $priority );
57: }
58: }
59:
60: 61: 62: 63: 64: 65:
66: function apply_filters( $filter_name, $value ) {
67: if ( defined( 'WP_CONTENT_DIR') ) {
68: $args = func_get_args();
69: $args[0] = $this->_hash_hook_name( $filter_name );
70: $value = call_user_func_array( 'apply_filters', $args );
71: } else {
72: $filters = RESTian::get_filters( $filter_name );
73: if ( count( $filters ) ) {
74: $args = func_get_args();
75: array_shift( $args );
76: foreach( $filters as $function ) {
77: 78: 79:
80: ksort( $function );
81: foreach( $function as $priority ) {
82: foreach( $priority as $callable ) {
83: $value = call_user_func_array( $callable, $args );
84: }
85: }
86: }
87: }
88: }
89: return $value;
90: }
91:
92: 93: 94: 95: 96:
97: function do_action( $action_name ) {
98: if ( defined( 'WP_CONTENT_DIR') ) {
99: $args = func_get_args();
100: $args[0] = $this->_hash_hook_name( $action_name );
101: call_user_func_array( 'do_action', $args );
102: } else {
103: call_user_func_array( array( $this, 'apply_filters' ), func_get_args() );
104: }
105: }
106:
107: 108: 109: 110: 111: 112: 113: 114: 115:
116: private function _parse_callable_args( $filter_name, $callable_object_or_priority = null, $priority = null ) {
117: if ( ! $callable_object_or_priority ) {
118: $callable = array( $this, "_{$filter_name}" );
119: } else if ( is_numeric( $callable_object_or_priority ) ) {
120: $priority = $callable_object_or_priority;
121: } else if ( is_string( $callable_object_or_priority ) ) {
122: $callable = array( $this, $callable_object_or_priority );
123: } else if ( is_array( $callable_object_or_priority ) ) {
124: $callable = $callable_object_or_priority;
125: } else if ( is_object( $callable_object_or_priority ) ) {
126: $callable = array( $callable_object_or_priority, "_{$filter_name}" );
127: }
128: if ( is_null( $priority ) ) {
129: $priority = 10;
130: }
131: return array( $callable, $priority );
132: }
133:
134: private function _hash_hook_name( $hook_name ) {
135: return spl_object_hash( $this ) . "->{$hook_name}()";
136: }
137:
138: }
139: