How can I hook into the Affiliate enabling process?

Hi guys,
I'm working on a manual entry system for Affiliates that will hook into the invite code system of Membership. But I need to know what function to hook into in order to add my code into the process that enables the affiliate. So far, I'm using the following add_action to add my function to that process in affiliateadmin.php:
add_action( 'add_profile_report_page', 'add_affiliate_invite_code' );

The thing is, I don't think that my code is being executed when I enable affiliate links, enter my paypal email, and press submit on the affiliate details page.

I've placed my function on the tail end of the membership addon file.

I'm working with @Paul to add this functionality.

Some help would be great.

  • Christian

    This is what my code looks like, if you want to take a look:

    add_action( 'add_profile_report_page', 'add_affiliate_invite_code' );
    	// Get Referrer's Affiliate ID and Insert it into Invite Codes List
    	function add_affiliate_invite_code(){
    		$user = wp_get_current_user();
    		$user_ID = $user->ID;
    		$reference = get_user_meta($user_ID, 'affiliate_reference', true);
    		$Msi_options = M_get_option('membership_simpleinvite_options', array());
    		// The Invite Codes List
    		$codes = array_map( 'trim', explode( PHP_EOL, $Msi_options['invitecodes'] ) );
    		// If the Affiliate ID is NOT Listed Add it into Invite Codes List
    		if ( !in_array( $reference, $codes ) ) {
    		$codes .= $reference;
    		$updated_codes = implode( PHP_EOL, $codes );
    		M_update_option('membership_simpleinvite_options', $updated_codes);
    		} else {
    		return __( 'Sorry, that Affiliate already has an Invite Code.', 'affiliate' );
    	add_action( 'M_SimpleInviteFieldValidate', 'affiliate_invite_check' );
    	// Validate Affiliate Invite Code
    	function affiliate_invite_check($new_user_id){
    		if (isset($_POST['invitecode']) && (!empty($_POST['invitecode']))) {
    			$Msi_options = M_get_option('membership_simpleinvite_options', array());
    			$codes = array_map( 'trim', explode( PHP_EOL, $Msi_options['invitecodes'] ) );
    			$thekey = filter_input( INPUT_POST, 'invitecode' );
    			$affiliate = $this->db->get_var( $this->db->prepare( "SELECT user_id FROM {$this->db->usermeta} WHERE meta_key = 'affiliate_reference' AND meta_value='%s'", $thekey) );
    			// Check for invite code & remove it if it doesn't match an affiliate's id
    			$key = array_search( $thekey, $codes );
    			if ($key !== false && empty($affiliate)) {
    				unset( $codes[$key] );
    				$Msi_options['invitecodes'] = implode( PHP_EOL, $codes );
    				M_update_option( 'membership_simpleinvite_options', $Msi_options['invitecodes'] );
    				} else if($key !== false && !empty($affiliate)){
    							update_user_meta($new_user_id, 'affiliate_referred_by', $affiliate);
    	add_action( 'user_register', 'autofriend_affiliate' );
    	add_action( 'wpmu_activate_user', 'autofriend_affiliate' );
    	//Auto-Friend the Referring Affiliate of the Referred Member
    	function autofriend_affiliate(){
    		global $bp, $new_user_id, $new_blog_meta;
    		// Check for BuddyPress Friends Component
    		if ( bp_is_active( 'friends' ) && function_exists( 'friends_add_friend' ) ){
    			$affiliate_referred_by = intval(get_user_meta($new_user_id, 'affiliate_referred_by', true));
    			// See if this signup was from an affiliate referral.
    			if (isset($affiliate_referred_by) && (!empty($affiliate_referred_by) ) ) {
    						// Request & accept the friendship
    						friends_add_friend( $new_user_id, $affiliate_user_id, $force_accept = true);
    						self::update_friendship_counts( $affiliate_user_id );			
    				} else if(isset($new_blog_meta['affiliate_referred_by']) && (!empty($new_blog_meta['affiliate_referred_by']) ) ){
    						$affiliate_user_id = intval($new_blog_meta['affiliate_referred_by']);
    						// Request & accept the friendship
    						friends_add_friend( $new_user_id, $affiliate_user_id, $force_accept = true);
    						self::update_friendship_counts( $new_user_id );
    	// Update Friend Count
    	function update_friendship_counts( $new_user_id ) {
    		/* Get friends of new user */
    		$friend_ids = BP_Friends_Friendship::get_friend_user_ids( $new_user_id );
    		/* Loop through the affiliate's friends and update their friend counts */
    		foreach ( (array) $friend_ids as $friend_id ) {
    			BP_Friends_Friendship::total_friend_count( $friend_id );
    		/* Update affiliate friend counts */
    		BP_Friends_Friendship::total_friend_count( $new_user_id );

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.