@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function get_value() { |
26 | 26 | |
27 | - if ( wordpoints_is_network_context() ) { |
|
27 | + if (wordpoints_is_network_context()) { |
|
28 | 28 | return false; |
29 | 29 | } |
30 | 30 | |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @since 1.0.0 |
36 | 36 | */ |
37 | 37 | public function get_title() { |
38 | - return __( 'Site', 'wordpoints' ); |
|
38 | + return __('Site', 'wordpoints'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 |
@@ -65,15 +65,15 @@ discard block |
||
65 | 65 | WordPoints_Hook_Event_Args $event_args |
66 | 66 | ) { |
67 | 67 | |
68 | - if ( ! isset( $settings[ $this->slug ] ) ) { |
|
68 | + if ( ! isset($settings[$this->slug])) { |
|
69 | 69 | return $settings; |
70 | 70 | } |
71 | 71 | |
72 | 72 | $this->validator = $validator; |
73 | 73 | $this->event_args = $event_args; |
74 | 74 | |
75 | - $this->validator->push_field( $this->slug ); |
|
76 | - $settings[ $this->slug ] = $this->{"validate_{$this->slug}"}( $settings[ $this->slug ] ); |
|
75 | + $this->validator->push_field($this->slug); |
|
76 | + $settings[$this->slug] = $this->{"validate_{$this->slug}"}($settings[$this->slug]); |
|
77 | 77 | $this->validator->pop_field(); |
78 | 78 | |
79 | 79 | return $settings; |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * @since 1.0.0 |
84 | 84 | */ |
85 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
85 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
86 | 86 | |
87 | - if ( isset( $settings[ $this->slug ] ) ) { |
|
88 | - $reaction->update_meta( $this->slug, $settings[ $this->slug ] ); |
|
87 | + if (isset($settings[$this->slug])) { |
|
88 | + $reaction->update_meta($this->slug, $settings[$this->slug]); |
|
89 | 89 | } else { |
90 | - $reaction->delete_meta( $this->slug ); |
|
90 | + $reaction->delete_meta($this->slug); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return bool Whether the target should be hit by this hook firing. |
102 | 102 | */ |
103 | - abstract public function should_hit( WordPoints_Hook_Fire $fire ); |
|
103 | + abstract public function should_hit(WordPoints_Hook_Fire $fire); |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * After a reaction has hit the target. |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
111 | 111 | */ |
112 | - public function after_hit( WordPoints_Hook_Fire $fire ) {} |
|
112 | + public function after_hit(WordPoints_Hook_Fire $fire) {} |
|
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Called after a reverse action is called. |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param WordPoints_Hook_Fire $fire The reverse fire object. |
120 | 120 | */ |
121 | - public function after_reverse( WordPoints_Hook_Fire $fire ) {} |
|
121 | + public function after_reverse(WordPoints_Hook_Fire $fire) {} |
|
122 | 122 | |
123 | 123 | /** |
124 | 124 | * Get the data the scripts need for the UI. |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | |
43 | 43 | $conditions_data = array(); |
44 | 44 | |
45 | - foreach ( $this->conditions->get_all() as $data_type => $conditions ) { |
|
46 | - foreach ( $conditions as $slug => $condition ) { |
|
45 | + foreach ($this->conditions->get_all() as $data_type => $conditions) { |
|
46 | + foreach ($conditions as $slug => $condition) { |
|
47 | 47 | |
48 | - if ( ! ( $condition instanceof WordPoints_Hook_Condition ) ) { |
|
48 | + if ( ! ($condition instanceof WordPoints_Hook_Condition)) { |
|
49 | 49 | continue; |
50 | 50 | } |
51 | 51 | |
52 | - $conditions_data[ $data_type ][ $slug ] = array( |
|
52 | + $conditions_data[$data_type][$slug] = array( |
|
53 | 53 | 'slug' => $slug, |
54 | 54 | 'data_type' => $data_type, |
55 | 55 | 'title' => $condition->get_title(), |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | - return array( 'conditions' => $conditions_data ); |
|
61 | + return array('conditions' => $conditions_data); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -70,31 +70,31 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @return array The validated settings. |
72 | 72 | */ |
73 | - protected function validate_conditions( $args ) { |
|
73 | + protected function validate_conditions($args) { |
|
74 | 74 | |
75 | - if ( ! is_array( $args ) ) { |
|
75 | + if ( ! is_array($args)) { |
|
76 | 76 | |
77 | 77 | $this->validator->add_error( |
78 | - __( 'Conditions do not match expected format.', 'wordpoints' ) |
|
78 | + __('Conditions do not match expected format.', 'wordpoints') |
|
79 | 79 | ); |
80 | 80 | |
81 | 81 | return array(); |
82 | 82 | } |
83 | 83 | |
84 | - foreach ( $args as $arg_slug => $sub_args ) { |
|
84 | + foreach ($args as $arg_slug => $sub_args) { |
|
85 | 85 | |
86 | - if ( '_conditions' === $arg_slug ) { |
|
86 | + if ('_conditions' === $arg_slug) { |
|
87 | 87 | |
88 | - $this->validator->push_field( $arg_slug ); |
|
88 | + $this->validator->push_field($arg_slug); |
|
89 | 89 | |
90 | - foreach ( $sub_args as $index => $settings ) { |
|
90 | + foreach ($sub_args as $index => $settings) { |
|
91 | 91 | |
92 | - $this->validator->push_field( $index ); |
|
92 | + $this->validator->push_field($index); |
|
93 | 93 | |
94 | - $condition = $this->validate_condition( $settings ); |
|
94 | + $condition = $this->validate_condition($settings); |
|
95 | 95 | |
96 | - if ( $condition ) { |
|
97 | - $sub_args[ $index ] = $condition; |
|
96 | + if ($condition) { |
|
97 | + $sub_args[$index] = $condition; |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | $this->validator->pop_field(); |
@@ -104,18 +104,18 @@ discard block |
||
104 | 104 | |
105 | 105 | } else { |
106 | 106 | |
107 | - if ( ! $this->event_args->descend( $arg_slug ) ) { |
|
107 | + if ( ! $this->event_args->descend($arg_slug)) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | |
111 | - $sub_args = $this->validate_conditions( $sub_args ); |
|
111 | + $sub_args = $this->validate_conditions($sub_args); |
|
112 | 112 | |
113 | - $args[ $arg_slug ] = $sub_args; |
|
113 | + $args[$arg_slug] = $sub_args; |
|
114 | 114 | |
115 | 115 | $this->event_args->ascend(); |
116 | 116 | } |
117 | 117 | |
118 | - $args[ $arg_slug ] = $sub_args; |
|
118 | + $args[$arg_slug] = $sub_args; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | return $args; |
@@ -131,32 +131,32 @@ discard block |
||
131 | 131 | * @return array|false The validated conditions settings, or false if unable to |
132 | 132 | * validate. |
133 | 133 | */ |
134 | - protected function validate_condition( $settings ) { |
|
134 | + protected function validate_condition($settings) { |
|
135 | 135 | |
136 | - if ( ! isset( $settings['type'] ) ) { |
|
137 | - $this->validator->add_error( __( 'Condition type is missing.', 'wordpoints' ) ); |
|
136 | + if ( ! isset($settings['type'])) { |
|
137 | + $this->validator->add_error(__('Condition type is missing.', 'wordpoints')); |
|
138 | 138 | return false; |
139 | 139 | } |
140 | 140 | |
141 | 141 | $arg = $this->event_args->get_current(); |
142 | 142 | |
143 | - $data_type = $this->get_data_type( $arg ); |
|
143 | + $data_type = $this->get_data_type($arg); |
|
144 | 144 | |
145 | - if ( ! $data_type ) { |
|
145 | + if ( ! $data_type) { |
|
146 | 146 | $this->validator->add_error( |
147 | - __( 'This type of condition does not work for the selected attribute.', 'wordpoints' ) |
|
147 | + __('This type of condition does not work for the selected attribute.', 'wordpoints') |
|
148 | 148 | ); |
149 | 149 | |
150 | 150 | return false; |
151 | 151 | } |
152 | 152 | |
153 | - $condition = wordpoints_hooks()->conditions->get( $data_type, $settings['type'] ); |
|
153 | + $condition = wordpoints_hooks()->conditions->get($data_type, $settings['type']); |
|
154 | 154 | |
155 | - if ( ! $condition ) { |
|
155 | + if ( ! $condition) { |
|
156 | 156 | |
157 | 157 | $this->validator->add_error( |
158 | 158 | sprintf( |
159 | - __( 'Unknown condition type “%s”.', 'wordpoints' ) |
|
159 | + __('Unknown condition type “%s”.', 'wordpoints') |
|
160 | 160 | , $settings['type'] |
161 | 161 | ) |
162 | 162 | , 'type' |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | - if ( ! isset( $settings['settings'] ) ) { |
|
169 | - $this->validator->add_error( __( 'Condition settings are missing.', 'wordpoints' ) ); |
|
168 | + if ( ! isset($settings['settings'])) { |
|
169 | + $this->validator->add_error(__('Condition settings are missing.', 'wordpoints')); |
|
170 | 170 | return false; |
171 | 171 | } |
172 | 172 | |
173 | - $this->validator->push_field( 'settings' ); |
|
173 | + $this->validator->push_field('settings'); |
|
174 | 174 | |
175 | 175 | // The condition may call this object's validate_settings() method to |
176 | 176 | // validate some sub-conditions. When that happens, these properties will be |
177 | 177 | // reset, so we need to back up their values and then restore them below. |
178 | - $backup = array( $this->validator, $this->event_args ); |
|
178 | + $backup = array($this->validator, $this->event_args); |
|
179 | 179 | |
180 | 180 | $settings['settings'] = $condition->validate_settings( |
181 | 181 | $arg |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | , $this->validator |
184 | 184 | ); |
185 | 185 | |
186 | - list( $this->validator, $this->event_args ) = $backup; |
|
186 | + list($this->validator, $this->event_args) = $backup; |
|
187 | 187 | |
188 | 188 | $this->validator->pop_field(); |
189 | 189 | |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | /** |
194 | 194 | * @since 1.0.0 |
195 | 195 | */ |
196 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
196 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
197 | 197 | |
198 | - $conditions = $fire->reaction->get_meta( 'conditions' ); |
|
198 | + $conditions = $fire->reaction->get_meta('conditions'); |
|
199 | 199 | |
200 | - if ( $conditions && ! $this->conditions_are_met( $conditions, $fire->event_args ) ) { |
|
200 | + if ($conditions && ! $this->conditions_are_met($conditions, $fire->event_args)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
@@ -219,35 +219,35 @@ discard block |
||
219 | 219 | WordPoints_Hook_Event_Args $event_args |
220 | 220 | ) { |
221 | 221 | |
222 | - foreach ( $conditions as $arg_slug => $sub_args ) { |
|
222 | + foreach ($conditions as $arg_slug => $sub_args) { |
|
223 | 223 | |
224 | - $event_args->descend( $arg_slug ); |
|
224 | + $event_args->descend($arg_slug); |
|
225 | 225 | |
226 | - if ( isset( $sub_args['_conditions'] ) ) { |
|
226 | + if (isset($sub_args['_conditions'])) { |
|
227 | 227 | |
228 | - foreach ( $sub_args['_conditions'] as $settings ) { |
|
228 | + foreach ($sub_args['_conditions'] as $settings) { |
|
229 | 229 | |
230 | 230 | $condition = $this->conditions->get( |
231 | - $this->get_data_type( $event_args->get_current() ) |
|
231 | + $this->get_data_type($event_args->get_current()) |
|
232 | 232 | , $settings['type'] |
233 | 233 | ); |
234 | 234 | |
235 | - $is_met = $condition->is_met( $settings['settings'], $event_args ); |
|
235 | + $is_met = $condition->is_met($settings['settings'], $event_args); |
|
236 | 236 | |
237 | - if ( ! $is_met ) { |
|
237 | + if ( ! $is_met) { |
|
238 | 238 | $event_args->ascend(); |
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - unset( $sub_args['_conditions'] ); |
|
243 | + unset($sub_args['_conditions']); |
|
244 | 244 | } |
245 | 245 | |
246 | - $are_met = $this->conditions_are_met( $sub_args, $event_args ); |
|
246 | + $are_met = $this->conditions_are_met($sub_args, $event_args); |
|
247 | 247 | |
248 | 248 | $event_args->ascend(); |
249 | 249 | |
250 | - if ( ! $are_met ) { |
|
250 | + if ( ! $are_met) { |
|
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | } |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | * |
265 | 265 | * @return string|false The data type, or false. |
266 | 266 | */ |
267 | - protected function get_data_type( $arg ) { |
|
267 | + protected function get_data_type($arg) { |
|
268 | 268 | |
269 | - if ( $arg instanceof WordPoints_Entity_Attr ) { |
|
269 | + if ($arg instanceof WordPoints_Entity_Attr) { |
|
270 | 270 | $data_type = $arg->get_data_type(); |
271 | - } elseif ( $arg instanceof WordPoints_Entity_Array ) { |
|
271 | + } elseif ($arg instanceof WordPoints_Entity_Array) { |
|
272 | 272 | $data_type = 'entity_array'; |
273 | - } elseif ( $arg instanceof WordPoints_Entity ) { |
|
273 | + } elseif ($arg instanceof WordPoints_Entity) { |
|
274 | 274 | $data_type = 'entity'; |
275 | 275 | } else { |
276 | 276 | $data_type = false; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @since 1.0.0 |
28 | 28 | */ |
29 | - public function __construct( $slug ) { |
|
29 | + public function __construct($slug) { |
|
30 | 30 | $this->slug = $slug; |
31 | 31 | } |
32 | 32 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @since 1.0.0 |
42 | 42 | */ |
43 | - public function do_event( $event_slug, WordPoints_Hook_Event_Args $event_args ) { |
|
43 | + public function do_event($event_slug, WordPoints_Hook_Event_Args $event_args) { |
|
44 | 44 | |
45 | 45 | $hooks = wordpoints_hooks(); |
46 | 46 | |
47 | 47 | /** @var WordPoints_Hook_Reactor $reactor */ |
48 | - foreach ( $hooks->reactors->get_all() as $reactor ) { |
|
48 | + foreach ($hooks->reactors->get_all() as $reactor) { |
|
49 | 49 | |
50 | - foreach ( $reactor->get_all_reactions_to_event( $event_slug ) as $reaction ) { |
|
50 | + foreach ($reactor->get_all_reactions_to_event($event_slug) as $reaction) { |
|
51 | 51 | |
52 | 52 | $validator = new WordPoints_Hook_Reaction_Validator( |
53 | 53 | $reaction |
@@ -57,29 +57,29 @@ discard block |
||
57 | 57 | |
58 | 58 | $validator->validate(); |
59 | 59 | |
60 | - if ( $validator->had_errors() ) { |
|
60 | + if ($validator->had_errors()) { |
|
61 | 61 | continue; |
62 | 62 | } |
63 | 63 | |
64 | - unset( $validator ); |
|
64 | + unset($validator); |
|
65 | 65 | |
66 | - $fire = new WordPoints_Hook_Fire( $this, $event_args, $reaction ); |
|
66 | + $fire = new WordPoints_Hook_Fire($this, $event_args, $reaction); |
|
67 | 67 | |
68 | 68 | /** @var WordPoints_Hook_Extension[] $extensions */ |
69 | 69 | $extensions = $hooks->extensions->get_all(); |
70 | 70 | |
71 | - foreach ( $extensions as $extension ) { |
|
72 | - if ( ! $extension->should_hit( $fire ) ) { |
|
71 | + foreach ($extensions as $extension) { |
|
72 | + if ( ! $extension->should_hit($fire)) { |
|
73 | 73 | continue 2; |
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
77 | 77 | $fire->hit(); |
78 | 78 | |
79 | - $reactor->hit( $fire ); |
|
79 | + $reactor->hit($fire); |
|
80 | 80 | |
81 | - foreach ( $extensions as $extension ) { |
|
82 | - $extension->after_hit( $fire ); |
|
81 | + foreach ($extensions as $extension) { |
|
82 | + $extension->after_hit($fire); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | } |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return mixed The entity, or false if not found. |
108 | 108 | */ |
109 | - protected function get_entity( $id ) { |
|
109 | + protected function get_entity($id) { |
|
110 | 110 | |
111 | - $entity = call_user_func( $this->getter, $id ); |
|
111 | + $entity = call_user_func($this->getter, $id); |
|
112 | 112 | |
113 | - if ( ! $this->is_entity( $entity ) ) { |
|
113 | + if ( ! $this->is_entity($entity)) { |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
@@ -126,13 +126,13 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return bool Whether the passed value is an entity. |
128 | 128 | */ |
129 | - protected function is_entity( $entity ) { |
|
129 | + protected function is_entity($entity) { |
|
130 | 130 | |
131 | - if ( ! is_object( $entity ) && ! is_array( $entity ) ) { |
|
131 | + if ( ! is_object($entity) && ! is_array($entity)) { |
|
132 | 132 | return false; |
133 | 133 | } |
134 | 134 | |
135 | - return (bool) $this->get_entity_id( $entity ); |
|
135 | + return (bool) $this->get_entity_id($entity); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return mixed The value of the attribute of the entity. |
147 | 147 | */ |
148 | - protected function get_attr_value( $entity, $attr ) { |
|
148 | + protected function get_attr_value($entity, $attr) { |
|
149 | 149 | |
150 | - if ( is_array( $entity ) ) { |
|
151 | - if ( isset( $entity[ $attr ] ) ) { |
|
152 | - return $entity[ $attr ]; |
|
150 | + if (is_array($entity)) { |
|
151 | + if (isset($entity[$attr])) { |
|
152 | + return $entity[$attr]; |
|
153 | 153 | } |
154 | 154 | } else { |
155 | - if ( isset( $entity->{$attr} ) ) { |
|
155 | + if (isset($entity->{$attr} )) { |
|
156 | 156 | return $entity->{$attr}; |
157 | 157 | } |
158 | 158 | } |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @return mixed The ID of the entity. |
171 | 171 | */ |
172 | - protected function get_entity_id( $entity ) { |
|
173 | - return $this->get_attr_value( $entity, $this->get_id_field() ); |
|
172 | + protected function get_entity_id($entity) { |
|
173 | + return $this->get_attr_value($entity, $this->get_id_field()); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @return mixed The human ID of the entity. |
188 | 188 | */ |
189 | - protected function get_entity_human_id( $entity ) { |
|
190 | - return $this->get_attr_value( $entity, $this->human_id_field ); |
|
189 | + protected function get_entity_human_id($entity) { |
|
190 | + return $this->get_attr_value($entity, $this->human_id_field); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // |
@@ -231,15 +231,15 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return string|int|float|false The human identifier for the entity, or false. |
233 | 233 | */ |
234 | - public function get_human_id( $id ) { |
|
234 | + public function get_human_id($id) { |
|
235 | 235 | |
236 | - $entity = $this->get_entity( $id ); |
|
236 | + $entity = $this->get_entity($id); |
|
237 | 237 | |
238 | - if ( ! $entity ) { |
|
238 | + if ( ! $entity) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | |
242 | - return $this->get_entity_human_id( $entity ); |
|
242 | + return $this->get_entity_human_id($entity); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @return bool Whether or not an entity with that ID exists. |
253 | 253 | */ |
254 | - public function exists( $id ) { |
|
255 | - return (bool) $this->get_entity( $id ); |
|
254 | + public function exists($id) { |
|
255 | + return (bool) $this->get_entity($id); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
@@ -267,17 +267,17 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @return WordPoints_Entityish|false The child's object, or false if not found. |
269 | 269 | */ |
270 | - public function get_child( $child_slug ) { |
|
270 | + public function get_child($child_slug) { |
|
271 | 271 | |
272 | 272 | $children = wordpoints_entities()->children; |
273 | 273 | |
274 | - $child = $children->get( $this->slug, $child_slug ); |
|
274 | + $child = $children->get($this->slug, $child_slug); |
|
275 | 275 | |
276 | 276 | if ( |
277 | - isset( $this->the_value ) |
|
277 | + isset($this->the_value) |
|
278 | 278 | && $child instanceof WordPoints_Entity_ChildI |
279 | 279 | ) { |
280 | - $child->set_the_value_from_entity( $this ); |
|
280 | + $child->set_the_value_from_entity($this); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | return $child; |
@@ -299,20 +299,20 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @return bool Whether the value was set. |
301 | 301 | */ |
302 | - public function set_the_value( $value ) { |
|
302 | + public function set_the_value($value) { |
|
303 | 303 | |
304 | 304 | $this->the_value = $this->the_entity = $this->the_context = null; |
305 | 305 | |
306 | - if ( $this->is_entity( $value ) ) { |
|
306 | + if ($this->is_entity($value)) { |
|
307 | 307 | |
308 | 308 | $entity = $value; |
309 | - $value = $this->get_entity_id( $value ); |
|
309 | + $value = $this->get_entity_id($value); |
|
310 | 310 | |
311 | 311 | } else { |
312 | 312 | |
313 | - $entity = $this->get_entity( $value ); |
|
313 | + $entity = $this->get_entity($value); |
|
314 | 314 | |
315 | - if ( ! $entity ) { |
|
315 | + if ( ! $entity) { |
|
316 | 316 | return false; |
317 | 317 | } |
318 | 318 | } |
@@ -335,8 +335,8 @@ discard block |
||
335 | 335 | * |
336 | 336 | * @return mixed The value of the attribute. |
337 | 337 | */ |
338 | - public function get_the_attr_value( $attr ) { |
|
339 | - return $this->get_attr_value( $this->the_entity, $attr ); |
|
338 | + public function get_the_attr_value($attr) { |
|
339 | + return $this->get_attr_value($this->the_entity, $attr); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @return string|int|float|null The human identifier for the entity, or null. |
361 | 361 | */ |
362 | 362 | public function get_the_human_id() { |
363 | - return $this->get_entity_human_id( $this->the_entity ); |
|
363 | + return $this->get_entity_human_id($this->the_entity); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | /** |
@@ -394,11 +394,11 @@ discard block |
||
394 | 394 | |
395 | 395 | $guid = $this->get_the_context(); |
396 | 396 | |
397 | - if ( ! is_array( $guid ) ) { |
|
397 | + if ( ! is_array($guid)) { |
|
398 | 398 | return $guid; |
399 | 399 | } |
400 | 400 | |
401 | - $guid = array( $this->slug => $this->get_the_id() ) + $guid; |
|
401 | + $guid = array($this->slug => $this->get_the_id()) + $guid; |
|
402 | 402 | |
403 | 403 | return $guid; |
404 | 404 | } |
@@ -16,16 +16,16 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @param WordPoints_App $app The main WordPoints app. |
18 | 18 | */ |
19 | -function wordpoints_hooks_register_admin_apps( $app ) { |
|
19 | +function wordpoints_hooks_register_admin_apps($app) { |
|
20 | 20 | |
21 | 21 | $apps = $app->sub_apps; |
22 | 22 | |
23 | - $apps->register( 'admin', 'WordPoints_App' ); |
|
23 | + $apps->register('admin', 'WordPoints_App'); |
|
24 | 24 | |
25 | 25 | /** @var WordPoints_App $admin */ |
26 | - $admin = $apps->get( 'admin' ); |
|
26 | + $admin = $apps->get('admin'); |
|
27 | 27 | |
28 | - $admin->sub_apps->register( 'screen', 'WordPoints_Admin_Screens' ); |
|
28 | + $admin->sub_apps->register('screen', 'WordPoints_Admin_Screens'); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | // Hooks page. |
47 | 47 | $id = add_submenu_page( |
48 | 48 | $wordpoints_menu |
49 | - , __( 'WordPoints — Points Types', 'wordpoints' ) |
|
50 | - , __( 'Points Types', 'wordpoints' ) |
|
49 | + , __('WordPoints — Points Types', 'wordpoints') |
|
50 | + , __('Points Types', 'wordpoints') |
|
51 | 51 | , 'manage_options' |
52 | 52 | , 'wordpoints_points_types' |
53 | - , array( $admin_screens, 'display' ) |
|
53 | + , array($admin_screens, 'display') |
|
54 | 54 | ); |
55 | 55 | |
56 | - if ( $id ) { |
|
57 | - $admin_screens->register( $id, 'WordPoints_Admin_Screen_Points_Types' ); |
|
56 | + if ($id) { |
|
57 | + $admin_screens->register($id, 'WordPoints_Admin_Screen_Points_Types'); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | */ |
68 | 68 | function wordpoints_hooks_admin_register_scripts() { |
69 | 69 | |
70 | - $assets_url = wordpoints_modules_url( '/assets', dirname( __FILE__ ) ); |
|
70 | + $assets_url = wordpoints_modules_url('/assets', dirname(__FILE__)); |
|
71 | 71 | |
72 | 72 | // CSS |
73 | 73 | |
74 | 74 | wp_register_style( |
75 | 75 | 'wordpoints-hooks-admin' |
76 | - , $assets_url . '/css/hooks.css' |
|
77 | - , array( 'dashicons', 'wp-jquery-ui-dialog' ) |
|
76 | + , $assets_url.'/css/hooks.css' |
|
77 | + , array('dashicons', 'wp-jquery-ui-dialog') |
|
78 | 78 | , WORDPOINTS_VERSION |
79 | 79 | ); |
80 | 80 | |
@@ -82,15 +82,15 @@ discard block |
||
82 | 82 | |
83 | 83 | wp_register_script( |
84 | 84 | 'wordpoints-hooks-models' |
85 | - , $assets_url . '/js/hooks/models.js' |
|
86 | - , array( 'backbone', 'jquery-ui-dialog', 'wp-util' ) |
|
85 | + , $assets_url.'/js/hooks/models.js' |
|
86 | + , array('backbone', 'jquery-ui-dialog', 'wp-util') |
|
87 | 87 | , WORDPOINTS_VERSION |
88 | 88 | ); |
89 | 89 | |
90 | 90 | wp_register_script( |
91 | 91 | 'wordpoints-hooks-views' |
92 | - , $assets_url . '/js/hooks/views.js' |
|
93 | - , array( 'wordpoints-hooks-models' ) |
|
92 | + , $assets_url.'/js/hooks/views.js' |
|
93 | + , array('wordpoints-hooks-models') |
|
94 | 94 | , WORDPOINTS_VERSION |
95 | 95 | ); |
96 | 96 | |
@@ -98,16 +98,16 @@ discard block |
||
98 | 98 | 'wordpoints-hooks-views' |
99 | 99 | , 'WordPointsHooksAdminL10n' |
100 | 100 | , array( |
101 | - 'unexpectedError' => __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ), |
|
102 | - 'changesSaved' => __( 'Your changes have been saved.', 'wordpoints' ), |
|
101 | + 'unexpectedError' => __('There was an unexpected error. Try reloading the page.', 'wordpoints'), |
|
102 | + 'changesSaved' => __('Your changes have been saved.', 'wordpoints'), |
|
103 | 103 | /* translators: the name of the field that cannot be empty */ |
104 | - 'emptyField' => sprintf( __( '%s cannot be empty.', 'wordpoints' ), '{{ data.label }}' ), |
|
105 | - 'confirmDelete' => __( 'Are you sure that you want to delete this reaction? This action cannot be undone.', 'wordpoints' ), |
|
106 | - 'confirmTitle' => __( 'Are you sure?', 'wordpoints' ), |
|
107 | - 'deleteText' => __( 'Delete', 'wordpoints' ), |
|
108 | - 'cancelText' => __( 'Cancel', 'wordpoints' ), |
|
109 | - 'separator' => __( ' » ', 'wordpoints' ), |
|
110 | - 'target_label' => __( 'Target', 'wordpoints' ), |
|
104 | + 'emptyField' => sprintf(__('%s cannot be empty.', 'wordpoints'), '{{ data.label }}'), |
|
105 | + 'confirmDelete' => __('Are you sure that you want to delete this reaction? This action cannot be undone.', 'wordpoints'), |
|
106 | + 'confirmTitle' => __('Are you sure?', 'wordpoints'), |
|
107 | + 'deleteText' => __('Delete', 'wordpoints'), |
|
108 | + 'cancelText' => __('Cancel', 'wordpoints'), |
|
109 | + 'separator' => __(' » ', 'wordpoints'), |
|
110 | + 'target_label' => __('Target', 'wordpoints'), |
|
111 | 111 | ) |
112 | 112 | ); |
113 | 113 | |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | <div class="view"> |
120 | 120 | <div class="title"></div> |
121 | 121 | <button type="button" class="edit button-secondary"> |
122 | - ' . esc_html__( 'Edit', 'wordpoints' ) . ' |
|
122 | + ' . esc_html__('Edit', 'wordpoints').' |
|
123 | 123 | </button> |
124 | 124 | <button type="button" class="close button-secondary"> |
125 | - ' . esc_html__( 'Close', 'wordpoints' ) . ' |
|
125 | + ' . esc_html__('Close', 'wordpoints').' |
|
126 | 126 | </button> |
127 | 127 | </div> |
128 | 128 | <div class="form"> |
@@ -141,16 +141,16 @@ discard block |
||
141 | 141 | </div> |
142 | 142 | <div class="action-buttons"> |
143 | 143 | <button type="button" class="save button-primary" disabled> |
144 | - ' . esc_html__( 'Save', 'wordpoints' ) . ' |
|
144 | + ' . esc_html__('Save', 'wordpoints').' |
|
145 | 145 | </button> |
146 | 146 | <button type="button" class="cancel button-secondary"> |
147 | - ' . esc_html__( 'Cancel', 'wordpoints' ) . ' |
|
147 | + ' . esc_html__('Cancel', 'wordpoints').' |
|
148 | 148 | </button> |
149 | 149 | <button type="button" class="close button-secondary"> |
150 | - ' . esc_html__( 'Close', 'wordpoints' ) . ' |
|
150 | + ' . esc_html__('Close', 'wordpoints').' |
|
151 | 151 | </button> |
152 | 152 | <button type="button" class="delete button-secondary"> |
153 | - ' . esc_html__( 'Delete', 'wordpoints' ) . ' |
|
153 | + ' . esc_html__('Delete', 'wordpoints').' |
|
154 | 154 | </button> |
155 | 155 | </div> |
156 | 156 | </div> |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | |
199 | 199 | wp_register_script( |
200 | 200 | 'wordpoints-hooks-reactor-points' |
201 | - , $assets_url . '/js/hooks/reactors/points.js' |
|
202 | - , array( 'wordpoints-hooks-views' ) |
|
201 | + , $assets_url.'/js/hooks/reactors/points.js' |
|
202 | + , array('wordpoints-hooks-views') |
|
203 | 203 | , WORDPOINTS_VERSION |
204 | 204 | ); |
205 | 205 | |
206 | 206 | wp_register_script( |
207 | 207 | 'wordpoints-hooks-extension-conditions' |
208 | - , $assets_url . '/js/hooks/extensions/conditions.js' |
|
209 | - , array( 'wordpoints-hooks-views' ) |
|
208 | + , $assets_url.'/js/hooks/extensions/conditions.js' |
|
209 | + , array('wordpoints-hooks-views') |
|
210 | 210 | , WORDPOINTS_VERSION |
211 | 211 | ); |
212 | 212 | |
@@ -216,25 +216,25 @@ discard block |
||
216 | 216 | , ' |
217 | 217 | <script type="text/template" id="tmpl-wordpoints-hook-condition-groups"> |
218 | 218 | <div class="conditions-title section-title"> |
219 | - <h4>' . esc_html__( 'Conditions', 'wordpoints' ) . '</h4> |
|
219 | + <h4>' . esc_html__('Conditions', 'wordpoints').'</h4> |
|
220 | 220 | <button type="button" class="add-new button-secondary button-link"> |
221 | - <span class="screen-reader-text">' . esc_html__( 'Add New Condition', 'wordpoints' ) . '</span> |
|
221 | + <span class="screen-reader-text">' . esc_html__('Add New Condition', 'wordpoints').'</span> |
|
222 | 222 | <span class="dashicons dashicons-plus"></span> |
223 | 223 | </button> |
224 | 224 | </div> |
225 | 225 | <div class="add-condition-form hidden"> |
226 | 226 | <div class="no-conditions hidden"> |
227 | - ' . esc_html__( 'No conditions available.', 'wordpoints' ) . ' |
|
227 | + ' . esc_html__('No conditions available.', 'wordpoints').' |
|
228 | 228 | </div> |
229 | 229 | <div class="condition-selectors"> |
230 | 230 | <div class="arg-selectors"></div> |
231 | 231 | <div class="condition-selector"></div> |
232 | 232 | </div> |
233 | - <button type="button" class="confirm-add-new button-secondary" disabled aria-label="' . esc_attr__( 'Add Condition', 'wordpoints' ) . '"> |
|
234 | - ' . esc_html_x( 'Add', 'reaction condition', 'wordpoints' ) . ' |
|
233 | + <button type="button" class="confirm-add-new button-secondary" disabled aria-label="' . esc_attr__('Add Condition', 'wordpoints').'"> |
|
234 | + ' . esc_html_x('Add', 'reaction condition', 'wordpoints').' |
|
235 | 235 | </button> |
236 | - <button type="button" class="cancel-add-new button-secondary" aria-label="' . esc_attr__( 'Cancel Adding New Condition', 'wordpoints' ) . '"> |
|
237 | - ' . esc_html_x( 'Cancel', 'reaction condition', 'wordpoints' ) . ' |
|
236 | + <button type="button" class="cancel-add-new button-secondary" aria-label="' . esc_attr__('Cancel Adding New Condition', 'wordpoints').'"> |
|
237 | + ' . esc_html_x('Cancel', 'reaction condition', 'wordpoints').' |
|
238 | 238 | </button> |
239 | 239 | </div> |
240 | 240 | <div class="condition-groups section-content"></div> |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | <div class="condition-controls"> |
249 | 249 | <div class="condition-title"></div> |
250 | 250 | <button type="button" class="delete button-secondary button-link"> |
251 | - <span class="screen-reader-text">' . esc_html__( 'Remove Condition', 'wordpoints' ) . '</span> |
|
251 | + <span class="screen-reader-text">' . esc_html__('Remove Condition', 'wordpoints').'</span> |
|
252 | 252 | <span class="dashicons dashicons-no"></span> |
253 | 253 | </button> |
254 | 254 | </div> |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | |
267 | 267 | wp_register_script( |
268 | 268 | 'wordpoints-hooks-extension-periods' |
269 | - , $assets_url . '/js/hooks/extensions/periods.js' |
|
270 | - , array( 'wordpoints-hooks-views' ) |
|
269 | + , $assets_url.'/js/hooks/extensions/periods.js' |
|
270 | + , array('wordpoints-hooks-views') |
|
271 | 271 | , WORDPOINTS_VERSION |
272 | 272 | ); |
273 | 273 | |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | , ' |
278 | 278 | <script type="text/template" id="tmpl-wordpoints-hook-periods"> |
279 | 279 | <div class="periods-title section-title"> |
280 | - <h4>' . esc_html__( 'Rate Limit', 'wordpoints' ) . '</h4> |
|
280 | + <h4>' . esc_html__('Rate Limit', 'wordpoints').'</h4> |
|
281 | 281 | </div> |
282 | 282 | <div class="periods section-content"></div> |
283 | 283 | </script> |
@@ -296,27 +296,27 @@ discard block |
||
296 | 296 | |
297 | 297 | $extensions_data = array(); |
298 | 298 | |
299 | - foreach ( $hooks->extensions->get_all() as $slug => $extension ) { |
|
299 | + foreach ($hooks->extensions->get_all() as $slug => $extension) { |
|
300 | 300 | |
301 | - if ( $extension instanceof WordPoints_Hook_Extension ) { |
|
302 | - $extensions_data[ $slug ] = $extension->get_ui_script_data(); |
|
301 | + if ($extension instanceof WordPoints_Hook_Extension) { |
|
302 | + $extensions_data[$slug] = $extension->get_ui_script_data(); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( wp_script_is( "wordpoints-hooks-extension-{$slug}", 'registered' ) ) { |
|
306 | - wp_enqueue_script( "wordpoints-hooks-extension-{$slug}" ); |
|
305 | + if (wp_script_is("wordpoints-hooks-extension-{$slug}", 'registered')) { |
|
306 | + wp_enqueue_script("wordpoints-hooks-extension-{$slug}"); |
|
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | 310 | $reactor_data = array(); |
311 | 311 | |
312 | - foreach ( $hooks->reactors->get_all() as $slug => $reactor ) { |
|
312 | + foreach ($hooks->reactors->get_all() as $slug => $reactor) { |
|
313 | 313 | |
314 | - if ( $reactor instanceof WordPoints_Hook_Reactor ) { |
|
315 | - $reactor_data[ $slug ] = $reactor->get_ui_script_data(); |
|
314 | + if ($reactor instanceof WordPoints_Hook_Reactor) { |
|
315 | + $reactor_data[$slug] = $reactor->get_ui_script_data(); |
|
316 | 316 | } |
317 | 317 | |
318 | - if ( wp_script_is( "wordpoints-hooks-reactor-{$slug}", 'registered' ) ) { |
|
319 | - wp_enqueue_script( "wordpoints-hooks-reactor-{$slug}" ); |
|
318 | + if (wp_script_is("wordpoints-hooks-reactor-{$slug}", 'registered')) { |
|
319 | + wp_enqueue_script("wordpoints-hooks-reactor-{$slug}"); |
|
320 | 320 | } |
321 | 321 | } |
322 | 322 | |
@@ -328,28 +328,28 @@ discard block |
||
328 | 328 | $entity_children = $entities->children; |
329 | 329 | |
330 | 330 | /** @var WordPoints_Entity $entity */ |
331 | - foreach ( $entities->get_all() as $slug => $entity ) { |
|
331 | + foreach ($entities->get_all() as $slug => $entity) { |
|
332 | 332 | |
333 | 333 | $child_data = array(); |
334 | 334 | |
335 | 335 | /** @var WordPoints_EntityishI $child */ |
336 | - foreach ( $entity_children->get_children( $slug ) as $child_slug => $child ) { |
|
336 | + foreach ($entity_children->get_children($slug) as $child_slug => $child) { |
|
337 | 337 | |
338 | - $child_data[ $child_slug ] = array( |
|
338 | + $child_data[$child_slug] = array( |
|
339 | 339 | 'slug' => $child_slug, |
340 | 340 | 'title' => $child->get_title(), |
341 | 341 | ); |
342 | 342 | |
343 | - if ( $child instanceof WordPoints_Entity_Attr ) { |
|
343 | + if ($child instanceof WordPoints_Entity_Attr) { |
|
344 | 344 | |
345 | - $child_data[ $child_slug ]['_type'] = 'attr'; |
|
346 | - $child_data[ $child_slug ]['data_type'] = $child->get_data_type(); |
|
345 | + $child_data[$child_slug]['_type'] = 'attr'; |
|
346 | + $child_data[$child_slug]['data_type'] = $child->get_data_type(); |
|
347 | 347 | |
348 | - } elseif ( $child instanceof WordPoints_Entity_Relationship ) { |
|
348 | + } elseif ($child instanceof WordPoints_Entity_Relationship) { |
|
349 | 349 | |
350 | - $child_data[ $child_slug ]['_type'] = 'relationship'; |
|
351 | - $child_data[ $child_slug ]['primary'] = $child->get_primary_entity_slug(); |
|
352 | - $child_data[ $child_slug ]['secondary'] = $child->get_related_entity_slug(); |
|
350 | + $child_data[$child_slug]['_type'] = 'relationship'; |
|
351 | + $child_data[$child_slug]['primary'] = $child->get_primary_entity_slug(); |
|
352 | + $child_data[$child_slug]['secondary'] = $child->get_related_entity_slug(); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | /** |
@@ -360,10 +360,10 @@ discard block |
||
360 | 360 | * @param array $data The data for the entity child. |
361 | 361 | * @param WordPoints_Entityish $child The child's object. |
362 | 362 | */ |
363 | - $child_data[ $child_slug ] = apply_filters( 'wordpoints_hooks_ui_data_entity_child', $child_data[ $child_slug ], $child ); |
|
363 | + $child_data[$child_slug] = apply_filters('wordpoints_hooks_ui_data_entity_child', $child_data[$child_slug], $child); |
|
364 | 364 | } |
365 | 365 | |
366 | - $entities_data[ $slug ] = array( |
|
366 | + $entities_data[$slug] = array( |
|
367 | 367 | 'slug' => $slug, |
368 | 368 | 'title' => $entity->get_title(), |
369 | 369 | 'children' => $child_data, |
@@ -371,12 +371,12 @@ discard block |
||
371 | 371 | '_type' => 'entity', |
372 | 372 | ); |
373 | 373 | |
374 | - if ( $entity instanceof WordPoints_Entity_EnumerableI ) { |
|
374 | + if ($entity instanceof WordPoints_Entity_EnumerableI) { |
|
375 | 375 | |
376 | 376 | $values = array(); |
377 | 377 | |
378 | - foreach ( $entity->get_enumerated_values() as $value ) { |
|
379 | - if ( $entity->set_the_value( $value ) ) { |
|
378 | + foreach ($entity->get_enumerated_values() as $value) { |
|
379 | + if ($entity->set_the_value($value)) { |
|
380 | 380 | $values[] = array( |
381 | 381 | 'value' => $entity->get_the_id(), |
382 | 382 | 'label' => $entity->get_the_human_id(), |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | - $entities_data[ $slug ]['values'] = $values; |
|
387 | + $entities_data[$slug]['values'] = $values; |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | * @param array $data The data for the entity. |
394 | 394 | * @param WordPoints_Entity $entity The entity object. |
395 | 395 | */ |
396 | - $entities_data[ $slug ] = apply_filters( 'wordpoints_hooks_ui_data_entity', $entities_data[ $slug ], $entity ); |
|
396 | + $entities_data[$slug] = apply_filters('wordpoints_hooks_ui_data_entity', $entities_data[$slug], $entity); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | $data = array( |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | * |
415 | 415 | * @param array $data The data. |
416 | 416 | */ |
417 | - $data = apply_filters( 'wordpoints_hooks_ui_data', $data ); |
|
417 | + $data = apply_filters('wordpoints_hooks_ui_data', $data); |
|
418 | 418 | |
419 | 419 | wp_localize_script( |
420 | 420 | 'wordpoints-hooks-models' |
@@ -439,13 +439,13 @@ discard block |
||
439 | 439 | * |
440 | 440 | * @return string The HTML with templates appended. |
441 | 441 | */ |
442 | -function wordpoints_script_templates_filter( $html, $handle ) { |
|
442 | +function wordpoints_script_templates_filter($html, $handle) { |
|
443 | 443 | |
444 | 444 | global $wp_scripts; |
445 | 445 | |
446 | - $templates = $wp_scripts->get_data( $handle, 'wordpoints-templates' ); |
|
446 | + $templates = $wp_scripts->get_data($handle, 'wordpoints-templates'); |
|
447 | 447 | |
448 | - if ( $templates ) { |
|
448 | + if ($templates) { |
|
449 | 449 | $html .= $templates; |
450 | 450 | } |
451 | 451 | |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | */ |
462 | 462 | function wordpoints_hooks_admin_ajax() { |
463 | 463 | |
464 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
464 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
465 | 465 | new WordPoints_Admin_Ajax_Hooks; |
466 | 466 | } |
467 | 467 | } |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | public function get_ui_script_data() { |
26 | 26 | |
27 | 27 | $periods = array( |
28 | - MINUTE_IN_SECONDS => __( 'Minute', 'wordpoints' ), |
|
29 | - HOUR_IN_SECONDS => __( 'Hour', 'wordpoints' ), |
|
30 | - DAY_IN_SECONDS => __( 'Day', 'wordpoints' ), |
|
31 | - WEEK_IN_SECONDS => __( 'Week', 'wordpoints' ), |
|
32 | - 30 * DAY_IN_SECONDS => __( 'Month', 'wordpoints' ), |
|
28 | + MINUTE_IN_SECONDS => __('Minute', 'wordpoints'), |
|
29 | + HOUR_IN_SECONDS => __('Hour', 'wordpoints'), |
|
30 | + DAY_IN_SECONDS => __('Day', 'wordpoints'), |
|
31 | + WEEK_IN_SECONDS => __('Week', 'wordpoints'), |
|
32 | + 30 * DAY_IN_SECONDS => __('Month', 'wordpoints'), |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | /** |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | * |
40 | 40 | * @param string[] $periods The period titles, indexed by length in seconds. |
41 | 41 | */ |
42 | - $periods = apply_filters( 'wordpoints_hooks_ui_data_periods', $periods ); |
|
42 | + $periods = apply_filters('wordpoints_hooks_ui_data_periods', $periods); |
|
43 | 43 | |
44 | 44 | return array( |
45 | 45 | 'periods' => $periods, |
46 | 46 | 'l10n' => array( |
47 | - 'label' => __( 'Trigger reaction no more than once per:', 'wordpoints' ), |
|
47 | + 'label' => __('Trigger reaction no more than once per:', 'wordpoints'), |
|
48 | 48 | ), |
49 | 49 | ); |
50 | 50 | } |
@@ -58,25 +58,25 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array The validated periods. |
60 | 60 | */ |
61 | - protected function validate_periods( $periods ) { |
|
61 | + protected function validate_periods($periods) { |
|
62 | 62 | |
63 | - if ( ! is_array( $periods ) ) { |
|
63 | + if ( ! is_array($periods)) { |
|
64 | 64 | |
65 | 65 | $this->validator->add_error( |
66 | - __( 'Periods do not match expected format.', 'wordpoints' ) |
|
66 | + __('Periods do not match expected format.', 'wordpoints') |
|
67 | 67 | ); |
68 | 68 | |
69 | 69 | return array(); |
70 | 70 | } |
71 | 71 | |
72 | - foreach ( $periods as $index => $period ) { |
|
72 | + foreach ($periods as $index => $period) { |
|
73 | 73 | |
74 | - $this->validator->push_field( $index ); |
|
74 | + $this->validator->push_field($index); |
|
75 | 75 | |
76 | - $period = $this->validate_period( $period ); |
|
76 | + $period = $this->validate_period($period); |
|
77 | 77 | |
78 | - if ( $period ) { |
|
79 | - $periods[ $index ] = $period; |
|
78 | + if ($period) { |
|
79 | + $periods[$index] = $period; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $this->validator->pop_field(); |
@@ -94,30 +94,30 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return array|false The validated period, or false if invalid. |
96 | 96 | */ |
97 | - protected function validate_period( $period ) { |
|
97 | + protected function validate_period($period) { |
|
98 | 98 | |
99 | - if ( ! is_array( $period ) ) { |
|
99 | + if ( ! is_array($period)) { |
|
100 | 100 | $this->validator->add_error( |
101 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
101 | + __('Period does not match expected format.', 'wordpoints') |
|
102 | 102 | ); |
103 | 103 | |
104 | 104 | return false; |
105 | 105 | } |
106 | 106 | |
107 | - if ( isset( $period['args'] ) ) { |
|
108 | - $this->validate_period_args( $period['args'] ); |
|
107 | + if (isset($period['args'])) { |
|
108 | + $this->validate_period_args($period['args']); |
|
109 | 109 | } |
110 | 110 | |
111 | - if ( ! isset( $period['length'] ) ) { |
|
111 | + if ( ! isset($period['length'])) { |
|
112 | 112 | |
113 | 113 | $this->validator->add_error( |
114 | - __( 'Period length setting is missing.', 'wordpoints' ) |
|
114 | + __('Period length setting is missing.', 'wordpoints') |
|
115 | 115 | ); |
116 | 116 | |
117 | - } elseif ( false === wordpoints_posint( $period['length'] ) ) { |
|
117 | + } elseif (false === wordpoints_posint($period['length'])) { |
|
118 | 118 | |
119 | 119 | $this->validator->add_error( |
120 | - __( 'Period length must be a positive integer.', 'wordpoints' ) |
|
120 | + __('Period length must be a positive integer.', 'wordpoints') |
|
121 | 121 | , 'length' |
122 | 122 | ); |
123 | 123 | |
@@ -134,34 +134,34 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param mixed $args The args the period is related to. |
136 | 136 | */ |
137 | - protected function validate_period_args( $args ) { |
|
137 | + protected function validate_period_args($args) { |
|
138 | 138 | |
139 | - if ( ! is_array( $args ) ) { |
|
139 | + if ( ! is_array($args)) { |
|
140 | 140 | |
141 | 141 | $this->validator->add_error( |
142 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
142 | + __('Period does not match expected format.', 'wordpoints') |
|
143 | 143 | , 'args' |
144 | 144 | ); |
145 | 145 | |
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
149 | - $this->validator->push_field( 'args' ); |
|
149 | + $this->validator->push_field('args'); |
|
150 | 150 | |
151 | - foreach ( $args as $index => $hierarchy ) { |
|
151 | + foreach ($args as $index => $hierarchy) { |
|
152 | 152 | |
153 | - $this->validator->push_field( $index ); |
|
153 | + $this->validator->push_field($index); |
|
154 | 154 | |
155 | - if ( ! is_array( $hierarchy ) ) { |
|
155 | + if ( ! is_array($hierarchy)) { |
|
156 | 156 | |
157 | 157 | $this->validator->add_error( |
158 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
158 | + __('Period does not match expected format.', 'wordpoints') |
|
159 | 159 | ); |
160 | 160 | |
161 | - } elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) { |
|
161 | + } elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) { |
|
162 | 162 | |
163 | 163 | $this->validator->add_error( |
164 | - __( 'Invalid period.', 'wordpoints' ) // TODO better error message |
|
164 | + __('Invalid period.', 'wordpoints') // TODO better error message |
|
165 | 165 | ); |
166 | 166 | } |
167 | 167 | |
@@ -174,18 +174,18 @@ discard block |
||
174 | 174 | /** |
175 | 175 | * @since 1.0.0 |
176 | 176 | */ |
177 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
177 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
178 | 178 | |
179 | - $periods = $fire->reaction->get_meta( 'periods' ); |
|
179 | + $periods = $fire->reaction->get_meta('periods'); |
|
180 | 180 | |
181 | - if ( empty( $periods ) ) { |
|
181 | + if (empty($periods)) { |
|
182 | 182 | return true; |
183 | 183 | } |
184 | 184 | |
185 | 185 | $this->event_args = $fire->event_args; |
186 | 186 | |
187 | - foreach ( $periods as $period ) { |
|
188 | - if ( ! $this->has_period_ended( $period, $fire->reaction ) ) { |
|
187 | + foreach ($periods as $period) { |
|
188 | + if ( ! $this->has_period_ended($period, $fire->reaction)) { |
|
189 | 189 | return false; |
190 | 190 | } |
191 | 191 | } |
@@ -209,24 +209,24 @@ discard block |
||
209 | 209 | ) { |
210 | 210 | |
211 | 211 | $period = $this->get_period_by_reaction( |
212 | - $this->get_period_signature( $settings, $reaction ) |
|
212 | + $this->get_period_signature($settings, $reaction) |
|
213 | 213 | , $reaction |
214 | 214 | ); |
215 | 215 | |
216 | 216 | // If the period isn't found, we know that we can still fire. |
217 | - if ( ! $period ) { |
|
217 | + if ( ! $period) { |
|
218 | 218 | return true; |
219 | 219 | } |
220 | 220 | |
221 | - $now = current_time( 'timestamp' ); |
|
222 | - $hit_time = strtotime( $period->date, $now ); |
|
221 | + $now = current_time('timestamp'); |
|
222 | + $hit_time = strtotime($period->date, $now); |
|
223 | 223 | |
224 | - if ( ! empty( $settings['relative'] ) ) { |
|
225 | - return ( $hit_time < $now - $settings['length'] ); |
|
224 | + if ( ! empty($settings['relative'])) { |
|
225 | + return ($hit_time < $now - $settings['length']); |
|
226 | 226 | } else { |
227 | 227 | return ( |
228 | - (int) ( $hit_time / $settings['length'] ) |
|
229 | - < (int) ( $now / $settings['length'] ) |
|
228 | + (int) ($hit_time / $settings['length']) |
|
229 | + < (int) ($now / $settings['length']) |
|
230 | 230 | ); |
231 | 231 | } |
232 | 232 | } |
@@ -240,24 +240,24 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return array The arg values. |
242 | 242 | */ |
243 | - protected function get_arg_values( array $period_args ) { |
|
243 | + protected function get_arg_values(array $period_args) { |
|
244 | 244 | |
245 | 245 | $values = array(); |
246 | 246 | |
247 | - foreach ( $period_args as $arg_hierarchy ) { |
|
247 | + foreach ($period_args as $arg_hierarchy) { |
|
248 | 248 | |
249 | 249 | $arg = $this->event_args->get_from_hierarchy( |
250 | 250 | $arg_hierarchy |
251 | 251 | ); |
252 | 252 | |
253 | - if ( ! $arg instanceof WordPoints_EntityishI ) { |
|
253 | + if ( ! $arg instanceof WordPoints_EntityishI) { |
|
254 | 254 | continue; |
255 | 255 | } |
256 | 256 | |
257 | - $values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value(); |
|
257 | + $values[implode('.', $arg_hierarchy)] = $arg->get_the_value(); |
|
258 | 258 | } |
259 | 259 | |
260 | - ksort( $values ); |
|
260 | + ksort($values); |
|
261 | 261 | |
262 | 262 | return $values; |
263 | 263 | } |
@@ -271,11 +271,11 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return object|false The period data, or false if not found. |
273 | 273 | */ |
274 | - protected function get_period( $period_id ) { |
|
274 | + protected function get_period($period_id) { |
|
275 | 275 | |
276 | - $period = wp_cache_get( $period_id, 'wordpoints_hook_periods' ); |
|
276 | + $period = wp_cache_get($period_id, 'wordpoints_hook_periods'); |
|
277 | 277 | |
278 | - if ( ! $period ) { |
|
278 | + if ( ! $period) { |
|
279 | 279 | |
280 | 280 | global $wpdb; |
281 | 281 | |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | - if ( ! $period ) { |
|
295 | + if ( ! $period) { |
|
296 | 296 | return false; |
297 | 297 | } |
298 | 298 | |
299 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
299 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | return $period; |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | |
321 | 321 | $reaction_guid = $reaction->get_guid(); |
322 | 322 | |
323 | - $cache_key = wp_json_encode( $reaction_guid ) . "-{$signature}"; |
|
323 | + $cache_key = wp_json_encode($reaction_guid)."-{$signature}"; |
|
324 | 324 | |
325 | 325 | // Before we run the query, we try to lookup the ID in the cache. |
326 | - $period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids_by_reaction' ); |
|
326 | + $period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids_by_reaction'); |
|
327 | 327 | |
328 | 328 | // If we found it, we can retrieve the period by ID instead. |
329 | - if ( $period_id ) { |
|
330 | - return $this->get_period( $period_id ); |
|
329 | + if ($period_id) { |
|
330 | + return $this->get_period($period_id); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | global $wpdb; |
@@ -351,17 +351,17 @@ discard block |
||
351 | 351 | , $signature |
352 | 352 | , $reaction_guid['reactor'] |
353 | 353 | , $reaction_guid['group'] |
354 | - , wp_json_encode( $reaction_guid['context_id'] ) |
|
354 | + , wp_json_encode($reaction_guid['context_id']) |
|
355 | 355 | , $reaction_guid['id'] |
356 | 356 | ) |
357 | 357 | ); |
358 | 358 | |
359 | - if ( ! $period ) { |
|
359 | + if ( ! $period) { |
|
360 | 360 | return false; |
361 | 361 | } |
362 | 362 | |
363 | - wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction' ); |
|
364 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
363 | + wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction'); |
|
364 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
365 | 365 | |
366 | 366 | return $period; |
367 | 367 | } |
@@ -369,20 +369,20 @@ discard block |
||
369 | 369 | /** |
370 | 370 | * @since 1.0.0 |
371 | 371 | */ |
372 | - public function after_hit( WordPoints_Hook_Fire $fire ) { |
|
372 | + public function after_hit(WordPoints_Hook_Fire $fire) { |
|
373 | 373 | |
374 | - $periods = $fire->reaction->get_meta( 'periods' ); |
|
374 | + $periods = $fire->reaction->get_meta('periods'); |
|
375 | 375 | |
376 | - if ( empty( $periods ) ) { |
|
376 | + if (empty($periods)) { |
|
377 | 377 | return; |
378 | 378 | } |
379 | 379 | |
380 | 380 | $this->event_args = $fire->event_args; |
381 | 381 | |
382 | - foreach ( $periods as $settings ) { |
|
382 | + foreach ($periods as $settings) { |
|
383 | 383 | |
384 | 384 | $this->add_period( |
385 | - $this->get_period_signature( $settings, $fire->reaction ) |
|
385 | + $this->get_period_signature($settings, $fire->reaction) |
|
386 | 386 | , $fire |
387 | 387 | ); |
388 | 388 | } |
@@ -407,14 +407,14 @@ discard block |
||
407 | 407 | WordPoints_Hook_ReactionI $reaction |
408 | 408 | ) { |
409 | 409 | |
410 | - if ( isset( $settings['args'] ) ) { |
|
410 | + if (isset($settings['args'])) { |
|
411 | 411 | $period_args = $settings['args']; |
412 | 412 | } else { |
413 | - $period_args = array( $reaction->get_meta( 'target' ) ); |
|
413 | + $period_args = array($reaction->get_meta('target')); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | return wordpoints_hash( |
417 | - wp_json_encode( $this->get_arg_values( $period_args ) ) |
|
417 | + wp_json_encode($this->get_arg_values($period_args)) |
|
418 | 418 | ); |
419 | 419 | } |
420 | 420 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * |
429 | 429 | * @return false|object The period data, or false if not found. |
430 | 430 | */ |
431 | - protected function add_period( $signature, WordPoints_Hook_Fire $fire ) { |
|
431 | + protected function add_period($signature, WordPoints_Hook_Fire $fire) { |
|
432 | 432 | |
433 | 433 | global $wpdb; |
434 | 434 | |
@@ -438,17 +438,17 @@ discard block |
||
438 | 438 | 'hit_id' => $fire->hit_id, |
439 | 439 | 'signature' => $signature, |
440 | 440 | ) |
441 | - , array( '%d', '%s' ) |
|
441 | + , array('%d', '%s') |
|
442 | 442 | ); |
443 | 443 | |
444 | - if ( ! $inserted ) { |
|
444 | + if ( ! $inserted) { |
|
445 | 445 | return false; |
446 | 446 | } |
447 | 447 | |
448 | 448 | $period_id = $wpdb->insert_id; |
449 | 449 | |
450 | 450 | wp_cache_set( |
451 | - wp_json_encode( $fire->reaction->get_guid() ) . "-{$signature}" |
|
451 | + wp_json_encode($fire->reaction->get_guid())."-{$signature}" |
|
452 | 452 | , $period_id |
453 | 453 | , 'wordpoints_hook_period_ids_by_reaction' |
454 | 454 | ); |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function get_settings_fields() { |
55 | 55 | |
56 | - $this->settings_fields['points']['label'] = _x( 'Points', 'form label', 'wordpoints' ); |
|
57 | - $this->settings_fields['log_text']['label'] = _x( 'Log Text', 'form label', 'wordpoints' ); |
|
58 | - $this->settings_fields['description']['label'] = _x( 'Description', 'form label', 'wordpoints' ); |
|
56 | + $this->settings_fields['points']['label'] = _x('Points', 'form label', 'wordpoints'); |
|
57 | + $this->settings_fields['log_text']['label'] = _x('Log Text', 'form label', 'wordpoints'); |
|
58 | + $this->settings_fields['description']['label'] = _x('Description', 'form label', 'wordpoints'); |
|
59 | 59 | |
60 | 60 | return parent::get_settings_fields(); |
61 | 61 | } |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | |
68 | 68 | $data = parent::get_ui_script_data(); |
69 | 69 | |
70 | - $data['target_label'] = __( 'Award To', 'wordpoints' ); |
|
71 | - $data['periods_label'] = __( 'Award each user no more than once per:', 'wordpoints' ); |
|
70 | + $data['target_label'] = __('Award To', 'wordpoints'); |
|
71 | + $data['periods_label'] = __('Award each user no more than once per:', 'wordpoints'); |
|
72 | 72 | |
73 | 73 | return $data; |
74 | 74 | } |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | WordPoints_Hook_Event_Args $event_args |
83 | 83 | ) { |
84 | 84 | |
85 | - if ( ! isset( $settings['points'] ) || false === wordpoints_int( $settings['points'] ) ) { |
|
86 | - $validator->add_error( __( 'Points must be an integer.', 'wordpoints' ), 'points' ); |
|
85 | + if ( ! isset($settings['points']) || false === wordpoints_int($settings['points'])) { |
|
86 | + $validator->add_error(__('Points must be an integer.', 'wordpoints'), 'points'); |
|
87 | 87 | } |
88 | 88 | |
89 | - if ( ! isset( $settings['points_type'] ) || ! wordpoints_is_points_type( $settings['points_type'] ) ) { |
|
90 | - $validator->add_error( __( 'Invalid points type.', 'wordpoints' ), 'points_type' ); |
|
89 | + if ( ! isset($settings['points_type']) || ! wordpoints_is_points_type($settings['points_type'])) { |
|
90 | + $validator->add_error(__('Invalid points type.', 'wordpoints'), 'points_type'); |
|
91 | 91 | } |
92 | 92 | |
93 | - if ( ! isset( $settings['description'] ) ) { |
|
94 | - $validator->add_error( __( 'Description is required.', 'wordpoints' ), 'description' ); |
|
93 | + if ( ! isset($settings['description'])) { |
|
94 | + $validator->add_error(__('Description is required.', 'wordpoints'), 'description'); |
|
95 | 95 | } |
96 | 96 | |
97 | - if ( ! isset( $settings['log_text'] ) ) { |
|
98 | - $validator->add_error( __( 'Log Text is required.', 'wordpoints' ), 'log_text' ); |
|
97 | + if ( ! isset($settings['log_text'])) { |
|
98 | + $validator->add_error(__('Log Text is required.', 'wordpoints'), 'log_text'); |
|
99 | 99 | } |
100 | 100 | |
101 | - return parent::validate_settings( $settings, $validator, $event_args ); |
|
101 | + return parent::validate_settings($settings, $validator, $event_args); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,49 +109,49 @@ discard block |
||
109 | 109 | array $settings |
110 | 110 | ) { |
111 | 111 | |
112 | - parent::update_settings( $reaction, $settings ); |
|
112 | + parent::update_settings($reaction, $settings); |
|
113 | 113 | |
114 | - $reaction->update_meta( 'points', $settings['points'] ); |
|
115 | - $reaction->update_meta( 'points_type', $settings['points_type'] ); |
|
116 | - $reaction->update_meta( 'description', $settings['description'] ); |
|
117 | - $reaction->update_meta( 'log_text', $settings['log_text'] ); |
|
114 | + $reaction->update_meta('points', $settings['points']); |
|
115 | + $reaction->update_meta('points_type', $settings['points_type']); |
|
116 | + $reaction->update_meta('description', $settings['description']); |
|
117 | + $reaction->update_meta('log_text', $settings['log_text']); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
121 | 121 | * @since 1.0.0 |
122 | 122 | */ |
123 | - public function hit( WordPoints_Hook_Fire $fire ) { |
|
123 | + public function hit(WordPoints_Hook_Fire $fire) { |
|
124 | 124 | |
125 | 125 | $reaction = $fire->reaction; |
126 | 126 | |
127 | 127 | $target = $fire->event_args->get_from_hierarchy( |
128 | - $reaction->get_meta( 'target' ) |
|
128 | + $reaction->get_meta('target') |
|
129 | 129 | ); |
130 | 130 | |
131 | - if ( ! $target instanceof WordPoints_Entity ) { |
|
131 | + if ( ! $target instanceof WordPoints_Entity) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | 135 | $meta = array(); |
136 | 136 | |
137 | - foreach ( $fire->event_args->get_entities() as $entity ) { |
|
138 | - $meta[ $entity->get_slug() ] = $entity->get_the_id(); |
|
137 | + foreach ($fire->event_args->get_entities() as $entity) { |
|
138 | + $meta[$entity->get_slug()] = $entity->get_the_id(); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | wordpoints_alter_points( |
142 | 142 | $target->get_the_id() |
143 | - , $reaction->get_meta( 'points' ) |
|
144 | - , $reaction->get_meta( 'points_type' ) |
|
143 | + , $reaction->get_meta('points') |
|
144 | + , $reaction->get_meta('points_type') |
|
145 | 145 | , $reaction->get_event_slug() |
146 | 146 | , $meta |
147 | - , $reaction->get_meta( 'log_text' ) |
|
147 | + , $reaction->get_meta('log_text') |
|
148 | 148 | ); |
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
152 | 152 | * @since 1.0.0 |
153 | 153 | */ |
154 | - public function reverse_hit( WordPoints_Hook_Fire $fire ) { |
|
154 | + public function reverse_hit(WordPoints_Hook_Fire $fire) { |
|
155 | 155 | |
156 | 156 | $meta_queries = array( |
157 | 157 | array( |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | ), |
163 | 163 | ); |
164 | 164 | |
165 | - foreach ( $fire->event_args->get_entities() as $slug => $entity ) { |
|
165 | + foreach ($fire->event_args->get_entities() as $slug => $entity) { |
|
166 | 166 | |
167 | 167 | $meta_queries[] = array( |
168 | 168 | 'key' => $slug, |
@@ -179,35 +179,35 @@ discard block |
||
179 | 179 | |
180 | 180 | $logs = $query->get(); |
181 | 181 | |
182 | - if ( ! $logs ) { |
|
182 | + if ( ! $logs) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | |
186 | 186 | global $wpdb; |
187 | 187 | |
188 | - add_filter( 'wordpoints_points_log', '__return_false' ); |
|
188 | + add_filter('wordpoints_points_log', '__return_false'); |
|
189 | 189 | |
190 | - foreach ( $logs as $log ) { |
|
190 | + foreach ($logs as $log) { |
|
191 | 191 | |
192 | 192 | wordpoints_alter_points( |
193 | 193 | $log->user_id |
194 | 194 | , -$log->points |
195 | 195 | , $log->points_type |
196 | 196 | , "reverse-{$log->log_type}" |
197 | - , array( 'original_log_id' => $log->id ) |
|
197 | + , array('original_log_id' => $log->id) |
|
198 | 198 | ); |
199 | 199 | |
200 | - wordpoints_points_log_delete_all_metadata( $log->id ); |
|
200 | + wordpoints_points_log_delete_all_metadata($log->id); |
|
201 | 201 | |
202 | 202 | // Now delete the log. |
203 | 203 | $wpdb->delete( |
204 | 204 | $wpdb->wordpoints_points_logs |
205 | - , array( 'id' => $log->id ) |
|
205 | + , array('id' => $log->id) |
|
206 | 206 | , '%d' |
207 | 207 | ); // WPCS: cache OK, cleaned by wordpoints_alter_points(). |
208 | 208 | } |
209 | 209 | |
210 | - remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
210 | + remove_filter('wordpoints_points_log', '__return_false'); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | ) { |
97 | 97 | |
98 | 98 | return 'wordpoints_create_hook_reaction' |
99 | - . '|' . $reactor->get_slug() |
|
100 | - . '|' . wordpoints_hooks()->get_current_mode() |
|
101 | - . '|' . wp_json_encode( $reactor->reactions->get_context_id() ); |
|
99 | + . '|' . $reactor->get_slug() |
|
100 | + . '|' . wordpoints_hooks()->get_current_mode() |
|
101 | + . '|' . wp_json_encode( $reactor->reactions->get_context_id() ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | WordPoints_Hook_ReactionI $reaction |
129 | 129 | ) { |
130 | 130 | return 'wordpoints_update_hook_reaction|' |
131 | - . wp_json_encode( $reaction->get_guid() ); |
|
131 | + . wp_json_encode( $reaction->get_guid() ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | WordPoints_Hook_ReactionI $reaction |
159 | 159 | ) { |
160 | 160 | return 'wordpoints_delete_hook_reaction|' |
161 | - . wp_json_encode( $reaction->get_guid() ); |
|
161 | + . wp_json_encode( $reaction->get_guid() ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return array The hook reaction data extracted into an array. |
54 | 54 | */ |
55 | - public static function prepare_hook_reaction( WordPoints_Hook_ReactionI $reaction ) { |
|
55 | + public static function prepare_hook_reaction(WordPoints_Hook_ReactionI $reaction) { |
|
56 | 56 | |
57 | 57 | return array_merge( |
58 | 58 | $reaction->get_all_meta() |
@@ -60,8 +60,8 @@ discard block |
||
60 | 60 | 'id' => $reaction->ID, |
61 | 61 | 'event' => $reaction->get_event_slug(), |
62 | 62 | 'reactor' => $reaction->get_reactor_slug(), |
63 | - 'nonce' => self::get_update_nonce( $reaction ), |
|
64 | - 'delete_nonce' => self::get_delete_nonce( $reaction ), |
|
63 | + 'nonce' => self::get_update_nonce($reaction), |
|
64 | + 'delete_nonce' => self::get_delete_nonce($reaction), |
|
65 | 65 | ) |
66 | 66 | ); |
67 | 67 | } |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return string A nonce for creating a new reaction to this reactor. |
78 | 78 | */ |
79 | - public static function get_create_nonce( WordPoints_Hook_Reactor $reactor ) { |
|
79 | + public static function get_create_nonce(WordPoints_Hook_Reactor $reactor) { |
|
80 | 80 | |
81 | - return wp_create_nonce( self::get_create_nonce_action( $reactor ) ); |
|
81 | + return wp_create_nonce(self::get_create_nonce_action($reactor)); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | ) { |
97 | 97 | |
98 | 98 | return 'wordpoints_create_hook_reaction' |
99 | - . '|' . $reactor->get_slug() |
|
100 | - . '|' . wordpoints_hooks()->get_current_mode() |
|
101 | - . '|' . wp_json_encode( $reactor->reactions->get_context_id() ); |
|
99 | + . '|'.$reactor->get_slug() |
|
100 | + . '|'.wordpoints_hooks()->get_current_mode() |
|
101 | + . '|'.wp_json_encode($reactor->reactions->get_context_id()); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return string A nonce for updating this reaction. |
112 | 112 | */ |
113 | - public static function get_update_nonce( WordPoints_Hook_ReactionI $reaction ) { |
|
113 | + public static function get_update_nonce(WordPoints_Hook_ReactionI $reaction) { |
|
114 | 114 | |
115 | - return wp_create_nonce( self::get_update_nonce_action( $reaction ) ); |
|
115 | + return wp_create_nonce(self::get_update_nonce_action($reaction)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | WordPoints_Hook_ReactionI $reaction |
129 | 129 | ) { |
130 | 130 | return 'wordpoints_update_hook_reaction|' |
131 | - . wp_json_encode( $reaction->get_guid() ); |
|
131 | + . wp_json_encode($reaction->get_guid()); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return string A nonce for deleting this reaction. |
142 | 142 | */ |
143 | - public static function get_delete_nonce( WordPoints_Hook_ReactionI $reaction ) { |
|
143 | + public static function get_delete_nonce(WordPoints_Hook_ReactionI $reaction) { |
|
144 | 144 | |
145 | - return wp_create_nonce( self::get_delete_nonce_action( $reaction ) ); |
|
145 | + return wp_create_nonce(self::get_delete_nonce_action($reaction)); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | WordPoints_Hook_ReactionI $reaction |
159 | 159 | ) { |
160 | 160 | return 'wordpoints_delete_hook_reaction|' |
161 | - . wp_json_encode( $reaction->get_guid() ); |
|
161 | + . wp_json_encode($reaction->get_guid()); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // |
@@ -184,17 +184,17 @@ discard block |
||
184 | 184 | |
185 | 185 | add_action( |
186 | 186 | 'wp_ajax_wordpoints_admin_create_hook_reaction' |
187 | - , array( $this, 'create_hook_reaction' ) |
|
187 | + , array($this, 'create_hook_reaction') |
|
188 | 188 | ); |
189 | 189 | |
190 | 190 | add_action( |
191 | 191 | 'wp_ajax_wordpoints_admin_update_hook_reaction' |
192 | - , array( $this, 'update_hook_reaction' ) |
|
192 | + , array($this, 'update_hook_reaction') |
|
193 | 193 | ); |
194 | 194 | |
195 | 195 | add_action( |
196 | 196 | 'wp_ajax_wordpoints_admin_delete_hook_reaction' |
197 | - , array( $this, 'delete_hook_reaction' ) |
|
197 | + , array($this, 'delete_hook_reaction') |
|
198 | 198 | ); |
199 | 199 | } |
200 | 200 | |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | |
210 | 210 | $reactor = $this->get_reactor(); |
211 | 211 | |
212 | - $this->verify_request( $this->get_create_nonce_action( $reactor ) ); |
|
212 | + $this->verify_request($this->get_create_nonce_action($reactor)); |
|
213 | 213 | |
214 | - $reaction = $reactor->reactions->create_reaction( $this->get_data() ); |
|
214 | + $reaction = $reactor->reactions->create_reaction($this->get_data()); |
|
215 | 215 | |
216 | - $this->send_json_result( $reaction, 'create' ); |
|
216 | + $this->send_json_result($reaction, 'create'); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -228,14 +228,14 @@ discard block |
||
228 | 228 | $reactor = $this->get_reactor(); |
229 | 229 | $reaction = $this->get_reaction(); |
230 | 230 | |
231 | - $this->verify_request( $this->get_update_nonce_action( $reaction ) ); |
|
231 | + $this->verify_request($this->get_update_nonce_action($reaction)); |
|
232 | 232 | |
233 | 233 | $reaction = $reactor->reactions->update_reaction( |
234 | 234 | $reaction->ID |
235 | 235 | , $this->get_data() |
236 | 236 | ); |
237 | 237 | |
238 | - $this->send_json_result( $reaction, 'update' ); |
|
238 | + $this->send_json_result($reaction, 'update'); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -250,12 +250,12 @@ discard block |
||
250 | 250 | $reactor = $this->get_reactor(); |
251 | 251 | $reaction = $this->get_reaction(); |
252 | 252 | |
253 | - $this->verify_request( $this->get_delete_nonce_action( $reaction ) ); |
|
253 | + $this->verify_request($this->get_delete_nonce_action($reaction)); |
|
254 | 254 | |
255 | - $result = $reactor->reactions->delete_reaction( $reaction->ID ); |
|
255 | + $result = $reactor->reactions->delete_reaction($reaction->ID); |
|
256 | 256 | |
257 | - if ( ! $result ) { |
|
258 | - wp_send_json_error( array( 'message' => __( 'There was an error deleting the reaction. Please try again.', 'wordpoints' ) ) ); |
|
257 | + if ( ! $result) { |
|
258 | + wp_send_json_error(array('message' => __('There was an error deleting the reaction. Please try again.', 'wordpoints'))); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | wp_send_json_success(); |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @param string $debug_context Context sent with the message (for debugging). |
278 | 278 | */ |
279 | - private function unexpected_error( $debug_context ) { |
|
279 | + private function unexpected_error($debug_context) { |
|
280 | 280 | |
281 | 281 | wp_send_json_error( |
282 | 282 | array( |
283 | - 'message' => __( 'There was an unexpected error. Try reloading the page.', 'wordpoints' ), |
|
283 | + 'message' => __('There was an unexpected error. Try reloading the page.', 'wordpoints'), |
|
284 | 284 | 'debug' => $debug_context, |
285 | 285 | ) |
286 | 286 | ); |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | */ |
297 | 297 | private function verify_user_can() { |
298 | 298 | |
299 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
300 | - wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action. Maybe you have been logged out?', 'wordpoints' ) ) ); |
|
299 | + if ( ! current_user_can('manage_options')) { |
|
300 | + wp_send_json_error(array('message' => __('You do not have permission to perform this action. Maybe you have been logged out?', 'wordpoints'))); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
@@ -310,14 +310,14 @@ discard block |
||
310 | 310 | * |
311 | 311 | * @param string $action The action the nonce should be for. |
312 | 312 | */ |
313 | - private function verify_request( $action ) { |
|
313 | + private function verify_request($action) { |
|
314 | 314 | |
315 | 315 | if ( |
316 | - empty( $_POST['nonce'] ) |
|
317 | - || ! wordpoints_verify_nonce( 'nonce', $action, null, 'post' ) |
|
316 | + empty($_POST['nonce']) |
|
317 | + || ! wordpoints_verify_nonce('nonce', $action, null, 'post') |
|
318 | 318 | ) { |
319 | 319 | wp_send_json_error( |
320 | - array( 'message' => __( 'Your security token for this action has expired. Refresh the page and try again.', 'wordpoints' ) ) |
|
320 | + array('message' => __('Your security token for this action has expired. Refresh the page and try again.', 'wordpoints')) |
|
321 | 321 | ); |
322 | 322 | } |
323 | 323 | } |
@@ -331,16 +331,16 @@ discard block |
||
331 | 331 | */ |
332 | 332 | protected function get_reactor() { |
333 | 333 | |
334 | - if ( ! isset( $_POST['reactor'] ) ) { // WPCS: CSRF OK. |
|
335 | - $this->unexpected_error( 'reactor' ); |
|
334 | + if ( ! isset($_POST['reactor'])) { // WPCS: CSRF OK. |
|
335 | + $this->unexpected_error('reactor'); |
|
336 | 336 | } |
337 | 337 | |
338 | - $reactor_slug = sanitize_key( $_POST['reactor'] ); // WPCS: CSRF OK. |
|
338 | + $reactor_slug = sanitize_key($_POST['reactor']); // WPCS: CSRF OK. |
|
339 | 339 | |
340 | - $reactor = wordpoints_hooks()->reactors->get( $reactor_slug ); |
|
340 | + $reactor = wordpoints_hooks()->reactors->get($reactor_slug); |
|
341 | 341 | |
342 | - if ( ! $reactor instanceof WordPoints_Hook_Reactor ) { |
|
343 | - $this->unexpected_error( 'reactor_invalid' ); |
|
342 | + if ( ! $reactor instanceof WordPoints_Hook_Reactor) { |
|
343 | + $this->unexpected_error('reactor_invalid'); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | $this->reactor_slug = $reactor_slug; |
@@ -358,16 +358,16 @@ discard block |
||
358 | 358 | */ |
359 | 359 | protected function get_reaction() { |
360 | 360 | |
361 | - if ( ! isset( $_POST['id'] ) ) { // WPCS: CSRF OK. |
|
362 | - $this->unexpected_error( 'id' ); |
|
361 | + if ( ! isset($_POST['id'])) { // WPCS: CSRF OK. |
|
362 | + $this->unexpected_error('id'); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | $reaction = $this->reactor->reactions->get_reaction( |
366 | - wordpoints_int( $_POST['id'] ) // WPCS: CSRF OK. |
|
366 | + wordpoints_int($_POST['id']) // WPCS: CSRF OK. |
|
367 | 367 | ); |
368 | 368 | |
369 | - if ( ! $reaction ) { |
|
370 | - wp_send_json_error( array( 'message' => __( 'The reaction ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints' ) ) ); |
|
369 | + if ( ! $reaction) { |
|
370 | + wp_send_json_error(array('message' => __('The reaction ID passed to the server is invalid. Perhaps it has been deleted. Try reloading the page.', 'wordpoints'))); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | return $reaction; |
@@ -382,9 +382,9 @@ discard block |
||
382 | 382 | */ |
383 | 383 | protected function get_data() { |
384 | 384 | |
385 | - $data = wp_unslash( $_POST ); // WPCS: CSRF OK. |
|
385 | + $data = wp_unslash($_POST); // WPCS: CSRF OK. |
|
386 | 386 | |
387 | - unset( $data['id'], $data['action'], $data['nonce'], $data['reactor'] ); |
|
387 | + unset($data['id'], $data['action'], $data['nonce'], $data['reactor']); |
|
388 | 388 | |
389 | 389 | return $data; |
390 | 390 | } |
@@ -397,30 +397,30 @@ discard block |
||
397 | 397 | * @param mixed $result The result of the action. |
398 | 398 | * @param string $action The action being performed: 'create' or 'update'. |
399 | 399 | */ |
400 | - private function send_json_result( $result, $action ) { |
|
400 | + private function send_json_result($result, $action) { |
|
401 | 401 | |
402 | - if ( ! $result ) { |
|
402 | + if ( ! $result) { |
|
403 | 403 | |
404 | - if ( 'create' === $action ) { |
|
405 | - $message = __( 'There was an error adding the reaction. Please try again.', 'wordpoints' ); |
|
404 | + if ('create' === $action) { |
|
405 | + $message = __('There was an error adding the reaction. Please try again.', 'wordpoints'); |
|
406 | 406 | } else { |
407 | - $message = __( 'There was an error updating the reaction. Please try again.', 'wordpoints' ); |
|
407 | + $message = __('There was an error updating the reaction. Please try again.', 'wordpoints'); |
|
408 | 408 | } |
409 | 409 | |
410 | - wp_send_json_error( array( 'message' => $message ) ); |
|
410 | + wp_send_json_error(array('message' => $message)); |
|
411 | 411 | |
412 | - } elseif ( $result instanceof WordPoints_Hook_Reaction_Validator ) { |
|
412 | + } elseif ($result instanceof WordPoints_Hook_Reaction_Validator) { |
|
413 | 413 | |
414 | - wp_send_json_error( array( 'errors' => $result->get_errors() ) ); |
|
414 | + wp_send_json_error(array('errors' => $result->get_errors())); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $data = null; |
418 | 418 | |
419 | - if ( 'create' === $action ) { |
|
420 | - $data = self::prepare_hook_reaction( $result ); |
|
419 | + if ('create' === $action) { |
|
420 | + $data = self::prepare_hook_reaction($result); |
|
421 | 421 | } |
422 | 422 | |
423 | - wp_send_json_success( $data ); |
|
423 | + wp_send_json_success($data); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 |