function test_is_affiliate()
 {
     $this->assertFalse(affwp_is_affiliate());
 }
 /**
  * Get the affiliate ID
  *
  * @since 1.0.0
  */
 public function get_affiliate_id()
 {
     // credit last referrer enabled
     $credit_last_referrer = affiliate_wp()->settings->get('referral_credit_last');
     // get referral variable (eg ref)
     $referral_var = affiliate_wp()->tracking->get_referral_var();
     // if credit last referrer is enabled it needs to get the affiliate ID from the URL straight away
     if ($credit_last_referrer) {
         if ($this->get_the_affiliate_id()) {
             $affiliate_id = $this->get_the_affiliate_id();
         } elseif (affiliate_wp()->tracking->get_affiliate_id()) {
             // get affiliate ID from cookies
             $affiliate_id = affiliate_wp()->tracking->get_affiliate_id();
         } else {
             // no affiliate ID
             $affiliate_id = '';
         }
     } else {
         // get affiliate from cookie first
         if (affiliate_wp()->tracking->get_affiliate_id()) {
             $affiliate_id = affiliate_wp()->tracking->get_affiliate_id();
         } elseif ($this->get_the_affiliate_id()) {
             $affiliate_id = $this->get_the_affiliate_id();
         } else {
             // no affiliate ID
             $affiliate_id = '';
         }
     }
     // finally, check if they are a valid affiliate
     if ($affiliate_id && affwp_is_affiliate(affwp_get_affiliate_user_id($affiliate_id)) && affwp_is_active_affiliate($affiliate_id)) {
         return $affiliate_id;
     }
     return false;
 }
/**
 * Plugin Name: AffiliateWP - Override OptimizeMember redirects
 * Plugin URI: http://affiliatewp.com
 * Description: OptimizeMember overrides the login redirects. This makes sure affiliates are redirected to their affiliate area.
 * Author: Andrew Munro, Sumobi
 * Author URI: http://sumobi.com
 * Version: 1.0
 */
function affwp_override_optimize_member_login_redirect($return, $vars)
{
    $user_id = $vars['user_id'];
    if (function_exists('affwp_is_affiliate') && affwp_is_affiliate($user_id)) {
        $return = false;
    }
    return $return;
}
/**
 *  Fixes affiliate redirects when "Allow WishList Member To Handle Login Redirect"
 *  and "Allow WishList Member To Handle Logout Redirect" are enabled in WishList Member
 *
 *  @since 1.7.13
 *  @return boolean
 */
function affwp_wishlist_member_redirects($return)
{
    $user = wp_get_current_user();
    $user_id = $user->ID;
    if (affwp_is_affiliate($user_id)) {
        $return = true;
    }
    return $return;
}
 /**
  * Process registration form submission
  *
  * @since 1.0
  */
 public function process_registration($data)
 {
     if (!isset($_POST['affwp_register_nonce']) || !wp_verify_nonce($_POST['affwp_register_nonce'], 'affwp-register-nonce')) {
         return;
     }
     do_action('affwp_pre_process_register_form');
     if (!is_user_logged_in()) {
         // Loop through required fields and show error message
         foreach ($this->required_fields() as $field_name => $value) {
             if (empty($_POST[$field_name])) {
                 $this->add_error($value['error_id'], $value['error_message']);
             }
         }
         if (username_exists($data['affwp_user_login'])) {
             $this->add_error('username_unavailable', __('Username already taken', 'affiliate-wp'));
         }
         if (!validate_username($data['affwp_user_login'])) {
             if (is_multisite()) {
                 $this->add_error('username_invalid', __('Invalid username. Only lowercase letters (a-z) and numbers are allowed', 'affiliate-wp'));
             } else {
                 $this->add_error('username_invalid', __('Invalid username', 'affiliate-wp'));
             }
         }
         if (email_exists($data['affwp_user_email'])) {
             $this->add_error('email_unavailable', __('Email address already taken', 'affiliate-wp'));
         }
         if (empty($data['affwp_user_email']) || !is_email($data['affwp_user_email'])) {
             $this->add_error('email_invalid', __('Invalid email', 'affiliate-wp'));
         }
         if (!empty($data['affwp_payment_email']) && $data['affwp_payment_email'] != $data['affwp_user_email'] && !is_email($data['affwp_payment_email'])) {
             $this->add_error('payment_email_invalid', __('Invalid payment email', 'affiliate-wp'));
         }
         if (!empty($_POST['affwp_user_pass']) && empty($_POST['affwp_user_pass2']) || $_POST['affwp_user_pass'] !== $_POST['affwp_user_pass2']) {
             $this->add_error('password_mismatch', __('Passwords do not match', 'affiliate-wp'));
         }
     }
     $terms_of_use = affiliate_wp()->settings->get('terms_of_use');
     if (!empty($terms_of_use) && empty($_POST['affwp_tos'])) {
         $this->add_error('empty_tos', __('Please agree to our terms of use', 'affiliate-wp'));
     }
     if (!empty($_POST['affwp_honeypot'])) {
         $this->add_error('spam', __('Nice try honey bear, don\'t touch our honey', 'affiliate-wp'));
     }
     if (affwp_is_affiliate()) {
         $this->add_error('already_registered', __('You are already registered as an affiliate', 'affiliate-wp'));
     }
     do_action('affwp_process_register_form');
     // only log the user in if there are no errors
     if (empty($this->errors)) {
         $this->register_user();
         $redirect = apply_filters('affwp_register_redirect', $data['affwp_redirect']);
         if ($redirect) {
             wp_redirect($redirect);
             exit;
         }
     }
 }
