Forums

Help with register modification (2 posts)

  1. MBCUK
    Member
    Posted 5 months ago #

    Hi there I am trying to edit the Facebook AWD Login button plugin to include a hook upon registering so I can track affiliate referrals

    I have found this script below but now I need to tailor it to the Facebook AWD script.

    add_action('register_form','show_reff_field'); function show_reff_field(){ ?> <input id="ref" type="text" tabindex="20" size="25" value= "<?php if (isset($_GET['ref'])){echo $_GET['ref'];} ?>" name="ref" readonly="readonly"/> <?php }

    add_action('user_register', 'register_refferal'); function register_refferal($user_id) { $userdata = array(); $userdata['ID'] = $user_id; wp_update_user($userdata); $userdata['ref'] = $_POST['ref']; if (isset($userdata['ref']) && !empty($userdata['ref']) && $userdata['ref'] != ""){ //get reffering user id by his login $refuser = get_userdatabylogin($userdata['ref']); //get current refferial credit that user has $current_ref_credit = get_user_meta($refuser->ID, 'ref_credit', true); //add credit for the newly created user $current_ref_credit[] = $user_id; //save the changes update_user_meta( $refuser->ID, 'ref_credit', $current_ref_credit); } }

  2. AHWEBDEV
    Member
    Posted 4 months ago #

    the function show_reff_field() can not be called in the plugin, because it's for the register form. And Facebook connect do not use it.

    But the other one register_refferal() can be called.
    I must implement the action "user_register" in the register process of facebook.

    Then you will be able to add it in your function.php (in your theme.)

    The only thing you have to do is, waiting for the next verison of the plugin. (0.9.9)
    I added the hook "user_register" in the register process.

    Modifications in your function:

    //cannot be done with AWD...
    add_action('register_form','show_reff_field');
    function show_reff_field(){
    	?>
    	<input id="ref" type="text" tabindex="20" size="25" value= "<?php if (isset($_GET['ref'])){echo $_GET['ref'];} ?>" name="ref" readonly="readonly"/>
    	<?php
    }
    //the action user register is called in the file login_process.php in the plugin Facebook AWD. So this function will be called when a user register.
    add_action('user_register', 'register_refferal');
    function register_refferal($user_id) {
    	$userdata = array();
    	$userdata['ID'] = $user_id;
    	wp_update_user($userdata);
    	$userdata['ref'] = $_POST['ref'];
            //We must modify the $_POST['ref']; (the plugin can not send that value. so we must find it by an other way.)
           //get facebook user id to know if it's a user form facebook
           $fb_uid = get_user_meta($user_id,'fb_uid',true);
           if($fb_uid != ''){
           $userdata['ref'] = 'Facebook';
           }
    	if (isset($userdata['ref']) && !empty($userdata['ref']) && $userdata['ref'] != ""){
    		//get reffering user id by his login
    		$refuser = get_userdatabylogin($userdata['ref']);
    		//get current refferial credit that user has
    		$current_ref_credit = get_user_meta($refuser->ID, 'ref_credit', true);
    		//add credit for the newly created user
    		$current_ref_credit[] = $user_id;
    		//save the changes
    		update_user_meta( $refuser->ID, 'ref_credit', $current_ref_credit);
    	}
    }

    This will the code you should use with the version 0.9.9 of the plugin

Reply

You must log in to post.

About this Topic