不了解插件,但只需使用两个钩子和回调函数即可轻松实现:首先,使用register_form
挂钩:
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
}
那么您只需要使用
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\'];
if (isset($userdata[\'ref\']) && !empty($userdata[\'ref\']) && $userdata[\'ref\'] != ""){
//get reffering user id by his login
$refuser = get_user_by(\'login\',$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);
}
}
所以,剩下要做的就是让您的用户共享那里的推荐链接:
http://example.com/wp-login.php?action=register&ref=my_login_name
因此,如果我的用户名是“bainternet”,那么我的推荐链接将是:
http://example.com/wp-login.php?action=register&ref=bainternet
要查看用户下行链路中有多少成员,这里有一个简单的函数,它接受用户ID并返回他引用的用户ID数组:
function get_user_downline($user_id){
return $current_ref_credit = get_user_meta($user_id, \'ref_credit\', true);
}
其用法很简单:
// to echo count of how many user with ID of 24 as reffered:
echo count(get_user_downline(24));
// to list the users user with ID of 24 as reffered:
<ul>
<?php
$reffed = get_users(array(\'orderby\' => \'registered\', \'include\' => get_user_downline(24));
foreach ($blogusers as $user) {
echo \'<li>\' . $user->display_name . \'</li>\';
}
?>
</ul>
所以只要复制所有这些代码,就有了一个转诊系统插件