| @@ -1,0 +1,57 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Triggers | |
| 4 | + * | |
| 5 | + * @package GamiPress\AffiliatePress\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_affiliatepress_activity_triggers( $triggers ) { | |
| 20 | + | |
| 21 | + $triggers[__( 'AffiliatePress', 'gamipress' )] = array( | |
| 22 | + | |
| 23 | + 'gamipress_affiliatepress_become_affiliate' => __( 'Become as affiliate', 'gamipress' ), | |
| 24 | + 'gamipress_affiliatepress_earn_commission' => __( 'Earn a commission', 'gamipress' ), | |
| 25 | + 'gamipress_affiliatepress_get_payment' => __( 'Get a generated payment', 'gamipress' ), | |
| 26 | + | |
| 27 | + ); | |
| 28 | + | |
| 29 | + return $triggers; | |
| 30 | + | |
| 31 | +} | |
| 32 | +add_filter( 'gamipress_activity_triggers', 'gamipress_affiliatepress_activity_triggers' ); | |
| 33 | + | |
| 34 | +/** | |
| 35 | + * Get user for a given trigger action. | |
| 36 | + * | |
| 37 | + * @since 1.0.0 | |
| 38 | + * | |
| 39 | + * @param integer $user_id user ID to override. | |
| 40 | + * @param string $trigger Trigger name. | |
| 41 | + * @param array $args Passed trigger args. | |
| 42 | + * @return integer User ID. | |
| 43 | + */ | |
| 44 | +function gamipress_affiliatepress_trigger_get_user_id( $user_id, $trigger, $args ) { | |
| 45 | + | |
| 46 | + switch ( $trigger ) { | |
| 47 | + case 'gamipress_affiliatepress_become_affiliate': | |
| 48 | + case 'gamipress_affiliatepress_earn_commission': | |
| 49 | + case 'gamipress_affiliatepress_get_payment': | |
| 50 | + $user_id = $args[0]; | |
| 51 | + break; | |
| 52 | + } | |
| 53 | + | |
| 54 | + return $user_id; | |
| 55 | + | |
| 56 | +} | |
| 57 | +add_filter( 'gamipress_trigger_get_user_id', 'gamipress_affiliatepress_trigger_get_user_id', 10, 3 ); | |