@@ -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; |
@@ -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,13 +39,13 @@ 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 | 47 | // TODO this should be supplied per-reactor |
48 | - 'label' => __( 'Award each user no more than once per:', 'wordpoints' ), |
|
48 | + 'label' => __('Award each user no more than once per:', 'wordpoints'), |
|
49 | 49 | ), |
50 | 50 | ); |
51 | 51 | } |
@@ -59,25 +59,25 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return array The validated periods. |
61 | 61 | */ |
62 | - protected function validate_periods( $periods ) { |
|
62 | + protected function validate_periods($periods) { |
|
63 | 63 | |
64 | - if ( ! is_array( $periods ) ) { |
|
64 | + if ( ! is_array($periods)) { |
|
65 | 65 | |
66 | 66 | $this->validator->add_error( |
67 | - __( 'Periods do not match expected format.', 'wordpoints' ) |
|
67 | + __('Periods do not match expected format.', 'wordpoints') |
|
68 | 68 | ); |
69 | 69 | |
70 | 70 | return array(); |
71 | 71 | } |
72 | 72 | |
73 | - foreach ( $periods as $index => $period ) { |
|
73 | + foreach ($periods as $index => $period) { |
|
74 | 74 | |
75 | - $this->validator->push_field( $index ); |
|
75 | + $this->validator->push_field($index); |
|
76 | 76 | |
77 | - $period = $this->validate_period( $period ); |
|
77 | + $period = $this->validate_period($period); |
|
78 | 78 | |
79 | - if ( $period ) { |
|
80 | - $periods[ $index ] = $period; |
|
79 | + if ($period) { |
|
80 | + $periods[$index] = $period; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $this->validator->pop_field(); |
@@ -95,30 +95,30 @@ discard block |
||
95 | 95 | * |
96 | 96 | * @return array|false The validated period, or false if invalid. |
97 | 97 | */ |
98 | - protected function validate_period( $period ) { |
|
98 | + protected function validate_period($period) { |
|
99 | 99 | |
100 | - if ( ! is_array( $period ) ) { |
|
100 | + if ( ! is_array($period)) { |
|
101 | 101 | $this->validator->add_error( |
102 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
102 | + __('Period does not match expected format.', 'wordpoints') |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | |
108 | - if ( isset( $period['args'] ) ) { |
|
109 | - $this->validate_period_args( $period['args'] ); |
|
108 | + if (isset($period['args'])) { |
|
109 | + $this->validate_period_args($period['args']); |
|
110 | 110 | } |
111 | 111 | |
112 | - if ( ! isset( $period['length'] ) ) { |
|
112 | + if ( ! isset($period['length'])) { |
|
113 | 113 | |
114 | 114 | $this->validator->add_error( |
115 | - __( 'Period length setting is missing.', 'wordpoints' ) |
|
115 | + __('Period length setting is missing.', 'wordpoints') |
|
116 | 116 | ); |
117 | 117 | |
118 | - } elseif ( false === wordpoints_posint( $period['length'] ) ) { |
|
118 | + } elseif (false === wordpoints_posint($period['length'])) { |
|
119 | 119 | |
120 | 120 | $this->validator->add_error( |
121 | - __( 'Period length must be a positive integer.', 'wordpoints' ) |
|
121 | + __('Period length must be a positive integer.', 'wordpoints') |
|
122 | 122 | , 'length' |
123 | 123 | ); |
124 | 124 | |
@@ -135,34 +135,34 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @param mixed $args The args the period is related to. |
137 | 137 | */ |
138 | - protected function validate_period_args( $args ) { |
|
138 | + protected function validate_period_args($args) { |
|
139 | 139 | |
140 | - if ( ! is_array( $args ) ) { |
|
140 | + if ( ! is_array($args)) { |
|
141 | 141 | |
142 | 142 | $this->validator->add_error( |
143 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
143 | + __('Period does not match expected format.', 'wordpoints') |
|
144 | 144 | , 'args' |
145 | 145 | ); |
146 | 146 | |
147 | 147 | return; |
148 | 148 | } |
149 | 149 | |
150 | - $this->validator->push_field( 'args' ); |
|
150 | + $this->validator->push_field('args'); |
|
151 | 151 | |
152 | - foreach ( $args as $index => $hierarchy ) { |
|
152 | + foreach ($args as $index => $hierarchy) { |
|
153 | 153 | |
154 | - $this->validator->push_field( $index ); |
|
154 | + $this->validator->push_field($index); |
|
155 | 155 | |
156 | - if ( ! is_array( $hierarchy ) ) { |
|
156 | + if ( ! is_array($hierarchy)) { |
|
157 | 157 | |
158 | 158 | $this->validator->add_error( |
159 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
159 | + __('Period does not match expected format.', 'wordpoints') |
|
160 | 160 | ); |
161 | 161 | |
162 | - } elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) { |
|
162 | + } elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) { |
|
163 | 163 | |
164 | 164 | $this->validator->add_error( |
165 | - __( 'Invalid period.', 'wordpoints' ) // TODO better error message |
|
165 | + __('Invalid period.', 'wordpoints') // TODO better error message |
|
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @since 1.0.0 |
177 | 177 | */ |
178 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
178 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
179 | 179 | |
180 | - $periods = $fire->reaction->get_meta( 'periods' ); |
|
180 | + $periods = $fire->reaction->get_meta('periods'); |
|
181 | 181 | |
182 | - if ( empty( $periods ) ) { |
|
182 | + if (empty($periods)) { |
|
183 | 183 | return true; |
184 | 184 | } |
185 | 185 | |
186 | 186 | $this->event_args = $fire->event_args; |
187 | 187 | |
188 | - foreach ( $periods as $period ) { |
|
189 | - if ( ! $this->has_period_ended( $period, $fire->reaction ) ) { |
|
188 | + foreach ($periods as $period) { |
|
189 | + if ( ! $this->has_period_ended($period, $fire->reaction)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | } |
@@ -210,24 +210,24 @@ discard block |
||
210 | 210 | ) { |
211 | 211 | |
212 | 212 | $period = $this->get_period_by_reaction( |
213 | - $this->get_period_signature( $settings, $reaction ) |
|
213 | + $this->get_period_signature($settings, $reaction) |
|
214 | 214 | , $reaction |
215 | 215 | ); |
216 | 216 | |
217 | 217 | // If the period isn't found, we know that we can still fire. |
218 | - if ( ! $period ) { |
|
218 | + if ( ! $period) { |
|
219 | 219 | return true; |
220 | 220 | } |
221 | 221 | |
222 | - $now = current_time( 'timestamp' ); |
|
223 | - $hit_time = strtotime( $period->hit_time, $now ); |
|
222 | + $now = current_time('timestamp'); |
|
223 | + $hit_time = strtotime($period->hit_time, $now); |
|
224 | 224 | |
225 | - if ( ! empty( $settings['relative'] ) ) { |
|
226 | - return ( $hit_time < $now - $settings['length'] ); |
|
225 | + if ( ! empty($settings['relative'])) { |
|
226 | + return ($hit_time < $now - $settings['length']); |
|
227 | 227 | } else { |
228 | 228 | return ( |
229 | - (int) ( $hit_time / $settings['length'] ) |
|
230 | - < (int) ( $now / $settings['length'] ) |
|
229 | + (int) ($hit_time / $settings['length']) |
|
230 | + < (int) ($now / $settings['length']) |
|
231 | 231 | ); |
232 | 232 | } |
233 | 233 | } |
@@ -241,24 +241,24 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return array The arg values. |
243 | 243 | */ |
244 | - protected function get_arg_values( array $period_args ) { |
|
244 | + protected function get_arg_values(array $period_args) { |
|
245 | 245 | |
246 | 246 | $values = array(); |
247 | 247 | |
248 | - foreach ( $period_args as $arg_hierarchy ) { |
|
248 | + foreach ($period_args as $arg_hierarchy) { |
|
249 | 249 | |
250 | 250 | $arg = $this->event_args->get_from_hierarchy( |
251 | 251 | $arg_hierarchy |
252 | 252 | ); |
253 | 253 | |
254 | - if ( ! $arg instanceof WordPoints_EntityishI ) { |
|
254 | + if ( ! $arg instanceof WordPoints_EntityishI) { |
|
255 | 255 | continue; |
256 | 256 | } |
257 | 257 | |
258 | - $values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value(); |
|
258 | + $values[implode('.', $arg_hierarchy)] = $arg->get_the_value(); |
|
259 | 259 | } |
260 | 260 | |
261 | - ksort( $values ); |
|
261 | + ksort($values); |
|
262 | 262 | |
263 | 263 | return $values; |
264 | 264 | } |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return object|false The period data, or false if not found. |
274 | 274 | */ |
275 | - protected function get_period( $period_id ) { |
|
275 | + protected function get_period($period_id) { |
|
276 | 276 | |
277 | - $period = wp_cache_get( $period_id, 'wordpoints_hook_period' ); |
|
277 | + $period = wp_cache_get($period_id, 'wordpoints_hook_period'); |
|
278 | 278 | |
279 | - if ( ! $period ) { |
|
279 | + if ( ! $period) { |
|
280 | 280 | |
281 | 281 | global $wpdb; |
282 | 282 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | ) |
292 | 292 | ); |
293 | 293 | |
294 | - if ( ! $period ) { |
|
294 | + if ( ! $period) { |
|
295 | 295 | return false; |
296 | 296 | } |
297 | 297 | |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | , 'wordpoints_hook_period_ids' |
302 | 302 | ); |
303 | 303 | |
304 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
304 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | return $period; |
@@ -328,11 +328,11 @@ discard block |
||
328 | 328 | $cache_key = "{$reaction_id}-{$signature}"; |
329 | 329 | |
330 | 330 | // Before we run the query, we try to lookup the ID in the cache. |
331 | - $period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids' ); |
|
331 | + $period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids'); |
|
332 | 332 | |
333 | 333 | // If we found it, we can retrieve the period by ID instead. |
334 | - if ( $period_id ) { |
|
335 | - return $this->get_period( $period_id ); |
|
334 | + if ($period_id) { |
|
335 | + return $this->get_period($period_id); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | global $wpdb; |
@@ -353,12 +353,12 @@ discard block |
||
353 | 353 | ) |
354 | 354 | ); |
355 | 355 | |
356 | - if ( ! $period ) { |
|
356 | + if ( ! $period) { |
|
357 | 357 | return false; |
358 | 358 | } |
359 | 359 | |
360 | - wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids' ); |
|
361 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
360 | + wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids'); |
|
361 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
362 | 362 | |
363 | 363 | return $period; |
364 | 364 | } |
@@ -366,20 +366,20 @@ discard block |
||
366 | 366 | /** |
367 | 367 | * @since 1.0.0 |
368 | 368 | */ |
369 | - public function after_hit( WordPoints_Hook_Fire $fire ) { |
|
369 | + public function after_hit(WordPoints_Hook_Fire $fire) { |
|
370 | 370 | |
371 | - $periods = $fire->reaction->get_meta( 'periods' ); |
|
371 | + $periods = $fire->reaction->get_meta('periods'); |
|
372 | 372 | |
373 | - if ( empty( $periods ) ) { |
|
373 | + if (empty($periods)) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | 377 | $this->event_args = $fire->event_args; |
378 | 378 | |
379 | - foreach ( $periods as $settings ) { |
|
379 | + foreach ($periods as $settings) { |
|
380 | 380 | |
381 | 381 | $this->add_period( |
382 | - $this->get_period_signature( $settings, $fire->reaction ) |
|
382 | + $this->get_period_signature($settings, $fire->reaction) |
|
383 | 383 | , $fire->reaction |
384 | 384 | ); |
385 | 385 | } |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | WordPoints_Hook_ReactionI $reaction |
405 | 405 | ) { |
406 | 406 | |
407 | - if ( isset( $settings['args'] ) ) { |
|
407 | + if (isset($settings['args'])) { |
|
408 | 408 | $period_args = $settings['args']; |
409 | 409 | } else { |
410 | - $period_args = array( $reaction->get_meta( 'target' ) ); |
|
410 | + $period_args = array($reaction->get_meta('target')); |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | return wordpoints_hash( |
414 | - wp_json_encode( $this->get_arg_values( $period_args ) ) |
|
414 | + wp_json_encode($this->get_arg_values($period_args)) |
|
415 | 415 | ); |
416 | 416 | } |
417 | 417 | |
@@ -439,12 +439,12 @@ discard block |
||
439 | 439 | , array( |
440 | 440 | 'reaction_id' => $reaction_id, |
441 | 441 | 'signature' => $signature, |
442 | - 'hit_time' => current_time( 'mysql' ), |
|
442 | + 'hit_time' => current_time('mysql'), |
|
443 | 443 | ) |
444 | - , array( '%d', '%s', '%s' ) |
|
444 | + , array('%d', '%s', '%s') |
|
445 | 445 | ); |
446 | 446 | |
447 | - if ( ! $inserted ) { |
|
447 | + if ( ! $inserted) { |
|
448 | 448 | return false; |
449 | 449 | } |
450 | 450 |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $this->firer = $firer; |
85 | 85 | $this->event_args = $event_args; |
86 | 86 | $this->reaction = $reaction; |
87 | - $this->hit_logger = new WordPoints_Hook_Hit_Logger( $this ); |
|
87 | + $this->hit_logger = new WordPoints_Hook_Hit_Logger($this); |
|
88 | 88 | $this->supersedes = $supersedes; |
89 | 89 | } |
90 | 90 | |
@@ -97,11 +97,11 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function hit() { |
99 | 99 | |
100 | - if ( ! $this->hit_id ) { |
|
100 | + if ( ! $this->hit_id) { |
|
101 | 101 | |
102 | 102 | $this->hit_id = $this->hit_logger->log_hit(); |
103 | 103 | |
104 | - if ( ! $this->hit_id ) { |
|
104 | + if ( ! $this->hit_id) { |
|
105 | 105 | return false; |
106 | 106 | } |
107 | 107 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function get_superseded_hit() { |
122 | 122 | |
123 | - if ( isset( $this->supersedes ) ) { |
|
123 | + if (isset($this->supersedes)) { |
|
124 | 124 | return $this->supersedes; |
125 | 125 | } |
126 | 126 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | AND `superseded_by` IS NULL |
141 | 141 | " |
142 | 142 | , $this->firer->get_slug() |
143 | - , wordpoints_hooks_get_event_signature( $this->event_args ) |
|
143 | + , wordpoints_hooks_get_event_signature($this->event_args) |
|
144 | 144 | , $this->reaction->get_event_slug() |
145 | 145 | , $this->reaction->get_reactor_slug() |
146 | 146 | , $this->reaction->get_storage_group_slug() |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | ) |
149 | 149 | ); |
150 | 150 | |
151 | - $this->supersedes = ( $hit ) ? $hit : false; |
|
151 | + $this->supersedes = ($hit) ? $hit : false; |
|
152 | 152 | |
153 | 153 | return $this->supersedes; |
154 | 154 | } |
@@ -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 | } |
@@ -17,39 +17,39 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @since 1.0.0 |
19 | 19 | */ |
20 | - public function do_event( $event_slug, WordPoints_Hook_Event_Args $event_args ) { |
|
20 | + public function do_event($event_slug, WordPoints_Hook_Event_Args $event_args) { |
|
21 | 21 | |
22 | 22 | $hooks = wordpoints_hooks(); |
23 | 23 | |
24 | - foreach ( $this->get_hits( $event_slug, $event_args ) as $hit ) { |
|
24 | + foreach ($this->get_hits($event_slug, $event_args) as $hit) { |
|
25 | 25 | |
26 | - $reactor = $hooks->reactors->get( $hit->reactor ); |
|
26 | + $reactor = $hooks->reactors->get($hit->reactor); |
|
27 | 27 | |
28 | - if ( ! $reactor instanceof WordPoints_Hook_Reactor ) { |
|
28 | + if ( ! $reactor instanceof WordPoints_Hook_Reactor) { |
|
29 | 29 | continue; |
30 | 30 | } |
31 | 31 | |
32 | - $reactions = $reactor->get_reaction_group( $hit->reaction_type ); |
|
32 | + $reactions = $reactor->get_reaction_group($hit->reaction_type); |
|
33 | 33 | |
34 | - if ( ! $reactions ) { |
|
34 | + if ( ! $reactions) { |
|
35 | 35 | continue; |
36 | 36 | } |
37 | 37 | |
38 | - $reaction = $reactions->get_reaction( $hit->reaction_id ); |
|
38 | + $reaction = $reactions->get_reaction($hit->reaction_id); |
|
39 | 39 | |
40 | - if ( ! $reaction ) { |
|
40 | + if ( ! $reaction) { |
|
41 | 41 | continue; |
42 | 42 | } |
43 | 43 | |
44 | - $fire = new WordPoints_Hook_Fire( $this, $event_args, $reaction, $hit ); |
|
44 | + $fire = new WordPoints_Hook_Fire($this, $event_args, $reaction, $hit); |
|
45 | 45 | |
46 | 46 | $fire->hit(); |
47 | 47 | |
48 | - $reactor->reverse_hit( $fire ); |
|
48 | + $reactor->reverse_hit($fire); |
|
49 | 49 | |
50 | 50 | /** @var WordPoints_Hook_Extension $extension */ |
51 | - foreach ( $hooks->extensions->get_all() as $extension ) { |
|
52 | - $extension->after_reverse( $fire ); |
|
51 | + foreach ($hooks->extensions->get_all() as $extension) { |
|
52 | + $extension->after_reverse($fire); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return object[] The data for each hit from the hit logs database table. |
66 | 66 | */ |
67 | - protected function get_hits( $event_slug, WordPoints_Hook_Event_Args $event_args ) { |
|
67 | + protected function get_hits($event_slug, WordPoints_Hook_Event_Args $event_args) { |
|
68 | 68 | |
69 | 69 | global $wpdb; |
70 | 70 | |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | AND `event` = %s |
79 | 79 | AND `superseded_by` IS NULL |
80 | 80 | " |
81 | - , wordpoints_hooks_get_event_signature( $event_args ) |
|
81 | + , wordpoints_hooks_get_event_signature($event_args) |
|
82 | 82 | , $event_slug |
83 | 83 | ) |
84 | 84 | ); |
85 | 85 | |
86 | - if ( ! is_array( $hits ) ) { |
|
86 | + if ( ! is_array($hits)) { |
|
87 | 87 | return array(); |
88 | 88 | } |
89 | 89 |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @param WordPoints_Hook_Fire $fire The fire that might be logged as a hit. |
28 | 28 | */ |
29 | - public function __construct( WordPoints_Hook_Fire $fire ) { |
|
29 | + public function __construct(WordPoints_Hook_Fire $fire) { |
|
30 | 30 | |
31 | 31 | $this->fire = $fire; |
32 | 32 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | global $wpdb; |
44 | 44 | |
45 | - $signature = wordpoints_hooks_get_event_signature( $this->fire->event_args ); |
|
45 | + $signature = wordpoints_hooks_get_event_signature($this->fire->event_args); |
|
46 | 46 | |
47 | 47 | $inserted = $wpdb->insert( |
48 | 48 | $wpdb->wordpoints_hook_hits |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | 'reactor' => $this->fire->reaction->get_reactor_slug(), |
54 | 54 | 'reaction_type' => $this->fire->reaction->get_storage_group_slug(), |
55 | 55 | 'reaction_id' => $this->fire->reaction->ID, |
56 | - 'date' => current_time( 'mysql' ), |
|
56 | + 'date' => current_time('mysql'), |
|
57 | 57 | ) |
58 | 58 | ); |
59 | 59 | |
60 | - if ( ! $inserted ) { |
|
60 | + if ( ! $inserted) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | |
66 | 66 | $supersedes = $this->fire->get_superseded_hit(); |
67 | 67 | |
68 | - if ( $supersedes ) { |
|
68 | + if ($supersedes) { |
|
69 | 69 | $wpdb->update( |
70 | 70 | $wpdb->wordpoints_hook_hits |
71 | - , array( 'superseded_by' => $hit_id ) |
|
72 | - , array( 'id' => $supersedes->id ) |
|
73 | - , array( '%d' ) |
|
74 | - , array( '%d' ) |
|
71 | + , array('superseded_by' => $hit_id) |
|
72 | + , array('id' => $supersedes->id) |
|
73 | + , array('%d') |
|
74 | + , array('%d') |
|
75 | 75 | ); |
76 | 76 | } |
77 | 77 |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @since 1.0.0 |
55 | 55 | */ |
56 | - public function __get( $var ) { |
|
56 | + public function __get($var) { |
|
57 | 57 | |
58 | - if ( 'reactions' !== $var ) { |
|
58 | + if ('reactions' !== $var) { |
|
59 | 59 | return null; |
60 | 60 | } |
61 | 61 | |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | wordpoints_hooks()->get_current_mode() |
64 | 64 | ); |
65 | 65 | |
66 | - if ( ! $reaction_group ) { |
|
66 | + if ( ! $reaction_group) { |
|
67 | 67 | return null; |
68 | 68 | } |
69 | 69 | |
@@ -79,20 +79,20 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return WordPoints_Hook_Reaction_StorageI|false The reaction storage object. |
81 | 81 | */ |
82 | - public function get_reaction_group( $slug ) { |
|
82 | + public function get_reaction_group($slug) { |
|
83 | 83 | |
84 | 84 | $reaction_group = wordpoints_hooks()->reaction_groups->get( |
85 | 85 | $this->slug |
86 | 86 | , $slug |
87 | - , array( $this ) |
|
87 | + , array($this) |
|
88 | 88 | ); |
89 | 89 | |
90 | - if ( ! $reaction_group instanceof WordPoints_Hook_Reaction_StorageI ) { |
|
90 | + if ( ! $reaction_group instanceof WordPoints_Hook_Reaction_StorageI) { |
|
91 | 91 | return false; |
92 | 92 | } |
93 | 93 | |
94 | 94 | // Allowing access to groups out-of-context would lead to strange behavior. |
95 | - if ( false === $reaction_group->get_context_id() ) { |
|
95 | + if (false === $reaction_group->get_context_id()) { |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * |
167 | 167 | * @return WordPoints_Hook_ReactionI[] All of the reaction objects. |
168 | 168 | */ |
169 | - public function get_all_reactions_to_event( $event_slug ) { |
|
169 | + public function get_all_reactions_to_event($event_slug) { |
|
170 | 170 | |
171 | 171 | $reactions = array(); |
172 | 172 | |
@@ -174,17 +174,17 @@ discard block |
||
174 | 174 | $this->slug |
175 | 175 | ); |
176 | 176 | |
177 | - foreach ( $slugs as $slug ) { |
|
177 | + foreach ($slugs as $slug) { |
|
178 | 178 | |
179 | - $storage = $this->get_reaction_group( $slug ); |
|
179 | + $storage = $this->get_reaction_group($slug); |
|
180 | 180 | |
181 | - if ( ! $storage ) { |
|
181 | + if ( ! $storage) { |
|
182 | 182 | continue; |
183 | 183 | } |
184 | 184 | |
185 | 185 | $reactions = array_merge( |
186 | 186 | $reactions |
187 | - , $storage->get_reactions_to_event( $event_slug ) |
|
187 | + , $storage->get_reactions_to_event($event_slug) |
|
188 | 188 | ); |
189 | 189 | } |
190 | 190 | |
@@ -213,15 +213,15 @@ discard block |
||
213 | 213 | $this->slug |
214 | 214 | ); |
215 | 215 | |
216 | - foreach ( $slugs as $slug ) { |
|
216 | + foreach ($slugs as $slug) { |
|
217 | 217 | |
218 | - $storage = $this->get_reaction_group( $slug ); |
|
218 | + $storage = $this->get_reaction_group($slug); |
|
219 | 219 | |
220 | - if ( ! $storage ) { |
|
220 | + if ( ! $storage) { |
|
221 | 221 | continue; |
222 | 222 | } |
223 | 223 | |
224 | - $reactions = array_merge( $reactions, $storage->get_reactions() ); |
|
224 | + $reactions = array_merge($reactions, $storage->get_reactions()); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | return $reactions; |
@@ -237,21 +237,21 @@ discard block |
||
237 | 237 | ) { |
238 | 238 | |
239 | 239 | if ( |
240 | - empty( $settings['target'] ) |
|
241 | - || ! is_array( $settings['target'] ) |
|
240 | + empty($settings['target']) |
|
241 | + || ! is_array($settings['target']) |
|
242 | 242 | ) { |
243 | 243 | |
244 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
244 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
245 | 245 | |
246 | 246 | } else { |
247 | 247 | |
248 | - $target = $event_args->get_from_hierarchy( $settings['target'] ); |
|
248 | + $target = $event_args->get_from_hierarchy($settings['target']); |
|
249 | 249 | |
250 | 250 | if ( |
251 | 251 | ! $target instanceof WordPoints_Entity |
252 | - || ! in_array( $target->get_slug(), (array) $this->arg_types ) |
|
252 | + || ! in_array($target->get_slug(), (array) $this->arg_types) |
|
253 | 253 | ) { |
254 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
254 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | /** |
262 | 262 | * @since 1.0.0 |
263 | 263 | */ |
264 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
265 | - $reaction->update_meta( 'target', $settings['target'] ); |
|
264 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
265 | + $reaction->update_meta('target', $settings['target']); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
274 | 274 | */ |
275 | - abstract public function hit( WordPoints_Hook_Fire $fire ); |
|
275 | + abstract public function hit(WordPoints_Hook_Fire $fire); |
|
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Reverses all hits matching this event and args. |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | * |
282 | 282 | * @param WordPoints_Hook_Fire $fire The reverse fire object. |
283 | 283 | */ |
284 | - abstract public function reverse_hit( WordPoints_Hook_Fire $fire ); |
|
284 | + abstract public function reverse_hit(WordPoints_Hook_Fire $fire); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | // EOF |
@@ -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 | } |
@@ -69,23 +69,23 @@ discard block |
||
69 | 69 | WordPoints_Hook_Event_Args $event_args |
70 | 70 | ) { |
71 | 71 | |
72 | - if ( ! isset( $settings['points'] ) || false === wordpoints_int( $settings['points'] ) ) { |
|
73 | - $validator->add_error( __( 'Points must be an integer.', 'wordpoints' ), 'points' ); |
|
72 | + if ( ! isset($settings['points']) || false === wordpoints_int($settings['points'])) { |
|
73 | + $validator->add_error(__('Points must be an integer.', 'wordpoints'), 'points'); |
|
74 | 74 | } |
75 | 75 | |
76 | - if ( ! isset( $settings['points_type'] ) || ! wordpoints_is_points_type( $settings['points_type'] ) ) { |
|
77 | - $validator->add_error( __( 'Invalid points type.', 'wordpoints' ), 'points_type' ); |
|
76 | + if ( ! isset($settings['points_type']) || ! wordpoints_is_points_type($settings['points_type'])) { |
|
77 | + $validator->add_error(__('Invalid points type.', 'wordpoints'), 'points_type'); |
|
78 | 78 | } |
79 | 79 | |
80 | - if ( ! isset( $settings['description'] ) ) { |
|
81 | - $validator->add_error( __( 'Description is required.', 'wordpoints' ), 'description' ); |
|
80 | + if ( ! isset($settings['description'])) { |
|
81 | + $validator->add_error(__('Description is required.', 'wordpoints'), 'description'); |
|
82 | 82 | } |
83 | 83 | |
84 | - if ( ! isset( $settings['log_text'] ) ) { |
|
85 | - $validator->add_error( __( 'Log Text is required.', 'wordpoints' ), 'log_text' ); |
|
84 | + if ( ! isset($settings['log_text'])) { |
|
85 | + $validator->add_error(__('Log Text is required.', 'wordpoints'), 'log_text'); |
|
86 | 86 | } |
87 | 87 | |
88 | - return parent::validate_settings( $settings, $validator, $event_args ); |
|
88 | + return parent::validate_settings($settings, $validator, $event_args); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
@@ -96,49 +96,49 @@ discard block |
||
96 | 96 | array $settings |
97 | 97 | ) { |
98 | 98 | |
99 | - parent::update_settings( $reaction, $settings ); |
|
99 | + parent::update_settings($reaction, $settings); |
|
100 | 100 | |
101 | - $reaction->update_meta( 'points', $settings['points'] ); |
|
102 | - $reaction->update_meta( 'points_type', $settings['points_type'] ); |
|
103 | - $reaction->update_meta( 'description', $settings['description'] ); |
|
104 | - $reaction->update_meta( 'log_text', $settings['log_text'] ); |
|
101 | + $reaction->update_meta('points', $settings['points']); |
|
102 | + $reaction->update_meta('points_type', $settings['points_type']); |
|
103 | + $reaction->update_meta('description', $settings['description']); |
|
104 | + $reaction->update_meta('log_text', $settings['log_text']); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @since 1.0.0 |
109 | 109 | */ |
110 | - public function hit( WordPoints_Hook_Fire $fire ) { |
|
110 | + public function hit(WordPoints_Hook_Fire $fire) { |
|
111 | 111 | |
112 | 112 | $reaction = $fire->reaction; |
113 | 113 | |
114 | 114 | $target = $fire->event_args->get_from_hierarchy( |
115 | - $reaction->get_meta( 'target' ) |
|
115 | + $reaction->get_meta('target') |
|
116 | 116 | ); |
117 | 117 | |
118 | - if ( ! $target instanceof WordPoints_Entity ) { |
|
118 | + if ( ! $target instanceof WordPoints_Entity) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
122 | 122 | $meta = array(); |
123 | 123 | |
124 | - foreach ( $fire->event_args->get_entities() as $entity ) { |
|
125 | - $meta[ $entity->get_slug() ] = $entity->get_the_id(); |
|
124 | + foreach ($fire->event_args->get_entities() as $entity) { |
|
125 | + $meta[$entity->get_slug()] = $entity->get_the_id(); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | wordpoints_alter_points( |
129 | 129 | $target->get_the_id() |
130 | - , $reaction->get_meta( 'points' ) |
|
131 | - , $reaction->get_meta( 'points_type' ) |
|
130 | + , $reaction->get_meta('points') |
|
131 | + , $reaction->get_meta('points_type') |
|
132 | 132 | , $reaction->get_event_slug() |
133 | 133 | , $meta |
134 | - , $reaction->get_meta( 'log_text' ) |
|
134 | + , $reaction->get_meta('log_text') |
|
135 | 135 | ); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | 139 | * @since 1.0.0 |
140 | 140 | */ |
141 | - public function reverse_hit( WordPoints_Hook_Fire $fire ) { |
|
141 | + public function reverse_hit(WordPoints_Hook_Fire $fire) { |
|
142 | 142 | |
143 | 143 | $meta_queries = array( |
144 | 144 | array( |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | ), |
150 | 150 | ); |
151 | 151 | |
152 | - foreach ( $fire->event_args->get_entities() as $slug => $entity ) { |
|
152 | + foreach ($fire->event_args->get_entities() as $slug => $entity) { |
|
153 | 153 | |
154 | 154 | $meta_queries[] = array( |
155 | 155 | 'key' => $slug, |
@@ -166,35 +166,35 @@ discard block |
||
166 | 166 | |
167 | 167 | $logs = $query->get(); |
168 | 168 | |
169 | - if ( ! $logs ) { |
|
169 | + if ( ! $logs) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | 173 | global $wpdb; |
174 | 174 | |
175 | - add_filter( 'wordpoints_points_log', '__return_false' ); |
|
175 | + add_filter('wordpoints_points_log', '__return_false'); |
|
176 | 176 | |
177 | - foreach ( $logs as $log ) { |
|
177 | + foreach ($logs as $log) { |
|
178 | 178 | |
179 | 179 | wordpoints_alter_points( |
180 | 180 | $log->user_id |
181 | 181 | , -$log->points |
182 | 182 | , $log->points_type |
183 | 183 | , "reverse-{$log->log_type}" |
184 | - , array( 'original_log_id' => $log->id ) |
|
184 | + , array('original_log_id' => $log->id) |
|
185 | 185 | ); |
186 | 186 | |
187 | - wordpoints_points_log_delete_all_metadata( $log->id ); |
|
187 | + wordpoints_points_log_delete_all_metadata($log->id); |
|
188 | 188 | |
189 | 189 | // Now delete the log. |
190 | 190 | $wpdb->delete( |
191 | 191 | $wpdb->wordpoints_points_logs |
192 | - , array( 'id' => $log->id ) |
|
192 | + , array('id' => $log->id) |
|
193 | 193 | , '%d' |
194 | 194 | ); // WPCS: cache OK, cleaned by wordpoints_alter_points(). |
195 | 195 | } |
196 | 196 | |
197 | - remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
197 | + remove_filter('wordpoints_points_log', '__return_false'); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 |