Plugin Directory

Changeset 2841215


Ignore:
Timestamp:
12/29/2022 07:01:45 PM (3 years ago)
Author:
Beee
Message:

Store as single meta

Location:
acf-city-selector/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • acf-city-selector/trunk/ACF_City_Selector.php

    r2798478 r2841215  
    44    Plugin URI:     https://acf-city-selector.com
    55    Description:    An extension for ACF which allows you to select a city based on country and province/state.
    6     Version:        1.9.1
    7     Tested up to:   6.0.2
     6    Version:        1.10.0
     7    Tested up to:   6.1.1
    88    Requires PHP:   7.0
    99    Author:         Beee
     
    3636                    'db_version' => '1.0',
    3737                    'url'        => plugin_dir_url( __FILE__ ),
    38                     'version'    => '1.9.1',
     38                    'version'    => '1.10.0',
    3939                );
    4040
     
    109109                do_action( 'acfcs_delete_transients' );
    110110                // other important stuff gets done in uninstall.php
    111             }
    112 
    113 
    114             /*
    115              * Prepare database upon plugin activation
    116              */
    117             public function acfcs_fill_database() {
    118                 $countries = array( 'nl', 'be' );
    119                 foreach( $countries as $country ) {
    120                     acfcs_import_data( $country . '.csv', ACFCS_PLUGIN_PATH . 'import/' );
    121                 }
    122111            }
    123112
     
    270259             */
    271260            public function acfcs_settings_link( $links ) {
    272                 $settings_link = [ 'settings' => '<a href="options-general.php?page=acfcs-dashboard">' . esc_html__( 'Settings', 'acf-city-selector' ) . '</a>' ];
     261                $settings_link = [ 'settings' => sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=acfcs-dashboard' ), esc_html__( 'Settings', 'acf-city-selector' ) ) ];
    273262
    274263                return array_merge( $settings_link, $links );
     
    383372             * @param $to_index
    384373             */
    385             public static function acfcs_move_array_element( &$array, $from_index, $to_index ) {
     374            public function acfcs_move_array_element( &$array, $from_index, $to_index ) {
    386375                $splice = array_splice( $array, $from_index, 1 );
    387376                array_splice( $array, $to_index, 0, $splice );
  • acf-city-selector/trunk/admin/acf-city-selector-v5.php

    r2696652 r2841215  
    1111         */
    1212        class acf_field_city_selector extends acf_field {
    13 
    1413            /*
    1514             * Function index
     
    2625             * acf_field_city_selector constructor
    2726             *
    28              * This function will setup the class functionality
     27             * This function will set up the class functionality
    2928             *
    3029             * @param $settings
    3130             */
    3231            function __construct( $settings ) {
    33 
    3432                $this->name     = 'acf_city_selector';
    3533                $this->label    = 'City Selector';
     
    3735                $this->defaults = array(
    3836                    'show_labels'  => 1,
     37                    'store_meta'   => 0,
    3938                    'which_fields' => 'all',
    4039                    'use_select2'  => 0,
     
    4645
    4746                parent::__construct();
    48 
    49             }
     47            }
     48
    5049
    5150            /**
     
    5756             */
    5857            function render_field_settings( $field ) {
    59 
    6058                $select_options = array(
    6159                    1 => esc_attr__( 'Yes', 'acf-city-selector' ),
     
    7270                ) );
    7371
    74                 acf_render_field_setting( $field, array(
     72                acf_render_field_setting( $field, array(
    7573                    'choices'      => $select_options,
    7674                    'instructions' => esc_html__( 'Use select2 for dropdowns', 'acf-city-selector' ),
     
    8078                    'type'         => 'radio',
    8179                    'value'        => $field[ 'use_select2' ],
     80                ) );
     81
     82                acf_render_field_setting( $field, array(
     83                    'choices'      => $select_options,
     84                    'instructions' => esc_html__( 'Store location as single meta values', 'acf-city-selector' ),
     85                    'label'        => esc_html__( 'Store meta', 'acf-city-selector' ),
     86                    'layout'       => 'horizontal',
     87                    'name'         => 'store_meta',
     88                    'type'         => 'radio',
     89                    'value'        => $field[ 'store_meta' ],
    8290                ) );
    8391
     
    107115            }
    108116
     117
    109118            /**
    110119             * render_field()
     
    115124             */
    116125            function render_field( $field ) {
    117 
    118                 $default_country  = ( isset( $field[ 'default_country' ] ) && ! empty( $field[ 'default_country' ] ) ) ? $field[ 'default_country' ] : false;
    119                 $prefill_cities   = array();
    120                 $prefill_states   = array();
    121                 $selected_country = ( isset( $field[ 'value' ][ 'countryCode' ] ) ) ? $field[ 'value' ][ 'countryCode' ] : false;
    122                 $selected_state   = ( isset( $field[ 'value' ][ 'stateCode' ] ) ) ? $field[ 'value' ][ 'stateCode' ] : false;
    123                 $selected_city    = ( isset( $field[ 'value' ][ 'cityName' ] ) ) ? $field[ 'value' ][ 'cityName' ] : false;
    124                 $show_first       = true;
    125                 $which_fields     = ( isset( $field[ 'which_fields' ] ) ) ? $field[ 'which_fields' ] : 'all';
    126 
    127                 if ( false !== $default_country && false == $selected_country ) {
     126                $default_country  = ( isset( $field[ 'default_country' ] ) && ! empty( $field[ 'default_country' ] ) ) ? $field[ 'default_country' ] : false;
     127                $prefill_cities   = [];
     128                $prefill_states   = [];
     129                $selected_country = ( isset( $field[ 'value' ][ 'countryCode' ] ) ) ? $field[ 'value' ][ 'countryCode' ] : false;
     130                $selected_state   = ( isset( $field[ 'value' ][ 'stateCode' ] ) ) ? $field[ 'value' ][ 'stateCode' ] : false;
     131                $selected_city    = ( isset( $field[ 'value' ][ 'cityName' ] ) ) ? $field[ 'value' ][ 'cityName' ] : false;
     132                $show_first       = true;
     133                $store_meta       = ( isset( $field[ 'value' ][ 'store_meta' ] ) ) ? $field[ 'value' ][ 'store_meta' ] : false;
     134                $which_fields     = ( isset( $field[ 'which_fields' ] ) ) ? $field[ 'which_fields' ] : 'all';
     135
     136                if ( false !== $default_country && false == $selected_country ) {
    128137                    // New post with default country
    129138                    if ( in_array( $which_fields, [ 'all', 'country_state', 'state_city' ] ) ) {
     
    167176                    echo acfcs_render_dropdown( 'city', $field, $selected_city, $prefill_values );
    168177                }
     178                if ( ! isset( $field[ 'parent_layout' ] ) && ! isset( $field[ 'parent_repeater' ] ) && $store_meta ) {
     179                    echo acfcs_render_hidden_field( 'store_meta', '1' );
     180                }
    169181            }
    170182
     
    177189             */
    178190            function input_admin_enqueue_scripts() {
    179 
    180191                $plugin_url     = $this->settings[ 'url' ];
    181192                $plugin_version = $this->settings[ 'version' ];
     
    192203                $js_vars[ 'post_id' ]         = ( isset( $_GET[ 'post' ] ) ) ? (int) $_GET[ 'post' ] : false;
    193204                $js_vars[ 'show_labels' ]     = ( isset( $all_info[ 'show_labels' ] ) ) ? $all_info[ 'show_labels' ] : apply_filters( 'acfcs_show_labels', true );
     205                $js_vars[ 'store_meta' ]      = ( isset( $all_info[ 'store_meta' ] ) ) ? $all_info[ 'store_meta' ] : false;
    194206                $js_vars[ 'use_select2' ]     = ( isset( $all_info[ 'use_select2' ] ) ) ? $all_info[ 'use_select2' ] : false;
    195207                $js_vars[ 'which_fields' ]    = ( isset( $all_info[ 'which_fields' ] ) ) ? $all_info[ 'which_fields' ] : 'all';
    196208
    197209                wp_localize_script( 'acfcs-process', 'city_selector_vars', $js_vars );
    198 
    199210            }
    200211
     
    214225             */
    215226            function load_value( $value, $post_id, $field ) {
    216 
    217227                $state_code   = false;
    218228                $country_code = ( isset( $value[ 'countryCode' ] ) ) ? $value[ 'countryCode' ] : false;
     
    231241                if ( strlen( $country_code ) == 2 && false != $state_code ) {
    232242                    global $wpdb;
    233                     $sql_query              = $wpdb->prepare( "SELECT country, state_name FROM {$wpdb->prefix}cities WHERE country_code= %s AND state_code= %s", $country_code, $state_code );
    234                     $row                    = $wpdb->get_row( $sql_query );
    235                     $value[ 'stateCode' ]   = $state_code;
    236                     $value[ 'stateName' ]   = ( isset( $row->state_name ) ) ? $row->state_name : false;
    237                     $value[ 'countryName' ] = ( isset( $row->country ) ) ? $row->country : false;
     243                    $table                  = $wpdb->prefix . 'cities';
     244                    $sql_query              = $wpdb->prepare( "SELECT country, state_name FROM {$table} WHERE country_code = %s AND state_code = %s", $country_code, $state_code );
     245                    $row                    = $wpdb->get_row( $sql_query );
     246                    $value[ 'stateCode' ]   = $state_code;
     247                    $value[ 'stateName' ]   = ( isset( $row->state_name ) ) ? $row->state_name : false;
     248                    $value[ 'countryName' ] = ( isset( $row->country ) ) ? $row->country : false;
    238249                }
    239250
     
    255266             */
    256267            function update_value( $value, $post_id, $field ) {
    257 
    258268                $required = $field[ 'required' ];
    259269                if ( 0 == $required ) {
     
    316326                }
    317327
     328                if ( ! isset( $field[ 'parent_layout' ] ) && ! isset( $field[ 'parent_repeater' ] ) ) {
     329                    do_action( 'acfcs_store_meta', $value, $post_id );
     330                }
     331
    318332                return $value;
    319 
    320333            }
    321334
     
    336349             */
    337350            function validate_value( $valid, $value, $field, $input ) {
    338 
    339351                if ( 1 == $field[ 'required' ] ) {
    340352                    $nothing       = esc_html__( "You didn't select anything.", 'acf-city-selector' );
     
    384396
    385397        new acf_field_city_selector( $this->settings );
    386 
    387398    }
  • acf-city-selector/trunk/admin/acfcs-countries.php

    r2685642 r2841215  
    5252                            <p>
    5353                                <?php esc_html_e( "And now you can !! We have created several 'country packages' for you to import 'as is'.", 'acf-city-selector' ); ?>
    54                                 <?php echo sprintf( __( 'Download them %s.', 'acf-city-selector' ), sprintf( '<a href="%s">%s</a>', esc_url( ACFCS_WEBSITE_URL . '/get-countries/' ), __( 'here', 'acf-city-selector' ) ) ); ?>
     54                                <?php echo sprintf( esc_html__( 'Download them %s.', 'acf-city-selector' ), sprintf( '<a href="%s" target="_blank" rel="noopener">%s</a>', esc_url( ACFCS_WEBSITE_URL . '/get-countries/' ), esc_html__( 'here', 'acf-city-selector' ) ) ); ?>
    5555                            </p>
    5656                        </div>
  • acf-city-selector/trunk/admin/acfcs-info.php

    r2696652 r2841215  
    2727                            <p>
    2828                                <?php esc_html_e( 'This page shows real-time info about your site and settings.', 'acf-city-selector' ); ?>
    29                                 <br />
    30                                 <?php esc_html_e( 'We might ask for this info if support is helping you fix a problem.', 'acf-city-selector' ); ?>
    3129                            </p>
    3230                        </div>
  • acf-city-selector/trunk/assets/css/general.css

    r2685642 r2841215  
    11/* errors */
    22.acfcs .notice--error {
    3     border-left-color: #dc3232;
     3    border-left-color: #dc3232;
    44}
    55
    66.acfcs .notice--success {
    7     border-left-color: #43bc71;
     7    border-left-color: #43bc71;
    88}
    99
    1010.acfcs .notice--warning {
    11     border-left-color: #ff9000;
     11    border-left-color: #ff9000;
    1212}
    1313
    1414.acfcs .notice--info {
    15     border-left-color: #00a0d2;
     15    border-left-color: #00a0d2;
    1616}
    1717
    1818.acfcs .field__message {
    19     background-color: #f9f9f9;
    20     border-left:       2px solid #ccd0d4;
    21     border-top:        1px solid #ccd0d4;
    22     border-right:      1px solid #ccd0d4;
    23     border-bottom:     1px solid #ccd0d4;
    24     margin-bottom:     1rem;
    25     padding:           5px;
     19    background-color: #f9f9f9;
     20    border-left:      2px solid #ccd0d4;
     21    border-top:       1px solid #ccd0d4;
     22    border-right:     1px solid #ccd0d4;
     23    border-bottom:    1px solid #ccd0d4;
     24    margin-bottom:    1rem;
     25    padding:          5px;
    2626}
    2727
    2828.acfcs .field__message--error {
    29     border-left-color: #dc3232;
     29    border-left-color: #dc3232;
    3030}
    3131
    3232.acfcs .field__message--warning {
    33     border-left-color: #ff9000;
     33    border-left-color: #ff9000;
    3434}
    3535
     
    3737/* not actively supported anymore */
    3838.field_type-acf_city_selector .acfcs__dropdown-box {
    39     margin-bottom: 1rem;
     39    margin-bottom: 1rem;
    4040}
    4141
    4242.field_type-acf_city_selector span.acf-input-header {
    43     display:       block;
    44     margin-bottom: 10px;
     43    display:       block;
     44    margin-bottom: 10px;
    4545}
    4646
    4747/* edit post screens v5 */
    4848.acf-field-acf-city-selector .acfcs__dropdown-box {
    49     margin-bottom: 1rem;
     49    margin-bottom: 1rem;
     50}
     51
     52.acf-field-acf-city-selector .acfcs__checkbox {
     53    display:   flex;
     54    flex-flow: row nowrap;
     55    align-items: center;
     56}
     57
     58.acfcs__checkbox input[type="checkbox"] {
     59    margin-right: 0.5rem;
     60}
     61
     62.acfcs__checkbox label {
     63    vertical-align: initial;
    5064}
    5165
    5266.acf-field.acf-field-acf-city-selector select.acfcs__dropdown {
    53     padding: 4px;
     67    padding: 4px;
    5468}
    5569
    5670.acf-field-acf-city-selector .acf-input-header {
    57     margin-bottom: 10px;
     71    margin-bottom: 10px;
    5872}
  • acf-city-selector/trunk/inc/acfcs-actions.php

    r2797458 r2841215  
    4848    }
    4949    add_action( 'acfcs_after_success_import', 'acfcs_reimport_cities' );
     50
     51
     52    /**
     53     * Save location as single meta values
     54     *
     55     * @param $value
     56     * @param $post_id
     57     *
     58     * @return void
     59     */
     60    function acfcs_save_single_meta( $value, $post_id ) {
     61        if ( isset( $_POST[ 'store_meta' ] ) && 1 == $_POST[ 'store_meta' ] ) {
     62            if ( ! empty( $value[ 'countryCode' ] ) ) {
     63                update_post_meta( $post_id, 'acfcs_search_country', $value[ 'countryCode' ] );
     64            }
     65            if ( ! empty( $value[ 'stateCode' ] ) ) {
     66                update_post_meta( $post_id, 'acfcs_search_state', $value[ 'stateCode' ] );
     67            }
     68            if ( ! empty( $value[ 'cityName' ] ) ) {
     69                update_post_meta( $post_id, 'acfcs_search_city', $value[ 'cityName' ] );
     70            }
     71        } elseif ( $post_id ) {
     72            // remove meta
     73            delete_post_meta( $post_id, 'acfcs_search_country' );
     74            delete_post_meta( $post_id, 'acfcs_search_state' );
     75            delete_post_meta( $post_id, 'acfcs_search_city' );
     76        }
     77    }
     78    add_action( 'acfcs_store_meta', 'acfcs_save_single_meta', 10, 2 );
  • acf-city-selector/trunk/inc/acfcs-ajax.php

    r2685642 r2841215  
    2828            }
    2929
    30             if ( ! isset( $field[ 'show_labels' ] ) ) {
    31                 if ( isset( $_POST[ 'show_labels' ] ) ) {
    32                     $field[ 'show_labels' ] = ( '1' == sanitize_text_field( $_POST[ 'show_labels' ] ) ) ? true : false;
    33                 }
    34             }
     30            if ( ! isset( $field[ 'show_labels' ] ) && isset( $_POST[ 'show_labels' ] ) ) {
     31                $field[ 'show_labels' ] = ( '1' == sanitize_text_field( $_POST[ 'show_labels' ] ) ) ? true : false;
     32            }
    3533
    3634            if ( isset( $country_code ) ) {
     
    8381            }
    8482
    85             if ( ! isset( $field[ 'show_labels' ] ) ) {
    86                 if ( isset( $_POST[ 'show_labels' ] ) ) {
    87                     $show_labels = sanitize_text_field( $_POST[ 'show_labels' ] );
    88                     if ( '1' == $show_labels ) {
    89                         $field[ 'show_labels' ] = true;
    90                     } elseif ( '0' == $show_labels ) {
    91                         $field[ 'show_labels' ] = false;
    92                     }
    93                 }
     83            if ( ! isset( $field[ 'show_labels' ] ) && isset( $_POST[ 'show_labels' ] ) ) {
     84                $show_labels = sanitize_text_field( $_POST[ 'show_labels' ] );
     85                if ( '1' == $show_labels ) {
     86                    $field[ 'show_labels' ] = true;
     87                } elseif ( '0' == $show_labels ) {
     88                    $field[ 'show_labels' ] = false;
     89                }
    9490            }
    9591
  • acf-city-selector/trunk/inc/acfcs-functions.php

    r2797458 r2841215  
    2929        }
    3030
    31         global $wpdb;
    32         $results = $wpdb->get_results( "
    33             SELECT * FROM {$wpdb->prefix}cities
    34             GROUP BY country
    35             ORDER BY country ASC
    36         " );
     31        global $wpdb;
     32        $table   = $wpdb->prefix . 'cities';
     33        $results = $wpdb->get_results( "SELECT * FROM $table GROUP BY country ORDER BY country ASC" );
    3734
    3835        if ( ! empty( $results ) ) {
     
    4643        }
    4744
    48 
    4945        return $countries;
    5046    }
     
    7672            $transient = get_transient( 'acfcs_states_' . strtolower( $country_code ) );
    7773            if ( false == $transient || is_array( $transient ) && empty( $transient ) ) {
    78                 $order = 'ORDER BY state_name ASC';
     74                $order = ' ORDER BY state_name ASC';
    7975                if ( 'FR' == $country_code ) {
    80                     $order = "ORDER BY LENGTH(state_name), state_name";
    81                 }
    82 
    83                 global $wpdb;
    84                 $sql = $wpdb->prepare( "
    85                     SELECT *
    86                     FROM {$wpdb->prefix}cities
    87                     WHERE country_code = %s
    88                     GROUP BY state_code
    89                     " . $order, strtoupper( $country_code )
    90                 );
    91                 $results = $wpdb->get_results( $sql );
     76                    $order = " ORDER BY LENGTH(state_name), state_name";
     77                }
     78
     79                global $wpdb;
     80                $table   = $wpdb->prefix . 'cities';
     81                $sql     = $wpdb->prepare( "SELECT * FROM $table WHERE country_code = %s GROUP BY state_code" . $order, strtoupper( $country_code ) );
     82                $results = $wpdb->get_results( $sql );
    9283
    9384                $state_results = array();
     
    151142            if ( false !== $country_code ) {
    152143                global $wpdb;
    153                 $query = "SELECT * FROM {$wpdb->prefix}cities";
     144                $table = $wpdb->prefix . 'cities';
     145                $query = "SELECT * FROM $table";
    154146                if ( $country_code && $state_code ) {
    155147                    if ( 3 < strlen( $state_code ) ) {
     
    198190    function acfcs_get_country_name( $country_code = false ) {
    199191        if ( false != $country_code ) {
    200             global $wpdb;
    201             $country = $wpdb->get_row( $wpdb->prepare( "SELECT country FROM {$wpdb->prefix}cities WHERE country_code = %s", $country_code ) );
     192            global $wpdb;
     193            $table   = $wpdb->prefix . 'cities';
     194            $query   = $wpdb->prepare( "SELECT country FROM $table WHERE country_code = %s", $country_code );
     195            $country = $wpdb->get_row( $query );
     196
    202197            if ( isset( $country->country ) ) {
    203198                return $country->country;
     
    215210
    216211    /**
    217      * Checks if there any cities in the database (for page availability)
     212     * Checks if there are any cities in the database (for page availability)
    218213     *
    219214     * @param $country_code
     
    223218    function acfcs_has_cities( $country_code = false ) {
    224219        global $wpdb;
    225         $query = "SELECT * FROM {$wpdb->prefix}cities LIMIT 1";
     220        $table = $wpdb->prefix . 'cities';
     221        $query = "SELECT * FROM $table LIMIT 1";
    226222        if ( $country_code ) {
    227             $query = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}cities WHERE country_code = %s LIMIT 1", $country_code );
     223            $query = $wpdb->prepare( "SELECT * FROM $table WHERE country_code = %s LIMIT 1", $country_code );
    228224        }
    229225
     
    244240     */
    245241    function acfcs_check_if_files() {
    246         $target_dir = acfcs_upload_folder();
    247         if ( is_dir( $target_dir ) ) {
     242        $actual_files = [];
     243        $target_dir   = acfcs_upload_folder();
     244
     245        if ( is_dir( $target_dir ) ) {
    248246            $file_index = scandir( $target_dir );
    249247            $excluded_files = [
     
    255253
    256254            if ( is_array( $file_index ) ) {
    257                 $actual_files = array();
    258255                foreach ( $file_index as $file ) {
    259256                    if ( ! in_array( $file, $excluded_files ) ) {
     
    267264        }
    268265
    269         return array();
     266        return $actual_files;
    270267    }
    271268
     
    439436    function acfcs_get_countries_info() {
    440437        global $wpdb;
    441         $results = $wpdb->get_results( "
    442                 SELECT country_code FROM {$wpdb->prefix}cities
    443                 GROUP BY country_code
    444                 ORDER BY country_code ASC
    445             " );
     438        $table   = $wpdb->prefix . 'cities';
     439        $results = $wpdb->get_results( "SELECT country_code FROM $table GROUP BY country_code ORDER BY country_code ASC" );
    446440
    447441        $acfcs_info = array();
    448442        foreach ( $results as $data ) {
    449             $country_code = $data->country_code;
    450             $results      = $wpdb->get_results( $wpdb->prepare( "
    451                 SELECT * FROM {$wpdb->prefix}cities
    452                 WHERE country_code = %s
    453                 ORDER BY country_code ASC
    454             ", $country_code ) );
     443            $country_code = $data->country_code;
     444            $query        = $wpdb->prepare( "SELECT * FROM $table WHERE country_code = %s ORDER BY country_code ASC", $country_code );
     445            $results      = $wpdb->get_results( $query );
    455446
    456447            $acfcs_info[ $country_code ] = [
     
    589580
    590581
     582    function acfcs_render_hidden_field( $name, $value ) {
     583        if ( $name && $value ) {
     584            return sprintf( '<input type="hidden" name="%s" value="%s" />', $name, $value );
     585        }
     586
     587        return false;
     588    }
     589
     590
    591591    /**
    592592     * Verify CSV data
     
    726726        if ( ! empty( $sanitized_country_codes ) ) {
    727727            global $wpdb;
    728             $country_string = strtoupper( "'" . implode( "', '", $sanitized_country_codes ) . "'" );
    729             $query          = "DELETE FROM {$wpdb->prefix}cities WHERE `country_code` IN ({$country_string})";
    730             $result         = $wpdb->query( $query );
     728            $table          = $wpdb->prefix . 'cities';
     729            $country_string = strtoupper( "'" . implode( "', '", $sanitized_country_codes ) . "'" );
     730            $query          = $wpdb->prepare( "DELETE FROM $table WHERE `country_code` IN (%s)", $country_string );
     731            $result         = $wpdb->query( $query );
     732
    731733            if ( $result > 0 ) {
    732734                ACF_City_Selector::acfcs_errors()->add( 'success_country_remove', sprintf( esc_html__( 'You have successfully removed all entries for %s.', 'acf-city-selector' ), $country_names_and ) );
     
    763765     */
    764766    function acfcs_render_preview_results( $csv_data = [] ) {
    765         if ( ! empty( $csv_data ) ) {
     767        $table = '';
     768        if ( ! empty( $csv_data ) ) {
    766769            $table_columns = [
    767770                esc_html__( 'City', 'acf-city-selector' ),
     
    789792            $table_body = sprintf( '<tbody>%s</tbody>', $table_rows );
    790793            $table      = sprintf( '<table class="acfcs__table acfcs__table--preview-result scrollable">%s%s</table>', $table_headers, $table_body );
    791 
    792             return $table;
    793         }
    794 
    795         return '';
     794        }
     795
     796        return $table;
    796797    }
    797798
     
    806807    function acfcs_get_states_optgroup() {
    807808        $results = acfcs_get_countries( false );
     809        $states  = [];
     810
    808811        // if there is at least 1 country
    809812        if ( ! empty( $results ) ) {
     
    817820            // get states for these countries
    818821            if ( ! empty( $countries ) ) {
    819                 global $wpdb;
    820                 $states = array();
    821                 foreach ( $countries as $country ) {
     822                global $wpdb;
     823                $table  = $wpdb->prefix . 'cities';
     824
     825                foreach ( $countries as $country ) {
    822826                    $states[] = array(
    823827                        'state' => 'open_optgroup',
     
    830834                    }
    831835
    832                     $query   = "SELECT * FROM {$wpdb->prefix}cities WHERE country_code = %s GROUP BY state_code " . $order;
     836                    $query   = "SELECT * FROM $table WHERE country_code = %s GROUP BY state_code " . $order;
    833837                    $sql     = $wpdb->prepare( $query, $country[ 'code' ] );
    834838                    $results = $wpdb->get_results( $sql );
     
    848852                    );
    849853                }
    850 
    851                 return $states;
    852             }
    853         }
    854 
    855         return [];
     854            }
     855        }
     856
     857        return $states;
    856858    }
    857859
     
    905907        }
    906908
    907         $sql = "SELECT * FROM {$wpdb->prefix}cities
    908                 " . $where . "
    909                 " . $orderby . "
    910                 " . $search_limit . "
    911             ";
    912         $cities = $wpdb->get_results( $sql );
     909        $table  = $wpdb->prefix . 'cities';
     910        $query  = $wpdb->prepare( "SELECT * FROM $table %s %s %s", $where, $orderby, $search_limit );
     911        $cities = $wpdb->get_results( $query );
    913912
    914913        return $cities;
  • acf-city-selector/trunk/inc/form-handling.php

    r2685642 r2841215  
    119119                        }
    120120                    }
    121                     $cities  = implode( ', ', $cities );
    122                     $row_ids = implode( ',', $ids );
    123                     $query   = "DELETE FROM " . $wpdb->prefix . "cities WHERE id IN (" . $row_ids . ")";
    124                     $amount  = $wpdb->query( $query );
     121                    $cities  = implode( ', ', $cities );
     122                    $row_ids = implode( ',', $ids );
     123                    $table   = $wpdb->prefix . 'cities';
     124                    $query   = $wpdb->prepare( "DELETE FROM {$table} WHERE id IN (%s)", $row_ids );
     125                    $amount  = $wpdb->query( $query );
    125126
    126127                    if ( $amount > 0 ) {
  • acf-city-selector/trunk/readme.txt

    r2798478 r2841215  
    44Requires at least: 3.6.0
    55Requires PHP: 7.0
    6 Tested up to: 6.0.2
    7 Stable tag: 1.9.1
     6Tested up to: 6.1.1
     7Stable tag: 1.10.0
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 This plugins adds a new (ACF) field to select a city depending on country and state/province.
     11This plugin adds a new (ACF) field to select a city depending on country and state/province.
    1212
    1313== Description ==
     
    4242== Changelog ==
    4343
     44= 1.10.0 =
     45* Add option to store location as single meta values
     46* Fix ordering for states (which caused some issues)
     47
    4448= 1.9.1 =
    4549* fix incorrect version
Note: See TracChangeset for help on using the changeset viewer.