Skip to content

Commit

Permalink
Merge pull request #27 from Beee4life/0.6-fix-import-city
Browse files Browse the repository at this point in the history
0.6 fix import city
  • Loading branch information
Beee4life authored Aug 11, 2019
2 parents c04b411 + a39adfa commit 7ef8b1a
Show file tree
Hide file tree
Showing 16 changed files with 16,022 additions and 26,874 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: http://acfcs.berryplasman.com
Description: An extension for ACF which allows you to select a city based on country and province/state.
Version: 0.5
Version: 0.6
Author: Beee
Author URI: http://berryplasman.com
Text Domain: acf-city-selector
Expand Down Expand Up @@ -33,7 +33,7 @@ class ACF_City_Selector {
public function __construct() {

$this->settings = array(
'version' => '0.5',
'version' => '0.6',
'url' => plugin_dir_url( __FILE__ ),
'path' => plugin_dir_path( __FILE__ )
);
Expand Down
110 changes: 74 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,54 @@

Welcome to the City Selector plugin, which is an extension for [Advanced Custom Fields](http://www.advancedcustomfields.com). This is not a stand-alone plugin, you'll need ACF for it.

## Index
- [Version](#version)
- [Description](#description)
- [Installation](#installation)
- [Usage](#usage)
- [Impact](#impact)
- [Cities](#cities)
- [Hooks](#hooks)
- [Compatibility](#compatibility)
- [Tested on](#tested)
- [Support](#support)
- [Remove donation notice](#removedonation)
- [Website](#website)
- [Disclaimer](#disclaimer)
- [Credit](#credit)
- [TO DO](#todo)
- [Changelog](#changelog)

<a name="version"></a>
### Version

0.5

### Installation

1. Copy the `acf-city-selector` folder into your `wp-content/plugins` folder.
2. Activate the `ACF City Selector` plugin via the plugins admin page.
3. Create a new field via ACF and select the `City Selector` type (listed in the Choice section).
4. (optional) Import new cities with help of the included excel sheet.
5. Please refer to the description for more info regarding the field type settings.
0.6

<a name="description"></a>
### Description

This plugin allows you to select a city, based on country and province/state in an ACF Field Group.

![Screenshot ACF City Selector](http://beee4life.github.com/beee4life.github.io/images/screenshot-acf-city-selector.png)

It creates a new 'field type' for you to choose when you're creating an ACF Field Group. If you click '+ add field' in a Field Group, you will find a new option (category: "Choice") to choose called `City Selector`.
It creates a new `field type` for you to choose when you're creating an ACF Field Group. If you click '+ add field' in a Field Group, you will find a new option (category: "Choice") to choose called `City Selector`.

* Add the field.
* Choose any name you want.
* Choose any key you want.
* Select whether to show labels above the input fields (default = yes)
* Save/publish the Field Group.

<a name="installation"></a>
### Installation

1. Copy the `acf-city-selector` folder into your `wp-content/plugins` folder.
2. Activate the `ACF City Selector` plugin via the plugins admin page.
3. Create a new field via ACF and select the `City Selector` type (listed in the Choice section).
4. (optional) Import new cities with help of the included excel sheet.
5. Please refer to the description for more info regarding the field type settings.

<a name="usage"></a>
### Usage

3 values are stored in an array:
Expand Down Expand Up @@ -69,10 +91,12 @@ This outputs:

"I live in Amsterdam which is in the state Noord-Holland (NH) which lies in the country Netherlands (NL)".
<a name="impact"></a>
### Impact

The plugin adds a database table named `{$wpdb->prefix}cities` upon plugin activation and imports cities from 3 different countries.

<a name="cities"></a>
### Cities

The plugin comes with all cities in the Benelux (Belgium, Netherlands, Luxembourg) pre-installed.
Expand All @@ -83,6 +107,7 @@ The explanation on how to do this, can be found on the first tab/sheet of the ex

We have created several country packages (csv files) especially for this plugin. These files are ready to go and can be imported without right away. These will be made available for a small fee soon, through the [ACFCS website](http://acfcs.berryplasman.com).

<a name="hooks"></a>
### Hooks

There are a few hooks available to add your own custom actions.
Expand All @@ -95,66 +120,79 @@ There are a few hooks available to add your own custom actions.
* acfcs_after_success_import_nl - hooks after importing preset country Netherlands
* acfcs_after_success_nuke - hooks after truncating the table

<a name="compatibility"></a>
### Compatibility

This ACF field type is compatible/tested with ACF 4 (Free) as well as ACF 5 (Pro).

### Contents

The plugin contains the following languages:
* php
* javascript / jquery
* sql
* css

<a name="tested"></a>
### Tested on

* Wordpress 4.9.4
* Wordpress 5.2.2
* Advanced Custom Fields 4.4.12
* Advanced Custom Fields Pro 5.6.8

#### To Do

* [ ] - Test on Mac Firefox
* [ ] - Test on Mac Safari
* [ ] - Test on PC Chrome
* [ ] - Test on PC Firefox
* [ ] - Test on PC Safari
* [ ] - Test on iPhone Chrome
* [ ] - Test on iPhone Safari
* [ ] - Test on iPad Chrome
* [ ] - Test on iPad Safari
* Advanced Custom Fields Pro 5.8.2

<a name="support"></a>
### Support

If you need support, please turn to [Github](https://github.com/Beee4life/acf-city-selector/issues).

<a name="removedonation"></a>
### Remove donation notice

If you want to remove the donation box in ACF, add the following line to functions.php:
`add_filter('remove_acfcs_donate_nag', '__return_true');`

<a name="website"></a>
### Website

http://acfcs.berryplasman.com (not for support)

<a name="disclaimer"></a>
### Disclaimer

This plugin is not 100% finished yet. It most likely won't break anything but use caution, just in case.
This plugin is not 100% finished yet. It most likely won't break anything but use caution, just in case.

This plugin doesn't work yet in the following field types, when adding more than 1 instance:
* repeater
* group
* flexible content

<a name="credit"></a>
### Credit

I got the idea for this plugin through [Fabrizio Sabato](https://github.com/fab01) who used it a bit differently, which can ben seen [here](http://www.deskema.it/en/articles/multi-level-country-state-city-cascading-select-wordpress).

Since I couldn't fix the Javascript for this plugin, [Jarah de Jong](https://github.com/inquota) took care of it.

<a name="todo"></a>
#### To Do

* [ ] - Test on Mac Firefox
* [ ] - Test on Mac Safari
* [ ] - Test on PC Chrome
* [ ] - Test on PC Firefox
* [ ] - Test on PC Safari
* [ ] - Test on iPhone Chrome
* [ ] - Test on iPhone Safari
* [ ] - Test on iPad Chrome
* [ ] - Test on iPad Safari

<a name="changelog"></a>
### Changelog

0.6
* Fix import errors for Luxembourg
* DRY import code

0.5
* Fix unescaped characters on import

0.4
Internationalised all cities/states/countries
* Internationalised all cities/states/countries

0.3
Added hooks for import/delete actions
* Added hooks for import/delete actions

0.2
Added database collation
* Added database collation
82 changes: 41 additions & 41 deletions fields/acf-city_selector-v4.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ function create_options( $field ) {

// Create Field Options HTML
?>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php esc_html_e("Show labels",'acf-city-selector'); ?></label>
<p class="description"><?php esc_html_e( 'Show field labels above the dropdown menus', 'acf-city-selector' ); ?></p>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'radio',
'name' => 'fields[' . $key . '][show_labels]',
'choices' => $select_options,
'value' => $field['show_labels'],
'layout' => 'horizontal',
));
?>
</td>
</tr>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php esc_html_e("Show labels",'acf-city-selector'); ?></label>
<p class="description"><?php esc_html_e( 'Show field labels above the dropdown menus', 'acf-city-selector' ); ?></p>
</td>
<td>
<?php
do_action('acf/create_field', array(
'type' => 'radio',
'name' => 'fields[' . $key . '][show_labels]',
'choices' => $select_options,
'value' => $field['show_labels'],
'layout' => 'horizontal',
));
?>
</td>
</tr>
<?php
}

Expand All @@ -110,7 +110,7 @@ function create_field( $field ) {
if ( isset( $field[ 'value' ][ 'countryCode' ] ) ) {
$countrycode = $field[ 'value' ][ 'countryCode' ];
}
$countries = populate_country_select( '', $field );
$countries = populate_country_select( $field, '' );
$states = false;
if ( isset( $countrycode ) && '0' !== $countrycode ) {
$stateCode = $field['value']['stateCode'];
Expand All @@ -120,42 +120,42 @@ function create_field( $field ) {
$states = get_states( $countrycode );
}
?>
<div class="dropdown-box cs-countries">
<div class="dropdown-box cs-countries">
<?php if ( $field['show_labels'] == 1 ) { ?>
<span class="acf-input-header"><?php esc_html_e( 'Select country', 'acf-city-selector' ); ?></span>
<span class="acf-input-header"><?php esc_html_e( 'Select country', 'acf-city-selector' ); ?></span>
<?php } ?>
<label for="countryCode" class="screen-reader-text"></label>
<select name="<?php echo $field['name']; ?>[countryCode]" id="countryCode" class="countrySelect">
<label for="countryCode" class="screen-reader-text"></label>
<select name="<?php echo $field['name']; ?>[countryCode]" id="countryCode" class="countrySelect">
<?php
foreach ( $countries as $key => $country ) {
if ( isset( $countrycode ) ) {
$selected = ( $countrycode === $key ) ? " selected=\"selected\"" : false;
$selected = ( $countrycode === $key ) ? ' selected="selected"' : false;
} else {
$selected = false;
}
?>
<option value="<?php echo $key; ?>"<?php echo $selected; ?>><?php echo $country; ?></option>
<option value="<?php echo $key; ?>"<?php echo $selected; ?>><?php echo $country; ?></option>
<?php } ?>
</select>
</div>
</select>
</div>

<div class="dropdown-box cs-provinces">
<div class="dropdown-box cs-provinces">
<?php if ( $field['show_labels'] == 1 ) { ?>
<span class="acf-input-header"><?php esc_html_e( 'Select province/state', 'acf-city-selector' ); ?></span>
<span class="acf-input-header"><?php esc_html_e( 'Select province/state', 'acf-city-selector' ); ?></span>
<?php } ?>
<label for="stateCode" class="screen-reader-text"></label>
<select name="<?php echo $field['name']; ?>[stateCode]" id="stateCode" class="countrySelect">
</select>
</div>
<label for="stateCode" class="screen-reader-text"></label>
<select name="<?php echo $field['name']; ?>[stateCode]" id="stateCode" class="countrySelect">
</select>
</div>

<div class="dropdown-box cs-cities">
<div class="dropdown-box cs-cities">
<?php if ( $field['show_labels'] == 1 ) { ?>
<span class="acf-input-header"><?php esc_html_e( 'Select city', 'acf-city-selector' ); ?></span>
<span class="acf-input-header"><?php esc_html_e( 'Select city', 'acf-city-selector' ); ?></span>
<?php } ?>
<label for="cityName" class="screen-reader-text"></label>
<select name="<?php echo $field['name']; ?>[cityName]" id="cityName" class="countrySelect">
</select>
</div>
<label for="cityName" class="screen-reader-text"></label>
<select name="<?php echo $field['name']; ?>[cityName]" id="cityName" class="countrySelect">
</select>
</div>
<?php

}
Expand All @@ -175,7 +175,7 @@ function create_field( $field ) {

function input_admin_enqueue_scripts() {

$url = $this->settings['url'];
$url = $this->settings['url'];
$version = $this->settings['version'];

// register & include JS
Expand Down Expand Up @@ -277,7 +277,7 @@ function load_value( $value, $post_id, $field ) {
global $wpdb;
$country_code = $value['countryCode'];
if ( '0' != $country_code ) {
$state_code = substr( $value['stateCode'], 3 );
$state_code = substr( $value['stateCode'], 3 );
}
if ( strlen( $country_code ) == 2 && ( isset( $value['stateCode'] ) && '-' != $value['stateCode'] ) && ( isset( $value['cityName'] ) && 'Select a city' != $value['cityName'] ) ) {
$table = $wpdb->prefix . 'cities';
Expand Down Expand Up @@ -311,7 +311,7 @@ function load_value( $value, $post_id, $field ) {

function format_value_for_api( $value, $post_id, $field ) {
// defaults?
/*
/*
$field = array_merge($this->defaults, $field);
*/

Expand Down
Loading

0 comments on commit 7ef8b1a

Please sign in to comment.