Skip to content

Commit

Permalink
Merge pull request #114 from Beee4life/feature/1.9.0
Browse files Browse the repository at this point in the history
Feature/1.9.0
  • Loading branch information
Beee4life authored Oct 11, 2022
2 parents 45db6e2 + 3d9d235 commit f6b0518
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
4 changes: 2 additions & 2 deletions ACF_City_Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' ) ) {
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Welcome to the City Selector plugin, which is an extension for [Advanced Custom
<a name="version"></a>
### Version

1.8.0 - released xx.07.22
1.9.0 - released 12.10.22

<a name="description"></a>
### Description
Expand Down Expand Up @@ -228,6 +228,11 @@ I got the idea for this plugin through [Fabrizio Sabato](https://github.com/fab0
<a name="changelog"></a>
### 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 '
Expand Down
1 change: 1 addition & 0 deletions inc/acfcs-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
43 changes: 21 additions & 22 deletions inc/acfcs-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 )
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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 . "
Expand Down
10 changes: 5 additions & 5 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down

0 comments on commit f6b0518

Please sign in to comment.