Skip to content

Commit

Permalink
Merge pull request #135 from Beee4life/feature/1.14.0
Browse files Browse the repository at this point in the history
Feature/1.14.0
  • Loading branch information
Beee4life authored Aug 11, 2024
2 parents 31635f7 + 5198765 commit f9cb196
Show file tree
Hide file tree
Showing 17 changed files with 592 additions and 694 deletions.
110 changes: 54 additions & 56 deletions ACF_City_Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
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.13.0
Tested up to: 6.5.2
Version: 1.14.0
Tested up to: 6.6.1
Requires PHP: 7.0
Author: Beee
Author URI: https://berryplasman.com
Expand All @@ -31,13 +31,13 @@ class ACF_City_Selector {
* This function will set up the class functionality
*/
public function __construct() {

$this->settings = array(
$this->settings = [
'db_version' => '1.0',
'url' => plugin_dir_url( __FILE__ ),
'version' => '1.13.0',
);

'version' => '1.14.0',
];
if ( ! class_exists( 'ACFCS_WEBSITE_URL' ) ) {
define( 'ACFCS_WEBSITE_URL', 'https://acf-city-selector.com' );
}
Expand All @@ -46,30 +46,30 @@ public function __construct() {
$plugin_path = plugin_dir_path( __FILE__ );
define( 'ACFCS_PLUGIN_PATH', $plugin_path );
}

register_activation_hook( __FILE__, array( $this, 'acfcs_plugin_activation' ) );
register_deactivation_hook( __FILE__, array( $this, 'acfcs_plugin_deactivation' ) );

add_action( 'acf/register_fields', array( $this, 'acfcs_include_field_types' ) ); // v4
add_action( 'acf/include_field_types', array( $this, 'acfcs_include_field_types' ) ); // v5

add_action( 'admin_enqueue_scripts', array( $this, 'acfcs_add_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'acfcs_add_scripts' ) );

add_action( 'admin_menu', array( $this, 'acfcs_add_admin_pages' ) );
add_action( 'admin_init', array( $this, 'acfcs_admin_menu' ) );
add_action( 'admin_init', array( $this, 'acfcs_errors' ) );
add_action( 'admin_init', array( $this, 'acfcs_check_table' ) );
add_action( 'admin_notices', array( $this, 'acfcs_check_cities' ) );
add_action( 'init', array( $this, 'acfcs_load_textdomain' ) );
add_action( 'plugins_loaded', array( $this, 'acfcs_change_plugin_order' ), 5 );
add_action( 'plugins_loaded', array( $this, 'acfcs_check_for_acf' ), 6 );
add_action( 'plugins_loaded', array( $this, 'acfcs_check_acf_version' ) );

add_action( 'acf/input/admin_l10n', array( $this, 'acfcs_error_messages' ) );

add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'acfcs_settings_link' ) );

register_activation_hook( __FILE__, [ $this, 'acfcs_plugin_activation' ] );
register_deactivation_hook( __FILE__, [ $this, 'acfcs_plugin_deactivation' ] );
add_action( 'acf/register_fields', [ $this, 'acfcs_include_field_types' ] ); // v4
add_action( 'acf/include_field_types', [ $this, 'acfcs_include_field_types' ] ); // v5
add_action( 'admin_enqueue_scripts', [ $this, 'acfcs_add_scripts' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'acfcs_add_scripts' ] );
add_action( 'admin_menu', [ $this, 'acfcs_add_admin_pages' ] );
add_action( 'admin_init', [ $this, 'acfcs_admin_menu' ] );
add_action( 'admin_init', [ $this, 'acfcs_errors' ] );
add_action( 'admin_init', [ $this, 'acfcs_check_table' ] );
add_action( 'admin_notices', [ $this, 'acfcs_check_cities' ] );
add_action( 'init', [ $this, 'acfcs_load_textdomain' ] );
add_action( 'plugins_loaded', [ $this, 'acfcs_change_plugin_order' ], 5 );
add_action( 'plugins_loaded', [ $this, 'acfcs_check_for_acf' ], 6 );
add_action( 'plugins_loaded', [ $this, 'acfcs_check_acf_version' ] );
add_action( 'acf/input/admin_l10n', [ $this, 'acfcs_error_messages' ] );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'acfcs_settings_link' ] );
// functions & hooks
include 'inc/acfcs-actions.php';
include 'inc/acfcs-functions.php';
Expand Down Expand Up @@ -105,8 +105,6 @@ public function acfcs_plugin_activation() {
*/
public function acfcs_plugin_deactivation() {
delete_option( 'acfcs_db_version' );
// this hook is here because I didn't want to create a new hook for an existing action
do_action( 'acfcs_delete_transients' );
// other important stuff gets done in uninstall.php
}

Expand Down Expand Up @@ -149,29 +147,29 @@ public static function acfcs_check_uploads_folder() {
mkdir( $target_folder, 0755 );
}
}


