Plugin Directory

Changeset 3339099


Ignore:
Timestamp:
08/04/2025 03:08:27 PM (8 months ago)
Author:
IQComputing
Message:

Update to version 1.0.2 from GitHub

Location:
live-rates-for-shipstation
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • live-rates-for-shipstation/tags/1.0.2/changelog.txt

    r3337929 r3339099  
    22
    33This is a brief text document keeping track of changes to the plugin. For a full history, see the Github Repository.
     4
     5= 1.0.2 =
     6
     7Relase Date: August 04, 2025
     8
     9* Overview
     10    * Automatically clears the API caching whenever Integration settings or Shipping Zone settings are saved.
     11        * Shoutout to .org user @dpkonofa for their assistance in debugging this issue!
     12
     13* Code Updates
     14    * Moves the \IQLRSS\Core\Settings_Shipstation::api_actions_endpoint() clearcache action into it's own method.
     15        * In a future release, the caching will be in it's own class definition.
    416
    517= 1.0.1 =
  • live-rates-for-shipstation/tags/1.0.2/core/settings-shipstation.php

    r3337929 r3339099  
    4242        add_action( 'woocommerce_cart_totals_after_order_total',array( $this, 'display_cart_weight' ) ) ;
    4343        add_action( 'rest_api_init',                            array( $this, 'api_actions_endpoint' ) );
     44        add_action( 'woocommerce_update_option',                array( $this, 'clear_cache_on_update' ) );
    4445
    4546    }
     
    180181            'callback' => function( $request ) {
    181182
    182                 global $wpdb;
    183 
    184183                $params = $request->get_params();
    185184                if( ! isset( $params['action'] ) || empty( $params['action'] ) ) {
     
    192191                    case 'clearcache':
    193192
    194                         /**
    195                          * The API Class creates various transients to cache carrier services.
    196                          * These transients are not tracked but generated based on the responses carrier codes.
    197                          * All these transients are prefixed with our plugins unique string slug.
    198                          * The first WHERE ensures only `_transient_` and the 2nd ensures only our plugins transients.
    199                          */
    200                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s AND option_name LIKE %s",
    201                             $wpdb->esc_like( '_transient_' ) . '%',
    202                             '%' . $wpdb->esc_like( '_' . \IQLRSS\Driver::get( 'slug' ) . '_' ) . '%'
    203                         ) );
    204 
    205                         // Set transient to clear any WC_Session caches if they are found.
    206                         $time = absint( apply_filters( 'wc_session_expiration', DAY_IN_SECONDS * 2 ) );
    207                         set_transient( \IQLRSS\Driver::plugin_prefix( 'wcs_timeout' ), time(), $time );
    208 
    209193                        // Success!
     194                        $this->clear_cache();
    210195                        wp_send_json_success();
    211196
     
    283268
    284269
     270    /**
     271     * Clear the API cache.
     272     *
     273     * @return void
     274     */
     275    public function clear_cache() {
     276
     277        global $wpdb;
     278
     279        /**
     280         * The API Class creates various transients to cache carrier services.
     281         * These transients are not tracked but generated based on the responses carrier codes.
     282         * All these transients are prefixed with our plugins unique string slug.
     283         * The first WHERE ensures only `_transient_` and the 2nd ensures only our plugins transients.
     284         */
     285        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s AND option_name LIKE %s",
     286            $wpdb->esc_like( '_transient_' ) . '%',
     287            '%' . $wpdb->esc_like( '_' . \IQLRSS\Driver::get( 'slug' ) . '_' ) . '%'
     288        ) );
     289
     290        // Set transient to clear any WC_Session caches if they are found.
     291        $time = absint( apply_filters( 'wc_session_expiration', DAY_IN_SECONDS * 2 ) );
     292        set_transient( \IQLRSS\Driver::plugin_prefix( 'wcs_timeout' ), time(), $time );
     293
     294    }
     295
     296
     297    /**
     298     * Clear the cache whenever the Integration settings have been updated.
     299     *
     300     * @param Array $args
     301     *
     302     * @return void
     303     */
     304    public function clear_cache_on_update( $args ) {
     305
     306        if( ! isset( $args['id'] ) || false === strpos( $args['id'], 'shipstation' ) ) {
     307            return;
     308        }
     309
     310        $this->clear_cache();
     311
     312    }
     313
     314
    285315
    286316    /**------------------------------------------------------------------------------------------------ **/
     
    326356        $appended_fields = array();
    327357        $carrier_desc = esc_html__( 'Select which ShipStation carriers you would like to see live shipping rates from.', 'live-rates-for-shipstation' );
     358
     359        $carriers = array();
     360        $shipStationAPI = new Shipstation_Api();
     361        $response = $shipStationAPI->get_carriers();
     362
     363        if( ! is_a( $response, 'WP_Error' ) ) {
     364            foreach( $response as $carrier ) {
     365                $carriers[ $carrier['carrier_id'] ] = $carrier['name'];
     366            }
     367        }
    328368
    329369        foreach( $fields as $key => $field ) {
     
    345385                    'type'          => 'multiselect',
    346386                    'class'         => 'chosen_select',
    347                     'options'       => ( function() { // Closure since it's only used once.
    348 
    349                         $carriers = array();
    350                         $shipStationAPI = new Shipstation_Api();
    351                         $response = $shipStationAPI->get_carriers();
    352 
    353                         if( ! is_a( $response, 'WP_Error' ) ) {
    354                             foreach( $response as $carrier ) {
    355                                 $carriers[ $carrier['carrier_id'] ] = $carrier['name'];
    356                             }
    357                         }
    358 
    359                         return $carriers;
    360 
    361                     } )(),
     387                    'options'       => $carriers,
    362388                    'description'   => $carrier_desc,
    363389                    'desc_tip'      => esc_html__( 'Services from selected carriers will be available when setting up Shipping Zones.', 'live-rates-for-shipstation' ),
  • live-rates-for-shipstation/tags/1.0.2/core/shipping-method-shipstation.php

    r3337929 r3339099  
    3838
    3939    /**
     40     * Array of global carriers
     41     * There are the carriers saved in Integration settings.
     42     *
     43     * @var Array
     44     */
     45    protected $carriers = array();
     46
     47
     48    /**
    4049     * ShipStation API Helper Class
    4150     *
    4251     * @var Object
    4352     */
    44     protected $shipStationApi;
     53    protected $shipStationApi = null;
    4554
    4655
     
    7079        $this->supports             = array( 'instance-settings' );
    7180
     81        $this->carriers = \IQLRSS\Driver::get_ss_opt( 'carriers', array(), true );
    7282        $saved_key = \IQLRSS\Driver::get_ss_opt( 'api_key_valid', false, true );
    73         $saved_carriers = \IQLRSS\Driver::get_ss_opt( 'carriers', array(), true );
    7483
    7584        // Only show in Shipping Zones if API Key is invalid.
     
    8897
    8998    /**
     99     * Clear cache whenever settings are updated.
     100     *
     101     * @return Boolean
     102     */
     103    public function process_admin_options() {
     104
     105        ( new \IQLRSS\Core\Settings_Shipstation() )->clear_cache();
     106        return parent::process_admin_options();
     107
     108    }
     109
     110
     111    /**
    90112     * Increase the HTTP Request Timeout
    91113     * Sometimes ShipStation takes awhile to responde with rates.
     
    117139     */
    118140    protected function init_instance_form_fields() {
    119 
    120         $global_adjustment = \IQLRSS\Driver::get_ss_opt( 'global_adjustment', '0', true );
    121141
    122142        $this->instance_form_fields = array(
     
    345365        }
    346366
     367        $saved_carriers = array_keys( $saved_services );
     368        if( ! empty( $saved_carriers ) && ! empty( $this->carriers ) ) {
     369            $saved_carriers = array_values( array_intersect( $saved_carriers, $this->carriers ) );
     370        }
     371
    347372        $global_upcharge = floatval( \IQLRSS\Driver::get_ss_opt( 'global_adjustment', 0, true ) );
    348         $saved_carriers = array_keys( $saved_services );
    349373        $packing_type   = $this->get_option( 'packing', 'individual' );
    350374        $request = array(
     
    435459                $rate = array(
    436460                    'id'        => $shiprate['code'],
    437                     'label'     => $shiprate['carrier_name'] . ' - ' . $shiprate['name'],
     461                    'label'     => sprintf( '%s (%s)', $shiprate['name'], $shiprate['carrier_name'] ),
    438462                    'package'   => $packages,
    439463                    'meta_data' => array(
  • live-rates-for-shipstation/tags/1.0.2/live-rates-for-shipstation.php

    r3337929 r3339099  
    44 * Plugin URI: https://iqcomputing.com/contact/
    55 * Description: ShipStation shipping method with live rates.
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Requries at least: 5.9
    88 * Author: IQComputing
     
    2626     * @var String
    2727     */
    28     protected static $version = '1.0.1';
     28    protected static $version = '1.0.2';
    2929
    3030
  • live-rates-for-shipstation/tags/1.0.2/readme.txt

    r3337929 r3339099  
    44Requires at least: 5.9
    55Tested up to: 6.8
    6 Stable tag: 1.0.1
     6Stable tag: 1.0.2
    77License: GPLv3 or later
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    4949== Changelog ==
    5050
     51= 1.0.2 (2025-08-04) =
     52* Refines API caching that clears on settings save (thanks again to @dpkonofa for test/reporting!).
     53
    5154= 1.0.1 (2025-08-01) =
    5255* Patches an issue with Individual Shipping Requests (thanks @dpkonofa !).
  • live-rates-for-shipstation/trunk/changelog.txt

    r3337929 r3339099  
    22
    33This is a brief text document keeping track of changes to the plugin. For a full history, see the Github Repository.
     4
     5= 1.0.2 =
     6
     7Relase Date: August 04, 2025
     8
     9* Overview
     10    * Automatically clears the API caching whenever Integration settings or Shipping Zone settings are saved.
     11        * Shoutout to .org user @dpkonofa for their assistance in debugging this issue!
     12
     13* Code Updates
     14    * Moves the \IQLRSS\Core\Settings_Shipstation::api_actions_endpoint() clearcache action into it's own method.
     15        * In a future release, the caching will be in it's own class definition.
    416
    517= 1.0.1 =
  • live-rates-for-shipstation/trunk/core/settings-shipstation.php

    r3337929 r3339099  
    4242        add_action( 'woocommerce_cart_totals_after_order_total',array( $this, 'display_cart_weight' ) ) ;
    4343        add_action( 'rest_api_init',                            array( $this, 'api_actions_endpoint' ) );
     44        add_action( 'woocommerce_update_option',                array( $this, 'clear_cache_on_update' ) );
    4445
    4546    }
     
    180181            'callback' => function( $request ) {
    181182
    182                 global $wpdb;
    183 
    184183                $params = $request->get_params();
    185184                if( ! isset( $params['action'] ) || empty( $params['action'] ) ) {
     
    192191                    case 'clearcache':
    193192
    194                         /**
    195                          * The API Class creates various transients to cache carrier services.
    196                          * These transients are not tracked but generated based on the responses carrier codes.
    197                          * All these transients are prefixed with our plugins unique string slug.
    198                          * The first WHERE ensures only `_transient_` and the 2nd ensures only our plugins transients.
    199                          */
    200                         $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s AND option_name LIKE %s",
    201                             $wpdb->esc_like( '_transient_' ) . '%',
    202                             '%' . $wpdb->esc_like( '_' . \IQLRSS\Driver::get( 'slug' ) . '_' ) . '%'
    203                         ) );
    204 
    205                         // Set transient to clear any WC_Session caches if they are found.
    206                         $time = absint( apply_filters( 'wc_session_expiration', DAY_IN_SECONDS * 2 ) );
    207                         set_transient( \IQLRSS\Driver::plugin_prefix( 'wcs_timeout' ), time(), $time );
    208 
    209193                        // Success!
     194                        $this->clear_cache();
    210195                        wp_send_json_success();
    211196
     
    283268
    284269
     270    /**
     271     * Clear the API cache.
     272     *
     273     * @return void
     274     */
     275    public function clear_cache() {
     276
     277        global $wpdb;
     278
     279        /**
     280         * The API Class creates various transients to cache carrier services.
     281         * These transients are not tracked but generated based on the responses carrier codes.
     282         * All these transients are prefixed with our plugins unique string slug.
     283         * The first WHERE ensures only `_transient_` and the 2nd ensures only our plugins transients.
     284         */
     285        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s AND option_name LIKE %s",
     286            $wpdb->esc_like( '_transient_' ) . '%',
     287            '%' . $wpdb->esc_like( '_' . \IQLRSS\Driver::get( 'slug' ) . '_' ) . '%'
     288        ) );
     289
     290        // Set transient to clear any WC_Session caches if they are found.
     291        $time = absint( apply_filters( 'wc_session_expiration', DAY_IN_SECONDS * 2 ) );
     292        set_transient( \IQLRSS\Driver::plugin_prefix( 'wcs_timeout' ), time(), $time );
     293
     294    }
     295
     296
     297    /**
     298     * Clear the cache whenever the Integration settings have been updated.
     299     *
     300     * @param Array $args
     301     *
     302     * @return void
     303     */
     304    public function clear_cache_on_update( $args ) {
     305
     306        if( ! isset( $args['id'] ) || false === strpos( $args['id'], 'shipstation' ) ) {
     307            return;
     308        }
     309
     310        $this->clear_cache();
     311
     312    }
     313
     314
    285315
    286316    /**------------------------------------------------------------------------------------------------ **/
     
    326356        $appended_fields = array();
    327357        $carrier_desc = esc_html__( 'Select which ShipStation carriers you would like to see live shipping rates from.', 'live-rates-for-shipstation' );
     358
     359        $carriers = array();
     360        $shipStationAPI = new Shipstation_Api();
     361        $response = $shipStationAPI->get_carriers();
     362
     363        if( ! is_a( $response, 'WP_Error' ) ) {
     364            foreach( $response as $carrier ) {
     365                $carriers[ $carrier['carrier_id'] ] = $carrier['name'];
     366            }
     367        }
    328368
    329369        foreach( $fields as $key => $field ) {
     
    345385                    'type'          => 'multiselect',
    346386                    'class'         => 'chosen_select',
    347                     'options'       => ( function() { // Closure since it's only used once.
    348 
    349                         $carriers = array();
    350                         $shipStationAPI = new Shipstation_Api();
    351                         $response = $shipStationAPI->get_carriers();
    352 
    353                         if( ! is_a( $response, 'WP_Error' ) ) {
    354                             foreach( $response as $carrier ) {
    355                                 $carriers[ $carrier['carrier_id'] ] = $carrier['name'];
    356                             }
    357                         }
    358 
    359                         return $carriers;
    360 
    361                     } )(),
     387                    'options'       => $carriers,
    362388                    'description'   => $carrier_desc,
    363389                    'desc_tip'      => esc_html__( 'Services from selected carriers will be available when setting up Shipping Zones.', 'live-rates-for-shipstation' ),
  • live-rates-for-shipstation/trunk/core/shipping-method-shipstation.php

    r3337929 r3339099  
    3838
    3939    /**
     40     * Array of global carriers
     41     * There are the carriers saved in Integration settings.
     42     *
     43     * @var Array
     44     */
     45    protected $carriers = array();
     46
     47
     48    /**
    4049     * ShipStation API Helper Class
    4150     *
    4251     * @var Object
    4352     */
    44     protected $shipStationApi;
     53    protected $shipStationApi = null;
    4554
    4655
     
    7079        $this->supports             = array( 'instance-settings' );
    7180
     81        $this->carriers = \IQLRSS\Driver::get_ss_opt( 'carriers', array(), true );
    7282        $saved_key = \IQLRSS\Driver::get_ss_opt( 'api_key_valid', false, true );
    73         $saved_carriers = \IQLRSS\Driver::get_ss_opt( 'carriers', array(), true );
    7483
    7584        // Only show in Shipping Zones if API Key is invalid.
     
    8897
    8998    /**
     99     * Clear cache whenever settings are updated.
     100     *
     101     * @return Boolean
     102     */
     103    public function process_admin_options() {
     104
     105        ( new \IQLRSS\Core\Settings_Shipstation() )->clear_cache();
     106        return parent::process_admin_options();
     107
     108    }
     109
     110
     111    /**
    90112     * Increase the HTTP Request Timeout
    91113     * Sometimes ShipStation takes awhile to responde with rates.
     
    117139     */
    118140    protected function init_instance_form_fields() {
    119 
    120         $global_adjustment = \IQLRSS\Driver::get_ss_opt( 'global_adjustment', '0', true );
    121141
    122142        $this->instance_form_fields = array(
     
    345365        }
    346366
     367        $saved_carriers = array_keys( $saved_services );
     368        if( ! empty( $saved_carriers ) && ! empty( $this->carriers ) ) {
     369            $saved_carriers = array_values( array_intersect( $saved_carriers, $this->carriers ) );
     370        }
     371
    347372        $global_upcharge = floatval( \IQLRSS\Driver::get_ss_opt( 'global_adjustment', 0, true ) );
    348         $saved_carriers = array_keys( $saved_services );
    349373        $packing_type   = $this->get_option( 'packing', 'individual' );
    350374        $request = array(
     
    435459                $rate = array(
    436460                    'id'        => $shiprate['code'],
    437                     'label'     => $shiprate['carrier_name'] . ' - ' . $shiprate['name'],
     461                    'label'     => sprintf( '%s (%s)', $shiprate['name'], $shiprate['carrier_name'] ),
    438462                    'package'   => $packages,
    439463                    'meta_data' => array(
  • live-rates-for-shipstation/trunk/live-rates-for-shipstation.php

    r3337929 r3339099  
    44 * Plugin URI: https://iqcomputing.com/contact/
    55 * Description: ShipStation shipping method with live rates.
    6  * Version: 1.0.1
     6 * Version: 1.0.2
    77 * Requries at least: 5.9
    88 * Author: IQComputing
     
    2626     * @var String
    2727     */
    28     protected static $version = '1.0.1';
     28    protected static $version = '1.0.2';
    2929
    3030
  • live-rates-for-shipstation/trunk/readme.txt

    r3337929 r3339099  
    44Requires at least: 5.9
    55Tested up to: 6.8
    6 Stable tag: 1.0.1
     6Stable tag: 1.0.2
    77License: GPLv3 or later
    88License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    4949== Changelog ==
    5050
     51= 1.0.2 (2025-08-04) =
     52* Refines API caching that clears on settings save (thanks again to @dpkonofa for test/reporting!).
     53
    5154= 1.0.1 (2025-08-01) =
    5255* Patches an issue with Individual Shipping Requests (thanks @dpkonofa !).
Note: See TracChangeset for help on using the changeset viewer.