Changeset 3203635
- Timestamp:
- 12/06/2024 01:11:16 PM (3 months ago)
- Location:
- shipping-simulator-for-woocommerce
- Files:
-
- 83 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
shipping-simulator-for-woocommerce/trunk/CHANGELOG.md
r3141733 r3203635 2 2 3 3 All 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 4 11 5 12 ## 2.3.4 - 2024-08-26 -
shipping-simulator-for-woocommerce/trunk/classes/Request.php
r2912471 r3203635 108 108 109 109 $package = new Shipping_Package(); 110 111 /** @var Shipping_Package */ 110 112 $package = apply_filters( 'wc_shipping_simulator_request_update_package', $package, $this->data ); 111 113 … … 120 122 } 121 123 122 protected function get_results ( $rates , $notice = null) {124 protected function get_results ( $rates ) { 123 125 $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, 126 132 ]; 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 }137 133 return \apply_filters( 138 134 'wc_shipping_simulator_request_results_html', -
shipping-simulator-for-woocommerce/trunk/composer.json
r2912471 r3203635 1 1 { 2 2 "require": { 3 "php": ">=7.4", 3 4 "ext-mbstring": "*" 4 5 }, … … 7 8 "php-stubs/woocommerce-stubs": "^7.4", 8 9 "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"17 10 }, 18 11 "autoload": { … … 26 19 } 27 20 }, 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 }, 28 32 "wp-plugin-base": { 29 33 "namespace": "Shipping_Simulator", -
shipping-simulator-for-woocommerce/trunk/config.php
r2765398 r3203635 1 1 <?php 2 2 3 defined( ' WPINC' ) || exit( 1 );3 defined( 'ABSPATH' ) || exit( 1 ); 4 4 5 5 return [ 6 6 'SLUG' => 'wc-shipping-simulator', 7 7 'PREFIX' => 'wc_shipping_simulator_', 8 'LANGUAGES_DIR' => 'languages',9 8 'TEMPLATES_DIR' => 'templates', 10 9 'DONATION_URL' => 'https://luizpb.com/donate/', -
shipping-simulator-for-woocommerce/trunk/core/Config.php
r2791336 r3203635 3 3 namespace Shipping_Simulator\Core; 4 4 5 abstract class Config { 5 final class Config { 6 /** @var array */ 6 7 protected static $values = []; 7 8 9 /** 10 * @param string $main_file The file that contains the plugin headers 11 * @return void 12 * @throws \Exception 13 */ 8 14 public static function init ( $main_file ) { 9 15 if ( self::get_size() > 0 ) { 10 throw new \E rror( __CLASS__ . ' already initialized' );16 throw new \Exception( __CLASS__ . ' already initialized' ); 11 17 } 12 18 … … 15 21 16 22 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 ); 18 33 } 19 34 … … 28 43 $slug = isset( self::$values[ 'SLUG' ] ) ? self::$values[ 'SLUG' ] : false; 29 44 if ( ! $slug || ! is_string( $slug ) ) { 30 throw new \E rror( $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)' ); 31 46 } 32 47 33 48 $prefix = isset( self::$values[ 'PREFIX' ] ) ? self::$values[ 'PREFIX' ] : false; 34 49 if ( ! $prefix || ! is_string( $prefix ) ) { 35 throw new \E rror( $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)' ); 36 51 } 37 52 … … 41 56 $data = \get_file_data( $main_file, [ 'Plugin Name', 'Version' ] ); 42 57 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; 44 59 } 45 60 61 /** 62 * @param string $key 63 * @param mixed $value 64 * @return mixed The value 65 * @throws \Exception 66 */ 46 67 public static function set ( $key, $value ) { 47 68 $key = mb_strtoupper( $key ); 48 69 if ( isset( self::$values[ $key ] ) ) { 49 throw new \E rror( __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." ); 50 71 } 51 72 self::$values[ $key ] = $value; … … 53 74 } 54 75 76 /** 77 * @param string $key 78 * @param mixed $default 79 * @return mixed 80 * @throws \Exception 81 */ 55 82 public static function get ( $key, $default = null ) { 56 83 $key = \mb_strtoupper( $key ); 57 84 $value = isset( self::$values[ $key ] ) ? self::$values[ $key ] : $default; 58 85 if ( null === $value ) { 59 throw new \E rror( __METHOD__ . ": Undefined key $key" );86 throw new \Exception( __METHOD__ . ": Undefined key $key" ); 60 87 } 61 88 return $value; 62 89 } 63 90 91 /** 92 * @return int<0, max> 93 */ 64 94 public static function get_size () { 65 95 return count( self::$values ); 66 96 } 67 97 98 /** 99 * @param string $string 100 * @param string $sep 101 * @return string 102 */ 68 103 public static function sanitize_slug ( $string, $sep = '-' ) { 69 104 $slug = \strtolower( \remove_accents( $string ) ); // Convert to ASCII -
shipping-simulator-for-woocommerce/trunk/core/Dependencies.php
r2970338 r3203635 3 3 namespace Shipping_Simulator\Core; 4 4 5 abstract class Dependencies { 5 final class Dependencies { 6 /** @var array */ 6 7 protected static $dependencies; 8 9 /** @var bool */ 7 10 protected static $initialized = false; 8 11 12 /** 13 * @return void 14 * @throws \Exception 15 */ 9 16 public static function init () { 10 17 if ( self::$initialized ) { 11 throw new \E rror( __CLASS__ . ' already initialized' );18 throw new \Exception( __CLASS__ . ' already initialized' ); 12 19 } 13 20 … … 15 22 self::$dependencies = include_once $root . '/dependencies.php'; 16 23 if ( ! is_array( self::$dependencies ) ) { 17 throw new \E rror( $root . '/dependencies.php must return an Array' );24 throw new \Exception( $root . '/dependencies.php must return an Array' ); 18 25 } 19 26 … … 23 30 } 24 31 32 /** 33 * @return void 34 */ 25 35 public static function maybe_start_plugin () { 26 36 $result = self::check_dependencies(); … … 33 43 } 34 44 45 /** 46 * @return array{success: bool, messages: array<int, array{text: string, is_error: bool}>} 47 * @throws \Exception 48 */ 35 49 public static function check_dependencies () { 36 50 $result = [ … … 48 62 if ( ! is_string( $message ) || '' === trim( $message ) ) { 49 63 $id = is_integer( $key ) ? '#' . ( 1 + $key ) : $key; 50 throw new \E rror( "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." ); 51 65 } 52 66 … … 72 86 } 73 87 88 /** 89 * @param string $shortcut 90 * @return bool 91 * @throws \Exception 92 */ 74 93 protected static function handle_shortcut ( $shortcut ) { 75 94 $parts = explode( ':', $shortcut ); … … 77 96 $type = trim( $parts[0] ); 78 97 if ( ! $value || ! $type ) { 79 throw new \E rror( "Invalid shortcut syntax: $shortcut" );98 throw new \Exception( "Invalid shortcut syntax: $shortcut" ); 80 99 } 81 100 switch ( $type ) { … … 102 121 } 103 122 104 throw new \E rror( "Unexpected shortcut: $shortcut" );123 throw new \Exception( "Unexpected shortcut: $shortcut" ); 105 124 } 106 125 126 /** 127 * @param array<int, array{text:string, is_error:bool}> $messages 128 * @return void 129 */ 107 130 protected static function display_notice_missing_deps ( $messages ) { 108 131 if ( ! \is_admin() ) return; … … 110 133 if ( 0 === count( $messages ) ) return; 111 134 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 ); 115 141 116 142 \add_action( 'admin_notices', function () use ( $messages ) { -
shipping-simulator-for-woocommerce/trunk/core/Loader.php
r2791336 r3203635 3 3 namespace Shipping_Simulator\Core; 4 4 5 abstract class Loader { 5 final class Loader { 6 /** @var bool */ 6 7 protected static $initialized = false; 8 9 /** @var string */ 7 10 protected static $main_file; 8 11 12 /** 13 * @return void 14 * @throws \Exception 15 */ 9 16 public static function init () { 10 17 if ( self::$initialized ) { 11 throw new \E rror( __CLASS__ . ' already initialized' );18 throw new \Exception( __CLASS__ . ' already initialized' ); 12 19 } 13 20 … … 18 25 } 19 26 27 /** 28 * @return string 29 */ 20 30 public static function get_hook_start_plugin () { 21 31 return 'start_plugin_' . self::$main_file; 22 32 } 23 33 34 /** 35 * @return void 36 * @throws \Exception 37 */ 24 38 public static function load_classes () { 25 39 $root = Config::get( 'DIR' ); … … 27 41 28 42 if ( ! is_array( $loader ) ) { 29 throw new \E rror( $root . '/loader.php must return an Array' );43 throw new \Exception( $root . '/loader.php must return an Array' ); 30 44 } 31 45 … … 54 68 55 69 if ( is_string( $class_name ) && ! \class_exists( $class_name ) ) { 56 throw new \E rror( 'class ' . $class_name . ' does not exist' );70 throw new \Exception( 'class ' . $class_name . ' does not exist' ); 57 71 } 58 72 … … 76 90 77 91 if ( ! $loaded ) { 78 throw new \E rror( "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)" ); 79 93 } 80 94 } -
shipping-simulator-for-woocommerce/trunk/core/Main.php
r2791336 r3203635 3 3 namespace Shipping_Simulator\Core; 4 4 5 abstract class Main { 6 protected static $classes_to_load = []; 7 protected static $dependencies = []; 5 final class Main { 8 6 7 /** 8 * @param string $main_file The file that contains the plugin headers 9 * @return void 10 */ 9 11 public static function start_plugin ( $main_file ) { 10 12 if ( ! file_exists( $main_file ) ) { 11 throw new \E rror( 'Invalid plugin main file path in ' . __CLASS__ );13 throw new \Exception( 'Invalid plugin main file path in ' . __CLASS__ ); 12 14 } 13 15 … … 15 17 Loader::init(); 16 18 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 } 17 37 } 18 38 } -
shipping-simulator-for-woocommerce/trunk/core/Traits/Common_Helpers.php
r2791336 r3203635 3 3 namespace Shipping_Simulator\Core\Traits; 4 4 5 use Shipping_Simulator\Core\Traits\Log_Helpers; 5 6 use Shipping_Simulator\Core\Config; 6 7 7 8 trait 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; 11 23 } 12 24 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 */ 14 32 public static function get_defined ( $name, $default = null ) { 15 33 return defined( $name ) ? constant( $name ) : $default; 16 34 } 17 35 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 */ 20 43 public static function filled ( $var ) { 21 44 if ( null === $var ) return false; … … 26 49 } 27 50 28 // example: turns "Hello World" into "hello-world" 51 /** 52 * @param string $string 53 * @param string $sep 54 * @return string 55 */ 29 56 public static function sanitize_slug ( $string, $sep = '-' ) { 30 57 return Config::sanitize_slug( $string, $sep ); 31 58 } 32 59 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 */ 35 67 public static function prefix ( $appends = '' ) { 36 68 return Config::get( 'PREFIX' ) . $appends; -
shipping-simulator-for-woocommerce/trunk/core/Traits/Config_Helpers.php
r2791336 r3203635 6 6 7 7 trait Config_Helpers { 8 9 /** 10 * @param string $key 11 * @param mixed $default 12 * @return mixed 13 * @throws \Exception 14 */ 8 15 public static function config_get ( $key, $default = null ) { 9 16 return Config::get( $key, $default ); 10 17 } 11 18 19 /** 20 * @param string $key 21 * @param mixed $value 22 * @return mixed The value 23 * @throws \Exception 24 */ 12 25 public static function config_set ( $key, $value ) { 13 26 return Config::set( $key, $value ); -
shipping-simulator-for-woocommerce/trunk/core/Traits/Debug_Helpers.php
r2791336 r3203635 6 6 7 7 trait Debug_Helpers { 8 9 /** 10 * Dump and die 11 * 12 * @param mixed ...$values 13 * @return void|never 14 */ 8 15 public static function dd ( ...$values ) { 9 16 if ( ! WP_DEBUG ) return; … … 15 22 die; 16 23 } 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 }35 24 } -
shipping-simulator-for-woocommerce/trunk/core/Traits/String_Helpers.php
r2791336 r3203635 4 4 5 5 trait 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 ); 8 14 } 9 15 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 ); 12 23 } 13 24 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 ); 16 32 } 17 33 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 */ 18 48 public static function str_before ( $string, $search ) { 19 49 return '' === $search ? $string : \explode( $search, $string )[0]; 20 50 } 21 51 52 /** 53 * @param string $string 54 * @param string $search 55 * @return string 56 */ 22 57 public static function str_after ( $string, $search ) { 23 58 return '' === $search ? $string : \array_reverse( \explode( $search, $string, 2 ) )[0]; 24 59 } 25 60 61 /** 62 * @param string $string 63 * @param string $search 64 * @return bool 65 */ 26 66 public static function str_starts_with ( $string, $search ) { 27 67 return self::str_after( $string, $search ) !== $string; 28 68 } 29 69 70 /** 71 * @param string $string 72 * @param string $search 73 * @return bool 74 */ 30 75 public static function str_ends_with ( $string, $search ) { 31 76 return self::str_before( $string, $search ) !== $string; 32 77 } 33 78 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 */ 35 87 public static function str_mask ( $string, $mask, $symbol = 'X' ) { 36 88 $result = ''; 37 for ( $i = 0, $k = 0; $i < \strlen( $mask ); ++$i ) {89 for ( $i = 0, $k = 0; $i < self::str_length( $mask ); ++$i ) { 38 90 if ( $mask[ $i ] === $symbol ) { 39 91 if ( isset( $string[ $k ] ) ) $result .= $string[ $k++ ]; -
shipping-simulator-for-woocommerce/trunk/core/Traits/Template_Helpers.php
r2791336 r3203635 8 8 use Config_Helpers; 9 9 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 */ 11 16 public static function safe_html ( $html ) { 12 17 // remove all script and style tags with code … … 17 22 } 18 23 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 */ 20 32 public static function get_template ( $template_path, $args = [] ) { 21 33 $args = \apply_filters( self::prefix( 'get_template_args' ), $args, $template_path ); … … 28 40 $html = \ob_get_clean(); 29 41 } catch ( \Throwable $e ) { 42 self::log_critical( $e ); 30 43 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>'; 33 45 } else { 34 throw new \E rror( $e );46 throw new \Exception( $e ); 35 47 } 36 48 } … … 38 50 } 39 51 52 /** 53 * @param string $template_path 54 * @return string The template absolute path 55 */ 40 56 public static function get_template_path ( $template_path ) { 41 57 $template_path .= '.php' === substr( $template_path, -4 ) ? '' : '.php'; … … 44 60 } 45 61 62 /** 63 * @return string The directory that contains the plugin templates. 64 */ 46 65 public static function get_templates_dir () { 47 66 $templates = \trim( Config::get( 'TEMPLATES_DIR', 'templates' ), '/' ); -
shipping-simulator-for-woocommerce/trunk/core/Traits/Throw_Helpers.php
r2791336 r3203635 4 4 5 5 trait Throw_Helpers { 6 7 /** 8 * @return \Exception 9 */ 6 10 public static function get_error_class () { 7 return \E rror::class;11 return \Exception::class; 8 12 } 9 13 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 */ 10 23 public static function throw_if ( $condition, $message, $exception_class = null ) { 11 24 if ( $condition ) { … … 18 31 } 19 32 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 */ 20 42 public static function throw_wp_error ( $var, $code = null, $exception_class = null ) { 21 43 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 6 6 7 7 trait 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 */ 8 15 public static function plugin_url ( $path = '' ) { 9 // usage: `$script_url = h::plugin_url( 'assets/js/app.js' );`10 16 return \plugins_url( $path, Config::get( 'FILE' ) ); 11 17 } 12 18 19 /** 20 * @param boolean $raw 21 * @return string The plugin version 22 */ 13 23 public static function get_plugin_version ( $raw = false ) { 14 24 $version = Config::get( 'VERSION' ); … … 16 26 } 17 27 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 */ 18 38 public static function set_transient ( $transient, $value, $duration = 0 ) { 19 39 if ( is_callable( $value ) ) { 20 40 $value = \call_user_func( $value ); 21 41 } 22 if ( self::config_get( 'CACHE_ENABLED', true ) ) {42 if ( Config::get( 'CACHE_ENABLED', true ) ) { 23 43 $key = self::get_transient_key( $transient ); 24 44 if ( ! self::filled( $value ) ) { … … 38 58 } 39 59 60 /** 61 * @param string $transient 62 * @param mixed $default 63 * @return mixed 64 */ 40 65 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 } 43 71 return false !== $value ? $value : $default; 44 72 } 45 73 74 /** 75 * @param string $transient 76 * @return string 77 */ 46 78 public static function get_transient_key ( $transient ) { 47 79 return self::prefix( $transient ) . '_' . self::get_plugin_version(); -
shipping-simulator-for-woocommerce/trunk/core/VERSION
r2791336 r3203635 1 1.6.11 2.0.1 -
shipping-simulator-for-woocommerce/trunk/languages/wc-shipping-simulator-pt_BR.po
r2970338 r3203635 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/shipping-" 7 7 "simulator-for-woocommerce\n" 8 "POT-Creation-Date: 202 3-09-22T14:38:15-03:00\n"9 "PO-Revision-Date: 202 3-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" 10 10 "Last-Translator: \n" 11 11 "Language-Team: \n" … … 15 15 "Content-Transfer-Encoding: 8bit\n" 16 16 "Plural-Forms: nplurals=2; plural=(n > 1);\n" 17 "X-Generator: Poedit 3. 0.1\n"17 "X-Generator: Poedit 3.4.4\n" 18 18 "X-Domain: wc-shipping-simulator\n" 19 19 … … 271 271 "conflito." 272 272 273 #: classes/Request.php:16 5273 #: classes/Request.php:161 274 274 msgid "The postcode is required." 275 275 msgstr "O CEP é obrigatório." 276 276 277 #: classes/Request.php:1 70277 #: classes/Request.php:166 278 278 msgid "Invalid product." 279 279 msgstr "Produto inválido." 280 280 281 #: classes/Request.php:17 4281 #: classes/Request.php:170 282 282 msgid "The quantity must be greater than zero." 283 283 msgstr "A quantidade deve ser maior que zero." … … 304 304 305 305 #. translators: %s is replaced with plugin name 306 #: core/Dependencies.php:1 20306 #: core/Dependencies.php:146 307 307 msgid "The %s plugin needs the following dependencies to work:" 308 308 msgstr "O plugin %s requer as seguintes dependências para funcionar:" 309 309 310 #: core/Dependencies.php:1 25310 #: core/Dependencies.php:151 311 311 msgid "Missing" 312 312 msgstr "Faltando" … … 326 326 msgstr "Locais de entrega" 327 327 328 #. translators: the %s are PHP versions329 #: main.php:41330 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 message336 #: main.php:59337 msgid "Error on %1$s plugin activation: %2$s"338 msgstr "Erro na ativação do plugin %1$s: %2$s"339 340 328 #. translators: %1$s is replaced with plugin name and %2$s with 5 stars 341 329 #: templates/notice-donation.php:7 … … 358 346 msgid "Avaliable shipping options" 359 347 msgstr "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" 360 358 361 359 #~ msgid "" -
shipping-simulator-for-woocommerce/trunk/languages/wc-shipping-simulator.pot
r2970338 r3203635 1 # Copyright (C) 202 3Luiz Bills1 # Copyright (C) 2024 Luiz Bills 2 2 # This file is distributed under the GPLv3. 3 3 msgid "" 4 4 msgstr "" 5 "Project-Id-Version: Shipping Simulator for WooCommerce 2.3. 1\n"5 "Project-Id-Version: Shipping Simulator for WooCommerce 2.3.5\n" 6 6 "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/shipping-simulator-for-woocommerce\n" 7 7 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" … … 10 10 "Content-Type: text/plain; charset=UTF-8\n" 11 11 "Content-Transfer-Encoding: 8bit\n" 12 "POT-Creation-Date: 202 3-09-22T14:38:15-03:00\n"12 "POT-Creation-Date: 2024-12-06T12:51:41+00:00\n" 13 13 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 14 "X-Generator: WP-CLI 2.6.0\n" … … 235 235 msgstr "" 236 236 237 #: classes/Request.php:16 5237 #: classes/Request.php:161 238 238 msgid "The postcode is required." 239 239 msgstr "" 240 240 241 #: classes/Request.php:166 242 msgid "Invalid product." 243 msgstr "" 244 241 245 #: classes/Request.php:170 242 msgid "Invalid product."243 msgstr ""244 245 #: classes/Request.php:174246 246 msgid "The quantity must be greater than zero." 247 247 msgstr "" … … 268 268 269 269 #. translators: %s is replaced with plugin name 270 #: core/Dependencies.php:1 20270 #: core/Dependencies.php:146 271 271 msgid "The %s plugin needs the following dependencies to work:" 272 272 msgstr "" 273 273 274 #: core/Dependencies.php:1 25274 #: core/Dependencies.php:151 275 275 msgid "Missing" 276 276 msgstr "" … … 290 290 msgstr "" 291 291 292 #. translators: the %s are PHP versions293 #: main.php:41294 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 message298 #: main.php:59299 msgid "Error on %1$s plugin activation: %2$s"300 msgstr ""301 302 292 #. translators: %1$s is replaced with plugin name and %2$s with 5 stars 303 293 #: templates/notice-donation.php:7 -
shipping-simulator-for-woocommerce/trunk/main.php
r3141723 r3203635 4 4 Plugin URI: https://github.com/luizbills/shipping-simulator-for-woocommerce 5 5 Description: Allows your customers to calculate the shipping rates on the product page 6 Version: 2.3. 46 Version: 2.3.5 7 7 Requires at least: 4.9 8 8 Requires PHP: 7.4 … … 28 28 29 29 // prevents your PHP files from being executed via direct browser access 30 defined( ' WPINC' ) || exit( 1 );30 defined( 'ABSPATH' ) || exit( 1 ); 31 31 32 load_plugin_textdomain( 'wc-shipping-simulator', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 32 $autoload = __DIR__ . '/vendor/autoload.php'; 33 if ( 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; 33 43 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>' 45 51 ); 46 }47 52 48 // check composer autoload49 $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 );64 53 echo "<div class='notice notice-error'><p>$message</p></div>"; 65 54 } ); 66 55 } 67 68 // run the plugin69 \Shipping_Simulator\Core\Main::start_plugin( __FILE__ ); -
shipping-simulator-for-woocommerce/trunk/readme.txt
r3141733 r3203635 2 2 Contributors: luizbills 3 3 Donate link: https://luizpb.com/donate/ 4 Tags: woocommerce, shipping simulator, simulador de frete, brazil, calculadora de frete5 Stable tag: 2.3. 44 Tags: woocommerce, shipping simulator, simulador de frete, brazil, brasil, calculadora de frete, shipping calculator, product 5 Stable tag: 2.3.5 6 6 Requires at least: 4.9 7 7 Requires PHP: 7.4 8 Tested up to: 6. 68 Tested up to: 6.7 9 9 License: GPLv3 10 10 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 51 51 == Changelog == 52 52 53 = v2.3.5 = 54 55 - Tested up to WordPress 6.7 56 - Minor fixes. 57 53 58 = v2.3.4 = 54 59 -
shipping-simulator-for-woocommerce/trunk/templates/shipping-simulator-results.php
r2969410 r3203635 24 24 25 25 <?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 ) ?> 28 34 <?php endif ?> -
shipping-simulator-for-woocommerce/trunk/vendor/autoload.php
r3141733 r3203635 23 23 require_once __DIR__ . '/composer/autoload_real.php'; 24 24 25 return ComposerAutoloaderInit bb28a3cf58e65d22cd7027e39468ca0a::getLoader();25 return ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662::getLoader(); -
shipping-simulator-for-woocommerce/trunk/vendor/composer/autoload_classmap.php
r2968891 r3203635 18 18 'Shipping_Simulator\\Core\\Traits\\Config_Helpers' => $baseDir . '/core/Traits/Config_Helpers.php', 19 19 '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', 20 21 'Shipping_Simulator\\Core\\Traits\\String_Helpers' => $baseDir . '/core/Traits/String_Helpers.php', 21 22 'Shipping_Simulator\\Core\\Traits\\Template_Helpers' => $baseDir . '/core/Traits/Template_Helpers.php', -
shipping-simulator-for-woocommerce/trunk/vendor/composer/autoload_real.php
r3141733 r3203635 3 3 // autoload_real.php @generated by Composer 4 4 5 class ComposerAutoloaderInit bb28a3cf58e65d22cd7027e39468ca0a5 class ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662 6 6 { 7 7 private static $loader; … … 23 23 } 24 24 25 spl_autoload_register(array('ComposerAutoloaderInit bb28a3cf58e65d22cd7027e39468ca0a', 'loadClassLoader'), true, true);25 spl_autoload_register(array('ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662', 'loadClassLoader'), true, true); 26 26 self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); 27 spl_autoload_unregister(array('ComposerAutoloaderInit bb28a3cf58e65d22cd7027e39468ca0a', 'loadClassLoader'));27 spl_autoload_unregister(array('ComposerAutoloaderInit934b111d6349565ac57cbee28bff5662', 'loadClassLoader')); 28 28 29 29 require __DIR__ . '/autoload_static.php'; 30 call_user_func(\Composer\Autoload\ComposerStaticInit bb28a3cf58e65d22cd7027e39468ca0a::getInitializer($loader));30 call_user_func(\Composer\Autoload\ComposerStaticInit934b111d6349565ac57cbee28bff5662::getInitializer($loader)); 31 31 32 32 $loader->register(true); -
shipping-simulator-for-woocommerce/trunk/vendor/composer/autoload_static.php
r3141733 r3203635 5 5 namespace Composer\Autoload; 6 6 7 class ComposerStaticInit bb28a3cf58e65d22cd7027e39468ca0a7 class ComposerStaticInit934b111d6349565ac57cbee28bff5662 8 8 { 9 9 public static $prefixLengthsPsr4 = array ( … … 38 38 'Shipping_Simulator\\Core\\Traits\\Config_Helpers' => __DIR__ . '/../..' . '/core/Traits/Config_Helpers.php', 39 39 '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', 40 41 'Shipping_Simulator\\Core\\Traits\\String_Helpers' => __DIR__ . '/../..' . '/core/Traits/String_Helpers.php', 41 42 'Shipping_Simulator\\Core\\Traits\\Template_Helpers' => __DIR__ . '/../..' . '/core/Traits/Template_Helpers.php', … … 61 62 { 62 63 return \Closure::bind(function () use ($loader) { 63 $loader->prefixLengthsPsr4 = ComposerStaticInit bb28a3cf58e65d22cd7027e39468ca0a::$prefixLengthsPsr4;64 $loader->prefixDirsPsr4 = ComposerStaticInit bb28a3cf58e65d22cd7027e39468ca0a::$prefixDirsPsr4;65 $loader->classMap = ComposerStaticInit bb28a3cf58e65d22cd7027e39468ca0a::$classMap;64 $loader->prefixLengthsPsr4 = ComposerStaticInit934b111d6349565ac57cbee28bff5662::$prefixLengthsPsr4; 65 $loader->prefixDirsPsr4 = ComposerStaticInit934b111d6349565ac57cbee28bff5662::$prefixDirsPsr4; 66 $loader->classMap = ComposerStaticInit934b111d6349565ac57cbee28bff5662::$classMap; 66 67 67 68 }, null, ClassLoader::class); -
shipping-simulator-for-woocommerce/trunk/vendor/composer/installed.php
r3141733 r3203635 4 4 'pretty_version' => 'dev-main', 5 5 'version' => 'dev-main', 6 'reference' => '6 2cbe378d96c0a699f43cd7a9464cad56a5b161c',6 'reference' => '68526d3f9cf08e650b3668ac1e1de26c25250bbd', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 14 14 'pretty_version' => 'dev-main', 15 15 'version' => 'dev-main', 16 'reference' => '6 2cbe378d96c0a699f43cd7a9464cad56a5b161c',16 'reference' => '68526d3f9cf08e650b3668ac1e1de26c25250bbd', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.