Plugin Directory

Changeset 3203635


Ignore:
Timestamp:
12/06/2024 01:11:16 PM (3 months ago)
Author:
luizbills
Message:

Release 2.3.5, see readme.txt for the changelog.

Location:
shipping-simulator-for-woocommerce
Files:
83 added
27 edited

Legend:

Unmodified
Added
Removed
  • shipping-simulator-for-woocommerce/trunk/CHANGELOG.md

    r3141733 r3203635  
    22
    33All notable changes to this project will be documented in this file.
     4
     5## 2.3.5 - 2024-12-05
     6
     7[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/2.3.4...2.3.5)
     8
     9-   Tested up to WordPress 6.7
     10-   Minor fixes
    411
    512## 2.3.4 - 2024-08-26
  • shipping-simulator-for-woocommerce/trunk/classes/Request.php

    r2912471 r3203635  
    108108
    109109        $package = new Shipping_Package();
     110
     111        /** @var Shipping_Package */
    110112        $package = apply_filters( 'wc_shipping_simulator_request_update_package', $package, $this->data );
    111113
     
    120122    }
    121123
    122     protected function get_results ( $rates, $notice = null ) {
     124    protected function get_results ( $rates ) {
    123125        $args = [
    124             'rates' => [],
    125             'notice' => $notice,
     126            'rates' => $rates,
     127            'notice' => apply_filters(
     128                'wc_shipping_simulator_no_results_notice',
     129                Settings::get_option( 'no_results' )
     130            ),
     131            'data' => $this->data,
    126132        ];
    127         if ( ! $notice ) {
    128             $args = [
    129                 'rates' => $rates,
    130                 'notice' => apply_filters(
    131                     'wc_shipping_simulator_no_results_notice',
    132                     Settings::get_option( 'no_results' )
    133                 ),
    134                 'data' => $this->data,
    135             ];
    136         }
    137133        return \apply_filters(
    138134            'wc_shipping_simulator_request_results_html',
  • shipping-simulator-for-woocommerce/trunk/composer.json

    r2912471 r3203635  
    11{
    22    "require": {
     3        "php": ">=7.4",
    34        "ext-mbstring": "*"
    45    },
     
    78        "php-stubs/woocommerce-stubs": "^7.4",
    89        "phpstan/phpstan": "^1.10"
    9     },
    10     "scripts": {
    11         "check": "phpstan",
    12         "build": "./scripts/build",
    13         "deploy": "./scripts/svn-push",
    14         "update-trunk": "./scripts/svn-push --only-trunk",
    15         "make-pot": "wp i18n make-pot . languages/wc-shipping-simulator.pot",
    16         "upgrade-core": "./scripts/upgrade-core"
    1710    },
    1811    "autoload": {
     
    2619        }
    2720    },
     21    "config": {
     22        "platform-check": false
     23    },
     24    "scripts": {
     25        "build": "./scripts/build",
     26        "deploy": "./scripts/svn-push",
     27        "update-trunk": "./scripts/svn-push --only-trunk",
     28        "make-pot": "wp i18n make-pot . languages/wc-shipping-simulator.pot",
     29        "upgrade-core": "./scripts/upgrade-core",
     30        "check": "phpstan"
     31    },
    2832    "wp-plugin-base": {
    2933        "namespace": "Shipping_Simulator",
  • shipping-simulator-for-woocommerce/trunk/config.php

    r2765398 r3203635  
    11<?php
    22
    3 defined( 'WPINC' ) || exit( 1 );
     3defined( 'ABSPATH' ) || exit( 1 );
    44
    55return [
    66    'SLUG' => 'wc-shipping-simulator',
    77    'PREFIX' => 'wc_shipping_simulator_',
    8     'LANGUAGES_DIR' => 'languages',
    98    'TEMPLATES_DIR' => 'templates',
    109    'DONATION_URL' => 'https://luizpb.com/donate/',
  • shipping-simulator-for-woocommerce/trunk/core/Config.php

    r2791336 r3203635  
    33namespace Shipping_Simulator\Core;
    44
    5 abstract class Config {
     5final class Config {
     6    /** @var array */
    67    protected static $values = [];
    78
     9    /**
     10     * @param string $main_file The file that contains the plugin headers
     11     * @return void
     12     * @throws \Exception
     13     */
    814    public static function init ( $main_file ) {
    915        if ( self::get_size() > 0 ) {
    10             throw new \Error( __CLASS__ . ' already initialized' );
     16            throw new \Exception( __CLASS__ . ' already initialized' );
    1117        }
    1218
     
    1521
    1622        if ( ! is_array( $config ) ) {
    17             throw new \Error( $root . '/config.php must return an Array' );
     23            throw new \Exception( $root . '/config.php must return an Array' );
     24        }
     25
     26        if (
     27            function_exists( 'wp_get_environment_type' )
     28            && in_array( \wp_get_environment_type(), [ 'local', 'development' ] )
     29            && file_exists( $root . '/config.dev.php' )
     30        ) {
     31            $config_dev = include $root . '/config.dev.php';
     32            $config = array_replace( $config, $config_dev );
    1833        }
    1934
     
    2843        $slug = isset( self::$values[ 'SLUG' ] ) ? self::$values[ 'SLUG' ] : false;
    2944        if ( ! $slug || ! is_string( $slug ) ) {
    30             throw new \Error( $root . '/config.php must define a string SLUG (Recommended: only alphanumeric and dashes)' );
     45            throw new \Exception( $root . '/config.php must define a string SLUG (Recommended: only alphanumeric and dashes)' );
    3146        }
    3247
    3348        $prefix = isset( self::$values[ 'PREFIX' ] ) ? self::$values[ 'PREFIX' ] : false;
    3449        if ( ! $prefix || ! is_string( $prefix ) ) {
    35             throw new \Error( $root . '/config.php must define a string PREFIX (only alphanumeric and underscores)' );
     50            throw new \Exception( $root . '/config.php must define a string PREFIX (only alphanumeric and underscores)' );
    3651        }
    3752
     
    4156        $data = \get_file_data( $main_file, [ 'Plugin Name', 'Version' ] );
    4257        self::$values[ 'NAME' ] = __( $data[0], 'wc-shipping-simulator' );
    43         self::$values[ 'VERSION' ] = $data[1] ? $data[1] : '0.0.0';
     58        self::$values[ 'VERSION' ] = $data[1] ? $data[1] : false;
    4459    }
    4560
     61    /**
     62     * @param string $key
     63     * @param mixed $value
     64     * @return mixed The value
     65     * @throws \Exception
     66     */
    4667    public static function set ( $key, $value ) {
    4768        $key = mb_strtoupper( $key );
    4869        if ( isset( self::$values[ $key ] ) ) {
    49             throw new \Error( __METHOD__ . ": Key \"$key\" has already been assigned. No key can be assigned more than once." );
     70            throw new \Exception( __METHOD__ . ": Key \"$key\" has already been assigned. No key can be assigned more than once." );
    5071        }
    5172        self::$values[ $key ] = $value;
     
    5374    }
    5475
     76    /**
     77     * @param string $key
     78     * @param mixed $default
     79     * @return mixed
     80     * @throws \Exception
     81     */
    5582    public static function get ( $key, $default = null ) {
    5683        $key = \mb_strtoupper( $key );
    5784        $value = isset( self::$values[ $key ] ) ? self::$values[ $key ] : $default;
    5885        if ( null === $value ) {
    59             throw new \Error( __METHOD__ . ": Undefined key $key" );
     86            throw new \Exception( __METHOD__ . ": Undefined key $key" );
    6087        }
    6188        return $value;
    6289    }
    6390
     91    /**
     92     * @return int<0, max>
     93     */
    6494    public static function get_size () {
    6595        return count( self::$values );
    6696    }
    6797
     98    /**
     99     * @param string $string
     100     * @param string $sep
     101     * @return string
     102     */
    68103    public static function sanitize_slug ( $string, $sep = '-' ) {
    69104        $slug = \strtolower( \remove_accents( $string ) ); // Convert to ASCII
  • shipping-simulator-for-woocommerce/trunk/core/Dependencies.php

    r2970338 r3203635  
    33namespace Shipping_Simulator\Core;
    44
    5 abstract class Dependencies {
     5final class Dependencies {
     6    /** @var array */
    67    protected static $dependencies;
     8
     9    /** @var bool */
    710    protected static $initialized = false;
    811
     12    /**
     13     * @return void
     14     * @throws \Exception
     15     */
    916    public static function init () {
    1017        if ( self::$initialized ) {
    11             throw new \Error( __CLASS__ . ' already initialized' );
     18            throw new \Exception( __CLASS__ . ' already initialized' );
    1219        }
    1320
     
    1522        self::$dependencies = include_once $root . '/dependencies.php';
    1623        if ( ! is_array( self::$dependencies ) ) {
    17             throw new \Error( $root . '/dependencies.php must return an Array' );
     24            throw new \Exception( $root . '/dependencies.php must return an Array' );
    1825        }
    1926
     
    2330    }
    2431
     32    /**
     33     * @return void
     34     */
    2535    public static function maybe_start_plugin () {
    2636        $result = self::check_dependencies();
     
    3343    }
    3444
     45    /**
     46     * @return array{success: bool, messages: array<int, array{text: string, is_error: bool}>}
     47     * @throws \Exception
     48     */
    3549    public static function check_dependencies () {
    3650        $result = [
     
    4862            if ( ! is_string( $message ) || '' === trim( $message ) ) {
    4963                $id = is_integer( $key ) ? '#' . ( 1 + $key ) : $key;
    50                 throw new \Error( "Dependency $id has an invalid 'message': its must be a string and and it cannot be empty." );
     64                throw new \Exception( "Dependency $id has an invalid 'message': its must be a string and and it cannot be empty." );
    5165            }
    5266
     
    7286    }
    7387
     88    /**
     89     * @param string $shortcut
     90     * @return bool
     91     * @throws \Exception
     92     */
    7493    protected static function handle_shortcut ( $shortcut ) {
    7594        $parts = explode( ':', $shortcut );
     
    7796        $type = trim( $parts[0] );
    7897        if ( ! $value || ! $type ) {
    79             throw new \Error( "Invalid shortcut syntax: $shortcut" );
     98            throw new \Exception( "Invalid shortcut syntax: $shortcut" );
    8099        }
    81100        switch ( $type ) {
     
    102121        }
    103122
    104         throw new \Error( "Unexpected shortcut: $shortcut" );
     123        throw new \Exception( "Unexpected shortcut: $shortcut" );
    105124    }
    106125
     126    /**
     127     * @param array<int, array{text:string, is_error:bool}> $messages
     128     * @return void
     129     */
    107130    protected static function display_notice_missing_deps ( $messages ) {
    108131        if ( ! \is_admin() ) return;
     
    110133        if ( 0 === count( $messages ) ) return;
    111134
    112         \usort( $messages, function ( $a, $b ) {
    113             return $b['is_error'] <=> $a['is_error'];
    114         } );
     135        \usort(
     136            $messages,
     137            function ( $a, $b ) {
     138                return $b['is_error'] <=> $a['is_error'];
     139            }
     140        );
    115141
    116142        \add_action( 'admin_notices', function () use ( $messages ) {
  • shipping-simulator-for-woocommerce/trunk/core/Loader.php

    r2791336 r3203635  
    33namespace Shipping_Simulator\Core;
    44
    5 abstract class Loader {
     5final class Loader {
     6    /** @var bool */
    67    protected static $initialized = false;
     8
     9    /** @var string */
    710    protected static $main_file;
    811
     12    /**
     13     * @return void
     14     * @throws \Exception
     15     */
    916    public static function init () {
    1017        if ( self::$initialized ) {
    11             throw new \Error( __CLASS__ . ' already initialized' );
     18            throw new \Exception( __CLASS__ . ' already initialized' );
    1219        }
    1320
     
    1825    }
    1926
     27    /**
     28     * @return string
     29     */
    2030    public static function get_hook_start_plugin () {
    2131        return 'start_plugin_' . self::$main_file;
    2232    }
    2333
     34    /**
     35     * @return void
     36     * @throws \Exception
     37     */
    2438    public static function load_classes () {
    2539        $root = Config::get( 'DIR' );
     
    2741
    2842        if ( ! is_array( $loader ) ) {
    29             throw new \Error( $root . '/loader.php must return an Array' );
     43            throw new \Exception( $root . '/loader.php must return an Array' );
    3044        }
    3145
     
    5468
    5569            if ( is_string( $class_name ) && ! \class_exists( $class_name ) ) {
    56                 throw new \Error( 'class ' . $class_name . ' does not exist' );
     70                throw new \Exception( 'class ' . $class_name . ' does not exist' );
    5771            }
    5872
     
    7690
    7791            if ( ! $loaded ) {
    78                 throw new \Error( "class $class_name must have at least one of the following methods: __start, __activation (static) or __deactivation (static)" );
     92                throw new \Exception( "class $class_name must have at least one of the following methods: __start, __activation (static) or __deactivation (static)" );
    7993            }
    8094        }
  • shipping-simulator-for-woocommerce/trunk/core/Main.php

    r2791336 r3203635  
    33namespace Shipping_Simulator\Core;
    44
    5 abstract class Main {
    6     protected static $classes_to_load = [];
    7     protected static $dependencies = [];
     5final class Main {
    86
     7    /**
     8     * @param string $main_file The file that contains the plugin headers
     9     * @return void
     10     */
    911    public static function start_plugin ( $main_file ) {
    1012        if ( ! file_exists( $main_file ) ) {
    11             throw new \Error( 'Invalid plugin main file path in ' . __CLASS__ );
     13            throw new \Exception( 'Invalid plugin main file path in ' . __CLASS__ );
    1214        }
    1315
     
    1517        Loader::init();
    1618        Dependencies::init();
     19
     20        add_action( 'init', [ __CLASS__, 'load_textdomain' ], 0 );
     21    }
     22
     23    /**
     24     * Loads the plugin translations
     25     * @return void
     26     */
     27    public static function load_textdomain () {
     28        $languages_dir = Config::get( 'DOMAIN_PATH', 'languages' );
     29        $path = Config::get( 'DIR' ) . "/$languages_dir";
     30        if ( file_exists( $path ) && is_dir( $path ) ) {
     31            \load_plugin_textdomain(
     32                'wc-shipping-simulator',
     33                false,
     34                dirname( plugin_basename( Config::get( 'FILE' ) ) ) . "/$languages_dir/"
     35            );
     36        }
    1737    }
    1838}
  • shipping-simulator-for-woocommerce/trunk/core/Traits/Common_Helpers.php

    r2791336 r3203635  
    33namespace Shipping_Simulator\Core\Traits;
    44
     5use Shipping_Simulator\Core\Traits\Log_Helpers;
    56use Shipping_Simulator\Core\Config;
    67
    78trait Common_Helpers {
    8     // Get the value if set, otherwise return a default value or `null`. Prevents notices when data is not set.
    9     public static function get ( &$var, $default = null ) {
    10         return $var ?? $default;
     9
     10    use Log_Helpers;
     11
     12    /**
     13     * Get the value if set, otherwise return a default value or `null`.
     14     * Prevents notices when data is not set.
     15     *
     16     * @param mixed $var
     17     * @param mixed $default
     18     * @return mixed
     19     */
     20    public static function get ( &$var, $default = null, $clean = true ) {
     21        $value = isset( $var ) ? $var : $default;
     22        return $clean && is_scalar( $value ) ? \sanitize_text_field( $value ) : $value;
    1123    }
    1224
    13     // Get the constant if set, otherwise return a default value or `null`.
     25    /**
     26     * Get the constant if set, otherwise return a default value.
     27     *
     28     * @param string $name The constant name
     29     * @param mixed $default
     30     * @return mixed
     31     */
    1432    public static function get_defined ( $name, $default = null ) {
    1533        return defined( $name ) ? constant( $name ) : $default;
    1634    }
    1735
    18     // returns `false` ONLY IF $var is null, empty array/object or empty string
    19     // note: `$var = false` returns `true` (because $var is filled with a boolean)
     36    /**
     37     * Returns `false` ONLY IF $var is null, empty array/object or empty string
     38     * Note: `$var = false` returns `true` (because $var is filled with a boolean)
     39     *
     40     * @param mixed $var
     41     * @return bool
     42     */
    2043    public static function filled ( $var ) {
    2144        if ( null === $var ) return false;
     
    2649    }
    2750
    28     // example: turns "Hello World" into "hello-world"
     51    /**
     52     * @param string $string
     53     * @param string $sep
     54     * @return string
     55     */
    2956    public static function sanitize_slug ( $string, $sep = '-' ) {
    3057        return Config::sanitize_slug( $string, $sep );
    3158    }
    3259
    33     // appends the plugin prefix (defined in /config.php)
    34     // example: h::prefix( 'something' ) returns "your_prefix_something"
     60    /**
     61     * Appends the plugin prefix (defined in /config.php).
     62     * Example: h::prefix( 'something' ) returns "your_prefix_something"
     63     *
     64     * @param string $appends
     65     * @return string
     66     */
    3567    public static function prefix ( $appends = '' ) {
    3668        return Config::get( 'PREFIX' ) . $appends;
  • shipping-simulator-for-woocommerce/trunk/core/Traits/Config_Helpers.php

    r2791336 r3203635  
    66
    77trait Config_Helpers {
     8
     9    /**
     10     * @param string $key
     11     * @param mixed $default
     12     * @return mixed
     13     * @throws \Exception
     14     */
    815    public static function config_get ( $key, $default = null ) {
    916        return Config::get( $key, $default );
    1017    }
    1118
     19    /**
     20     * @param string $key
     21     * @param mixed $value
     22     * @return mixed The value
     23     * @throws \Exception
     24     */
    1225    public static function config_set ( $key, $value ) {
    1326        return Config::set( $key, $value );
  • shipping-simulator-for-woocommerce/trunk/core/Traits/Debug_Helpers.php

    r2791336 r3203635  
    66
    77trait Debug_Helpers {
     8
     9    /**
     10     * Dump and die
     11     *
     12     * @param mixed ...$values
     13     * @return void|never
     14     */
    815    public static function dd ( ...$values ) {
    916        if ( ! WP_DEBUG ) return;
     
    1522        die;
    1623    }
    17 
    18     public static function log ( ...$values ) {
    19         $debug_log_enabled = WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG;
    20         if ( ! $debug_log_enabled ) return;
    21         $message = '';
    22         foreach ( $values as $value ) {
    23             if ( \is_string( $value ) ) {
    24                 $message .= $value;
    25             } else {
    26                 ob_start();
    27                 var_dump( $value );
    28                 $message .= ob_get_clean();
    29             }
    30             $message .= ' ';
    31         }
    32         $slug = Config::get( 'SLUG' );
    33         \error_log( "[$slug] $message" );
    34     }
    3524}
  • shipping-simulator-for-woocommerce/trunk/core/Traits/String_Helpers.php

    r2791336 r3203635  
    44
    55trait String_Helpers {
    6     public static function str_length ( $string, $encoding = null ) {
    7         return \mb_strlen( $string, $encoding ? $encoding : 'UTF-8' );
     6
     7    /**
     8     * @param string $string
     9     * @param string $encoding
     10     * @return int<0, max>
     11     */
     12    public static function str_length ( $string, $encoding = 'UTF-8' ) {
     13        return \mb_strlen( $string, $encoding );
    814    }
    915
    10     public static function str_lower ( $string, $encoding = null ) {
    11         return \mb_strtolower( $string, $encoding ? $encoding : 'UTF-8' );
     16    /**
     17     * @param string $string
     18     * @param string $encoding
     19     * @return string
     20     */
     21    public static function str_lower ( $string, $encoding = 'UTF-8' ) {
     22        return \mb_strtolower( $string, $encoding );
    1223    }
    1324
    14     public static function str_upper ( $string, $encoding = null ) {
    15         return \mb_strtoupper( $string, $encoding ? $encoding : 'UTF-8' );
     25    /**
     26     * @param string $string
     27     * @param string $encoding
     28     * @return string
     29     */
     30    public static function str_upper ( $string, $encoding = 'UTF-8' ) {
     31        return \mb_strtoupper( $string, $encoding );
    1632    }
    1733
     34    /**
     35     * @param string $string
     36     * @param string $encoding
     37     * @return bool
     38     */
     39    public static function str_contains ( $string, $search, $encoding = 'UTF-8' ) {
     40        return $search !== '' && mb_strpos( $string, $search, 0, $encoding ) !== false;
     41    }
     42
     43    /**
     44     * @param string $string
     45     * @param string $search
     46     * @return string
     47     */
    1848    public static function str_before ( $string, $search ) {
    1949        return '' === $search ? $string : \explode( $search, $string )[0];
    2050    }
    2151
     52    /**
     53     * @param string $string
     54     * @param string $search
     55     * @return string
     56     */
    2257    public static function str_after ( $string, $search ) {
    2358        return '' === $search ? $string : \array_reverse( \explode( $search, $string, 2 ) )[0];
    2459    }
    2560
     61    /**
     62     * @param string $string
     63     * @param string $search
     64     * @return bool
     65     */
    2666    public static function str_starts_with ( $string, $search ) {
    2767        return self::str_after( $string, $search ) !== $string;
    2868    }
    2969
     70    /**
     71     * @param string $string
     72     * @param string $search
     73     * @return bool
     74     */
    3075    public static function str_ends_with ( $string, $search ) {
    3176        return self::str_before( $string, $search ) !== $string;
    3277    }
    3378
    34     // usage: `h::str_mask( 'XXX.XXX.XXX-XX', '83699642062' ); // outputs 836.996.420-62`
     79    /**
     80     * Usage: h::str_mask( 'XXX.XXX.XXX-XX', '83699642062' ); // outputs 836.996.420-62
     81     *
     82     * @param string $string
     83     * @param string $mask
     84     * @param string $symbol
     85     * @return string
     86     */
    3587    public static function str_mask ( $string, $mask, $symbol = 'X' ) {
    3688        $result = '';
    37         for ( $i = 0, $k = 0; $i < \strlen( $mask ); ++$i ) {
     89        for ( $i = 0, $k = 0; $i < self::str_length( $mask ); ++$i ) {
    3890            if ( $mask[ $i ] === $symbol ) {
    3991                if ( isset( $string[ $k ] ) ) $result .= $string[ $k++ ];
  • shipping-simulator-for-woocommerce/trunk/core/Traits/Template_Helpers.php

    r2791336 r3203635  
    88    use Config_Helpers;
    99
    10     // remove evil tags: script, style, link, iframe
     10    /**
     11     * Remove evil tags: script, style, link, iframe
     12     *
     13     * @param string $html
     14     * @return string The sanitized html
     15     */
    1116    public static function safe_html ( $html ) {
    1217        // remove all script and style tags with code
     
    1722    }
    1823
    19     // TEMPLATE RENDERER
     24    /**
     25     * Returns a template rendered with the arguments (2nd parameter).
     26     *
     27     * @param string $template_path
     28     * @param array $args
     29     * @return string - The rendered template
     30     * @throws \Exception
     31     */
    2032    public static function get_template ( $template_path, $args = [] ) {
    2133        $args = \apply_filters( self::prefix( 'get_template_args' ), $args, $template_path );
     
    2840            $html = \ob_get_clean();
    2941        } catch ( \Throwable $e ) {
     42            self::log_critical( $e );
    3043            if ( self::get_defined( 'WP_DEBUG' ) && current_user_can( 'administrator' ) ) {
    31                 $error = wp_slash( "Error while rendering template '$template_path': " . $e->getMessage() );
    32                 $html = '<script>alert("' . esc_js( $error ) . '")</script>';
     44                echo '<pre>' . esc_html( wp_slash( "Error while rendering template '$template_path': " . $e->getMessage() ) ) . '</pre>';
    3345            } else {
    34                 throw new \Error( $e );
     46                throw new \Exception( $e );
    3547            }
    3648        }
     
    3850    }
    3951
     52    /**
     53     * @param string $template_path
     54     * @return string The template absolute path
     55     */
    4056    public static function get_template_path ( $template_path ) {
    4157        $template_path .= '.php' === substr( $template_path, -4 ) ? '' : '.php';
     
    4460    }
    4561
     62    /**
     63     * @return string The directory that contains the plugin templates.
     64     */
    4665    public static function get_templates_dir () {
    4766        $templates = \trim( Config::get( 'TEMPLATES_DIR', 'templates' ), '/' );
  • shipping-simulator-for-woocommerce/trunk/core/Traits/Throw_Helpers.php

    r2791336 r3203635  
    44
    55trait Throw_Helpers {
     6
     7    /**
     8     * @return \Exception
     9     */
    610    public static function get_error_class () {
    7         return \Error::class;
     11        return \Exception::class;
    812    }
    913
     14    /**
     15     * If the condition is falsy, throws a Exception.
     16     *
     17     * @param bool $condition
     18     * @param callable|mixed $message
     19     * @param \Throwable|null $exception_class
     20     * @return void
     21     * @throws \Throwable
     22     */
    1023    public static function throw_if ( $condition, $message, $exception_class = null ) {
    1124        if ( $condition ) {
     
    1831    }
    1932
     33    /**
     34     * If the $var is a WP_Error instance, throws a Exception.
     35     *
     36     * @param mixed $var
     37     * @param string $code
     38     * @param \Throwable|null $exception_class
     39     * @return void
     40     * @throws \Throwable
     41     */
    2042    public static function throw_wp_error ( $var, $code = null, $exception_class = null ) {
    2143        if ( \is_wp_error( $var ) ) self::throw_if( true, $var->get_error_message( $code ), $exception_class );
  • shipping-simulator-for-woocommerce/trunk/core/Traits/WordPress_Helpers.php

    r2791336 r3203635  
    66
    77trait WordPress_Helpers {
     8
     9    /**
     10     * Usage: `$script_url = h::plugin_url( 'assets/js/app.js' );`
     11     *
     12     * @param string $path
     13     * @return string the link
     14     */
    815    public static function plugin_url ( $path = '' ) {
    9         // usage: `$script_url = h::plugin_url( 'assets/js/app.js' );`
    1016        return \plugins_url( $path, Config::get( 'FILE' ) );
    1117    }
    1218
     19    /**
     20     * @param boolean $raw
     21     * @return string The plugin version
     22     */
    1323    public static function get_plugin_version ( $raw = false ) {
    1424        $version = Config::get( 'VERSION' );
     
    1626    }
    1727
     28    /**
     29     * Saves a WordPress transient prefixed with the plugin slug.
     30     *
     31     * @see https://developer.wordpress.org/apis/transients/
     32     * @see https://codex.wordpress.org/Easier_Expression_of_Time_Constants
     33     * @param string $transient
     34     * @param mixed $value
     35     * @param integer $duration
     36     * @return mixed
     37     */
    1838    public static function set_transient ( $transient, $value, $duration = 0 ) {
    1939        if ( is_callable( $value ) ) {
    2040            $value = \call_user_func( $value );
    2141        }
    22         if ( self::config_get( 'CACHE_ENABLED', true ) ) {
     42        if ( Config::get( 'CACHE_ENABLED', true ) ) {
    2343            $key = self::get_transient_key( $transient );
    2444            if ( ! self::filled( $value ) ) {
     
    3858    }
    3959
     60    /**
     61     * @param string $transient
     62     * @param mixed $default
     63     * @return mixed
     64     */
    4065    public static function get_transient ( $transient, $default = false ) {
    41         $key = self::get_transient_key( $transient );
    42         $value = \get_transient( $key );
     66        $value = false;
     67        if ( Config::get( 'CACHE_ENABLED', true ) ) {
     68            $key = self::get_transient_key( $transient );
     69            $value = \get_transient( $key );
     70        }
    4371        return false !== $value ? $value : $default;
    4472    }
    4573
     74    /**
     75     * @param string $transient
     76     * @return string
     77     */
    4678    public static function get_transient_key ( $transient ) {
    4779        return self::prefix( $transient ) . '_' . self::get_plugin_version();
  • shipping-simulator-for-woocommerce/trunk/core/VERSION

    r2791336 r3203635  
    1 1.6.1
     12.0.1
  • shipping-simulator-for-woocommerce/trunk/languages/wc-shipping-simulator-pt_BR.po

    r2970338 r3203635  
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/shipping-"
    77"simulator-for-woocommerce\n"
    8 "POT-Creation-Date: 2023-09-22T14:38:15-03:00\n"
    9 "PO-Revision-Date: 2023-09-22 14:39-0300\n"
     8"POT-Creation-Date: 2024-12-06T12:51:41+00:00\n"
     9"PO-Revision-Date: 2024-12-06 09:52-0300\n"
    1010"Last-Translator: \n"
    1111"Language-Team: \n"
     
    1515"Content-Transfer-Encoding: 8bit\n"
    1616"Plural-Forms: nplurals=2; plural=(n > 1);\n"
    17 "X-Generator: Poedit 3.0.1\n"
     17"X-Generator: Poedit 3.4.4\n"
    1818"X-Domain: wc-shipping-simulator\n"
    1919
     
    271271"conflito."
    272272
    273 #: classes/Request.php:165
     273#: classes/Request.php:161
    274274msgid "The postcode is required."
    275275msgstr "O CEP é obrigatório."
    276276
    277 #: classes/Request.php:170
     277#: classes/Request.php:166
    278278msgid "Invalid product."
    279279msgstr "Produto inválido."
    280280
    281 #: classes/Request.php:174
     281#: classes/Request.php:170
    282282msgid "The quantity must be greater than zero."
    283283msgstr "A quantidade deve ser maior que zero."
     
    304304
    305305#. translators: %s is replaced with plugin name
    306 #: core/Dependencies.php:120
     306#: core/Dependencies.php:146
    307307msgid "The %s plugin needs the following dependencies to work:"
    308308msgstr "O plugin %s requer as seguintes dependências para funcionar:"
    309309
    310 #: core/Dependencies.php:125
     310#: core/Dependencies.php:151
    311311msgid "Missing"
    312312msgstr "Faltando"
     
    326326msgstr "Locais de entrega"
    327327
    328 #. translators: the %s are PHP versions
    329 #: main.php:41
    330 msgid ""
    331 "This plugin requires PHP version %s or later (your server PHP version is %s)"
    332 msgstr ""
    333 "Este plugin requer PHP na versão %s ou superior (o PHP do seu servidor é %s)"
    334 
    335 #. translators: %1$s is replaced with plugin name and %2$s with an error message
    336 #: main.php:59
    337 msgid "Error on %1$s plugin activation: %2$s"
    338 msgstr "Erro na ativação do plugin %1$s: %2$s"
    339 
    340328#. translators: %1$s is replaced with plugin name and %2$s with 5 stars
    341329#: templates/notice-donation.php:7
     
    358346msgid "Avaliable shipping options"
    359347msgstr "Opções de frete disponíveis"
     348
     349#~ msgid ""
     350#~ "This plugin requires PHP version %s or later (your server PHP version is "
     351#~ "%s)"
     352#~ msgstr ""
     353#~ "Este plugin requer PHP na versão %s ou superior (o PHP do seu servidor é "
     354#~ "%s)"
     355
     356#~ msgid "Error on %1$s plugin activation: %2$s"
     357#~ msgstr "Erro na ativação do plugin %1$s: %2$s"
    360358
    361359#~ msgid ""
  • shipping-simulator-for-woocommerce/trunk/languages/wc-shipping-simulator.pot

    r2970338 r3203635  
    1 # Copyright (C) 2023 Luiz Bills
     1# Copyright (C) 2024 Luiz Bills
    22# This file is distributed under the GPLv3.
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Shipping Simulator for WooCommerce 2.3.1\n"
     5"Project-Id-Version: Shipping Simulator for WooCommerce 2.3.5\n"
    66"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/shipping-simulator-for-woocommerce\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-09-22T14:38:15-03:00\n"
     12"POT-Creation-Date: 2024-12-06T12:51:41+00:00\n"
    1313"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1414"X-Generator: WP-CLI 2.6.0\n"
     
    235235msgstr ""
    236236
    237 #: classes/Request.php:165
     237#: classes/Request.php:161
    238238msgid "The postcode is required."
    239239msgstr ""
    240240
     241#: classes/Request.php:166
     242msgid "Invalid product."
     243msgstr ""
     244
    241245#: classes/Request.php:170
    242 msgid "Invalid product."
    243 msgstr ""
    244 
    245 #: classes/Request.php:174
    246246msgid "The quantity must be greater than zero."
    247247msgstr ""
     
    268268
    269269#. translators: %s is replaced with plugin name
    270 #: core/Dependencies.php:120
     270#: core/Dependencies.php:146
    271271msgid "The %s plugin needs the following dependencies to work:"
    272272msgstr ""
    273273
    274 #: core/Dependencies.php:125
     274#: core/Dependencies.php:151
    275275msgid "Missing"
    276276msgstr ""
     
    290290msgstr ""
    291291
    292 #. translators: the %s are PHP versions
    293 #: main.php:41
    294 msgid "This plugin requires PHP version %s or later (your server PHP version is %s)"
    295 msgstr ""
    296 
    297 #. translators: %1$s is replaced with plugin name and %2$s with an error message
    298 #: main.php:59
    299 msgid "Error on %1$s plugin activation: %2$s"
    300 msgstr ""
    301 
    302292#. translators: %1$s is replaced with plugin name and %2$s with 5 stars
    303293#: templates/notice-donation.php:7
  • shipping-simulator-for-woocommerce/trunk/main.php

    r3141723 r3203635  
    44Plugin URI: https://github.com/luizbills/shipping-simulator-for-woocommerce
    55Description: Allows your customers to calculate the shipping rates on the product page
    6 Version: 2.3.4
     6Version: 2.3.5
    77Requires at least: 4.9
    88Requires PHP: 7.4
     
    2828
    2929// prevents your PHP files from being executed via direct browser access
    30 defined( 'WPINC' ) || exit( 1 );
     30defined( 'ABSPATH' ) || exit( 1 );
    3131
    32 load_plugin_textdomain( 'wc-shipping-simulator', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     32$autoload = __DIR__ . '/vendor/autoload.php';
     33if ( file_exists( $autoload ) ) {
     34    // composer autoload
     35    include $autoload;
     36    // start the plugin
     37    \Shipping_Simulator\Core\Main::start_plugin( __FILE__ );
     38} else {
     39    // display a error
     40    return add_action( 'admin_notices', function () {
     41        // error visible only for admin users
     42        if ( ! current_user_can( 'install_plugins' ) ) return;
    3343
    34 try {
    35     // Check PHP Version
    36     $php_expected = '7.4';
    37     $php_current = PHP_VERSION;
    38     if ( version_compare( $php_current, $php_expected, '<' ) ) {
    39         throw new Error(
    40             sprintf(
    41                 // translators: the %s are PHP versions
    42                 esc_html__( "This plugin requires PHP version %s or later (your server PHP version is %s)", 'wc-shipping-simulator' ),
    43                 $php_expected, esc_html( $php_current )
    44             )
     44        include_once ABSPATH . '/wp-includes/functions.php';
     45        list( $plugin_name ) = get_file_data( __FILE__, [ 'plugin name' ] );
     46
     47        $message = sprintf(
     48            'Error on %1$s plugin activation: %2$s',
     49            '<strong>' . esc_html( $plugin_name ) . '</strong>',
     50            '<code>Autoload file not found</code><br><em>Download this plugin from WordPress repository and avoid downloading from other sources (Github, etc).</em>'
    4551        );
    46     }
    4752
    48     // check composer autoload
    49     $composer_autoload = __DIR__ . '/vendor/autoload.php';
    50     if ( ! file_exists( $composer_autoload ) ) {
    51         throw new Error( $composer_autoload . ' does not exist' );
    52     }
    53     include_once $composer_autoload;
    54 } catch ( Throwable $e ) {
    55     return add_action( 'admin_notices', function () use ( $e ) {
    56         if ( ! current_user_can( 'install_plugins' ) ) return;
    57         list( $plugin_name ) = get_file_data( __FILE__, [ 'plugin name' ] );
    58         $message = sprintf(
    59             /* translators: %1$s is replaced with plugin name and %2$s with an error message */
    60             esc_html__( 'Error on %1$s plugin activation: %2$s', 'wc-shipping-simulator' ),
    61             '<strong>' . esc_html( $plugin_name ) . '</strong>',
    62             '<br><code>' . esc_html( $e->getMessage() ) . '</code>'
    63         );
    6453        echo "<div class='notice notice-error'><p>$message</p></div>";
    6554    } );
    6655}
    67 
    68 // run the plugin
    69 \Shipping_Simulator\Core\Main::start_plugin( __FILE__ );
  • shipping-simulator-for-woocommerce/trunk/readme.txt

    r3141733 r3203635  
    22Contributors: luizbills
    33Donate link: https://luizpb.com/donate/
    4 Tags: woocommerce, shipping simulator, simulador de frete, brazil, calculadora de frete
    5 Stable tag: 2.3.4
     4Tags: woocommerce, shipping simulator, simulador de frete, brazil, brasil, calculadora de frete, shipping calculator, product
     5Stable tag: 2.3.5
    66Requires at least: 4.9
    77Requires PHP: 7.4
    8 Tested up to: 6.6
     8Tested up to: 6.7
    99License: GPLv3
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    5151== Changelog ==
    5252
     53= v2.3.5 =
     54
     55-   Tested up to WordPress 6.7
     56-   Minor fixes.
     57
    5358= v2.3.4 =
    5459
  • shipping-simulator-for-woocommerce/trunk/templates/shipping-simulator-results.php

    r2969410 r3203635  
    2424
    2525    <?php do_action( 'wc_shipping_simulator_results_after', $data ) ?>
    26 <?php elseif ( $notice ) : ?>
    27     <div class="no-results"><?php echo h::safe_html( $notice ) ?></div>
     26<?php else : ?>
     27    <?php do_action( 'wc_shipping_simulator_no_results_before', $data ) ?>
     28
     29    <?php if ( $notice ) : ?>
     30        <div class="no-results"><?php echo h::safe_html( $notice ) ?></div>
     31    <?php endif; ?>
     32
     33    <?php do_action( 'wc_shipping_simulator_no_results_after', $data ) ?>
    2834<?php endif ?>
  • shipping-simulator-for-woocommerce/trunk/vendor/autoload.php

    r3141733 r3203635  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInitbb28a3cf58e65d22cd7027e39468ca0a::getLoader();
     25return ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662::getLoader();
  • shipping-simulator-for-woocommerce/trunk/vendor/composer/autoload_classmap.php

    r2968891 r3203635  
    1818    'Shipping_Simulator\\Core\\Traits\\Config_Helpers' => $baseDir . '/core/Traits/Config_Helpers.php',
    1919    'Shipping_Simulator\\Core\\Traits\\Debug_Helpers' => $baseDir . '/core/Traits/Debug_Helpers.php',
     20    'Shipping_Simulator\\Core\\Traits\\Log_Helpers' => $baseDir . '/core/Traits/Log_Helpers.php',
    2021    'Shipping_Simulator\\Core\\Traits\\String_Helpers' => $baseDir . '/core/Traits/String_Helpers.php',
    2122    'Shipping_Simulator\\Core\\Traits\\Template_Helpers' => $baseDir . '/core/Traits/Template_Helpers.php',
  • shipping-simulator-for-woocommerce/trunk/vendor/composer/autoload_real.php

    r3141733 r3203635  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInitbb28a3cf58e65d22cd7027e39468ca0a
     5class ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInitbb28a3cf58e65d22cd7027e39468ca0a', 'loadClassLoader'), true, true);
     25        spl_autoload_register(array('ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662', 'loadClassLoader'), true, true);
    2626        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    27         spl_autoload_unregister(array('ComposerAutoloaderInitbb28a3cf58e65d22cd7027e39468ca0a', 'loadClassLoader'));
     27        spl_autoload_unregister(array('ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662', 'loadClassLoader'));
    2828
    2929        require __DIR__ . '/autoload_static.php';
    30         call_user_func(\Composer\Autoload\ComposerStaticInitbb28a3cf58e65d22cd7027e39468ca0a::getInitializer($loader));
     30        call_user_func(\Composer\Autoload\ComposerStaticInit934b111d6349565ac57cbee28bff5662::getInitializer($loader));
    3131
    3232        $loader->register(true);
  • shipping-simulator-for-woocommerce/trunk/vendor/composer/autoload_static.php

    r3141733 r3203635  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInitbb28a3cf58e65d22cd7027e39468ca0a
     7class ComposerStaticInit934b111d6349565ac57cbee28bff5662
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    3838        'Shipping_Simulator\\Core\\Traits\\Config_Helpers' => __DIR__ . '/../..' . '/core/Traits/Config_Helpers.php',
    3939        'Shipping_Simulator\\Core\\Traits\\Debug_Helpers' => __DIR__ . '/../..' . '/core/Traits/Debug_Helpers.php',
     40        'Shipping_Simulator\\Core\\Traits\\Log_Helpers' => __DIR__ . '/../..' . '/core/Traits/Log_Helpers.php',
    4041        'Shipping_Simulator\\Core\\Traits\\String_Helpers' => __DIR__ . '/../..' . '/core/Traits/String_Helpers.php',
    4142        'Shipping_Simulator\\Core\\Traits\\Template_Helpers' => __DIR__ . '/../..' . '/core/Traits/Template_Helpers.php',
     
    6162    {
    6263        return \Closure::bind(function () use ($loader) {
    63             $loader->prefixLengthsPsr4 = ComposerStaticInitbb28a3cf58e65d22cd7027e39468ca0a::$prefixLengthsPsr4;
    64             $loader->prefixDirsPsr4 = ComposerStaticInitbb28a3cf58e65d22cd7027e39468ca0a::$prefixDirsPsr4;
    65             $loader->classMap = ComposerStaticInitbb28a3cf58e65d22cd7027e39468ca0a::$classMap;
     64            $loader->prefixLengthsPsr4 = ComposerStaticInit934b111d6349565ac57cbee28bff5662::$prefixLengthsPsr4;
     65            $loader->prefixDirsPsr4 = ComposerStaticInit934b111d6349565ac57cbee28bff5662::$prefixDirsPsr4;
     66            $loader->classMap = ComposerStaticInit934b111d6349565ac57cbee28bff5662::$classMap;
    6667
    6768        }, null, ClassLoader::class);
  • shipping-simulator-for-woocommerce/trunk/vendor/composer/installed.php

    r3141733 r3203635  
    44        'pretty_version' => 'dev-main',
    55        'version' => 'dev-main',
    6         'reference' => '62cbe378d96c0a699f43cd7a9464cad56a5b161c',
     6        'reference' => '68526d3f9cf08e650b3668ac1e1de26c25250bbd',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1414            'pretty_version' => 'dev-main',
    1515            'version' => 'dev-main',
    16             'reference' => '62cbe378d96c0a699f43cd7a9464cad56a5b161c',
     16            'reference' => '68526d3f9cf08e650b3668ac1e1de26c25250bbd',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.