Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added region validation #359

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doofinder-for-woocommerce/doofinder-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: DOOFINDER Search and Discovery for WP & WooCommerce
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Version: 2.6.0
* Version: 2.6.1
* Requires at least: 5.6
* Requires PHP: 7.0
* Author: Doofinder
Expand Down Expand Up @@ -40,7 +40,7 @@ class Doofinder_For_WordPress {
* @var string
*/

public static $version = '2.5.20';
public static $version = '2.6.1';

/**
* The only instance of Doofinder_For_WordPress
Expand Down
7 changes: 7 additions & 0 deletions doofinder-for-woocommerce/includes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class Settings {
'stock_status',
);

/**
* List of valid regions
*
* @var array
*/
const VALID_REGIONS = array( 'eu1', 'us1' );

/**
* Array of tab settings, indexed by the id of the tag (the GET variable
* representing given tab). Values contain:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function () use ( $region_option_name ) {
)
);

register_setting( self::$top_level_menu, $region_option_name );
register_setting( self::$top_level_menu, $region_option_name, array( 'sanitize_callback' => array( $this, 'validate_region' ) ) );

// Search engine hash.
$search_engine_hash_option_name =
Expand Down Expand Up @@ -439,6 +439,24 @@ public function validate_update_on_save( $input ) {
return $input;
}

/**
* Validate region
*
* @param string $region_input region value.
*
* @return string|null
*/
public function validate_region( $region_input ) {
if ( ! in_array( $region_input, Settings::VALID_REGIONS, true ) ) {
add_settings_error(
'doofinder_for_wp_messages',
'doofinder_for_wp_message',
__( 'Selecting a region is mandatory.', 'wordpress-doofinder' )
);
return '';
}
return $region_input;
}

/**
* Process additional attributes sent from the frontend
Expand Down
7 changes: 5 additions & 2 deletions doofinder-for-woocommerce/readme.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
=== DOOFINDER Search and Discovery for WP & WooCommerce ===
Contributors: Doofinder
Tags: search, autocomplete
Version: 2.6.0
Version: 2.6.1
Requires at least: 5.6
Tested up to: 6.7.1
Requires PHP: 7.0
Stable tag: 2.6.0
Stable tag: 2.6.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -126,6 +126,9 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro

== Changelog ==

= 2.6.1 =
- Added region validation.

= 2.6.0 =
- Remove old config URL.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doofinder-woocommerce",
"version": "2.6.0",
"version": "2.6.1",
"description": "Integrate Doofinder in your WooCommerce site with (almost) no effort.",
"main": "index.js",
"scripts": {
Expand Down