Created
November 19, 2011 19:39
-
-
Save brandondove/1379270 to your computer and use it in GitHub Desktop.
reassign affiliate in AR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'edit_user_profile', 'edit_user_profile' ); | |
add_action( 'edit_user_profile_update', 'edit_user_profile_update' ); | |
function edit_user_profile( $user ) { | |
?> | |
<h3><?php _e("Affiliate Assignment", "blank"); ?></h3> | |
<table class="form-table"> | |
<tr> | |
<th><label for="assigned-affiliate"><?php _e("Affiliate Username"); ?></label></th> | |
<td> | |
<?php | |
$affiliate_id = get_user_meta( $user->ID, 'wafp-affiliate-referrer', true ); | |
$affiliate = new WP_User( $affiliate_id ); | |
?> | |
<input type="text" name="assigned-affiliate" id="assigned-affiliate" value="<?php echo esc_attr( $affiliate->user_login ); ?>" class="regular-text" /><br /> | |
<span class="description"><?php _e("Please enter the username of the affiliate you want to assign to this user."); ?></span> | |
</td> | |
</tr> | |
</table> | |
<?php | |
} | |
function edit_user_profile_update( $user_id ) { | |
if ( !current_user_can( 'edit_user', $user_id ) ) return false; | |
if ( !isset( $_POST['assigned-affiliate'] ) ) return false; | |
$affiliate = get_user_by( 'login', $_POST['assigned-affiliate'] ); | |
update_user_meta( $user_id, 'wafp-affiliate-referrer', $affiliate->ID ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment