PluginProbe
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI / 7.9.8
GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI v7.9.8
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 / groundhogg / includes / triggers.php

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

211 lines 6.3 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\Groundhogg\Triggers
6 * @since 1.0.0
7 */
8
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Register plugin specific triggers
14 *
15 * @since 1.0.0
16 *
17 * @param array $triggers
18 * @return mixed
19 */
20 function gamipress_groundhogg_activity_triggers( $triggers ) {
21
22 $triggers[__( 'Groundhogg', 'gamipress' )] = array(
23 // Tag added
24 'gamipress_groundhogg_tag_added' => __( 'Any tag added', 'gamipress' ),
25 'gamipress_groundhogg_specific_tag_added' => __( 'Specific tag added', 'gamipress' ),
26 // Tag removed
27 'gamipress_groundhogg_tag_removed' => __( 'Any tag removed', 'gamipress' ),
28 'gamipress_groundhogg_specific_tag_removed' => __( 'Specific tag removed', 'gamipress' ),
29 );
30
31 return $triggers;
32
33 }
34 add_filter( 'gamipress_activity_triggers', 'gamipress_groundhogg_activity_triggers' );
35
36 /**
37 * Register plugin specific activity triggers
38 *
39 * @since 1.0.0
40 *
41 * @param array $specific_activity_triggers
42 * @return array
43 */
44 function gamipress_groundhogg_specific_activity_triggers( $specific_activity_triggers ) {
45
46 $specific_activity_triggers['gamipress_groundhogg_specific_tag_added'] = array( 'groundhogg_tags' );
47 $specific_activity_triggers['gamipress_groundhogg_specific_tag_removed'] = array( 'groundhogg_tags' );
48
49 return $specific_activity_triggers;
50
51 }
52 add_filter( 'gamipress_specific_activity_triggers', 'gamipress_groundhogg_specific_activity_triggers' );
53
54 /**
55 * Register plugin specific activity triggers labels
56 *
57 * @since 1.0.0
58 *
59 * @param array $specific_activity_trigger_labels
60 * @return array
61 */
62 function gamipress_groundhogg_specific_activity_trigger_label( $specific_activity_trigger_labels ) {
63
64 $specific_activity_trigger_labels['gamipress_groundhogg_specific_tag_added'] = __( 'Tag %s added', 'gamipress' );
65 $specific_activity_trigger_labels['gamipress_groundhogg_specific_tag_removed'] = __( 'Tag %s removed', 'gamipress' );
66
67 return $specific_activity_trigger_labels;
68 }
69 add_filter( 'gamipress_specific_activity_trigger_label', 'gamipress_groundhogg_specific_activity_trigger_label' );
70
71 /**
72 * Get plugin specific activity trigger post title
73 *
74 * @since 1.0.0
75 *
76 * @param string $post_title
77 * @param integer $specific_id
78 * @param string $trigger_type
79 *
80 * @return string
81 */
82 function gamipress_groundhogg_specific_activity_trigger_post_title( $post_title, $specific_id, $trigger_type ) {
83
84 switch( $trigger_type ) {
85 case 'gamipress_groundhogg_specific_tag_added':
86 case 'gamipress_groundhogg_specific_tag_removed':
87 if( absint( $specific_id ) !== 0 ) {
88
89 // Get the tag title
90 $tag_title = gamipress_groundhogg_get_tag_title( $specific_id );
91
92 $post_title = $tag_title;
93 }
94 break;
95 }
96
97 return $post_title;
98
99 }
100 add_filter( 'gamipress_specific_activity_trigger_post_title', 'gamipress_groundhogg_specific_activity_trigger_post_title', 10, 3 );
101
102 /**
103 * Get plugin specific activity trigger permalink
104 *
105 * @since 1.0.0
106 *
107 * @param string $permalink
108 * @param integer $specific_id
109 * @param string $trigger_type
110 * @param integer $site_id
111 *
112 * @return string
113 */
114 function gamipress_groundhogg_specific_activity_trigger_permalink( $permalink, $specific_id, $trigger_type, $site_id ) {
115
116 switch( $trigger_type ) {
117 case 'gamipress_groundhogg_specific_tag_added':
118 case 'gamipress_groundhogg_specific_tag_removed':
119 $permalink = '';
120 break;
121 }
122
123 return $permalink;
124
125 }
126 add_filter( 'gamipress_specific_activity_trigger_permalink', 'gamipress_groundhogg_specific_activity_trigger_permalink', 10, 4 );
127
128 /**
129 * Get user for a groundhoggn trigger action.
130 *
131 * @since 1.0.0
132 *
133 * @param integer $user_id user ID to override.
134 * @param string $trigger Trigger name.
135 * @param array $args Passed trigger args.
136 * @return integer User ID.
137 */
138 function gamipress_groundhogg_trigger_get_user_id( $user_id, $trigger, $args ) {
139
140 switch ( $trigger ) {
141 // Tag added
142 case 'gamipress_groundhogg_tag_added':
143 case 'gamipress_groundhogg_specific_tag_added':
144 // Tag removed
145 case 'gamipress_groundhogg_tag_removed':
146 case 'gamipress_groundhogg_specific_tag_removed':
147 $user_id = $args[1];
148 break;
149 }
150
151 return $user_id;
152
153 }
154 add_filter( 'gamipress_trigger_get_user_id', 'gamipress_groundhogg_trigger_get_user_id', 10, 3 );
155
156 /**
157 * Get the id for a groundhoggn specific trigger action.
158 *
159 * @since 1.0.0
160 *
161 * @param integer $specific_id Specific ID.
162 * @param string $trigger Trigger name.
163 * @param array $args Passed trigger args.
164 *
165 * @return integer Specific ID.
166 */
167 function gamipress_groundhogg_specific_trigger_get_id( $specific_id, $trigger = '', $args = array() ) {
168
169 switch ( $trigger ) {
170 // Tag added
171 case 'gamipress_groundhogg_specific_tag_added':
172 // Tag removed
173 case 'gamipress_groundhogg_specific_tag_removed':
174 $specific_id = $args[0];
175 break;
176 }
177
178 return $specific_id;
179 }
180 add_filter( 'gamipress_specific_trigger_get_id', 'gamipress_groundhogg_specific_trigger_get_id', 10, 3 );
181
182 /**
183 * Extended meta data for event trigger logging
184 *
185 * @since 1.0.0
186 *
187 * @param array $log_meta
188 * @param integer $user_id
189 * @param string $trigger
190 * @param integer $site_id
191 * @param array $args
192 *
193 * @return array
194 */
195 function gamipress_groundhogg_log_event_trigger_meta_data( $log_meta, $user_id, $trigger, $site_id, $args ) {
196
197 switch ( $trigger ) {
198 // Tag added
199 case 'gamipress_groundhogg_tag_added':
200 case 'gamipress_groundhogg_specific_tag_added':
201 // Tag removed
202 case 'gamipress_groundhogg_tag_removed':
203 case 'gamipress_groundhogg_specific_tag_removed':
204 // Add the result ID, tag ID and the tag type
205 $log_meta['tag_id'] = $args[0];
206 break;
207 }
208
209 return $log_meta;
210 }
211 add_filter( 'gamipress_log_event_trigger_meta_data', 'gamipress_groundhogg_log_event_trigger_meta_data', 10, 5 );