| 1 |
<?php |
| 2 |
|
| 3 |
defined( 'ABSPATH' ) || exit; |
| 4 |
|
| 5 |
if ( ! class_exists( 'Dfrapi_Configuration' ) ) { |
| 6 |
|
| 7 |
/** |
| 8 |
* Configuration page. |
| 9 |
*/ |
| 10 |
class Dfrapi_Configuration { |
| 11 |
|
| 12 |
private $page = 'dfrapi-configuration'; |
| 13 |
private $key; |
| 14 |
private $account; |
| 15 |
public $options; |
| 16 |
|
| 17 |
public function __construct() { |
| 18 |
$this->key = 'dfrapi_configuration'; |
| 19 |
$this->account = (array) get_option( 'dfrapi_account', array( 'max_length' => 50 ) ); |
| 20 |
add_action( 'init', array( $this, 'load_settings' ) ); |
| 21 |
add_action( 'admin_init', array( $this, 'register_settings' ) ); |
| 22 |
add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
| 23 |
add_action( 'admin_notices', array( $this, 'admin_notice' ) ); |
| 24 |
} |
| 25 |
|
| 26 |
function admin_menu() { |
| 27 |
add_submenu_page( |
| 28 |
'dfrapi', |
| 29 |
__( 'Configuration — Datafeedr API', 'datafeedr-api' ), |
| 30 |
__( 'Configuration', 'datafeedr-api' ), |
| 31 |
'manage_options', |
| 32 |
'dfrapi', |
| 33 |
array( $this, 'output' ) |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
function admin_notice() { |
| 38 |
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && 'dfrapi' == $_GET['page'] ) { |
| 39 |
dfrapi_admin_notice( __( 'Configuration successfully updated!', 'datafeedr-api' ), 'success' ); |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
function output() { |
| 44 |
echo '<div class="wrap" id="' . $this->key . '">'; |
| 45 |
echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' — Datafeedr API</h2>'; |
| 46 |
echo '<form method="post" action="options.php">'; |
| 47 |
wp_nonce_field( 'update-options' ); |
| 48 |
settings_fields( $this->page ); |
| 49 |
do_settings_sections( $this->page); |
| 50 |
submit_button(); |
| 51 |
echo '</form>'; |
| 52 |
echo '</div>'; |
| 53 |
} |
| 54 |
|
| 55 |
function load_settings() { |
| 56 |
|
| 57 |
$this->options = (array) get_option( $this->key ); |
| 58 |
|
| 59 |
$this->options = array_merge( array( |
| 60 |
'access_id' => '', |
| 61 |
'secret_key' => '', |
| 62 |
'api_version' => 'stable', |
| 63 |
'transport_method' => 'curl', |
| 64 |
'disable_api' => 'no', |
| 65 |
'zanox_connection_key' => '', |
| 66 |
'zanox_secret_key' => '', |
| 67 |
'amazon_access_key_id' => '', |
| 68 |
'amazon_secret_access_key' => '', |
| 69 |
'amazon_tracking_id' => '', |
| 70 |
'amazon_locale' => 'us', |
| 71 |
'ph_application_key' => '', |
| 72 |
'ph_user_api_key' => '', |
| 73 |
'ph_publisher_id' => '', |
| 74 |
'effiliation_key' => '', |
| 75 |
'awin_access_token' => '', |
| 76 |
'affiliate_gateway_sid' => '', |
| 77 |
'belboon_aid' => '', |
| 78 |
'adservice_mid' => '', |
| 79 |
'hs_beacon' => 'on', |
| 80 |
'amazon_api' => 'paapi', // 'capi' or 'paapi' |
| 81 |
'capi_credential_id' => '', |
| 82 |
'capi_credential_secret' => '', |
| 83 |
'capi_partner_tag' => '', |
| 84 |
'capi_marketplace' => 'US', |
| 85 |
), $this->options ); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
function register_settings() { |
| 90 |
register_setting( $this->page, $this->key, array( $this, 'validate' ) ); |
| 91 |
add_settings_section( 'api_settings', __( 'Datafeedr API Settings', 'datafeedr-api' ), array( &$this, 'section_api_settings_desc' ), $this->page ); |
| 92 |
add_settings_field( 'access_id', __( 'API Access ID', 'datafeedr-api' ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' ); |
| 93 |
add_settings_field( 'secret_key', __( 'API Secret Key', 'datafeedr-api' ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' ); |
| 94 |
add_settings_field( 'api_version', __( 'API Version', 'datafeedr-api' ), array( &$this, 'field_api_version' ), $this->page, 'api_settings' ); |
| 95 |
// add_settings_field( 'transport_method', __( 'Transport Method', 'datafeedr-api' ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' ); |
| 96 |
|
| 97 |
/* |
| 98 |
add_settings_field( |
| 99 |
'disable_api', |
| 100 |
__( 'Disable API', 'datafeedr-api' ), |
| 101 |
array( &$this, 'field_disable_api' ), |
| 102 |
$this->page, |
| 103 |
'api_settings' |
| 104 |
); |
| 105 |
*/ |
| 106 |
|
| 107 |
add_settings_section( 'awin_settings', __( 'Awin Settings', 'datafeedr-api' ), array( &$this, 'section_awin_settings_desc' ), $this->page ); |
| 108 |
add_settings_field( 'awin_access_token', __( 'Awin API Token', 'datafeedr-api' ), array( &$this, 'field_awin_access_token' ), $this->page, 'awin_settings' ); |
| 109 |
|
| 110 |
add_settings_section( 'affiliate_gateway_settings', __( 'Affiliate Gateway Settings', 'datafeedr-api' ), array( &$this, 'section_affiliate_gateway_settings_desc' ), $this->page ); |
| 111 |
add_settings_field( 'affiliate_gateway_sid', __( 'Affiliate Gateway SID', 'datafeedr-api' ), array( &$this, 'field_affiliate_gateway_sid' ), $this->page, 'affiliate_gateway_settings' ); |
| 112 |
|
| 113 |
add_settings_section( 'adservice_settings', __( 'Adservice Settings', 'datafeedr-api' ), array( &$this, 'section_adservice_settings_desc' ), $this->page ); |
| 114 |
add_settings_field( 'adservice_mid', __( 'Adservice Media ID', 'datafeedr-api' ), array( &$this, 'field_adservice_mid' ), $this->page, 'adservice_settings' ); |
| 115 |
|
| 116 |
add_settings_section( 'belboon_settings', __( 'Belboon Settings', 'datafeedr-api' ), array( &$this, 'section_belboon_settings_desc' ), $this->page ); |
| 117 |
add_settings_field( 'belboon_aid', __( 'Adspace ID', 'datafeedr-api' ), array( &$this, 'field_belboon_aid' ), $this->page, 'belboon_settings' ); |
| 118 |
|
| 119 |
if ( defined( 'DFRCS_VERSION' ) ) { |
| 120 |
add_settings_section( 'amazon_api_settings', __( 'Amazon Settings', 'datafeedr-api' ), array( &$this, 'section_amazon_api_settings_desc' ), $this->page ); |
| 121 |
add_settings_field( 'amazon_api', __( 'Amazon API', 'datafeedr-api' ), array( &$this, 'field_amazon_api' ), $this->page, 'amazon_api_settings' ); |
| 122 |
add_settings_field( 'amazon_access_key_id', __( 'Access Key ID', 'datafeedr-api' ), array( &$this, 'field_amazon_access_key_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] ); |
| 123 |
add_settings_field( 'amazon_secret_access_key', __( 'Secret Access Key', 'datafeedr-api' ), array( &$this, 'field_amazon_secret_access_key' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] ); |
| 124 |
add_settings_field( 'amazon_tracking_id', __( 'Tracking ID', 'datafeedr-api' ), array( &$this, 'field_amazon_tracking_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] ); |
| 125 |
add_settings_field( 'amazon_locale', __( 'Locale', 'datafeedr-api' ), array( &$this, 'field_amazon_locale' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] ); |
| 126 |
add_settings_field( 'capi_credential_id', __( 'Credential ID', 'datafeedr-api' ), array( &$this, 'field_capi_credential_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] ); |
| 127 |
add_settings_field( 'capi_credential_secret', __( 'Credential Secret', 'datafeedr-api' ), array( &$this, 'field_capi_credential_secret' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] ); |
| 128 |
add_settings_field( 'capi_partner_tag', __( 'Partner Tag', 'datafeedr-api' ), array( &$this, 'field_capi_partner_tag' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] ); |
| 129 |
add_settings_field( 'capi_marketplace', __( 'Marketplace', 'datafeedr-api' ), array( &$this, 'field_capi_marketplace' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] ); |
| 130 |
} |
| 131 |
|
| 132 |
add_settings_section( 'ph_api_settings', __( 'Partnerize Settings', 'datafeedr-api' ), array( &$this, 'section_ph_api_settings_desc' ), $this->page ); |
| 133 |
add_settings_field( 'ph_application_key', __( 'Application Key', 'datafeedr-api' ), array( &$this, 'field_ph_application_key' ), $this->page, 'ph_api_settings' ); |
| 134 |
add_settings_field( 'ph_user_api_key', __( 'User API Key', 'datafeedr-api' ), array( &$this, 'field_ph_user_api_key' ), $this->page, 'ph_api_settings' ); |
| 135 |
add_settings_field( 'ph_publisher_id', __( 'Publisher ID', 'datafeedr-api' ), array( &$this, 'field_ph_publisher_id' ), $this->page, 'ph_api_settings' ); |
| 136 |
|
| 137 |
add_settings_section( 'effiliation_api_settings', __( 'Effiliation Settings', 'datafeedr-api' ), array( &$this, 'section_effiliation_api_settings_desc' ), $this->page ); |
| 138 |
add_settings_field( 'effiliation_key', __( 'Effiliation Key', 'datafeedr-api' ), array( &$this, 'field_effiliation_key' ), $this->page, 'effiliation_api_settings' ); |
| 139 |
|
| 140 |
add_settings_section( 'hs_beacon_settings', __( 'Datafeedr Documentation & Support Link', 'datafeedr-api' ), array( &$this, 'section_hs_beacon_settings_desc' ), $this->page ); |
| 141 |
add_settings_field( 'hs_beacon_status', __( 'Enabled', 'datafeedr-api' ), array( &$this, 'field_hs_beacon_status' ), $this->page, 'hs_beacon_settings' ); |
| 142 |
} |
| 143 |
|
| 144 |
function section_api_settings_desc() { |
| 145 |
echo __( 'Add your ', 'datafeedr-api' ); |
| 146 |
echo ' <a href="'.DFRAPI_KEYS_URL.'?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiconfigpage" target="_blank" title="' . __( 'Get your Datafeedr API Keys', 'datafeedr-api' ) . '">'; |
| 147 |
echo __( 'Datafeedr API Keys', 'datafeedr-api' ); |
| 148 |
echo '</a>.'; |
| 149 |
} |
| 150 |
|
| 151 |
function field_access_id() { |
| 152 |
?> |
| 153 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[access_id]" value="<?php echo esc_attr( $this->options['access_id'] ); ?>" /> |
| 154 |
<?php |
| 155 |
} |
| 156 |
|
| 157 |
function field_secret_key() { |
| 158 |
?> |
| 159 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[secret_key]" value="<?php echo esc_attr( $this->options['secret_key'] ); ?>" /> |
| 160 |
<?php |
| 161 |
} |
| 162 |
|
| 163 |
function field_api_version() { |
| 164 |
?> |
| 165 |
<p> |
| 166 |
<input type="radio" value="stable" name="<?php echo $this->key; ?>[api_version]" <?php checked( $this->options['api_version'], 'stable', true ); ?> /> <?php _e( 'stable', 'datafeedr-api' ); ?> |
| 167 |
</p> |
| 168 |
<p> |
| 169 |
<input type="radio" value="beta" disabled name="<?php echo $this->key; ?>[api_version]" <?php checked( $this->options['api_version'], 'beta', true ); ?> /> <?php _e( 'beta', 'datafeedr-api' ); ?> |
| 170 |
</p> |
| 171 |
<p class="description"> |
| 172 |
<?php _e( 'The only available version of the API at this time is the "stable" version.', 'datafeedr-api' ); ?> |
| 173 |
</p> |
| 174 |
<?php |
| 175 |
} |
| 176 |
|
| 177 |
function section_ph_api_settings_desc() { |
| 178 |
echo __( 'If you want to use the Partnerize affiliate network, add your ', 'datafeedr-api' ); |
| 179 |
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/195-how-to-find-your-partnerize-publisher-id-and-api-keys" target="_blank" title="' . __( 'Learn how to find your Partnerize Keys', 'datafeedr-api' ) . '">'; |
| 180 |
echo __( 'Partnerize Keys', 'datafeedr-api' ); |
| 181 |
echo '</a>.'; |
| 182 |
} |
| 183 |
|
| 184 |
function field_ph_application_key() { |
| 185 |
?> |
| 186 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_application_key]" value="<?php echo esc_attr( $this->options['ph_application_key'] ); ?>" /> |
| 187 |
<?php |
| 188 |
} |
| 189 |
|
| 190 |
function field_ph_user_api_key() { |
| 191 |
?> |
| 192 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_user_api_key]" value="<?php echo esc_attr( $this->options['ph_user_api_key'] ); ?>" /> |
| 193 |
<?php |
| 194 |
} |
| 195 |
|
| 196 |
function field_ph_publisher_id() { |
| 197 |
?> |
| 198 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[ph_publisher_id]" value="<?php echo esc_attr( $this->options['ph_publisher_id'] ); ?>" /> |
| 199 |
<?php |
| 200 |
} |
| 201 |
|
| 202 |
function section_effiliation_api_settings_desc() { |
| 203 |
echo __( 'If you want to use the Effiliation affiliate network, add your ', 'datafeedr-api' ); |
| 204 |
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/211-how-to-find-your-effiliation-api-key" target="_blank" title="' . __( 'Get your Effiliation Key', 'datafeedr-api' ) . '">'; |
| 205 |
echo __( 'Effiliation Key', 'datafeedr-api' ); |
| 206 |
echo '</a>.'; |
| 207 |
} |
| 208 |
|
| 209 |
function field_effiliation_key() { |
| 210 |
?> |
| 211 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[effiliation_key]" value="<?php echo esc_attr( $this->options['effiliation_key'] ); ?>" /> |
| 212 |
<?php |
| 213 |
} |
| 214 |
|
| 215 |
function section_awin_settings_desc() { |
| 216 |
echo __( 'If you want to use the Awin affiliate network, enter your Awin API Token to view the Awin programs you have joined.', 'datafeedr-api' ); |
| 217 |
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/120-how-to-find-your-awin-affiliate-id-and-api-key" target="_blank" title="' . __( 'Learn how to get your Awin API Token', 'datafeedr-api' ) . '">'; |
| 218 |
echo __( 'Learn how to find your Awin API Token', 'datafeedr-api' ); |
| 219 |
echo '</a>.'; |
| 220 |
} |
| 221 |
|
| 222 |
function field_awin_access_token() { |
| 223 |
?> |
| 224 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[awin_access_token]" value="<?php echo esc_attr( $this->options['awin_access_token'] ); ?>" /> |
| 225 |
<?php |
| 226 |
} |
| 227 |
|
| 228 |
function section_affiliate_gateway_settings_desc() { |
| 229 |
echo __( 'If you want to use The Affiliate Gateway affiliate network, enter your Affiliate Gateway SID.', 'datafeedr-api' ); |
| 230 |
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/225-how-to-find-your-affiliate-gateway-affiliate-id" target="_blank" title="' . __( 'Learn how to get your Affiliate Gateway SID', 'datafeedr-api' ) . '">'; |
| 231 |
echo __( 'Learn how to get your Affiliate Gateway SID', 'datafeedr-api' ); |
| 232 |
echo '</a>.'; |
| 233 |
} |
| 234 |
|
| 235 |
function field_affiliate_gateway_sid() { |
| 236 |
?> |
| 237 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[affiliate_gateway_sid]" value="<?php echo esc_attr( $this->options['affiliate_gateway_sid'] ); ?>" /> |
| 238 |
<?php |
| 239 |
} |
| 240 |
|
| 241 |
function section_adservice_settings_desc() { |
| 242 |
echo __( 'If you want to use the Adservice affiliate network, enter your Adservice Media ID.', 'datafeedr-api' ); |
| 243 |
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/251-how-to-find-your-adservice-affiliate-id-and-media-id" target="_blank" title="' . __( 'Learn how to get your Adservice Media ID', 'datafeedr-api' ) . '">'; |
| 244 |
echo __( 'Learn how to get your Adservice Media ID', 'datafeedr-api' ); |
| 245 |
echo '</a>.'; |
| 246 |
} |
| 247 |
|
| 248 |
function field_adservice_mid() { |
| 249 |
?> |
| 250 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[adservice_mid]" value="<?php echo esc_attr( $this->options['adservice_mid'] ); ?>" /> |
| 251 |
<?php |
| 252 |
} |
| 253 |
|
| 254 |
function section_belboon_settings_desc() { |
| 255 |
echo __( 'If you want to use the Belboon affiliate network, enter your Belboon Adspace ID.', 'datafeedr-api' ); |
| 256 |
echo ' <a href="https://datafeedrapi.helpscoutdocs.com/article/125-how-to-find-your-belboon-affiliate-id" target="_blank" title="' . __( 'Learn how to get your Belboon Adspace ID', 'datafeedr-api' ) . '">'; |
| 257 |
echo __( 'Learn how to get your Belboon Adspace ID', 'datafeedr-api' ); |
| 258 |
echo '</a>.'; |
| 259 |
} |
| 260 |
|
| 261 |
function field_belboon_aid() { |
| 262 |
?> |
| 263 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[belboon_aid]" value="<?php echo esc_attr( $this->options['belboon_aid'] ); ?>" /> |
| 264 |
<?php |
| 265 |
} |
| 266 |
|
| 267 |
function field_transport_method() { |
| 268 |
?> |
| 269 |
<select id="transport_method" name="<?php echo $this->key; ?>[transport_method]"> |
| 270 |
<option value="curl" <?php selected( $this->options['transport_method'], 'curl', true ); ?>><?php _e( 'CURL', 'datafeedr-api' ); ?></option> |
| 271 |
<option value="file" <?php selected( $this->options['transport_method'], 'file', true ); ?>><?php _e( 'File', 'datafeedr-api' ); ?></option> |
| 272 |
<option value="socket" <?php selected( $this->options['transport_method'], 'socket', true ); ?>><?php _e( 'Socket', 'datafeedr-api' ); ?></option> |
| 273 |
</select> |
| 274 |
<p class="description"><?php _e( 'If you\'re not sure, use CURL.', 'datafeedr-api' ); ?></p> |
| 275 |
<?php |
| 276 |
} |
| 277 |
|
| 278 |
function field_disable_api() { |
| 279 |
?> |
| 280 |
<p> |
| 281 |
<input type="radio" value="yes" name="<?php echo $this->key; ?>[disable_api]" <?php checked( $this->options['disable_api'], 'yes', true ); ?> /> <?php _e( 'Yes', 'datafeedr-api' ); ?> |
| 282 |
</p> |
| 283 |
<p> |
| 284 |
<input type="radio" value="no" name="<?php echo $this->key; ?>[disable_api]" <?php checked( $this->options['disable_api'], 'no', true ); ?> /> <?php _e( 'No', 'datafeedr-api' ); ?> |
| 285 |
</p> |
| 286 |
<p class="description"><?php _e( 'Prevent your site from attempting to make a request to the Datafeedr API.', 'datafeedr-api' ); ?></p> |
| 287 |
<?php |
| 288 |
} |
| 289 |
|
| 290 |
function field_amazon_api() { |
| 291 |
?> |
| 292 |
<p> |
| 293 |
<label> |
| 294 |
<input type="radio" |
| 295 |
value="paapi" |
| 296 |
name="<?php echo $this->key; ?>[amazon_api]" |
| 297 |
<?php checked( $this->options['amazon_api'], 'paapi' ); ?> |
| 298 |
/> |
| 299 |
<?php _e( 'Product Advertising API', 'datafeedr-api' ); ?> |
| 300 |
<strong> |
| 301 |
<?php _e( '(deprecated)', 'datafeedr-api' ); ?> |
| 302 |
</strong> |
| 303 |
</label> |
| 304 |
</p> |
| 305 |
<p> |
| 306 |
<label> |
| 307 |
<input type="radio" |
| 308 |
value="capi" |
| 309 |
name="<?php echo $this->key; ?>[amazon_api]" |
| 310 |
<?php checked( $this->options['amazon_api'], 'capi' ); ?> |
| 311 |
/> |
| 312 |
<?php _e( 'Creators API', 'datafeedr-api' ); ?> |
| 313 |
<strong> |
| 314 |
<?php _e( '(recommended)', 'datafeedr-api' ); ?> |
| 315 |
</strong> |
| 316 |
</label> |
| 317 |
</p> |
| 318 |
<p class="description"> |
| 319 |
<?php _e( 'Which Amazon API would you like to connect to?', 'datafeedr-api' ); ?> |
| 320 |
</p> |
| 321 |
<?php |
| 322 |
} |
| 323 |
|
| 324 |
function section_amazon_api_settings_desc() { |
| 325 |
echo __( 'Add your ', 'datafeedr-api' ); |
| 326 |
echo '<a href="https://affiliate-program.amazon.com/gp/advertising/api/detail/your-account.html" target="_blank">'; |
| 327 |
echo __( 'Amazon Product Advertising API keys', 'datafeedr-api' ); |
| 328 |
echo '</a>.'; |
| 329 |
echo '<br /><span style="color:red">'; |
| 330 |
echo __( 'These are ONLY compatible with the ', 'datafeedr-api' ); |
| 331 |
echo '<a href="https://datafeedr.me/dfrcs" target="_blank">'; |
| 332 |
echo __( 'Datafeedr Comparison Sets', 'datafeedr-api' ); |
| 333 |
echo '</a>'; |
| 334 |
echo __( ' plugin.', 'datafeedr-api' ); |
| 335 |
echo '</span>'; |
| 336 |
} |
| 337 |
|
| 338 |
function field_amazon_access_key_id() { |
| 339 |
?> |
| 340 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_access_key_id]" value="<?php echo esc_attr( $this->options['amazon_access_key_id'] ); ?>" /> |
| 341 |
<?php |
| 342 |
} |
| 343 |
|
| 344 |
function field_amazon_secret_access_key() { |
| 345 |
?> |
| 346 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_secret_access_key]" value="<?php echo esc_attr( $this->options['amazon_secret_access_key'] ); ?>" /> |
| 347 |
<?php |
| 348 |
} |
| 349 |
|
| 350 |
function field_amazon_tracking_id() { |
| 351 |
?> |
| 352 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[amazon_tracking_id]" value="<?php echo esc_attr( $this->options['amazon_tracking_id'] ); ?>" /> |
| 353 |
<p class="description"> |
| 354 |
<?php _e( 'This is the same as your Associates Tag usually ending in "-20" or "-21". Can be found ', 'datafeedr-api' ); ?> |
| 355 |
<a href="https://affiliate-program.amazon.com/gp/associates/network/main.html" target="_blank"><?php _e( 'here', 'datafeedr-api' ); ?></a>. |
| 356 |
</p> |
| 357 |
<?php |
| 358 |
} |
| 359 |
|
| 360 |
function field_amazon_locale() { |
| 361 |
?> |
| 362 |
<select id="amazon_locale" name="<?php echo $this->key; ?>[amazon_locale]"> |
| 363 |
<option value="au" <?php selected( $this->options['amazon_locale'], 'au', true ); ?>><?php _e( 'Australia', 'datafeedr-api' ); ?></option> |
| 364 |
<option value="br" <?php selected( $this->options['amazon_locale'], 'br', true ); ?>><?php _e( 'Brazil', 'datafeedr-api' ); ?></option> |
| 365 |
<option value="ca" <?php selected( $this->options['amazon_locale'], 'ca', true ); ?>><?php _e( 'Canada', 'datafeedr-api' ); ?></option> |
| 366 |
<option value="fr" <?php selected( $this->options['amazon_locale'], 'fr', true ); ?>><?php _e( 'France', 'datafeedr-api' ); ?></option> |
| 367 |
<option value="de" <?php selected( $this->options['amazon_locale'], 'de', true ); ?>><?php _e( 'Germany', 'datafeedr-api' ); ?></option> |
| 368 |
<option value="in" <?php selected( $this->options['amazon_locale'], 'in', true ); ?>><?php _e( 'India', 'datafeedr-api' ); ?></option> |
| 369 |
<option value="it" <?php selected( $this->options['amazon_locale'], 'it', true ); ?>><?php _e( 'Italy', 'datafeedr-api' ); ?></option> |
| 370 |
<option value="jp" <?php selected( $this->options['amazon_locale'], 'jp', true ); ?>><?php _e( 'Japan', 'datafeedr-api' ); ?></option> |
| 371 |
<option value="mx" <?php selected( $this->options['amazon_locale'], 'mx', true ); ?>><?php _e( 'Mexico', 'datafeedr-api' ); ?></option> |
| 372 |
<option value="nl" <?php selected( $this->options['amazon_locale'], 'nl', true ); ?>><?php _e( 'Netherlands', 'datafeedr-api' ); ?></option> |
| 373 |
<option value="sg" <?php selected( $this->options['amazon_locale'], 'sg', true ); ?>><?php _e( 'Singapore', 'datafeedr-api' ); ?></option> |
| 374 |
<option value="sa" <?php selected( $this->options['amazon_locale'], 'sa', true ); ?>><?php _e( 'Saudi Arabia', 'datafeedr-api' ); ?></option> |
| 375 |
<option value="es" <?php selected( $this->options['amazon_locale'], 'es', true ); ?>><?php _e( 'Spain', 'datafeedr-api' ); ?></option> |
| 376 |
<option value="se" <?php selected( $this->options['amazon_locale'], 'se', true ); ?>><?php _e( 'Sweden', 'datafeedr-api' ); ?></option> |
| 377 |
<option value="tr" <?php selected( $this->options['amazon_locale'], 'tr', true ); ?>><?php _e( 'Turkey', 'datafeedr-api' ); ?></option> |
| 378 |
<option value="ae" <?php selected( $this->options['amazon_locale'], 'ae', true ); ?>><?php _e( 'United Arab Emirates', 'datafeedr-api' ); ?></option> |
| 379 |
<option value="uk" <?php selected( $this->options['amazon_locale'], 'uk', true ); ?>><?php _e( 'United Kingdom', 'datafeedr-api' ); ?></option> |
| 380 |
<option value="us" <?php selected( $this->options['amazon_locale'], 'us', true ); ?>><?php _e( 'United States', 'datafeedr-api' ); ?></option> |
| 381 |
</select> |
| 382 |
<p class="description"> |
| 383 |
<a href="http://docs.aws.amazon.com/AWSECommerceService/latest/DG/AssociateIDs.html" target="_blank"><?php _e( 'More information', 'datafeedr-api' ); ?></a> <?php _e( 'regarding Amazon Locales.', 'datafeedr-api' ); ?> |
| 384 |
</p> |
| 385 |
<?php |
| 386 |
} |
| 387 |
|
| 388 |
function field_capi_credential_id() { |
| 389 |
?> |
| 390 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[capi_credential_id]" value="<?php echo esc_attr( $this->options['capi_credential_id'] ); ?>" /> |
| 391 |
<?php |
| 392 |
} |
| 393 |
|
| 394 |
function field_capi_credential_secret() { |
| 395 |
?> |
| 396 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[capi_credential_secret]" value="<?php echo esc_attr( $this->options['capi_credential_secret'] ); ?>" /> |
| 397 |
<?php |
| 398 |
} |
| 399 |
|
| 400 |
function field_capi_partner_tag() { |
| 401 |
?> |
| 402 |
<input type="text" class="regular-text" name="<?php echo $this->key; ?>[capi_partner_tag]" value="<?php echo esc_attr( $this->options['capi_partner_tag'] ); ?>" /> |
| 403 |
<?php |
| 404 |
} |
| 405 |
|
| 406 |
function field_capi_marketplace() { |
| 407 |
|
| 408 |
?> |
| 409 |
<select name="<?php echo $this->key; ?>[capi_marketplace]"> |
| 410 |
<?php foreach ( dfrapi_get_capi_marketplaces() as $code => $marketplace ) : ?> |
| 411 |
<option value="<?php esc_attr_e( $code ); ?>" <?php selected( $this->options['capi_marketplace'], $code ); ?>> |
| 412 |
<?php esc_html_e( $marketplace['locale'] ); ?> |
| 413 |
</option> |
| 414 |
<?php endforeach; ?> |
| 415 |
</select> |
| 416 |
<?php |
| 417 |
} |
| 418 |
|
| 419 |
function section_hs_beacon_settings_desc() { |
| 420 |
echo __( 'Display the link to Datafeedr documentation and support on every Datafeedr-specific page in your WordPress Admin Area. ', |
| 421 |
'datafeedr-api' ); |
| 422 |
echo __( 'This provides the full Datafeedr documentation and access to a support contact form right inside your WordPress site.', |
| 423 |
'datafeedr-api' ); |
| 424 |
} |
| 425 |
|
| 426 |
function field_hs_beacon_status() { |
| 427 |
?> |
| 428 |
<p> |
| 429 |
<input type="radio" value="on" name="<?php echo $this->key; ?>[hs_beacon]" <?php checked( $this->options['hs_beacon'], 'on', true ); ?> /> <?php _e( 'Yes', 'datafeedr-api' ); ?> |
| 430 |
</p> |
| 431 |
<p> |
| 432 |
<input type="radio" value="off" name="<?php echo $this->key; ?>[hs_beacon]" <?php checked( $this->options['hs_beacon'], 'off', true ); ?> /> <?php _e( 'No', 'datafeedr-api' ); ?> |
| 433 |
</p> |
| 434 |
<?php |
| 435 |
} |
| 436 |
|
| 437 |
function validate( $input ) { |
| 438 |
|
| 439 |
if ( !isset( $input ) || !is_array( $input ) || empty( $input ) ) { return $input; } |
| 440 |
|
| 441 |
$new_input = array(); |
| 442 |
|
| 443 |
foreach ( $input as $key => $value ) { |
| 444 |
|
| 445 |
// Validate "access_id" |
| 446 |
if ( $key === 'access_id' ) { |
| 447 |
$new_input['access_id'] = trim( $value ); |
| 448 |
} |
| 449 |
|
| 450 |
// Validate "secret_key" |
| 451 |
if ( $key === 'secret_key' ) { |
| 452 |
$new_input['secret_key'] = trim( $value ); |
| 453 |
} |
| 454 |
|
| 455 |
// Validate "api_version" |
| 456 |
if ( $key === 'api_version' ) { |
| 457 |
$api_version = trim( $value ); |
| 458 |
|
| 459 |
$new_input['api_version'] = in_array( $api_version, dfrapi_get_valid_api_versions(), true ) |
| 460 |
? $api_version |
| 461 |
: dfrapi_get_default_api_version(); |
| 462 |
} |
| 463 |
|
| 464 |
// Validate "transport_method" |
| 465 |
if ( $key === 'transport_method' ) { |
| 466 |
$new_input['transport_method'] = trim( $value ); |
| 467 |
} |
| 468 |
|
| 469 |
// Validate "disable_api" |
| 470 |
if ( $key === 'disable_api' ) { |
| 471 |
$new_input['disable_api'] = trim( $value ); |
| 472 |
} |
| 473 |
|
| 474 |
// Validate Amazon API |
| 475 |
if ( $key === 'amazon_api' ) { |
| 476 |
$amazon_api = strtolower( trim( $value ) ); |
| 477 |
$new_input['amazon_api'] = in_array( $amazon_api, [ 'paapi', 'capi' ], true ) |
| 478 |
? $amazon_api |
| 479 |
: 'paapi'; |
| 480 |
} |
| 481 |
|
| 482 |
// Validate Amazon Access Key ID |
| 483 |
if ( $key === 'amazon_access_key_id' ) { |
| 484 |
$new_input['amazon_access_key_id'] = trim( $value ); |
| 485 |
} |
| 486 |
|
| 487 |
// Validate Amazon Secret Access Key |
| 488 |
if ( $key === 'amazon_secret_access_key' ) { |
| 489 |
$new_input['amazon_secret_access_key'] = trim( $value ); |
| 490 |
} |
| 491 |
|
| 492 |
// Validate Amazon Tracking ID |
| 493 |
if ( $key === 'amazon_tracking_id' ) { |
| 494 |
$new_input['amazon_tracking_id'] = trim( $value ); |
| 495 |
} |
| 496 |
|
| 497 |
// Validate Amazon Locale |
| 498 |
if ( $key === 'amazon_locale' ) { |
| 499 |
$new_input['amazon_locale'] = trim( $value ); |
| 500 |
} |
| 501 |
|
| 502 |
// Validate CAPI Credential ID |
| 503 |
if ( $key === 'capi_credential_id' ) { |
| 504 |
$new_input['capi_credential_id'] = trim( $value ); |
| 505 |
} |
| 506 |
|
| 507 |
// Validate CAPI Credential Secret |
| 508 |
if ( $key === 'capi_credential_secret' ) { |
| 509 |
$new_input['capi_credential_secret'] = trim( $value ); |
| 510 |
} |
| 511 |
|
| 512 |
// Validate CAPI Partner Tag |
| 513 |
if ( $key === 'capi_partner_tag' ) { |
| 514 |
$new_input['capi_partner_tag'] = trim( $value ); |
| 515 |
} |
| 516 |
|
| 517 |
// Validate CAPI Marketplace |
| 518 |
if ( $key === 'capi_marketplace' ) { |
| 519 |
|
| 520 |
$marketplace = strtoupper( trim( $value ) ); |
| 521 |
$valid_marketplaces = array_keys( dfrapi_get_capi_marketplaces() ); |
| 522 |
|
| 523 |
$new_input['capi_marketplace'] = in_array( $marketplace, $valid_marketplaces, true ) |
| 524 |
? $marketplace |
| 525 |
: 'US'; |
| 526 |
} |
| 527 |
|
| 528 |
// Validate PH Application Key |
| 529 |
if ( $key === 'ph_application_key' ) { |
| 530 |
$new_input['ph_application_key'] = trim( $value ); |
| 531 |
} |
| 532 |
|
| 533 |
// Validate PH User API Key |
| 534 |
if ( $key === 'ph_user_api_key' ) { |
| 535 |
$new_input['ph_user_api_key'] = trim( $value ); |
| 536 |
} |
| 537 |
|
| 538 |
// Validate PH Publisher Key |
| 539 |
if ( $key === 'ph_publisher_id' ) { |
| 540 |
$new_input['ph_publisher_id'] = trim( $value ); |
| 541 |
} |
| 542 |
|
| 543 |
// Validate Effiliation Key |
| 544 |
if ( $key === 'effiliation_key' ) { |
| 545 |
$new_input['effiliation_key'] = trim( $value ); |
| 546 |
} |
| 547 |
|
| 548 |
// Validate Awin Acceess Token |
| 549 |
if ( $key === 'awin_access_token' ) { |
| 550 |
$new_input['awin_access_token'] = trim( $value ); |
| 551 |
} |
| 552 |
|
| 553 |
// Validate The Affiliate Gateway SID |
| 554 |
if ( $key === 'affiliate_gateway_sid' ) { |
| 555 |
$new_input['affiliate_gateway_sid'] = trim( $value ); |
| 556 |
} |
| 557 |
|
| 558 |
// Validate Adservice MID |
| 559 |
if ( $key === 'adservice_mid' ) { |
| 560 |
$new_input['adservice_mid'] = trim( $value ); |
| 561 |
} |
| 562 |
|
| 563 |
// Validate Belboon AID |
| 564 |
if ( $key === 'belboon_aid' ) { |
| 565 |
$new_input['belboon_aid'] = trim( $value ); |
| 566 |
} |
| 567 |
|
| 568 |
// Enable HelpScout Beacon |
| 569 |
if ( $key === 'hs_beacon' ) { |
| 570 |
$new_input['hs_beacon'] = ( 'on' === $value ) ? 'on' : 'off'; |
| 571 |
} |
| 572 |
} // foreach |
| 573 |
|
| 574 |
// Override setting so it's always enabled. |
| 575 |
$new_input['disable_api'] = trim( 'no' ); |
| 576 |
|
| 577 |
return $new_input; |
| 578 |
} |
| 579 |
|
| 580 |
} // class Dfrapi_Configuration |
| 581 |
|
| 582 |
} // class_exists check |
| 583 |
|