Changeset 2364606
- Timestamp:
- 08/19/2020 07:17:12 AM (6 years ago)
- Location:
- woo-license-keys/trunk
- Files:
-
- 8 edited
-
README.txt (modified) (2 diffs)
-
app/Config/app.php (modified) (1 diff)
-
app/Controllers/ValidatorController.php (modified) (6 diffs)
-
app/Lib/functions.php (modified) (4 diffs)
-
app/Main.php (modified) (2 diffs)
-
app/Validators/ApiValidator.php (modified) (5 diffs)
-
plugin.php (modified) (2 diffs)
-
vendor/composer/installed.json (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
woo-license-keys/trunk/README.txt
r2362708 r2364606 7 7 Requires PHP: 5.4 8 8 Tested up to: 5.5 9 Stable tag: 1.5. 09 Stable tag: 1.5.1 10 10 License: GPLv3 11 11 License URI: https://www.gnu.org/licenses/gpl-3.0.html … … 86 86 == Changelog == 87 87 88 = 1.5.1 = 89 *Release Date - 19 Aug 2020* 90 * Activation, validation and deactivation are now available within WP through global functions. 91 * Tested with WooCommerce 4.4. 92 * Minor refactoring. 93 * Added hooks. 94 88 95 = 1.5.0 = 89 96 *Release Date - 17 Aug 2020* -
woo-license-keys/trunk/app/Config/app.php
r2362708 r2364606 19 19 ], 20 20 21 'version' => '1.5. 0',21 'version' => '1.5.1', 22 22 23 23 'author' => '10 Quality Studio <https://www.10quality.com/>', -
woo-license-keys/trunk/app/Controllers/ValidatorController.php
r2362708 r2364606 11 11 use LicenseKeys\Core\ValidationException; 12 12 use LicenseKeys\Validators\ApiValidator; 13 use LicenseKeys\Models\LicenseKey; 13 14 /** 14 15 * API Validator controller. … … 19 20 * @license GPLv3 20 21 * @package woo-license-keys 21 * @version 1.5. 022 * @version 1.5.1 22 23 */ 23 24 class ValidatorController extends Controller … … 50 51 // Prepare validations 51 52 $validation_args = apply_filters( 'woocommerce_license_keys_validation_args', [ 52 'error_format' => get_option( 'license_keys_response_errors_format', 'property' ),53 ] );53 'error_format' => get_option( 'license_keys_response_errors_format', 'property' ), 54 ], $request ); 54 55 // Validator 55 56 $this->validator->activate( $request, $response, $validation_args ); … … 140 141 // Prepare validations 141 142 $validation_args = apply_filters( 'woocommerce_license_keys_validation_args', [ 142 'error_format' => get_option( 'license_keys_response_errors_format', 'property' ),143 ] );143 'error_format' => get_option( 'license_keys_response_errors_format', 'property' ), 144 ], $request ); 144 145 // Validator 145 146 $this->validator->validate( $request, $response, $validation_args ); … … 205 206 // Prepare validations 206 207 $validation_args = apply_filters( 'woocommerce_license_keys_validation_args', [ 207 'error_format' => get_option( 'license_keys_response_errors_format', 'property' ),208 ] );208 'error_format' => get_option( 'license_keys_response_errors_format', 'property' ), 209 ], $request ); 209 210 // Validator 210 211 $this->validator->deactivate( $request, $response, $validation_args ); … … 346 347 } 347 348 /** 349 * Returns arguments passed by through validator functions, 350 * (wc_license_key_activate, wc_license_key_validate, wc_license_key_deactivate). 351 * @since 1.5.1 352 * 353 * @hook woocommerce_license_keys_validator_via_function_args 354 * 355 * @throws \Exception 356 * 357 * @param array|\LicenseKeys\Models\LicenseKey $args Validation arguments. 358 * @param int $activation_id Expected if a model is passed as argument. 359 * 360 * @return array 361 */ 362 public function via_function_args( $args, $activation_id = null, $requires_activation = false ) 363 { 364 // Validations 365 if ( is_object( $args ) && !$args instanceof LicenseKey ) 366 throw new Exception( 'Parameter must be a valid License Key model.' ); 367 if ( is_object( $args ) 368 && $args instanceof LicenseKey 369 && $requires_activation 370 && empty( $activation_id ) 371 ) 372 throw new Exception( 'Activation ID is expected as the second parameter.' ); 373 // Build arguments 374 if ( is_object( $args ) ) { 375 $args = ['key_code' => $args->the_key ]; 376 if ( $requires_activation ) 377 $args['activation_id'] = $activation_id; 378 } 379 if ( array_key_exists( 'license_key', $args ) ) { 380 $args['key_code'] = $args['license_key']; 381 unset( $args['license_key'] ); 382 } 383 if ( array_key_exists( 'code', $args ) ) { 384 $args['key_code'] = $args['code']; 385 unset( $args['code'] ); 386 } 387 $args['store_code'] = get_option( 'woocommerce_store_code' ); 388 $args['_via'] = 'functions'; 389 return $args; 390 } 391 /** 392 * Returns validation arguments. 393 * Checks if request was generated via functions to force "property" error format. 394 * @since 1.5.1 395 * 396 * @hook woocommerce_license_keys_validation_args 397 * 398 * @param array $args 399 * @param array $request 400 * 401 * @return array 402 */ 403 public function validation_args( $args, $request ) 404 { 405 if ( array_key_exists( '_via', $request ) && $request['_via'] === 'functions' ) 406 $args['error_format'] = 'property'; 407 return $args; 408 } 409 /** 348 410 * Sets API validator to use. 349 411 * @since 1.5.0 -
woo-license-keys/trunk/app/Lib/functions.php
r2274899 r2364606 10 10 * @license GPLv3 11 11 * @package woo-license-keys 12 * @version 1. 4.012 * @version 1.5.1 13 13 */ 14 14 … … 76 76 function wc_get_license_key( $code ) 77 77 { 78 _deprecated_function( __FUNCTION__, '1.5.0', 'wc_find_license_key()' ); 78 79 return wc_find_license_key( $code ); 79 80 } … … 85 86 * @since 1.3.0 86 87 * 87 * @param array $args88 * @param string|array $args 88 89 * 89 90 * @return \LicenseKeys\Models\LicenseKey … … 177 178 } 178 179 } 180 181 if ( !function_exists( 'wc_license_key_activate' ) ) { 182 /** 183 * Activates (adds an activation) to a license key. 184 * @since 1.5.1 185 * 186 * @param array|\LicenseKeys\Models\LicenseKey $args Activation arguments. 187 * 188 * @return \WPMVC\Response Response from validator. 189 */ 190 function wc_license_key_activate( $args ) 191 { 192 return WC_LK()->{'_c_return_ValidatorController@activate'}( 193 apply_filters( 'woocommerce_license_keys_validator_via_function_args', $args ) 194 ); 195 } 196 } 197 198 if ( !function_exists( 'wc_license_key_validate' ) ) { 199 /** 200 * Validates a license key activation. 201 * @since 1.5.1 202 * 203 * @param array|\LicenseKeys\Models\LicenseKey $args Validation arguments. 204 * @param int $activation_id Expected if a model is passed as argument. 205 * 206 * @return \WPMVC\Response Response from validator. 207 */ 208 function wc_license_key_validate( $args, $activation_id = null ) 209 { 210 return WC_LK()->{'_c_return_ValidatorController@validate'}( 211 apply_filters( 'woocommerce_license_keys_validator_via_function_args', $args, $activation_id, true ) 212 ); 213 } 214 } 215 216 if ( !function_exists( 'wc_license_key_deactivate' ) ) { 217 /** 218 * Deactivates a license key activation. 219 * @since 1.5.1 220 * 221 * @param array|\LicenseKeys\Models\LicenseKey $args Validation arguments. 222 * @param int $activation_id Expected if a model is passed as argument. 223 * 224 * @return \WPMVC\Response Response from validator. 225 */ 226 function wc_license_key_deactivate( $args, $activation_id = null ) 227 { 228 return WC_LK()->{'_c_return_ValidatorController@deactivate'}( 229 apply_filters( 'woocommerce_license_keys_validator_via_function_args', $args, $activation_id, true ) 230 ); 231 } 232 } -
woo-license-keys/trunk/app/Main.php
r2362708 r2364606 15 15 * @license GPLv3 16 16 * @package woo-license-keys 17 * @version 1.5. 017 * @version 1.5.1 18 18 */ 19 19 class Main extends Bridge … … 54 54 $this->add_filter( 'woocommerce_license_keys_enable_sku_validation', 'ValidatorController@enable_sku_validation', 1 ); 55 55 $this->add_filter( 'woocommerce_license_keys_enable_domain_validation', 'ValidatorController@enable_domain_validation', 1 ); 56 // API endpoints 56 // API endpoints and validator 57 57 $this->add_action( 'woocommerce_license_key_api_headers', 'ValidatorController@set_headers' ); 58 58 $this->add_filter( 'woocommerce_license_keys_activate_success_response', 'ValidatorController@success_response', 1, 2 ); 59 59 $this->add_filter( 'woocommerce_license_keys_validate_success_response', 'ValidatorController@success_response', 1, 2 ); 60 $this->add_filter( 'woocommerce_license_keys_validator_via_function_args', 'ValidatorController@via_function_args', 1, 3 ); 61 $this->add_filter( 'woocommerce_license_keys_validation_args', 'ValidatorController@validation_args', 1, 2 ); 60 62 // API Handler 61 63 $handler = get_option( 'license_keys_api_handler', 'wp_ajax' ); -
woo-license-keys/trunk/app/Validators/ApiValidator.php
r2362708 r2364606 14 14 * @license GPLv3 15 15 * @package woo-license-keys 16 * @version 1.5. 016 * @version 1.5.1 17 17 */ 18 18 class ApiValidator implements Validatable … … 137 137 public function is_valid( $validation, &$request, &$response, $args = [] ) 138 138 { 139 $is_code = isset( $args['error_format'] ) && $args['error_format'] === 'code';139 $is_code = $this->error_is_code( $args ); 140 140 switch ( $validation ) { 141 141 case 'store_code': … … 276 276 public function parse_license_key( &$request, &$response, $args = [] ) 277 277 { 278 $is_code = isset( $args['error_format'] ) && $args['error_format'] === 'code';278 $is_code = $this->error_is_code( $args ); 279 279 $key = apply_filters( 'woocommerce_license_keys_enable_parse_validation', true ) 280 280 ? explode( '-', $request['key_code'] ) … … 305 305 public function get_license_key( &$request, &$response, $args = [] ) 306 306 { 307 $is_code = isset( $args['error_format'] ) && $args['error_format'] === 'code';307 $is_code = $this->error_is_code( $args ); 308 308 $request['license_key'] = wc_find_license_key( $request ); 309 309 if ( $request['license_key'] === null ) { … … 313 313 return true; 314 314 } 315 /** 316 * Returns flag indicating if error format is code or field key. 317 * @since 1.5.1 318 * 319 * @param array &$args Validation arguments. 320 * 321 * @return bool 322 */ 323 protected function error_is_code( &$args ) 324 { 325 return isset( $args['error_format'] ) && $args['error_format'] === 'code'; 326 } 315 327 } -
woo-license-keys/trunk/plugin.php
r2362708 r2364606 4 4 Plugin URI: https://www.10quality.com/product/woocommerce-license-keys/ 5 5 Description: Enable and handle "License Keys" with WooCommerce. 6 Version: 1.5. 06 Version: 1.5.1 7 7 Author: 10 Quality 8 8 Author URI: https://www.10quality.com/ … … 12 12 13 13 WC requires at least: 3 14 WC tested up to: 4. 314 WC tested up to: 4.4 15 15 16 16 See "LICENSE" file. -
woo-license-keys/trunk/vendor/composer/installed.json
r2362481 r2364606 567 567 }, 568 568 { 569 "name": "nikic/php-parser",570 "version": "dev-master",571 "version_normalized": "9999999-dev",572 "source": {573 "type": "git",574 "url": "https://github.com/nikic/PHP-Parser.git",575 "reference": "f9d35fe11e58105dff933931344d6e6beb1406d8"576 },577 "dist": {578 "type": "zip",579 "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f9d35fe11e58105dff933931344d6e6beb1406d8",580 "reference": "f9d35fe11e58105dff933931344d6e6beb1406d8",581 "shasum": ""582 },583 "require": {584 "ext-tokenizer": "*",585 "php": ">=7.0"586 },587 "require-dev": {588 "ircmaxell/php-yacc": "^0.0.7",589 "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"590 },591 "time": "2020-08-10T09:21:16+00:00",592 "bin": [593 "bin/php-parse"594 ],595 "type": "library",596 "extra": {597 "branch-alias": {598 "dev-master": "4.8-dev"599 }600 },601 "installation-source": "source",602 "autoload": {603 "psr-4": {604 "PhpParser\\": "lib/PhpParser"605 }606 },607 "notification-url": "https://packagist.org/downloads/",608 "license": [609 "BSD-3-Clause"610 ],611 "authors": [612 {613 "name": "Nikita Popov"614 }615 ],616 "description": "A PHP parser written in PHP",617 "keywords": [618 "parser",619 "php"620 ]621 },622 {623 569 "name": "10quality/wpmvc-commands", 624 570 "version": "v1.1.11", … … 727 673 "wordpress" 728 674 ] 675 }, 676 { 677 "name": "nikic/php-parser", 678 "version": "dev-master", 679 "version_normalized": "9999999-dev", 680 "source": { 681 "type": "git", 682 "url": "https://github.com/nikic/PHP-Parser.git", 683 "reference": "aaee038b912e567780949787d5fe1977be11a778" 684 }, 685 "dist": { 686 "type": "zip", 687 "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/aaee038b912e567780949787d5fe1977be11a778", 688 "reference": "aaee038b912e567780949787d5fe1977be11a778", 689 "shasum": "" 690 }, 691 "require": { 692 "ext-tokenizer": "*", 693 "php": ">=7.0" 694 }, 695 "require-dev": { 696 "ircmaxell/php-yacc": "^0.0.7", 697 "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" 698 }, 699 "time": "2020-08-18T19:48:01+00:00", 700 "bin": [ 701 "bin/php-parse" 702 ], 703 "type": "library", 704 "extra": { 705 "branch-alias": { 706 "dev-master": "4.9-dev" 707 } 708 }, 709 "installation-source": "source", 710 "autoload": { 711 "psr-4": { 712 "PhpParser\\": "lib/PhpParser" 713 } 714 }, 715 "notification-url": "https://packagist.org/downloads/", 716 "license": [ 717 "BSD-3-Clause" 718 ], 719 "authors": [ 720 { 721 "name": "Nikita Popov" 722 } 723 ], 724 "description": "A PHP parser written in PHP", 725 "keywords": [ 726 "parser", 727 "php" 728 ] 729 729 } 730 730 ]
Note: See TracChangeset
for help on using the changeset viewer.