key = 'dfrapi_configuration';
$this->account = (array) get_option( 'dfrapi_account', array( 'max_length' => 50 ) );
add_action( 'init', array( $this, 'load_settings' ) );
add_action( 'admin_init', array( $this, 'register_settings' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
add_action( 'admin_notices', array( $this, 'admin_notice' ) );
}
function admin_menu() {
add_submenu_page(
'dfrapi',
__( 'Configuration — Datafeedr API', 'datafeedr-api' ),
__( 'Configuration', 'datafeedr-api' ),
'manage_options',
'dfrapi',
array( $this, 'output' )
);
}
function admin_notice() {
if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && 'dfrapi' == $_GET['page'] ) {
dfrapi_admin_notice( __( 'Configuration successfully updated!', 'datafeedr-api' ), 'success' );
}
}
function output() {
echo '
';
echo '
' . dfrapi_setting_pages( $this->page ) . ' — Datafeedr API ';
echo '';
echo '';
}
function load_settings() {
$this->options = (array) get_option( $this->key );
$this->options = array_merge( array(
'access_id' => '',
'secret_key' => '',
'api_version' => 'stable',
'transport_method' => 'curl',
'disable_api' => 'no',
'zanox_connection_key' => '',
'zanox_secret_key' => '',
'amazon_access_key_id' => '',
'amazon_secret_access_key' => '',
'amazon_tracking_id' => '',
'amazon_locale' => 'us',
'ph_application_key' => '',
'ph_user_api_key' => '',
'ph_publisher_id' => '',
'effiliation_key' => '',
'awin_access_token' => '',
'affiliate_gateway_sid' => '',
'belboon_aid' => '',
'adservice_mid' => '',
'hs_beacon' => 'on',
'amazon_api' => 'paapi', // 'capi' or 'paapi'
'capi_credential_id' => '',
'capi_credential_secret' => '',
'capi_partner_tag' => '',
'capi_marketplace' => 'US',
), $this->options );
}
function register_settings() {
register_setting( $this->page, $this->key, array( $this, 'validate' ) );
add_settings_section( 'api_settings', __( 'Datafeedr API Settings', 'datafeedr-api' ), array( &$this, 'section_api_settings_desc' ), $this->page );
add_settings_field( 'access_id', __( 'API Access ID', 'datafeedr-api' ), array( &$this, 'field_access_id' ), $this->page, 'api_settings' );
add_settings_field( 'secret_key', __( 'API Secret Key', 'datafeedr-api' ), array( &$this, 'field_secret_key' ), $this->page, 'api_settings' );
add_settings_field( 'api_version', __( 'API Version', 'datafeedr-api' ), array( &$this, 'field_api_version' ), $this->page, 'api_settings' );
// add_settings_field( 'transport_method', __( 'Transport Method', 'datafeedr-api' ), array( &$this, 'field_transport_method' ), $this->page, 'api_settings' );
/*
add_settings_field(
'disable_api',
__( 'Disable API', 'datafeedr-api' ),
array( &$this, 'field_disable_api' ),
$this->page,
'api_settings'
);
*/
add_settings_section( 'awin_settings', __( 'Awin Settings', 'datafeedr-api' ), array( &$this, 'section_awin_settings_desc' ), $this->page );
add_settings_field( 'awin_access_token', __( 'Awin API Token', 'datafeedr-api' ), array( &$this, 'field_awin_access_token' ), $this->page, 'awin_settings' );
add_settings_section( 'affiliate_gateway_settings', __( 'Affiliate Gateway Settings', 'datafeedr-api' ), array( &$this, 'section_affiliate_gateway_settings_desc' ), $this->page );
add_settings_field( 'affiliate_gateway_sid', __( 'Affiliate Gateway SID', 'datafeedr-api' ), array( &$this, 'field_affiliate_gateway_sid' ), $this->page, 'affiliate_gateway_settings' );
add_settings_section( 'adservice_settings', __( 'Adservice Settings', 'datafeedr-api' ), array( &$this, 'section_adservice_settings_desc' ), $this->page );
add_settings_field( 'adservice_mid', __( 'Adservice Media ID', 'datafeedr-api' ), array( &$this, 'field_adservice_mid' ), $this->page, 'adservice_settings' );
add_settings_section( 'belboon_settings', __( 'Belboon Settings', 'datafeedr-api' ), array( &$this, 'section_belboon_settings_desc' ), $this->page );
add_settings_field( 'belboon_aid', __( 'Adspace ID', 'datafeedr-api' ), array( &$this, 'field_belboon_aid' ), $this->page, 'belboon_settings' );
if ( defined( 'DFRCS_VERSION' ) ) {
add_settings_section( 'amazon_api_settings', __( 'Amazon Settings', 'datafeedr-api' ), array( &$this, 'section_amazon_api_settings_desc' ), $this->page );
add_settings_field( 'amazon_api', __( 'Amazon API', 'datafeedr-api' ), array( &$this, 'field_amazon_api' ), $this->page, 'amazon_api_settings' );
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' ] );
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' ] );
add_settings_field( 'amazon_tracking_id', __( 'Tracking ID', 'datafeedr-api' ), array( &$this, 'field_amazon_tracking_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] );
add_settings_field( 'amazon_locale', __( 'Locale', 'datafeedr-api' ), array( &$this, 'field_amazon_locale' ), $this->page, 'amazon_api_settings', [ 'class'=>'paapi_settings' ] );
add_settings_field( 'capi_credential_id', __( 'Credential ID', 'datafeedr-api' ), array( &$this, 'field_capi_credential_id' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
add_settings_field( 'capi_credential_secret', __( 'Credential Secret', 'datafeedr-api' ), array( &$this, 'field_capi_credential_secret' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
add_settings_field( 'capi_partner_tag', __( 'Partner Tag', 'datafeedr-api' ), array( &$this, 'field_capi_partner_tag' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
add_settings_field( 'capi_marketplace', __( 'Marketplace', 'datafeedr-api' ), array( &$this, 'field_capi_marketplace' ), $this->page, 'amazon_api_settings', [ 'class'=>'capi_settings' ] );
}
add_settings_section( 'ph_api_settings', __( 'Partnerize Settings', 'datafeedr-api' ), array( &$this, 'section_ph_api_settings_desc' ), $this->page );
add_settings_field( 'ph_application_key', __( 'Application Key', 'datafeedr-api' ), array( &$this, 'field_ph_application_key' ), $this->page, 'ph_api_settings' );
add_settings_field( 'ph_user_api_key', __( 'User API Key', 'datafeedr-api' ), array( &$this, 'field_ph_user_api_key' ), $this->page, 'ph_api_settings' );
add_settings_field( 'ph_publisher_id', __( 'Publisher ID', 'datafeedr-api' ), array( &$this, 'field_ph_publisher_id' ), $this->page, 'ph_api_settings' );
add_settings_section( 'effiliation_api_settings', __( 'Effiliation Settings', 'datafeedr-api' ), array( &$this, 'section_effiliation_api_settings_desc' ), $this->page );
add_settings_field( 'effiliation_key', __( 'Effiliation Key', 'datafeedr-api' ), array( &$this, 'field_effiliation_key' ), $this->page, 'effiliation_api_settings' );
add_settings_section( 'hs_beacon_settings', __( 'Datafeedr Documentation & Support Link', 'datafeedr-api' ), array( &$this, 'section_hs_beacon_settings_desc' ), $this->page );
add_settings_field( 'hs_beacon_status', __( 'Enabled', 'datafeedr-api' ), array( &$this, 'field_hs_beacon_status' ), $this->page, 'hs_beacon_settings' );
}
function section_api_settings_desc() {
echo __( 'Add your ', 'datafeedr-api' );
echo ' ';
echo __( 'Datafeedr API Keys', 'datafeedr-api' );
echo ' .';
}
function field_access_id() {
?>
options['api_version'], 'stable', true ); ?> />
options['api_version'], 'beta', true ); ?> />
';
echo __( 'Partnerize Keys', 'datafeedr-api' );
echo '.';
}
function field_ph_application_key() {
?>
';
echo __( 'Effiliation Key', 'datafeedr-api' );
echo '.';
}
function field_effiliation_key() {
?>
';
echo __( 'Learn how to find your Awin API Token', 'datafeedr-api' );
echo '.';
}
function field_awin_access_token() {
?>
';
echo __( 'Learn how to get your Affiliate Gateway SID', 'datafeedr-api' );
echo '.';
}
function field_affiliate_gateway_sid() {
?>
';
echo __( 'Learn how to get your Adservice Media ID', 'datafeedr-api' );
echo '.';
}
function field_adservice_mid() {
?>
';
echo __( 'Learn how to get your Belboon Adspace ID', 'datafeedr-api' );
echo '.';
}
function field_belboon_aid() {
?>
options['transport_method'], 'curl', true ); ?>>
options['transport_method'], 'file', true ); ?>>
options['transport_method'], 'socket', true ); ?>>
options['disable_api'], 'yes', true ); ?> />
options['disable_api'], 'no', true ); ?> />
options['amazon_api'], 'paapi' ); ?>
/>
options['amazon_api'], 'capi' ); ?>
/>
';
echo __( 'Amazon Product Advertising API keys', 'datafeedr-api' );
echo '.';
echo '';
echo __( 'These are ONLY compatible with the ', 'datafeedr-api' );
echo '';
echo __( 'Datafeedr Comparison Sets', 'datafeedr-api' );
echo ' ';
echo __( ' plugin.', 'datafeedr-api' );
echo ' ';
}
function field_amazon_access_key_id() {
?>
.
options['amazon_locale'], 'au', true ); ?>>
options['amazon_locale'], 'br', true ); ?>>
options['amazon_locale'], 'ca', true ); ?>>
options['amazon_locale'], 'fr', true ); ?>>
options['amazon_locale'], 'de', true ); ?>>
options['amazon_locale'], 'in', true ); ?>>
options['amazon_locale'], 'it', true ); ?>>
options['amazon_locale'], 'jp', true ); ?>>
options['amazon_locale'], 'mx', true ); ?>>
options['amazon_locale'], 'nl', true ); ?>>
options['amazon_locale'], 'sg', true ); ?>>
options['amazon_locale'], 'sa', true ); ?>>
options['amazon_locale'], 'es', true ); ?>>
options['amazon_locale'], 'se', true ); ?>>
options['amazon_locale'], 'tr', true ); ?>>
options['amazon_locale'], 'ae', true ); ?>>
options['amazon_locale'], 'uk', true ); ?>>
options['amazon_locale'], 'us', true ); ?>>
$marketplace ) : ?>
options['capi_marketplace'], $code ); ?>>
options['hs_beacon'], 'on', true ); ?> />
options['hs_beacon'], 'off', true ); ?> />
$value ) {
// Validate "access_id"
if ( $key === 'access_id' ) {
$new_input['access_id'] = dfrapi_sanitize_setting_text( $value );
}
// Validate "secret_key"
if ( $key === 'secret_key' ) {
$new_input['secret_key'] = dfrapi_sanitize_setting_text( $value );
}
// Validate "api_version"
if ( $key === 'api_version' ) {
$api_version = dfrapi_sanitize_setting_text( $value );
$new_input['api_version'] = in_array( $api_version, dfrapi_get_valid_api_versions(), true )
? $api_version
: dfrapi_get_default_api_version();
}
// Validate "transport_method"
if ( $key === 'transport_method' ) {
$transport_method = dfrapi_sanitize_setting_text( $value );
$new_input['transport_method'] = in_array( $transport_method, [ 'curl', 'file', 'socket' ], true )
? $transport_method
: 'curl';
}
// Validate "disable_api"
if ( $key === 'disable_api' ) {
$new_input['disable_api'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Amazon API
if ( $key === 'amazon_api' ) {
$amazon_api = strtolower( dfrapi_sanitize_setting_text( $value ) );
$new_input['amazon_api'] = in_array( $amazon_api, [ 'paapi', 'capi' ], true )
? $amazon_api
: 'paapi';
}
// Validate Amazon Access Key ID
if ( $key === 'amazon_access_key_id' ) {
$new_input['amazon_access_key_id'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Amazon Secret Access Key
if ( $key === 'amazon_secret_access_key' ) {
$new_input['amazon_secret_access_key'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Amazon Tracking ID
if ( $key === 'amazon_tracking_id' ) {
$new_input['amazon_tracking_id'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Amazon Locale
if ( $key === 'amazon_locale' ) {
$amazon_locale = strtolower( dfrapi_sanitize_setting_text( $value ) );
$valid_amazon_locales = [ 'au', 'br', 'ca', 'fr', 'de', 'in', 'it', 'jp', 'mx', 'nl', 'sg', 'sa', 'es', 'se', 'tr', 'ae', 'uk', 'us' ];
$new_input['amazon_locale'] = in_array( $amazon_locale, $valid_amazon_locales, true )
? $amazon_locale
: 'us';
}
// Validate CAPI Credential ID
if ( $key === 'capi_credential_id' ) {
$new_input['capi_credential_id'] = dfrapi_sanitize_setting_text( $value );
}
// Validate CAPI Credential Secret
if ( $key === 'capi_credential_secret' ) {
$new_input['capi_credential_secret'] = dfrapi_sanitize_setting_text( $value );
}
// Validate CAPI Partner Tag
if ( $key === 'capi_partner_tag' ) {
$new_input['capi_partner_tag'] = dfrapi_sanitize_setting_text( $value );
}
// Validate CAPI Marketplace
if ( $key === 'capi_marketplace' ) {
$marketplace = strtoupper( dfrapi_sanitize_setting_text( $value ) );
$valid_marketplaces = array_keys( dfrapi_get_capi_marketplaces() );
$new_input['capi_marketplace'] = in_array( $marketplace, $valid_marketplaces, true )
? $marketplace
: 'US';
}
// Validate PH Application Key
if ( $key === 'ph_application_key' ) {
$new_input['ph_application_key'] = dfrapi_sanitize_setting_text( $value );
}
// Validate PH User API Key
if ( $key === 'ph_user_api_key' ) {
$new_input['ph_user_api_key'] = dfrapi_sanitize_setting_text( $value );
}
// Validate PH Publisher Key
if ( $key === 'ph_publisher_id' ) {
$new_input['ph_publisher_id'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Effiliation Key
if ( $key === 'effiliation_key' ) {
$new_input['effiliation_key'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Awin Acceess Token
if ( $key === 'awin_access_token' ) {
$new_input['awin_access_token'] = dfrapi_sanitize_setting_text( $value );
}
// Validate The Affiliate Gateway SID
if ( $key === 'affiliate_gateway_sid' ) {
$new_input['affiliate_gateway_sid'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Adservice MID
if ( $key === 'adservice_mid' ) {
$new_input['adservice_mid'] = dfrapi_sanitize_setting_text( $value );
}
// Validate Belboon AID
if ( $key === 'belboon_aid' ) {
$new_input['belboon_aid'] = dfrapi_sanitize_setting_text( $value );
}
// Enable HelpScout Beacon
if ( $key === 'hs_beacon' ) {
$new_input['hs_beacon'] = ( 'on' === $value ) ? 'on' : 'off';
}
} // foreach
// Override setting so it's always enabled.
$new_input['disable_api'] = trim( 'no' );
return $new_input;
}
} // class Dfrapi_Configuration
} // class_exists check