@@ -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,33 +296,33 @@ 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 | - unset( $extension, $slug ); |
|
310 | + unset($extension, $slug); |
|
311 | 311 | |
312 | 312 | $reactor_data = array(); |
313 | 313 | |
314 | - foreach ( $hooks->reactors->get_all() as $slug => $reactor ) { |
|
314 | + foreach ($hooks->reactors->get_all() as $slug => $reactor) { |
|
315 | 315 | |
316 | - if ( $reactor instanceof WordPoints_Hook_Reactor ) { |
|
317 | - $reactor_data[ $slug ] = $reactor->get_ui_script_data(); |
|
316 | + if ($reactor instanceof WordPoints_Hook_Reactor) { |
|
317 | + $reactor_data[$slug] = $reactor->get_ui_script_data(); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( wp_script_is( "wordpoints-hooks-reactor-{$slug}", 'registered' ) ) { |
|
321 | - wp_enqueue_script( "wordpoints-hooks-reactor-{$slug}" ); |
|
320 | + if (wp_script_is("wordpoints-hooks-reactor-{$slug}", 'registered')) { |
|
321 | + wp_enqueue_script("wordpoints-hooks-reactor-{$slug}"); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 | |
325 | - unset( $reactor, $slug ); |
|
325 | + unset($reactor, $slug); |
|
326 | 326 | |
327 | 327 | $event_action_types = wordpoints_hooks_ui_get_script_data_event_action_types(); |
328 | 328 | $entities_data = wordpoints_hooks_ui_get_script_data_entities(); |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @param array $data The data. |
348 | 348 | */ |
349 | - $data = apply_filters( 'wordpoints_hooks_ui_data', $data ); |
|
349 | + $data = apply_filters('wordpoints_hooks_ui_data', $data); |
|
350 | 350 | |
351 | 351 | wp_localize_script( |
352 | 352 | 'wordpoints-hooks-models' |
@@ -372,28 +372,28 @@ discard block |
||
372 | 372 | $entity_children = $entities->children; |
373 | 373 | |
374 | 374 | /** @var WordPoints_Entity $entity */ |
375 | - foreach ( $entities->get_all() as $slug => $entity ) { |
|
375 | + foreach ($entities->get_all() as $slug => $entity) { |
|
376 | 376 | |
377 | 377 | $child_data = array(); |
378 | 378 | |
379 | 379 | /** @var WordPoints_EntityishI $child */ |
380 | - foreach ( $entity_children->get_children( $slug ) as $child_slug => $child ) { |
|
380 | + foreach ($entity_children->get_children($slug) as $child_slug => $child) { |
|
381 | 381 | |
382 | - $child_data[ $child_slug ] = array( |
|
382 | + $child_data[$child_slug] = array( |
|
383 | 383 | 'slug' => $child_slug, |
384 | 384 | 'title' => $child->get_title(), |
385 | 385 | ); |
386 | 386 | |
387 | - if ( $child instanceof WordPoints_Entity_Attr ) { |
|
387 | + if ($child instanceof WordPoints_Entity_Attr) { |
|
388 | 388 | |
389 | - $child_data[ $child_slug ]['_type'] = 'attr'; |
|
390 | - $child_data[ $child_slug ]['data_type'] = $child->get_data_type(); |
|
389 | + $child_data[$child_slug]['_type'] = 'attr'; |
|
390 | + $child_data[$child_slug]['data_type'] = $child->get_data_type(); |
|
391 | 391 | |
392 | - } elseif ( $child instanceof WordPoints_Entity_Relationship ) { |
|
392 | + } elseif ($child instanceof WordPoints_Entity_Relationship) { |
|
393 | 393 | |
394 | - $child_data[ $child_slug ]['_type'] = 'relationship'; |
|
395 | - $child_data[ $child_slug ]['primary'] = $child->get_primary_entity_slug(); |
|
396 | - $child_data[ $child_slug ]['secondary'] = $child->get_related_entity_slug(); |
|
394 | + $child_data[$child_slug]['_type'] = 'relationship'; |
|
395 | + $child_data[$child_slug]['primary'] = $child->get_primary_entity_slug(); |
|
396 | + $child_data[$child_slug]['secondary'] = $child->get_related_entity_slug(); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
@@ -404,14 +404,14 @@ discard block |
||
404 | 404 | * @param array $data The data for the entity child. |
405 | 405 | * @param WordPoints_Entityish $child The child's object. |
406 | 406 | */ |
407 | - $child_data[ $child_slug ] = apply_filters( |
|
407 | + $child_data[$child_slug] = apply_filters( |
|
408 | 408 | 'wordpoints_hooks_ui_data_entity_child' |
409 | - , $child_data[ $child_slug ] |
|
409 | + , $child_data[$child_slug] |
|
410 | 410 | , $child |
411 | 411 | ); |
412 | 412 | } |
413 | 413 | |
414 | - $entities_data[ $slug ] = array( |
|
414 | + $entities_data[$slug] = array( |
|
415 | 415 | 'slug' => $slug, |
416 | 416 | 'title' => $entity->get_title(), |
417 | 417 | 'children' => $child_data, |
@@ -419,12 +419,12 @@ discard block |
||
419 | 419 | '_type' => 'entity', |
420 | 420 | ); |
421 | 421 | |
422 | - if ( $entity instanceof WordPoints_Entity_EnumerableI ) { |
|
422 | + if ($entity instanceof WordPoints_Entity_EnumerableI) { |
|
423 | 423 | |
424 | 424 | $values = array(); |
425 | 425 | |
426 | - foreach ( $entity->get_enumerated_values() as $value ) { |
|
427 | - if ( $entity->set_the_value( $value ) ) { |
|
426 | + foreach ($entity->get_enumerated_values() as $value) { |
|
427 | + if ($entity->set_the_value($value)) { |
|
428 | 428 | $values[] = array( |
429 | 429 | 'value' => $entity->get_the_id(), |
430 | 430 | 'label' => $entity->get_the_human_id(), |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | - $entities_data[ $slug ]['values'] = $values; |
|
435 | + $entities_data[$slug]['values'] = $values; |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | * @param array $data The data for the entity. |
442 | 442 | * @param WordPoints_Entity $entity The entity object. |
443 | 443 | */ |
444 | - $entities_data[ $slug ] = apply_filters( |
|
444 | + $entities_data[$slug] = apply_filters( |
|
445 | 445 | 'wordpoints_hooks_ui_data_entity' |
446 | - , $entities_data[ $slug ] |
|
446 | + , $entities_data[$slug] |
|
447 | 447 | , $entity |
448 | 448 | ); |
449 | 449 | } |
@@ -467,15 +467,15 @@ discard block |
||
467 | 467 | |
468 | 468 | // We don't care about the action slugs, so first we get rid of that bottom level |
469 | 469 | // of the array. |
470 | - $event_index = call_user_func_array( 'array_merge_recursive', $event_index ); |
|
470 | + $event_index = call_user_func_array('array_merge_recursive', $event_index); |
|
471 | 471 | |
472 | 472 | $event_action_types = array(); |
473 | 473 | |
474 | 474 | // This leaves us the event indexed by action type. But we actually need to flip |
475 | 475 | // this, so that we have the action types indexed by event slug. |
476 | - foreach ( $event_index as $action_type => $events ) { |
|
477 | - foreach ( $events as $event => $unused ) { |
|
478 | - $event_action_types[ $event ][ $action_type ] = true; |
|
476 | + foreach ($event_index as $action_type => $events) { |
|
477 | + foreach ($events as $event => $unused) { |
|
478 | + $event_action_types[$event][$action_type] = true; |
|
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
@@ -498,13 +498,13 @@ discard block |
||
498 | 498 | * |
499 | 499 | * @return string The HTML with templates appended. |
500 | 500 | */ |
501 | -function wordpoints_script_templates_filter( $html, $handle ) { |
|
501 | +function wordpoints_script_templates_filter($html, $handle) { |
|
502 | 502 | |
503 | 503 | global $wp_scripts; |
504 | 504 | |
505 | - $templates = $wp_scripts->get_data( $handle, 'wordpoints-templates' ); |
|
505 | + $templates = $wp_scripts->get_data($handle, 'wordpoints-templates'); |
|
506 | 506 | |
507 | - if ( $templates ) { |
|
507 | + if ($templates) { |
|
508 | 508 | $html .= $templates; |
509 | 509 | } |
510 | 510 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | */ |
521 | 521 | function wordpoints_hooks_admin_ajax() { |
522 | 522 | |
523 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
523 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
524 | 524 | new WordPoints_Admin_Ajax_Hooks; |
525 | 525 | } |
526 | 526 | } |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param WordPoints_Class_Registry_Persistent $reactors The reactors registry. |
35 | 35 | */ |
36 | -function wordpoints_hook_reactors_init( $reactors ) { |
|
36 | +function wordpoints_hook_reactors_init($reactors) { |
|
37 | 37 | |
38 | - $reactors->register( 'points', 'WordPoints_Hook_Reactor_Points' ); |
|
38 | + $reactors->register('points', 'WordPoints_Hook_Reactor_Points'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param WordPoints_Class_Registry_Children $reaction_stores The store registry. |
49 | 49 | */ |
50 | -function wordpoints_hook_reaction_stores_init( $reaction_stores ) { |
|
50 | +function wordpoints_hook_reaction_stores_init($reaction_stores) { |
|
51 | 51 | |
52 | 52 | $reaction_stores->register( |
53 | 53 | 'standard' |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | , 'WordPoints_Hook_Reaction_Store_Options' |
56 | 56 | ); |
57 | 57 | |
58 | - if ( is_wordpoints_network_active() ) { |
|
58 | + if (is_wordpoints_network_active()) { |
|
59 | 59 | $reaction_stores->register( |
60 | 60 | 'network' |
61 | 61 | , 'points' |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @param WordPoints_Class_Registry_Persistent $extensions The extension registry. |
75 | 75 | */ |
76 | -function wordpoints_hook_extension_init( $extensions ) { |
|
76 | +function wordpoints_hook_extension_init($extensions) { |
|
77 | 77 | |
78 | - $extensions->register( 'blocker', 'WordPoints_Hook_Extension_Blocker' ); |
|
79 | - $extensions->register( 'conditions', 'WordPoints_Hook_Extension_Conditions' ); |
|
80 | - $extensions->register( 'periods', 'WordPoints_Hook_Extension_Periods' ); |
|
78 | + $extensions->register('blocker', 'WordPoints_Hook_Extension_Blocker'); |
|
79 | + $extensions->register('conditions', 'WordPoints_Hook_Extension_Conditions'); |
|
80 | + $extensions->register('periods', 'WordPoints_Hook_Extension_Periods'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @param WordPoints_Class_Registry_Children $conditions The conditions registry. |
91 | 91 | */ |
92 | -function wordpoints_hook_conditions_init( $conditions ) { |
|
92 | +function wordpoints_hook_conditions_init($conditions) { |
|
93 | 93 | |
94 | 94 | $conditions->register( |
95 | 95 | 'text' |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param WordPoints_Hook_Actions $actions The action registry. |
127 | 127 | */ |
128 | -function wordpoints_hook_actions_init( $actions ) { |
|
128 | +function wordpoints_hook_actions_init($actions) { |
|
129 | 129 | |
130 | 130 | $actions->register( |
131 | 131 | 'comment_approve' |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | , array( |
134 | 134 | 'action' => 'transition_comment_status', |
135 | 135 | 'data' => array( |
136 | - 'arg_index' => array( 'comment' => 2 ), |
|
137 | - 'requirements' => array( 0 => 'approved' ), |
|
136 | + 'arg_index' => array('comment' => 2), |
|
137 | + 'requirements' => array(0 => 'approved'), |
|
138 | 138 | ), |
139 | 139 | ) |
140 | 140 | ); |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | , array( |
146 | 146 | 'action' => 'wp_insert_comment', |
147 | 147 | 'data' => array( |
148 | - 'arg_index' => array( 'comment' => 1 ), |
|
148 | + 'arg_index' => array('comment' => 1), |
|
149 | 149 | ), |
150 | 150 | ) |
151 | 151 | ); |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | , array( |
157 | 157 | 'action' => 'transition_comment_status', |
158 | 158 | 'data' => array( |
159 | - 'arg_index' => array( 'comment' => 2 ), |
|
160 | - 'requirements' => array( 1 => 'approved' ), |
|
159 | + 'arg_index' => array('comment' => 2), |
|
160 | + 'requirements' => array(1 => 'approved'), |
|
161 | 161 | ), |
162 | 162 | ) |
163 | 163 | ); |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | , array( |
170 | 170 | 'action' => 'transition_post_status', |
171 | 171 | 'data' => array( |
172 | - 'arg_index' => array( 'post' => 2 ), |
|
173 | - 'requirements' => array( 0 => 'publish' ), |
|
172 | + 'arg_index' => array('post' => 2), |
|
173 | + 'requirements' => array(0 => 'publish'), |
|
174 | 174 | ), |
175 | 175 | ) |
176 | 176 | ); |
@@ -181,8 +181,8 @@ discard block |
||
181 | 181 | , array( |
182 | 182 | 'action' => 'transition_post_status', |
183 | 183 | 'data' => array( |
184 | - 'arg_index' => array( 'post' => 2 ), |
|
185 | - 'requirements' => array( 1 => 'publish' ), |
|
184 | + 'arg_index' => array('post' => 2), |
|
185 | + 'requirements' => array(1 => 'publish'), |
|
186 | 186 | ), |
187 | 187 | ) |
188 | 188 | ); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | , array( |
194 | 194 | 'action' => 'add_attachment', |
195 | 195 | 'data' => array( |
196 | - 'arg_index' => array( 'post\attachment' => 0 ), |
|
196 | + 'arg_index' => array('post\attachment' => 0), |
|
197 | 197 | ), |
198 | 198 | ) |
199 | 199 | ); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | , array( |
205 | 205 | 'action' => 'delete_post', |
206 | 206 | 'data' => array( |
207 | - 'arg_index' => array( 'post' => 0 ), |
|
207 | + 'arg_index' => array('post' => 0), |
|
208 | 208 | ), |
209 | 209 | ) |
210 | 210 | ); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | , array( |
216 | 216 | 'action' => 'user_register', |
217 | 217 | 'data' => array( |
218 | - 'arg_index' => array( 'user' => 0 ), |
|
218 | + 'arg_index' => array('user' => 0), |
|
219 | 219 | ), |
220 | 220 | ) |
221 | 221 | ); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | , array( |
227 | 227 | 'action' => is_multisite() ? 'wpmu_delete_user' : 'delete_user', |
228 | 228 | 'data' => array( |
229 | - 'arg_index' => array( 'user' => 0 ), |
|
229 | + 'arg_index' => array('user' => 0), |
|
230 | 230 | ), |
231 | 231 | ) |
232 | 232 | ); |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @param WordPoints_Hook_Events $events The event registry. |
251 | 251 | */ |
252 | -function wordpoints_hook_events_init( $events ) { |
|
252 | +function wordpoints_hook_events_init($events) { |
|
253 | 253 | |
254 | 254 | $events->register( |
255 | 255 | 'user_register' |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | ); |
280 | 280 | |
281 | 281 | // Register events for all of the public post types. |
282 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
282 | + $post_types = get_post_types(array('public' => true)); |
|
283 | 283 | |
284 | 284 | /** |
285 | 285 | * Filter which post types to register hook events for. |
@@ -288,20 +288,20 @@ discard block |
||
288 | 288 | * |
289 | 289 | * @param string[] The post type slugs ("names"). |
290 | 290 | */ |
291 | - $post_types = apply_filters( 'wordpoints_register_hook_events_for_post_types', $post_types ); |
|
291 | + $post_types = apply_filters('wordpoints_register_hook_events_for_post_types', $post_types); |
|
292 | 292 | |
293 | - foreach ( $post_types as $slug ) { |
|
294 | - wordpoints_register_post_type_hook_events( $slug ); |
|
293 | + foreach ($post_types as $slug) { |
|
294 | + wordpoints_register_post_type_hook_events($slug); |
|
295 | 295 | } |
296 | 296 | |
297 | - if ( is_multisite() ) { |
|
297 | + if (is_multisite()) { |
|
298 | 298 | |
299 | 299 | $event_slugs = array( |
300 | 300 | 'user_visit', |
301 | 301 | 'user_register', |
302 | 302 | ); |
303 | 303 | |
304 | - foreach ( $event_slugs as $event_slug ) { |
|
304 | + foreach ($event_slugs as $event_slug) { |
|
305 | 305 | // TODO network hooks |
306 | 306 | $events->args->register( |
307 | 307 | $event_slug |
@@ -321,10 +321,10 @@ discard block |
||
321 | 321 | * |
322 | 322 | * @param WordPoints_App_Registry $entities The entities app. |
323 | 323 | */ |
324 | -function wordpoints_entities_app_init( $entities ) { |
|
324 | +function wordpoints_entities_app_init($entities) { |
|
325 | 325 | |
326 | - $entities->sub_apps->register( 'children', 'WordPoints_Class_Registry_Children' ); |
|
327 | - $entities->sub_apps->register( 'contexts', 'WordPoints_Class_Registry' ); |
|
326 | + $entities->sub_apps->register('children', 'WordPoints_Class_Registry_Children'); |
|
327 | + $entities->sub_apps->register('contexts', 'WordPoints_Class_Registry'); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WordPoints_Class_Registry $contexts The entity context registry. |
338 | 338 | */ |
339 | -function wordpoints_entity_contexts_init( $contexts ) { |
|
339 | +function wordpoints_entity_contexts_init($contexts) { |
|
340 | 340 | |
341 | - $contexts->register( 'network', 'WordPoints_Entity_Context_Network' ); |
|
342 | - $contexts->register( 'site', 'WordPoints_Entity_Context_Site' ); |
|
341 | + $contexts->register('network', 'WordPoints_Entity_Context_Network'); |
|
342 | + $contexts->register('site', 'WordPoints_Entity_Context_Site'); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -351,18 +351,18 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @param WordPoints_App_Registry $entities The entities app. |
353 | 353 | */ |
354 | -function wordpoints_entities_init( $entities ) { |
|
354 | +function wordpoints_entities_init($entities) { |
|
355 | 355 | |
356 | 356 | $children = $entities->children; |
357 | 357 | |
358 | - $entities->register( 'user', 'WordPoints_Entity_User' ); |
|
359 | - $children->register( 'user', 'roles', 'WordPoints_Entity_User_Roles' ); |
|
358 | + $entities->register('user', 'WordPoints_Entity_User'); |
|
359 | + $children->register('user', 'roles', 'WordPoints_Entity_User_Roles'); |
|
360 | 360 | |
361 | - $entities->register( 'user_role', 'WordPoints_Entity_User_Role' ); |
|
362 | - $children->register( 'user_role', 'name', 'WordPoints_Entity_User_Role_Name' ); |
|
361 | + $entities->register('user_role', 'WordPoints_Entity_User_Role'); |
|
362 | + $children->register('user_role', 'name', 'WordPoints_Entity_User_Role_Name'); |
|
363 | 363 | |
364 | 364 | // Register entities for all of the public post types. |
365 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
365 | + $post_types = get_post_types(array('public' => true)); |
|
366 | 366 | |
367 | 367 | /** |
368 | 368 | * Filter which post types to register entities for. |
@@ -371,14 +371,14 @@ discard block |
||
371 | 371 | * |
372 | 372 | * @param string[] The post type slugs ("names"). |
373 | 373 | */ |
374 | - $post_types = apply_filters( 'wordpoints_register_entities_for_post_types', $post_types ); |
|
374 | + $post_types = apply_filters('wordpoints_register_entities_for_post_types', $post_types); |
|
375 | 375 | |
376 | - foreach ( $post_types as $slug ) { |
|
377 | - wordpoints_register_post_type_entities( $slug ); |
|
376 | + foreach ($post_types as $slug) { |
|
377 | + wordpoints_register_post_type_entities($slug); |
|
378 | 378 | } |
379 | 379 | |
380 | 380 | // Register entities for all of the public taxonomies. |
381 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
381 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
382 | 382 | |
383 | 383 | /** |
384 | 384 | * Filter which taxonomies to register entities for. |
@@ -387,10 +387,10 @@ discard block |
||
387 | 387 | * |
388 | 388 | * @param string[] The taxonomy slugs. |
389 | 389 | */ |
390 | - $taxonomies = apply_filters( 'wordpoints_register_entities_for_taxonomies', $taxonomies ); |
|
390 | + $taxonomies = apply_filters('wordpoints_register_entities_for_taxonomies', $taxonomies); |
|
391 | 391 | |
392 | - foreach ( $taxonomies as $slug ) { |
|
393 | - wordpoints_register_taxonomy_entities( $slug ); |
|
392 | + foreach ($taxonomies as $slug) { |
|
393 | + wordpoints_register_taxonomy_entities($slug); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
@@ -401,28 +401,28 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @param string $slug The slug of the post type. |
403 | 403 | */ |
404 | -function wordpoints_register_post_type_entities( $slug ) { |
|
404 | +function wordpoints_register_post_type_entities($slug) { |
|
405 | 405 | |
406 | 406 | $entities = wordpoints_entities(); |
407 | 407 | $children = $entities->children; |
408 | 408 | |
409 | - $entities->register( "post\\{$slug}", 'WordPoints_Entity_Post' ); |
|
410 | - $children->register( "post\\{$slug}", 'author', 'WordPoints_Entity_Post_Author' ); |
|
409 | + $entities->register("post\\{$slug}", 'WordPoints_Entity_Post'); |
|
410 | + $children->register("post\\{$slug}", 'author', 'WordPoints_Entity_Post_Author'); |
|
411 | 411 | |
412 | - $supports = get_all_post_type_supports( $slug ); |
|
412 | + $supports = get_all_post_type_supports($slug); |
|
413 | 413 | |
414 | - if ( isset( $supports['editor'] ) ) { |
|
415 | - $children->register( "post\\{$slug}", 'content', 'WordPoints_Entity_Post_Content' ); |
|
414 | + if (isset($supports['editor'])) { |
|
415 | + $children->register("post\\{$slug}", 'content', 'WordPoints_Entity_Post_Content'); |
|
416 | 416 | } |
417 | 417 | |
418 | - if ( isset( $supports['comments'] ) ) { |
|
419 | - $entities->register( "comment\\{$slug}", 'WordPoints_Entity_Comment' ); |
|
420 | - $children->register( "comment\\{$slug}", "post\\{$slug}", 'WordPoints_Entity_Comment_Post' ); |
|
421 | - $children->register( "comment\\{$slug}", 'author', 'WordPoints_Entity_Comment_Author' ); |
|
418 | + if (isset($supports['comments'])) { |
|
419 | + $entities->register("comment\\{$slug}", 'WordPoints_Entity_Comment'); |
|
420 | + $children->register("comment\\{$slug}", "post\\{$slug}", 'WordPoints_Entity_Comment_Post'); |
|
421 | + $children->register("comment\\{$slug}", 'author', 'WordPoints_Entity_Comment_Author'); |
|
422 | 422 | } |
423 | 423 | |
424 | - foreach ( get_object_taxonomies( $slug ) as $taxonomy_slug ) { |
|
425 | - $children->register( "post\\{$slug}", "terms\\{$taxonomy_slug}", 'WordPoints_Entity_Post_Terms' ); |
|
424 | + foreach (get_object_taxonomies($slug) as $taxonomy_slug) { |
|
425 | + $children->register("post\\{$slug}", "terms\\{$taxonomy_slug}", 'WordPoints_Entity_Post_Terms'); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * |
433 | 433 | * @param string $slug The slug ("name") of the post type. |
434 | 434 | */ |
435 | - do_action( 'wordpoints_register_post_type_entities', $slug ); |
|
435 | + do_action('wordpoints_register_post_type_entities', $slug); |
|
436 | 436 | } |
437 | 437 | |
438 | 438 | /** |
@@ -442,13 +442,13 @@ discard block |
||
442 | 442 | * |
443 | 443 | * @param string $slug The slug of the post type. |
444 | 444 | */ |
445 | -function wordpoints_register_post_type_hook_events( $slug ) { |
|
445 | +function wordpoints_register_post_type_hook_events($slug) { |
|
446 | 446 | |
447 | 447 | $event_slugs = array(); |
448 | 448 | |
449 | 449 | $events = wordpoints_hooks()->events; |
450 | 450 | |
451 | - if ( 'attachment' === $slug ) { |
|
451 | + if ('attachment' === $slug) { |
|
452 | 452 | |
453 | 453 | $event_slugs[] = 'media_upload'; |
454 | 454 | |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | , array( |
477 | 477 | 'actions' => array( |
478 | 478 | 'toggle_on' => 'post_publish', |
479 | - 'toggle_off' => array( 'post_depublish', 'post_delete' ), |
|
479 | + 'toggle_off' => array('post_depublish', 'post_delete'), |
|
480 | 480 | ), |
481 | 481 | 'args' => array( |
482 | 482 | "post\\{$slug}" => 'WordPoints_Hook_Arg_Dynamic', |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | ); |
486 | 486 | } |
487 | 487 | |
488 | - if ( post_type_supports( $slug, 'comments' ) ) { |
|
488 | + if (post_type_supports($slug, 'comments')) { |
|
489 | 489 | |
490 | 490 | $event_slugs[] = "comment_leave\\{$slug}"; |
491 | 491 | |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | , 'WordPoints_Hook_Event_Comment_Leave' |
495 | 495 | , array( |
496 | 496 | 'actions' => array( |
497 | - 'toggle_on' => array( 'comment_approve', 'comment_new' ), |
|
497 | + 'toggle_on' => array('comment_approve', 'comment_new'), |
|
498 | 498 | 'toggle_off' => 'comment_deapprove', |
499 | 499 | ), |
500 | 500 | 'args' => array( |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | ); |
505 | 505 | } |
506 | 506 | |
507 | - if ( is_multisite() ) { |
|
508 | - foreach ( $event_slugs as $event_slug ) { |
|
507 | + if (is_multisite()) { |
|
508 | + foreach ($event_slugs as $event_slug) { |
|
509 | 509 | $events->args->register( |
510 | 510 | $event_slug |
511 | 511 | , 'current:site' |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @param string $slug The slug ("name") of the post type. |
523 | 523 | */ |
524 | - do_action( 'wordpoints_register_post_type_hook_events', $slug ); |
|
524 | + do_action('wordpoints_register_post_type_hook_events', $slug); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
@@ -531,13 +531,13 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @param string $slug The slug of the taxonomy. |
533 | 533 | */ |
534 | -function wordpoints_register_taxonomy_entities( $slug ) { |
|
534 | +function wordpoints_register_taxonomy_entities($slug) { |
|
535 | 535 | |
536 | 536 | $entities = wordpoints_entities(); |
537 | 537 | $children = $entities->children; |
538 | 538 | |
539 | - $entities->register( "term\\{$slug}", 'WordPoints_Entity_Term' ); |
|
540 | - $children->register( "term\\{$slug}", 'id', 'WordPoints_Entity_Term_Id' ); |
|
539 | + $entities->register("term\\{$slug}", 'WordPoints_Entity_Term'); |
|
540 | + $children->register("term\\{$slug}", 'id', 'WordPoints_Entity_Term_Id'); |
|
541 | 541 | |
542 | 542 | /** |
543 | 543 | * Fired when registering the entities for a taxonomy. |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @param string $slug The taxonomy's slug. |
548 | 548 | */ |
549 | - do_action( 'wordpoints_register_taxonomy_entities', $slug ); |
|
549 | + do_action('wordpoints_register_taxonomy_entities', $slug); |
|
550 | 550 | } |
551 | 551 | |
552 | 552 | /** |
@@ -558,10 +558,10 @@ discard block |
||
558 | 558 | * |
559 | 559 | * @param WordPoints_Class_RegistryI $data_types The data types registry. |
560 | 560 | */ |
561 | -function wordpoints_data_types_init( $data_types ) { |
|
561 | +function wordpoints_data_types_init($data_types) { |
|
562 | 562 | |
563 | - $data_types->register( 'integer', 'WordPoints_Data_Type_Integer' ); |
|
564 | - $data_types->register( 'text', 'WordPoints_Data_Type_Text' ); |
|
563 | + $data_types->register('integer', 'WordPoints_Data_Type_Integer'); |
|
564 | + $data_types->register('text', 'WordPoints_Data_Type_Text'); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | * |
577 | 577 | * @return bool Whether the user can view the points log. |
578 | 578 | */ |
579 | -function wordpoints_hooks_user_can_view_points_log( $can_view, $log ) { |
|
579 | +function wordpoints_hooks_user_can_view_points_log($can_view, $log) { |
|
580 | 580 | |
581 | - if ( ! $can_view ) { |
|
581 | + if ( ! $can_view) { |
|
582 | 582 | return $can_view; |
583 | 583 | } |
584 | 584 | |
@@ -587,11 +587,11 @@ discard block |
||
587 | 587 | $event_slug = $log->log_type; |
588 | 588 | |
589 | 589 | /** @var WordPoints_Hook_Arg $arg */ |
590 | - foreach ( wordpoints_hooks()->events->args->get_children( $event_slug ) as $slug => $arg ) { |
|
590 | + foreach (wordpoints_hooks()->events->args->get_children($event_slug) as $slug => $arg) { |
|
591 | 591 | |
592 | - $value = wordpoints_get_points_log_meta( $log->id, $slug, true ); |
|
592 | + $value = wordpoints_get_points_log_meta($log->id, $slug, true); |
|
593 | 593 | |
594 | - if ( ! $value ) { |
|
594 | + if ( ! $value) { |
|
595 | 595 | continue; |
596 | 596 | } |
597 | 597 | |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | , $value |
602 | 602 | ); |
603 | 603 | |
604 | - if ( ! $can_view ) { |
|
604 | + if ( ! $can_view) { |
|
605 | 605 | break; |
606 | 606 | } |
607 | 607 | } |
@@ -620,20 +620,20 @@ discard block |
||
620 | 620 | * |
621 | 621 | * @return bool Whether the user can view this entity. |
622 | 622 | */ |
623 | -function wordpoints_entity_user_can_view( $user_id, $entity_slug, $entity_id ) { |
|
623 | +function wordpoints_entity_user_can_view($user_id, $entity_slug, $entity_id) { |
|
624 | 624 | |
625 | - $entity = wordpoints_entities()->get( $entity_slug ); |
|
625 | + $entity = wordpoints_entities()->get($entity_slug); |
|
626 | 626 | |
627 | 627 | // If this entity type is not found, we have no way of determining whether it is |
628 | 628 | // safe for the user to view it. |
629 | - if ( ! ( $entity instanceof WordPoints_Entity ) ) { |
|
629 | + if ( ! ($entity instanceof WordPoints_Entity)) { |
|
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | 633 | $can_view = true; |
634 | 634 | |
635 | - if ( $entity instanceof WordPoints_Entity_Restricted_VisibilityI ) { |
|
636 | - $can_view = $entity->user_can_view( $user_id, $entity_id ); |
|
635 | + if ($entity instanceof WordPoints_Entity_Restricted_VisibilityI) { |
|
636 | + $can_view = $entity->user_can_view($user_id, $entity_id); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | */ |
665 | 665 | function wordpoints_apps() { |
666 | 666 | |
667 | - if ( ! isset( WordPoints_App::$main ) ) { |
|
668 | - WordPoints_App::$main = new WordPoints_App( 'apps' ); |
|
667 | + if ( ! isset(WordPoints_App::$main)) { |
|
668 | + WordPoints_App::$main = new WordPoints_App('apps'); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | return WordPoints_App::$main; |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | */ |
681 | 681 | function wordpoints_hooks() { |
682 | 682 | |
683 | - if ( ! isset( WordPoints_App::$main ) ) { |
|
683 | + if ( ! isset(WordPoints_App::$main)) { |
|
684 | 684 | wordpoints_apps(); |
685 | 685 | } |
686 | 686 | |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | */ |
697 | 697 | function wordpoints_entities() { |
698 | 698 | |
699 | - if ( ! isset( WordPoints_App::$main ) ) { |
|
699 | + if ( ! isset(WordPoints_App::$main)) { |
|
700 | 700 | wordpoints_apps(); |
701 | 701 | } |
702 | 702 | |
@@ -712,13 +712,13 @@ discard block |
||
712 | 712 | * |
713 | 713 | * @param WordPoints_App $app The main apps app. |
714 | 714 | */ |
715 | -function wordpoints_apps_init( $app ) { |
|
715 | +function wordpoints_apps_init($app) { |
|
716 | 716 | |
717 | 717 | $apps = $app->sub_apps; |
718 | 718 | |
719 | - $apps->register( 'hooks', 'WordPoints_Hooks' ); |
|
720 | - $apps->register( 'entities', 'WordPoints_App_Registry' ); |
|
721 | - $apps->register( 'data_types', 'WordPoints_Class_Registry' ); |
|
719 | + $apps->register('hooks', 'WordPoints_Hooks'); |
|
720 | + $apps->register('entities', 'WordPoints_App_Registry'); |
|
721 | + $apps->register('data_types', 'WordPoints_Class_Registry'); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
@@ -731,19 +731,19 @@ discard block |
||
731 | 731 | * |
732 | 732 | * @return object|false The constructed object, or false if to many args were passed. |
733 | 733 | */ |
734 | -function wordpoints_construct_class_with_args( $class_name, array $args ) { |
|
734 | +function wordpoints_construct_class_with_args($class_name, array $args) { |
|
735 | 735 | |
736 | - switch ( count( $args ) ) { |
|
736 | + switch (count($args)) { |
|
737 | 737 | case 0: |
738 | 738 | return new $class_name(); |
739 | 739 | case 1: |
740 | - return new $class_name( $args[0] ); |
|
740 | + return new $class_name($args[0]); |
|
741 | 741 | case 2: |
742 | - return new $class_name( $args[0], $args[1] ); |
|
742 | + return new $class_name($args[0], $args[1]); |
|
743 | 743 | case 3: |
744 | - return new $class_name( $args[0], $args[1], $args[2] ); |
|
744 | + return new $class_name($args[0], $args[1], $args[2]); |
|
745 | 745 | case 4: |
746 | - return new $class_name( $args[0], $args[1], $args[2], $args[3] ); |
|
746 | + return new $class_name($args[0], $args[1], $args[2], $args[3]); |
|
747 | 747 | default: |
748 | 748 | return false; |
749 | 749 | } |
@@ -765,13 +765,13 @@ discard block |
||
765 | 765 | * @return array The slug parsed into the 'generic' and 'dynamic' portions. If the |
766 | 766 | * slug is not dynamic, the value of each of those keys will be false. |
767 | 767 | */ |
768 | -function wordpoints_parse_dynamic_slug( $slug ) { |
|
768 | +function wordpoints_parse_dynamic_slug($slug) { |
|
769 | 769 | |
770 | - $parsed = array( 'dynamic' => false, 'generic' => false ); |
|
770 | + $parsed = array('dynamic' => false, 'generic' => false); |
|
771 | 771 | |
772 | - $parts = explode( '\\', $slug, 2 ); |
|
772 | + $parts = explode('\\', $slug, 2); |
|
773 | 773 | |
774 | - if ( isset( $parts[1] ) ) { |
|
774 | + if (isset($parts[1])) { |
|
775 | 775 | $parsed['dynamic'] = $parts[1]; |
776 | 776 | $parsed['generic'] = $parts[0]; |
777 | 777 | } |
@@ -810,28 +810,28 @@ discard block |
||
810 | 810 | * contexts, indexed by context slug, or false if any of the |
811 | 811 | * contexts isn't current. |
812 | 812 | */ |
813 | -function wordpoints_entities_get_current_context_id( $slug ) { |
|
813 | +function wordpoints_entities_get_current_context_id($slug) { |
|
814 | 814 | |
815 | 815 | $current_context = array(); |
816 | 816 | |
817 | 817 | /** @var WordPoints_Class_Registry $contexts */ |
818 | 818 | $contexts = wordpoints_entities()->contexts; |
819 | 819 | |
820 | - while ( $slug ) { |
|
820 | + while ($slug) { |
|
821 | 821 | |
822 | - $context = $contexts->get( $slug ); |
|
822 | + $context = $contexts->get($slug); |
|
823 | 823 | |
824 | - if ( ! $context instanceof WordPoints_Entity_Context ) { |
|
824 | + if ( ! $context instanceof WordPoints_Entity_Context) { |
|
825 | 825 | return false; |
826 | 826 | } |
827 | 827 | |
828 | 828 | $id = $context->get_current_id(); |
829 | 829 | |
830 | - if ( false === $id ) { |
|
830 | + if (false === $id) { |
|
831 | 831 | return false; |
832 | 832 | } |
833 | 833 | |
834 | - $current_context[ $slug ] = $id; |
|
834 | + $current_context[$slug] = $id; |
|
835 | 835 | |
836 | 836 | $slug = $context->get_parent_slug(); |
837 | 837 | } |
@@ -852,22 +852,22 @@ discard block |
||
852 | 852 | */ |
853 | 853 | function wordpoints_is_network_context() { |
854 | 854 | |
855 | - if ( ! is_multisite() ) { |
|
855 | + if ( ! is_multisite()) { |
|
856 | 856 | return false; |
857 | 857 | } |
858 | 858 | |
859 | - if ( is_network_admin() ) { |
|
859 | + if (is_network_admin()) { |
|
860 | 860 | return true; |
861 | 861 | } |
862 | 862 | |
863 | 863 | // See https://core.trac.wordpress.org/ticket/22589 |
864 | 864 | if ( |
865 | - defined( 'DOING_AJAX' ) |
|
865 | + defined('DOING_AJAX') |
|
866 | 866 | && DOING_AJAX |
867 | - && isset( $_SERVER['HTTP_REFERER'] ) |
|
867 | + && isset($_SERVER['HTTP_REFERER']) |
|
868 | 868 | && preg_match( |
869 | - '#^' . preg_quote( network_admin_url(), '#' ) . '#i' |
|
870 | - , esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) |
|
869 | + '#^'.preg_quote(network_admin_url(), '#').'#i' |
|
870 | + , esc_url_raw(wp_unslash($_SERVER['HTTP_REFERER'])) |
|
871 | 871 | ) |
872 | 872 | ) { |
873 | 873 | return true; |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | * |
881 | 881 | * @param bool $in_network_context Whether we are in network context. |
882 | 882 | */ |
883 | - return apply_filters( 'wordpoints_is_network_context', false ); |
|
883 | + return apply_filters('wordpoints_is_network_context', false); |
|
884 | 884 | } |
885 | 885 | |
886 | 886 | /** |
@@ -894,21 +894,21 @@ discard block |
||
894 | 894 | * |
895 | 895 | * @return string The primary arg's GUID, JSON encoded. |
896 | 896 | */ |
897 | -function wordpoints_hooks_get_event_primary_arg_guid_json( WordPoints_Hook_Event_Args $event_args ) { |
|
897 | +function wordpoints_hooks_get_event_primary_arg_guid_json(WordPoints_Hook_Event_Args $event_args) { |
|
898 | 898 | |
899 | 899 | $entity = $event_args->get_primary_arg(); |
900 | 900 | |
901 | - if ( ! $entity ) { |
|
901 | + if ( ! $entity) { |
|
902 | 902 | return ''; |
903 | 903 | } |
904 | 904 | |
905 | 905 | $the_guid = $entity->get_the_guid(); |
906 | 906 | |
907 | - if ( ! $the_guid ) { |
|
907 | + if ( ! $the_guid) { |
|
908 | 908 | return ''; |
909 | 909 | } |
910 | 910 | |
911 | - return wp_json_encode( $the_guid ); |
|
911 | + return wp_json_encode($the_guid); |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | /** |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | */ |
922 | 922 | function wordpoints_hooks_api_add_global_cache_groups() { |
923 | 923 | |
924 | - if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
924 | + if (function_exists('wp_cache_add_global_groups')) { |
|
925 | 925 | |
926 | 926 | wp_cache_add_global_groups( |
927 | 927 | array( |
@@ -947,8 +947,8 @@ discard block |
||
947 | 947 | * @return string The escaped identifier. Already quoted, do not place within |
948 | 948 | * backticks. |
949 | 949 | */ |
950 | -function wordpoints_escape_mysql_identifier( $identifier ) { |
|
951 | - return '`' . str_replace( '`', '``', $identifier ) . '`'; |
|
950 | +function wordpoints_escape_mysql_identifier($identifier) { |
|
951 | + return '`'.str_replace('`', '``', $identifier).'`'; |
|
952 | 952 | } |
953 | 953 | |
954 | 954 | // EOF |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @since 1.0.0 |
39 | 39 | */ |
40 | - public function __construct( $slug ) { |
|
40 | + public function __construct($slug) { |
|
41 | 41 | |
42 | 42 | $hooks = wordpoints_hooks(); |
43 | 43 | |
44 | 44 | $this->router = $hooks->router; |
45 | 45 | |
46 | - parent::__construct( $slug ); |
|
46 | + parent::__construct($slug); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function init() { |
53 | 53 | |
54 | - $this->sub_apps->register( 'args', 'WordPoints_Class_Registry_Children' ); |
|
54 | + $this->sub_apps->register('args', 'WordPoints_Class_Registry_Children'); |
|
55 | 55 | |
56 | 56 | parent::init(); |
57 | 57 | } |
@@ -75,25 +75,25 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return bool Whether the event was registered. |
77 | 77 | */ |
78 | - public function register( $slug, $class, array $args = array() ) { |
|
78 | + public function register($slug, $class, array $args = array()) { |
|
79 | 79 | |
80 | - parent::register( $slug, $class, $args ); |
|
80 | + parent::register($slug, $class, $args); |
|
81 | 81 | |
82 | - if ( isset( $args['actions'] ) ) { |
|
83 | - foreach ( $args['actions'] as $type => $actions ) { |
|
84 | - foreach ( (array) $actions as $action_slug ) { |
|
85 | - $this->router->add_event_to_action( $slug, $action_slug, $type ); |
|
82 | + if (isset($args['actions'])) { |
|
83 | + foreach ($args['actions'] as $type => $actions) { |
|
84 | + foreach ((array) $actions as $action_slug) { |
|
85 | + $this->router->add_event_to_action($slug, $action_slug, $type); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | - if ( isset( $args['args'] ) ) { |
|
91 | - foreach ( $args['args'] as $arg_slug => $class ) { |
|
92 | - $this->args->register( $slug, $arg_slug, $class ); |
|
90 | + if (isset($args['args'])) { |
|
91 | + foreach ($args['args'] as $arg_slug => $class) { |
|
92 | + $this->args->register($slug, $arg_slug, $class); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | - $this->event_data[ $slug ] = $args; |
|
96 | + $this->event_data[$slug] = $args; |
|
97 | 97 | |
98 | 98 | return true; |
99 | 99 | } |
@@ -101,23 +101,23 @@ discard block |
||
101 | 101 | /** |
102 | 102 | * @since 1.0.0 |
103 | 103 | */ |
104 | - public function deregister( $slug ) { |
|
104 | + public function deregister($slug) { |
|
105 | 105 | |
106 | - if ( ! $this->is_registered( $slug ) ) { |
|
106 | + if ( ! $this->is_registered($slug)) { |
|
107 | 107 | return; |
108 | 108 | } |
109 | 109 | |
110 | - parent::deregister( $slug ); |
|
110 | + parent::deregister($slug); |
|
111 | 111 | |
112 | - foreach ( (array) $this->event_data[ $slug ]['actions'] as $type => $actions ) { |
|
113 | - foreach ( (array) $actions as $action_slug ) { |
|
114 | - $this->router->remove_event_from_action( $slug, $action_slug, $type ); |
|
112 | + foreach ((array) $this->event_data[$slug]['actions'] as $type => $actions) { |
|
113 | + foreach ((array) $actions as $action_slug) { |
|
114 | + $this->router->remove_event_from_action($slug, $action_slug, $type); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
118 | - $this->args->deregister_children( $slug ); |
|
118 | + $this->args->deregister_children($slug); |
|
119 | 119 | |
120 | - unset( $this->event_data[ $slug ] ); |
|
120 | + unset($this->event_data[$slug]); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * @since 1.0.0 |
82 | 82 | */ |
83 | - public function __call( $name, $args ) { |
|
83 | + public function __call($name, $args) { |
|
84 | 84 | |
85 | - $this->route_action( $name, $args ); |
|
85 | + $this->route_action($name, $args); |
|
86 | 86 | |
87 | 87 | // Return the first value, in case it is hooked to a filter. |
88 | 88 | $return = null; |
89 | - if ( isset( $args[0] ) ) { |
|
89 | + if (isset($args[0])) { |
|
90 | 90 | $return = $args[0]; |
91 | 91 | } |
92 | 92 | |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * action name and the priority. |
104 | 104 | * @param array $args The args the action was fired with. |
105 | 105 | */ |
106 | - protected function route_action( $name, $args ) { |
|
106 | + protected function route_action($name, $args) { |
|
107 | 107 | |
108 | - if ( ! isset( $this->action_index[ $name ] ) ) { |
|
108 | + if ( ! isset($this->action_index[$name])) { |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | // registry attempts to access the router in its own constructor. The result |
114 | 114 | // of attempting to do this before the router itself has been fully |
115 | 115 | // constructed is that the events registry gets null instead of the router. |
116 | - if ( ! isset( $this->hooks ) ) { |
|
116 | + if ( ! isset($this->hooks)) { |
|
117 | 117 | |
118 | 118 | $hooks = wordpoints_hooks(); |
119 | 119 | |
@@ -122,38 +122,38 @@ discard block |
||
122 | 122 | $this->actions = $hooks->actions; |
123 | 123 | } |
124 | 124 | |
125 | - foreach ( $this->action_index[ $name ]['actions'] as $slug => $data ) { |
|
125 | + foreach ($this->action_index[$name]['actions'] as $slug => $data) { |
|
126 | 126 | |
127 | - if ( ! isset( $this->event_index[ $slug ] ) ) { |
|
127 | + if ( ! isset($this->event_index[$slug])) { |
|
128 | 128 | continue; |
129 | 129 | } |
130 | 130 | |
131 | - $action_object = $this->actions->get( $slug, $args, $data ); |
|
131 | + $action_object = $this->actions->get($slug, $args, $data); |
|
132 | 132 | |
133 | - if ( ! ( $action_object instanceof WordPoints_Hook_ActionI ) ) { |
|
133 | + if ( ! ($action_object instanceof WordPoints_Hook_ActionI)) { |
|
134 | 134 | continue; |
135 | 135 | } |
136 | 136 | |
137 | - if ( ! $action_object->should_fire() ) { |
|
137 | + if ( ! $action_object->should_fire()) { |
|
138 | 138 | continue; |
139 | 139 | } |
140 | 140 | |
141 | - foreach ( $this->event_index[ $slug ] as $type => $events ) { |
|
142 | - foreach ( $events as $event_slug => $unused ) { |
|
141 | + foreach ($this->event_index[$slug] as $type => $events) { |
|
142 | + foreach ($events as $event_slug => $unused) { |
|
143 | 143 | |
144 | - if ( ! $this->events->is_registered( $event_slug ) ) { |
|
144 | + if ( ! $this->events->is_registered($event_slug)) { |
|
145 | 145 | continue; |
146 | 146 | } |
147 | 147 | |
148 | - $event_args = $this->events->args->get_children( $event_slug, array( $action_object ) ); |
|
148 | + $event_args = $this->events->args->get_children($event_slug, array($action_object)); |
|
149 | 149 | |
150 | - if ( empty( $event_args ) ) { |
|
150 | + if (empty($event_args)) { |
|
151 | 151 | continue; |
152 | 152 | } |
153 | 153 | |
154 | - $event_args = new WordPoints_Hook_Event_Args( $event_args ); |
|
154 | + $event_args = new WordPoints_Hook_Event_Args($event_args); |
|
155 | 155 | |
156 | - $this->hooks->fire( $type, $event_slug, $event_args ); |
|
156 | + $this->hooks->fire($type, $event_slug, $event_args); |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | } |
@@ -182,56 +182,56 @@ discard block |
||
182 | 182 | * } |
183 | 183 | * } |
184 | 184 | */ |
185 | - public function add_action( $slug, array $args ) { |
|
185 | + public function add_action($slug, array $args) { |
|
186 | 186 | |
187 | 187 | $priority = 10; |
188 | - if ( isset( $args['priority'] ) ) { |
|
188 | + if (isset($args['priority'])) { |
|
189 | 189 | $priority = $args['priority']; |
190 | 190 | } |
191 | 191 | |
192 | - if ( ! isset( $args['action'] ) ) { |
|
192 | + if ( ! isset($args['action'])) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | 195 | |
196 | 196 | $method = "{$args['action']},{$priority}"; |
197 | 197 | |
198 | - $this->action_index[ $method ]['actions'][ $slug ] = array(); |
|
198 | + $this->action_index[$method]['actions'][$slug] = array(); |
|
199 | 199 | |
200 | 200 | $arg_number = 1; |
201 | 201 | |
202 | - if ( isset( $args['data'] ) ) { |
|
202 | + if (isset($args['data'])) { |
|
203 | 203 | |
204 | - if ( isset( $args['data']['arg_index'] ) ) { |
|
205 | - $arg_number = 1 + max( $args['data']['arg_index'] ); |
|
204 | + if (isset($args['data']['arg_index'])) { |
|
205 | + $arg_number = 1 + max($args['data']['arg_index']); |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( isset( $args['data']['requirements'] ) ) { |
|
209 | - $requirements = 1 + max( array_keys( $args['data']['requirements'] ) ); |
|
208 | + if (isset($args['data']['requirements'])) { |
|
209 | + $requirements = 1 + max(array_keys($args['data']['requirements'])); |
|
210 | 210 | |
211 | - if ( $requirements > $arg_number ) { |
|
211 | + if ($requirements > $arg_number) { |
|
212 | 212 | $arg_number = $requirements; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - $this->action_index[ $method ]['actions'][ $slug ] = $args['data']; |
|
216 | + $this->action_index[$method]['actions'][$slug] = $args['data']; |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( isset( $args['arg_number'] ) ) { |
|
219 | + if (isset($args['arg_number'])) { |
|
220 | 220 | $arg_number = $args['arg_number']; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // If this action is already being routed, and will have enough args, we |
224 | 224 | // don't need to hook to it again. |
225 | 225 | if ( |
226 | - isset( $this->action_index[ $method ]['arg_number'] ) |
|
227 | - && $this->action_index[ $method ]['arg_number'] >= $arg_number |
|
226 | + isset($this->action_index[$method]['arg_number']) |
|
227 | + && $this->action_index[$method]['arg_number'] >= $arg_number |
|
228 | 228 | ) { |
229 | 229 | return; |
230 | 230 | } |
231 | 231 | |
232 | - $this->action_index[ $method ]['arg_number'] = $arg_number; |
|
232 | + $this->action_index[$method]['arg_number'] = $arg_number; |
|
233 | 233 | |
234 | - add_action( $args['action'], array( $this, $method ), $priority, $arg_number ); |
|
234 | + add_action($args['action'], array($this, $method), $priority, $arg_number); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @param string $slug The action slug. |
243 | 243 | */ |
244 | - public function remove_action( $slug ) { |
|
244 | + public function remove_action($slug) { |
|
245 | 245 | |
246 | - foreach ( $this->action_index as $method => $data ) { |
|
247 | - if ( isset( $data['actions'][ $slug ] ) ) { |
|
246 | + foreach ($this->action_index as $method => $data) { |
|
247 | + if (isset($data['actions'][$slug])) { |
|
248 | 248 | |
249 | - unset( $this->action_index[ $method ]['actions'][ $slug ] ); |
|
249 | + unset($this->action_index[$method]['actions'][$slug]); |
|
250 | 250 | |
251 | - if ( empty( $this->action_index[ $method ]['actions'] ) ) { |
|
251 | + if (empty($this->action_index[$method]['actions'])) { |
|
252 | 252 | |
253 | - unset( $this->action_index[ $method ] ); |
|
253 | + unset($this->action_index[$method]); |
|
254 | 254 | |
255 | - list( $action, $priority ) = explode( ',', $method ); |
|
255 | + list($action, $priority) = explode(',', $method); |
|
256 | 256 | |
257 | - remove_action( $action, array( $this, $method ), $priority ); |
|
257 | + remove_action($action, array($this, $method), $priority); |
|
258 | 258 | } |
259 | 259 | } |
260 | 260 | } |
@@ -269,8 +269,8 @@ discard block |
||
269 | 269 | * @param string $action_slug The slug of the action. |
270 | 270 | * @param string $action_type The type of action. Default is 'fire'. |
271 | 271 | */ |
272 | - public function add_event_to_action( $event_slug, $action_slug, $action_type = 'fire' ) { |
|
273 | - $this->event_index[ $action_slug ][ $action_type ][ $event_slug ] = true; |
|
272 | + public function add_event_to_action($event_slug, $action_slug, $action_type = 'fire') { |
|
273 | + $this->event_index[$action_slug][$action_type][$event_slug] = true; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * @param string $action_slug The slug of the action. |
283 | 283 | * @param string $action_type The type of action. Default is 'fire'. |
284 | 284 | */ |
285 | - public function remove_event_from_action( $event_slug, $action_slug, $action_type = 'fire' ) { |
|
286 | - unset( $this->event_index[ $action_slug ][ $action_type ][ $event_slug ] ); |
|
285 | + public function remove_event_from_action($event_slug, $action_slug, $action_type = 'fire') { |
|
286 | + unset($this->event_index[$action_slug][$action_type][$event_slug]); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function get_event_index() { |
297 | 297 | |
298 | - if ( empty( $this->event_index ) ) { |
|
298 | + if (empty($this->event_index)) { |
|
299 | 299 | wordpoints_hooks()->events; |
300 | 300 | } |
301 | 301 |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | public function get_ui_script_data() { |
37 | 37 | |
38 | 38 | $periods = array( |
39 | - MINUTE_IN_SECONDS => __( 'Minute', 'wordpoints' ), |
|
40 | - HOUR_IN_SECONDS => __( 'Hour', 'wordpoints' ), |
|
41 | - DAY_IN_SECONDS => __( 'Day', 'wordpoints' ), |
|
42 | - WEEK_IN_SECONDS => __( 'Week', 'wordpoints' ), |
|
43 | - 30 * DAY_IN_SECONDS => __( 'Month', 'wordpoints' ), |
|
39 | + MINUTE_IN_SECONDS => __('Minute', 'wordpoints'), |
|
40 | + HOUR_IN_SECONDS => __('Hour', 'wordpoints'), |
|
41 | + DAY_IN_SECONDS => __('Day', 'wordpoints'), |
|
42 | + WEEK_IN_SECONDS => __('Week', 'wordpoints'), |
|
43 | + 30 * DAY_IN_SECONDS => __('Month', 'wordpoints'), |
|
44 | 44 | ); |
45 | 45 | |
46 | 46 | /** |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param string[] $periods The period titles, indexed by length in seconds. |
52 | 52 | */ |
53 | - $periods = apply_filters( 'wordpoints_hooks_ui_data_periods', $periods ); |
|
53 | + $periods = apply_filters('wordpoints_hooks_ui_data_periods', $periods); |
|
54 | 54 | |
55 | 55 | return array( |
56 | 56 | 'periods' => $periods, |
57 | 57 | 'l10n' => array( |
58 | - 'label' => __( 'Trigger reaction no more than once per:', 'wordpoints' ), |
|
58 | + 'label' => __('Trigger reaction no more than once per:', 'wordpoints'), |
|
59 | 59 | ), |
60 | 60 | ); |
61 | 61 | } |
@@ -69,25 +69,25 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return array The validated periods. |
71 | 71 | */ |
72 | - protected function validate_action_type_settings( $periods ) { |
|
72 | + protected function validate_action_type_settings($periods) { |
|
73 | 73 | |
74 | - if ( ! is_array( $periods ) ) { |
|
74 | + if ( ! is_array($periods)) { |
|
75 | 75 | |
76 | 76 | $this->validator->add_error( |
77 | - __( 'Periods do not match expected format.', 'wordpoints' ) |
|
77 | + __('Periods do not match expected format.', 'wordpoints') |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | return array(); |
81 | 81 | } |
82 | 82 | |
83 | - foreach ( $periods as $index => $period ) { |
|
83 | + foreach ($periods as $index => $period) { |
|
84 | 84 | |
85 | - $this->validator->push_field( $index ); |
|
85 | + $this->validator->push_field($index); |
|
86 | 86 | |
87 | - $period = $this->validate_period( $period ); |
|
87 | + $period = $this->validate_period($period); |
|
88 | 88 | |
89 | - if ( $period ) { |
|
90 | - $periods[ $index ] = $period; |
|
89 | + if ($period) { |
|
90 | + $periods[$index] = $period; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | $this->validator->pop_field(); |
@@ -105,30 +105,30 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return array|false The validated period, or false if invalid. |
107 | 107 | */ |
108 | - protected function validate_period( $period ) { |
|
108 | + protected function validate_period($period) { |
|
109 | 109 | |
110 | - if ( ! is_array( $period ) ) { |
|
110 | + if ( ! is_array($period)) { |
|
111 | 111 | $this->validator->add_error( |
112 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
112 | + __('Period does not match expected format.', 'wordpoints') |
|
113 | 113 | ); |
114 | 114 | |
115 | 115 | return false; |
116 | 116 | } |
117 | 117 | |
118 | - if ( isset( $period['args'] ) ) { |
|
119 | - $this->validate_period_args( $period['args'] ); |
|
118 | + if (isset($period['args'])) { |
|
119 | + $this->validate_period_args($period['args']); |
|
120 | 120 | } |
121 | 121 | |
122 | - if ( ! isset( $period['length'] ) ) { |
|
122 | + if ( ! isset($period['length'])) { |
|
123 | 123 | |
124 | 124 | $this->validator->add_error( |
125 | - __( 'Period length setting is missing.', 'wordpoints' ) |
|
125 | + __('Period length setting is missing.', 'wordpoints') |
|
126 | 126 | ); |
127 | 127 | |
128 | - } elseif ( false === wordpoints_posint( $period['length'] ) ) { |
|
128 | + } elseif (false === wordpoints_posint($period['length'])) { |
|
129 | 129 | |
130 | 130 | $this->validator->add_error( |
131 | - __( 'Period length must be a positive integer.', 'wordpoints' ) |
|
131 | + __('Period length must be a positive integer.', 'wordpoints') |
|
132 | 132 | , 'length' |
133 | 133 | ); |
134 | 134 | |
@@ -145,34 +145,34 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param mixed $args The args the period is related to. |
147 | 147 | */ |
148 | - protected function validate_period_args( $args ) { |
|
148 | + protected function validate_period_args($args) { |
|
149 | 149 | |
150 | - if ( ! is_array( $args ) ) { |
|
150 | + if ( ! is_array($args)) { |
|
151 | 151 | |
152 | 152 | $this->validator->add_error( |
153 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
153 | + __('Period does not match expected format.', 'wordpoints') |
|
154 | 154 | , 'args' |
155 | 155 | ); |
156 | 156 | |
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
160 | - $this->validator->push_field( 'args' ); |
|
160 | + $this->validator->push_field('args'); |
|
161 | 161 | |
162 | - foreach ( $args as $index => $hierarchy ) { |
|
162 | + foreach ($args as $index => $hierarchy) { |
|
163 | 163 | |
164 | - $this->validator->push_field( $index ); |
|
164 | + $this->validator->push_field($index); |
|
165 | 165 | |
166 | - if ( ! is_array( $hierarchy ) ) { |
|
166 | + if ( ! is_array($hierarchy)) { |
|
167 | 167 | |
168 | 168 | $this->validator->add_error( |
169 | - __( 'Period does not match expected format.', 'wordpoints' ) |
|
169 | + __('Period does not match expected format.', 'wordpoints') |
|
170 | 170 | ); |
171 | 171 | |
172 | - } elseif ( ! $this->event_args->get_from_hierarchy( $hierarchy ) ) { |
|
172 | + } elseif ( ! $this->event_args->get_from_hierarchy($hierarchy)) { |
|
173 | 173 | |
174 | 174 | $this->validator->add_error( |
175 | - __( 'Invalid period.', 'wordpoints' ) // TODO better error message |
|
175 | + __('Invalid period.', 'wordpoints') // TODO better error message |
|
176 | 176 | ); |
177 | 177 | } |
178 | 178 | |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | /** |
186 | 186 | * @since 1.0.0 |
187 | 187 | */ |
188 | - public function should_hit( WordPoints_Hook_Fire $fire ) { |
|
188 | + public function should_hit(WordPoints_Hook_Fire $fire) { |
|
189 | 189 | |
190 | - $periods = $this->get_settings_from_fire( $fire ); |
|
190 | + $periods = $this->get_settings_from_fire($fire); |
|
191 | 191 | |
192 | - if ( empty( $periods ) ) { |
|
192 | + if (empty($periods)) { |
|
193 | 193 | return true; |
194 | 194 | } |
195 | 195 | |
196 | 196 | $this->event_args = $fire->event_args; |
197 | 197 | $this->action_type = $fire->action_type; |
198 | 198 | |
199 | - foreach ( $periods as $period ) { |
|
200 | - if ( ! $this->has_period_ended( $period, $fire->reaction ) ) { |
|
199 | + foreach ($periods as $period) { |
|
200 | + if ( ! $this->has_period_ended($period, $fire->reaction)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | } |
@@ -221,24 +221,24 @@ discard block |
||
221 | 221 | ) { |
222 | 222 | |
223 | 223 | $period = $this->get_period_by_reaction( |
224 | - $this->get_period_signature( $settings, $reaction ) |
|
224 | + $this->get_period_signature($settings, $reaction) |
|
225 | 225 | , $reaction |
226 | 226 | ); |
227 | 227 | |
228 | 228 | // If the period isn't found, we know that we can still fire. |
229 | - if ( ! $period ) { |
|
229 | + if ( ! $period) { |
|
230 | 230 | return true; |
231 | 231 | } |
232 | 232 | |
233 | - $now = current_time( 'timestamp' ); |
|
234 | - $hit_time = strtotime( $period->date, $now ); |
|
233 | + $now = current_time('timestamp'); |
|
234 | + $hit_time = strtotime($period->date, $now); |
|
235 | 235 | |
236 | - if ( ! empty( $settings['relative'] ) ) { |
|
237 | - return ( $hit_time < $now - $settings['length'] ); |
|
236 | + if ( ! empty($settings['relative'])) { |
|
237 | + return ($hit_time < $now - $settings['length']); |
|
238 | 238 | } else { |
239 | 239 | return ( |
240 | - (int) ( $hit_time / $settings['length'] ) |
|
241 | - < (int) ( $now / $settings['length'] ) |
|
240 | + (int) ($hit_time / $settings['length']) |
|
241 | + < (int) ($now / $settings['length']) |
|
242 | 242 | ); |
243 | 243 | } |
244 | 244 | } |
@@ -252,24 +252,24 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @return array The arg values. |
254 | 254 | */ |
255 | - protected function get_arg_values( array $period_args ) { |
|
255 | + protected function get_arg_values(array $period_args) { |
|
256 | 256 | |
257 | 257 | $values = array(); |
258 | 258 | |
259 | - foreach ( $period_args as $arg_hierarchy ) { |
|
259 | + foreach ($period_args as $arg_hierarchy) { |
|
260 | 260 | |
261 | 261 | $arg = $this->event_args->get_from_hierarchy( |
262 | 262 | $arg_hierarchy |
263 | 263 | ); |
264 | 264 | |
265 | - if ( ! $arg instanceof WordPoints_EntityishI ) { |
|
265 | + if ( ! $arg instanceof WordPoints_EntityishI) { |
|
266 | 266 | continue; |
267 | 267 | } |
268 | 268 | |
269 | - $values[ implode( '.', $arg_hierarchy ) ] = $arg->get_the_value(); |
|
269 | + $values[implode('.', $arg_hierarchy)] = $arg->get_the_value(); |
|
270 | 270 | } |
271 | 271 | |
272 | - ksort( $values ); |
|
272 | + ksort($values); |
|
273 | 273 | |
274 | 274 | return $values; |
275 | 275 | } |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | * |
284 | 284 | * @return object|false The period data, or false if not found. |
285 | 285 | */ |
286 | - protected function get_period( $period_id ) { |
|
286 | + protected function get_period($period_id) { |
|
287 | 287 | |
288 | - $period = wp_cache_get( $period_id, 'wordpoints_hook_periods' ); |
|
288 | + $period = wp_cache_get($period_id, 'wordpoints_hook_periods'); |
|
289 | 289 | |
290 | - if ( ! $period ) { |
|
290 | + if ( ! $period) { |
|
291 | 291 | |
292 | 292 | global $wpdb; |
293 | 293 | |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | ) |
305 | 305 | ); |
306 | 306 | |
307 | - if ( ! $period ) { |
|
307 | + if ( ! $period) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | |
311 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
311 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | return $period; |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | |
333 | 333 | $reaction_guid = $reaction->get_guid(); |
334 | 334 | |
335 | - $cache_key = wp_json_encode( $reaction_guid ) . "-{$signature}-{$this->action_type}"; |
|
335 | + $cache_key = wp_json_encode($reaction_guid)."-{$signature}-{$this->action_type}"; |
|
336 | 336 | |
337 | 337 | // Before we run the query, we try to lookup the ID in the cache. |
338 | - $period_id = wp_cache_get( $cache_key, 'wordpoints_hook_period_ids_by_reaction' ); |
|
338 | + $period_id = wp_cache_get($cache_key, 'wordpoints_hook_period_ids_by_reaction'); |
|
339 | 339 | |
340 | 340 | // If we found it, we can retrieve the period by ID instead. |
341 | - if ( $period_id ) { |
|
342 | - return $this->get_period( $period_id ); |
|
341 | + if ($period_id) { |
|
342 | + return $this->get_period($period_id); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | global $wpdb; |
@@ -362,18 +362,18 @@ discard block |
||
362 | 362 | " |
363 | 363 | , $signature |
364 | 364 | , $reaction_guid['store'] |
365 | - , wp_json_encode( $reaction_guid['context_id'] ) |
|
365 | + , wp_json_encode($reaction_guid['context_id']) |
|
366 | 366 | , $reaction_guid['id'] |
367 | 367 | , $this->action_type |
368 | 368 | ) |
369 | 369 | ); |
370 | 370 | |
371 | - if ( ! $period ) { |
|
371 | + if ( ! $period) { |
|
372 | 372 | return false; |
373 | 373 | } |
374 | 374 | |
375 | - wp_cache_set( $cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction' ); |
|
376 | - wp_cache_set( $period->id, $period, 'wordpoints_hook_periods' ); |
|
375 | + wp_cache_set($cache_key, $period->id, 'wordpoints_hook_period_ids_by_reaction'); |
|
376 | + wp_cache_set($period->id, $period, 'wordpoints_hook_periods'); |
|
377 | 377 | |
378 | 378 | return $period; |
379 | 379 | } |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | /** |
382 | 382 | * @since 1.0.0 |
383 | 383 | */ |
384 | - public function after_hit( WordPoints_Hook_Fire $fire ) { |
|
384 | + public function after_hit(WordPoints_Hook_Fire $fire) { |
|
385 | 385 | |
386 | - $periods = $this->get_settings_from_fire( $fire ); |
|
386 | + $periods = $this->get_settings_from_fire($fire); |
|
387 | 387 | |
388 | - if ( empty( $periods ) ) { |
|
388 | + if (empty($periods)) { |
|
389 | 389 | return; |
390 | 390 | } |
391 | 391 | |
392 | 392 | $this->event_args = $fire->event_args; |
393 | 393 | $this->action_type = $fire->action_type; |
394 | 394 | |
395 | - foreach ( $periods as $settings ) { |
|
395 | + foreach ($periods as $settings) { |
|
396 | 396 | |
397 | 397 | $this->add_period( |
398 | - $this->get_period_signature( $settings, $fire->reaction ) |
|
398 | + $this->get_period_signature($settings, $fire->reaction) |
|
399 | 399 | , $fire |
400 | 400 | ); |
401 | 401 | } |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | WordPoints_Hook_ReactionI $reaction |
421 | 421 | ) { |
422 | 422 | |
423 | - if ( isset( $settings['args'] ) ) { |
|
423 | + if (isset($settings['args'])) { |
|
424 | 424 | $period_args = $settings['args']; |
425 | 425 | } else { |
426 | - $period_args = array( $reaction->get_meta( 'target' ) ); |
|
426 | + $period_args = array($reaction->get_meta('target')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return wordpoints_hash( |
430 | - wp_json_encode( $this->get_arg_values( $period_args ) ) |
|
430 | + wp_json_encode($this->get_arg_values($period_args)) |
|
431 | 431 | ); |
432 | 432 | } |
433 | 433 | |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return false|object The period data, or false if not found. |
443 | 443 | */ |
444 | - protected function add_period( $signature, WordPoints_Hook_Fire $fire ) { |
|
444 | + protected function add_period($signature, WordPoints_Hook_Fire $fire) { |
|
445 | 445 | |
446 | 446 | global $wpdb; |
447 | 447 | |
@@ -451,17 +451,17 @@ discard block |
||
451 | 451 | 'hit_id' => $fire->hit_id, |
452 | 452 | 'signature' => $signature, |
453 | 453 | ) |
454 | - , array( '%d', '%s' ) |
|
454 | + , array('%d', '%s') |
|
455 | 455 | ); |
456 | 456 | |
457 | - if ( ! $inserted ) { |
|
457 | + if ( ! $inserted) { |
|
458 | 458 | return false; |
459 | 459 | } |
460 | 460 | |
461 | 461 | $period_id = $wpdb->insert_id; |
462 | 462 | |
463 | 463 | wp_cache_set( |
464 | - wp_json_encode( $fire->reaction->get_guid() ) . "-{$signature}-{$this->action_type}" |
|
464 | + wp_json_encode($fire->reaction->get_guid())."-{$signature}-{$this->action_type}" |
|
465 | 465 | , $period_id |
466 | 466 | , 'wordpoints_hook_period_ids_by_reaction' |
467 | 467 | ); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | /** |
28 | 28 | * @since 1.0.0 |
29 | 29 | */ |
30 | - protected $action_types = array( 'fire', 'toggle_on', 'toggle_off' ); |
|
30 | + protected $action_types = array('fire', 'toggle_on', 'toggle_off'); |
|
31 | 31 | |
32 | 32 | /** |
33 | 33 | * @since 1.0.0 |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function get_settings_fields() { |
60 | 60 | |
61 | - $this->settings_fields['points']['label'] = _x( 'Points', 'form label', 'wordpoints' ); |
|
62 | - $this->settings_fields['log_text']['label'] = _x( 'Log Text', 'form label', 'wordpoints' ); |
|
63 | - $this->settings_fields['description']['label'] = _x( 'Description', 'form label', 'wordpoints' ); |
|
61 | + $this->settings_fields['points']['label'] = _x('Points', 'form label', 'wordpoints'); |
|
62 | + $this->settings_fields['log_text']['label'] = _x('Log Text', 'form label', 'wordpoints'); |
|
63 | + $this->settings_fields['description']['label'] = _x('Description', 'form label', 'wordpoints'); |
|
64 | 64 | |
65 | 65 | return parent::get_settings_fields(); |
66 | 66 | } |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | |
73 | 73 | $data = parent::get_ui_script_data(); |
74 | 74 | |
75 | - $data['target_label'] = __( 'Award To', 'wordpoints' ); |
|
76 | - $data['periods_label'] = __( 'Award each user no more than once per:', 'wordpoints' ); |
|
75 | + $data['target_label'] = __('Award To', 'wordpoints'); |
|
76 | + $data['periods_label'] = __('Award each user no more than once per:', 'wordpoints'); |
|
77 | 77 | |
78 | 78 | return $data; |
79 | 79 | } |
@@ -87,23 +87,23 @@ discard block |
||
87 | 87 | WordPoints_Hook_Event_Args $event_args |
88 | 88 | ) { |
89 | 89 | |
90 | - if ( ! isset( $settings['points'] ) || false === wordpoints_int( $settings['points'] ) ) { |
|
91 | - $validator->add_error( __( 'Points must be an integer.', 'wordpoints' ), 'points' ); |
|
90 | + if ( ! isset($settings['points']) || false === wordpoints_int($settings['points'])) { |
|
91 | + $validator->add_error(__('Points must be an integer.', 'wordpoints'), 'points'); |
|
92 | 92 | } |
93 | 93 | |
94 | - if ( ! isset( $settings['points_type'] ) || ! wordpoints_is_points_type( $settings['points_type'] ) ) { |
|
95 | - $validator->add_error( __( 'Invalid points type.', 'wordpoints' ), 'points_type' ); |
|
94 | + if ( ! isset($settings['points_type']) || ! wordpoints_is_points_type($settings['points_type'])) { |
|
95 | + $validator->add_error(__('Invalid points type.', 'wordpoints'), 'points_type'); |
|
96 | 96 | } |
97 | 97 | |
98 | - if ( ! isset( $settings['description'] ) ) { |
|
99 | - $validator->add_error( __( 'Description is required.', 'wordpoints' ), 'description' ); |
|
98 | + if ( ! isset($settings['description'])) { |
|
99 | + $validator->add_error(__('Description is required.', 'wordpoints'), 'description'); |
|
100 | 100 | } |
101 | 101 | |
102 | - if ( ! isset( $settings['log_text'] ) ) { |
|
103 | - $validator->add_error( __( 'Log Text is required.', 'wordpoints' ), 'log_text' ); |
|
102 | + if ( ! isset($settings['log_text'])) { |
|
103 | + $validator->add_error(__('Log Text is required.', 'wordpoints'), 'log_text'); |
|
104 | 104 | } |
105 | 105 | |
106 | - return parent::validate_settings( $settings, $validator, $event_args ); |
|
106 | + return parent::validate_settings($settings, $validator, $event_args); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -114,54 +114,54 @@ discard block |
||
114 | 114 | array $settings |
115 | 115 | ) { |
116 | 116 | |
117 | - parent::update_settings( $reaction, $settings ); |
|
117 | + parent::update_settings($reaction, $settings); |
|
118 | 118 | |
119 | - $reaction->update_meta( 'points', $settings['points'] ); |
|
120 | - $reaction->update_meta( 'points_type', $settings['points_type'] ); |
|
121 | - $reaction->update_meta( 'description', $settings['description'] ); |
|
122 | - $reaction->update_meta( 'log_text', $settings['log_text'] ); |
|
119 | + $reaction->update_meta('points', $settings['points']); |
|
120 | + $reaction->update_meta('points_type', $settings['points_type']); |
|
121 | + $reaction->update_meta('description', $settings['description']); |
|
122 | + $reaction->update_meta('log_text', $settings['log_text']); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | 126 | * @since 1.0.0 |
127 | 127 | */ |
128 | - public function hit( WordPoints_Hook_Fire $fire ) { |
|
128 | + public function hit(WordPoints_Hook_Fire $fire) { |
|
129 | 129 | |
130 | - if ( 'toggle_off' === $fire->action_type ) { |
|
131 | - $this->reverse_hit( $fire ); |
|
130 | + if ('toggle_off' === $fire->action_type) { |
|
131 | + $this->reverse_hit($fire); |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
135 | 135 | $reaction = $fire->reaction; |
136 | 136 | |
137 | 137 | $target = $fire->event_args->get_from_hierarchy( |
138 | - $reaction->get_meta( 'target' ) |
|
138 | + $reaction->get_meta('target') |
|
139 | 139 | ); |
140 | 140 | |
141 | - if ( ! $target instanceof WordPoints_Entity ) { |
|
141 | + if ( ! $target instanceof WordPoints_Entity) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | 145 | $meta = array(); |
146 | 146 | |
147 | - foreach ( $fire->event_args->get_entities() as $entity ) { |
|
148 | - $meta[ $entity->get_slug() ] = $entity->get_the_id(); |
|
147 | + foreach ($fire->event_args->get_entities() as $entity) { |
|
148 | + $meta[$entity->get_slug()] = $entity->get_the_id(); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | wordpoints_alter_points( |
152 | 152 | $target->get_the_id() |
153 | - , $reaction->get_meta( 'points' ) |
|
154 | - , $reaction->get_meta( 'points_type' ) |
|
153 | + , $reaction->get_meta('points') |
|
154 | + , $reaction->get_meta('points_type') |
|
155 | 155 | , $reaction->get_event_slug() |
156 | 156 | , $meta |
157 | - , $reaction->get_meta( 'log_text' ) |
|
157 | + , $reaction->get_meta('log_text') |
|
158 | 158 | ); |
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * @since 1.0.0 |
163 | 163 | */ |
164 | - public function reverse_hit( WordPoints_Hook_Fire $fire ) { |
|
164 | + public function reverse_hit(WordPoints_Hook_Fire $fire) { |
|
165 | 165 | |
166 | 166 | $meta_queries = array( |
167 | 167 | array( |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | ), |
173 | 173 | ); |
174 | 174 | |
175 | - foreach ( $fire->event_args->get_entities() as $slug => $entity ) { |
|
175 | + foreach ($fire->event_args->get_entities() as $slug => $entity) { |
|
176 | 176 | |
177 | 177 | $meta_queries[] = array( |
178 | 178 | 'key' => $slug, |
@@ -189,35 +189,35 @@ discard block |
||
189 | 189 | |
190 | 190 | $logs = $query->get(); |
191 | 191 | |
192 | - if ( ! $logs ) { |
|
192 | + if ( ! $logs) { |
|
193 | 193 | return; |
194 | 194 | } |
195 | 195 | |
196 | 196 | global $wpdb; |
197 | 197 | |
198 | - add_filter( 'wordpoints_points_log', '__return_false' ); |
|
198 | + add_filter('wordpoints_points_log', '__return_false'); |
|
199 | 199 | |
200 | - foreach ( $logs as $log ) { |
|
200 | + foreach ($logs as $log) { |
|
201 | 201 | |
202 | 202 | wordpoints_alter_points( |
203 | 203 | $log->user_id |
204 | 204 | , -$log->points |
205 | 205 | , $log->points_type |
206 | 206 | , "reverse-{$log->log_type}" |
207 | - , array( 'original_log_id' => $log->id ) |
|
207 | + , array('original_log_id' => $log->id) |
|
208 | 208 | ); |
209 | 209 | |
210 | - wordpoints_points_log_delete_all_metadata( $log->id ); |
|
210 | + wordpoints_points_log_delete_all_metadata($log->id); |
|
211 | 211 | |
212 | 212 | // Now delete the log. |
213 | 213 | $wpdb->delete( |
214 | 214 | $wpdb->wordpoints_points_logs |
215 | - , array( 'id' => $log->id ) |
|
215 | + , array('id' => $log->id) |
|
216 | 216 | , '%d' |
217 | 217 | ); // WPCS: cache OK, cleaned by wordpoints_alter_points(). |
218 | 218 | } |
219 | 219 | |
220 | - remove_filter( 'wordpoints_points_log', '__return_false' ); |
|
220 | + remove_filter('wordpoints_points_log', '__return_false'); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 |
@@ -143,21 +143,21 @@ discard block |
||
143 | 143 | ) { |
144 | 144 | |
145 | 145 | if ( |
146 | - empty( $settings['target'] ) |
|
147 | - || ! is_array( $settings['target'] ) |
|
146 | + empty($settings['target']) |
|
147 | + || ! is_array($settings['target']) |
|
148 | 148 | ) { |
149 | 149 | |
150 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
150 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
151 | 151 | |
152 | 152 | } else { |
153 | 153 | |
154 | - $target = $event_args->get_from_hierarchy( $settings['target'] ); |
|
154 | + $target = $event_args->get_from_hierarchy($settings['target']); |
|
155 | 155 | |
156 | 156 | if ( |
157 | 157 | ! $target instanceof WordPoints_Entity |
158 | - || ! in_array( $target->get_slug(), (array) $this->arg_types ) |
|
158 | + || ! in_array($target->get_slug(), (array) $this->arg_types) |
|
159 | 159 | ) { |
160 | - $validator->add_error( __( 'Invalid target.', 'wordpoints' ), 'target' ); |
|
160 | + $validator->add_error(__('Invalid target.', 'wordpoints'), 'target'); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | /** |
168 | 168 | * @since 1.0.0 |
169 | 169 | */ |
170 | - public function update_settings( WordPoints_Hook_ReactionI $reaction, array $settings ) { |
|
171 | - $reaction->update_meta( 'target', $settings['target'] ); |
|
170 | + public function update_settings(WordPoints_Hook_ReactionI $reaction, array $settings) { |
|
171 | + $reaction->update_meta('target', $settings['target']); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
180 | 180 | */ |
181 | - abstract public function hit( WordPoints_Hook_Fire $fire ); |
|
181 | + abstract public function hit(WordPoints_Hook_Fire $fire); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // EOF |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | protected function init() { |
47 | 47 | |
48 | 48 | $sub_apps = $this->sub_apps; |
49 | - $sub_apps->register( 'router', 'WordPoints_Hook_Router' ); |
|
50 | - $sub_apps->register( 'actions', 'WordPoints_Hook_Actions' ); |
|
51 | - $sub_apps->register( 'events', 'WordPoints_Hook_Events' ); |
|
52 | - $sub_apps->register( 'reactors', 'WordPoints_Class_Registry_Persistent' ); |
|
53 | - $sub_apps->register( 'reaction_stores', 'WordPoints_Class_Registry_Children' ); |
|
54 | - $sub_apps->register( 'extensions', 'WordPoints_Class_Registry_Persistent' ); |
|
55 | - $sub_apps->register( 'conditions', 'WordPoints_Class_Registry_Children' ); |
|
49 | + $sub_apps->register('router', 'WordPoints_Hook_Router'); |
|
50 | + $sub_apps->register('actions', 'WordPoints_Hook_Actions'); |
|
51 | + $sub_apps->register('events', 'WordPoints_Hook_Events'); |
|
52 | + $sub_apps->register('reactors', 'WordPoints_Class_Registry_Persistent'); |
|
53 | + $sub_apps->register('reaction_stores', 'WordPoints_Class_Registry_Children'); |
|
54 | + $sub_apps->register('extensions', 'WordPoints_Class_Registry_Persistent'); |
|
55 | + $sub_apps->register('conditions', 'WordPoints_Class_Registry_Children'); |
|
56 | 56 | |
57 | 57 | parent::init(); |
58 | 58 | } |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function get_current_mode() { |
77 | 77 | |
78 | - if ( ! isset( $this->current_mode ) ) { |
|
79 | - $this->current_mode = ( wordpoints_is_network_context() ? 'network' : 'standard' ); |
|
78 | + if ( ! isset($this->current_mode)) { |
|
79 | + $this->current_mode = (wordpoints_is_network_context() ? 'network' : 'standard'); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return $this->current_mode; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param string $mode The slug of the mode to set as the current mode. |
96 | 96 | */ |
97 | - public function set_current_mode( $mode ) { |
|
97 | + public function set_current_mode($mode) { |
|
98 | 98 | $this->current_mode = $mode; |
99 | 99 | } |
100 | 100 | |
@@ -107,19 +107,19 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return WordPoints_Hook_Reaction_StoreI|false The reaction storage object. |
109 | 109 | */ |
110 | - public function get_reaction_store( $slug ) { |
|
110 | + public function get_reaction_store($slug) { |
|
111 | 111 | |
112 | 112 | $reaction_store = $this->reaction_stores->get( |
113 | 113 | $this->get_current_mode() |
114 | 114 | , $slug |
115 | 115 | ); |
116 | 116 | |
117 | - if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI ) { |
|
117 | + if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI) { |
|
118 | 118 | return false; |
119 | 119 | } |
120 | 120 | |
121 | 121 | // Allowing access to stores out-of-context would lead to strange behavior. |
122 | - if ( false === $reaction_store->get_context_id() ) { |
|
122 | + if (false === $reaction_store->get_context_id()) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
@@ -142,19 +142,19 @@ discard block |
||
142 | 142 | WordPoints_Hook_Event_Args $event_args |
143 | 143 | ) { |
144 | 144 | |
145 | - foreach ( $this->reaction_stores->get_all() as $reaction_stores ) { |
|
146 | - foreach ( $reaction_stores as $reaction_store ) { |
|
145 | + foreach ($this->reaction_stores->get_all() as $reaction_stores) { |
|
146 | + foreach ($reaction_stores as $reaction_store) { |
|
147 | 147 | |
148 | - if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI ) { |
|
148 | + if ( ! $reaction_store instanceof WordPoints_Hook_Reaction_StoreI) { |
|
149 | 149 | continue; |
150 | 150 | } |
151 | 151 | |
152 | 152 | // Allowing access to stores out-of-context would lead to strange behavior. |
153 | - if ( false === $reaction_store->get_context_id() ) { |
|
153 | + if (false === $reaction_store->get_context_id()) { |
|
154 | 154 | continue; |
155 | 155 | } |
156 | 156 | |
157 | - foreach ( $reaction_store->get_reactions_to_event( $event_slug ) as $reaction ) { |
|
157 | + foreach ($reaction_store->get_reactions_to_event($event_slug) as $reaction) { |
|
158 | 158 | |
159 | 159 | $fire = new WordPoints_Hook_Fire( |
160 | 160 | $action_type |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | , $reaction |
163 | 163 | ); |
164 | 164 | |
165 | - $this->fire_reaction( $fire ); |
|
165 | + $this->fire_reaction($fire); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | } |
@@ -175,39 +175,39 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @param WordPoints_Hook_Fire $fire The hook fire object. |
177 | 177 | */ |
178 | - protected function fire_reaction( $fire ) { |
|
178 | + protected function fire_reaction($fire) { |
|
179 | 179 | |
180 | 180 | /** @var WordPoints_Hook_Reactor $reactor */ |
181 | - $reactor = $this->reactors->get( $fire->reaction->get_reactor_slug() ); |
|
181 | + $reactor = $this->reactors->get($fire->reaction->get_reactor_slug()); |
|
182 | 182 | |
183 | - if ( ! in_array( $fire->action_type, $reactor->get_action_types(), true ) ) { |
|
183 | + if ( ! in_array($fire->action_type, $reactor->get_action_types(), true)) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | - $validator = new WordPoints_Hook_Reaction_Validator( $fire->reaction, true ); |
|
187 | + $validator = new WordPoints_Hook_Reaction_Validator($fire->reaction, true); |
|
188 | 188 | $validator->validate(); |
189 | 189 | |
190 | - if ( $validator->had_errors() ) { |
|
190 | + if ($validator->had_errors()) { |
|
191 | 191 | return; |
192 | 192 | } |
193 | 193 | |
194 | - unset( $validator ); |
|
194 | + unset($validator); |
|
195 | 195 | |
196 | 196 | /** @var WordPoints_Hook_Extension[] $extensions */ |
197 | 197 | $extensions = $this->extensions->get_all(); |
198 | 198 | |
199 | - foreach ( $extensions as $extension ) { |
|
200 | - if ( ! $extension->should_hit( $fire ) ) { |
|
199 | + foreach ($extensions as $extension) { |
|
200 | + if ( ! $extension->should_hit($fire)) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | 205 | $fire->hit(); |
206 | 206 | |
207 | - $reactor->hit( $fire ); |
|
207 | + $reactor->hit($fire); |
|
208 | 208 | |
209 | - foreach ( $extensions as $extension ) { |
|
210 | - $extension->after_hit( $fire ); |
|
209 | + foreach ($extensions as $extension) { |
|
210 | + $extension->after_hit($fire); |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | } |