Exemplo n.º 1
0
			<label for="affwp-referral-url"><?php 
_e('Referral URL', 'affiliate-wp');
?>
</label>
			<input type="text" id="affwp-referral-url" value="<?php 
echo esc_url(urldecode(affwp_get_affiliate_referral_url()));
?>
" />
			<div class="description"><?php 
_e('(now copy this referral link and share it anywhere)', 'affiliate-wp');
?>
</div>
		</div>

		<div class="affwp-referral-url-submit-wrap">
			<input type="hidden" class="affwp-affiliate-id" value="<?php 
echo esc_attr(urldecode(affwp_get_referral_format_value()));
?>
" />
			<input type="hidden" class="affwp-referral-var" value="<?php 
echo esc_attr(affiliate_wp()->tracking->get_referral_var());
?>
" />
			<input type="submit" class="button" value="<?php 
_e('Generate URL', 'affiliate-wp');
?>
" />
		</div>
	</form>
</div>
/**
 * Builds an affiliate's referral URL
 * Used by creatives, referral URL generator and [affiliate_referral_url] shortcode
 *
 * @since  1.6
 * @return string
 * @param  $args array of arguments. $base_url, $format, $pretty
 */
function affwp_get_affiliate_referral_url($args = array())
{
    $defaults = array('pretty' => '', 'format' => '');
    $args = wp_parse_args($args, $defaults);
    // get affiliate ID if passed in
    $affiliate_id = isset($args['affiliate_id']) ? $args['affiliate_id'] : '';
    // get format, username or id
    $format = isset($args['format']) ? $args['format'] : affwp_get_referral_format();
    // pretty URLs
    if (!empty($args['pretty']) && 'yes' == $args['pretty']) {
        // pretty URLS explicitly turned on
        $pretty = true;
    } elseif (!empty($args['pretty']) && 'no' == $args['pretty'] || false === $args['pretty']) {
        // pretty URLS explicitly turned off
        $pretty = false;
    } else {
        // pretty URLs set from admin
        $pretty = affwp_is_pretty_referral_urls();
    }
    // get base URL
    if (isset($args['base_url'])) {
        $base_url = $args['base_url'];
    } else {
        $base_url = affwp_get_affiliate_base_url();
    }
    // add trailing slash only if no query string exists and there's no fragment identifier
    if (isset($args['base_url']) && !array_key_exists('query', parse_url($base_url)) && !array_key_exists('fragment', parse_url($base_url))) {
        $base_url = trailingslashit($args['base_url']);
    }
    // the format value, either affiliate's ID or username
    $format_value = affwp_get_referral_format_value($format, $affiliate_id);
    $url_parts = parse_url($base_url);
    // if fragment identifier exists in base URL, strip it and store in variable so we can append it later
    $fragment = array_key_exists('fragment', $url_parts) ? '#' . $url_parts['fragment'] : '';
    // if query exists in base URL, strip it and store in variable so we can append to the end of the URL
    $query_string = array_key_exists('query', $url_parts) ? '?' . $url_parts['query'] : '';
    $url_scheme = isset($url_parts['scheme']) ? $url_parts['scheme'] : 'http';
    $url_host = isset($url_parts['host']) ? $url_parts['host'] : '';
    $constructed_url = $url_scheme . '://' . $url_host . $url_parts['path'];
    $base_url = $constructed_url;
    // set up URLs
    $pretty_urls = trailingslashit($base_url) . trailingslashit(affiliate_wp()->tracking->get_referral_var()) . trailingslashit($format_value) . $query_string . $fragment;
    $non_pretty_urls = esc_url(add_query_arg(affiliate_wp()->tracking->get_referral_var(), $format_value, $base_url . $query_string . $fragment));
    if ($pretty) {
        $referral_url = $pretty_urls;
    } else {
        $referral_url = $non_pretty_urls;
    }
    return $referral_url;
}
			<label for="affwp-referral-url"><?php 
_e('Referral URL', 'affiliate-wp');
?>
</label>
			<input type="text" id="affwp-referral-url" value="<?php 
echo esc_url(affwp_get_affiliate_referral_url());
?>
" />
			<div class="description"><?php 
_e('(now copy this referral link and share it anywhere)', 'affiliate-wp');
?>
</div>
		</div>

		<div class="affwp-referral-url-submit-wrap">
			<input type="hidden" class="affwp-affiliate-id" value="<?php 
echo esc_attr(affwp_get_referral_format_value());
?>
" />
			<input type="hidden" class="affwp-referral-var" value="<?php 
echo esc_attr(affiliate_wp()->tracking->get_referral_var());
?>
" />
			<input type="submit" class="button" value="<?php 
_e('Generate URL', 'affiliate-wp');
?>
" />
		</div>
	</form>
</div>