Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Step 1: Decline Signup Referral Payouts
- * First we save the transaction and then decline it since we will
- * payout first when the user has activated their account
- * @version 1.0
- */
- add_filter( 'mycred_add', 'mycred_pro_decline_signup_ref', 20, 3 );
- function mycred_pro_decline_signup_ref( $reply, $request, $mycred ) {
- // Only applicable for signup referral and if the transaction has not already been decliend
- if ( $request['ref'] != 'signup_referral' || $reply === false || $request['data'] == 'activated' ) return $reply;
- // Get the new users ID
- $pending_user_id = absint( $request['ref_id'] );
- // Save this instance for when a user verifies their account
- update_user_meta( $pending_user_id, 'signup_referral', array(
- 'reffering_user_id' => absint( $request['user_id'] ),
- 'amount' => $request['amount'],
- 'type' => $request['type'],
- 'log' => $request['entry']
- ) );
- // Decline
- return false;
- }
- /**
- * Step 2: Payout on Activation
- * Once a user activates their account by logging in, we
- * payout any pending referral that might exist.
- * @version 1.0
- */
- function check_first_login($user_login, $user) {
- $user_info = get_user_meta( $user->ID );
- if ( $user_info["accountactivated"][0]!="accountactivated" ) {
- update_user_meta( $user->ID, 'accountactivated', 'accountactivated' );
- if ( function_exists( 'mycred_add' ) ) {
- $pending_transaction = get_user_meta( $user->ID, 'signup_referral', true );
- if ( $pending_transaction != '' ) {
- // Just to be safe
- $pending_transaction = maybe_unserialize( $pending_transaction );
- // Payout
- mycred_add(
- 'signup_referral',
- $pending_transaction['reffering_user_id'],
- $pending_transaction['amount'],
- $pending_transaction['log'],
- $user->ID,
- 'activated', // added to prevent our filter from declining this as well
- $pending_transaction['type']
- );
- // Clean up
- delete_user_meta( $user->ID, 'signup_referral' );
- }
- }
- }
- }
- add_action('wp_login', 'check_first_login', 1, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement