Plugin Directory

Changeset 2364606


Ignore:
Timestamp:
08/19/2020 07:17:12 AM (6 years ago)
Author:
10quality
Message:

Updating to version 1.5.1

Location:
woo-license-keys/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • woo-license-keys/trunk/README.txt

    r2362708 r2364606  
    77Requires PHP: 5.4
    88Tested up to: 5.5
    9 Stable tag: 1.5.0
     9Stable tag: 1.5.1
    1010License: GPLv3
    1111License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    8686== Changelog ==
    8787
     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
    8895= 1.5.0 =
    8996*Release Date - 17 Aug 2020*
  • woo-license-keys/trunk/app/Config/app.php

    r2362708 r2364606  
    1919    ],
    2020
    21     'version' => '1.5.0',
     21    'version' => '1.5.1',
    2222
    2323    'author' => '10 Quality Studio <https://www.10quality.com/>',
  • woo-license-keys/trunk/app/Controllers/ValidatorController.php

    r2362708 r2364606  
    1111use LicenseKeys\Core\ValidationException;
    1212use LicenseKeys\Validators\ApiValidator;
     13use LicenseKeys\Models\LicenseKey;
    1314/**
    1415 * API Validator controller.
     
    1920 * @license GPLv3
    2021 * @package woo-license-keys
    21  * @version 1.5.0
     22 * @version 1.5.1
    2223 */
    2324class ValidatorController extends Controller
     
    5051            // Prepare validations
    5152            $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 );
    5455            // Validator
    5556            $this->validator->activate( $request, $response, $validation_args );
     
    140141            // Prepare validations
    141142            $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 );
    144145            // Validator
    145146            $this->validator->validate( $request, $response, $validation_args );
     
    205206            // Prepare validations
    206207            $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 );
    209210            // Validator
    210211            $this->validator->deactivate( $request, $response, $validation_args );
     
    346347    }
    347348    /**
     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    /**
    348410     * Sets API validator to use.
    349411     * @since 1.5.0
  • woo-license-keys/trunk/app/Lib/functions.php

    r2274899 r2364606  
    1010 * @license GPLv3
    1111 * @package woo-license-keys
    12  * @version 1.4.0
     12 * @version 1.5.1
    1313 */
    1414
     
    7676    function wc_get_license_key( $code )
    7777    {
     78        _deprecated_function( __FUNCTION__, '1.5.0', 'wc_find_license_key()' );
    7879        return wc_find_license_key( $code );
    7980    }
     
    8586     * @since 1.3.0
    8687     *
    87      * @param array $args
     88     * @param string|array $args
    8889     *
    8990     * @return \LicenseKeys\Models\LicenseKey
     
    177178    }
    178179}
     180
     181if ( !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
     198if ( !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
     216if ( !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  
    1515 * @license GPLv3
    1616 * @package woo-license-keys
    17  * @version 1.5.0
     17 * @version 1.5.1
    1818 */
    1919class Main extends Bridge
     
    5454        $this->add_filter( 'woocommerce_license_keys_enable_sku_validation', 'ValidatorController@enable_sku_validation', 1 );
    5555        $this->add_filter( 'woocommerce_license_keys_enable_domain_validation', 'ValidatorController@enable_domain_validation', 1 );
    56         // API endpoints
     56        // API endpoints and validator
    5757        $this->add_action( 'woocommerce_license_key_api_headers', 'ValidatorController@set_headers' );
    5858        $this->add_filter( 'woocommerce_license_keys_activate_success_response', 'ValidatorController@success_response', 1, 2 );
    5959        $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 );
    6062        // API Handler
    6163        $handler = get_option( 'license_keys_api_handler', 'wp_ajax' );
  • woo-license-keys/trunk/app/Validators/ApiValidator.php

    r2362708 r2364606  
    1414 * @license GPLv3
    1515 * @package woo-license-keys
    16  * @version 1.5.0
     16 * @version 1.5.1
    1717 */
    1818class ApiValidator implements Validatable
     
    137137    public function is_valid( $validation, &$request, &$response, $args = [] )
    138138    {
    139         $is_code = isset( $args['error_format'] ) && $args['error_format'] === 'code';
     139        $is_code = $this->error_is_code( $args );
    140140        switch ( $validation ) {
    141141            case 'store_code':
     
    276276    public function parse_license_key( &$request, &$response, $args = [] )
    277277    {
    278         $is_code = isset( $args['error_format'] ) && $args['error_format'] === 'code';
     278        $is_code = $this->error_is_code( $args );
    279279        $key = apply_filters( 'woocommerce_license_keys_enable_parse_validation', true )
    280280            ? explode( '-', $request['key_code'] )
     
    305305    public function get_license_key( &$request, &$response, $args = [] )
    306306    {
    307         $is_code = isset( $args['error_format'] ) && $args['error_format'] === 'code';
     307        $is_code = $this->error_is_code( $args );
    308308        $request['license_key'] = wc_find_license_key( $request );
    309309        if ( $request['license_key'] === null ) {
     
    313313        return true;
    314314    }
     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    }
    315327}
  • woo-license-keys/trunk/plugin.php

    r2362708 r2364606  
    44Plugin URI: https://www.10quality.com/product/woocommerce-license-keys/
    55Description: Enable and handle "License Keys" with WooCommerce.
    6 Version: 1.5.0
     6Version: 1.5.1
    77Author: 10 Quality
    88Author URI: https://www.10quality.com/
     
    1212
    1313WC requires at least: 3
    14 WC tested up to: 4.3
     14WC tested up to: 4.4
    1515
    1616See "LICENSE" file.
  • woo-license-keys/trunk/vendor/composer/installed.json

    r2362481 r2364606  
    567567    },
    568568    {
    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     {
    623569        "name": "10quality/wpmvc-commands",
    624570        "version": "v1.1.11",
     
    727673            "wordpress"
    728674        ]
     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        ]
    729729    }
    730730]
Note: See TracChangeset for help on using the changeset viewer.