/**
* Check if cities need to be re-imported
*
* @return void
*/
/**
* Check if cities need to be re-imported
*
* @return void
*/
public function acfcs_check_cities() {
if ( '1.7.0' < $this->settings[ 'version' ] && false == get_option( 'acfcs_city_update_1_8_0' ) ) {
$countries = [ 'nl', 'be' ];
foreach( $countries as $country_code ) {
if ( true === acfcs_has_cities( $country_code ) ) {
$reimport[] = $country_code;
}
}
if ( isset( $reimport ) ) {
$country_name = 1 === count( $reimport ) ? acfcs_get_country_name( $reimport[ 0 ] ) : false;
$notice = sprintf( __( 'Several %s had broken ascii characters. You need to re-import these countries to get the correct city names.', 'acf-city-selector' ), _n( sprintf( __( 'cities in %s', 'acf-city-selector' ), $country_name ), __( 'cities in Belgium and Netherlands', 'acf-city-selector' ), count( $reimport ), 'acf-city-selector' ) );
echo sprintf( '<div class="notice notice-warning is-dismissible"><p>%s</p></div>', $notice );
} else {
update_option( 'acfcs_city_update_1_8_0', 'done' );
}
}
if ( '1.7.0' < $this->settings[ 'version' ] && false == get_option( 'acfcs_city_update_1_8_0' ) ) {
$countries = [ 'nl', 'be' ];
foreach( $countries as $country_code ) {
if ( true === acfcs_has_cities( $country_code ) ) {
$reimport[] = $country_code;
}
}
if ( isset( $reimport ) ) {
$country_name = 1 === count( $reimport ) ? acfcs_get_country_name( $reimport[ 0 ] ) : false;
$notice = sprintf( __( 'Several %s had broken ascii characters. You need to re-import these countries to get the correct city names.', 'acf-city-selector' ), _n( sprintf( __( 'cities in %s', 'acf-city-selector' ), $country_name ), __( 'cities in Belgium and Netherlands', 'acf-city-selector' ), count( $reimport ), 'acf-city-selector' ) );
echo sprintf( '<div class="notice notice-warning is-dismissible"><p>%s</p></div>', $notice );
} else {
update_option( 'acfcs_city_update_1_8_0', 'done' );
}
}
}


