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 / caldera-forms / 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/caldera-forms/includes/rules-engine.php

75 lines 2.9 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\Caldera_Forms\Rules_Engine
6 * @since 1.0.0
7 */
8 // Exit if accessed directly
9 if( !defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Checks if an user is allowed to work on a given requirement related to a specific form
13 *
14 * @since 1.0.0
15 *
16 * @param bool $return The default return value
17 * @param int $user_id The given user's ID
18 * @param int $requirement_id The given requirement's post ID
19 * @param string $trigger The trigger triggered
20 * @param int $site_id The site id
21 * @param array $args Arguments of this trigger
22 *
23 * @return bool True if user has access to the requirement, false otherwise
24 */
25 function gamipress_cf_user_has_access_to_achievement( $return = false, $user_id = 0, $requirement_id = 0, $trigger = '', $site_id = 0, $args = array() ) {
26
27 // If we're not working with a requirement, bail here
28 if ( ! in_array( get_post_type( $requirement_id ), gamipress_get_requirement_types_slugs() ) )
29 return $return;
30
31 // Check if user has access to the achievement ($return will be false if user has exceed the limit or achievement is not published yet)
32 if( ! $return )
33 return $return;
34
35 // If is specific form trigger, rules engine needs the attached form
36 if( $trigger === 'gamipress_cf_specific_new_form_submission'
37 || $trigger === 'gamipress_cf_specific_field_value_submission' ) {
38
39 $form_id = $args[0];
40 $required_form_id = get_post_meta( $requirement_id, '_gamipress_caldera_form', true );
41
42 // True if there is a specific form, an attached form and both are equal
43 $return = (bool) (
44 $form_id
45 && $required_form_id
46 && $form_id === $required_form_id
47 );
48 }
49
50 // If is specific field value trigger, rules engine needs the field value
51 if( $return && ( $trigger === 'gamipress_cf_field_value_submission'
52 || $trigger === 'gamipress_cf_specific_field_value_submission' ) ) {
53
54 $field_name = $args[2];
55 $field_value = $args[3];
56
57 $required_field_name = get_post_meta( $requirement_id, '_gamipress_cf_field_name', true );
58 $required_field_value = get_post_meta( $requirement_id, '_gamipress_cf_field_value', true );
59
60 // First, check if field name matches the required one
61 $return = (bool) ( $field_name === $required_field_name );
62
63 if( $return ) {
64 // Check if field value matches the required one (with support for arrays)
65 if( is_array( $field_value ) )
66 $return = (bool) ( in_array( $required_field_value, $field_value ) );
67 else
68 $return = (bool) ( $field_value === $required_field_value );
69 }
70 }
71
72 // Send back our eligibility
73 return $return;
74 }
75 add_filter( 'user_has_access_to_achievement', 'gamipress_cf_user_has_access_to_achievement', 10, 6 );