get_var( $wpdb->prepare( "SELECT user_id FROM $affiliates_users_table WHERE affiliate_id = %d", intval( $affiliate_id ) ) );
if ( $affiliate_user_id !== null ) {
$affiliate_user = get_user_by( 'id', intval( $affiliate_user_id ) );
if ( $affiliate_user ) {
if ( current_user_can( 'edit_user', $affiliate_user->ID ) ) {
$affiliate_user_edit = sprintf( __( 'Edit %s', AFFILIATES_PLUGIN_DOMAIN ) , 'ID" ) . '">' . $affiliate_user->user_login . '' );
} else {
$affiliate_user_edit = $affiliate_user->user_login;
}
}
}
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url = remove_query_arg( 'action', $current_url );
$current_url = remove_query_arg( 'affiliate_id', $current_url );
$output =
'
' .
'
' .
'
' .
__( 'Remove an affiliate', AFFILIATES_PLUGIN_DOMAIN ) .
'
' .
'' .
'
' . // .affiliate.remove
'' .
''; // .manage-affiliates
echo $output;
affiliates_footer();
} // function affiliates_admin_affiliates_remove
/**
* Handle remove form submission.
*/
function affiliates_admin_affiliates_remove_submit() {
global $wpdb;
$result = false;
if ( !current_user_can( AFFILIATES_ADMINISTER_AFFILIATES ) ) {
wp_die( __( 'Access denied.', AFFILIATES_PLUGIN_DOMAIN ) );
}
$affiliates_table = _affiliates_get_tablename( 'affiliates' );
$affiliate_id = isset( $_POST['affiliate-id-field'] ) ? $_POST['affiliate-id-field'] : null;
if ( $affiliate_id ) {
$valid_affiliate = false;
// do not mark the pseudo-affiliate as deleted: type != ...
$check = $wpdb->prepare(
"SELECT affiliate_id FROM $affiliates_table WHERE affiliate_id = %d AND (type IS NULL OR type != '" . AFFILIATES_DIRECT_TYPE . "')",
intval( $affiliate_id ) );
if ( $wpdb->query( $check ) ) {
$valid_affiliate = true;
}
if ( $valid_affiliate ) {
$result = false !== $wpdb->query(
$query = $wpdb->prepare(
"UPDATE $affiliates_table SET status = 'deleted' WHERE affiliate_id = %d",
intval( $affiliate_id )
)
);
}
}
return $result;
} // function affiliates_admin_affiliates_remove_submit
?>