| @@ -443,19 +443,19 @@ | ||
| 443 | 443 | foreach ( $input as $key => $value ) { |
| 444 | 444 | |
| 445 | 445 | // Validate "access_id" |
| 446 | 446 | if ( $key === 'access_id' ) { |
| 447 | - $new_input['access_id'] = trim( $value ); | |
| 447 | + $new_input['access_id'] = dfrapi_sanitize_setting_text( $value ); | |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Validate "secret_key" |
| 451 | 451 | if ( $key === 'secret_key' ) { |
| 452 | - $new_input['secret_key'] = trim( $value ); | |
| 452 | + $new_input['secret_key'] = dfrapi_sanitize_setting_text( $value ); | |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | // Validate "api_version" |
| 456 | 456 | if ( $key === 'api_version' ) { |
| 457 | - $api_version = trim( $value ); | |
| 457 | + $api_version = dfrapi_sanitize_setting_text( $value ); | |
| 458 | 458 | |
| 459 | 459 | $new_input['api_version'] = in_array( $api_version, dfrapi_get_valid_api_versions(), true ) |
| 460 | 460 | ? $api_version |
| 461 | 461 | : dfrapi_get_default_api_version(); |
| @@ -462,19 +462,22 @@ | ||
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | // Validate "transport_method" |
| 465 | 465 | if ( $key === 'transport_method' ) { |
| 466 | - $new_input['transport_method'] = trim( $value ); | |
| 466 | + $transport_method = dfrapi_sanitize_setting_text( $value ); | |
| 467 | + $new_input['transport_method'] = in_array( $transport_method, [ 'curl', 'file', 'socket' ], true ) | |
| 468 | + ? $transport_method | |
| 469 | + : 'curl'; | |
| 467 | 470 | } |
| 468 | 471 | |
| 469 | 472 | // Validate "disable_api" |
| 470 | 473 | if ( $key === 'disable_api' ) { |
| 471 | - $new_input['disable_api'] = trim( $value ); | |
| 474 | + $new_input['disable_api'] = dfrapi_sanitize_setting_text( $value ); | |
| 472 | 475 | } |
| 473 | 476 | |
| 474 | 477 | // Validate Amazon API |
| 475 | 478 | if ( $key === 'amazon_api' ) { |
| 476 | - $amazon_api = strtolower( trim( $value ) ); | |
| 479 | + $amazon_api = strtolower( dfrapi_sanitize_setting_text( $value ) ); | |
| 477 | 480 | $new_input['amazon_api'] = in_array( $amazon_api, [ 'paapi', 'capi' ], true ) |
| 478 | 481 | ? $amazon_api |
| 479 | 482 | : 'paapi'; |
| 480 | 483 | } |
| @@ -480,45 +483,49 @@ | ||
| 480 | 483 | } |
| 481 | 484 | |
| 482 | 485 | // Validate Amazon Access Key ID |
| 483 | 486 | if ( $key === 'amazon_access_key_id' ) { |
| 484 | - $new_input['amazon_access_key_id'] = trim( $value ); | |
| 487 | + $new_input['amazon_access_key_id'] = dfrapi_sanitize_setting_text( $value ); | |
| 485 | 488 | } |
| 486 | 489 | |
| 487 | 490 | // Validate Amazon Secret Access Key |
| 488 | 491 | if ( $key === 'amazon_secret_access_key' ) { |
| 489 | - $new_input['amazon_secret_access_key'] = trim( $value ); | |
| 492 | + $new_input['amazon_secret_access_key'] = dfrapi_sanitize_setting_text( $value ); | |
| 490 | 493 | } |
| 491 | 494 | |
| 492 | 495 | // Validate Amazon Tracking ID |
| 493 | 496 | if ( $key === 'amazon_tracking_id' ) { |
| 494 | - $new_input['amazon_tracking_id'] = trim( $value ); | |
| 497 | + $new_input['amazon_tracking_id'] = dfrapi_sanitize_setting_text( $value ); | |
| 495 | 498 | } |
| 496 | 499 | |
| 497 | 500 | // Validate Amazon Locale |
| 498 | 501 | if ( $key === 'amazon_locale' ) { |
| 499 | - $new_input['amazon_locale'] = trim( $value ); | |
| 502 | + $amazon_locale = strtolower( dfrapi_sanitize_setting_text( $value ) ); | |
| 503 | + $valid_amazon_locales = [ 'au', 'br', 'ca', 'fr', 'de', 'in', 'it', 'jp', 'mx', 'nl', 'sg', 'sa', 'es', 'se', 'tr', 'ae', 'uk', 'us' ]; | |
| 504 | + $new_input['amazon_locale'] = in_array( $amazon_locale, $valid_amazon_locales, true ) | |
| 505 | + ? $amazon_locale | |
| 506 | + : 'us'; | |
| 500 | 507 | } |
| 501 | 508 | |
| 502 | 509 | // Validate CAPI Credential ID |
| 503 | 510 | if ( $key === 'capi_credential_id' ) { |
| 504 | - $new_input['capi_credential_id'] = trim( $value ); | |
| 511 | + $new_input['capi_credential_id'] = dfrapi_sanitize_setting_text( $value ); | |
| 505 | 512 | } |
| 506 | 513 | |
| 507 | 514 | // Validate CAPI Credential Secret |
| 508 | 515 | if ( $key === 'capi_credential_secret' ) { |
| 509 | - $new_input['capi_credential_secret'] = trim( $value ); | |
| 516 | + $new_input['capi_credential_secret'] = dfrapi_sanitize_setting_text( $value ); | |
| 510 | 517 | } |
| 511 | 518 | |
| 512 | 519 | // Validate CAPI Partner Tag |
| 513 | 520 | if ( $key === 'capi_partner_tag' ) { |
| 514 | - $new_input['capi_partner_tag'] = trim( $value ); | |
| 521 | + $new_input['capi_partner_tag'] = dfrapi_sanitize_setting_text( $value ); | |
| 515 | 522 | } |
| 516 | 523 | |
| 517 | 524 | // Validate CAPI Marketplace |
| 518 | 525 | if ( $key === 'capi_marketplace' ) { |
| 519 | 526 | |
| 520 | - $marketplace = strtoupper( trim( $value ) ); | |
| 527 | + $marketplace = strtoupper( dfrapi_sanitize_setting_text( $value ) ); | |
| 521 | 528 | $valid_marketplaces = array_keys( dfrapi_get_capi_marketplaces() ); |
| 522 | 529 | |
| 523 | 530 | $new_input['capi_marketplace'] = in_array( $marketplace, $valid_marketplaces, true ) |
| 524 | 531 | ? $marketplace |
| @@ -526,44 +533,44 @@ | ||
| 526 | 533 | } |
| 527 | 534 | |
| 528 | 535 | // Validate PH Application Key |
| 529 | 536 | if ( $key === 'ph_application_key' ) { |
| 530 | - $new_input['ph_application_key'] = trim( $value ); | |
| 537 | + $new_input['ph_application_key'] = dfrapi_sanitize_setting_text( $value ); | |
| 531 | 538 | } |
| 532 | 539 | |
| 533 | 540 | // Validate PH User API Key |
| 534 | 541 | if ( $key === 'ph_user_api_key' ) { |
| 535 | - $new_input['ph_user_api_key'] = trim( $value ); | |
| 542 | + $new_input['ph_user_api_key'] = dfrapi_sanitize_setting_text( $value ); | |
| 536 | 543 | } |
| 537 | 544 | |
| 538 | 545 | // Validate PH Publisher Key |
| 539 | 546 | if ( $key === 'ph_publisher_id' ) { |
| 540 | - $new_input['ph_publisher_id'] = trim( $value ); | |
| 547 | + $new_input['ph_publisher_id'] = dfrapi_sanitize_setting_text( $value ); | |
| 541 | 548 | } |
| 542 | 549 | |
| 543 | 550 | // Validate Effiliation Key |
| 544 | 551 | if ( $key === 'effiliation_key' ) { |
| 545 | - $new_input['effiliation_key'] = trim( $value ); | |
| 552 | + $new_input['effiliation_key'] = dfrapi_sanitize_setting_text( $value ); | |
| 546 | 553 | } |
| 547 | 554 | |
| 548 | 555 | // Validate Awin Acceess Token |
| 549 | 556 | if ( $key === 'awin_access_token' ) { |
| 550 | - $new_input['awin_access_token'] = trim( $value ); | |
| 557 | + $new_input['awin_access_token'] = dfrapi_sanitize_setting_text( $value ); | |
| 551 | 558 | } |
| 552 | 559 | |
| 553 | 560 | // Validate The Affiliate Gateway SID |
| 554 | 561 | if ( $key === 'affiliate_gateway_sid' ) { |
| 555 | - $new_input['affiliate_gateway_sid'] = trim( $value ); | |
| 562 | + $new_input['affiliate_gateway_sid'] = dfrapi_sanitize_setting_text( $value ); | |
| 556 | 563 | } |
| 557 | 564 | |
| 558 | 565 | // Validate Adservice MID |
| 559 | 566 | if ( $key === 'adservice_mid' ) { |
| 560 | - $new_input['adservice_mid'] = trim( $value ); | |
| 567 | + $new_input['adservice_mid'] = dfrapi_sanitize_setting_text( $value ); | |
| 561 | 568 | } |
| 562 | 569 | |
| 563 | 570 | // Validate Belboon AID |
| 564 | 571 | if ( $key === 'belboon_aid' ) { |
| 565 | - $new_input['belboon_aid'] = trim( $value ); | |
| 572 | + $new_input['belboon_aid'] = dfrapi_sanitize_setting_text( $value ); | |
| 566 | 573 | } |
| 567 | 574 | |
| 568 | 575 | // Enable HelpScout Beacon |
| 569 | 576 | if ( $key === 'hs_beacon' ) { |