| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
/** |
| 6 |
* Set the API Version "url" and "scheme". |
| 7 |
*/ |
| 8 |
function dfrapi_update_api_version_params( $options ) { |
| 9 |
if ( dfrapi_get_datafeedr_api_version() === 'beta' ) { |
| 10 |
$options['host'] = 'api.datafeedr.com'; // There currently is no "beta" version, so we will use "stable" instead. |
| 11 |
$options['https'] = 'https'; |
| 12 |
} |
| 13 |
|
| 14 |
return $options; |
| 15 |
} |
| 16 |
|
| 17 |
add_filter( 'dfrapi_api_options', 'dfrapi_update_api_version_params' ); |
| 18 |
|
| 19 |
/** |
| 20 |
* Modify affiliate ID if product is a Zanox product. |
| 21 |
* Replaces $affiliate_id with "zmid". |
| 22 |
*/ |
| 23 |
function dfrapi_get_zanox_zmid( $affiliate_id, $product, $networks ) { |
| 24 |
if ( isset( $product['source'] ) && preg_match( "/\bZanox\b/", $product['source'] ) ) { |
| 25 |
$zanox = dfrapi_api_get_zanox_zmid( $product['merchant_id'], $affiliate_id ); |
| 26 |
$affiliate_id = ( ! isset( $zanox[0]['zmid'] ) ) ? '___MISSING___' : $zanox[0]['zmid']; |
| 27 |
} |
| 28 |
|
| 29 |
return $affiliate_id; |
| 30 |
} |
| 31 |
|
| 32 |
add_filter( 'dfrapi_affiliate_id', 'dfrapi_get_zanox_zmid', 10, 3 ); |
| 33 |
|
| 34 |
/** |
| 35 |
* Modify affiliate ID if product is a Partnerize product. |
| 36 |
* Replaces $affiliate_id with "camref". |
| 37 |
* |
| 38 |
* @since 1.0.66 |
| 39 |
* @return string Affiliate ID. |
| 40 |
*/ |
| 41 |
function dfrapi_get_ph_camref( $affiliate_id, $product, $networks ) { |
| 42 |
if ( isset( $product['source'] ) && preg_match( "/\bPartnerize\b/", $product['source'] ) ) { |
| 43 |
$ph = dfrapi_api_get_ph_camref( $product['merchant_id'] ); |
| 44 |
$affiliate_id = ( ! isset( $ph[0]['camref'] ) ) ? '___MISSING___' : $ph[0]['camref']; |
| 45 |
} |
| 46 |
|
| 47 |
return $affiliate_id; |
| 48 |
} |
| 49 |
|
| 50 |
add_filter( 'dfrapi_affiliate_id', 'dfrapi_get_ph_camref', 10, 3 ); |
| 51 |
|
| 52 |
/** |
| 53 |
* Modify affiliate ID if product is a Effiliation product. |
| 54 |
* Replaces $affiliate_id with "affiliate ID". |
| 55 |
* |
| 56 |
* @since 1.0.81 |
| 57 |
* @return string Affiliate ID. |
| 58 |
*/ |
| 59 |
function dfrapi_get_effiliation_affiliate_id( $affiliate_id, $product, $networks ) { |
| 60 |
if ( isset( $product['source'] ) && preg_match( "/\bEffiliation\b/", $product['source'] ) ) { |
| 61 |
$effiliation = dfrapi_api_get_effiliation_affiliate_id( $product['merchant_id'] ); |
| 62 |
$affiliate_id = $effiliation === 'dfrapi_unapproved_effiliation_merchant' ? '___MISSING___' : $effiliation; |
| 63 |
} |
| 64 |
|
| 65 |
return $affiliate_id; |
| 66 |
} |
| 67 |
|
| 68 |
add_filter( 'dfrapi_affiliate_id', 'dfrapi_get_effiliation_affiliate_id', 10, 3 ); |
| 69 |
|
| 70 |
/** |
| 71 |
* Insert SID into The Affiliate Gateway affiliate links. |
| 72 |
* |
| 73 |
* @param string $url |
| 74 |
* @param array $product |
| 75 |
* @param string $tracking_id |
| 76 |
* |
| 77 |
* @return string |
| 78 |
*/ |
| 79 |
function dfrapi_insert_affiliate_gateway_sid_into_affiliate_link( $url, $product, $tracking_id ) { |
| 80 |
|
| 81 |
if ( $product['source'] !== 'The Affiliate Gateway' ) { |
| 82 |
return $url; |
| 83 |
} |
| 84 |
|
| 85 |
$sid = dfrapi_get_affiliate_gateway_sid(); |
| 86 |
|
| 87 |
if ( is_wp_error( $sid ) ) { |
| 88 |
return $url; |
| 89 |
} |
| 90 |
|
| 91 |
$url = str_replace( '{SID}', $sid, $url ); |
| 92 |
|
| 93 |
return $url; |
| 94 |
} |
| 95 |
|
| 96 |
add_filter( 'dfrapi_after_tracking_id_insertion', 'dfrapi_insert_affiliate_gateway_sid_into_affiliate_link', 20, 3 ); |
| 97 |
|
| 98 |
/** |
| 99 |
* Insert Media ID into Adservice affiliate links. |
| 100 |
* |
| 101 |
* @param string $url |
| 102 |
* @param array $product |
| 103 |
* @param string $tracking_id |
| 104 |
* |
| 105 |
* @return string |
| 106 |
*/ |
| 107 |
function dfrapi_insert_adservice_mid_into_affiliate_link( $url, $product, $tracking_id ) { |
| 108 |
|
| 109 |
if ( ! dfrapi_str_contains( $product['source'], 'Adservice' ) ) { |
| 110 |
return $url; |
| 111 |
} |
| 112 |
|
| 113 |
$mid = dfrapi_get_adservice_mid(); |
| 114 |
|
| 115 |
return is_wp_error( $mid ) ? $url : str_replace( '{MID}', $mid, $url ); |
| 116 |
} |
| 117 |
|
| 118 |
add_filter( 'dfrapi_after_tracking_id_insertion', 'dfrapi_insert_adservice_mid_into_affiliate_link', 20, 3 ); |
| 119 |
|
| 120 |
/** |
| 121 |
* Insert Adspace ID into Belboon affiliate links. |
| 122 |
* |
| 123 |
* @since 1.0.124 |
| 124 |
* |
| 125 |
* @param array $product |
| 126 |
* @param string $affiliate_id |
| 127 |
* |
| 128 |
* @param string $url |
| 129 |
* |
| 130 |
* @return string |
| 131 |
*/ |
| 132 |
function dfrapi_insert_belboon_adspace_id_into_affiliate_link( $url, $product, $affiliate_id ): string { |
| 133 |
|
| 134 |
if ( strpos( $product['source'], 'Belboon' ) === false ) { |
| 135 |
return $url; |
| 136 |
} |
| 137 |
|
| 138 |
$aid = dfrapi_get_belboon_adspace_id(); |
| 139 |
|
| 140 |
if ( is_wp_error( $aid ) ) { |
| 141 |
return $url; |
| 142 |
} |
| 143 |
|
| 144 |
$url = str_replace( '{AID}', $aid, $url ); |
| 145 |
|
| 146 |
return $url; |
| 147 |
} |
| 148 |
|
| 149 |
add_filter( 'dfrapi_before_affiliate_id_insertion', 'dfrapi_insert_belboon_adspace_id_into_affiliate_link', 20, 3 ); |
| 150 |
|