Expand Down Expand Up @@ -344,7 +342,7 @@ public function acfcs_check_acf_version() {


public function acfcs_load_textdomain() {
load_plugin_textdomain( 'acf-city-selector', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
load_plugin_textdomain( 'acf-city-selector', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}


Expand Down
11 changes: 8 additions & 3 deletions 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.13.0 - 21.04.24
1.14.0 - 09.08.24

<a name="description"></a>
### Description
Expand Down Expand Up @@ -183,8 +183,8 @@ This ACF field type is compatible/tested with ACF 5 (Pro). It's slightly tested
<a name="tested"></a>
### Tested with

* [X] WordPress 6.2
* [X] Advanced Custom Fields Pro 6.1.4
* [X] WordPress 6.6.1
* [X] Advanced Custom Fields Pro 6.3.5
* [X] Advanced Custom Fields 4.4.12

<a name="support"></a>
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.14.0
* update database queries for searching citites in admin
* update database queries for deleting countries in admin
* removed transients because it conflicted with translation

1.13.0
* remove typo in function call

Expand Down
137 changes: 71 additions & 66 deletions admin/acf-city-selector-v4.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ class acf_field_city_selector extends acf_field {
// vars
var $settings, // will hold info such as dir / path
$defaults; // will hold default field options


/*
* __construct
*
* Set name / label needed for actions / filters
*
* @since 3.6
* @date 23/01/13
*/


/**
* __construct
*
* Set name / label needed for actions / filters
*
* @since 3.6
* @date 23/01/13
*
* @param $settings
*/
function __construct( $settings ) {

$this->name = 'acf_city_selector';
Expand All @@ -41,18 +43,20 @@ function __construct( $settings ) {
}


/*
* create_options()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like below) to save extra data to the $field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field - an array holding all the field's data
*/
/**
* create_options()
*
* Create extra options for your field. This is rendered when editing a field.
* The value of $field['name'] can be used (like below) to save extra data to the $field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field
*
* @return void
*/
function create_options( $field ) {
$field = array_merge($this->defaults, $field);

Expand Down Expand Up @@ -129,17 +133,19 @@ function create_options( $field ) {
}


/*
* create_field()
*
* Create the HTML interface for your field
*
* @param $field - an array holding all the field's data
*
* @type action
* @since 3.6
* @date 23/01/13
*/
/**
* create_field()
*
* Create the HTML interface for your field
*
* @type action
* @since 3.6
* @date 23/01/13
*
* @param $field
*
* @return void
*/
function create_field( $field ) {
$field = array_merge( $this->defaults, $field );
$default_country = ( isset( $field[ 'default_country' ] ) && ! empty( $field[ 'default_country' ] ) ) ? $field[ 'default_country' ] : false;
Expand Down Expand Up @@ -196,19 +202,21 @@ function create_field( $field ) {
}


/*
* input_admin_enqueue_scripts()
*
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
* Use this action to add CSS + JavaScript to assist your create_field() action.
*
* $info https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
* @type action
* @since 3.6
* @date 23/01/13
*
* @TODO: DRY
*/
/**
* input_admin_enqueue_scripts()
*
* This action is called in the admin_enqueue_scripts action on the edit screen where your field is created.
* Use this action to add CSS + JavaScript to assist your create_field() action.
*
* $info https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
* @type action
* @since 3.6
* @date 23/01/13
*
* @return void
*
* @TODO: DRY
*/
function input_admin_enqueue_scripts() {

$plugin_url = $this->settings[ 'url' ];
Expand Down Expand Up @@ -264,23 +272,23 @@ function input_admin_enqueue_scripts() {
}


/*
* load_value()
*
* This filter is applied to the $value after it is loaded from the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value found in the database
* @param $post_id - the $post_id from which the value was loaded
* @param $field - the field array holding all the field options
*
* @TODO: DRY
*
* @return $value - the value to be saved in the database
*/
/**
* load_value()
*
* This filter is applied to the $value after it is loaded from the db
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value
* @param $post_id
* @param $field
*
* @return mixed
*
* @TODO: DRY
*/
function load_value( $value, $post_id, $field ) {
$state_code = false;
$country_code = ( isset( $value[ 'countryCode' ] ) ) ? $value[ 'countryCode' ] : false;
Expand Down Expand Up @@ -387,10 +395,7 @@ function update_value( $value, $post_id, $field ) {
}
}


// initialize
new acf_field_city_selector( $this->settings );


// class_exists check
endif;
Loading

0 comments on commit f9cb196

Please sign in to comment.