/**
 * Plugin Name: AffiliateWP - Append Affiliate ID To Jetpack Sharing Links
 * Plugin URI: http://affiliatewp.com
 * Description: Automatically appends an affiliate's ID to Jetpack sharing links.
 * Author: Andrew Munro, Sumobi
 * Author URI: http://sumobi.com
 * Version: 1.0
 */
function affwp_custom_append_affiliate_id_to_jetpack_sharing_links($permalink, $post_id, $id)
{
    // return if non-affiliate
    if (!(is_user_logged_in() && affwp_is_affiliate())) {
        return $permalink;
    }
    // append referral variable and affiliate ID to sharing links in Jetpack
    $permalink = add_query_arg(affiliate_wp()->tracking->get_referral_var(), affwp_get_affiliate_id(), $permalink);
    return $permalink;
}
function affwp_custom_affiliate_area_shortcode($atts, $content = null)
{
    ob_start();
    if (is_user_logged_in() && affwp_is_affiliate()) {
        // show the affiliate dashboard for logged in affiliates
        affiliate_wp()->templates->get_template_part('dashboard');
    } elseif (!is_user_logged_in()) {
        affiliate_wp()->templates->get_template_part('login');
    }
    return ob_get_clean();
}
/**
* [affiliate_area_order_details] shortcode
*/
function affwp_aas_order_details_shortcode($atts, $content = null)
{
    if (!(is_user_logged_in() && affwp_is_affiliate())) {
        return $content;
    }
    ob_start();
    echo '<div id="affwp-affiliate-dashboard">';
    affiliate_wp()->templates->get_template_part('dashboard-tab', 'order-details');
    echo '</div>';
    $content = ob_get_clean();
    return $content;
}
/**
 * Plugin Name: AffiliateWP - Hide Affiliate Area From Non Affiliates
 * Plugin URI: http://affiliatewp.com
 * Description: Hides the Affiliate Area from appearing in the site navigation unless the user is an affiliate
 * Author: Andrew Munro, Sumobi
 * Author URI: http://sumobi.com
 * Version: 1.0
 */
function affwp_custom_hide_affiliate_area_from_non_affiliates($items, $menu, $args)
{
    // grab the page ID of the affiliate area
    // Alternatively you can just set a page ID here
    // For example: $affiliate_area_page_id = 5;
    $affiliate_area_page_id = affiliate_wp()->settings->get('affiliates_page');
    // loop through and remove the page from the menu if user is not an affiliate
    foreach ($items as $key => $item) {
        if ($item->object_id == $affiliate_area_page_id && !affwp_is_affiliate()) {
            unset($items[$key]);
        }
    }
    return $items;
}
/**
 * Show a different image/banner/logo based on which affiliate is being tracked
 *
 * @since 1.0
 * @return string Image banner of affiliate
 */
