PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 8.0.2
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v8.0.2
8.0.4 8.0.3 8.0.1 8.0.2 8.0.0 7.9.9.7 7.9.9.6 7.9.9.5 7.9.9.4 7.9.9.3 7.9.9.2 7.9.9.1 7.9.9 7.9.8 7.9.7 7.9.6 7.9.5 7.9.4 7.9.3 7.9.2 7.9.1 7.9.0 7.8.9 7.8.8 7.8.7 All 46 releases
gamipress / integrations / wpdiscuz / includes / triggers.php

triggers.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 8.0.2, at integrations/wpdiscuz/includes/triggers.php

103 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Triggers
4 *
5 * @package GamiPress\wpDiscuz\Triggers
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Register plugin triggers
13 *
14 * @since 1.0.0
15 *
16 * @param array $triggers
17 * @return mixed
18 */
19 function gamipress_wpdiscuz_activity_triggers( $triggers ) {
20
21 $triggers[__( 'wpDiscuz', 'gamipress' )] = array(
22
23 // Vote Up
24 'gamipress_wpdiscuz_vote_up' => __( 'Vote up a comment', 'gamipress' ),
25 'gamipress_wpdiscuz_get_vote_up' => __( 'Get a vote up on a comment', 'gamipress' ),
26 // Vote Down
27 'gamipress_wpdiscuz_vote_down' => __( 'Vote down a comment', 'gamipress' ),
28 'gamipress_wpdiscuz_get_vote_down' => __( 'Get a vote down on a comment', 'gamipress' ),
29
30 );
31
32 return $triggers;
33
34 }
35 add_filter( 'gamipress_activity_triggers', 'gamipress_wpdiscuz_activity_triggers' );
36
37 /**
38 * Get user for a given trigger action.
39 *
40 * @since 1.0.0
41 *
42 * @param integer $user_id user ID to override.
43 * @param string $trigger Trigger name.
44 * @param array $args Passed trigger args.
45 * @return integer User ID.
46 */
47 function gamipress_wpdiscuz_trigger_get_user_id( $user_id, $trigger, $args ) {
48
49 switch ( $trigger ) {
50 // Vote Up
51 case 'gamipress_wpdiscuz_vote_up':
52 case 'gamipress_wpdiscuz_get_vote_up':
53 // Vote Down
54 case 'gamipress_wpdiscuz_vote_down':
55 case 'gamipress_wpdiscuz_get_vote_down':
56 $user_id = $args[1];
57 break;
58 }
59
60 return $user_id;
61
62 }
63 add_filter( 'gamipress_trigger_get_user_id', 'gamipress_wpdiscuz_trigger_get_user_id', 10, 3 );
64
65 /**
66 * Extended meta data for event trigger logging
67 *
68 * @since 1.0.1
69 *
70 * @param array $log_meta
71 * @param integer $user_id
72 * @param string $trigger
73 * @param integer $site_id
74 * @param array $args
75 *
76 * @return array
77 */
78 function gamipress_wpdiscuz_log_event_trigger_meta_data( $log_meta, $user_id, $trigger, $site_id, $args ) {
79
80 switch ( $trigger ) {
81 // Vote Up
82 case 'gamipress_wpdiscuz_vote_up':
83 // Vote Down
84 case 'gamipress_wpdiscuz_vote_down':
85 $log_meta['id'] = $args[0]; // Comment ID
86 $log_meta['comment_author_id'] = $args[2]; // Comment author ID
87 $log_meta['post_id'] = $args[3]; // Post ID
88 $log_meta['vote'] = $args[4]; // Vote type (1 up, -1 down)
89 break;
90 // Get a vote up
91 case 'gamipress_wpdiscuz_get_vote_up':
92 // Get a vote down
93 case 'gamipress_wpdiscuz_get_vote_down':
94 $log_meta['id'] = $args[0]; // Comment ID
95 $log_meta['voter_id'] = $args[2]; // Voter ID
96 $log_meta['post_id'] = $args[3]; // Post ID
97 $log_meta['vote'] = $args[4]; // Vote type (1 up, -1 down)
98 break;
99 }
100
101 return $log_meta;
102 }
103 add_filter( 'gamipress_log_event_trigger_meta_data', 'gamipress_wpdiscuz_log_event_trigger_meta_data', 10, 5 );