예제 #1
0
printf(__('Your referral URL is: <strong>%s</strong>', 'affiliate-wp'), esc_url(urldecode(affwp_get_affiliate_referral_url())));
?>
</p>
	<p><?php 
_e('Enter any URL from this website in the form below to generate a referral link!', 'affiliate-wp');
?>
</p>

	<form id="affwp-generate-ref-url" class="affwp-form" method="get" action="#affwp-generate-ref-url">
		<div class="affwp-wrap affwp-base-url-wrap">
			<label for="affwp-url"><?php 
_e('Page URL', 'affiliate-wp');
?>
</label>
			<input type="text" name="url" id="affwp-url" value="<?php 
echo esc_url(urldecode(affwp_get_affiliate_base_url()));
?>
" />
		</div>

		<div class="affwp-wrap affwp-campaign-wrap">
			<label for="affwp-campaign"><?php 
_e('Campaign Name (optional)', 'affiliate-wp');
?>
</label>
			<input type="text" name="campaign" id="affwp-campaign" value="" />
		</div>

		<div class="affwp-wrap affwp-referral-url-wrap" <?php 
if (!isset($_GET['url'])) {
    echo 'style="display:none;"';
/**
 * 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;
}
printf(__('Your referral URL is: <strong>%s</strong>', 'affiliate-wp'), esc_url(affwp_get_affiliate_referral_url()));
?>
</p>
	<p><?php 
_e('Enter any URL from this website in the form below to generate a referral link!', 'affiliate-wp');
?>
</p>

	<form id="affwp-generate-ref-url" class="affwp-form" method="get" action="#affwp-generate-ref-url">
		<div class="affwp-wrap affwp-base-url-wrap">
			<label for="affwp-url"><?php 
_e('Page URL', 'affiliate-wp');
?>
</label>
			<input type="text" name="url" id="affwp-url" value="<?php 
echo esc_url(affwp_get_affiliate_base_url());
?>
" />
		</div>

		<div class="affwp-wrap affwp-campaign-wrap">
			<label for="affwp-campaign"><?php 
_e('Campaign Name (optional)', 'affiliate-wp');
?>
</label>
			<input type="text" name="campaign" id="affwp-campaign" value="" />
		</div>

		<div class="affwp-wrap affwp-referral-url-wrap" <?php 
if (!isset($_GET['url'])) {
    echo 'style="display:none;"';