function affwp_affiliate_banners_get_banner()
{
    // get the affiliate ID from query string
    $ref_var = isset($_GET[affiliate_wp()->tracking->get_referral_var()]) ? $_GET[affiliate_wp()->tracking->get_referral_var()] : '';
    // if affiliate ID is set in query string make sure they're actually an affiliate
    if (isset($ref_var) && affwp_is_affiliate(affwp_get_affiliate_user_id($ref_var))) {
        $affiliate_id = $ref_var;
    } elseif (affiliate_wp()->tracking->get_affiliate_id()) {
        $affiliate_id = affiliate_wp()->tracking->get_affiliate_id();
    } else {
        $affiliate_id = '';
    }
    // built out the image based on the image path of the affiliate
    return '<img src="' . affwp_affiliate_banners_get_image($affiliate_id) . '" />';
}
/**
 * Plugin Name: AffiliateWP - Move Login Form Above Register Form
 * Plugin URI: http://affiliatewp.com
 * Description: Swaps the position of the login and register form on the affiliate area
 * Author: Andrew Munro, Sumobi
 * Author URI: http://sumobi.com
 * Version: 1.0
 */
function affwp_custom_move_login_above_register()
{
    ob_start();
    if (is_user_logged_in() && affwp_is_affiliate()) {
        affiliate_wp()->templates->get_template_part('dashboard');
    } elseif (is_user_logged_in() && affiliate_wp()->settings->get('allow_affiliate_registration')) {
        affiliate_wp()->templates->get_template_part('register');
    } else {
        if (!is_user_logged_in()) {
            affiliate_wp()->templates->get_template_part('login');
        }
        if (affiliate_wp()->settings->get('allow_affiliate_registration')) {
            affiliate_wp()->templates->get_template_part('register');
        } else {
            affiliate_wp()->templates->get_template_part('no', 'access');
        }
    }
    return ob_get_clean();
}
Beispiel #12
0
 /**
  * Affiliate creatives shortcode.
  * Shows all the creatives from Affiliates -> Creatives
  *
  * @since  1.1.4
  * @return string
  */
 public function affiliate_creatives($atts, $content = null)
 {
     $atts = shortcode_atts(array('preview' => 'yes', 'number' => 20), $atts, 'affiliate_creatives');
     if (!(affwp_is_affiliate() && affwp_is_active_affiliate())) {
         return;
     }
     $content = affiliate_wp()->creative->affiliate_creatives($atts);
     return do_shortcode($content);
 }
 public static function generate_affiliatewp_referral_link($permalink)
 {
     if (!(is_user_logged_in() && affwp_is_affiliate())) {
         return $permalink;
     }
     // append referral variable and affiliate ID to sharing links in Jetpack
     $permalink = add_query_arg(affiliate_wp()->tracking->get_referral_var(), affwp_get_affiliate_id(), $permalink);
     return $permalink;
 }
Beispiel #14
0
			<ul class="linked list">
				<li<?php 
    if (is_page('account')) {
        echo ' class="active"';
    }
    ?>
><a href="<?php 
    echo site_url('account');
    ?>
"><?php 
    _e('Your Account', 'pp');
    ?>
</a></li>

				<?php 
    if (function_exists('affwp_is_affiliate') && affwp_is_affiliate()) {
        ?>
				<li<?php 
        if (is_page($affiliate_area_id)) {
            echo ' class="active"';
        }
        ?>
><a href="<?php 
        echo get_permalink($affiliate_area_id);
        ?>
"><?php 
        _e('Affiliate Dashboard', 'pp');
        ?>
</a></li>
				<?php 
    }
Beispiel #15
0
/**
 * Template Name: Affiliates
 */
get_header();
?>


<?php 
pp_page_header();
?>


<?php 
// user is logged in and is an affiliate, load the dashboard
// uses a sidebar layout
if (is_user_logged_in() && affwp_is_affiliate()) {
    ?>
 

	<div class="columns-main-side columns">
		<div class="wrapper">

			<div class="primary col content-area">
				<article class="page">
					<?php 
    affiliate_wp()->templates->get_template_part('dashboard');
    ?>
	
				</article>
				
			</div>
 /**
  * Show a logout link for the affiliate
  *
  * [affiliate_logout]
  *
  * @since  1.1
  */
 function affiliate_logout($atts, $content = null)
 {
     if (!(affwp_is_affiliate() && affwp_is_active_affiliate())) {
         return;
     }
     $redirect = function_exists('affiliate_wp') && affiliate_wp()->settings->get('affiliates_page') ? affiliate_wp()->login->get_login_url() : home_url();
     $redirect = apply_filters('affwp_aas_logout_redirect', $redirect);
     $content = apply_filters('affwp_aas_logout_link', '<a href=" ' . wp_logout_url($redirect) . '">' . __('Log out', 'affiliatewp-affiliate-area-shortcodes') . '</a>', $redirect);
     return do_shortcode($content);
 }