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 / asgaros-forum / includes / rules-engine.php

rules-engine.php in GamiPress – Gamification plugin to reward points, badges & ranks in WordPress, now with AI 7.9.8, at integrations/asgaros-forum/includes/rules-engine.php

131 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Rules Engine
4 *
5 * @package GamiPress\Asgaros_Forum\Rules_Engine
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Filter triggered requirements to reduce the number of requirements to check by the awards engine
13 *
14 * @since 1.0.0
15 *
16 * @param array $triggered_requirements
17 * @param integer $user_id
18 * @param string $trigger
19 * @param integer $site_id
20 * @param array $args
21 *
22 * @return array
23 */
24 /*
25 function gamipress_asgaros_forum_filter_triggered_requirements( $triggered_requirements, $user_id, $trigger, $site_id, $args ) {
26
27 $new_requirements = array();
28
29 foreach( $triggered_requirements as $i => $requirement ) {
30
31 // Skip item
32 if( ! gamipress_asgaros_forum_check_if_meets_requirements( $requirement->ID, $trigger, $args ) ) {
33 continue;
34 }
35
36 // Keep the requirement on the list of requirements to check by the awards engine
37 $new_requirements[] = $requirement;
38
39 }
40
41 return $new_requirements;
42
43 }
44 add_filter( 'gamipress_get_triggered_requirements', 'gamipress_asgaros_forum_filter_triggered_requirements', 20, 5 );
45 */
46 /**
47 * Checks if an user is allowed to work on a given requirement related to a minimum of score
48 *
49 * @since 1.0.0
50 *
51 * @param bool $return The default return value
52 * @param int $user_id The given user's ID
53 * @param int $requirement_id The given requirement's post ID
54 * @param string $trigger The trigger triggered
55 * @param int $site_id The site id
56 * @param array $args Arguments of this trigger
57 *
58 * @return bool True if user has access to the requirement, false otherwise
59 */
60 function gamipress_asgaros_forum_user_has_access_to_achievement( $return = false, $user_id = 0, $requirement_id = 0, $trigger = '', $site_id = 0, $args = array() ) {
61
62 // If we're not working with a requirement, bail here
63 if ( ! in_array( get_post_type( $requirement_id ), gamipress_get_requirement_types_slugs() ) )
64 return $return;
65
66 // Check if user has access to the achievement ($return will be false if user has exceed the limit or achievement is not published yet)
67 if( ! $return )
68 return $return;
69
70 // Send back our eligibility
71 return gamipress_asgaros_forum_check_if_meets_requirements( $requirement_id, $trigger, $args );
72
73 }
74 add_filter( 'user_has_access_to_achievement', 'gamipress_asgaros_forum_user_has_access_to_achievement', 10, 6 );
75
76 /**
77 * Checks if given requirement meets the requirements of triggered event
78 *
79 * @since 1.0.0
80 *
81 * @param int $requirement_id
82 * @param string $trigger
83 * @param array $args
84 *
85 * @return bool
86 */
87 function gamipress_asgaros_forum_check_if_meets_requirements( $requirement_id, $trigger, $args ) {
88
89 // Initialize the return value
90 $return = true;
91
92 // Check forum ID
93 if( $trigger === 'gamipress_asgaros_forum_specific_forum_new_post'
94 || $trigger === 'gamipress_asgaros_forum_specific_forum_like_post'
95 || $trigger === 'gamipress_asgaros_forum_specific_forum_dislike_post' ) {
96
97 $forum_id = $args[3];
98
99 $required_forum_id = get_post_meta( $requirement_id, '_gamipress_asgaros_forum_forum', true );
100
101 // Check if forum ID matches the required one
102 $return = (bool) ( $forum_id === $required_forum_id );
103 }
104
105 // Check forum ID when a topic is created in specific forum
106 if( $trigger === 'gamipress_asgaros_forum_specific_forum_new_topic' ) {
107
108 $forum_id = $args[2];
109
110 $required_forum_id = get_post_meta( $requirement_id, '_gamipress_asgaros_forum_forum', true );
111
112 // Check if forum ID matches the required one
113 $return = (bool) ( $forum_id === $required_forum_id );
114 }
115
116 // Check topic ID
117 if( $trigger === 'gamipress_asgaros_forum_specific_topic_new_post'
118 || $trigger === 'gamipress_asgaros_forum_specific_topic_like_post'
119 || $trigger === 'gamipress_asgaros_forum_specific_topic_dislike_post' ) {
120
121 $topic_id = $args[2];
122
123 $required_topic_id = get_post_meta( $requirement_id, '_gamipress_asgaros_forum_topic', true );
124
125 // Check if topic ID matches the required one
126 $return = (bool) ( $topic_id === $required_topic_id );
127 }
128
129 return $return;
130
131 }