diff --git a/ACF_City_Selector.php b/ACF_City_Selector.php index 4ae82c5..392c9c8 100755 --- a/ACF_City_Selector.php +++ b/ACF_City_Selector.php @@ -3,7 +3,7 @@ Plugin Name: ACF City Selector Plugin URI: https://acf-city-selector.com Description: An extension for ACF which allows you to select a city based on country and province/state. - Version: 1.8.0 + Version: 1.9.0 Tested up to: 6.0.2 Requires PHP: 7.0 Author: Beee @@ -35,7 +35,7 @@ public function __construct() { $this->settings = array( 'db_version' => '1.0', 'url' => plugin_dir_url( __FILE__ ), - 'version' => get_plugin_data( __FILE__ )['Version'], + 'version' => '1.9.0', ); if ( ! class_exists( 'ACFCS_WEBSITE_URL' ) ) { diff --git a/README.md b/README.md index 65135f0..ecf81cd 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Welcome to the City Selector plugin, which is an extension for [Advanced Custom ### Version -1.8.0 - released xx.07.22 +1.9.0 - released 12.10.22 ### Description @@ -228,6 +228,11 @@ I got the idea for this plugin through [Fabrizio Sabato](https://github.com/fab0 ### Changelog +1.9.0 +* fixed case in states transient +* added wpdb->prepare (where needed) +* reverted version by function due to some people reporting errors + 1.8.0 * fixed preview * fixed city names with an ' diff --git a/inc/acfcs-actions.php b/inc/acfcs-actions.php index 3e2fedf..ccc5358 100755 --- a/inc/acfcs-actions.php +++ b/inc/acfcs-actions.php @@ -14,6 +14,7 @@ function acfcs_delete_transients( $country_code = false ) { if ( ! empty( $countries ) ) { foreach( $countries as $country_code => $label ) { do_action( 'acfcs_delete_transients', $country_code ); + // @TODO: also add states } } } diff --git a/inc/acfcs-functions.php b/inc/acfcs-functions.php index cea2ddf..2251684 100755 --- a/inc/acfcs-functions.php +++ b/inc/acfcs-functions.php @@ -29,11 +29,11 @@ function acfcs_get_countries( $show_first = true, $field = false, $force = false } global $wpdb; - $results = $wpdb->get_results( ' - SELECT * FROM ' . $wpdb->prefix . 'cities - GROUP BY country - ORDER BY country ASC - ' ); + $results = $wpdb->get_results( " + SELECT * FROM {$wpdb->prefix}cities + GROUP BY country + ORDER BY country ASC + " ); if ( ! empty( $results ) ) { $country_results = array(); @@ -83,7 +83,7 @@ function acfcs_get_states( $country_code = false, $show_first = true, $field = f global $wpdb; $sql = $wpdb->prepare( " SELECT * - FROM " . $wpdb->prefix . "cities + FROM {$wpdb->prefix}cities WHERE country_code = %s GROUP BY state_code " . $order, strtoupper( $country_code ) @@ -92,7 +92,7 @@ function acfcs_get_states( $country_code = false, $show_first = true, $field = f $state_results = array(); foreach ( $results as $data ) { - $state_results[ $country_code . '-' . $data->state_code ] = esc_attr__( $data->state_name, 'acf-city-selector' ); + $state_results[ strtoupper( $country_code ) . '-' . $data->state_code ] = esc_attr__( $data->state_name, 'acf-city-selector' ); } set_transient( 'acfcs_states_' . strtolower( $country_code ), $state_results, DAY_IN_SECONDS ); @@ -150,15 +150,14 @@ function acfcs_get_cities( $country_code = false, $state_code = false, $field = if ( $set_transient ) { if ( false !== $country_code ) { global $wpdb; - $query = 'SELECT * FROM ' . $wpdb->prefix . 'cities'; + $query = "SELECT * FROM {$wpdb->prefix}cities"; if ( $country_code && $state_code ) { if ( 3 < strlen( $state_code ) ) { $state_code = substr( $state_code, 3 ); } - $query .= " WHERE country_code = '{$country_code}' AND state_code = '{$state_code}'"; - $query .= " ORDER BY state_name, city_name ASC"; + $query = $wpdb->prepare( $query . " WHERE country_code = %s AND state_code = %s ORDER BY state_name, city_name ASC", $country_code, $state_code ); } elseif ( $country_code ) { - $query .= " WHERE country_code = '{$country_code}'"; + $query = $wpdb->prepare( $query . " WHERE country_code = %s", $country_code ); } $city_results = array(); $results = $wpdb->get_results( $query ); @@ -223,9 +222,9 @@ function acfcs_get_country_name( $country_code = false ) { */ function acfcs_has_cities( $country_code = false ) { global $wpdb; - $query = 'SELECT * FROM ' . $wpdb->prefix . 'cities LIMIT 1'; + $query = "SELECT * FROM {$wpdb->prefix}cities LIMIT 1"; if ( $country_code ) { - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'cities WHERE country_code = %s LIMIT 1', $country_code ); + $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}cities WHERE country_code = %s LIMIT 1", $country_code ); } $results = $wpdb->get_results( $query ); @@ -439,20 +438,20 @@ function acfcs_get_packages( $endpoint = 'single' ) { */ function acfcs_get_countries_info() { global $wpdb; - $results = $wpdb->get_results( ' - SELECT country_code FROM ' . $wpdb->prefix . 'cities + $results = $wpdb->get_results( " + SELECT country_code FROM {$wpdb->prefix}cities GROUP BY country_code ORDER BY country_code ASC - ' ); + " ); $acfcs_info = array(); foreach ( $results as $data ) { $country_code = $data->country_code; - $results = $wpdb->get_results( $wpdb->prepare( ' - SELECT * FROM ' . $wpdb->prefix . 'cities + $results = $wpdb->get_results( $wpdb->prepare( " + SELECT * FROM {$wpdb->prefix}cities WHERE country_code = %s ORDER BY country_code ASC - ', $country_code ) ); + ", $country_code ) ); $acfcs_info[ $country_code ] = [ 'country_code' => $country_code, @@ -827,10 +826,10 @@ function acfcs_get_states_optgroup() { $order = 'ORDER BY state_name ASC'; if ( 'FR' == $country[ 'code' ] ) { - $order = "ORDER BY LENGTH(state_name), state_name"; + $order = 'ORDER BY LENGTH(state_name), state_name'; } - $query = "SELECT * FROM " . $wpdb->prefix . "cities WHERE country_code = %s GROUP BY state_code " . $order; + $query = "SELECT * FROM {$wpdb->prefix}cities WHERE country_code = %s GROUP BY state_code " . $order; $sql = $wpdb->prepare( $query, $country[ 'code' ] ); $results = $wpdb->get_results( $sql ); @@ -905,7 +904,7 @@ function acfcs_get_searched_cities() { $orderby = 'ORDER BY city_name ASC, state_name ASC'; } - $sql = "SELECT * FROM " . $wpdb->prefix . "cities + $sql = "SELECT * FROM {$wpdb->prefix}cities " . $where . " " . $orderby . " " . $search_limit . " diff --git a/readme.txt b/readme.txt index 56d31b5..04fe773 100755 --- a/readme.txt +++ b/readme.txt @@ -39,13 +39,13 @@ ACF City Selector is an extension for Advanced Custom Fields which creates a new A. Please read the FAQ @ [https://acf-city-selector.com/documentation/](https://acf-city-selector.com/documentation/) -== Upgrade Notice == - -= 1.8.0 = -The preview option was broken, which is now fixed. Also all 'broken' special characters are replaced. - == Changelog == += 1.9.0 = +* fixed case for country code in states transient +* added wpdb->prepare (where needed) +* reverted version by function due to some people reporting errors + = 1.8.0 = * fixed preview * fixed city names with an '