@@ -24,15 +24,15 @@ |
||
| 24 | 24 | /** |
| 25 | 25 | * @since 2.1.0 |
| 26 | 26 | */ |
| 27 | - public function validate_action_type_settings( $settings ) { |
|
| 27 | + public function validate_action_type_settings($settings) { |
|
| 28 | 28 | return (bool) $settings; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @since 2.1.0 |
| 33 | 33 | */ |
| 34 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
| 35 | - return ! $this->get_settings_from_fire( $fire ); |
|
| 34 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
| 35 | + return ! $this->get_settings_from_fire($fire); |
|
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | public function get_ui_script_data() { |
| 40 | 40 | |
| 41 | 41 | $period_units = array( |
| 42 | - 1 => __( 'Seconds', 'wordpoints' ), |
|
| 43 | - MINUTE_IN_SECONDS => __( 'Minutes', 'wordpoints' ), |
|
| 44 | - HOUR_IN_SECONDS => __( 'Hours', 'wordpoints' ), |
|
| 45 | - DAY_IN_SECONDS => __( 'Days', 'wordpoints' ), |
|
| 46 | - WEEK_IN_SECONDS => __( 'Weeks', 'wordpoints' ), |
|
| 47 | - 30 * DAY_IN_SECONDS => __( 'Months', 'wordpoints' ), |
|
| 42 | + 1 => __('Seconds', 'wordpoints'), |
|
| 43 | + MINUTE_IN_SECONDS => __('Minutes', 'wordpoints'), |
|
| 44 | + HOUR_IN_SECONDS => __('Hours', 'wordpoints'), |
|
| 45 | + DAY_IN_SECONDS => __('Days', 'wordpoints'), |
|
| 46 | + WEEK_IN_SECONDS => __('Weeks', 'wordpoints'), |
|
| 47 | + 30 * DAY_IN_SECONDS => __('Months', 'wordpoints'), |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | return array( |
| 63 | 63 | 'period_units' => $period_units, |
| 64 | 64 | 'l10n' => array( |
| 65 | - 'label' => __( 'Trigger reaction no more than once in:', 'wordpoints' ), |
|
| 65 | + 'label' => __('Trigger reaction no more than once in:', 'wordpoints'), |
|
| 66 | 66 | ), |
| 67 | 67 | ); |
| 68 | 68 | } |
@@ -76,25 +76,25 @@ discard block |
||
| 76 | 76 | * |
| 77 | 77 | * @return array The validated periods. |
| 78 | 78 | */ |
| 79 | - protected function validate_action_type_settings( $periods ) { |
|
| 79 | + protected function validate_action_type_settings($periods) { |
|
| 80 | 80 | |
| 81 | - if ( ! is_array( $periods ) ) { |
|
| 81 | + if ( ! is_array($periods)) { |
|
| 82 | 82 | |
| 83 | 83 | $this->validator->add_error( |
| 84 | - __( 'Periods do not match expected format.', 'wordpoints' ) |
|
| 84 | + __('Periods do not match expected format.', 'wordpoints') |
|
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | 87 | return array(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - foreach ( $periods as $index => $period ) { |
|
| 90 | + foreach ($periods as $index => $period) { |
|
| 91 | 91 | |
| 92 | - $this->validator->push_field( $index ); |
|
| 92 | + $this->validator->push_field($index); |
|
| 93 | 93 | |
| 94 | - $period = $this->validate_period( $period ); |
|
| 94 | + $period = $this->validate_period($period); |
|
| 95 | 95 | |
| 96 | - if ( $period ) { |
|
| 97 | - $periods[ $index ] = $period; |
|
| 96 | + if ($period) { |
|
| 97 | + $periods[$index] = $period; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $this->validator->pop_field(); |
@@ -112,30 +112,30 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return array|false The validated period, or false if invalid. |
| 114 | 114 | */ |
| 115 | - protected function validate_period( $period ) { |
|
| 115 | + protected function validate_period($period) { |
|
| 116 | 116 | |
| 117 | - if ( ! is_array( $period ) ) { |
|
| 117 | + if ( ! is_array($period)) { |
|
| 118 | 118 | $this->validator->add_error( |
| 119 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
| 119 | + __('Period does not match expected format.', 'wordpoints') |
|
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | return false; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( isset( $period['args'] ) ) { |
|
| 126 | - $this->validate_period_args( $period['args'] ); |
|
| 125 | + if (isset($period['args'])) { |
|
| 126 | + $this->validate_period_args($period['args']); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - if ( ! isset( $period['length'] ) ) { |
|
| 129 | + if ( ! isset($period['length'])) { |
|
| 130 | 130 | |
| 131 | 131 | $this->validator->add_error( |
| 132 | - __( 'Period length setting is missing.', 'wordpoints' ) |
|
| 132 | + __('Period length setting is missing.', 'wordpoints') |
|
| 133 | 133 | ); |
| 134 | 134 | |
| 135 | - } elseif ( false === wordpoints_posint( $period['length'] ) ) { |
|
| 135 | + } elseif (false === wordpoints_posint($period['length'])) { |
|
| 136 | 136 | |
| 137 | 137 | $this->validator->add_error( |
| 138 | - __( 'Period length must be a positive integer.', 'wordpoints' ) |
|
| 138 | + __('Period length must be a positive integer.', 'wordpoints') |
|
| 139 | 139 | , 'length' |
| 140 | 140 | ); |
| 141 | 141 | |
@@ -152,34 +152,34 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @param mixed $args The args the period is related to. |
| 154 | 154 | */ |
| 155 | - protected function validate_period_args( $args ) { |
|
| 155 | + protected function validate_period_args($args) { |
|
| 156 | 156 | |
| 157 | - if ( ! is_array( $args ) ) { |
|
| 157 | + if ( ! is_array($args)) { |
|
| 158 | 158 | |
| 159 | 159 | $this->validator->add_error( |
| 160 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
| 160 | + __('Period does not match expected format.', 'wordpoints') |
|
| 161 | 161 | , 'args' |
| 162 | 162 | ); |
| 163 | 163 | |
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $this->validator->push_field( 'args' ); |
|
| 167 | + $this->validator->push_field('args'); |
|
| 168 | 168 | |
| 169 | - foreach ( $args as $index => $hierarchy ) { |
|
| 169 | + foreach ($args as $index => $hierarchy) { |
|
| 170 | 170 | |
| 171 | - $this->validator->push_field( $index ); |
|
| 171 | + $this->validator->push_field($index); |
|
| 172 | 172 | |
| 173 | - if ( ! is_array( $hierarchy ) ) { |
|
| 173 | + if ( ! is_array($hierarchy)) { |
|
| 174 | 174 | |
| 175 | 175 | $this->validator->add_error( |
| 176 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
| 176 | + __('Period does not match expected format.', 'wordpoints') |
|
| 177 | 177 | ); |
| 178 | 178 | |
| 179 | - } elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) { |
|
| 179 | + } elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) { |
|
| 180 | 180 | |
| 181 | 181 | $this->validator->add_error( |
| 182 | - __( 'Invalid arg hierarchy for period.', 'wordpoints' ) |
|
| 182 | + __('Invalid arg hierarchy for period.', 'wordpoints') |
|
| 183 | 183 | ); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | /** |
| 193 | 193 | * @since 2.1.0 |
| 194 | 194 | */ |
| 195 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
| 195 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
| 196 | 196 | |
| 197 | - $periods = $this->get_settings_from_fire( $fire ); |
|
| 197 | + $periods = $this->get_settings_from_fire($fire); |
|
| 198 | 198 | |
| 199 | - if ( empty( $periods ) ) { |
|
| 199 | + if (empty($periods)) { |
|
| 200 | 200 | return true; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | $this->event_args = $fire->event_args; |
| 204 | 204 | $this->action_type = $fire->action_type; |
| 205 | 205 | |
| 206 | - foreach ( $periods as $period ) { |
|
| 207 | - if ( ! $this->has_period_ended( $period, $fire->reaction ) ) { |
|
| 206 | + foreach ($periods as $period) { |
|
| 207 | + if ( ! $this->has_period_ended($period, $fire->reaction)) { |
|
| 208 | 208 | return false; |
| 209 | 209 | } |
| 210 | 210 | } |
@@ -227,27 +227,27 @@ discard block |
||
| 227 | 227 | WordPoints_Hook_ReactionI $reaction |
| 228 | 228 | ) { |
| 229 | 229 | |
| 230 | - $period = $this->get_period_by_reaction( $settings, $reaction ); |
|
| 230 | + $period = $this->get_period_by_reaction($settings, $reaction); |
|
| 231 | 231 | |
| 232 | 232 | // If the period isn't found, we know that we can still fire. |
| 233 | - if ( ! $period ) { |
|
| 233 | + if ( ! $period) { |
|
| 234 | 234 | return true; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $now = current_time( 'timestamp', true ); |
|
| 238 | - $hit_time = strtotime( $period->date, $now ); |
|
| 237 | + $now = current_time('timestamp', true); |
|
| 238 | + $hit_time = strtotime($period->date, $now); |
|
| 239 | 239 | |
| 240 | - if ( ! empty( $settings['relative'] ) ) { |
|
| 240 | + if ( ! empty($settings['relative'])) { |
|
| 241 | 241 | |
| 242 | - return ( $now > $hit_time + $settings['length'] ); |
|
| 242 | + return ($now > $hit_time + $settings['length']); |
|
| 243 | 243 | |
| 244 | 244 | } else { |
| 245 | 245 | |
| 246 | - $offset = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; |
|
| 246 | + $offset = get_option('gmt_offset') * HOUR_IN_SECONDS; |
|
| 247 | 247 | |
| 248 | 248 | return ( |
| 249 | - (int) ( ( $hit_time + $offset ) / $settings['length'] ) |
|
| 250 | - < (int) ( ( $now + $offset ) / $settings['length'] ) |
|
| 249 | + (int) (($hit_time + $offset) / $settings['length']) |
|
| 250 | + < (int) (($now + $offset) / $settings['length']) |
|
| 251 | 251 | ); |
| 252 | 252 | } |
| 253 | 253 | } |
@@ -261,24 +261,24 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @return array The arg values. |
| 263 | 263 | */ |
| 264 | - protected function get_arg_values( array $period_args ) { |
|
| 264 | + protected function get_arg_values(array $period_args) { |
|
| 265 | 265 | |
| 266 | 266 | $values = array(); |
| 267 | 267 | |
| 268 | - foreach ( $period_args as $arg_hierarchy ) { |
|
| 268 | + foreach ($period_args as $arg_hierarchy) { |
|
| 269 | 269 | |
| 270 | 270 | $arg = $this->event_args->get_from_hierarchy( |
| 271 | 271 | $arg_hierarchy |
| 272 | 272 | ); |
| 273 | 273 | |
| 274 | - if ( ! $arg instanceof WordPoints_EntityishI ) { |
|
| 274 | + if ( ! $arg instanceof WordPoints_EntityishI) { |
|
| 275 | 275 | continue; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - $values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value(); |
|
| 278 | + $values[implode('.', $arg_hierarchy)] = $arg->get_the_value(); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - ksort( $values ); |
|
| 281 | + ksort($values); |
|
| 282 | 282 | |
| 283 | 283 | return $values; |
| 284 | 284 | } |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | * |
| 293 | 293 | * @return object|false The period data, or false if not found. |
| 294 | 294 | */ |
| 295 | - protected function get_period( $period_id ) { |
|
| 295 | + protected function get_period($period_id) { |
|
| 296 | 296 | |
| 297 | - $period = wp_cache_get( $period_id, 'wordpoints_hook_periods' ); |
|
| 297 | + $period = wp_cache_get($period_id, 'wordpoints_hook_periods'); |
|
| 298 | 298 | |
| 299 | - if ( ! $period ) { |
|
| 299 | + if ( ! $period) { |
|
| 300 | 300 | |
| 301 | 301 | global $wpdb; |
| 302 | 302 | |
@@ -313,11 +313,11 @@ discard block |
||
| 313 | 313 | ) |
| 314 | 314 | ); |
| 315 | 315 | |
| 316 | - if ( ! $period ) { |
|
| 316 | + if ( ! $period) { |
|
| 317 | 317 | return false; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
| 320 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | return $period; |
@@ -338,17 +338,17 @@ discard block |
||
| 338 | 338 | WordPoints_Hook_ReactionI $reaction |
| 339 | 339 | ) { |
| 340 | 340 | |
| 341 | - $signature = $this->get_period_signature( $settings, $reaction ); |
|
| 341 | + $signature = $this->get_period_signature($settings, $reaction); |
|
| 342 | 342 | $reaction_guid = $reaction->get_guid(); |
| 343 | 343 | |
| 344 | - $cache_key = wp_json_encode( $reaction_guid ) . "-{$signature}-{$this->action_type}"; |
|
| 344 | + $cache_key = wp_json_encode($reaction_guid) . "-{$signature}-{$this->action_type}"; |
|
| 345 | 345 | |
| 346 | 346 | // Before we run the query, we try to lookup the ID in the cache. |
| 347 | - $period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids_by_reaction' ); |
|
| 347 | + $period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids_by_reaction'); |
|
| 348 | 348 | |
| 349 | 349 | // If we found it, we can retrieve the period by ID instead. |
| 350 | - if ( $period_id ) { |
|
| 351 | - return $this->get_period( $period_id ); |
|
| 350 | + if ($period_id) { |
|
| 351 | + return $this->get_period($period_id); |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | global $wpdb; |
@@ -373,18 +373,18 @@ discard block |
||
| 373 | 373 | , $signature |
| 374 | 374 | , $reaction_guid['mode'] |
| 375 | 375 | , $reaction_guid['store'] |
| 376 | - , wp_json_encode( $reaction_guid['context_id'] ) |
|
| 376 | + , wp_json_encode($reaction_guid['context_id']) |
|
| 377 | 377 | , $reaction_guid['id'] |
| 378 | 378 | , $this->action_type |
| 379 | 379 | ) |
| 380 | 380 | ); |
| 381 | 381 | |
| 382 | - if ( ! $period ) { |
|
| 382 | + if ( ! $period) { |
|
| 383 | 383 | return false; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction' ); |
|
| 387 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
| 386 | + wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction'); |
|
| 387 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
| 388 | 388 | |
| 389 | 389 | return $period; |
| 390 | 390 | } |
@@ -392,21 +392,21 @@ discard block |
||
| 392 | 392 | /** |
| 393 | 393 | * @since 2.1.0 |
| 394 | 394 | */ |
| 395 | - public function after_hit( WordPoints_Hook_Fire $fire ) { |
|
| 395 | + public function after_hit(WordPoints_Hook_Fire $fire) { |
|
| 396 | 396 | |
| 397 | - $periods = $this->get_settings_from_fire( $fire ); |
|
| 397 | + $periods = $this->get_settings_from_fire($fire); |
|
| 398 | 398 | |
| 399 | - if ( empty( $periods ) ) { |
|
| 399 | + if (empty($periods)) { |
|
| 400 | 400 | return; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | $this->event_args = $fire->event_args; |
| 404 | 404 | $this->action_type = $fire->action_type; |
| 405 | 405 | |
| 406 | - foreach ( $periods as $settings ) { |
|
| 406 | + foreach ($periods as $settings) { |
|
| 407 | 407 | |
| 408 | 408 | $this->add_period( |
| 409 | - $this->get_period_signature( $settings, $fire->reaction ) |
|
| 409 | + $this->get_period_signature($settings, $fire->reaction) |
|
| 410 | 410 | , $fire |
| 411 | 411 | ); |
| 412 | 412 | } |
@@ -431,14 +431,14 @@ discard block |
||
| 431 | 431 | WordPoints_Hook_ReactionI $reaction |
| 432 | 432 | ) { |
| 433 | 433 | |
| 434 | - if ( isset( $settings['args'] ) ) { |
|
| 434 | + if (isset($settings['args'])) { |
|
| 435 | 435 | $period_args = $settings['args']; |
| 436 | 436 | } else { |
| 437 | - $period_args = array( $reaction->get_meta( 'target' ) ); |
|
| 437 | + $period_args = array($reaction->get_meta('target')); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | return wordpoints_hash( |
| 441 | - wp_json_encode( $this->get_arg_values( $period_args ) ) |
|
| 441 | + wp_json_encode($this->get_arg_values($period_args)) |
|
| 442 | 442 | ); |
| 443 | 443 | } |
| 444 | 444 | |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | * |
| 453 | 453 | * @return false|object The period data, or false if not found. |
| 454 | 454 | */ |
| 455 | - protected function add_period( $signature, WordPoints_Hook_Fire $fire ) { |
|
| 455 | + protected function add_period($signature, WordPoints_Hook_Fire $fire) { |
|
| 456 | 456 | |
| 457 | 457 | global $wpdb; |
| 458 | 458 | |
@@ -462,17 +462,17 @@ discard block |
||
| 462 | 462 | 'hit_id' => $fire->hit_id, |
| 463 | 463 | 'signature' => $signature, |
| 464 | 464 | ) |
| 465 | - , array( '%d', '%s' ) |
|
| 465 | + , array('%d', '%s') |
|
| 466 | 466 | ); |
| 467 | 467 | |
| 468 | - if ( ! $inserted ) { |
|
| 468 | + if ( ! $inserted) { |
|
| 469 | 469 | return false; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | $period_id = $wpdb->insert_id; |
| 473 | 473 | |
| 474 | 474 | wp_cache_set( |
| 475 | - wp_json_encode( $fire->reaction->get_guid() ) . "-{$signature}-{$this->action_type}" |
|
| 475 | + wp_json_encode($fire->reaction->get_guid()) . "-{$signature}-{$this->action_type}" |
|
| 476 | 476 | , $period_id |
| 477 | 477 | , 'wordpoints_hook_period_ids_by_reaction' |
| 478 | 478 | ); |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | * |
| 22 | 22 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
| 23 | 23 | */ |
| 24 | - public function after_hit( WordPoints_Hook_Fire $fire ); |
|
| 24 | + public function after_hit(WordPoints_Hook_Fire $fire); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // EOF |
@@ -18,6 +18,7 @@ |
||
| 18 | 18 | * @since 2.2.0 |
| 19 | 19 | * |
| 20 | 20 | * @param object $log The object for the points log the restriction is for. |
| 21 | + * @return void |
|
| 21 | 22 | */ |
| 22 | 23 | public function __construct( $log ); |
| 23 | 24 | |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | * |
| 22 | 22 | * @param WordPoints_Hook_Fire $fire The fire that was a miss. |
| 23 | 23 | */ |
| 24 | - public function after_miss( WordPoints_Hook_Fire $fire ); |
|
| 24 | + public function after_miss(WordPoints_Hook_Fire $fire); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // EOF |
@@ -18,6 +18,7 @@ |
||
| 18 | 18 | * @since 2.2.0 |
| 19 | 19 | * |
| 20 | 20 | * @param object $log The object for the points log the restriction is for. |
| 21 | + * @return void |
|
| 21 | 22 | */ |
| 22 | 23 | public function __construct( $log ); |
| 23 | 24 | |
@@ -22,22 +22,22 @@ |
||
| 22 | 22 | /** |
| 23 | 23 | * @since 2.1.0 |
| 24 | 24 | */ |
| 25 | - protected function validate_action_type_settings( $settings ) { |
|
| 25 | + protected function validate_action_type_settings($settings) { |
|
| 26 | 26 | return (bool) $settings; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @since 2.1.0 |
| 31 | 31 | */ |
| 32 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
| 32 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
| 33 | 33 | |
| 34 | - $block_repeats = (bool) $this->get_settings_from_fire( $fire ); |
|
| 34 | + $block_repeats = (bool) $this->get_settings_from_fire($fire); |
|
| 35 | 35 | |
| 36 | - if ( ! $block_repeats ) { |
|
| 36 | + if ( ! $block_repeats) { |
|
| 37 | 37 | return true; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if ( $fire->get_matching_hits_query()->count() > 0 ) { |
|
| 40 | + if ($fire->get_matching_hits_query()->count() > 0) { |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @since 2.1.0 |
| 35 | 35 | */ |
| 36 | 36 | public function __construct() { |
| 37 | - $this->conditions = wordpoints_hooks()->get_sub_app( 'conditions' ); |
|
| 37 | + $this->conditions = wordpoints_hooks()->get_sub_app('conditions'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -44,14 +44,14 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $conditions_data = array(); |
| 46 | 46 | |
| 47 | - foreach ( $this->conditions->get_all() as $data_type => $conditions ) { |
|
| 48 | - foreach ( $conditions as $slug => $condition ) { |
|
| 47 | + foreach ($this->conditions->get_all() as $data_type => $conditions) { |
|
| 48 | + foreach ($conditions as $slug => $condition) { |
|
| 49 | 49 | |
| 50 | - if ( ! ( $condition instanceof WordPoints_Hook_ConditionI ) ) { |
|
| 50 | + if ( ! ($condition instanceof WordPoints_Hook_ConditionI)) { |
|
| 51 | 51 | continue; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $conditions_data[ $data_type ][ $slug ] = array( |
|
| 54 | + $conditions_data[$data_type][$slug] = array( |
|
| 55 | 55 | 'slug' => $slug, |
| 56 | 56 | 'data_type' => $data_type, |
| 57 | 57 | 'title' => $condition->get_title(), |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - return array( 'conditions' => $conditions_data ); |
|
| 63 | + return array('conditions' => $conditions_data); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * @since 2.1.0 |
| 68 | 68 | */ |
| 69 | - protected function validate_action_type_settings( $settings ) { |
|
| 70 | - return $this->validate_conditions( $settings ); |
|
| 69 | + protected function validate_action_type_settings($settings) { |
|
| 70 | + return $this->validate_conditions($settings); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -80,36 +80,36 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return array The validated settings. |
| 82 | 82 | */ |
| 83 | - public function validate_conditions( $conditions, WordPoints_Hook_Event_Args $event_args = null ) { |
|
| 83 | + public function validate_conditions($conditions, WordPoints_Hook_Event_Args $event_args = null) { |
|
| 84 | 84 | |
| 85 | - if ( $event_args ) { |
|
| 85 | + if ($event_args) { |
|
| 86 | 86 | $this->event_args = $event_args; |
| 87 | 87 | $this->validator = $event_args->get_validator(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if ( ! is_array( $conditions ) ) { |
|
| 90 | + if ( ! is_array($conditions)) { |
|
| 91 | 91 | |
| 92 | 92 | $this->validator->add_error( |
| 93 | - __( 'Conditions do not match expected format.', 'wordpoints' ) |
|
| 93 | + __('Conditions do not match expected format.', 'wordpoints') |
|
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | return array(); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach ( $conditions as $arg_slug => $sub_args ) { |
|
| 99 | + foreach ($conditions as $arg_slug => $sub_args) { |
|
| 100 | 100 | |
| 101 | - if ( '_conditions' === $arg_slug ) { |
|
| 101 | + if ('_conditions' === $arg_slug) { |
|
| 102 | 102 | |
| 103 | - $this->validator->push_field( $arg_slug ); |
|
| 103 | + $this->validator->push_field($arg_slug); |
|
| 104 | 104 | |
| 105 | - foreach ( $sub_args as $index => $settings ) { |
|
| 105 | + foreach ($sub_args as $index => $settings) { |
|
| 106 | 106 | |
| 107 | - $this->validator->push_field( $index ); |
|
| 107 | + $this->validator->push_field($index); |
|
| 108 | 108 | |
| 109 | - $condition = $this->validate_condition( $settings ); |
|
| 109 | + $condition = $this->validate_condition($settings); |
|
| 110 | 110 | |
| 111 | - if ( $condition ) { |
|
| 112 | - $sub_args[ $index ] = $condition; |
|
| 111 | + if ($condition) { |
|
| 112 | + $sub_args[$index] = $condition; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $this->validator->pop_field(); |
@@ -119,18 +119,18 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | } else { |
| 121 | 121 | |
| 122 | - if ( ! $this->event_args->descend( $arg_slug ) ) { |
|
| 122 | + if ( ! $this->event_args->descend($arg_slug)) { |
|
| 123 | 123 | continue; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - $sub_args = $this->validate_action_type_settings( $sub_args ); |
|
| 126 | + $sub_args = $this->validate_action_type_settings($sub_args); |
|
| 127 | 127 | |
| 128 | - $conditions[ $arg_slug ] = $sub_args; |
|
| 128 | + $conditions[$arg_slug] = $sub_args; |
|
| 129 | 129 | |
| 130 | 130 | $this->event_args->ascend(); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $conditions[ $arg_slug ] = $sub_args; |
|
| 133 | + $conditions[$arg_slug] = $sub_args; |
|
| 134 | 134 | |
| 135 | 135 | } // End foreach ( $conditions ). |
| 136 | 136 | |
@@ -147,32 +147,32 @@ discard block |
||
| 147 | 147 | * @return array|false The validated conditions settings, or false if unable to |
| 148 | 148 | * validate. |
| 149 | 149 | */ |
| 150 | - protected function validate_condition( $settings ) { |
|
| 150 | + protected function validate_condition($settings) { |
|
| 151 | 151 | |
| 152 | - if ( ! isset( $settings['type'] ) ) { |
|
| 153 | - $this->validator->add_error( __( 'Condition type is missing.', 'wordpoints' ) ); |
|
| 152 | + if ( ! isset($settings['type'])) { |
|
| 153 | + $this->validator->add_error(__('Condition type is missing.', 'wordpoints')); |
|
| 154 | 154 | return false; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $arg = $this->event_args->get_current(); |
| 158 | 158 | |
| 159 | - $data_type = $this->get_data_type( $arg ); |
|
| 159 | + $data_type = $this->get_data_type($arg); |
|
| 160 | 160 | |
| 161 | - if ( ! $data_type ) { |
|
| 161 | + if ( ! $data_type) { |
|
| 162 | 162 | $this->validator->add_error( |
| 163 | - __( 'This type of condition does not work for the selected attribute.', 'wordpoints' ) |
|
| 163 | + __('This type of condition does not work for the selected attribute.', 'wordpoints') |
|
| 164 | 164 | ); |
| 165 | 165 | |
| 166 | 166 | return false; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $condition = $this->conditions->get( $data_type, $settings['type'] ); |
|
| 169 | + $condition = $this->conditions->get($data_type, $settings['type']); |
|
| 170 | 170 | |
| 171 | - if ( ! $condition ) { |
|
| 171 | + if ( ! $condition) { |
|
| 172 | 172 | |
| 173 | 173 | $this->validator->add_error( |
| 174 | 174 | sprintf( |
| 175 | - __( 'Unknown condition type “%s”.', 'wordpoints' ) |
|
| 175 | + __('Unknown condition type “%s”.', 'wordpoints') |
|
| 176 | 176 | , $settings['type'] |
| 177 | 177 | ) |
| 178 | 178 | , 'type' |
@@ -181,17 +181,17 @@ discard block |
||
| 181 | 181 | return false; |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - if ( ! isset( $settings['settings'] ) ) { |
|
| 185 | - $this->validator->add_error( __( 'Condition settings are missing.', 'wordpoints' ) ); |
|
| 184 | + if ( ! isset($settings['settings'])) { |
|
| 185 | + $this->validator->add_error(__('Condition settings are missing.', 'wordpoints')); |
|
| 186 | 186 | return false; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - $this->validator->push_field( 'settings' ); |
|
| 189 | + $this->validator->push_field('settings'); |
|
| 190 | 190 | |
| 191 | 191 | // The condition may call this object's validate_settings() method to |
| 192 | 192 | // validate some sub-conditions. When that happens, these properties will be |
| 193 | 193 | // reset, so we need to back up their values and then restore them below. |
| 194 | - $backup = array( $this->validator, $this->event_args ); |
|
| 194 | + $backup = array($this->validator, $this->event_args); |
|
| 195 | 195 | |
| 196 | 196 | $settings['settings'] = $condition->validate_settings( |
| 197 | 197 | $arg |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | , $this->validator |
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - list( $this->validator, $this->event_args ) = $backup; |
|
| 202 | + list($this->validator, $this->event_args) = $backup; |
|
| 203 | 203 | |
| 204 | 204 | $this->validator->pop_field(); |
| 205 | 205 | |
@@ -209,11 +209,11 @@ discard block |
||
| 209 | 209 | /** |
| 210 | 210 | * @since 2.1.0 |
| 211 | 211 | */ |
| 212 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
| 212 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
| 213 | 213 | |
| 214 | - $conditions = $this->get_settings_from_fire( $fire ); |
|
| 214 | + $conditions = $this->get_settings_from_fire($fire); |
|
| 215 | 215 | |
| 216 | - if ( $conditions && ! $this->conditions_are_met( $conditions, $fire->event_args ) ) { |
|
| 216 | + if ($conditions && ! $this->conditions_are_met($conditions, $fire->event_args)) { |
|
| 217 | 217 | return false; |
| 218 | 218 | } |
| 219 | 219 | |
@@ -235,35 +235,35 @@ discard block |
||
| 235 | 235 | WordPoints_Hook_Event_Args $event_args |
| 236 | 236 | ) { |
| 237 | 237 | |
| 238 | - foreach ( $conditions as $arg_slug => $sub_args ) { |
|
| 238 | + foreach ($conditions as $arg_slug => $sub_args) { |
|
| 239 | 239 | |
| 240 | - $event_args->descend( $arg_slug ); |
|
| 240 | + $event_args->descend($arg_slug); |
|
| 241 | 241 | |
| 242 | - if ( isset( $sub_args['_conditions'] ) ) { |
|
| 242 | + if (isset($sub_args['_conditions'])) { |
|
| 243 | 243 | |
| 244 | - foreach ( $sub_args['_conditions'] as $settings ) { |
|
| 244 | + foreach ($sub_args['_conditions'] as $settings) { |
|
| 245 | 245 | |
| 246 | 246 | $condition = $this->conditions->get( |
| 247 | - $this->get_data_type( $event_args->get_current() ) |
|
| 247 | + $this->get_data_type($event_args->get_current()) |
|
| 248 | 248 | , $settings['type'] |
| 249 | 249 | ); |
| 250 | 250 | |
| 251 | - $is_met = $condition->is_met( $settings['settings'], $event_args ); |
|
| 251 | + $is_met = $condition->is_met($settings['settings'], $event_args); |
|
| 252 | 252 | |
| 253 | - if ( ! $is_met ) { |
|
| 253 | + if ( ! $is_met) { |
|
| 254 | 254 | $event_args->ascend(); |
| 255 | 255 | return false; |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - unset( $sub_args['_conditions'] ); |
|
| 259 | + unset($sub_args['_conditions']); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $are_met = $this->conditions_are_met( $sub_args, $event_args ); |
|
| 262 | + $are_met = $this->conditions_are_met($sub_args, $event_args); |
|
| 263 | 263 | |
| 264 | 264 | $event_args->ascend(); |
| 265 | 265 | |
| 266 | - if ( ! $are_met ) { |
|
| 266 | + if ( ! $are_met) { |
|
| 267 | 267 | return false; |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -280,13 +280,13 @@ discard block |
||
| 280 | 280 | * |
| 281 | 281 | * @return string|false The data type, or false. |
| 282 | 282 | */ |
| 283 | - protected function get_data_type( $arg ) { |
|
| 283 | + protected function get_data_type($arg) { |
|
| 284 | 284 | |
| 285 | - if ( $arg instanceof WordPoints_Entity_Attr ) { |
|
| 285 | + if ($arg instanceof WordPoints_Entity_Attr) { |
|
| 286 | 286 | $data_type = $arg->get_data_type(); |
| 287 | - } elseif ( $arg instanceof WordPoints_Entity_Array ) { |
|
| 287 | + } elseif ($arg instanceof WordPoints_Entity_Array) { |
|
| 288 | 288 | $data_type = 'entity_array'; |
| 289 | - } elseif ( $arg instanceof WordPoints_Entity ) { |
|
| 289 | + } elseif ($arg instanceof WordPoints_Entity) { |
|
| 290 | 290 | $data_type = 'entity'; |
| 291 | 291 | } else { |
| 292 | 292 | $data_type = false; |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | * |
| 65 | 65 | * @return bool Whether this condition is met. |
| 66 | 66 | */ |
| 67 | - public function is_met( array $settings, WordPoints_Hook_Event_Args $args ); |
|
| 67 | + public function is_met(array $settings, WordPoints_Hook_Event_Args $args); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // EOF |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | * |
| 37 | 37 | * @return bool Whether the target should be hit by this hook firing. |
| 38 | 38 | */ |
| 39 | - public function should_hit( WordPoints_Hook_Fire $fire ); |
|
| 39 | + public function should_hit(WordPoints_Hook_Fire $fire); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // EOF |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function __construct() { |
| 30 | 30 | |
| 31 | - $this->router = wordpoints_hooks()->get_sub_app( 'router' ); |
|
| 31 | + $this->router = wordpoints_hooks()->get_sub_app('router'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -40,23 +40,23 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return object|false The action object, or false if not found. |
| 42 | 42 | */ |
| 43 | - public function get( $slug, array $action_args = array(), array $args = array() ) { |
|
| 43 | + public function get($slug, array $action_args = array(), array $args = array()) { |
|
| 44 | 44 | |
| 45 | - if ( ! isset( $this->classes[ $slug ] ) ) { |
|
| 45 | + if ( ! isset($this->classes[$slug])) { |
|
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - return new $this->classes[ $slug ]( $slug, $action_args, $args ); |
|
| 49 | + return new $this->classes[$slug]($slug, $action_args, $args); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * @since 2.1.0 |
| 54 | 54 | */ |
| 55 | - public function register( $slug, $class, array $args = array() ) { |
|
| 55 | + public function register($slug, $class, array $args = array()) { |
|
| 56 | 56 | |
| 57 | - parent::register( $slug, $class, $args ); |
|
| 57 | + parent::register($slug, $class, $args); |
|
| 58 | 58 | |
| 59 | - $this->router->add_action( $slug, $args ); |
|
| 59 | + $this->router->add_action($slug, $args); |
|
| 60 | 60 | |
| 61 | 61 | return true; |
| 62 | 62 | } |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * @since 2.1.0 |
| 66 | 66 | */ |
| 67 | - public function deregister( $slug ) { |
|
| 67 | + public function deregister($slug) { |
|
| 68 | 68 | |
| 69 | - parent::deregister( $slug ); |
|
| 69 | + parent::deregister($slug); |
|
| 70 | 70 | |
| 71 | - $this->router->remove_action( $slug ); |
|
| 71 | + $this->router->remove_action($slug); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |