Plugin Directory

Changeset 2878134


Ignore:
Timestamp:
03/10/2023 08:50:25 PM (3 years ago)
Author:
devpress
Message:

Update to version 1.1.0 from GitHub

Location:
address-autocomplete-google-places
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • address-autocomplete-google-places/tags/1.1.0/address-autocomplete.php

    r2860332 r2878134  
    44 * Plugin URI: https://github.com/devpress/address-autocomplete-google-places
    55 * Description: Enables address autocomplete with Google Places API for WooCommerce.
    6  * Version: 1.0.1
     6 * Version: 1.1.0
    77 * Author: DevPress
    88 * Author URI: https://devpress.com
    99 * Text Domain: address-autocomplete-google-places
    10  * Requires at least: 5.9
     10 * Requires at least: 6.0
    1111 * Requires PHP: 7.2
    1212 * Tested up to: 6.1.1
     
    2929
    3030    /** @var string */
    31     public static $version = '1.0.1';
     31    public static $version = '1.1.0';
    3232
    3333    /** @var string */
     
    6060        self::$dir = plugin_dir_path( __FILE__ );
    6161
    62         // On plugins page adds link to the settings.
     62        // Declares compatibility with High Performance Order Storage.
     63        add_action( 'before_woocommerce_init', array( $this, 'declare_custom_order_table_compatibility' ) );
     64
     65        // Adds link to settings from plugins page.
    6366        $base_name = plugin_basename( __FILE__ );
    6467        add_filter( 'plugin_action_links_' . $base_name, array( $this, 'plugin_action_links' ) );
     
    6770        add_action( 'plugins_loaded', array( $this, 'init' ) );
    6871    }
     72
     73    /**
     74     * Declares compatibility with High Performance Order Storage.
     75     * https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book
     76     */
     77    public function declare_custom_order_table_compatibility() {
     78        if ( ! class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     79            return;
     80        }
     81        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     82    }
     83
    6984
    7085    /**
  • address-autocomplete-google-places/tags/1.1.0/assets/address-autocomplete.js

    r2860332 r2878134  
    9393            countryAllowList = [country];
    9494        }
    95 
    9695        address.setComponentRestrictions({
    9796            country: countryAllowList,
     
    103102     */
    104103    parsePlace = (address, fieldInputs) => {
    105         let place = address.getPlace();
    106         let streetNumber = "";
    107         let route = "";
    108 
    109         for (let i = 0; i < place.address_components.length; i++) {
    110             const type = place.address_components[i].types[0];
    111             const shortName = place.address_components[i].short_name;
    112             const longName = place.address_components[i].long_name;
    113 
    114             // Street number.
    115             if (type === "street_number") {
    116                 streetNumber = longName;
    117                 continue;
     104        const place = address.getPlace();
     105        const addressComponents = place.address_components;
     106
     107        // Get country first since address components vary by country.
     108        const country = this.getAddressComponentShortName(
     109            addressComponents,
     110            "country"
     111        );
     112
     113        // Set the country field.
     114        const countryField = fieldInputs.country;
     115        countryField.value = country;
     116        countryField.dispatchEvent(new Event("change"));
     117
     118        // Set the address1 field.
     119        fieldInputs.address1.value = this.parseStreetAddress(addressComponents);
     120
     121        // Set the city field.
     122        // Requires the country to properly parse.
     123        fieldInputs.city.value = this.parseCity(addressComponents, country);
     124
     125        // Set the state field.
     126        const stateField = fieldInputs.state;
     127        const stateComponent = this.getAddressComponent(
     128            addressComponents,
     129            "administrative_area_level_1"
     130        );
     131        if (stateField.tagName == "SELECT") {
     132            stateField.value = stateComponent.short_name;
     133            Array.prototype.forEach.call(stateField.options, function (option) {
     134                if (stateComponent.short_name == option.value) {
     135                    option.selected = true;
     136                    return true;
     137                }
     138            });
     139        } else {
     140            stateField.value = stateComponent.long_name;
     141        }
     142        stateField.dispatchEvent(new Event("change"));
     143
     144        // Set the postal code field.
     145        fieldInputs.postcode.value = this.getAddressComponentLongName(
     146            addressComponents,
     147            "postal_code"
     148        );
     149    };
     150
     151    /**
     152     * Parse address1 from address components.
     153     *
     154     * @return {string} The street address.
     155     */
     156    parseStreetAddress = (addressComponents) => {
     157        const streetNumber = this.getAddressComponentLongName(
     158            addressComponents,
     159            "street_number"
     160        );
     161        const route = this.getAddressComponentLongName(
     162            addressComponents,
     163            "route"
     164        );
     165        return `${streetNumber} ${route}`.trim();
     166    };
     167
     168    /**
     169     * Parse city from address components.
     170     *
     171     * @return {string} The city.
     172     */
     173    parseCity = (addressComponents, country) => {
     174        // Different countries use different address components for city.
     175        let city = "";
     176
     177        // GB has some oddities with city names.
     178        if ("GB" === country) {
     179            city = this.getAddressComponentLongName(
     180                addressComponents,
     181                "postal_town"
     182            );
     183            if (city === "") {
     184                city = this.getAddressComponentLongName(
     185                    addressComponents,
     186                    "administrative_area_level_2"
     187                );
    118188            }
    119 
    120             // Street name.
    121             if (type === "route") {
    122                 route = longName;
    123                 continue;
    124             }
    125 
    126             // City.
    127             if (type === "sublocality_level_1" || type === "locality") {
    128                 fieldInputs.city.value = longName;
    129                 continue;
    130             }
    131 
    132             // State.
    133             if (type === "administrative_area_level_1") {
    134                 const stateField = fieldInputs.state;
    135                 if (stateField.tagName == "SELECT") {
    136                     stateField.value = shortName;
    137                     Array.prototype.forEach.call(
    138                         stateField.options,
    139                         function (option) {
    140                             if (shortName == option.value) {
    141                                 option.selected = true;
    142                                 return true;
    143                             }
    144                         }
    145                     );
    146                 } else {
    147                     stateField.value = longName;
    148                 }
    149                 stateField.dispatchEvent(new Event("change"));
    150                 continue;
    151             }
    152 
    153             // Country.
    154             if (type === "country") {
    155                 const countryField = fieldInputs.country;
    156                 countryField.value = shortName;
    157                 countryField.dispatchEvent(new Event("change"));
    158                 continue;
    159             }
    160 
    161             // Postal code.
    162             if (type === "postal_code") {
    163                 fieldInputs.postcode.value = longName;
    164                 continue;
    165             }
    166         }
    167 
    168         // Populate address1 field.
    169         fieldInputs.address1.value = streetNumber + " " + route;
     189            return city;
     190        }
     191
     192        const locality = this.getAddressComponentLongName(
     193            addressComponents,
     194            "locality"
     195        );
     196
     197        if (locality !== "") {
     198            return locality;
     199        }
     200
     201        const sublocality = this.getAddressComponentLongName(
     202            addressComponents,
     203            "sublocality_level_1"
     204        );
     205
     206        if (sublocality !== "") {
     207            return sublocality;
     208        }
     209
     210        return "";
     211    };
     212
     213    /**
     214     * Gets the shortname for the address component.
     215     *
     216     * @return {string} The shortname.
     217     */
     218    getAddressComponentShortName = (addressComponents, key) => {
     219        const component = this.getAddressComponent(addressComponents, key);
     220        return component.short_name ?? "";
     221    };
     222
     223    /**
     224     * Gets the longname for the address component.
     225     *
     226     * @return {string} The shortname.
     227     */
     228    getAddressComponentLongName = (addressComponents, key) => {
     229        const component = this.getAddressComponent(addressComponents, key);
     230        return component.long_name ?? "";
     231    };
     232
     233    /**
     234     * Filters the address components by type key.
     235     *
     236     * @return {object} The address component.
     237     */
     238    getAddressComponent = (addressComponents, key) => {
     239        const component = addressComponents.filter((address) =>
     240            address.types.includes(key)
     241        );
     242        return component[0] ?? [];
    170243    };
    171244
  • address-autocomplete-google-places/tags/1.1.0/languages/address-autocomplete.pot

    r2860332 r2878134  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Address Autocomplete Google Places 1.0.0\n"
     5"Project-Id-Version: Address Autocomplete Google Places 1.1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/address-autocomplete-google-places\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-01-29T23:23:29+00:00\n"
     12"POT-Creation-Date: 2023-03-10T20:47:35+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
     
    3535msgstr ""
    3636
    37 #: address-autocomplete.php:101
     37#: address-autocomplete.php:119
    3838msgid "Address Autocomplete requires at least WooCommerce v%1$s in order to function."
    3939msgstr ""
    4040
    41 #: address-autocomplete.php:115
     41#: address-autocomplete.php:133
    4242msgid "Settings"
    4343msgstr ""
  • address-autocomplete-google-places/tags/1.1.0/readme.txt

    r2860332 r2878134  
    44Tags: woocommerce
    55Requires at least: 6.0
    6 Tested up to: 6.0
    7 Stable tag: 1.0.1
     6Tested up to: 6.1.1
     7Stable tag: 1.1.0
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    4949== Changelog ==
    5050
     51= 1.1.0 =
     52
     53* Update: Declare compatibility for High Performance Order Storage.
     54* Update: Improves methods for parsing address components.
     55
    5156= 1.0.1 =
    5257
  • address-autocomplete-google-places/trunk/address-autocomplete.php

    r2860332 r2878134  
    44 * Plugin URI: https://github.com/devpress/address-autocomplete-google-places
    55 * Description: Enables address autocomplete with Google Places API for WooCommerce.
    6  * Version: 1.0.1
     6 * Version: 1.1.0
    77 * Author: DevPress
    88 * Author URI: https://devpress.com
    99 * Text Domain: address-autocomplete-google-places
    10  * Requires at least: 5.9
     10 * Requires at least: 6.0
    1111 * Requires PHP: 7.2
    1212 * Tested up to: 6.1.1
     
    2929
    3030    /** @var string */
    31     public static $version = '1.0.1';
     31    public static $version = '1.1.0';
    3232
    3333    /** @var string */
     
    6060        self::$dir = plugin_dir_path( __FILE__ );
    6161
    62         // On plugins page adds link to the settings.
     62        // Declares compatibility with High Performance Order Storage.
     63        add_action( 'before_woocommerce_init', array( $this, 'declare_custom_order_table_compatibility' ) );
     64
     65        // Adds link to settings from plugins page.
    6366        $base_name = plugin_basename( __FILE__ );
    6467        add_filter( 'plugin_action_links_' . $base_name, array( $this, 'plugin_action_links' ) );
     
    6770        add_action( 'plugins_loaded', array( $this, 'init' ) );
    6871    }
     72
     73    /**
     74     * Declares compatibility with High Performance Order Storage.
     75     * https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book
     76     */
     77    public function declare_custom_order_table_compatibility() {
     78        if ( ! class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     79            return;
     80        }
     81        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     82    }
     83
    6984
    7085    /**
  • address-autocomplete-google-places/trunk/assets/address-autocomplete.js

    r2860332 r2878134  
    9393            countryAllowList = [country];
    9494        }
    95 
    9695        address.setComponentRestrictions({
    9796            country: countryAllowList,
     
    103102     */
    104103    parsePlace = (address, fieldInputs) => {
    105         let place = address.getPlace();
    106         let streetNumber = "";
    107         let route = "";
    108 
    109         for (let i = 0; i < place.address_components.length; i++) {
    110             const type = place.address_components[i].types[0];
    111             const shortName = place.address_components[i].short_name;
    112             const longName = place.address_components[i].long_name;
    113 
    114             // Street number.
    115             if (type === "street_number") {
    116                 streetNumber = longName;
    117                 continue;
     104        const place = address.getPlace();
     105        const addressComponents = place.address_components;
     106
     107        // Get country first since address components vary by country.
     108        const country = this.getAddressComponentShortName(
     109            addressComponents,
     110            "country"
     111        );
     112
     113        // Set the country field.
     114        const countryField = fieldInputs.country;
     115        countryField.value = country;
     116        countryField.dispatchEvent(new Event("change"));
     117
     118        // Set the address1 field.
     119        fieldInputs.address1.value = this.parseStreetAddress(addressComponents);
     120
     121        // Set the city field.
     122        // Requires the country to properly parse.
     123        fieldInputs.city.value = this.parseCity(addressComponents, country);
     124
     125        // Set the state field.
     126        const stateField = fieldInputs.state;
     127        const stateComponent = this.getAddressComponent(
     128            addressComponents,
     129            "administrative_area_level_1"
     130        );
     131        if (stateField.tagName == "SELECT") {
     132            stateField.value = stateComponent.short_name;
     133            Array.prototype.forEach.call(stateField.options, function (option) {
     134                if (stateComponent.short_name == option.value) {
     135                    option.selected = true;
     136                    return true;
     137                }
     138            });
     139        } else {
     140            stateField.value = stateComponent.long_name;
     141        }
     142        stateField.dispatchEvent(new Event("change"));
     143
     144        // Set the postal code field.
     145        fieldInputs.postcode.value = this.getAddressComponentLongName(
     146            addressComponents,
     147            "postal_code"
     148        );
     149    };
     150
     151    /**
     152     * Parse address1 from address components.
     153     *
     154     * @return {string} The street address.
     155     */
     156    parseStreetAddress = (addressComponents) => {
     157        const streetNumber = this.getAddressComponentLongName(
     158            addressComponents,
     159            "street_number"
     160        );
     161        const route = this.getAddressComponentLongName(
     162            addressComponents,
     163            "route"
     164        );
     165        return `${streetNumber} ${route}`.trim();
     166    };
     167
     168    /**
     169     * Parse city from address components.
     170     *
     171     * @return {string} The city.
     172     */
     173    parseCity = (addressComponents, country) => {
     174        // Different countries use different address components for city.
     175        let city = "";
     176
     177        // GB has some oddities with city names.
     178        if ("GB" === country) {
     179            city = this.getAddressComponentLongName(
     180                addressComponents,
     181                "postal_town"
     182            );
     183            if (city === "") {
     184                city = this.getAddressComponentLongName(
     185                    addressComponents,
     186                    "administrative_area_level_2"
     187                );
    118188            }
    119 
    120             // Street name.
    121             if (type === "route") {
    122                 route = longName;
    123                 continue;
    124             }
    125 
    126             // City.
    127             if (type === "sublocality_level_1" || type === "locality") {
    128                 fieldInputs.city.value = longName;
    129                 continue;
    130             }
    131 
    132             // State.
    133             if (type === "administrative_area_level_1") {
    134                 const stateField = fieldInputs.state;
    135                 if (stateField.tagName == "SELECT") {
    136                     stateField.value = shortName;
    137                     Array.prototype.forEach.call(
    138                         stateField.options,
    139                         function (option) {
    140                             if (shortName == option.value) {
    141                                 option.selected = true;
    142                                 return true;
    143                             }
    144                         }
    145                     );
    146                 } else {
    147                     stateField.value = longName;
    148                 }
    149                 stateField.dispatchEvent(new Event("change"));
    150                 continue;
    151             }
    152 
    153             // Country.
    154             if (type === "country") {
    155                 const countryField = fieldInputs.country;
    156                 countryField.value = shortName;
    157                 countryField.dispatchEvent(new Event("change"));
    158                 continue;
    159             }
    160 
    161             // Postal code.
    162             if (type === "postal_code") {
    163                 fieldInputs.postcode.value = longName;
    164                 continue;
    165             }
    166         }
    167 
    168         // Populate address1 field.
    169         fieldInputs.address1.value = streetNumber + " " + route;
     189            return city;
     190        }
     191
     192        const locality = this.getAddressComponentLongName(
     193            addressComponents,
     194            "locality"
     195        );
     196
     197        if (locality !== "") {
     198            return locality;
     199        }
     200
     201        const sublocality = this.getAddressComponentLongName(
     202            addressComponents,
     203            "sublocality_level_1"
     204        );
     205
     206        if (sublocality !== "") {
     207            return sublocality;
     208        }
     209
     210        return "";
     211    };
     212
     213    /**
     214     * Gets the shortname for the address component.
     215     *
     216     * @return {string} The shortname.
     217     */
     218    getAddressComponentShortName = (addressComponents, key) => {
     219        const component = this.getAddressComponent(addressComponents, key);
     220        return component.short_name ?? "";
     221    };
     222
     223    /**
     224     * Gets the longname for the address component.
     225     *
     226     * @return {string} The shortname.
     227     */
     228    getAddressComponentLongName = (addressComponents, key) => {
     229        const component = this.getAddressComponent(addressComponents, key);
     230        return component.long_name ?? "";
     231    };
     232
     233    /**
     234     * Filters the address components by type key.
     235     *
     236     * @return {object} The address component.
     237     */
     238    getAddressComponent = (addressComponents, key) => {
     239        const component = addressComponents.filter((address) =>
     240            address.types.includes(key)
     241        );
     242        return component[0] ?? [];
    170243    };
    171244
  • address-autocomplete-google-places/trunk/languages/address-autocomplete.pot

    r2860332 r2878134  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Address Autocomplete Google Places 1.0.0\n"
     5"Project-Id-Version: Address Autocomplete Google Places 1.1.0\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/address-autocomplete-google-places\n"
    77"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1010"Content-Type: text/plain; charset=UTF-8\n"
    1111"Content-Transfer-Encoding: 8bit\n"
    12 "POT-Creation-Date: 2023-01-29T23:23:29+00:00\n"
     12"POT-Creation-Date: 2023-03-10T20:47:35+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
     
    3535msgstr ""
    3636
    37 #: address-autocomplete.php:101
     37#: address-autocomplete.php:119
    3838msgid "Address Autocomplete requires at least WooCommerce v%1$s in order to function."
    3939msgstr ""
    4040
    41 #: address-autocomplete.php:115
     41#: address-autocomplete.php:133
    4242msgid "Settings"
    4343msgstr ""
  • address-autocomplete-google-places/trunk/readme.txt

    r2860332 r2878134  
    44Tags: woocommerce
    55Requires at least: 6.0
    6 Tested up to: 6.0
    7 Stable tag: 1.0.1
     6Tested up to: 6.1.1
     7Stable tag: 1.1.0
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    4949== Changelog ==
    5050
     51= 1.1.0 =
     52
     53* Update: Declare compatibility for High Performance Order Storage.
     54* Update: Improves methods for parsing address components.
     55
    5156= 1.0.1 =
    5257
Note: See TracChangeset for help on using the changeset viewer.