diff --git a/assets/js/admin/admin.js b/assets/js/admin/admin.js index 9774d88..532de7b 100755 --- a/assets/js/admin/admin.js +++ b/assets/js/admin/admin.js @@ -554,55 +554,66 @@ jQuery(document).ready(function($){ return data; }); - // We're on the Subscriptions settings page - if($('#woocommerce_subscriptions_allow_switching').length > 0 ){ - var allowSwitching = $('#woocommerce_subscriptions_allow_switching').val(), - $switchSettingsRows = $('#woocommerce_subscriptions_allow_switching').parents('tr').siblings('tr'), - $syncProratationRow = $('#woocommerce_subscriptions_prorate_synced_payments').parents('tr'), - $suspensionExtensionRow = $('#woocommerce_subscriptions_recoup_suspension').parents('tr'); + var $allowSwitching = $( document.getElementById( 'woocommerce_subscriptions_allow_switching' ) ); + var $syncRenewals = $( document.getElementById( 'woocommerce_subscriptions_sync_payments' ) ); - if('no'==allowSwitching){ + // We're on the Subscriptions settings page + if ( $allowSwitching.length > 0 ) { + var allowSwitchingVal = $allowSwitching.val(), + $switchSettingsRows = $allowSwitching.parents( 'tr' ).siblings( 'tr' ), + $prorateFirstRenewal = $( document.getElementById( 'woocommerce_subscriptions_prorate_synced_payments' ) ), + $syncRows = $syncRenewals.parents( 'tr' ).siblings( 'tr' ), + $daysNoFeeRow = $( document.getElementById( 'woocommerce_subscriptions_days_no_fee' ) ).parents( 'tr' ), + $suspensionExtensionRow = $( '#woocommerce_subscriptions_recoup_suspension' ).parents( 'tr' ); + + // No animation for initial hiding when switching is disabled. + if ( 'no' === allowSwitchingVal ) { $switchSettingsRows.hide(); } - $( '#woocommerce_subscriptions_allow_switching' ).on( 'change', function() { - if ( 'no' == $( this ).val() ) { + $allowSwitching.on( 'change', function() { + if ( 'no' === $( this ).val() ) { $switchSettingsRows.fadeOut(); - } else if ( 'no' == allowSwitching ) { // switching was previously disable, so settings will be hidden + } else if ( 'no' === allowSwitchingVal ) { // switching was previously disabled, so settings will be hidden $switchSettingsRows.fadeIn(); } - allowSwitching = $( this ).val(); + allowSwitchingVal = $( this ).val(); } ); // Show/hide suspension extension setting - if ($('#woocommerce_subscriptions_max_customer_suspensions').val() > 0) { - $suspensionExtensionRow.show(); - } else { - $suspensionExtensionRow.hide(); - } - - $('#woocommerce_subscriptions_max_customer_suspensions').on('change', function(){ - if ($(this).val() > 0) { + $( '#woocommerce_subscriptions_max_customer_suspensions' ).on( 'change', function() { + if ( $( this ).val() > 0 ) { $suspensionExtensionRow.show(); } else { $suspensionExtensionRow.hide(); } - }); + } ).change(); - // Show/hide sync proration setting - if ($('#woocommerce_subscriptions_sync_payments').is(':checked')) { - $syncProratationRow.show(); - } else { - $syncProratationRow.hide(); + // No animation when initially hiding prorated rows. + if ( ! $syncRenewals.is( ':checked' ) ) { + $syncRows.hide(); + } else if ( 'recurring' !== $prorateFirstRenewal.val() ) { + $daysNoFeeRow.hide(); } - $('#woocommerce_subscriptions_sync_payments').on('change', function(){ - if ($(this).is(':checked')) { - $syncProratationRow.show(); + // Animate showing and hiding the synchronization rows. + $syncRenewals.on( 'change', function(){ + if ( $( this ).is( ':checked' ) ) { + $syncRows.not( $daysNoFeeRow ).fadeIn(); + $prorateFirstRenewal.change(); } else { - $syncProratationRow.hide(); + $syncRows.fadeOut(); } - }); + } ); + + // Watch the Prorate First Renewal field for changes. + $prorateFirstRenewal.on( 'change', function() { + if ( 'recurring' === $( this ).val() ) { + $daysNoFeeRow.fadeIn(); + } else { + $daysNoFeeRow.fadeOut(); + } + } ); } // Don't display the variation notice for variable subscription products @@ -666,4 +677,70 @@ jQuery(document).ready(function($){ $( '#general_product_data, #variable_product_options' ).on( 'change', '[class^="wc_input_subscription_payment_sync"], [class^="wc_input_subscription_trial_length"]', function() { $.disableEnableOneTimeShipping(); }); + + /** + * Prevents removal of variations in use by a subscription. + */ + var wcs_prevent_variation_removal = { + init: function() { + if ( 0 === $( '#woocommerce-product-data' ).length ) { + return; + } + + $( 'body' ).on( 'woocommerce-product-type-change', this.product_type_change ); + $( '#variable_product_options' ).on( 'reload', this.product_type_change ); + $( 'select.variation_actions' ).on( 'delete_all_no_subscriptions_ajax_data', this.bulk_action_data ); + this.product_type_change(); + }, + + product_type_change: function() { + var product_type = $( '#product-type' ).val(); + var $variation_actions = $( 'select.variation_actions' ); + var $delete_all = $variation_actions.find( 'option[value="delete_all"], option[value="delete_all_no_subscriptions"]' ); + + if ( 'variable-subscription' === product_type && 'delete_all' === $delete_all.val() ) { + $delete_all.data( 'wcs_original_wc_label', $delete_all.text() ) + .attr( 'value', 'delete_all_no_subscriptions' ) + .text( WCSubscriptions.bulkDeleteOptionLabel ); + } else if ( 'variable-subscription' !== product_type && 'delete_all_no_subscriptions' === $delete_all.val() ) { + $delete_all.text( $delete_all.data( 'wcs_original_wc_label' ) ) + .attr( 'value', 'delete_all' ); + } + }, + + bulk_action_data: function( event, data ) { + if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_delete_all_variations ) ) { + if ( window.confirm( woocommerce_admin_meta_boxes_variations.i18n_last_warning ) ) { + data.allowed = true; + + // do_variation_action() in woocommerce/assets/js/admin/meta-boxes-product-variation.js doesn't + // allow us to do anything after the AJAX request, so we need to listen to all AJAX requests for a + // little while to update the quantity and refresh the variation list. + $( document ).bind( 'ajaxComplete', wcs_prevent_variation_removal.update_qty_after_removal ); + } + } + + return data; + }, + + update_qty_after_removal: function( event, jqXHR, ajaxOptions ) { + var $variations = $( '#variable_product_options .woocommerce_variations' ); + var removed; + + // Not our bulk edit request. Ignore. + if ( -1 === ajaxOptions.data.indexOf( 'action=woocommerce_bulk_edit_variations' ) || -1 === ajaxOptions.data.indexOf( 'bulk_action=delete_all_no_subscriptions' ) ) { + return; + } + + // Unbind so this doesn't get called every time an AJAX request is performed. + $( document ).unbind( 'ajaxComplete', wcs_prevent_variation_removal.update_qty_after_removal ); + + // Update variation quantity. + removed = ( 'OK' === jqXHR.statusText ) ? parseInt( jqXHR.responseText, 10 ) : 0; + $variations.attr( 'data-total', Math.max( 0, parseInt( $variations.attr( 'data-total' ), 10 ) - removed ) ); + $( '#variable_product_options' ).trigger( 'reload' ); + }, + }; + wcs_prevent_variation_removal.init(); + }); diff --git a/assets/js/admin/meta-boxes-coupon.js b/assets/js/admin/meta-boxes-coupon.js new file mode 100755 index 0000000..85218f6 --- /dev/null +++ b/assets/js/admin/meta-boxes-coupon.js @@ -0,0 +1,53 @@ +jQuery( document ).ready( function( $ ) { + 'use strict'; + + var renewals_field = document.querySelector( '.wcs_number_payments_field' ), + $renewals_field = $( renewals_field ); + + /** + * Subscription coupon actions. + * @type {{init: function, type_options: function, move_field: function}} + */ + var wcs_meta_boxes_coupon_actions = { + + /** + * Initialize variation actions. + */ + init: function() { + if ( renewals_field ) { + $( document.getElementById( 'discount_type' ) ).on( 'change', this.type_options ).change(); + this.move_field(); + } + }, + + /** + * Show/hide fields by coupon type options. + */ + type_options: function() { + var select_val = $( this ).val(); + + switch ( select_val ) { + case 'recurring_fee': + case 'recurring_percent': + $renewals_field.show(); + break; + + default: + $renewals_field.hide(); + break; + } + }, + + /** + * Move the renewal form field in the DOM to a better location. + */ + move_field: function() { + var parent = document.getElementById( 'general_coupon_data' ), + shipping = parent.querySelector( '.free_shipping_field' ); + + parent.insertBefore( renewals_field, shipping ); + } + }; + + wcs_meta_boxes_coupon_actions.init(); +} ); diff --git a/assets/js/admin/meta-boxes-subscription.js b/assets/js/admin/meta-boxes-subscription.js index dfca49e..871a3bd 100755 --- a/assets/js/admin/meta-boxes-subscription.js +++ b/assets/js/admin/meta-boxes-subscription.js @@ -168,6 +168,60 @@ jQuery(document).ready(function($){ function zeroise( val ) { return (val > 9 ) ? val : '0' + val; } + + if( $( '#parent-order-id' ).is( 'select' ) ) { + wcs_update_parent_order_options(); + + $( '#customer_user' ).on( 'change', wcs_update_parent_order_options ); + } + + function wcs_update_parent_order_options() { + + // Get user ID to load orders for + var user_id = $( '#customer_user' ).val(); + + if ( ! user_id ) { + return false; + } + + var data = { + user_id: user_id, + action: 'wcs_get_customer_orders', + security: wcs_admin_meta_boxes.get_customer_orders_nonce + }; + + $( '#parent-order-id' ).siblings( '.select2-container' ).block({ + message: null, + overlayCSS: { + background: '#fff', + opacity: 0.6 + } + }); + + $.ajax({ + url: WCSubscriptions.ajaxUrl, + data: data, + type: 'POST', + success: function( response ) { + if ( response ) { + var $orderlist = $( '#parent-order-id' ); + + $( '#parent-order-id' ).select2( 'val', '' ); + + $orderlist.empty(); // remove old options + + $orderlist.append( $( '' ).attr( 'value', '' ).text( 'Select an order' ) ); + + $.each( response, function( order_id, order_number ) { + $orderlist.append( $( '' ).attr( 'value', order_id ).text( order_number ) ); + }); + + $( '#parent-order-id' ).siblings( '.select2-container' ).unblock(); + } + } + }); + return false; + }; $('body.post-type-shop_subscription #post').submit(function(){ if('wcs_process_renewal' == $( "body.post-type-shop_subscription select[name='wc_order_action']" ).val()) { diff --git a/assets/js/frontend/wcs-cart.js b/assets/js/frontend/wcs-cart.js new file mode 100755 index 0000000..89b8a11 --- /dev/null +++ b/assets/js/frontend/wcs-cart.js @@ -0,0 +1,17 @@ +function hide_non_applicable_coupons() { + var coupon_elements = document.getElementsByClassName( 'cart-discount' ); + + for ( var i = 0; i < coupon_elements.length; i++ ) { + if ( 0 !== coupon_elements[i].getElementsByClassName( 'wcs-hidden-coupon' ).length ) { + coupon_elements[i].style.display = 'none'; + } + } +} + +hide_non_applicable_coupons(); + +jQuery( document ).ready( function( $ ){ + $( document.body ).on( 'updated_cart_totals updated_checkout', function() { + hide_non_applicable_coupons(); + } ); +} ); diff --git a/changelog.txt b/changelog.txt index b2ce373..2f45175 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,65 @@ *** WooCommerce Subscriptions Changelog *** +2018.07.10 - version 2.3.2 +* Fix: Extend the next payment date after early renewal if there's no end date. PR#2804 +* Fix: Prevent throwing type hinting errors when getting related orders from cache. RR#2805 +* Tweak: Don't copying `_created_via` meta from subscriptions to related orders as this overrides the value set when the order was created. PR#2794 +* Tweak: Make `wcs_get_subscriptions_for_order()` the canonical function for retrieving subscriptions for a given order (regardless of type). PR#2805 + +2018.07.06 - version 2.3.1 +* Fix: Catchable fatal error from function parameter hinting. PR#2797 + +2018.07.04 - version 2.3.0 +* New: Allow store managers to link an order with a subscription using the parent order relationship via a UI on the admin edit subscription screen. PR#2272 +* New: Add an option to charge the full recurring amount at the time of sign up for synchronised subscription products. PR#2343 +* New: Add new coupon setting which store managers to use to create recurring coupons which apply for a certain number of payments. PR * New: Add new sections to the system status. PR#2493 +* New: Allow customers to renew subscriptions before their next payment date from their My Account Subscription page. PR#2544 +* New: Add persistent cache of related order IDs in subscription meta. Improves performance when obtaining subscription related orders. PR#2572 +* New: Add new sections to the system status. PR#2493 +* New: Add persistent cache of customer subscriptions. PR#2635 +* New: Add extra args ($order and $cart) to woocommerce_checkout_create_subscription filter. PR#2645 +* New: Update Action Scheduler to v2.0.0. +* New: Add a new admin upgrade notice helper class `WCS_Upgrade_Notice_Manager`. PR#2622 +* New: Add WCS_INIT_TIMESTAMP constant and use it to time background updates. PR#2739 +* New: Display an admin notice when a site is downgraded. PR#2743 +* Fix: Repair subscriptions which have been suspended in PayPal but not in WooCommerce. PR#2407 +* Fix: Make sure wcs_get_product_limitation() uses the parent product when determining variation product subscription limitations. PR#2513 +* Fix: Remove non-recurring fees from renewal carts. PR#2642 +* Fix: Don't autocomplete orders which have a subtotal greater than 0. PR#2665 +* Fix: [Reports] Exclude trashed subscriptions from all calculations. Fixes inconsistencies between some subscription counts. PR#2674 +* Fix: Check if the recurring_carts variable has been set before calling count() on it. PR#2688 +* Fix: Issues caused by a loophole where trashed or non grouped products remain a valid subscription product parent for switching. PR#2682 +* Fix: Check if there is no shipping method for a shipping zone before trying to access it when displaying cart HTML. PR#2701 +* Fix: Correctly calculate switching sign-up fee proration when switching between synced products. PR#2722 +* Fix: Indirect modification of WC_Checkout::$shipping_methods PHP errors. PR#2729 +* Fix: Only allow switching between products which are visible to the customer. PR#2727 +* Fix: [WC3.4] Only trigger the woocommerce_after_add_to_cart_button action hook once on variable subscription single product pages. PR#2750 +* Fix: [WC3.4] Fix missing endpoint settings. PR#2767 +* Fix: Remove unused chosen shipping methods for recurring packages. Fixes an issue where if the number of available shipping methods changes, the recurring carts hold onto their previously chosen method. PR#2782 +* Fix: Protect against possible errors when getting the subscriptions my account endpoint url. PR#2781 +* Tweak: Prevent bulk deletion of variations in use by at least one subscription. PR#2678 +* Tweak: Add better support for custom order types via `WC_Subscription::get_last_order()`. PR#2644 +* Tweak: Add `WCS_Admin_Post_Types::get_date_column_content()` helper function for displaying date content in post tables. PR#2643 +* Tweak: Change the Edit Subscription Schedule meta box titles. PR#2649 +* Tweak: Hide Recurring Coupons in the initial cart if they don't apply. PR#2616 +* Tweak: Add a filter to allow third-parties to filter orders by custom order types. PR#2667 +* Tweak: Don't schedule events for subscription start & last payment dates. PR#2669 +* Tweak: Add new `wcs_create_subscription` action. PR#2732 +* Tweak: Include variations in the "Subscriptions by product" reports. PR#2704 +* Tweak: Improve performance of getting a variable product's min and max variation data. PR#2723 +* Tweak: Add Subscription endpoints to the WC_Query endpoints. This allows our endpoints to be considered by functions like is_wc_endpoint_url() and also wc_body_class(). PR#2749 +* Tweak: Add an order note to renewal orders processed under staging site conditions. PR#2773 +* Tweak: Add a new badge to the subscriptions admin menu item when a site is operating as a staging site. PR#2773 +* Tweak: Add note to guest checkout setting, noting that an account is required when purchasing subscription products. PR#2751 +* Tweak: Deprecate the 'wcs_pre_get_users_subscriptions' filter. PR#2785 +* Tweak: Increase minimum required WC version to 2.6. PR#2786 +* Tweak: Remove TLC transient library and the cache manager which implemented it. PR#2614 +* Tweak: On site's already running WC 3.0 ensure all subscriptions have address indexes via a background repair script. PR#2605 +* Tweak: Require PHP 5.6 or newer. PR#2325 +* Tweak: Change 'created_via' order property for subscription orders. PR#2389 +* Tweak: Boost performance of admin subscription search by using billing and shipping indexes. PR#2409 +* Tweak: Add filter to control the automatic redirect behaviour of the Subscriptions menu item on My Account. PR#2633 + 2018.05.29 - version 2.2.21 * Tweak: Update WooCommerce tested up to compatibility flag. * Fix: [GDPR] While processing erasure requests anonymise all user subscriptions with any status. PR#2720 diff --git a/composer.lock b/composer.lock deleted file mode 100755 index 51054e4..0000000 --- a/composer.lock +++ /dev/null @@ -1,1252 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "content-hash": "021c140a843bd5b969f18f6e06902332", - "packages": [ - { - "name": "composer/installers", - "version": "v1.4.0", - "source": { - "type": "git", - "url": "https://github.com/composer/installers.git", - "reference": "9ce17fb70e9a38dd8acff0636a29f5cf4d575c1b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/composer/installers/zipball/9ce17fb70e9a38dd8acff0636a29f5cf4d575c1b", - "reference": "9ce17fb70e9a38dd8acff0636a29f5cf4d575c1b", - "shasum": "" - }, - "require": { - "composer-plugin-api": "^1.0" - }, - "replace": { - "roundcube/plugin-installer": "*", - "shama/baton": "*" - }, - "require-dev": { - "composer/composer": "1.0.*@dev", - "phpunit/phpunit": "4.1.*" - }, - "type": "composer-plugin", - "extra": { - "class": "Composer\\Installers\\Plugin", - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-4": { - "Composer\\Installers\\": "src/Composer/Installers" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Kyle Robinson Young", - "email": "kyle@dontkry.com", - "homepage": "https://github.com/shama" - } - ], - "description": "A multi-framework Composer library installer", - "homepage": "https://composer.github.io/installers/", - "keywords": [ - "Craft", - "Dolibarr", - "Eliasis", - "Hurad", - "ImageCMS", - "Kanboard", - "Lan Management System", - "MODX Evo", - "Mautic", - "Maya", - "OXID", - "Plentymarkets", - "Porto", - "RadPHP", - "SMF", - "Thelia", - "WolfCMS", - "agl", - "aimeos", - "annotatecms", - "attogram", - "bitrix", - "cakephp", - "chef", - "cockpit", - "codeigniter", - "concrete5", - "croogo", - "dokuwiki", - "drupal", - "eZ Platform", - "elgg", - "expressionengine", - "fuelphp", - "grav", - "installer", - "itop", - "joomla", - "kohana", - "laravel", - "lavalite", - "lithium", - "magento", - "mako", - "mediawiki", - "modulework", - "moodle", - "osclass", - "phpbb", - "piwik", - "ppi", - "puppet", - "reindex", - "roundcube", - "shopware", - "silverstripe", - "sydes", - "symfony", - "typo3", - "wordpress", - "yawik", - "zend", - "zikula" - ], - "time": "2017-08-09T07:53:48+00:00" - } - ], - "packages-dev": [ - { - "name": "doctrine/instantiator", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", - "shasum": "" - }, - "require": { - "php": ">=5.3,<8.0-DEV" - }, - "require-dev": { - "athletic/athletic": "~0.1.8", - "ext-pdo": "*", - "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2015-06-14T21:17:01+00:00" - }, - { - "name": "phpdocumentor/reflection-common", - "version": "1.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "reference": "144c307535e82c8fdcaacbcfc1d6d8eeb896687c", - "shasum": "" - }, - "require": { - "php": ">=5.5" - }, - "require-dev": { - "phpunit/phpunit": "^4.6" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jaap van Otterdijk", - "email": "opensource@ijaap.nl" - } - ], - "description": "Common reflection classes used by phpdocumentor to reflect the code structure", - "homepage": "http://www.phpdoc.org", - "keywords": [ - "FQSEN", - "phpDocumentor", - "phpdoc", - "reflection", - "static analysis" - ], - "time": "2015-12-27T11:43:31+00:00" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "3.2.2", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/4aada1f93c72c35e22fb1383b47fee43b8f1d157", - "reference": "4aada1f93c72c35e22fb1383b47fee43b8f1d157", - "shasum": "" - }, - "require": { - "php": ">=5.5", - "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.3.0", - "webmozart/assert": "^1.0" - }, - "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^4.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-08-08T06:39:58+00:00" - }, - { - "name": "phpdocumentor/type-resolver", - "version": "0.3.0", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773", - "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773", - "shasum": "" - }, - "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" - }, - "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "me@mikevanriel.com" - } - ], - "time": "2017-06-03T08:32:36+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "v1.7.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "93d39f1f7f9326d746203c7c056f300f7f126073" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/93d39f1f7f9326d746203c7c056f300f7f126073", - "reference": "93d39f1f7f9326d746203c7c056f300f7f126073", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": "^5.3|^7.0", - "phpdocumentor/reflection-docblock": "^2.0|^3.0.2", - "sebastian/comparator": "^1.1|^2.0", - "sebastian/recursion-context": "^1.0|^2.0|^3.0" - }, - "require-dev": { - "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8 || ^5.6.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6.x-dev" - } - }, - "autoload": { - "psr-0": { - "Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2017-03-02T20:05:34+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "2.2.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "^1.3.2", - "sebastian/version": "~1.0" - }, - "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2015-10-06T15:47:00+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "reference": "3cc8f69b3028d0f96a9078e6295d86e9bf019be5", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2016-10-03T07:40:28+00:00" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21T13:50:34+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.9", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2017-02-26T11:10:40+00:00" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.4.11", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/e03f8f67534427a787e21a385a67ec3ca6978ea7", - "reference": "e03f8f67534427a787e21a385a67ec3ca6978ea7", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2017-02-27T10:12:30+00:00" - }, - { - "name": "phpunit/phpunit", - "version": "4.8.36", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517", - "reference": "46023de9a91eec7dfb06cc56cb4e260017298517", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.2.2", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.8.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2017-06-21T08:07:12+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2015-10-02T06:51:40+00:00" - }, - { - "name": "sebastian/comparator", - "version": "1.2.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2017-01-29T09:50:25+00:00" - }, - { - "name": "sebastian/diff", - "version": "1.4.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "time": "2017-05-22T07:24:03+00:00" - }, - { - "name": "sebastian/environment", - "version": "1.3.8", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea", - "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2016-08-18T05:49:44+00:00" - }, - { - "name": "sebastian/exporter", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4", - "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" - }, - "require-dev": { - "ext-mbstring": "*", - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2016-06-17T09:04:28+00:00" - }, - { - "name": "sebastian/global-state", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "time": "2015-10-12T03:26:01+00:00" - }, - { - "name": "sebastian/recursion-context", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7", - "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2016-10-03T07:41:43+00:00" - }, - { - "name": "sebastian/version", - "version": "1.0.6", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "shasum": "" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21T13:59:46+00:00" - }, - { - "name": "symfony/yaml", - "version": "v3.3.6", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/ddc23324e6cfe066f3dd34a37ff494fa80b617ed", - "reference": "ddc23324e6cfe066f3dd34a37ff494fa80b617ed", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "require-dev": { - "symfony/console": "~2.8|~3.0" - }, - "suggest": { - "symfony/console": "For validating YAML files using the lint command" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2017-07-23T12:43:26+00:00" - }, - { - "name": "webmozart/assert", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/webmozart/assert.git", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/2db61e59ff05fe5126d152bd0655c9ea113e550f", - "reference": "2db61e59ff05fe5126d152bd0655c9ea113e550f", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "psr-4": { - "Webmozart\\Assert\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Assertions to validate method input/output with nice error messages.", - "keywords": [ - "assert", - "check", - "validate" - ], - "time": "2016-11-23T20:04:58+00:00" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/includes/abstracts/abstract-wcs-background-updater.php b/includes/abstracts/abstract-wcs-background-updater.php new file mode 100755 index 0000000..513cd7f --- /dev/null +++ b/includes/abstracts/abstract-wcs-background-updater.php @@ -0,0 +1,148 @@ + System Status > Tools administration screen. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Background_Updater Class + * + * Provide APIs for a debug tool to update data in the background using Action Scheduler. + */ +abstract class WCS_Background_Updater { + + /** + * @var int The amount of time, in seconds, to give the background process to run the update. + */ + protected $time_limit; + + /** + * @var string The hook used to schedule background updates. + */ + protected $scheduled_hook; + + /** + * Attach callbacks to hooks + */ + public function init() { + + // Make sure child classes have defined a scheduled hook, otherwise we can't do background updates. + if ( is_null( $this->scheduled_hook ) ) { + throw new RuntimeException( __CLASS__ . ' must assign a hook to $this->scheduled_hook' ); + } + + if ( is_null( $this->time_limit ) ) { + + $this->time_limit = 60; + + // Allow more time for CLI requests, as they're not beholden to script timeouts + if ( $this->is_wp_cli_request() ) { + $this->time_limit *= 3; + } + } + + // Allow for each class's time limit to be customised by 3rd party code, as well as all tools' time limits + $this->time_limit = apply_filters( 'wcs_debug_tools_time_limit', $this->time_limit, $this ); + + // Action scheduled in Action Scheduler for updating data in the background + add_action( $this->scheduled_hook, array( $this, 'run_update' ) ); + } + + /** + * Get the items to be updated, if any. + * + * @return array An array of items to update, or empty array if there are no items to update. + */ + abstract protected function get_items_to_update(); + + /** + * Run the update for a single item. + * + * @param mixed $item The item to update. + */ + abstract protected function update_item( $item ); + + /** + * Update a set of items in the background. + * + * This method will loop over until there are no more items to update, or the process has been running for the + * time limit set on the class @see $this->time_limit, which is 60 seconds by default (wall clock time, not + * execution time). + * + * The $scheduler_hook is rescheduled before updating any items something goes wrong when processing a batch - it's + * scheduled for $this->time_limit in future, so there's little chance of duplicate processes running at the same + * time with WP Cron, but importantly, there is some chance so it should not be used for critical data, like + * payments. Instead, it is intended for use for things like cache updates. It's also a good idea to use an atomic + * update methods to avoid updating something that has already been updated in a separate request. + * + * Importantly, the overlap between the next scheduled update and the current batch is also useful for running + * Action Scheduler via WP CLI, because it will allow for continuous execution of updates (i.e. updating a new + * batch as soon as one batch has execeeded the time limit rather than having to run Action Scheduler via WP CLI + * again later). + */ + public function run_update() { + + $this->schedule_background_update(); + + // If the update is being run via WP CLI, we don't need to worry about the request time, just the processing time for this method + $start_time = $this->is_wp_cli_request() ? gmdate( 'U' ) : WCS_INIT_TIMESTAMP; + + do { + + $items = $this->get_items_to_update(); + + foreach ( $items as $item ) { + + $this->update_item( $item ); + + $time_elapsed = ( gmdate( 'U' ) - $start_time ); + + if ( $time_elapsed >= $this->time_limit ) { + break 2; + } + } + } while ( ! empty( $items ) ); + + // If we stopped processing the batch because we ran out of items to process, not because we ran out of time, we don't need to run any other batches + if ( empty( $items ) ) { + $this->unschedule_background_updates(); + } + } + + /** + * Schedule the instance's hook to run in $this->time_limit seconds, if it's not already scheduled. + */ + protected function schedule_background_update() { + if ( false === wc_next_scheduled_action( $this->scheduled_hook ) ) { + wc_schedule_single_action( gmdate( 'U' ) + $this->time_limit, $this->scheduled_hook ); + } + } + + /** + * Unschedule the instance's hook in Action Scheduler + */ + protected function unschedule_background_updates() { + wc_unschedule_action( $this->scheduled_hook ); + } + + /** + * Check whether the current request is via WP CLI + * + * @return bool + */ + protected function is_wp_cli_request() { + return ( defined( 'WP_CLI' ) && WP_CLI ); + } +} diff --git a/includes/abstracts/abstract-wcs-background-upgrader.php b/includes/abstracts/abstract-wcs-background-upgrader.php new file mode 100755 index 0000000..8b1bf2e --- /dev/null +++ b/includes/abstracts/abstract-wcs-background-upgrader.php @@ -0,0 +1,51 @@ +scheduled_hook action to start repairing subscriptions in + * @see $this->time_limit seconds (60 seconds by default). + * + * @since 2.3.0 + */ + public function schedule_repair() { + $this->schedule_background_update(); + } + + /** + * Add a message to the wcs-upgrade-subscriptions-paypal-suspended log + * + * @param string $message The message to be logged + * @since 2.3.0 + */ + protected function log( $message ) { + $this->logger->add( $this->log_handle, $message ); + } +} diff --git a/includes/abstracts/abstract-wcs-customer-store.php b/includes/abstracts/abstract-wcs-customer-store.php new file mode 100755 index 0000000..7d26e3e --- /dev/null +++ b/includes/abstracts/abstract-wcs-customer-store.php @@ -0,0 +1,58 @@ +init(); + } + + return self::$instance; + } + + /** + * Stub for initialising the class outside the constructor, for things like attaching callbacks to hooks. + */ + protected function init() {} +} diff --git a/includes/abstracts/abstract-wcs-debug-tool-cache-updater.php b/includes/abstracts/abstract-wcs-debug-tool-cache-updater.php new file mode 100755 index 0000000..9ebea36 --- /dev/null +++ b/includes/abstracts/abstract-wcs-debug-tool-cache-updater.php @@ -0,0 +1,47 @@ + System Status > Tools page that need to + * update a cached data store's cache. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Debug_Tool_Cache_Updater Class + * + * Shared methods for tool on the WooCommerce > System Status > Tools page that need to + * update a cached data store's cache. + */ +abstract class WCS_Debug_Tool_Cache_Updater extends WCS_Debug_Tool { + + /** + * @var mixed $data_Store The store used for updating the cache. + */ + protected $data_store; + + /** + * Attach callbacks and hooks, if the class's data store is using caching. + */ + public function init() { + if ( $this->is_data_store_cached() ) { + parent::init(); + } + } + + /** + * Check if the store is a cache updater, and has methods required to erase or generate cache. + */ + protected function is_data_store_cached() { + return is_a( $this->data_store, 'WCS_Cache_Updater' ); + } +} diff --git a/includes/abstracts/abstract-wcs-debug-tool.php b/includes/abstracts/abstract-wcs-debug-tool.php new file mode 100755 index 0000000..cf32dce --- /dev/null +++ b/includes/abstracts/abstract-wcs-debug-tool.php @@ -0,0 +1,66 @@ + System Status > Tools administration screen. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Debug_Tool Class + * + * Add a debug tool to the WooCommerce > System Status > Tools page. + */ +abstract class WCS_Debug_Tool { + + /** + * @var string $tool_key The key used to add the tool to the array of available tools. + */ + protected $tool_key; + + /** + * @var array $tool_data Data for this tool, containing: + * - 'name': The section name given to the tool + * - 'button': The text displayed on the tool's button + * - 'desc': The long description for the tool. + * - 'callback': The callback used to perform the tool's action. + */ + protected $tool_data; + + /** + * Attach callbacks to hooks and validate required properties are assigned values. + */ + public function init() { + + if ( empty( $this->tool_key ) ) { + throw new RuntimeException( __CLASS__ . ' must assign a tool key to $this->tool_key' ); + } + + if ( empty( $this->tool_data ) ) { + throw new RuntimeException( __CLASS__ . ' must assign an array of data about the tool to $this->tool_data' ); + } + + add_filter( 'woocommerce_debug_tools', array( $this, 'add_debug_tools' ) ); + } + + /** + * Add subscription related tools to display on the WooCommerce > System Status > Tools administration screen + * + * @param array $tools Arrays defining the tools displayed on the System Status screen + * @return array + */ + public function add_debug_tools( $tools ) { + $tools[ $this->tool_key ] = $this->tool_data; + return $tools; + } +} diff --git a/includes/abstracts/abstract-wcs-related-order-store.php b/includes/abstracts/abstract-wcs-related-order-store.php new file mode 100755 index 0000000..bf89b9e --- /dev/null +++ b/includes/abstracts/abstract-wcs-related-order-store.php @@ -0,0 +1,141 @@ +check_relation_type(). + * + * Set when instantiated. + * + * @var array + */ + private static $relation_type_keys = array( + 'renewal' => true, + 'switch' => true, + 'resubscribe' => true, + ); + + /** + * Get the active related order data store. + * + * @return WCS_Related_Order_Store + */ + final public static function instance() { + + if ( empty( self::$instance ) ) { + if ( ! did_action( 'plugins_loaded' ) ) { + wcs_doing_it_wrong( __METHOD__, 'This method was called before the "plugins_loaded" hook. It applies a filter to the related order data store instantiated. For that to work, it should first be called after all plugins are loaded.', '2.3.0' ); + } + + $class = apply_filters( 'wcs_related_order_store_class', 'WCS_Related_Order_Store_Cached_CPT' ); + self::$instance = new $class(); + self::$instance->init(); + } + + return self::$instance; + } + + /** + * Stub for initialising the class outside the constructor, for things like attaching callbacks to hooks. + */ + protected function init() {} + + /** + * Get orders related to a given subscription with a given relationship type. + * + * @param WC_Order $subscription The order or subscription for which calling code wants to find related orders. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + * + * @return array + */ + abstract public function get_related_order_ids( WC_Order $subscription, $relation_type ); + + /** + * Find subscriptions related to a given order in a given way, if any. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + * @return array + */ + abstract public function get_related_subscription_ids( WC_Order $order, $relation_type ); + + /** + * Helper function for linking an order to a subscription via a given relationship. + * + * @param WC_Order $order The order to link with the subscription. + * @param WC_Order $subscription The order or subscription to link the order to. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + abstract public function add_relation( WC_Order $order, WC_Order $subscription, $relation_type ); + + /** + * Remove the relationship between a given order and subscription. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param WC_Order $subscription A subscription or order to unlink the order with, if a relation exists. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + abstract public function delete_relation( WC_Order $order, WC_Order $subscription, $relation_type ); + + /** + * Remove all related orders/subscriptions of a given type from an order. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + abstract public function delete_relations( WC_Order $order, $relation_type ); + + /** + * Types of relationships the data store supports. + * + * @return array The possible relationships between a subscription and orders. Includes 'renewal', 'switch' or 'resubscribe' by default. + */ + public function get_relation_types() { + return self::$relation_types; + } + + /** + * Check if a given relationship is supported by the data store. + * + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + * + * @throws InvalidArgumentException If the given order relation is not a known type. + */ + protected function check_relation_type( $relation_type ) { + if ( ! isset( self::$relation_type_keys[ $relation_type ] ) ) { + throw new InvalidArgumentException( sprintf( __( 'Invalid relation type: %s. Order relationship type must be one of: %s.', 'woocommerce-subscriptions' ), $relation_type, implode( ', ', $this->get_relation_types() ) ) ); + } + } +} diff --git a/includes/abstracts/abstract-wcs-scheduler.php b/includes/abstracts/abstract-wcs-scheduler.php index c2dffc2..3ac1581 100755 --- a/includes/abstracts/abstract-wcs-scheduler.php +++ b/includes/abstracts/abstract-wcs-scheduler.php @@ -27,15 +27,10 @@ abstract class WCS_Scheduler { } public function set_date_types_to_schedule() { - $this->date_types_to_schedule = apply_filters( 'woocommerce_subscriptions_date_types_to_schedule', array_keys( wcs_get_subscription_date_types() ) ); + $date_types_to_schedule = wcs_get_subscription_date_types(); + unset( $date_types_to_schedule['start'], $date_types_to_schedule['last_payment'] ); - if ( isset( $this->date_types_to_schedule['start'] ) ) { - unset( $this->date_types_to_schedule['start'] ); - } - - if ( isset( $this->date_types_to_schedule['last_payment'] ) ) { - unset( $this->date_types_to_schedule['last_payment'] ); - } + $this->date_types_to_schedule = apply_filters( 'woocommerce_subscriptions_date_types_to_schedule', array_keys( $date_types_to_schedule ) ); } protected function get_date_types_to_schedule() { diff --git a/includes/admin/class-wc-subscriptions-admin.php b/includes/admin/class-wc-subscriptions-admin.php index e34486f..c939c37 100755 --- a/includes/admin/class-wc-subscriptions-admin.php +++ b/includes/admin/class-wc-subscriptions-admin.php @@ -112,8 +112,6 @@ class WC_Subscriptions_Admin { add_filter( 'set-screen-option', __CLASS__ . '::set_manage_subscriptions_screen_option', 10, 3 ); - add_filter( 'woocommerce_system_status_report', __CLASS__ . '::render_system_status_items' ); - add_filter( 'woocommerce_payment_gateways_setting_columns', __CLASS__ . '::payment_gateways_rewewal_column' ); add_action( 'woocommerce_payment_gateways_setting_column_renewals', __CLASS__ . '::payment_gateways_rewewal_support' ); @@ -127,6 +125,10 @@ class WC_Subscriptions_Admin { add_action( 'woocommerce_admin_order_totals_after_refunded', __CLASS__ . '::maybe_attach_gettext_callback', 10, 1 ); // Unhook gettext callback to prevent extra call impact add_action( 'woocommerce_order_item_add_action_buttons', __CLASS__ . '::maybe_unattach_gettext_callback', 10, 1 ); + + // Add a reminder on the enable guest checkout setting that subscriptions still require an account + add_filter( 'woocommerce_payment_gateways_settings', array( __CLASS__, 'add_guest_checkout_setting_note' ), 10, 1 ); + add_filter( 'woocommerce_account_settings', array( __CLASS__, 'add_guest_checkout_setting_note' ), 10, 1 ); } /** @@ -735,6 +737,7 @@ class WC_Subscriptions_Admin { 'bulkEditPeriodMessage' => __( 'Enter the new period, either day, week, month or year:', 'woocommerce-subscriptions' ), 'bulkEditLengthMessage' => __( 'Enter a new length (e.g. 5):', 'woocommerce-subscriptions' ), 'bulkEditIntervalhMessage' => __( 'Enter a new interval as a single number (e.g. to charge every 2nd month, enter 2):', 'woocommerce-subscriptions' ), + 'bulkDeleteOptionLabel' => __( 'Delete all variations without a subscription', 'woocommerce-subscriptions' ), 'oneTimeShippingCheckNonce' => wp_create_nonce( 'one_time_shipping' ), ); } else if ( 'edit-shop_order' == $screen->id ) { @@ -1400,38 +1403,6 @@ class WC_Subscriptions_Admin { return ob_get_clean(); } - /** - * Renders the Subscription information in the WC status page - */ - public static function render_system_status_items() { - $debug_data = array(); - $is_wcs_debug = defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false; - - $debug_data['wcs_debug'] = array( - 'name' => _x( 'WCS_DEBUG', 'label that indicates whether debugging is turned on for the plugin', 'woocommerce-subscriptions' ), - 'note' => ( $is_wcs_debug ) ? __( 'Yes', 'woocommerce-subscriptions' ) : __( 'No', 'woocommerce-subscriptions' ), - 'success' => $is_wcs_debug ? 0 : 1, - ); - - $debug_data['wcs_staging'] = array( - 'name' => _x( 'Subscriptions Mode', 'Live or Staging, Label on WooCommerce -> System Status page', 'woocommerce-subscriptions' ), - 'note' => '' . ( ( WC_Subscriptions::is_duplicate_site() ) ? _x( 'Staging', 'refers to staging site', 'woocommerce-subscriptions' ) : _x( 'Live', 'refers to live site', 'woocommerce-subscriptions' ) ) . '', - 'success' => ( WC_Subscriptions::is_duplicate_site() ) ? 0 : 1, - ); - - $theme_overrides = self::get_theme_overrides(); - $debug_data['wcs_theme_overrides'] = array( - 'name' => _x( 'Subscriptions Template Theme Overrides', 'label for the system status page', 'woocommerce-subscriptions' ), - 'mark' => '', - 'mark_icon' => $theme_overrides['has_outdated_templates'] ? 'warning' : 'yes', - 'data' => $theme_overrides, - ); - - $debug_data = apply_filters( 'wcs_system_status', $debug_data ); - - include( plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/admin/status.php' ); - } - /** * Adds Subscriptions specific details to the WooCommerce System Status report. * @@ -1673,57 +1644,6 @@ class WC_Subscriptions_Admin { return apply_filters( 'wcs_admin_is_subscription_product_save_request', $is_subscription_product_save_request, $post_id, $product_types ); } - /** - * Determine which of our files have been overridden by the theme. - * - * @author Jeremy Pry - * @return array Theme override data. - */ - private static function get_theme_overrides() { - $wcs_template_dir = dirname( WC_Subscriptions::$plugin_file ) . '/templates/'; - $wc_template_path = trailingslashit( wc()->template_path() ); - $theme_root = trailingslashit( get_theme_root() ); - $overridden = array(); - $outdated = false; - $templates = WC_Admin_Status::scan_template_files( $wcs_template_dir ); - - foreach ( $templates as $file ) { - $theme_file = $is_outdated = false; - $locations = array( - get_stylesheet_directory() . "/{$file}", - get_stylesheet_directory() . "/{$wc_template_path}{$file}", - get_template_directory() . "/{$file}", - get_template_directory() . "/{$wc_template_path}{$file}", - ); - - foreach ( $locations as $location ) { - if ( is_readable( $location ) ) { - $theme_file = $location; - break; - } - } - - if ( ! empty( $theme_file ) ) { - $core_version = WC_Admin_Status::get_file_version( $wcs_template_dir . $file ); - $theme_version = WC_Admin_Status::get_file_version( $theme_file ); - if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { - $outdated = $is_outdated = true; - } - $overridden[] = array( - 'file' => str_replace( $theme_root, '', $theme_file ), - 'version' => $theme_version, - 'core_version' => $core_version, - 'is_outdated' => $is_outdated, - ); - } - } - - return array( - 'has_outdated_templates' => $outdated, - 'overridden_templates' => $overridden, - ); - } - /** * Insert a setting or an array of settings after another specific setting by its ID. * @@ -1754,6 +1674,41 @@ class WC_Subscriptions_Admin { } } + /** + * Add a reminder on the enable guest checkout setting that subscriptions still require an account + * @since 2.3.0 + * @param array $settings The list of settings + */ + public static function add_guest_checkout_setting_note( $settings ) { + $is_wc_pre_3_4_0 = WC_Subscriptions::is_woocommerce_pre( '3.4.0' ); + $current_filter = current_filter(); + + if ( ( $is_wc_pre_3_4_0 && 'woocommerce_payment_gateways_settings' !== $current_filter ) || ( ! $is_wc_pre_3_4_0 && 'woocommerce_account_settings' !== $current_filter ) ) { + return $settings; + } + + if ( ! is_array( $settings ) ) { + return $settings; + } + + foreach ( $settings as &$value ) { + if ( isset( $value['id'] ) && 'woocommerce_enable_guest_checkout' === $value['id'] ) { + $value['desc_tip'] = ! empty( $value['desc_tip'] ) ? $value['desc_tip'] . ' ' : ''; + $value['desc_tip'] .= __( 'Note that purchasing a subscription still requires an account.', 'woocommerce-subscriptions' ); + break; + } + } + return $settings; + } + + /** + * Renders the Subscription information in the WC status page + */ + public static function render_system_status_items() { + _deprecated_function( __METHOD__, '2.3', 'WCS_Admin_System_Status::render_system_status_items()' ); + WCS_Admin_System_Status::render_system_status_items(); + } + /** * Outputs the contents of the "Renewal Orders" meta box. * diff --git a/includes/admin/class-wcs-admin-meta-boxes.php b/includes/admin/class-wcs-admin-meta-boxes.php index c08f9c1..2067936 100755 --- a/includes/admin/class-wcs-admin-meta-boxes.php +++ b/includes/admin/class-wcs-admin-meta-boxes.php @@ -41,6 +41,7 @@ class WCS_Admin_Meta_Boxes { add_action( 'woocommerce_order_action_wcs_process_renewal', __CLASS__ . '::process_renewal_action_request', 10, 1 ); add_action( 'woocommerce_order_action_wcs_create_pending_renewal', __CLASS__ . '::create_pending_renewal_action_request', 10, 1 ); + add_action( 'woocommerce_order_action_wcs_create_pending_parent', __CLASS__ . '::create_pending_parent_action_request', 10, 1 ); add_filter( 'woocommerce_resend_order_emails_available', __CLASS__ . '::remove_order_email_actions', 0, 1 ); @@ -55,7 +56,7 @@ class WCS_Admin_Meta_Boxes { add_meta_box( 'woocommerce-subscription-data', _x( 'Subscription Data', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Subscription_Data::output', 'shop_subscription', 'normal', 'high' ); - add_meta_box( 'woocommerce-subscription-schedule', _x( 'Billing Schedule', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Schedule::output', 'shop_subscription', 'side', 'default' ); + add_meta_box( 'woocommerce-subscription-schedule', _x( 'Schedule', 'meta box title', 'woocommerce-subscriptions' ), 'WCS_Meta_Box_Schedule::output', 'shop_subscription', 'side', 'default' ); remove_meta_box( 'woocommerce-order-data', 'shop_subscription', 'normal' ); @@ -91,9 +92,10 @@ class WCS_Admin_Meta_Boxes { global $post; // Get admin screen id - $screen = get_current_screen(); + $screen = get_current_screen(); + $screen_id = isset( $screen->id ) ? $screen->id : ''; - if ( 'shop_subscription' == $screen->id ) { + if ( 'shop_subscription' == $screen_id ) { wp_register_script( 'jstz', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/jstz.min.js' ); @@ -112,8 +114,9 @@ class WCS_Admin_Meta_Boxes { 'process_renewal_action_warning' => __( "Are you sure you want to process a renewal?\n\nThis will charge the customer and email them the renewal order (if emails are enabled).", 'woocommerce-subscriptions' ), 'payment_method' => wcs_get_subscription( $post )->get_payment_method(), 'search_customers_nonce' => wp_create_nonce( 'search-customers' ), + 'get_customer_orders_nonce' => wp_create_nonce( 'get-customer-orders' ), ) ) ); - } else if ( 'shop_order' == $screen->id ) { + } else if ( 'shop_order' == $screen_id ) { wp_enqueue_script( 'wcs-admin-meta-boxes-order', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/wcs-meta-boxes-order.js' ); @@ -122,6 +125,16 @@ class WCS_Admin_Meta_Boxes { ) ); } + + // Enqueue the metabox script for coupons. + if ( ! WC_Subscriptions::is_woocommerce_pre( '3.2' ) && in_array( $screen_id, array( 'shop_coupon', 'edit-shop_coupon' ) ) ) { + wp_enqueue_script( + 'wcs-admin-coupon-meta-boxes', + plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/meta-boxes-coupon.js', + array( 'jquery', 'wc-admin-meta-boxes' ), + WC_Subscriptions::$version + ); + } } /** @@ -140,8 +153,11 @@ class WCS_Admin_Meta_Boxes { $actions['wcs_process_renewal'] = esc_html__( 'Process renewal', 'woocommerce-subscriptions' ); } - $actions['wcs_create_pending_renewal'] = esc_html__( 'Create pending renewal order', 'woocommerce-subscriptions' ); - + if ( count( $theorder->get_related_orders() ) > 0 ) { + $actions['wcs_create_pending_renewal'] = esc_html__( 'Create pending renewal order', 'woocommerce-subscriptions' ); + } else { + $actions['wcs_create_pending_parent'] = esc_html__( 'Create pending parent order', 'woocommerce-subscriptions' ); + } } else if ( self::can_renewal_order_be_retried( $theorder ) ) { $actions['wcs_retry_renewal_payment'] = esc_html__( 'Retry Renewal Payment', 'woocommerce-subscriptions' ); } @@ -173,12 +189,46 @@ class WCS_Admin_Meta_Boxes { $renewal_order = wcs_create_renewal_order( $subscription ); if ( ! $subscription->is_manual() ) { + $renewal_order->set_payment_method( wc_get_payment_gateway_by_order( $subscription ) ); // We need to pass the payment gateway instance to be compatible with WC < 3.0, only WC 3.0+ supports passing the string name + + if ( is_callable( array( $renewal_order, 'save' ) ) ) { // WC 3.0+ + $renewal_order->save(); + } } $subscription->add_order_note( __( 'Create pending renewal order requested by admin action.', 'woocommerce-subscriptions' ), false, true ); } + /** + * Handles the action request to create a pending parent order. + * + * @param array $subscription + * @since 2.3 + */ + public static function create_pending_parent_action_request( $subscription ) { + + if ( ! $subscription->has_status( array( 'pending', 'on-hold' ) ) ) { + $subscription->update_status( 'on-hold' ); + } + + $parent_order = wcs_create_order_from_subscription( $subscription, 'parent' ); + + $subscription->set_parent_id( wcs_get_objects_property( $parent_order, 'id' ) ); + $subscription->save(); + + if ( ! $subscription->is_manual() ) { + + $parent_order->set_payment_method( wc_get_payment_gateway_by_order( $subscription ) ); // We need to pass the payment gateway instance to be compatible with WC < 3.0, only WC 3.0+ supports passing the string name + + if ( is_callable( array( $parent_order, 'save' ) ) ) { // WC 3.0+ + $parent_order->save(); + } + } + + $subscription->add_order_note( __( 'Create pending parent order requested by admin action.', 'woocommerce-subscriptions' ), false, true ); + } + /** * Removes order related emails from the available actions. * diff --git a/includes/admin/class-wcs-admin-notice.php b/includes/admin/class-wcs-admin-notice.php new file mode 100755 index 0000000..324aec3 --- /dev/null +++ b/includes/admin/class-wcs-admin-notice.php @@ -0,0 +1,272 @@ +type = $type; + $this->attributes = $attributes; + $this->dismiss_url = $dismiss_url; + } + + /** + * Display the admin notice. + * + * Will print the notice if called during the 'admin_notices' action. Otherwise will attach a callback and display the notice when the 'admin_notices' is triggered. + * + * @since 2.3.0 + */ + public function display() { + + if ( 'admin_notices' !== current_filter() ) { + add_action( 'admin_notices', array( $this, __FUNCTION__ ) ); + return; + } + + wc_get_template( + 'html-admin-notice.php', + array( 'notice' => $this ), + '', + plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/admin/' + ); + } + + /** + * Whether the admin notice is dismissible. + * + * @since 2.3.0 + * @return boolean + */ + public function is_dismissible() { + return ! empty( $this->dismiss_url ); + } + + /** + * Whether the admin notice has a heading or not. + * + * @since 2.3.0 + * @return boolean + */ + public function has_heading() { + return ! empty( $this->heading ); + } + + /** + * Whether the admin notice has actions or not. + * + * @since 2.3.0 + * @return boolean + */ + public function has_actions() { + return ! empty( $this->actions ) && is_array( $this->actions ); + } + + /* Printers */ + + /** + * Print the notice's heading. + * + * @since 2.3.0 + */ + public function print_heading() { + echo esc_html( $this->heading ); + } + + /** + * Get the notice's content. + * + * Will wrap simple notices in paragraph elements (

) for correct styling and print HTML notices unchanged. + * + * @since 2.3.0 + */ + public function print_content() { + switch ( $this->content_type ) { + case 'simple': + echo '

' . wp_kses_post( $this->content ) . '

'; + break; + case 'html': + echo wp_kses_post( $this->content ); + break; + case 'template': + wc_get_template( $this->content['template_name'], $this->content['args'], '', $this->content['template_path'] ); + break; + } + } + + /** + * Print the notice's attributes. + * + * Turns the attributes array into 'id="id" class="class class class"' strings. + * + * @since 2.3.0 + */ + public function print_attributes() { + $attributes = $this->attributes; + $attributes['class'][] = $this->type; + + if ( $this->is_dismissible() ) { + $attributes['style'][] = 'position: relative;'; + } + + foreach ( $attributes as $attribute => $values ) { + $attributes[ $attribute ] = $attribute . '="' . implode( ' ', array_map( 'esc_attr', $values ) ) . '"'; + } + + echo wp_kses_post( implode( ' ', $attributes ) ); + } + + /** + * Print the notice's dismiss URL. + * + * @since 2.3.0 + */ + public function print_dismiss_url() { + echo esc_attr( $this->dismiss_url ); + } + + /* Getters */ + + /** + * Get the notice's actions. + * + * @since 2.3.0 + * @return array + */ + public function get_actions() { + return $this->actions; + } + + /* Setters */ + + /** + * Set the notice's content to a simple string. + * + * @param string $content The notice content. + */ + public function set_simple_content( $content ) { + $this->content_type = 'simple'; + $this->content = $content; + } + + /** + * Set the notice's content to a string containing HTML elements. + * + * @param string $html The notice content. + */ + public function set_html_content( $html ) { + $this->content_type = 'html'; + $this->content = $html; + } + + /** + * Set the notice's content to a string containing HTML elements. + * + * @since 2.3.0 + * @param string $template_name Template name. + * @param string $template_path Template path. + * @param array $args Arguments. (default: array). + */ + public function set_content_template( $template_name, $template_path, $args = array() ) { + $this->content_type = 'template'; + $this->content = array( + 'template_name' => $template_name, + 'template_path' => $template_path, + 'args' => $args, + ); + } + + /** + * Set actions the user can make in response to this notice. + * + * @since 2.3.0 + * @param array $actions The actions the user can make. Example format: + * array( + * array( + * 'name' => 'The actions's name', // This arg will appear as the button text. + * 'url' => 'url', // The url the user will be directed to if clicked. + * 'class' => 'class string', // The class attribute string used in the link element. Optional. Will default to 'docs button' - a plain button. + * ) + * ) + */ + public function set_actions( array $actions ) { + $this->actions = $actions; + } + + /** + * Set notice's heading. If set this will appear at the top of the notice wrapped in a h2 element. + * + * @since 2.3.0 + * @param string $heading The notice heading. + */ + public function set_heading( $heading ) { + $this->heading = $heading; + } +} diff --git a/includes/admin/class-wcs-admin-post-types.php b/includes/admin/class-wcs-admin-post-types.php index fcea48f..5fc0eb4 100755 --- a/includes/admin/class-wcs-admin-post-types.php +++ b/includes/admin/class-wcs-admin-post-types.php @@ -593,20 +593,7 @@ class WCS_Admin_Post_Types { case 'next_payment_date': case 'last_payment_date': case 'end_date': - $date_type_map = array( 'start_date' => 'date_created', 'last_payment_date' => 'last_order_date_created' ); - $date_type = array_key_exists( $column, $date_type_map ) ? $date_type_map[ $column ] : $column; - - if ( 0 == $the_subscription->get_time( $date_type, 'gmt' ) ) { - $column_content .= '-'; - } else { - $column_content .= sprintf( '', esc_attr( $column ), esc_attr( date( __( 'Y/m/d g:i:s A', 'woocommerce-subscriptions' ) , $the_subscription->get_time( $date_type, 'site' ) ) ), esc_html( $the_subscription->get_date_to_display( $date_type ) ) ); - - if ( 'next_payment_date' == $column && $the_subscription->payment_method_supports( 'gateway_scheduled_payments' ) && ! $the_subscription->is_manual() && $the_subscription->has_status( 'active' ) ) { - $column_content .= '
'; - } - } - - $column_content = $column_content; + $column_content = self::get_date_column_content( $the_subscription, $column ); break; case 'orders' : @@ -618,6 +605,32 @@ class WCS_Admin_Post_Types { } + /** + * Return the content for a date column on the Edit Subscription screen + * + * @param WC_Subscription $subscription + * @param string $column + * @return string + * @since 2.3.0 + */ + public static function get_date_column_content( $subscription, $column ) { + + $date_type_map = array( 'start_date' => 'date_created', 'last_payment_date' => 'last_order_date_created' ); + $date_type = array_key_exists( $column, $date_type_map ) ? $date_type_map[ $column ] : $column; + + if ( 0 == $subscription->get_time( $date_type, 'gmt' ) ) { + $column_content = '-'; + } else { + $column_content = sprintf( '', esc_attr( $column ), esc_attr( date( __( 'Y/m/d g:i:s A', 'woocommerce-subscriptions' ) , $subscription->get_time( $date_type, 'site' ) ) ), esc_html( $subscription->get_date_to_display( $date_type ) ) ); + + if ( 'next_payment_date' == $column && $subscription->payment_method_supports( 'gateway_scheduled_payments' ) && ! $subscription->is_manual() && $subscription->has_status( 'active' ) ) { + $column_content .= '
'; + } + } + + return $column_content; + } + /** * Make columns sortable * @@ -653,80 +666,19 @@ class WCS_Admin_Post_Types { return; } - $search_fields = array_map( 'wc_clean', apply_filters( 'woocommerce_shop_subscription_search_fields', array( - '_order_key', - '_billing_company', - '_billing_address_1', - '_billing_address_2', - '_billing_city', - '_billing_postcode', - '_billing_country', - '_billing_state', - '_billing_email', - '_billing_phone', - '_shipping_address_1', - '_shipping_address_2', - '_shipping_city', - '_shipping_postcode', - '_shipping_country', - '_shipping_state', - ) ) ); + $post_ids = wcs_subscription_search( $_GET['s'] ); - $search_order_id = str_replace( 'Order #', '', $_GET['s'] ); - if ( ! is_numeric( $search_order_id ) ) { - $search_order_id = 0; + if ( ! empty( $post_ids ) ) { + + // Remove s - we don't want to search order name + unset( $wp->query_vars['s'] ); + + // so we know we're doing this + $wp->query_vars['shop_subscription_search'] = true; + + // Search by found posts + $wp->query_vars['post__in'] = $post_ids; } - - // Search orders - $post_ids = array_unique( array_merge( - $wpdb->get_col( - $wpdb->prepare( " - SELECT p1.post_id - FROM {$wpdb->postmeta} p1 - INNER JOIN {$wpdb->postmeta} p2 ON p1.post_id = p2.post_id - WHERE - ( p1.meta_key = '_billing_first_name' AND p2.meta_key = '_billing_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' ) - OR - ( p1.meta_key = '_shipping_first_name' AND p2.meta_key = '_shipping_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' ) - OR - ( p1.meta_key IN ('" . implode( "','", esc_sql( $search_fields ) ) . "') AND p1.meta_value LIKE '%%%s%%' ) - ", - esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] ), esc_attr( $_GET['s'] ) - ) - ), - $wpdb->get_col( - $wpdb->prepare( " - SELECT order_id - FROM {$wpdb->prefix}woocommerce_order_items as order_items - WHERE order_item_name LIKE '%%%s%%' - ", - esc_attr( $_GET['s'] ) - ) - ), - $wpdb->get_col( - $wpdb->prepare( " - SELECT p1.ID - FROM {$wpdb->posts} p1 - INNER JOIN {$wpdb->postmeta} p2 ON p1.ID = p2.post_id - INNER JOIN {$wpdb->users} u ON p2.meta_value = u.ID - WHERE u.user_email LIKE '%%%s%%' - AND p2.meta_key = '_customer_user' - AND p1.post_type = 'shop_subscription' - ", - esc_attr( $_GET['s'] ) - ) - ), - array( $search_order_id ) - ) ); - - // Remove s - we don't want to search order name - unset( $wp->query_vars['s'] ); - - // so we know we're doing this - $wp->query_vars['shop_subscription_search'] = true; - - // Search by found posts - $wp->query_vars['post__in'] = $post_ids; } /** diff --git a/includes/admin/class-wcs-admin-system-status.php b/includes/admin/class-wcs-admin-system-status.php new file mode 100755 index 0000000..c23e03b --- /dev/null +++ b/includes/admin/class-wcs-admin-system-status.php @@ -0,0 +1,347 @@ + __( 'Subscriptions', 'woocommerce-subscriptions' ), + 'tooltip' => __( 'This section shows any information about Subscriptions.', 'woocommerce-subscriptions' ), + 'data' => apply_filters( 'wcs_system_status', $subscriptions_data ), + ), + array( + 'title' => __( 'Store Setup', 'woocommerce-subscriptions' ), + 'tooltip' => __( 'This section shows general information about the store.', 'woocommerce-subscriptions' ), + 'data' => $store_data, + ), + array( + 'title' => __( 'Subscriptions by Payment Gateway', 'woocommerce-subscriptions' ), + 'tooltip' => __( 'This section shows information about Subscription payment methods.', 'woocommerce-subscriptions' ), + 'data' => $subscriptions_by_payment_gateway, + ), + array( + 'title' => __( 'Payment Gateway Support', 'woocommerce-subscriptions' ), + 'tooltip' => __( 'This section shows information about payment gateway feature support.', 'woocommerce-subscriptions' ), + 'data' => $payment_gateway_data, + ), + ); + + foreach ( $system_status_sections as $section ) { + $section_title = $section['title']; + $section_tooltip = $section['tooltip']; + $debug_data = $section['data']; + + include( plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/admin/status.php' ); + } + } + + /** + * Include WCS_DEBUG flag + */ + private static function set_debug_mode( &$debug_data ) { + $is_wcs_debug = defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false; + + $debug_data['wcs_debug'] = array( + 'name' => _x( 'WCS_DEBUG', 'label that indicates whether debugging is turned on for the plugin', 'woocommerce-subscriptions' ), + 'label' => 'WCS_DEBUG', + 'note' => ( $is_wcs_debug ) ? __( 'Yes', 'woocommerce-subscriptions' ) : __( 'No', 'woocommerce-subscriptions' ), + 'success' => $is_wcs_debug ? 0 : 1, + ); + } + + /** + * Include the staging/live mode the store is running in. + */ + private static function set_staging_mode( &$debug_data ) { + $debug_data['wcs_staging'] = array( + 'name' => _x( 'Subscriptions Mode', 'Live or Staging, Label on WooCommerce -> System Status page', 'woocommerce-subscriptions' ), + 'label' => 'Subscriptions Mode', + 'note' => '' . ( ( WC_Subscriptions::is_duplicate_site() ) ? _x( 'Staging', 'refers to staging site', 'woocommerce-subscriptions' ) : _x( 'Live', 'refers to live site', 'woocommerce-subscriptions' ) ) . '', + 'success' => ( WC_Subscriptions::is_duplicate_site() ) ? 0 : 1, + ); + } + + /** + * List any Subscriptions template overrides. + */ + private static function set_theme_overrides( &$debug_data ) { + $theme_overrides = self::get_theme_overrides(); + + if ( ! empty( $theme_overrides['overrides'] ) ) { + $debug_data['wcs_theme_overrides'] = array( + 'name' => _x( 'Subscriptions Template Theme Overrides', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Subscriptions Template Theme Overrides', + 'data' => $theme_overrides['overrides'], + ); + + // Include a note on how to update if the templates are out of date. + if ( ! empty( $theme_overrides['has_outdated_templates'] ) && true === $theme_overrides['has_outdated_templates'] ) { + $debug_data['wcs_theme_overrides'] += array( + 'mark_icon' => 'warning', + 'note' => sprintf( __( '%sLearn how to update%s', 'woocommerce-subscriptions' ), '', '' ), + ); + } + } + } + + /** + * Determine which of our files have been overridden by the theme. + * + * @author Jeremy Pry + * @return array Theme override data. + */ + private static function get_theme_overrides() { + $wcs_template_dir = dirname( WC_Subscriptions::$plugin_file ) . '/templates/'; + $wc_template_path = trailingslashit( wc()->template_path() ); + $theme_root = trailingslashit( get_theme_root() ); + $overridden = array(); + $outdated = false; + $templates = WC_Admin_Status::scan_template_files( $wcs_template_dir ); + + foreach ( $templates as $file ) { + $theme_file = $is_outdated = false; + $locations = array( + get_stylesheet_directory() . "/{$file}", + get_stylesheet_directory() . "/{$wc_template_path}{$file}", + get_template_directory() . "/{$file}", + get_template_directory() . "/{$wc_template_path}{$file}", + ); + + foreach ( $locations as $location ) { + if ( is_readable( $location ) ) { + $theme_file = $location; + break; + } + } + + if ( ! empty( $theme_file ) ) { + $core_version = WC_Admin_Status::get_file_version( $wcs_template_dir . $file ); + $theme_version = WC_Admin_Status::get_file_version( $theme_file ); + + $overridden_template_output = sprintf( '%s', esc_html( str_replace( $theme_root, '', $theme_file ) ) ); + + if ( $core_version && ( empty( $theme_version ) || version_compare( $theme_version, $core_version, '<' ) ) ) { + $outdated = true; + $overridden_template_output .= sprintf( + /* translators: %1$s is the file version, %2$s is the core version */ + esc_html__( 'version %1$s is out of date. The core version is %2$s', 'woocommerce-subscriptions' ), + '' . esc_html( $theme_version ) . '', + '' . esc_html( $core_version ) . '' + ); + } + + $overridden['overrides'][] = $overridden_template_output; + } + } + + $overridden['has_outdated_templates'] = $outdated; + + return $overridden; + } + + /** + * Add a breakdown of Subscriptions per status. + */ + private static function set_subscription_statuses( &$debug_data ) { + + $subscriptions_by_status = (array) wp_count_posts( 'shop_subscription' ); + $subscriptions_by_status_output = array(); + + foreach ( $subscriptions_by_status as $status => $count ) { + if ( ! empty( $count ) ) { + $subscriptions_by_status_output[] = $status . ': ' . $count; + } + } + + $debug_data['wcs_subscriptions_by_status'] = array( + 'name' => _x( 'Subscription Statuses', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Subscription Statuses', + 'mark' => '', + 'mark_icon' => '', + 'data' => $subscriptions_by_status_output, + ); + } + + /** + * Include information about whether the store is linked to a WooCommerce account and whether they have an active WCS product key. + */ + private static function set_woocommerce_account_data( &$debug_data ) { + + if ( ! class_exists( 'WC_Helper' ) ) { + return; + } + + $woocommerce_account_auth = WC_Helper_Options::get( 'auth' ); + $woocommerce_account_connected = ! empty( $woocommerce_account_auth ); + + $debug_data['wcs_woocommerce_account_connected'] = array( + 'name' => _x( 'WooCommerce Account Connected', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'WooCommerce Account Connected', + 'note' => $woocommerce_account_connected ? 'Yes' : 'No', + 'success' => $woocommerce_account_connected, + ); + + if ( ! $woocommerce_account_connected ) { + return; + } + + // Check for an active WooCommerce Subscriptions product key + $woocommerce_account_subscriptions = WC_Helper::get_subscriptions(); + $site_id = absint( $woocommerce_account_auth['site_id'] ); + $has_active_product_key = false; + + foreach ( $woocommerce_account_subscriptions as $subscription ) { + if ( isset( $subscription['product_id'] ) && self::WCS_PRODUCT_ID === $subscription['product_id'] ) { + $has_active_product_key = in_array( $site_id, $subscription['connections'] ); + break; + } + } + + $debug_data['wcs_active_product_key'] = array( + 'name' => _x( 'Active Product Key', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Active Product Key', + 'note' => $has_active_product_key ? 'Yes' : 'No', + 'success' => $has_active_product_key, + ); + } + + /** + * Add a breakdown of subscriptions per payment gateway. + */ + private static function set_subscriptions_by_payment_gateway( &$debug_data ) { + global $wpdb; + + $gateways = WC()->payment_gateways->get_available_payment_gateways(); + $results = $wpdb->get_results( " + SELECT COUNT(subscriptions.ID) as count, post_meta.meta_value as payment_method, subscriptions.post_status + FROM $wpdb->posts as subscriptions RIGHT JOIN $wpdb->postmeta as post_meta ON post_meta.post_id = subscriptions.ID + WHERE subscriptions.post_type = 'shop_subscription' && post_meta.meta_key = '_payment_method' + GROUP BY post_meta.meta_value, subscriptions.post_status", ARRAY_A ); + + $subscriptions_payment_gateway_data = array(); + + foreach ( $results as $result ) { + $payment_method = $result['payment_method']; + $subscription_status = $result['post_status']; + + if ( isset( $gateways[ $payment_method ] ) ) { + $payment_method_name = $payment_method_label = $gateways[ $payment_method ]->method_title; + } else { + $payment_method_label = $payment_method = 'other'; + $payment_method_name = _x( 'Other', 'label for the system status page', 'woocommerce-subscriptions' ); + } + + $key = 'wcs_payment_method_subscriptions_by' . $payment_method; + + if ( ! isset( $debug_data[ $key ] ) ) { + $debug_data[ $key ] = array( + 'name' => $payment_method_name, + 'label' => $payment_method_label, + 'data' => array(), + ); + } + + $debug_data[ $key ]['data'][] = $subscription_status . ': ' . $result['count']; + } + } + + /** + * List the enabled payment gateways and the features they support. + */ + private static function set_subscriptions_payment_gateway_support( &$debug_data ) { + $gateways = WC()->payment_gateways->get_available_payment_gateways(); + + foreach ( $gateways as $gateway_id => $gateway ) { + $debug_data[ 'wcs_' . $gateway_id . '_feature_support' ] = array( + 'name' => $gateway->method_title, + 'label' => $gateway->method_title, + 'data' => $gateway->supports, + ); + + if ( 'paypal' === $gateway_id ) { + $are_reference_transactions_enabled = WCS_PayPal::are_reference_transactions_enabled(); + + $debug_data['wcs_paypal_reference_transactions'] = array( + 'name' => _x( 'PayPal Reference Transactions Enabled', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'PayPal Reference Transactions Enabled', + 'mark_icon' => $are_reference_transactions_enabled ? 'yes' : 'warning', + 'note' => $are_reference_transactions_enabled ? 'Yes' : 'No', + 'success' => $are_reference_transactions_enabled, + ); + } + } + } + + /** + * Add the store's country and state information. + */ + private static function set_store_location( &$debug_data ) { + $store_base_location = wc_get_base_location(); + $countries = WC()->countries->get_countries(); + $states = WC()->countries->get_states( $store_base_location['country'] ); + $store_location_string = ''; + + if ( isset( $countries[ $store_base_location['country'] ] ) ) { + $store_location_string = $countries[ $store_base_location['country'] ]; + + if ( ! empty( $states[ $store_base_location['state'] ] ) ) { + $store_location_string .= ' — ' . $states[ $store_base_location['state'] ]; + } + } + + $debug_data['wcs_store_location'] = array( + 'name' => _x( 'Country / State', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Country / State', + 'note' => $store_location_string, + 'mark' => '', + 'mark_icon' => '', + ); + } +} diff --git a/includes/admin/debug-tools/class-wcs-debug-tool-cache-background-updater.php b/includes/admin/debug-tools/class-wcs-debug-tool-cache-background-updater.php new file mode 100755 index 0000000..d9ed4a3 --- /dev/null +++ b/includes/admin/debug-tools/class-wcs-debug-tool-cache-background-updater.php @@ -0,0 +1,59 @@ + System Status > Tools administration screen. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Debug_Tool_Cache_Background_Updater Class + * + * Provide APIs for a debug tool to update a cached data store's data in the background using Action Scheduler. + */ +class WCS_Debug_Tool_Cache_Background_Updater extends WCS_Background_Updater { + + /** + * @var WCS_Cache_Updater The data store used to manage the cache. + */ + protected $data_store; + + /** + * WCS_Debug_Tool_Cache_Background_Updater constructor. + * + * @param string $scheduled_hook The hook to schedule to run the update. + * @param WCS_Cache_Updater $data_store + */ + public function __construct( $scheduled_hook, WCS_Cache_Updater $data_store ) { + $this->scheduled_hook = $scheduled_hook; + $this->data_store = $data_store; + } + + /** + * Get the items to be updated, if any. + * + * @return array An array of items to update, or empty array if there are no items to update. + */ + protected function get_items_to_update() { + return $this->data_store->get_items_to_update(); + } + + /** + * Run the update for a single item. + * + * @param mixed $item The item to update. + */ + protected function update_item( $item ) { + return $this->data_store->update_items_cache( $item ); + } +} diff --git a/includes/admin/debug-tools/class-wcs-debug-tool-cache-eraser.php b/includes/admin/debug-tools/class-wcs-debug-tool-cache-eraser.php new file mode 100755 index 0000000..624d892 --- /dev/null +++ b/includes/admin/debug-tools/class-wcs-debug-tool-cache-eraser.php @@ -0,0 +1,54 @@ + System Status > Tools page for + * deleting a data store's cache/s. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Debug_Tool_Cache_Eraser Class + * + * Add a debug tool to the WooCommerce > System Status > Tools page for + * deleting a data store's cache/s. + */ +class WCS_Debug_Tool_Cache_Eraser extends WCS_Debug_Tool_Cache_Updater { + + /** + * WCS_Debug_Tool_Cache_Eraser constructor. + * + * @param string $tool_key The key used to add the tool to the array of available tools. + * @param string $tool_name The section name given to the tool on the admin screen. + * @param string $tool_description The long description for the tool displayed on the admin screen. + * @param WCS_Cache_Updater $data_store The cached data store this tool will use for erasing cache. + */ + public function __construct( $tool_key, $tool_name, $tool_description, WCS_Cache_Updater $data_store ) { + $this->tool_key = $tool_key; + $this->data_store = $data_store; + $this->tool_data = array( + 'name' => $tool_name, + 'button' => $tool_name, + 'desc' => $tool_description, + 'callback' => array( $this, 'delete_caches' ), + ); + } + + /** + * Clear all of the data store's caches. + */ + public function delete_caches() { + if ( $this->is_data_store_cached() ) { + $this->data_store->delete_all_caches(); + } + } +} diff --git a/includes/admin/debug-tools/class-wcs-debug-tool-cache-generator.php b/includes/admin/debug-tools/class-wcs-debug-tool-cache-generator.php new file mode 100755 index 0000000..1fe3cb7 --- /dev/null +++ b/includes/admin/debug-tools/class-wcs-debug-tool-cache-generator.php @@ -0,0 +1,68 @@ + System Status > Tools page for generating a cache. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Debug_Tool_Cache_Generator Class + * + * Add a debug tool to the WooCommerce > System Status > Tools page for generating a cache. + */ +class WCS_Debug_Tool_Cache_Generator extends WCS_Debug_Tool_Cache_Updater { + + /** + * @var WCS_Background_Updater $update The instance used to generate the cache data in the background. + */ + protected $cache_updater; + + /** + * WCS_Debug_Tool_Cache_Generator constructor. + * + * @param string $tool_key The key used to add the tool to the array of available tools. + * @param string $tool_name The section name given to the tool on the admin screen. + * @param string $tool_description The long description for the tool displayed on the admin screen. + * @param WCS_Cache_Updater $data_store + * @param WCS_Background_Updater $cache_updater + */ + public function __construct( $tool_key, $tool_name, $tool_description, WCS_Cache_Updater $data_store, WCS_Background_Updater $cache_updater ) { + $this->tool_key = $tool_key; + $this->data_store = $data_store; + $this->cache_updater = $cache_updater; + $this->tool_data = array( + 'name' => $tool_name, + 'button' => $tool_name, + 'desc' => $tool_description, + 'callback' => array( $this, 'generate_caches' ), + ); + } + + /** + * Attach callbacks and hooks, if the store supports getting uncached items, which is required to generate cache + * and also acts as a proxy to determine if the related order store is using caching + */ + public function init() { + if ( $this->is_data_store_cached() ) { + parent::init(); + $this->cache_updater->init(); + } + } + + /** + * Generate the data store's cache by calling the @see $this->>cache_updater's update method. + */ + public function generate_caches() { + $this->cache_updater->run_update(); + } +} diff --git a/includes/admin/debug-tools/class-wcs-debug-tool-factory.php b/includes/admin/debug-tools/class-wcs-debug-tool-factory.php new file mode 100755 index 0000000..12377a2 --- /dev/null +++ b/includes/admin/debug-tools/class-wcs-debug-tool-factory.php @@ -0,0 +1,114 @@ + System Status > Tools administration screen. + * + * @author Prospress + * @category Admin + * @package WooCommerce Subscriptions/Admin + * @version 2.3 + * @since 2.3 + */ + +if ( ! defined( 'ABSPATH' ) ) { + exit; +} // Exit if accessed directly + +/** + * WCS_Debug_Tool_Factory Class + * + * Add debug tools to the WooCommerce > System Status > Tools page. + */ +final class WCS_Debug_Tool_Factory { + + /** + * Add a debug tool for manually managing a data store's cache. + * + * @param string $tool_type A known type of cache tool. Known types are 'eraser' or 'generator'. + * @param string $tool_name The section name given to the tool on the admin screen. + * @param string $tool_desc The long description for the tool on the admin screen. + * @param WCS_Cache_Updater $data_store + */ + public static function add_cache_tool( $tool_type, $tool_name, $tool_desc, WCS_Cache_Updater $data_store ) { + + if ( ! is_admin() && ! defined( 'DOING_CRON' ) && ! defined( 'WP_CLI' ) ) { + return; + } + + self::load_cache_tool_file( $tool_type ); + $tool_class_name = self::get_cache_tool_class_name( $tool_type ); + $tool_key = self::get_tool_key( $tool_name ); + if ( 'generator' === $tool_type ) { + $cache_updater = new WCS_Debug_Tool_Cache_Background_Updater( $tool_key, $data_store ); + $tool = new $tool_class_name( $tool_key, $tool_name, $tool_desc, $data_store, $cache_updater ); + } else { + $tool = new $tool_class_name( $tool_key, $tool_name, $tool_desc, $data_store ); + } + $tool->init(); + } + + /** + * Get the string used to identify the tool. + * + * @param string The name of the cache tool being created + * @return string The key used to identify the tool - sanitized name with wcs_ prefix. + */ + protected static function get_tool_key( $tool_name ) { + return sprintf( 'wcs_%s', str_replace( ' ', '_', strtolower( $tool_name ) ) ); + } + + /** + * Get a cache tool's class name by passing in the cache name and type. + * + * For example, get_cache_tool_class_name( 'related-order', 'generator' ) will return WCS_Debug_Tool_Related_Order_Cache_Generator. + * + * To make sure the class's file is loaded, call @see self::load_cache_tool_class() first. + * + * @param array $cache_tool_type The type of cache tool. Known tools are 'eraser' and 'generator'. + * @return string The cache tool's class name. + */ + protected static function get_cache_tool_class_name( $cache_tool_type ) { + $tool_class_name = sprintf( 'WCS_Debug_Tool_Cache_%s', ucfirst( $cache_tool_type ) ); + + if ( ! class_exists( $tool_class_name ) ) { + throw new InvalidArgumentException( sprintf( '%s() requires a path to load %s. Class does not exist after loading %s.', __METHOD__, $class_name, $file_path ) ); + } + + return $tool_class_name; + } + + /** + * Load a cache tool file in the default file path. + * + * For example, load_cache_tool( 'related-order', 'generator' ) will load the file includes/admin/debug-tools/class-wcs-debug-tool-related-order-cache-generator.php + * + * @param array $cache_tool_type The type of cache tool. Known tools are 'eraser' and 'generator'. + */ + protected static function load_cache_tool_file( $cache_tool_type ) { + $file_path = sprintf( 'includes/admin/debug-tools/class-wcs-debug-tool-cache-%s.php', $cache_tool_type ); + $file_path = plugin_dir_path( WC_Subscriptions::$plugin_file ) . $file_path; + + if ( ! file_exists( $file_path ) ) { + throw new InvalidArgumentException( sprintf( '%s() requires a cache name linked to a valid debug tool. File does not exist: %s', __METHOD__, $rel_file_path ) ); + } + + self::load_required_classes( $cache_tool_type ); + require_once( $file_path ); + } + + /** + * Load classes that debug tools extend. + * + * @param array $cache_tool_type The type of cache tool. Known tools are 'eraser' and 'generator'. + */ + protected static function load_required_classes( $cache_tool_type ) { + + require_once( plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'includes/abstracts/abstract-wcs-debug-tool-cache-updater.php' ); + + if ( 'generator' === $cache_tool_type ) { + require_once( plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'includes/admin/debug-tools/class-wcs-debug-tool-cache-background-updater.php' ); + } + } +} diff --git a/includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php b/includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php index 6870865..d8e9270 100755 --- a/includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php +++ b/includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php @@ -71,18 +71,13 @@ class WCS_Meta_Box_Related_Orders { $initial_subscriptions = wcs_get_subscriptions_for_resubscribe_order( $this_subscription ); - $resubscribed_subscriptions = get_posts( array( - 'meta_key' => '_subscription_resubscribe', - 'meta_value' => $post->ID, - 'post_type' => 'shop_subscription', - 'post_status' => 'any', - 'posts_per_page' => -1, - ) ); + $resubscribe_order_ids = WCS_Related_Order_Store::instance()->get_related_order_ids( $this_subscription, 'resubscribe' ); - foreach ( $resubscribed_subscriptions as $subscription ) { - $subscription = wcs_get_subscription( $subscription ); - wcs_set_objects_property( $subscription, 'relationship', _x( 'Resubscribed Subscription', 'relation to order', 'woocommerce-subscriptions' ), 'set_prop_only' ); - $orders[] = $subscription; + foreach ( $resubscribe_order_ids as $order_id ) { + $order = wc_get_order( $order_id ); + $relation = wcs_is_subscription( $order ) ? _x( 'Resubscribed Subscription', 'relation to order', 'woocommerce-subscriptions' ) : _x( 'Resubscribe Order', 'relation to order', 'woocommerce-subscriptions' ); + wcs_set_objects_property( $order, 'relationship', $relation, 'set_prop_only' ); + $orders[] = $order; } } else if ( wcs_order_contains_subscription( $post->ID, array( 'resubscribe' ) ) ) { $initial_subscriptions = wcs_get_subscriptions_for_order( $post->ID, array( 'order_type' => array( 'resubscribe' ) ) ); diff --git a/includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php b/includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php index 5657cf0..5073822 100755 --- a/includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php +++ b/includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php @@ -97,8 +97,30 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data { ?>

- - + get_parent(); + if ( $parent_order ) { ?> +

+ + + get_order_number() ) ); ?> + +

+ +

+ + 'wc-enhanced-select', + 'name' => 'parent-order-id', + 'id' => 'parent-order-id', + 'placeholder' => esc_attr__( 'Select an order…', 'woocommerce-subscriptions' ), + ) ); + ?> +

+
@@ -302,6 +324,19 @@ class WCS_Meta_Box_Subscription_Data extends WC_Meta_Box_Order_Data { wcs_set_objects_property( $subscription, $field['id'], wc_clean( $_POST[ $field['id'] ] ) ); } + // Save the linked parent order id + if ( ! empty( $_POST['parent-order-id'] ) ) { + // if the parent order to be set is a renewal order + if ( wcs_order_contains_renewal( $_POST['parent-order-id'] ) ) { + // remove renewal meta + $parent = wc_get_order( $_POST['parent-order-id'] ); + wcs_delete_objects_property( $parent, 'subscription_renewal' ); + } + $subscription->set_parent_id( wc_clean( $_POST['parent-order-id'] ) ); + $subscription->add_order_note( sprintf( _x( 'Subscription linked to parent order %s via admin.', 'subscription note after linking to a parent order', 'woocommerce-subscriptions' ), sprintf( '#%2$s ', esc_url( wcs_get_edit_post_link( $subscription->get_parent_id() ) ), $subscription->get_parent()->get_order_number() ) ), false, true ); + $subscription->save(); + } + try { WCS_Change_Payment_Method_Admin::save_meta( $subscription ); diff --git a/includes/admin/meta-boxes/views/html-subscription-schedule.php b/includes/admin/meta-boxes/views/html-subscription-schedule.php index 09c89d1..25e2f06 100755 --- a/includes/admin/meta-boxes/views/html-subscription-schedule.php +++ b/includes/admin/meta-boxes/views/html-subscription-schedule.php @@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) { echo woocommerce_wp_select( array( 'id' => '_billing_interval', 'class' => 'billing_interval', - 'label' => __( 'Recurring:', 'woocommerce-subscriptions' ), + 'label' => __( 'Payment:', 'woocommerce-subscriptions' ), 'value' => $the_subscription->get_billing_interval(), 'options' => wcs_get_subscription_period_interval_strings(), ) @@ -42,7 +42,7 @@ if ( ! defined( 'ABSPATH' ) ) { get_billing_interval() ) ), esc_html( wcs_get_subscription_period_strings( 1, $the_subscription->get_billing_period() ) ) ); ?>
- + $date_label ) : ?> diff --git a/includes/admin/reports/class-wcs-report-cache-manager.php b/includes/admin/reports/class-wcs-report-cache-manager.php index 80151fd..97d071e 100755 --- a/includes/admin/reports/class-wcs-report-cache-manager.php +++ b/includes/admin/reports/class-wcs-report-cache-manager.php @@ -337,11 +337,13 @@ class WCS_Report_Cache_Manager { $new_data = array( 'wcs_report_cache_enabled' => array( 'name' => _x( 'Report Cache Enabled', 'Whether the Report Cache has been enabled', 'woocommerce-subscriptions' ), + 'label' => 'Report Cache Enabled', 'note' => $cache_enabled ? __( 'Yes', 'woocommerce-subscriptions' ) : __( 'No', 'woocommerce-subscriptions' ), 'success' => $cache_enabled, ), 'wcs_cache_update_failures' => array( 'name' => __( 'Cache Update Failures', 'woocommerce-subscriptions' ), + 'label' => 'Cache Update Failures', /* translators: %d refers to the number of times we have detected cache update failures */ 'note' => sprintf( _n( '%d failures', '%d failure', $failures, 'woocommerce-subscriptions' ), $failures ), 'success' => 0 === $failures, diff --git a/includes/admin/reports/class-wcs-report-subscription-by-product.php b/includes/admin/reports/class-wcs-report-subscription-by-product.php index 97072ff..9b53c50 100755 --- a/includes/admin/reports/class-wcs-report-subscription-by-product.php +++ b/includes/admin/reports/class-wcs-report-subscription-by-product.php @@ -55,7 +55,12 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { switch ( $column_name ) { case 'product_name' : - return edit_post_link( $report_item->product_name, null, null, $report_item->product_id ); + // If the product is a subscription variation, use the parent product's edit post link + if ( $report_item->parent_product_id > 0 ) { + return edit_post_link( $report_item->product_name, ' - ', null, $report_item->parent_product_id ); + } else { + return edit_post_link( $report_item->product_name, null, null, $report_item->product_id ); + } case 'subscription_count' : return sprintf( '%d', admin_url( 'edit.php?post_type=shop_subscription&_wcs_product=' ), $report_item->product_id, $report_item->subscription_count ); @@ -114,6 +119,7 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { $query = apply_filters( 'wcs_reports_product_query', "SELECT product.id as product_id, + product.post_parent as parent_product_id, product.post_title as product_name, mo.product_type, COUNT(subscription_line_items.subscription_id) as subscription_count, @@ -136,14 +142,14 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2 ON wcoimeta2.order_item_id = wcoitems.order_item_id WHERE wcoitems.order_item_type = 'line_item' - AND wcoimeta.meta_key = '_product_id' + AND ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' ) AND wcoimeta2.meta_key = '_line_total' ) as subscription_line_items ON product.id = subscription_line_items.product_id LEFT JOIN {$wpdb->posts} as subscriptions ON subscriptions.ID = subscription_line_items.subscription_id WHERE product.post_status = 'publish' - AND product.post_type = 'product' + AND ( product.post_type = 'product' OR product.post_type = 'product_variation' ) AND subscriptions.post_type = 'shop_subscription' AND subscriptions.post_status NOT IN( 'wc-pending', 'trash' ) GROUP BY product.id @@ -160,6 +166,33 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { $report_data = $cached_results[ $query_hash ]; + // Organize subscription variations under the parent product in a tree structure + $tree = array(); + foreach ( $report_data as $product_id => $product ) { + if ( ! $product->parent_product_id ) { + if ( isset( $tree[ $product_id ] ) ) { + array_unshift( $tree[ $product_id ], $product_id ); + } else { + $tree[ $product_id ][] = $product_id; + } + } else { + $tree[ $product->parent_product_id ][] = $product_id; + } + } + + // Create an array with all the report data in the correct order + $ordered_report_data = array(); + foreach ( $tree as $parent_id => $children ) { + foreach ( $children as $child_id ) { + $ordered_report_data[ $child_id ] = $report_data[ $child_id ]; + + // When there are variations, store the variation ids. + if ( 'variable-subscription' === $report_data[ $child_id ]->product_type ) { + $ordered_report_data[ $child_id ]->variations = array_diff( $children, array( $parent_id ) ); + } + } + } + // Now let's get the total revenue for each product so we can provide an average lifetime value for that product $query = apply_filters( 'wcs_reports_product_lifetime_value_query', "SELECT wcoimeta.meta_value as product_id, SUM(wcoimeta2.meta_value) as product_total @@ -172,7 +205,7 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { ON wcoimeta.order_item_id = wcoitems.order_item_id INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS wcoimeta2 ON wcoimeta2.order_item_id = wcoitems.order_item_id - WHERE wcoimeta.meta_key = '_product_id' + WHERE ( wcoimeta.meta_key = '_product_id' OR wcoimeta.meta_key = '_variation_id' ) AND wcoimeta2.meta_key = '_line_total' GROUP BY product_id" ); @@ -185,11 +218,11 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { } // Add the product total to each item - foreach ( array_keys( $report_data ) as $product_id ) { - $report_data[ $product_id ]->product_total = isset( $cached_results[ $query_hash ][ $product_id ] ) ? $cached_results[ $query_hash ][ $product_id ]->product_total : 0; + foreach ( array_keys( $ordered_report_data ) as $product_id ) { + $ordered_report_data[ $product_id ]->product_total = isset( $cached_results[ $query_hash ][ $product_id ] ) ? $cached_results[ $query_hash ][ $product_id ]->product_total : 0; } - return $report_data; + return $ordered_report_data; } /** @@ -199,20 +232,77 @@ class WC_Report_Subscription_By_Product extends WP_List_Table { $chart_colors = array( '#33a02c', '#1f78b4', '#6a3d9a', '#e31a1c', '#ff7f00', '#b15928', '#a6cee3', '#b2df8a', '#fb9a99', '#ffff99', '#fdbf6f', '#cab2d6' ); - //We only will display the first 12 plans in the chart - $products = array_slice( $this->items, 0, 12 ); + // We only will display the first 12 plans of parent products in the chart + $products = array_slice( wp_list_filter( $this->items, array( 'parent_product_id' => 0 ) ), 0, 12 ); + // Filter top n variations corresponding to top 12 parent products + $variations = array(); + foreach ( $products as $product ) { + if ( ! empty( $product->variations ) ) { // Variable subscription + foreach ( $product->variations as $variation_id ) { + $variations[] = $this->items[ $variation_id ]; + } + } else { // Simple subscription + $variations[] = $product; + } + } ?>
-
+
+
-
+
diff --git a/includes/admin/reports/class-wcs-report-subscription-events-by-date.php b/includes/admin/reports/class-wcs-report-subscription-events-by-date.php index 3c40c96..088c4c4 100755 --- a/includes/admin/reports/class-wcs-report-subscription-events-by-date.php +++ b/includes/admin/reports/class-wcs-report-subscription-events-by-date.php @@ -66,6 +66,13 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { 'name' => 'post_date', ), ), + 'where' => array( + 'post_status' => array( + 'key' => 'post_status', + 'operator' => 'NOT IN', + 'value' => array( 'trash', 'auto-draft' ), + ), + ), 'group_by' => $this->group_by_query, 'order_status' => '', 'order_by' => 'post_date ASC', @@ -102,6 +109,13 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { 'join_type' => 'LEFT', // To avoid issues if there is no renewal_total meta ), ), + 'where' => array( + 'post_status' => array( + 'key' => 'post_status', + 'operator' => 'NOT IN', + 'value' => array( 'trash', 'auto-draft' ), + ), + ), 'group_by' => $this->group_by_query, 'order_status' => $args['order_status'], 'order_by' => 'post_date ASC', @@ -138,6 +152,13 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { 'join_type' => 'LEFT', // To avoid issues if there is no resubscribe_total meta ), ), + 'where' => array( + 'post_status' => array( + 'key' => 'post_status', + 'operator' => 'NOT IN', + 'value' => array( 'trash', 'auto-draft' ), + ), + ), 'group_by' => $this->group_by_query, 'order_status' => $args['order_status'], 'order_by' => 'post_date ASC', @@ -168,6 +189,13 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { 'name' => 'switch_orders', ), ), + 'where' => array( + 'post_status' => array( + 'key' => 'post_status', + 'operator' => 'NOT IN', + 'value' => array( 'trash', 'auto-draft' ), + ), + ), 'group_by' => $this->group_by_query, 'order_status' => $args['order_status'], 'order_by' => 'post_date ASC', @@ -195,6 +223,7 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { WHERE subscription_posts.post_type = 'shop_subscription' AND subscription_posts.post_date >= %s AND subscription_posts.post_date < %s + AND subscription_posts.post_status NOT IN ( 'trash', 'auto-draft' ) GROUP BY order_id ) AS subscriptions ON subscriptions.order_id = order_posts.ID LEFT JOIN {$wpdb->postmeta} AS order_total_post_meta @@ -295,6 +324,7 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { JOIN {$wpdb->postmeta} AS wcsmeta_cancel ON wcsubs.ID = wcsmeta_cancel.post_id AND wcsmeta_cancel.meta_key = %s + AND wcsubs.post_status NOT IN ( 'trash', 'auto-draft' ) GROUP BY YEAR( cancel_date ), MONTH( cancel_date ), DAY( cancel_date ) HAVING cancel_date BETWEEN %s AND %s ORDER BY wcsmeta_cancel.meta_value ASC", @@ -322,6 +352,7 @@ class WC_Report_Subscription_Events_By_Date extends WC_Admin_Report { JOIN {$wpdb->postmeta} AS wcsmeta_end ON wcsubs.ID = wcsmeta_end.post_id AND wcsmeta_end.meta_key = %s + AND wcsubs.post_status NOT IN ( 'trash', 'auto-draft' ) GROUP BY YEAR( end_date ), MONTH( end_date ), DAY( end_date ) HAVING end_date BETWEEN %s AND %s ORDER BY wcsmeta_end.meta_value ASC", diff --git a/includes/class-wc-product-variable-subscription.php b/includes/class-wc-product-variable-subscription.php index b74fc97..32b253d 100755 --- a/includes/class-wc-product-variable-subscription.php +++ b/includes/class-wc-product-variable-subscription.php @@ -16,8 +16,18 @@ if ( ! defined( 'ABSPATH' ) ) { class WC_Product_Variable_Subscription extends WC_Product_Variable { - private $min_max_variation_data = array(); + /** + * A cache of the variable product's min and max data generated by @see wcs_get_min_max_variation_data(). + * + * @var array + */ + protected $min_max_variation_data = array(); + /** + * A cache of the variable product's sorted variation prices. + * + * @var array + */ private $sorted_variation_prices = array(); /** @@ -141,15 +151,10 @@ class WC_Product_Variable_Subscription extends WC_Product_Variable { if ( empty( $this->sorted_variation_prices[ $prices_hash ] ) ) { - $child_variation_ids = array_keys( $prices ); - $variation_hash = md5( json_encode( $child_variation_ids ) ); + $min_max_variation_data = $this->get_min_and_max_variation_data( array_keys( $prices ) ); - if ( empty( $this->min_max_variation_data[ $variation_hash ] ) ) { - $this->min_max_variation_data[ $variation_hash ] = wcs_get_min_max_variation_data( $this, $child_variation_ids ); - } - - $min_variation_id = $this->min_max_variation_data[ $variation_hash ]['min']['variation_id']; - $max_variation_id = $this->min_max_variation_data[ $variation_hash ]['max']['variation_id']; + $min_variation_id = $min_max_variation_data['min']['variation_id']; + $max_variation_id = $min_max_variation_data['max']['variation_id']; // Reorder the variable price arrays to reflect the min and max values so that WooCommerce will find them in the correct order $min_price = $prices[ $min_variation_id ]; @@ -168,6 +173,66 @@ class WC_Product_Variable_Subscription extends WC_Product_Variable { return $this->sorted_variation_prices[ $prices_hash ]; } + /** + * Set the product's min and max variation data. + * + * @param array $min_and_max_data The min and max variation data returned by @see wcs_get_min_max_variation_data(). Optional. + * @param array $variation_ids The child variation IDs. Optional. By default this value be generated by @see WC_Product_Variable->get_visible_children(). + * @since 2.3.0 + */ + public function set_min_and_max_variation_data( $min_and_max_data = array(), $variation_ids = array() ) { + + if ( empty( $variation_ids ) ) { + $variation_ids = $this->get_visible_children(); + } + + if ( empty( $min_and_max_data ) ) { + $min_and_max_data = wcs_get_min_max_variation_data( $this, $variation_ids ); + } + + $this->add_meta_data( '_min_max_variation_data', $min_and_max_data, true ); + $this->add_meta_data( '_min_max_variation_ids_hash', $this->get_variation_ids_hash( $variation_ids ), true ); + } + + /** + * Get the min and max variation data. + * + * This is a wrapper for @see wcs_get_min_max_variation_data() but to avoid calling + * that resource intensive function multiple times per request, check the value + * stored in meta or cached in memory before calling that function. + * + * @param array $variation_ids An array of variation IDs. + * @return array The variable product's min and max variation data. + * @since 2.3.0 + */ + public function get_min_and_max_variation_data( $variation_ids ) { + $variation_ids_hash = $this->get_variation_ids_hash( $variation_ids ); + + if ( $variation_ids_hash === $this->get_meta( '_min_max_variation_ids_hash', true ) ) { + $min_and_max_variation_data = $this->get_meta( '_min_max_variation_data', true ); + } elseif ( ! empty( $this->min_max_variation_data[ $variation_ids_hash ] ) ) { + $min_and_max_variation_data = $this->min_max_variation_data[ $variation_ids_hash ]; + } else { + $min_and_max_variation_data = wcs_get_min_max_variation_data( $this, $variation_ids ); + $this->min_max_variation_data[ $variation_ids_hash ] = $min_and_max_variation_data; + } + + return $min_and_max_variation_data; + } + + /** + * Generate a unique hash from an array of variation IDs. + * + * @param array $variation_ids + * @return string + */ + protected static function get_variation_ids_hash( $variation_ids ) { + // Sort the variation IDs so the hash isn't different for the same array of IDs + sort( $variation_ids ); + + return md5( json_encode( $variation_ids ) ); + } + /* Deprecated Functions */ /** @@ -235,15 +300,11 @@ class WC_Product_Variable_Subscription extends WC_Product_Variable { */ protected function get_price_prefix( $prices ) { + $child_variation_ids = array_keys( $prices['price'] ); + $min_max_variation_data = $this->get_min_and_max_variation_data( $child_variation_ids ); + // Are the subscription details of all variations identical? - $child_variation_ids = array_keys( $prices['price'] ); - $variation_hash = md5( json_encode( $child_variation_ids ) ); - - if ( empty( $this->min_max_variation_data[ $variation_hash ] ) ) { - $this->min_max_variation_data[ $variation_hash ] = wcs_get_min_max_variation_data( $this, $child_variation_ids ); - } - - if ( $this->min_max_variation_data[ $variation_hash ]['identical'] ) { + if ( $min_max_variation_data['identical'] ) { $prefix = ''; } else { $prefix = wcs_get_price_html_from_text( $this ); diff --git a/includes/class-wc-subscription.php b/includes/class-wc-subscription.php index d88ca2f..2be8f59 100755 --- a/includes/class-wc-subscription.php +++ b/includes/class-wc-subscription.php @@ -94,7 +94,7 @@ class WC_Subscription extends WC_Order { /** * Initialize the subscription object. * - * @param int|WC_Subscription $order + * @param int|WC_Subscription $subscription */ public function __construct( $subscription ) { @@ -257,30 +257,10 @@ class WC_Subscription extends WC_Order { // And finally, check that the latest order (switch or renewal) doesn't need payment } else { - $last_order_id = get_posts( array( - 'posts_per_page' => 1, - 'post_type' => 'shop_order', - 'post_status' => 'any', - 'fields' => 'ids', - 'orderby' => 'ID', - 'order' => 'DESC', - 'meta_query' => array( - array( - 'key' => '_subscription_renewal', - 'compare' => '=', - 'value' => $this->get_id(), - 'type' => 'numeric', - ), - ), - ) ); + $order = $this->get_last_order( 'all', array( 'renewal', 'switch' ) ); - if ( ! empty( $last_order_id ) ) { - - $order = wc_get_order( $last_order_id[0] ); - - if ( $order->needs_payment() || $order->has_status( array( 'on-hold', 'failed', 'cancelled' ) ) ) { - $needs_payment = true; - } + if ( $order && ( $order->needs_payment() || $order->has_status( array( 'on-hold', 'failed', 'cancelled' ) ) ) ) { + $needs_payment = true; } } @@ -654,49 +634,21 @@ class WC_Subscription extends WC_Order { $completed_payment_count = ( ( $parent_order = $this->get_parent() ) && ( null !== wcs_get_objects_property( $parent_order, 'date_paid' ) || $parent_order->has_status( $this->get_paid_order_statuses() ) ) ) ? 1 : 0; - // Get all renewal orders - for large sites its more efficient to find the two different sets of renewal orders below using post__in than complicated meta queries - $renewal_orders = get_posts( array( - 'posts_per_page' => -1, - 'post_status' => 'any', - 'post_type' => 'shop_order', - 'fields' => 'ids', - 'orderby' => 'date', - 'order' => 'desc', - 'meta_key' => '_subscription_renewal', - 'meta_compare' => '=', - 'meta_type' => 'numeric', - 'meta_value' => $this->get_id(), - 'update_post_term_cache' => false, - ) ); + $paid_renewal_orders = array(); + $renewal_order_ids = $this->get_related_order_ids( 'renewal' ); - if ( ! empty( $renewal_orders ) ) { + if ( ! empty( $renewal_order_ids ) ) { - // Not all gateways will call $order->payment_complete() so we need to find renewal orders with a paid status rather than just a _paid_date - $paid_status_renewal_orders = get_posts( array( - 'posts_per_page' => -1, - 'post_status' => $this->get_paid_order_statuses(), - 'post_type' => 'shop_order', - 'fields' => 'ids', - 'orderby' => 'date', - 'order' => 'desc', - 'post__in' => $renewal_orders, - ) ); + // Looping over the known orders is faster than database queries on large sites + foreach ( $renewal_order_ids as $renewal_order_id ) { - // Some stores may be using custom order status plugins, we also can't rely on order status to find paid orders, so also check for a _paid_date - $paid_date_renewal_orders = get_posts( array( - 'posts_per_page' => -1, - 'post_status' => 'any', - 'post_type' => 'shop_order', - 'fields' => 'ids', - 'orderby' => 'date', - 'order' => 'desc', - 'post__in' => $renewal_orders, - 'meta_key' => '_paid_date', - 'meta_compare' => 'EXISTS', - 'update_post_term_cache' => false, - ) ); + $renewal_order = wc_get_order( $renewal_order_id ); - $paid_renewal_orders = array_unique( array_merge( $paid_date_renewal_orders, $paid_status_renewal_orders ) ); + // Not all gateways call $order->payment_complete(), so with WC < 3.0 we need to find renewal orders with a paid date or a paid status. WC 3.0+ takes care of setting the paid date when payment_complete() wasn't called, so isn't needed with WC 3.0 or newer. + if ( $renewal_order && ( null !== wcs_get_objects_property( $renewal_order, 'date_paid' ) || $renewal_order->has_status( $this->get_paid_order_statuses() ) ) ) { + $paid_renewal_orders[] = $renewal_order_id; + } + } if ( ! empty( $paid_renewal_orders ) ) { $completed_payment_count += count( $paid_renewal_orders ); @@ -723,25 +675,10 @@ class WC_Subscription extends WC_Order { $failed_payment_count = ( ( $parent_order = $this->get_parent() ) && $parent_order->has_status( 'failed' ) ) ? 1 : 0; - $failed_renewal_orders = get_posts( array( - 'posts_per_page' => -1, - 'post_status' => 'wc-failed', - 'post_type' => 'shop_order', - 'fields' => 'ids', - 'orderby' => 'date', - 'order' => 'desc', - 'meta_query' => array( - array( - 'key' => '_subscription_renewal', - 'compare' => '=', - 'value' => $this->get_id(), - 'type' => 'numeric', - ), - ), - ) ); - - if ( ! empty( $failed_renewal_orders ) ) { - $failed_payment_count += count( $failed_renewal_orders ); + foreach ( $this->get_related_orders( 'all', 'renewal' ) as $renewal_order ) { + if ( $renewal_order->has_status( 'failed' ) ) { + $failed_payment_count++; + } } return apply_filters( 'woocommerce_subscription_payment_failed_count', $failed_payment_count, $this ); @@ -1079,10 +1016,10 @@ class WC_Subscription extends WC_Order { * * @since 2.2.0 * @param string $date_type Any valid WC 3.0 date property, including 'date_paid', 'date_completed', 'date_created', or 'date_modified' - * @param string $order_type The type of orders to return, can be 'last', 'parent', 'switch', 'renewal' or 'all'. Default 'all'. Use 'last' to only check the last order. + * @param string $order_type The type of orders to return, can be 'last', 'parent', 'switch', 'renewal' or 'any'. Default 'any'. Use 'last' to only check the last order. * @return WC_DateTime|NULL object if the date is set or null if there is no date. */ - protected function get_related_orders_date( $date_type, $order_type = 'all' ) { + protected function get_related_orders_date( $date_type, $order_type = 'any' ) { $date = null; @@ -1091,7 +1028,7 @@ class WC_Subscription extends WC_Order { $date = ( ! $last_order ) ? null : wcs_get_objects_property( $last_order, $date_type ); } else { // Loop over orders until we find a valid date of this type or run out of related orders - foreach ( $this->get_related_orders( 'ids', $order_type ) as $related_order_id ) { + foreach ( $this->get_related_orders( 'all', $order_type ) as $related_order_id ) { $related_order = wc_get_order( $related_order_id ); $date = ( ! $related_order ) ? null : wcs_get_objects_property( $related_order, $date_type ); if ( is_a( $date, 'WC_Datetime' ) ) { @@ -1813,69 +1750,77 @@ class WC_Subscription extends WC_Order { * Extracting the query from get_related_orders and get_last_order so it can be moved in a cached * value. * + * @deprecated 2.3.0 Moved to WCS_Subscription_Data_Store_CPT::get_related_order_ids() to separate cache logic from subscription instances and to avoid confusion from the misnomer on this method's name - it gets renewal orders, not related orders - and its ambiguity - it runs a query and returns order IDs, it does not return a SQL query string or order objects. * @return array */ - public function get_related_orders_query( $id ) { - $related_post_ids = get_posts( array( - 'posts_per_page' => -1, - 'post_type' => 'shop_order', - 'post_status' => 'any', - 'fields' => 'ids', - 'orderby' => 'date', - 'order' => 'DESC', - 'meta_query' => array( - array( - 'key' => '_subscription_renewal', - 'compare' => '=', - 'value' => $id, - 'type' => 'numeric', - ), - ), - ) ); - - return $related_post_ids; + public function get_related_orders_query( $subscription_id ) { + wcs_deprecated_function( __METHOD__, '2.3.0', 'WCS_Subscription_Data_Store_CPT::get_related_order_ids( $subscription_id ) via WCS_Subscription_Data_Store::instance()' ); + return WCS_Related_Order_Store::instance()->get_related_order_ids( $subscription_id, 'renewal' ); } /** * Get the related orders for a subscription, including renewal orders and the initial order (if any) * * @param string $return_fields The columns to return, either 'all' or 'ids' - * @param string $order_type The type of orders to return, either 'renewal' or 'all'. Default 'all'. + * @param array|string $order_types Can include 'any', 'parent', 'renewal', 'resubscribe' and/or 'switch'. Custom types possible via the 'woocommerce_subscription_related_orders' filter. Defaults to array( 'parent', 'renewal' ). * @since 2.0 + * @return array */ - public function get_related_orders( $return_fields = 'ids', $order_type = 'all' ) { + public function get_related_orders( $return_fields = 'ids', $order_types = array( 'parent', 'renewal' ) ) { $return_fields = ( 'ids' == $return_fields ) ? $return_fields : 'all'; + if ( 'all' === $order_types ) { + wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'The "all" value for $order_type parameter is deprecated. It was a misnomer, as it did not return resubscribe orders. It was also inconsistent with order type values accepted by wcs_get_subscription_orders(). Use array( "parent", "renewal", "switch" ) to maintain previous behaviour, or "any" to receive all order types, including switch and resubscribe.', 'woocommerce-subscriptions' ), __CLASS__ ) ); + $order_types = array( 'parent', 'renewal', 'switch' ); + } elseif ( ! is_array( $order_types ) ) { + // Accept either an array or string (to make it more convenient for singular types, like 'parent' or 'any') + $order_types = array( $order_types ); + } + $related_orders = array(); + foreach ( $order_types as $order_type ) { - $related_post_ids = WC_Subscriptions::$cache->cache_and_get( 'wcs-related-orders-to-' . $this->get_id(), array( $this, 'get_related_orders_query' ), array( $this->get_id() ) ); - - if ( 'all' == $return_fields ) { - - foreach ( $related_post_ids as $post_id ) { - $related_orders[ $post_id ] = wc_get_order( $post_id ); + $related_orders_for_order_type = array(); + foreach ( $this->get_related_order_ids( $order_type ) as $order_id ) { + $related_orders_for_order_type[ $order_id ] = ( 'all' == $return_fields ) ? wc_get_order( $order_id ) : $order_id; } - if ( false != $this->get_parent_id() && 'renewal' !== $order_type ) { - $related_orders[ $this->get_parent_id() ] = $this->get_parent(); - } - } else { + $related_orders += apply_filters( 'woocommerce_subscription_related_orders', $related_orders_for_order_type, $this, $return_fields, $order_type ); + } - // Return IDs only - if ( false != $this->get_parent_id() && 'renewal' !== $order_type ) { - $related_orders[ $this->get_parent_id() ] = $this->get_parent_id(); - } + arsort( $related_orders ); - foreach ( $related_post_ids as $post_id ) { - $related_orders[ $post_id ] = $post_id; + return $related_orders; + } + + /** + * Get the related order IDs for a subscription based on an order type. + * + * @param string $order_type Can include 'any', 'parent', 'renewal', 'resubscribe' and/or 'switch'. Defaults to 'any'. + * @return array List of related order IDs. + * @since 2.3.0 + */ + protected function get_related_order_ids( $order_type = 'any' ) { + + $related_order_ids = array(); + + if ( in_array( $order_type, array( 'any', 'parent' ) ) && $this->get_parent_id() ) { + $related_order_ids[ $this->get_parent_id() ] = $this->get_parent_id(); + } + + if ( 'parent' !== $order_type ) { + + $relation_types = ( 'any' === $order_type ) ? array( 'renewal', 'resubscribe', 'switch' ) : array( $order_type ); + + foreach ( $relation_types as $relation_type ) { + $related_order_ids = array_merge( $related_order_ids, WCS_Related_Order_Store::instance()->get_related_order_ids( $this, $relation_type ) ); } } - return apply_filters( 'woocommerce_subscription_related_orders', $related_orders, $this, $return_fields, $order_type ); + return $related_order_ids; } - /** * Gets the most recent order that relates to a subscription, including renewal orders and the initial order (if any). * @@ -1896,13 +1841,8 @@ class WC_Subscription extends WC_Order { $related_orders[] = $this->get_parent_id(); } break; - case 'renewal': - $related_orders = array_merge( $related_orders, WC_Subscriptions::$cache->cache_and_get( 'wcs-related-orders-to-' . $this->get_id(), array( $this, 'get_related_orders_query' ), array( $this->get_id() ) ) ); - break; - case 'switch': - $related_orders = array_merge( $related_orders, array_keys( wcs_get_switch_orders_for_subscription( $this->get_id() ) ) ); - break; default: + $related_orders = array_merge( $related_orders, $this->get_related_order_ids( $order_type ) ); break; } } @@ -2094,8 +2034,7 @@ class WC_Subscription extends WC_Order { /** * The total sign-up fee for the subscription if any. * - * @param array|int Either an order item (in the array format returned by self::get_items()) or the ID of an order item. - * @return bool + * @return int * @since 2.0 */ public function get_sign_up_fee() { @@ -2157,6 +2096,8 @@ class WC_Subscription extends WC_Order { } elseif ( 'true' === $line_item->get_meta( '_has_trial' ) ) { // Sign up is amount paid for this item on original order, we can safely use 3.0 getters here because we know from the above condition 3.0 is active $sign_up_fee = ( (float) $original_order_item->get_total( 'edit' ) ) / $original_order_item->get_quantity( 'edit' ); + } elseif ( $original_order_item->meta_exists( '_synced_sign_up_fee' ) ) { + $sign_up_fee = ( (float) $original_order_item->get_meta( '_synced_sign_up_fee' ) ) / $original_order_item->get_quantity( 'edit' ); } else { // Sign-up fee is any amount on top of recurring amount $order_line_total = ( (float) $original_order_item->get_total( 'edit' ) ) / $original_order_item->get_quantity( 'edit' ); @@ -2165,10 +2106,17 @@ class WC_Subscription extends WC_Order { $sign_up_fee = max( $order_line_total - $subscription_line_total, 0 ); } - // If prices inc tax, ensure that the sign up fee amount includes the tax - if ( 'inclusive_of_tax' === $tax_inclusive_or_exclusive && ! empty( $original_order_item ) && $this->get_prices_include_tax() ) { - $proportion = $sign_up_fee / ( $original_order_item->get_total( 'edit' ) / $original_order_item->get_quantity( 'edit' ) ); - $sign_up_fee += round( $original_order_item->get_total_tax( 'edit' ) * $proportion, 2 ); + if ( ! empty( $original_order_item ) && ! empty( $sign_up_fee ) ) { + $sign_up_fee_proportion = $sign_up_fee / ( $original_order_item->get_total( 'edit' ) / $original_order_item->get_quantity( 'edit' ) ); + $sign_up_fee_tax = wc_round_tax_total( $original_order_item->get_total_tax( 'edit' ) * $sign_up_fee_proportion ); + + // If prices don't inc tax, ensure that the sign up fee amount includes the tax. + if ( 'inclusive_of_tax' === $tax_inclusive_or_exclusive && ! $this->get_prices_include_tax() ) { + $sign_up_fee += $sign_up_fee_tax; + // If prices inc tax and the request is for prices exclusive of tax, remove the taxes. + } elseif ( 'inclusive_of_tax' !== $tax_inclusive_or_exclusive && $this->get_prices_include_tax() ) { + $sign_up_fee -= $sign_up_fee_tax; + } } } diff --git a/includes/class-wc-subscriptions-cart.php b/includes/class-wc-subscriptions-cart.php index 500d1f6..7e98fe6 100755 --- a/includes/class-wc-subscriptions-cart.php +++ b/includes/class-wc-subscriptions-cart.php @@ -124,6 +124,8 @@ class WC_Subscriptions_Cart { add_filter( 'woocommerce_add_to_cart_handler', __CLASS__ . '::add_to_cart_handler', 10, 2 ); add_action( 'woocommerce_cart_calculate_fees', __CLASS__ . '::apply_recurring_fees', 1000, 1 ); + + add_action( 'woocommerce_checkout_update_order_review', __CLASS__ . '::update_chosen_shipping_methods' ); } /** @@ -1159,11 +1161,16 @@ class WC_Subscriptions_Cart { $added_invalid_notice = true; } - WC()->checkout()->shipping_methods[ $recurring_shipping_package_key ] = ''; + $shipping_methods[ $recurring_shipping_package_key ] = ''; } } } + // If there was an invalid recurring shipping method found, we need to apply the changes to WC()->checkout()->shipping_methods. + if ( $added_invalid_notice ) { + WC()->checkout()->shipping_methods = $shipping_methods; + } + self::$calculation_type = $calculation_type; self::$recurring_cart_key = $recurring_cart_key_flag; } @@ -1294,6 +1301,35 @@ class WC_Subscriptions_Cart { } } + /** + * Update the chosen recurring package shipping methods from posted checkout form data. + * + * Between requests, the presence of recurring package chosen shipping methods in posted + * checkout data can change. For example, when the number of available shipping methods + * change and cause the hidden elements (generated by @see wcs_cart_print_shipping_input()) + * to be displayed or not displayed. + * + * When this occurs, we need to remove those chosen shipping methods from the session so + * that those packages no longer use the previously selected shipping method. + * + * @param string $encoded_form_data Encoded checkout form data. + * @since 2.3.0 + */ + public static function update_chosen_shipping_methods( $encoded_form_data ) { + $chosen_shipping_methods = WC()->session->get( 'chosen_shipping_methods', array() ); + + parse_str( $encoded_form_data, $form_data ); + + foreach ( $chosen_shipping_methods as $package_index => $method ) { + // Remove the chosen shipping methods for recurring packages which are no longer present in posted checkout data. + if ( ! is_numeric( $package_index ) && ! isset( $form_data['shipping_method'][ $package_index ] ) ) { + unset( $chosen_shipping_methods[ $package_index ] ); + } + } + + WC()->session->set( 'chosen_shipping_methods', $chosen_shipping_methods ); + } + /* Deprecated */ /** diff --git a/includes/class-wc-subscriptions-checkout.php b/includes/class-wc-subscriptions-checkout.php index 224d00c..5c46076 100755 --- a/includes/class-wc-subscriptions-checkout.php +++ b/includes/class-wc-subscriptions-checkout.php @@ -225,7 +225,7 @@ class WC_Subscriptions_Checkout { $subscription->set_total( $cart->total ); // Hook to adjust subscriptions before saving with WC 3.0+ (matches WC 3.0's new 'woocommerce_checkout_create_order' hook) - do_action( 'woocommerce_checkout_create_subscription', $subscription, $posted_data ); + do_action( 'woocommerce_checkout_create_subscription', $subscription, $posted_data, $order, $cart ); // Save the subscription if using WC 3.0 & CRUD $subscription->save(); diff --git a/includes/class-wc-subscriptions-coupon.php b/includes/class-wc-subscriptions-coupon.php index 6316efb..7980c2f 100755 --- a/includes/class-wc-subscriptions-coupon.php +++ b/includes/class-wc-subscriptions-coupon.php @@ -12,6 +12,13 @@ */ class WC_Subscriptions_Coupon { + /** + * The meta key used for the number of renewals. + * + * @var string + */ + protected static $coupons_renewals = '_wcs_number_payments'; + /** @var string error message for invalid subscription coupons */ public static $coupon_error; @@ -19,9 +26,31 @@ class WC_Subscriptions_Coupon { * Stores the coupons not applied to a given calculation (so they can be applied later) * * @since 1.3.5 + * @deprecated */ private static $removed_coupons = array(); + /** + * Subscription coupon types. + * + * @var array + */ + private static $recurring_coupons = array( + 'recurring_fee' => 1, + 'recurring_percent' => 1, + ); + + /** + * Virtual renewal coupon types. + * + * @var array + */ + private static $renewal_coupons = array( + 'renewal_cart' => 1, + 'renewal_fee' => 1, + 'renewal_percent' => 1, + ); + /** * Set up the class, including it's hooks & filters, when the file is loaded. * @@ -50,6 +79,63 @@ class WC_Subscriptions_Coupon { } add_filter( 'woocommerce_cart_totals_coupon_label', __CLASS__ . '::get_pseudo_coupon_label', 10, 2 ); + + add_filter( 'woocommerce_cart_totals_coupon_html', __CLASS__ . '::mark_recurring_coupon_in_initial_cart_for_hiding', 10, 3 ); + + // Hook recurring coupon functionality. + add_action( 'plugins_loaded', array( __CLASS__, 'maybe_add_recurring_coupon_hooks' ) ); + } + + /** + * Maybe add Recurring Coupon functionality. + * + * WC 3.2 added many API enhancements, especially around coupons. It would be very challenging to implement + * this functionality in older versions of WC, so we require 3.2+ to enable this. + * + * @author Jeremy Pry + */ + public static function maybe_add_recurring_coupon_hooks() { + if ( WC_Subscriptions::is_woocommerce_pre( '3.2' ) ) { + return; + } + + // Add custom coupon fields. + add_action( 'woocommerce_coupon_options', array( __CLASS__, 'add_coupon_fields' ), 10 ); + add_action( 'woocommerce_coupon_options_save', array( __CLASS__, 'save_coupon_fields' ), 10 ); + + // Filter the available payment gateways. + add_filter( 'woocommerce_available_payment_gateways', array( __CLASS__, 'gateways_subscription_amount_changes' ), 20 ); + + // Check coupons when a subscription is renewed. + add_action( 'woocommerce_subscription_payment_complete', array( __CLASS__, 'check_coupon_usages' ) ); + + // Add info to the Coupons list table. + add_action( 'manage_shop_coupon_posts_custom_column', array( __CLASS__, 'add_limit_to_list_table' ), 20, 2 ); + } + + /** + * When all items in the cart have free trial, a recurring coupon should not be applied to the main cart. + * Mark such recurring coupons with a dummy span with class wcs-hidden-coupon so that it can be hidden. + * + * @param string $coupon_html Html string of the recurring coupon's cell in the Cart totals table + * @param WC_coupon $coupon WC_Coupon object of the recurring coupon + * @return string $coupon_html Modified html string of the coupon containing the marking + * @since 2.3 + */ + public static function mark_recurring_coupon_in_initial_cart_for_hiding( $coupon_html, $coupon ) { + $displaying_initial_cart_totals = false; + + if ( is_cart() ) { + $displaying_initial_cart_totals = did_action( 'woocommerce_before_cart_totals' ) > did_action( 'woocommerce_cart_totals_before_order_total' ); + } elseif ( is_checkout() ) { + $displaying_initial_cart_totals = did_action( 'woocommerce_review_order_after_cart_contents' ) > did_action( 'woocommerce_review_order_before_order_total' ); + } + + if ( $displaying_initial_cart_totals && WC_Subscriptions_Cart::all_cart_items_have_free_trial() && in_array( wcs_get_coupon_property( $coupon, 'discount_type' ), array( 'recurring_fee', 'recurring_percent' ) ) ) { + $coupon_html .= ''; + } + + return $coupon_html; } /** @@ -435,55 +521,6 @@ class WC_Subscriptions_Coupon { } - /** - * Checks a given product / coupon combination to determine if the subscription should be discounted - * - * @since 1.2 - */ - private static function is_subscription_discountable( $cart_item, $coupon ) { - - $product_cats = wp_get_post_terms( $cart_item['product_id'], 'product_cat', array( 'fields' => 'ids' ) ); - - $this_item_is_discounted = false; - - // Specific products get the discount - if ( sizeof( $coupon_product_ids = wcs_get_coupon_property( $coupon, 'product_ids' ) ) > 0 ) { - - if ( in_array( wcs_get_canonical_product_id( $cart_item ), $coupon_product_ids ) || in_array( $cart_item['data']->get_parent(), $coupon_product_ids ) ) { - $this_item_is_discounted = true; - } - - // Category discounts - } elseif ( sizeof( $coupon_product_categories = wcs_get_coupon_property( $coupon, 'product_categories' ) ) > 0 ) { - - if ( sizeof( array_intersect( $product_cats, $coupon_product_categories ) ) > 0 ) { - $this_item_is_discounted = true; - } - } else { - - // No product ids - all items discounted - $this_item_is_discounted = true; - - } - - // Specific product ID's excluded from the discount - if ( sizeof( $coupon_excluded_product_ids = wcs_get_coupon_property( $coupon, 'exclude_product_ids' ) ) > 0 ) { - if ( in_array( wcs_get_canonical_product_id( $cart_item ), $coupon_excluded_product_ids ) || in_array( $cart_item['data']->get_parent(), $coupon_excluded_product_ids ) ) { - $this_item_is_discounted = false; - } - } - - // Specific categories excluded from the discount - if ( sizeof( $coupon_excluded_product_categories = wcs_get_coupon_property( $coupon, 'exclude_product_categories' ) ) > 0 ) { - if ( sizeof( array_intersect( $product_cats, $coupon_excluded_product_categories ) ) > 0 ) { - $this_item_is_discounted = false; - } - } - - // Apply filter - return apply_filters( 'woocommerce_item_is_discounted', $this_item_is_discounted, $cart_item, $before_tax = false ); - } - /** * Sets which coupons should be applied for this calculation. * @@ -491,53 +528,49 @@ class WC_Subscriptions_Coupon { * product's total based on the total of it's price per period and sign up fee (if any). * * @since 1.3.5 + * + * @param WC_Cart $cart */ public static function remove_coupons( $cart ) { - $calculation_type = WC_Subscriptions_Cart::get_calculation_type(); // Only hook when totals are being calculated completely (on cart & checkout pages) - if ( 'none' == $calculation_type || ! WC_Subscriptions_Cart::cart_contains_subscription() || ( ! is_checkout() && ! is_cart() && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! defined( 'WOOCOMMERCE_CART' ) ) ) { + if ( + 'none' === $calculation_type || + ! WC_Subscriptions_Cart::cart_contains_subscription() || + ( ! is_checkout() && ! is_cart() && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! defined( 'WOOCOMMERCE_CART' ) ) + ) { return; } $applied_coupons = $cart->get_applied_coupons(); + if ( empty( $applied_coupons ) ) { + return; + } // If we're calculating a sign-up fee or recurring fee only amount, remove irrelevant coupons - if ( ! empty( $applied_coupons ) ) { + foreach ( $applied_coupons as $coupon_code ) { + $coupon = new WC_Coupon( $coupon_code ); + $coupon_type = wcs_get_coupon_property( $coupon, 'discount_type' ); + if ( ! isset( self::$recurring_coupons[ $coupon_type ] ) ) { + $cart->remove_coupon( $coupon_code ); + continue; + } - // Keep track of which coupons, if any, need to be reapplied immediately - $coupons_to_reapply = array(); - - foreach ( $applied_coupons as $coupon_code ) { - - $coupon = new WC_Coupon( $coupon_code ); - $coupon_type = wcs_get_coupon_property( $coupon, 'discount_type' ); - - if ( in_array( $coupon_type, array( 'recurring_fee', 'recurring_percent' ) ) ) { // always apply coupons to their specific calculation case - if ( 'recurring_total' == $calculation_type ) { - $coupons_to_reapply[] = $coupon_code; - } elseif ( 'none' == $calculation_type && ! WC_Subscriptions_Cart::all_cart_items_have_free_trial() ) { // sometimes apply recurring coupons to initial total - $coupons_to_reapply[] = $coupon_code; - } else { - self::$removed_coupons[] = $coupon_code; - } - } elseif ( ( 'none' == $calculation_type ) && ! in_array( $coupon_type, array( 'recurring_fee', 'recurring_percent' ) ) ) { // apply all coupons to the first payment - $coupons_to_reapply[] = $coupon_code; - } else { - self::$removed_coupons[] = $coupon_code; + if ( 'recurring_total' === $calculation_type ) { + // Special handling for a single payment coupon. + if ( 1 === self::get_coupon_limit( $coupon_code ) && 0 < $cart->get_coupon_discount_amount( $coupon_code ) ) { + $cart->remove_coupon( $coupon_code ); } + + continue; } - // Now remove all coupons (WC only provides a function to remove all coupons) - $cart->remove_coupons(); - - // And re-apply those which relate to this calculation - $cart->applied_coupons = $coupons_to_reapply; - - if ( isset( $cart->coupons ) ) { // WC 2.3+ - $cart->coupons = $cart->get_coupons(); + if ( ! WC_Subscriptions_Cart::all_cart_items_have_free_trial() ) { + continue; } + + $cart->remove_coupon( $coupon_code ); } } @@ -658,6 +691,335 @@ class WC_Subscriptions_Coupon { return $label; } + /** + * Determine whether the cart contains a recurring coupon with set number of renewals. + * + * @author Jeremy Pry + * @return bool + */ + public static function cart_contains_limited_recurring_coupon() { + $has_coupon = false; + $applied_coupons = isset( WC()->cart->applied_coupons ) ? WC()->cart->applied_coupons : array(); + foreach ( $applied_coupons as $code ) { + if ( self::coupon_is_limited( $code ) ) { + $has_coupon = true; + break; + } + } + + return $has_coupon; + } + + /** + * Determine if a given order has a limited use coupon. + * + * @author Jeremy Pry + * + * @param WC_Order|WC_Subscription $order + * + * @return bool + */ + public static function order_has_limited_recurring_coupon( $order ) { + $has_coupon = false; + $coupons = $order->get_used_coupons(); + foreach ( $coupons as $code ) { + if ( self::coupon_is_limited( $code ) ) { + $has_coupon = true; + break; + } + } + + return $has_coupon; + } + + /** + * Determine if a given coupon is limited to a certain number of renewals. + * + * @author Jeremy Pry + * + * @param string $code The coupon code. + * + * @return bool + */ + public static function coupon_is_limited( $code ) { + return (bool) self::get_coupon_limit( $code ); + } + + /** + * Get the number of renewals for a limited coupon. + * + * @author Jeremy Pry + * + * @param string $code The coupon code. + * + * @return false|int False for non-recurring coupons, or the limit number for recurring coupons. + * A value of 0 is for unlimited usage. + */ + public static function get_coupon_limit( $code ) { + if ( WC_Subscriptions::is_woocommerce_pre( '3.2' ) ) { + return false; + } + + // Retrieve the coupon data. + $coupon = new WC_Coupon( $code ); + $coupon_type = $coupon->get_discount_type(); + + // If we have a virtual coupon, attempt to get the original coupon. + if ( isset( self::$renewal_coupons[ $coupon_type ] ) ) { + $coupon = self::map_virtual_coupon( $code ); + $coupon_type = $coupon->get_discount_type(); + } + + $limited = $coupon->get_meta( self::$coupons_renewals ); + + return isset( self::$recurring_coupons[ $coupon_type ] ) ? intval( $limited ) : false; + } + + /** + * Get a normal coupon from one of our virtual coupons. + * + * This is necessary when manually processing a renewal to ensure that we are correctly + * identifying limited payment coupons. + * + * @author Jeremy Pry + * + * @param string $code The virtual coupon code. + * + * @return WC_Coupon The original coupon. + */ + private static function map_virtual_coupon( $code ) { + add_filter( 'woocommerce_get_shop_coupon_data', '__return_false', 100 ); + $coupon = new WC_Coupon( $code ); + remove_filter( 'woocommerce_get_shop_coupon_data', '__return_false', 100 ); + + return $coupon; + } + + /** + * Limit payment gateways to those that support changing subscription amounts. + * + * @author Jeremy Pry + * + * @param WC_Payment_Gateway[] $gateways The current available gateways. + * + * @return WC_Payment_Gateway[], + */ + private static function limit_gateways_subscription_amount_changes( $gateways ) { + foreach ( $gateways as $index => $gateway ) { + if ( $gateway->supports( 'subscriptions' ) && ! $gateway->supports( 'subscription_amount_changes' ) ) { + unset( $gateways[ $index ] ); + } + } + + return $gateways; + } + + /** + * Filter the available gateways when there is a recurring coupon. + * + * @author Jeremy Pry + * + * @param WC_Payment_Gateway[] $gateways The available payment gateways. + * + * @return array The filtered payment gateways. + */ + public static function gateways_subscription_amount_changes( $gateways ) { + // If there are already no gateways, bail early. + if ( empty( $gateways ) ) { + return $gateways; + } + + // See if this is a request to change payment for an existing subscription. + $change_payment = isset( $_GET['change_payment_method'] ) ? wc_clean( $_GET['change_payment_method'] ) : 0; + $has_limited_coupon = false; + if ( $change_payment && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'] ) ) { + $subscription = wcs_get_subscription( $change_payment ); + $has_limited_coupon = self::order_has_limited_recurring_coupon( $subscription ); + } + + // If the cart doesn't have a limited coupon, and a change payment doesn't have a limited coupon, bail early. + if ( ! self::cart_contains_limited_recurring_coupon() && ! $has_limited_coupon ) { + return $gateways; + } + + // If we got this far, we should limit the gateways as needed. + $gateways = self::limit_gateways_subscription_amount_changes( $gateways ); + + // If there are no gateways now, it's because of the coupon. Filter the 'no available payment methods' message. + if ( empty( $gateways ) ) { + add_filter( 'woocommerce_no_available_payment_methods_message', array( __CLASS__, 'no_available_payment_methods_message' ), 20 ); + } + + return $gateways; + } + + /** + * Filter the message for when no payment gateways are available. + * + * @author Jeremy Pry + * + * @param string $message The current message indicating there are no payment methods available.. + * + * @return string The filtered message indicating there are no payment methods available. + */ + public static function no_available_payment_methods_message( $message ) { + return __( 'Sorry, it seems there are no available payment methods which support the recurring coupon you are using. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce-subscriptions' ); + } + + /** + * Add custom fields to the coupon data form. + * + * @see WC_Meta_Box_Coupon_Data::output() + * @author Jeremy Pry + * + * @param int $id The coupon ID. + */ + public static function add_coupon_fields( $id ) { + $coupon = new WC_Coupon( $id ); + woocommerce_wp_text_input( array( + 'id' => 'wcs_number_payments', + 'label' => __( 'Active for x payments', 'woocommerce-subscriptions' ), + 'placeholder' => __( 'Unlimited payments', 'woocommerce-subscriptions' ), + 'description' => __( 'Coupon will be limited to the given number of payments. It will then be automatically removed from the subscription. "Payments" also includes the initial subscription payment.', 'woocommerce-subscriptions' ), + 'desc_tip' => true, + 'data_type' => 'decimal', + 'value' => $coupon->get_meta( self::$coupons_renewals ), + ) ); + } + + /** + * Save our custom coupon fields. + * + * @see WC_Meta_Box_Coupon_Data::save() + * @author Jeremy Pry + * + * @param int $post_id + */ + public static function save_coupon_fields( $post_id ) { + // Check the nonce (again). + if ( empty( $_POST['woocommerce_meta_nonce'] ) || ! wp_verify_nonce( $_POST['woocommerce_meta_nonce'], 'woocommerce_save_data' ) ) { + return; + } + + $coupon = new WC_Coupon( $post_id ); + $coupon->add_meta_data( self::$coupons_renewals, wc_clean( $_POST['wcs_number_payments'] ), true ); + $coupon->save(); + } + + /** + * Determine how many subscriptions the coupon has been applied to. + * + * @author Jeremy Pry + * + * @param WC_Subscription $subscription The current subscription. + */ + public static function check_coupon_usages( $subscription ) { + // If there aren't any coupons, there's nothing to do. + $coupons = $subscription->get_used_coupons(); + if ( empty( $coupons ) ) { + return; + } + + // Set up the coupons we're looking for, and an initial count. + $limited_coupons = array(); + foreach ( $coupons as $code ) { + if ( self::coupon_is_limited( $code ) ) { + $limited_coupons[ $code ] = 0; + } + } + + // Don't continue if we have no limited use coupons. + if ( empty( $limited_coupons ) ) { + return; + } + + // Get all related orders, and count the number of uses for each coupon. + $related = $subscription->get_related_orders( 'all' ); + + /** @var WC_Order $order */ + foreach ( $related as $id => $order ) { + // Unpaid orders don't count as usages. + if ( $order->needs_payment() ) { + continue; + } + + /* + * If the order has been refunded, treat coupon as unused. We'll consider the order to be + * refunded when there is a non-null refund amount, and the order total equals the refund amount. + * + * The use of == instead of === is deliberate, to account for differences in amount formatting. + */ + $refunded = $order->get_total_refunded(); + $total = $order->get_total(); + if ( null !== $refunded && $total == $refunded ) { + continue; + } + + // If there was nothing discounted, then consider the coupon unused. + if ( ! $order->get_discount_total() ) { + continue; + } + + // Check for limited coupons, and add them to the count if the provide a discount. + $used_coupons = $order->get_items( 'coupon' ); + + /** @var WC_Order_Item_Coupon $used_coupon */ + foreach ( $used_coupons as $used_coupon ) { + if ( isset( $limited_coupons[ $used_coupon->get_code() ] ) && $used_coupon->get_discount() ) { + $limited_coupons[ $used_coupon->get_code() ]++; + } + } + } + + // Check each coupon to see if it needs to be removed. + foreach ( $limited_coupons as $code => $count ) { + if ( self::get_coupon_limit( $code ) <= $count ) { + $subscription->remove_coupon( $code ); + $subscription->add_order_note( sprintf( + _n( + /* translators: %1$s is the coupon code, %2$d is the number of payment usages */ + 'Limited use coupon "%1$s" removed from subscription. It has been used %2$d time.', + 'Limited use coupon "%1$s" removed from subscription. It has been used %2$d times.', + $count, + 'woocommerce-subscriptions' + ), + $code, + number_format_i18n( $count ) + ) ); + } + } + } + + /** + * Add our limited coupon data to the Coupon list table. + * + * @author Jeremy Pry + * + * @param string $column_name The name of the current column in the table. + * @param int $post_id The coupon post ID. + */ + public static function add_limit_to_list_table( $column_name, $post_id ) { + if ( 'usage' !== $column_name ) { + return; + } + + $limit = self::get_coupon_limit( wc_get_coupon_code_by_id( $post_id ) ); + if ( false === $limit ) { + return; + } + + echo '
'; + if ( $limit ) { + echo esc_html( sprintf( + /* translators: %d refers to the number of payments the coupon can be used for. */ + _n( 'Active for %d payment', 'Active for %d payments', $limit, 'woocommerce-subscriptions' ), + number_format_i18n( $limit ) + ) ); + } else { + esc_html_e( 'Active for unlimited payments', 'woocommerce-subscriptions' ); + } + } + /* Deprecated */ /** diff --git a/includes/class-wc-subscriptions-manager.php b/includes/class-wc-subscriptions-manager.php index 1176b2c..f8cf75a 100755 --- a/includes/class-wc-subscriptions-manager.php +++ b/includes/class-wc-subscriptions-manager.php @@ -133,7 +133,7 @@ class WC_Subscriptions_Manager { } else { if ( $subscription->is_manual() ) { - do_action( 'woocommerce_generated_manual_renewal_order', wcs_get_objects_property( $renewal_order, 'id' ) ); + do_action( 'woocommerce_generated_manual_renewal_order', wcs_get_objects_property( $renewal_order, 'id' ), $subscription ); } else { $renewal_order->set_payment_method( wc_get_payment_gateway_by_order( $subscription ) ); // We need to pass the payment gateway instance to be compatible with WC < 3.0, only WC 3.0+ supports passing the string name diff --git a/includes/class-wc-subscriptions-order.php b/includes/class-wc-subscriptions-order.php index 26e4201..a4cd33d 100755 --- a/includes/class-wc-subscriptions-order.php +++ b/includes/class-wc-subscriptions-order.php @@ -742,12 +742,19 @@ class WC_Subscriptions_Order { case 'switch' : $meta_key = '_subscription_switch'; break; + default: + $meta_key = ''; + break; } - $vars['meta_query'][] = array( - 'key' => $meta_key, - 'compare' => 'EXISTS', - ); + $meta_key = apply_filters( 'woocommerce_subscriptions_admin_order_type_filter_meta_key', $meta_key, $_GET['shop_order_subtype'] ); + + if ( ! empty( $meta_key ) ) { + $vars['meta_query'][] = array( + 'key' => $meta_key, + 'compare' => 'EXISTS', + ); + } } // Also exclude parent orders from non-subscription query @@ -1047,7 +1054,7 @@ class WC_Subscriptions_Order { $order = wc_get_order( $order_id ); add_filter( 'woocommerce_payment_complete_order_status', __METHOD__, 10, 2 ); - if ( 'processing' == $new_order_status && $order->get_total() == 0 && wcs_order_contains_subscription( $order ) ) { + if ( 'processing' == $new_order_status && $order->get_subtotal() == 0 && wcs_order_contains_subscription( $order ) ) { if ( wcs_order_contains_resubscribe( $order ) ) { $new_order_status = 'completed'; diff --git a/includes/class-wc-subscriptions-product.php b/includes/class-wc-subscriptions-product.php index e490ff6..284808e 100755 --- a/includes/class-wc-subscriptions-product.php +++ b/includes/class-wc-subscriptions-product.php @@ -310,44 +310,52 @@ class WC_Subscriptions_Product { if ( $include_length && $subscription_length == $billing_interval ) { $subscription_string = $price; // Only for one billing period so show "$5 for 3 months" instead of "$5 every 3 months for 3 months" } elseif ( WC_Subscriptions_Synchroniser::is_product_synced( $product ) && in_array( $billing_period, array( 'week', 'month', 'year' ) ) ) { + $subscription_string = ''; + + // Include string for upfront payment. + if ( WC_Subscriptions_Synchroniser::is_payment_upfront( $product ) ) { + /* translators: %1$s refers to the price. This string is meant to prefix another string below, e.g. "$5 now, and $5 on March 15th each year" */ + $subscription_string = sprintf( __( '%1$s now, and ', 'woocommerce-subscriptions' ), $price ); + } + $payment_day = WC_Subscriptions_Synchroniser::get_products_payment_day( $product ); switch ( $billing_period ) { case 'week': $payment_day_of_week = WC_Subscriptions_Synchroniser::get_weekday( $payment_day ); if ( 1 == $billing_interval ) { // translators: 1$: recurring amount string, 2$: day of the week (e.g. "$10 every Wednesday") - $subscription_string = sprintf( __( '%1$s every %2$s', 'woocommerce-subscriptions' ), $price, $payment_day_of_week ); + $subscription_string .= sprintf( __( '%1$s every %2$s', 'woocommerce-subscriptions' ), $price, $payment_day_of_week ); } else { // translators: 1$: recurring amount string, 2$: period, 3$: day of the week (e.g. "$10 every 2nd week on Wednesday") - $subscription_string = sprintf( __( '%1$s every %2$s on %3$s', 'woocommerce-subscriptions' ), $price, wcs_get_subscription_period_strings( $billing_interval, $billing_period ), $payment_day_of_week ); + $subscription_string .= sprintf( __( '%1$s every %2$s on %3$s', 'woocommerce-subscriptions' ), $price, wcs_get_subscription_period_strings( $billing_interval, $billing_period ), $payment_day_of_week ); } break; case 'month': if ( 1 == $billing_interval ) { if ( $payment_day > 27 ) { // translators: placeholder is recurring amount - $subscription_string = sprintf( __( '%s on the last day of each month', 'woocommerce-subscriptions' ), $price ); + $subscription_string .= sprintf( __( '%s on the last day of each month', 'woocommerce-subscriptions' ), $price ); } else { // translators: 1$: recurring amount, 2$: day of the month (e.g. "23rd") (e.g. "$5 every 23rd of each month") - $subscription_string = sprintf( __( '%1$s on the %2$s of each month', 'woocommerce-subscriptions' ), $price, WC_Subscriptions::append_numeral_suffix( $payment_day ) ); + $subscription_string .= sprintf( __( '%1$s on the %2$s of each month', 'woocommerce-subscriptions' ), $price, WC_Subscriptions::append_numeral_suffix( $payment_day ) ); } } else { if ( $payment_day > 27 ) { // translators: 1$: recurring amount, 2$: interval (e.g. "3rd") (e.g. "$10 on the last day of every 3rd month") - $subscription_string = sprintf( __( '%1$s on the last day of every %2$s month', 'woocommerce-subscriptions' ), $price, WC_Subscriptions::append_numeral_suffix( $billing_interval ) ); + $subscription_string .= sprintf( __( '%1$s on the last day of every %2$s month', 'woocommerce-subscriptions' ), $price, WC_Subscriptions::append_numeral_suffix( $billing_interval ) ); } else { // translators: 1$: on the, 2$: day of every, 3$: month (e.g. "$10 on the 23rd day of every 2nd month") - $subscription_string = sprintf( __( '%1$s on the %2$s day of every %3$s month', 'woocommerce-subscriptions' ), $price, WC_Subscriptions::append_numeral_suffix( $payment_day ), WC_Subscriptions::append_numeral_suffix( $billing_interval ) ); + $subscription_string .= sprintf( __( '%1$s on the %2$s day of every %3$s month', 'woocommerce-subscriptions' ), $price, WC_Subscriptions::append_numeral_suffix( $payment_day ), WC_Subscriptions::append_numeral_suffix( $billing_interval ) ); } } break; case 'year': if ( 1 == $billing_interval ) { // translators: 1$: on, 2$: , 3$: each year (e.g. "$15 on March 15th each year") - $subscription_string = sprintf( __( '%1$s on %2$s %3$s each year', 'woocommerce-subscriptions' ), $price, $wp_locale->month[ $payment_day['month'] ], WC_Subscriptions::append_numeral_suffix( $payment_day['day'] ) ); + $subscription_string .= sprintf( __( '%1$s on %2$s %3$s each year', 'woocommerce-subscriptions' ), $price, $wp_locale->month[ $payment_day['month'] ], WC_Subscriptions::append_numeral_suffix( $payment_day['day'] ) ); } else { // translators: 1$: recurring amount, 2$: month (e.g. "March"), 3$: day of the month (e.g. "23rd") (e.g. "$15 on March 15th every 3rd year") - $subscription_string = sprintf( __( '%1$s on %2$s %3$s every %4$s year', 'woocommerce-subscriptions' ), $price, $wp_locale->month[ $payment_day['month'] ], WC_Subscriptions::append_numeral_suffix( $payment_day['day'] ), WC_Subscriptions::append_numeral_suffix( $billing_interval ) ); + $subscription_string .= sprintf( __( '%1$s on %2$s %3$s every %4$s year', 'woocommerce-subscriptions' ), $price, $wp_locale->month[ $payment_day['month'] ], WC_Subscriptions::append_numeral_suffix( $payment_day['day'] ), WC_Subscriptions::append_numeral_suffix( $billing_interval ) ); } break; } @@ -855,6 +863,27 @@ class WC_Subscriptions_Product { * @since 1.5.29 */ public static function bulk_edit_variations( $bulk_action, $data, $variable_product_id, $variation_ids ) { + if ( 'delete_all_no_subscriptions' === $bulk_action && isset( $data['allowed'] ) && 'true' == $data['allowed'] ) { + $deleted = 0; + + foreach ( $variation_ids as $variation_id ) { + $variation = wc_get_product( $variation_id ); + $subscriptions = wcs_get_subscriptions_for_product( $variation_id ); + + if ( empty( $subscriptions ) ) { + if ( is_callable( array( $variation, 'delete' ) ) ) { + $variation->delete( true ); + } else { + wp_delete_post( $variation_id ); + } + + $deleted++; + } + } + + echo intval( $deleted ); + return; + } if ( ! isset( $data['value'] ) ) { return; @@ -1059,6 +1088,10 @@ class WC_Subscriptions_Product { $min_max_data = wcs_get_min_max_variation_data( $product, $child_variation_ids ); + if ( is_callable( array( $product, 'set_min_and_max_variation_data' ) ) ) { + $product->set_min_and_max_variation_data( $min_max_data, $child_variation_ids ); + } + $product->add_meta_data( '_min_price_variation_id', $min_max_data['min']['variation_id'], true ); $product->add_meta_data( '_max_price_variation_id', $min_max_data['max']['variation_id'], true ); @@ -1098,7 +1131,7 @@ class WC_Subscriptions_Product { global $wpdb; $parent_product_ids = array(); - if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) && $product->get_parent() ) { + if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) && isset( $product->post->post_parent ) ) { $parent_product_ids[] = $product->get_parent(); } else { $parent_product_ids = $wpdb->get_col( $wpdb->prepare( @@ -1112,6 +1145,30 @@ class WC_Subscriptions_Product { return $parent_product_ids; } + /** + * Get a product's list of parent IDs which are a grouped type. + * + * Unlike @see WC_Subscriptions_Product::get_parent_ids(), this function will return parent products which still exist, are visible and are a grouped product. + * + * @param WC_Product The product object to get parents from. + * @return array The product's grouped parent IDs. + * @since 2.3.0 + */ + public static function get_visible_grouped_parent_product_ids( $product ) { + $parent_product_ids = self::get_parent_ids( $product ); + + // Verify that the parent products exist and are indeed grouped products + foreach ( $parent_product_ids as $index => $product_id ) { + $parent_product = wc_get_product( $product_id ); + + if ( ! is_a( $parent_product, 'WC_Product' ) || ! $parent_product->is_type( 'grouped' ) || 'publish' !== wcs_get_objects_property( $parent_product, 'post_status' ) ) { + unset( $parent_product_ids[ $index ] ); + } + } + + return $parent_product_ids; + } + /************************ * Deprecated Functions * ************************/ diff --git a/includes/class-wc-subscriptions-renewal-order.php b/includes/class-wc-subscriptions-renewal-order.php index b1afe47..ca48c3d 100755 --- a/includes/class-wc-subscriptions-renewal-order.php +++ b/includes/class-wc-subscriptions-renewal-order.php @@ -20,18 +20,18 @@ class WC_Subscriptions_Renewal_Order { public static function init() { // Trigger special hook when payment is completed on renewal orders - add_action( 'woocommerce_payment_complete', __CLASS__ . '::trigger_renewal_payment_complete', 10 ); + add_action( 'woocommerce_payment_complete', array( __CLASS__, 'trigger_renewal_payment_complete' ), 10 ); // When a renewal order's status changes, check if a corresponding subscription's status should be changed by marking it as paid (we can't use the 'woocommerce_payment_complete' here because it's not triggered by all payment gateways) - add_filter( 'woocommerce_order_status_changed', __CLASS__ . '::maybe_record_subscription_payment', 10, 3 ); + add_action( 'woocommerce_order_status_changed', array( __CLASS__, 'maybe_record_subscription_payment' ), 10, 3 ); - add_filter( 'wcs_renewal_order_created', __CLASS__ . '::add_order_note', 10, 2 ); + add_filter( 'wcs_renewal_order_created', array( __CLASS__, 'add_order_note' ), 10, 2 ); // Prevent customers from cancelling renewal orders. Needs to be hooked before WC_Form_Handler::cancel_order() (20) - add_filter( 'wp_loaded', __CLASS__ . '::prevent_cancelling_renewal_orders', 19, 3 ); + add_action( 'wp_loaded', array( __CLASS__, 'prevent_cancelling_renewal_orders' ), 19, 3 ); // Don't copy switch order item meta to renewal order items - add_filter( 'wcs_new_order_items', __CLASS__ . '::remove_switch_item_meta_keys', 10, 1 ); + add_filter( 'wcs_new_order_items', array( __CLASS__, 'remove_switch_item_meta_keys' ), 10, 1 ); } /* Helper functions */ diff --git a/includes/class-wc-subscriptions-switcher.php b/includes/class-wc-subscriptions-switcher.php index f0a99c9..c9a2aa3 100755 --- a/includes/class-wc-subscriptions-switcher.php +++ b/includes/class-wc-subscriptions-switcher.php @@ -82,9 +82,6 @@ class WC_Subscriptions_Switcher { // Make sure sign-up fees paid on switch orders are accounted for in an items sign-up fee add_filter( 'woocommerce_subscription_items_sign_up_fee', __CLASS__ . '::subscription_items_sign_up_fee', 10, 4 ); - // Make sure switch orders are included in related orders returned for a subscription - add_filter( 'woocommerce_subscription_related_orders', __CLASS__ . '::add_related_orders', 10, 4 ); - // Display/indicate whether a cart switch item is a upgrade/downgrade/crossgrade add_filter( 'woocommerce_cart_item_subtotal', __CLASS__ . '::add_cart_item_switch_direction', 10, 3 ); @@ -467,7 +464,7 @@ class WC_Subscriptions_Switcher { } $product = wc_get_product( $item['product_id'] ); - $parent_products = WC_Subscriptions_Product::get_parent_ids( $product ); + $parent_products = WC_Subscriptions_Product::get_visible_grouped_parent_product_ids( $product ); $additional_query_args = array(); // Grouped product @@ -584,14 +581,14 @@ class WC_Subscriptions_Switcher { $order = wc_get_order( $order_id ); // delete all the existing subscription switch links before adding new ones - wcs_delete_objects_property( $order, 'subscription_switch' ); + WCS_Related_Order_Store::instance()->delete_relations( $order, 'switch' ); $switches = self::cart_contains_switches(); if ( false !== $switches ) { foreach ( $switches as $switch_details ) { - wcs_set_objects_property( $order, 'subscription_switch', $switch_details['subscription_id'] ); + WCS_Related_Order_Store::instance()->add_relation( $order, wcs_get_subscription( $switch_details['subscription_id'] ), 'switch' ); } } } @@ -1323,7 +1320,7 @@ class WC_Subscriptions_Switcher { // Because product add-ons etc. don't apply to sign-up fees, it's safe to use the product's sign-up fee value rather than the cart item's $sign_up_fee_due = WC_Subscriptions_Product::get_sign_up_fee( $product ); - $sign_up_fee_paid = $subscription->get_items_sign_up_fee( $existing_item, 'inclusive_of_tax' ); + $sign_up_fee_paid = $subscription->get_items_sign_up_fee( $existing_item, get_option( 'woocommerce_prices_include_tax' ) === 'yes' ? 'inclusive_of_tax' : 'exclusive_of_tax' ); // Make sure total prorated sign-up fee is prorated across total amount of sign-up fee so that customer doesn't get extra discounts if ( $cart_item['quantity'] > $existing_item['qty'] ) { @@ -1764,32 +1761,6 @@ class WC_Subscriptions_Switcher { return $table_content; } - /** - * Filter the WC_Subscription::get_related_orders() method to include switch orders. - * - * @since 2.0 - */ - public static function add_related_orders( $related_orders, $subscription, $return_fields, $order_type ) { - - if ( in_array( $order_type, array( 'all', 'switch' ) ) ) { - - $switch_orders = wcs_get_switch_orders_for_subscription( $subscription->get_id() ); - - if ( 'all' == $return_fields ) { - $related_orders += $switch_orders; - } else { - foreach ( $switch_orders as $order_id => $order ) { - $related_orders[ $order_id ] = $order_id; - } - } - - // This will change the ordering to be by ID instead of the default of date - krsort( $related_orders ); - } - - return $related_orders; - } - /** * Add the cart item upgrade/downgrade/crossgrade direction for display * @@ -2428,8 +2399,6 @@ class WC_Subscriptions_Switcher { return $cart_contains_subscription_creating_switch; } - /** Deprecated Methods **/ - /** * Don't allow switched subscriptions to be cancelled. * @@ -2688,5 +2657,39 @@ class WC_Subscriptions_Switcher { } } } + + /** + * Filter the WC_Subscription::get_related_orders() method to include switch orders. + * + * @since 2.0 + * @deprecated + * + * @param array $related_orders + * @param WC_Subscription $subscription + * @param string $return_fields + * @param string $order_type + * + * @return array + */ + public static function add_related_orders( $related_orders, $subscription, $return_fields, $order_type ) { + wcs_deprecated_function( __METHOD__, '2.3.0', 'wcs_get_switch_orders_for_subscription()' ); + if ( in_array( $order_type, array( 'all', 'switch' ) ) ) { + + $switch_orders = wcs_get_switch_orders_for_subscription( $subscription->get_id() ); + + if ( 'all' == $return_fields ) { + $related_orders += $switch_orders; + } else { + foreach ( $switch_orders as $order_id => $order ) { + $related_orders[ $order_id ] = $order_id; + } + } + + // This will change the ordering to be by ID instead of the default of date + krsort( $related_orders ); + } + + return $related_orders; + } } WC_Subscriptions_Switcher::init(); diff --git a/includes/class-wc-subscriptions-synchroniser.php b/includes/class-wc-subscriptions-synchroniser.php index 341c3c9..f7d2337 100755 --- a/includes/class-wc-subscriptions-synchroniser.php +++ b/includes/class-wc-subscriptions-synchroniser.php @@ -12,6 +12,7 @@ class WC_Subscriptions_Synchroniser { public static $setting_id; public static $setting_id_proration; + public static $setting_id_days_no_fee; public static $post_meta_key = '_subscription_payment_sync_date'; public static $post_meta_key_day = '_subscription_payment_sync_date_day'; @@ -40,9 +41,9 @@ class WC_Subscriptions_Synchroniser { * @since 1.5 */ public static function init() { - - self::$setting_id = WC_Subscriptions_Admin::$option_prefix . '_sync_payments'; - self::$setting_id_proration = WC_Subscriptions_Admin::$option_prefix . '_prorate_synced_payments'; + self::$setting_id = WC_Subscriptions_Admin::$option_prefix . '_sync_payments'; + self::$setting_id_proration = WC_Subscriptions_Admin::$option_prefix . '_prorate_synced_payments'; + self::$setting_id_days_no_fee = WC_Subscriptions_Admin::$option_prefix . '_days_no_fee'; self::$sync_field_label = __( 'Synchronise renewals', 'woocommerce-subscriptions' ); self::$sync_description = __( 'Align the payment date for all customers who purchase this subscription to a specific day of the week or month.', 'woocommerce-subscriptions' ); @@ -77,11 +78,11 @@ class WC_Subscriptions_Synchroniser { add_action( 'woocommerce_subscriptions_product_first_renewal_payment_time', __CLASS__ . '::products_first_renewal_payment_time', 10, 4 ); // Maybe mock a free trial on the product for calculating totals and displaying correct shipping costs - add_filter( 'woocommerce_before_calculate_totals', __CLASS__ . '::maybe_set_free_trial', 0, 1 ); + add_action( 'woocommerce_before_calculate_totals', __CLASS__ . '::maybe_set_free_trial', 0, 1 ); add_action( 'woocommerce_subscription_cart_before_grouping', __CLASS__ . '::maybe_unset_free_trial' ); add_action( 'woocommerce_subscription_cart_after_grouping', __CLASS__ . '::maybe_set_free_trial' ); - add_action( 'wcs_recurring_cart_start_date', __CLASS__ . '::maybe_unset_free_trial', 0, 1 ); - add_action( 'wcs_recurring_cart_end_date', __CLASS__ . '::maybe_set_free_trial', 100, 1 ); + add_filter( 'wcs_recurring_cart_start_date', __CLASS__ . '::maybe_unset_free_trial', 0, 1 ); + add_filter( 'wcs_recurring_cart_end_date', __CLASS__ . '::maybe_set_free_trial', 100, 1 ); add_filter( 'woocommerce_subscriptions_calculated_total', __CLASS__ . '::maybe_unset_free_trial', 10000, 1 ); add_action( 'woocommerce_cart_totals_before_shipping', __CLASS__ . '::maybe_set_free_trial' ); add_action( 'woocommerce_cart_totals_after_shipping', __CLASS__ . '::maybe_unset_free_trial' ); @@ -99,8 +100,10 @@ class WC_Subscriptions_Synchroniser { if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { add_action( 'woocommerce_order_add_product', __CLASS__ . '::maybe_add_meta_for_new_product', 10, 3 ); + add_action( 'woocommerce_add_order_item_meta', array( __CLASS__, 'maybe_add_order_item_meta' ), 10, 2 ); } else { add_action( 'woocommerce_new_order_item', __CLASS__ . '::maybe_add_meta_for_new_line_item', 10, 3 ); + add_action( 'woocommerce_checkout_create_order_line_item', array( __CLASS__, 'maybe_add_line_item_meta' ), 10, 3 ); } // Make sure the sign-up fee for a synchronised subscription is correct @@ -110,6 +113,58 @@ class WC_Subscriptions_Synchroniser { add_filter( 'woocommerce_order_item_quantity', __CLASS__ . '::maybe_do_not_reduce_stock', 10, 3 ); add_filter( 'woocommerce_subscriptions_recurring_cart_key', __CLASS__ . '::add_to_recurring_cart_key', 10, 2 ); + + // Add defaults for our options. + add_filter( 'default_option_' . self::$setting_id_days_no_fee, array( __CLASS__, 'option_default' ), 10, 3 ); + + // Sanitize options when saving. + add_filter( 'woocommerce_admin_settings_sanitize_option_' . self::$setting_id_days_no_fee, array( __CLASS__, 'sanitize_option' ), 10, 2 ); + + // Ensure options are the proper type. + add_filter( 'option_' . self::$setting_id_days_no_fee, 'intval' ); + } + + /** + * Set default value of 'no' for our options. + * + * This only sets the default + * + * @author Jeremy Pry + * + * @param mixed $default The default value for the option. + * @param string $option The option name. + * @param bool $passed_default Whether get_option() was passed a default value. + * + * @return mixed The default option value. + */ + public static function option_default( $default, $option, $passed_default = null ) { + switch ( $option ) { + case self::$setting_id_days_no_fee: + $default = $passed_default ? $default : 0; + break; + } + + return $default; + } + + /** + * Sanitize our options when they are saved in the admin area. + * + * @author Jeremy Pry + * + * @param mixed $value The value being saved. + * @param array $option The option data array. + * + * @return mixed The sanitized option value. + */ + public static function sanitize_option( $value, $option ) { + switch ( $option['id'] ) { + case self::$setting_id_days_no_fee: + $value = absint( $value ); + break; + } + + return $value; } /** @@ -118,16 +173,16 @@ class WC_Subscriptions_Synchroniser { * @since 1.5 */ public static function is_syncing_enabled() { - return ( 'yes' == get_option( self::$setting_id, 'no' ) ) ? true : false; + return 'yes' === get_option( self::$setting_id, 'no' ); } /** - * Check if payment syncing is enabled on the store. + * Check if payments can be prorated on the store. * * @since 1.5 */ public static function is_sync_proration_enabled() { - return ( 'no' != get_option( self::$setting_id_proration, 'no' ) ) ? true : false; + return 'no' !== get_option( self::$setting_id_proration, 'no' ); } /** @@ -137,7 +192,8 @@ class WC_Subscriptions_Synchroniser { */ public static function add_settings( $settings ) { - // Get the index of the index of the + // Get the index of the setting. + $index = 0; foreach ( $settings as $i => $setting ) { if ( 'title' == $setting['type'] && 'woocommerce_subscriptions_miscellaneous' == $setting['id'] ) { $index = $i; @@ -164,18 +220,28 @@ class WC_Subscriptions_Synchroniser { ), array( - 'name' => __( 'Prorate First Payment', 'woocommerce-subscriptions' ), - 'desc' => __( 'If a subscription is synchronised to a specific day of the week, month or year, charge a prorated amount for the subscription at the time of sign up.', 'woocommerce-subscriptions' ), - 'id' => self::$setting_id_proration, - 'css' => 'min-width:150px;', - 'default' => 'no', - 'type' => 'select', - 'options' => array( - 'no' => _x( 'Never', 'when to allow a setting', 'woocommerce-subscriptions' ), - 'virtual' => _x( 'For Virtual Subscription Products Only', 'when to prorate first payment / subscription length', 'woocommerce-subscriptions' ), - 'yes' => _x( 'For All Subscription Products', 'when to prorate first payment / subscription length', 'woocommerce-subscriptions' ), + 'name' => __( 'Prorate First Renewal', 'woocommerce-subscriptions' ), + 'desc' => __( 'If a subscription is synchronised to a specific day of the week, month or year, charge a prorated amount for the subscription at the time of sign up.', 'woocommerce-subscriptions' ), + 'id' => self::$setting_id_proration, + 'css' => 'min-width:150px;', + 'default' => 'no', + 'type' => 'select', + 'options' => array( + 'no' => _x( 'Never (do not charge any recurring amount)', 'when to prorate first payment / subscription length', 'woocommerce-subscriptions' ), + 'recurring' => _x( 'Never (charge the full recurring amount at sign-up)', 'when to prorate first payment / subscription length', 'woocommerce-subscriptions' ), + 'virtual' => _x( 'For Virtual Subscription Products Only', 'when to prorate first payment / subscription length', 'woocommerce-subscriptions' ), + 'yes' => _x( 'For All Subscription Products', 'when to prorate first payment / subscription length', 'woocommerce-subscriptions' ), ), - 'desc_tip' => true, + 'desc_tip' => true, + ), + + array( + 'name' => __( 'Sign-up grace period', 'woocommerce-subscriptions' ), + 'desc' => _x( 'days prior to Renewal Day', "there's a number immediately in front of this text", 'woocommerce-subscriptions' ), + 'id' => self::$setting_id_days_no_fee, + 'default' => 0, + 'type' => 'number', + 'desc_tip' => __( 'Subscriptions created within this many days prior to the Renewal Day will not be charged at sign-up. Set to zero for all new Subscriptions to be charged the full recurring amount. Must be a positive number.', 'woocommerce-subscriptions' ), ), array( 'type' => 'sectionend', 'id' => self::$setting_id . '_title' ), @@ -414,9 +480,12 @@ class WC_Subscriptions_Synchroniser { * at the time of sign-up but prorated to the sync day. * * @since 1.5.10 + * + * @param WC_Product $product + * + * @return bool */ public static function is_product_prorated( $product ) { - if ( false === self::is_sync_proration_enabled() || false === self::is_product_synced( $product ) ) { $is_product_prorated = false; } elseif ( 'yes' == get_option( self::$setting_id_proration, 'no' ) && 0 == WC_Subscriptions_Product::get_trial_length( $product ) ) { @@ -430,6 +499,66 @@ class WC_Subscriptions_Synchroniser { return $is_product_prorated; } + /** + * Determine whether the payment for a subscription should be the full price upfront. + * + * This method is particularly concerned with synchronized subscriptions. It will only return + * true when the following conditions are met: + * + * - There is no free trial + * - The subscription is synchronized + * - The store owner has determined that new subscribers need to pay for their subscription upfront. + * + * Additionally, if the store owner sets a number of days prior to the synchronization day that do not + * require an upfront payment, this method will check to see whether the current date falls within that + * period for the given product. + * + * @author Jeremy Pry + * + * @param WC_Product $product The product to check. + * + * @return bool Whether an upfront payment is required for the product. + */ + public static function is_payment_upfront( $product ) { + static $results = array(); + $is_upfront = null; + if ( array_key_exists( $product->get_id(), $results ) ) { + return $results[ $product->get_id() ]; + } + + // Normal cases where we aren't concerned with an upfront payment. + if ( + 0 !== WC_Subscriptions_Product::get_trial_length( $product ) || + ! self::is_product_synced( $product ) || + 'recurring' !== get_option( self::$setting_id_proration, 'no' ) + ) { + $is_upfront = false; + } + + // Maybe account for number of days without a fee. + if ( null === $is_upfront ) { + $no_fee_days = get_option( self::$setting_id_days_no_fee ); + + if ( $no_fee_days > 0 ) { + $payment_date = self::calculate_first_payment_date( $product, 'timestamp' ); + $buffer_date = $payment_date - ( $no_fee_days * DAY_IN_SECONDS ); + $is_upfront = wcs_strtotime_dark_knight( 'now' ) < $buffer_date; + } else { + $is_upfront = true; + } + } + + /** + * Filter whether payment is upfront for a given product. + * + * @param bool $is_upfront Whether the product needs to be paid upfront. + * @param WC_Product $product The current product. + */ + $results[ $product->get_id() ] = apply_filters( 'woocommerce_subscriptions_payment_upfront', $is_upfront, $product ); + + return $results[ $product->get_id() ]; + } + /** * Get the day of the week, month or year on which a subscription's payments should be * synchronised to. @@ -708,7 +837,12 @@ class WC_Subscriptions_Synchroniser { public static function maybe_set_free_trial( $total = '' ) { foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { - if ( self::is_product_synced( $cart_item['data'] ) && ! self::is_product_prorated( $cart_item['data'] ) && ! self::is_today( self::calculate_first_payment_date( $cart_item['data'], 'timestamp' ) ) ) { + if ( + self::is_product_synced( $cart_item['data'] ) && + ! self::is_payment_upfront( $cart_item['data'] ) && + ! self::is_product_prorated( $cart_item['data'] ) && + ! self::is_today( self::calculate_first_payment_date( $cart_item['data'], 'timestamp' ) ) + ) { $current_trial_length = WC_Subscriptions_Product::get_trial_length( WC()->cart->cart_contents[ $cart_item_key ]['data'] ); $new_trial_length = ( $current_trial_length > 1 ) ? $current_trial_length : 1; wcs_set_objects_property( WC()->cart->cart_contents[ $cart_item_key ]['data'], 'subscription_trial_length', $new_trial_length, 'set_prop_only' ); @@ -851,6 +985,11 @@ class WC_Subscriptions_Synchroniser { * Removes the "set_subscription_prices_for_calculation" filter from the WC Product's woocommerce_get_price hook once * * @since 1.5.10 + * + * @param int $price The current price. + * @param WC_Product $product The product object. + * + * @return int */ public static function set_prorated_price_for_calculation( $price, $product ) { @@ -1052,6 +1191,40 @@ class WC_Subscriptions_Synchroniser { } } + /** + * Store a synced product's signup fee on the line item on the subscription and order. + * + * When calculating prorated sign up fees during switches it's necessary to get the sign-up fee paid. + * For synced product purchases we cannot rely on the order line item price as that might include a prorated recurring price or no recurring price all. + * + * Attached to WC 3.0+ hooks and uses WC 3.0 methods. + * + * @param WC_Order_Item_Product $item The order item object. + * @param string $cart_item_key The hash used to identify the item in the cart + * @param array $cart_item The cart item's data. + * @since 2.3.0 + */ + public static function maybe_add_line_item_meta( $item, $cart_item_key, $cart_item ) { + if ( self::is_product_synced( $cart_item['data'] ) && ! self::is_today( self::calculate_first_payment_date( $cart_item['data'], 'timestamp' ) ) ) { + $item->add_meta_data( '_synced_sign_up_fee', WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] ) ); + } + } + + /** + * Store a synced product's signup fee on the line item on the subscription and order. + * + * This function is a pre WooCommerce 3.0 version of @see WC_Subscriptions_Synchroniser::maybe_add_line_item_meta() + * + * @param int $item_id The order item ID. + * @param array $cart_item The cart item's data. + * @since 2.3.0 + */ + public static function maybe_add_order_item_meta( $item_id, $cart_item ) { + if ( self::is_product_synced( $cart_item['data'] ) && ! self::is_today( self::calculate_first_payment_date( $cart_item['data'], 'timestamp' ) ) ) { + wc_update_order_item_meta( $item_id, '_synced_sign_up_fee', WC_Subscriptions_Product::get_sign_up_fee( $cart_item['data'] ) ); + } + } + /* Deprecated Functions */ /** diff --git a/includes/class-wcs-cache-manager-tlc.php b/includes/class-wcs-cache-manager-tlc.php deleted file mode 100755 index 0a4ee8b..0000000 --- a/includes/class-wcs-cache-manager-tlc.php +++ /dev/null @@ -1,189 +0,0 @@ -' . __FUNCTION__ ); - $this->logger = new WC_Logger(); - } - - /** - * Wrapper function around WC_Logger->log - * - * @param string $message Message to log - */ - public function log( $message ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - if ( defined( 'WCS_DEBUG' ) && WCS_DEBUG ) { - $this->logger->add( 'wcs-cache', $message ); - } - } - - /** - * Wrapper function around our cache library. - * - * @param string $key The key to cache the data with - * @param string|array $callback name of function, or array of class - method that fetches the data - * @param array $params arguments passed to $callback - * @param integer $expires number of seconds for how long to keep the cache. Don't set it to 0, as the cache will be autoloaded. Default is a week. - * - * @return bool|mixed - */ - public function cache_and_get( $key, $callback, $params = array(), $expires = WEEK_IN_SECONDS ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - $expires = absint( $expires ); - - $transient = tlc_transient( $key ) - ->updates_with( $callback, $params ) - ->expires_in( $expires ); - - return $transient->get(); - } - - /** - * Clearing for orders / subscriptions with sanitizing bits - * - * @param $post_id integer the ID of an order / subscription - */ - public function purge_subscription_cache_on_update( $post_id ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - $post_type = get_post_type( $post_id ); - - if ( 'shop_subscription' !== $post_type && 'shop_order' !== $post_type ) { - return; - } - - if ( 'shop_subscription' === $post_type ) { - $this->log( 'ID is subscription, calling wcs_clear_related_order_cache for ' . $post_id ); - - $this->wcs_clear_related_order_cache( $post_id ); - } else { - - $this->log( 'ID is order, getting subscription.' ); - - $subscription = wcs_get_subscriptions_for_order( $post_id ); - - if ( empty( $subscription ) ) { - $this->log( 'No sub for this ID: ' . $post_id ); - return; - } - $subscription = array_shift( $subscription ); - - $this->log( 'Got subscription, calling wcs_clear_related_order_cache for ' . $subscription->get_id() ); - - $this->wcs_clear_related_order_cache( $subscription->get_id() ); - } - } - - /** - * Clearing cache when a post is deleted - * - * @param $post_id integer the ID of a post - */ - public function purge_delete( $post_id ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - if ( 'shop_order' !== get_post_type( $post_id ) ) { - return; - } - - $linked_subscription = get_post_meta( $post_id, '_subscription_renewal', false ); - - // don't call this if there's nothing to call on - if ( $linked_subscription ) { - $this->log( 'Calling purge from ' . current_filter() . ' on ' . $linked_subscription[0] ); - $this->purge_subscription_cache_on_update( $linked_subscription[0] ); - } - } - - /** - * When the _subscription_renewal metadata is added / deleted / updated on the Order, we need to initiate cache invalidation for both the new - * value of the meta ($_meta_value), and the object it's being added to: $object_id. - * - * @param $meta_id integer the ID of the meta in the meta table - * @param $object_id integer the ID of the post we're updating on - * @param $meta_key string the meta_key in the table - * @param $_meta_value mixed the value we're deleting / adding / updating - */ - public function purge_from_metadata( $meta_id, $object_id, $meta_key, $_meta_value ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - if ( '_subscription_renewal' !== $meta_key || 'shop_order' !== get_post_type( $object_id ) ) { - return; - } - - $this->log( 'Calling purge from ' . current_filter() . ' on object ' . $object_id . ' and meta value ' . $_meta_value . ' due to _subscription_renewal meta.' ); - - $this->purge_subscription_cache_on_update( $_meta_value ); - $this->purge_subscription_cache_on_update( $object_id ); - } - - /** - * Wrapper function to clear cache that relates to related orders - * - * @param null $id - */ - public function wcs_clear_related_order_cache( $id = null ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - // if nothing was passed in, there's nothing to delete - if ( null === $id ) { - return; - } - - // if it's not a Subscription, we don't deal with it - if ( is_object( $id ) && $id instanceof WC_Subscription ) { - $id = $id->get_id(); - } elseif ( is_numeric( $id ) ) { - $id = absint( $id ); - } else { - return; - } - - $key = tlc_transient( 'wcs-related-orders-to-' . $id )->key; - - $this->log( 'In the clearing, key being purged is this: ' . "\n\n{$key}\n\n" ); - - $this->delete_cached( $key ); - } - - /** - * Delete cached data with key - * - * @param string $key Key that needs deleting - */ - public function delete_cached( $key ) { - _deprecated_function( __METHOD__, '2.1.2', 'WC_Subscriptions::$cache->' . __FUNCTION__ ); - if ( ! is_string( $key ) || empty( $key ) ) { - return; - } - // have to do this manually for now - delete_transient( 'tlc__' . $key ); - delete_transient( 'tlc_up__' . $key ); - } -} diff --git a/includes/class-wcs-cached-data-manager.php b/includes/class-wcs-cached-data-manager.php index 447bcab..98acf45 100755 --- a/includes/class-wcs-cached-data-manager.php +++ b/includes/class-wcs-cached-data-manager.php @@ -3,7 +3,8 @@ * Subscription Cached Data Manager Class * * @class WCS_Cached_Data_Manager - * @version 2.1.2 + * @version 2.3.0 + * @since 2.1.2 * @package WooCommerce Subscriptions/Classes * @category Class * @author Prospress @@ -15,20 +16,8 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { public function __construct() { add_action( 'woocommerce_loaded', array( $this, 'load_logger' ) ); - // Add filters for update / delete / trash post to purge cache - add_action( 'trashed_post', array( $this, 'purge_delete' ), 9999 ); // trashed posts aren't included in 'any' queries - add_action( 'untrashed_post', array( $this, 'purge_delete' ), 9999 ); // however untrashed posts are - add_action( 'before_delete_post', array( $this, 'purge_delete' ), 9999 ); // if forced delete is enabled - add_action( 'update_post_meta', array( $this, 'purge_from_metadata' ), 9999, 4 ); - add_action( 'updated_post_meta', array( $this, 'purge_from_metadata' ), 9999, 4 ); // tied to '_subscription_renewal', '_subscription_resubscribe' & '_subscription_switch' keys - add_action( 'deleted_post_meta', array( $this, 'purge_from_metadata' ), 9999, 4 ); // tied to '_subscription_renewal', '_subscription_resubscribe' & '_subscription_switch' keys - add_action( 'added_post_meta', array( $this, 'purge_from_metadata' ), 9999, 4 ); // tied to '_subscription_renewal', '_subscription_resubscribe' & '_subscription_switch' keys - add_action( 'admin_init', array( $this, 'initialize_cron_check_size' ) ); // setup cron task to truncate big logs. add_filter( 'cron_schedules', array( $this, 'add_weekly_cron_schedule' ) ); // create a weekly cron schedule - - // Add actions to handle cache purge for users. - add_action( 'save_post', array( $this, 'purge_delete' ), 9999, 2 ); } /** @@ -79,15 +68,20 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { * @param WP_Post $post The post object (on certain hooks). */ public function purge_delete( $post_id, $post = null ) { + wcs_deprecated_function( __METHOD__, '2.3.0' ); + $post_type = get_post_type( $post_id ); + if ( 'shop_order' === $post_type ) { - foreach ( wcs_get_subscriptions_for_order( $post_id, array( 'order_type' => 'renewal' ) ) as $subscription ) { - $this->log( 'Calling purge delete on ' . current_filter() . ' for ' . $subscription->get_id() ); - $this->clear_related_order_cache( $subscription ); + wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Related order caching is now handled by %1$s.', 'woocommerce-subscriptions' ), 'WCS_Related_Order_Store' ) ); + if ( is_callable( array( WCS_Related_Order_Store::instance(), 'delete_related_order_id_from_caches' ) ) ) { + WCS_Related_Order_Store::instance()->delete_related_order_id_from_caches( $post_id ); } } if ( 'shop_subscription' === $post_type ) { + wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Customer subscription caching is now handled by %1$s.', 'woocommerce-subscriptions' ), 'WCS_Customer_Store_Cached_CPT' ) ); + // Purge wcs_do_subscriptions_exist cache, but only on the before_delete_post hook. if ( doing_action( 'before_delete_post' ) ) { $this->log( "Subscription {$post_id} deleted. Purging subscription cache." ); @@ -106,49 +100,28 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { * * @param $meta_id integer the ID of the meta in the meta table * @param $object_id integer the ID of the post we're updating on, only concerned with order IDs - * @param $meta_key string the meta_key in the table, only concerned with '_subscription_renewal', '_subscription_resubscribe' & '_subscription_switch' keys + * @param $meta_key string the meta_key in the table, only concerned with the '_customer_user' key * @param $meta_value mixed the ID of the subscription that relates to the order */ public function purge_from_metadata( $meta_id, $object_id, $meta_key, $meta_value ) { - static $combined_keys = null; - static $order_keys = array( - '_subscription_renewal' => 1, - '_subscription_resubscribe' => 1, - '_subscription_switch' => 1, - ); - static $subscription_keys = array( - '_customer_user' => 1, - ); - - if ( null === $combined_keys ) { - $combined_keys = array_merge( $order_keys, $subscription_keys ); - } + wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Customer subscription caching is now handled by %1$s and %2$s.', 'woocommerce-subscriptions' ), 'WCS_Customer_Store_Cached_CPT', 'WCS_Post_Meta_Cache_Manager' ) ); // Ensure we're handling a meta key we actually care about. - if ( ! isset( $combined_keys[ $meta_key ] ) ) { + if ( '_customer_user' !== $meta_key || 'shop_subscription' !== get_post_type( $object_id ) ) { return; } - if ( 'shop_order' === get_post_type( $object_id ) && isset( $order_keys[ $meta_key ] ) ) { - $this->log( sprintf( - 'Calling purge from %1$s on object %2$s and meta value %3$s due to %4$s meta key.', - current_filter(), - $object_id, - $meta_value, - $meta_key - ) ); - $this->clear_related_order_cache( $meta_value ); - } elseif ( 'shop_subscription' === get_post_type( $object_id ) && isset( $subscription_keys[ $meta_key ] ) ) { - $this->purge_subscription_user_cache( $object_id ); - } + $this->purge_subscription_user_cache( $object_id ); } /** * Wrapper function to clear the cache that relates to related orders * * @param null $subscription_id + * @deprecated 2.3.0 */ protected function clear_related_order_cache( $subscription_id ) { + wcs_deprecated_function( __METHOD__, '2.3.0', __( 'new related order methods in WCS_Related_Order_Store', 'woocommerce-subscriptions' ) ); // if it's not a Subscription, we don't deal with it if ( is_object( $subscription_id ) && $subscription_id instanceof WC_Subscription ) { @@ -159,6 +132,12 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { return; } + // Clear the new cache, to honour the method call + if ( is_callable( array( WCS_Related_Order_Store::instance(), 'delete_caches_for_subscription' ) ) ) { + WCS_Related_Order_Store::instance()->delete_caches_for_subscription( $subscription_id ); + } + + // Clear the old cache, just in case it's still got data $key = 'wcs-related-orders-to-' . $subscription_id; $this->log( 'In the clearing, key being purged is this: ' . print_r( $key, true ) ); @@ -174,6 +153,8 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { * @return bool */ public function delete_cached( $key ) { + wcs_deprecated_argument( __METHOD__, '2.3.0' ); + if ( ! is_string( $key ) || empty( $key ) ) { return false; } @@ -253,6 +234,8 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { * @param int $subscription_id The subscription to purge. */ protected function purge_subscription_user_cache( $subscription_id ) { + wcs_deprecated_argument( __METHOD__, '2.3.0', sprintf( __( 'Customer subscription caching is now handled by %1$s and %2$s.', 'woocommerce-subscriptions' ), 'WCS_Customer_Store_Cached_CPT', 'WCS_Post_Meta_Cache_Manager' ) ); + $subscription = wcs_get_subscription( $subscription_id ); $subscription_user_id = $subscription->get_user_id(); $this->log( sprintf( @@ -262,45 +245,4 @@ class WCS_Cached_Data_Manager extends WCS_Cache_Manager { ) ); $this->delete_cached( "wcs_user_subscriptions_{$subscription_user_id}" ); } - - /* Deprecated Functions */ - - /** - * Wrapper function to clear cache that relates to related orders - * - * @param null $subscription_id - */ - public function wcs_clear_related_order_cache( $subscription_id = null ) { - _deprecated_function( __METHOD__, '2.1.2', __CLASS__ . '::clear_related_order_cache( $subscription_id )' ); - $this->clear_related_order_cache( $subscription_id ); - } - - /** - * Clearing for orders / subscriptions with sanitizing bits - * - * @param $post_id integer the ID of an order / subscription - */ - public function purge_subscription_cache_on_update( $post_id ) { - _deprecated_function( __METHOD__, '2.1.2', __CLASS__ . '::clear_related_order_cache( $subscription_id )' ); - - $post_type = get_post_type( $post_id ); - - if ( 'shop_subscription' === $post_type ) { - - $this->clear_related_order_cache( $post_id ); - - } elseif ( 'shop_order' === $post_type ) { - - $subscriptions = wcs_get_subscriptions_for_order( $post_id, array( 'order_type' => 'any' ) ); - - if ( empty( $subscriptions ) ) { - $this->log( 'No subscriptions for this ID: ' . $post_id ); - } else { - foreach ( $subscriptions as $subscription ) { - $this->log( 'Got subscription, calling clear_related_order_cache for ' . $subscription->get_id() ); - $this->clear_related_order_cache( $subscription ); - } - } - } - } } diff --git a/includes/class-wcs-cart-initial-payment.php b/includes/class-wcs-cart-initial-payment.php index a91178b..6376f27 100755 --- a/includes/class-wcs-cart-initial-payment.php +++ b/includes/class-wcs-cart-initial-payment.php @@ -22,6 +22,9 @@ class WCS_Cart_Initial_Payment extends WCS_Cart_Renewal { public function __construct() { $this->setup_hooks(); + + // When an order is paid for via checkout, ensure a new order isn't created due to mismatched cart hashes + add_filter( 'woocommerce_create_order', array( &$this, 'update_cart_hash' ), 10, 1 ); } /** diff --git a/includes/class-wcs-cart-renewal.php b/includes/class-wcs-cart-renewal.php index 474823d..3d884ee 100755 --- a/includes/class-wcs-cart-renewal.php +++ b/includes/class-wcs-cart-renewal.php @@ -39,7 +39,7 @@ class WCS_Cart_Renewal { add_filter( 'woocommerce_default_order_status', array( &$this, 'maybe_preserve_order_status' ) ); // When a failed/pending renewal order is paid for via checkout, ensure a new order isn't created due to mismatched cart hashes - add_filter( 'woocommerce_create_order', array( &$this, 'set_renewal_order_cart_hash' ), 10, 1 ); + add_filter( 'woocommerce_create_order', array( &$this, 'update_cart_hash' ), 10, 1 ); // When a user is prevented from paying for a failed/pending renewal order because they aren't logged in, redirect them back after login add_filter( 'woocommerce_login_redirect', array( &$this, 'maybe_redirect_after_login' ), 10 , 1 ); @@ -48,6 +48,9 @@ class WCS_Cart_Renewal { add_action( 'woocommerce_checkout_order_processed', array( &$this, 'update_session_cart_after_updating_renewal_order' ), 10 ); add_filter( 'wc_dynamic_pricing_apply_cart_item_adjustment', array( &$this, 'prevent_compounding_dynamic_discounts' ), 10, 2 ); + + // Remove non-recurring fees from renewal carts. Hooked in late (priority 1000), to ensure we handle all fees added by third-parties. + add_action( 'woocommerce_cart_calculate_fees', array( $this, 'remove_non_recurring_fees' ), 1000 ); } /** @@ -326,7 +329,9 @@ class WCS_Cart_Renewal { /** * Check if a renewal order subscription has any coupons applied and if so add pseudo renewal coupon equivalents to ensure the discount is still applied * - * @param object $subscription subscription + * @param WC_Subscription $subscription subscription + * @param WC_Order $order + * * @since 2.0.10 */ public function maybe_setup_discounts( $subscription, $order = null ) { @@ -1029,12 +1034,23 @@ class WCS_Cart_Renewal { * * @param Mixed | An order generated by third party plugins * @return Mixed | The unchanged order param - * @since 2.1.0 + * @since 2.2.11 */ - public function set_renewal_order_cart_hash( $order ) { + public function update_cart_hash( $order ) { - if ( $item = wcs_cart_contains_renewal() ) { - $this->set_cart_hash( $item[ $this->cart_item_key ]['renewal_order_id'] ); + if ( $item = $this->cart_contains() ) { + + if ( isset( $item[ $this->cart_item_key ]['renewal_order_id'] ) ) { + $order_id = $item[ $this->cart_item_key ]['renewal_order_id']; + } elseif ( isset( $item[ $this->cart_item_key ]['order_id'] ) ) { + $order_id = $item[ $this->cart_item_key ]['order_id']; + } else { + $order_id = ''; + } + + if ( $order_id ) { + $this->set_cart_hash( $order_id ); + } } return $order; @@ -1257,6 +1273,37 @@ class WCS_Cart_Renewal { } } + /** + * Remove any fees applied to the renewal cart which aren't recurring. + * + * @param WC_Cart $cart A WooCommerce cart object. + */ + public function remove_non_recurring_fees( $cart ) { + + if ( ! $this->cart_contains() ) { + return; + } + + $cart_fees = $cart->get_fees(); + + // WC doesn't have a method for removing fees individually so we clear them and re-add them where applicable. + if ( is_callable( array( $cart, 'fees_api' ) ) ) { // WC 3.2 + + $cart->fees_api()->remove_all_fees(); + } else { + $cart->fees = array(); + } + + foreach ( $cart_fees as $fee ) { + if ( true === apply_filters( 'woocommerce_subscriptions_is_recurring_fee', false, $fee, $cart ) ) { + if ( is_callable( array( $cart, 'fees_api' ) ) ) { // WC 3.2 + + $cart->fees_api()->add_fee( $fee ); + } else { + $cart->add_fee( $fee->name, $fee->amount, $fee->taxable, $fee->tax_class ); + } + } + } + } + /* Deprecated */ /** @@ -1321,5 +1368,19 @@ class WCS_Cart_Renewal { _deprecated_function( __METHOD__, '2.2.1', __CLASS__ . '::add_line_item_meta( $order_item, $cart_item_key, $cart_item )' ); $this->add_line_item_meta( $order_item, $cart_item_key, $cart_item ); } + + /** + * Right before WC processes a renewal cart through the checkout, set the cart hash. + * This ensures legitimate changes to taxes and shipping methods don't cause a new order to be created. + * + * @param Mixed | An order generated by third party plugins + * @return Mixed | The unchanged order param + * @since 2.1.0 + */ + public function set_renewal_order_cart_hash( $order ) { + _deprecated_function( __METHOD__, '2.3', __CLASS__ . '::update_cart_hash( $order )' ); + $this->update_cart_hash( $order ); + return $order; + } } new WCS_Cart_Renewal(); diff --git a/includes/class-wcs-cart-resubscribe.php b/includes/class-wcs-cart-resubscribe.php index eb0cdff..69fceef 100755 --- a/includes/class-wcs-cart-resubscribe.php +++ b/includes/class-wcs-cart-resubscribe.php @@ -149,9 +149,9 @@ class WCS_Cart_Resubscribe extends WCS_Cart_Renewal { $cart_item = $this->cart_contains( $recurring_cart ); if ( false !== $cart_item ) { - wcs_set_objects_property( $order, 'subscription_resubscribe', $cart_item[ $this->cart_item_key ]['subscription_id'] ); - $new_subscription->update_meta_data( '_subscription_resubscribe', $cart_item[ $this->cart_item_key ]['subscription_id'] ); - $new_subscription->save(); + $old_subscription = wcs_get_subscription( $cart_item[ $this->cart_item_key ]['subscription_id'] ); + WCS_Related_Order_Store::instance()->add_relation( $order, $old_subscription, 'resubscribe' ); + WCS_Related_Order_Store::instance()->add_relation( $new_subscription, $old_subscription, 'resubscribe' ); } } diff --git a/includes/class-wcs-cart-switch.php b/includes/class-wcs-cart-switch.php index 30cac78..66bef80 100755 --- a/includes/class-wcs-cart-switch.php +++ b/includes/class-wcs-cart-switch.php @@ -7,7 +7,7 @@ */ class WCS_Cart_Switch extends WCS_Cart_Renewal { - /* The flag used to indicate if a cart item is a renewal */ + /* The flag used to indicate if a cart item is a subscription switch */ public $cart_item_key = 'subscription_switch'; /** diff --git a/includes/class-wcs-limiter.php b/includes/class-wcs-limiter.php index 30b31ea..13255b5 100755 --- a/includes/class-wcs-limiter.php +++ b/includes/class-wcs-limiter.php @@ -140,7 +140,7 @@ class WCS_Limiter { if ( isset( $_GET['switch-subscription'] ) ) { $is_purchasable = true; - //Validating when restring cart from session + //Validating when restoring cart from session } elseif ( WC_Subscriptions_Switcher::cart_contains_switches() ) { $is_purchasable = true; diff --git a/includes/class-wcs-post-meta-cache-manager-many-to-one.php b/includes/class-wcs-post-meta-cache-manager-many-to-one.php new file mode 100755 index 0000000..e908b0d --- /dev/null +++ b/includes/class-wcs-post-meta-cache-manager-many-to-one.php @@ -0,0 +1,31 @@ +meta_updated_with_previous( null, $post_id, $meta_key, $meta_value, get_post_meta( $post_id, $meta_key, true ) ); + } +} diff --git a/includes/class-wcs-post-meta-cache-manager.php b/includes/class-wcs-post-meta-cache-manager.php new file mode 100755 index 0000000..6a7be97 --- /dev/null +++ b/includes/class-wcs-post-meta-cache-manager.php @@ -0,0 +1,254 @@ +post_type = $post_type; + + // We store the meta keys as the array keys to take advantage of the better query performance of isset() vs. in_array() + $this->meta_keys = array_flip( $meta_keys ); + } + + /** + * Attach callbacks to keep related order caches up-to-date. + */ + public function init() { + + // When the post for a related order is deleted or untrashed, make sure the corresponding related order cache is updated + add_action( 'before_delete_post', array( $this, 'post_deleted' ) ); + add_action( 'trashed_post', array( $this, 'post_deleted' ) ); + add_action( 'untrashed_post', array( $this, 'post_untrashed' ) ); + + // When a related order post meta flag is modified, make sure the corresponding related order cache is updated + add_action( 'added_post_meta', array( $this, 'meta_added' ), 10, 4 ); + add_action( 'update_post_meta', array( $this, 'meta_updated' ), 10, 4 ); + add_action( 'deleted_post_meta', array( $this, 'meta_deleted' ), 10, 4 ); + + // Special handling for meta updates containing a previous order ID to make sure we also delete any previously linked relationship + add_action( 'update_post_metadata', array( $this, 'meta_updated_with_previous' ), 10, 5 ); + + // Special handling for meta deletion on all posts/orders, not a specific post/order ID + add_action( 'delete_post_metadata', array( $this, 'meta_deleted_all' ), 100, 5 ); + } + + /** + * Check if the post meta change is one to act on or ignore, based on the post type and meta key being changed. + * + * One gotcha here: the 'delete_post_metadata' hook can be triggered with a $post_id of null. This is done when + * meta is deleted by key (i.e. delete_post_meta_by_key()) or when meta is being deleted for a specific value for + * all posts (as done by wp_delete_attachment() to remove the attachment from posts). To handle these cases, + * we only check the post type when the $post_id is non-null. + * + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @return bool False if the change should not be ignored, true otherwise. + */ + protected function is_change_to_ignore( $post_id, $meta_key = '' ) { + if ( ! is_null( $post_id ) && false === $this->is_managed_post_type( $post_id ) ) { + return true; + } elseif ( empty( $meta_key ) || ! isset( $this->meta_keys[ $meta_key ] ) ) { + return true; + } else { + return false; + } + } + + /* Callbacks for post meta hooks */ + + /** + * When post meta is added, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param int $meta_id The ID of the post meta row in the database. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The value being set in the database. + */ + public function meta_added( $meta_id, $post_id, $meta_key, $meta_value ) { + $this->maybe_trigger_update_cache_hook( 'add', $post_id, $meta_key, $meta_value ); + } + + /** + * When post meta is deleted, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param int $meta_id The ID of the post meta row in the database. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The value being delete from the database. + */ + public function meta_deleted( $meta_id, $post_id, $meta_key, $meta_value ) { + $this->maybe_trigger_update_cache_hook( 'delete', $post_id, $meta_key, $meta_value ); + } + + /** + * When post meta is updated from a previous value, check if this class instance cares about + * updating its cache to reflect the change. + * + * @param mixed $check Whether to update the meta or not. By default, this is null, meaning it will be updated. Callbacks may override it to prevent that. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The new value being saved in the database. + * @param mixed $prev_value The previous value stored in the database. + * @return mixed $check This method is attached to the "update_{$meta_type}_metadata" filter, which is used as a pre-check on whether to update meta data, so it needs to return the $check value passed in. + */ + public function meta_updated_with_previous( $check, $post_id, $meta_key, $meta_value, $prev_value ) { + + // If the meta data isn't actually being changed, we don't need to do anything. The use of == instead of === is deliberate to account for typecasting that can happen in WC's CRUD classes (e.g. ints cast as strings or bools as ints) + if ( $check || $prev_value == $meta_value ) { + return $check; + } + + $this->maybe_trigger_update_cache_hook( 'update', $post_id, $meta_key, $meta_value, $prev_value ); + + return $check; + } + + /** + * When post meta is updated, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param int $meta_id The ID of the post meta row in the database. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The value being deleted from the database. + */ + public function meta_updated( $meta_id, $post_id, $meta_key, $meta_value ) { + $this->meta_updated_with_previous( null, $post_id, $meta_key, $meta_value, '' ); + } + + /** + * When all post meta rows for a given key are about to be deleted, check if this class instance + * cares about updating its cache to reflect the change. + * + * WordPress has special handling for meta deletion on all posts rather than a specific post ID. + * This method handles that case. + * + * @param mixed $check Whether to delete the meta or not. By default, this is null, meaning it will be deleted. Callbacks may override it to prevent that. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The value being deleted from the database. + * @param bool $delete_all Whether meta data is being deleted on all posts, not a specific post. + * @return mixed $check This method is attached to the "update_{$meta_type}_metadata" filter, which is used as a pre-check on whether to update meta data, so it needs to return the $check value passed in. + */ + public function meta_deleted_all( $check, $post_id, $meta_key, $meta_value, $delete_all ) { + + if ( $delete_all && null === $check && false === $this->is_change_to_ignore( $post_id, $meta_key ) ) { + $this->trigger_delete_all_caches_hook( $meta_key ); + } + + return $check; + } + + /* Callbacks for post hooks */ + + /** + * When a post object is restored from the trash, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param int $post_id The post being restroed. + */ + public function post_untrashed( $post_id ) { + $this->maybe_update_for_post_change( 'add', $post_id ); + } + + /** + * When a post object is deleted or trashed, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param int $post_id The post being restroed. + */ + public function post_deleted( $post_id ) { + $this->maybe_update_for_post_change( 'delete', $post_id ); + } + + /** + * When a post object is changed, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param string $update_type The type of update to check. Only 'add' or 'delete' should be used. + * @param int $post_id The post being changed. + * @throws InvalidArgumentException If the given update type is not 'add' or 'delete'. + */ + protected function maybe_update_for_post_change( $update_type, $post_id ) { + + if ( ! in_array( $update_type, array( 'add', 'delete' ) ) ) { + throw new InvalidArgumentException( sprintf( __( 'Invalid update type: %s. Post update types supported are "add" or "delete". Updates are done on post meta directly.', 'woocommerce-subscriptions' ), $update_type ) ); + } + + foreach ( $this->meta_keys as $meta_key => $value ) { + $meta_value = ( 'add' === $update_type ) ? get_post_meta( $post_id, $meta_key, true ) : ''; + $this->maybe_trigger_update_cache_hook( $update_type, $post_id, $meta_key, $meta_value ); + } + } + + /** + * When post data is changed, check if this class instance cares about updating its cache + * to reflect the change. + * + * @param string $update_type The type of update to check. Only 'add' or 'delete' should be used. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The meta value. + * @param mixed $prev_value The previous value stored in the database. Optional. + */ + protected function maybe_trigger_update_cache_hook( $update_type, $post_id, $meta_key, $meta_value, $prev_value = '' ) { + if ( false === $this->is_change_to_ignore( $post_id, $meta_key ) ) { + $this->trigger_update_cache_hook( $update_type, $post_id, $meta_key, $meta_value, $prev_value ); + } + } + + /** + * Trigger a hook to allow 3rd party code to update its cache for data that it cares about. + * + * @param string $update_type The type of update to check. Only 'add' or 'delete' should be used. + * @param int $post_id The post the meta is being changed on. + * @param string $meta_key The post meta key being changed. + * @param mixed $meta_value The meta value. + * @param mixed $prev_value The previous value stored in the database. Optional. + */ + protected function trigger_update_cache_hook( $update_type, $post_id, $meta_key, $meta_value, $prev_value = '' ) { + do_action( 'wcs_update_post_meta_caches', $update_type, $post_id, $meta_key, $meta_value, $prev_value ); + } + + /** + * Trigger a hook to allow 3rd party code to delete its cache for data that it cares about. + * + * @param string $meta_key The post meta key being changed. + */ + protected function trigger_delete_all_caches_hook( $meta_key ) { + do_action( 'wcs_delete_all_post_meta_caches', $meta_key ); + } + + /** + * Abstract the check against get_post_type() so that it can be mocked for unit tests. + * + * @param int $post_id Post ID or post object. + * @return bool Whether the post type for the given post ID is the post type this instance manages. + */ + protected function is_managed_post_type( $post_id ) { + return $this->post_type === get_post_type( $post_id ); + } +} diff --git a/includes/class-wcs-query.php b/includes/class-wcs-query.php index d043e37..56d3468 100755 --- a/includes/class-wcs-query.php +++ b/includes/class-wcs-query.php @@ -18,6 +18,7 @@ class WCS_Query extends WC_Query { add_action( 'parse_request', array( $this, 'parse_request' ), 0 ); add_filter( 'woocommerce_get_breadcrumb', array( $this, 'add_breadcrumb' ), 10 ); add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ), 11 ); + add_filter( 'woocommerce_get_query_vars', array( $this, 'add_wcs_query_vars' ) ); // Inserting your new tab/page into the My Account page. add_filter( 'woocommerce_account_menu_items', array( $this, 'add_menu_items' ) ); @@ -27,7 +28,12 @@ class WCS_Query extends WC_Query { } $this->init_query_vars(); - add_filter( 'woocommerce_account_settings', array( $this, 'add_endpoint_account_settings' ) ); + + if ( WC_Subscriptions::is_woocommerce_pre( '3.4' ) ) { + add_filter( 'woocommerce_account_settings', array( $this, 'add_endpoint_account_settings' ) ); + } else { + add_filter( 'woocommerce_get_settings_advanced', array( $this, 'add_endpoint_account_settings' ) ); + } } /** @@ -117,7 +123,7 @@ class WCS_Query extends WC_Query { * @return array */ public function add_menu_items( $menu_items ) { - if ( 1 == count( wcs_get_users_subscriptions() ) ) { + if ( 1 == count( wcs_get_users_subscriptions() ) && apply_filters( 'wcs_my_account_redirect_to_single_subscription', true ) ) { $label = __( 'My Subscription', 'woocommerce-subscriptions' ); } else { $label = __( 'Subscriptions', 'woocommerce-subscriptions' ); @@ -145,7 +151,7 @@ class WCS_Query extends WC_Query { if ( 'subscriptions' == $endpoint && is_account_page() ) { $subscriptions = wcs_get_users_subscriptions(); - if ( 1 == count( $subscriptions ) ) { + if ( is_array( $subscriptions ) && 1 == count( $subscriptions ) && apply_filters( 'wcs_my_account_redirect_to_single_subscription', true ) ) { $subscription = reset( $subscriptions ); $url = $subscription->get_view_order_url(); } @@ -238,8 +244,6 @@ class WCS_Query extends WC_Query { * @return mixed $account_settings */ public function add_endpoint_account_settings( $settings ) { - $new_settings = array(); - $order_endpoint_found = false; $subscriptions_endpoint_setting = array( 'title' => __( 'Subscriptions', 'woocommerce-subscriptions' ), 'desc' => __( 'Endpoint for the My Account → Subscriptions page', 'woocommerce-subscriptions' ), @@ -258,23 +262,9 @@ class WCS_Query extends WC_Query { 'desc_tip' => true, ); - // Loop over and look for View Order Endpoint and include Subscriptions endpoint options after that. - foreach ( $settings as $value ) { + WC_Subscriptions_Admin::insert_setting_after( $settings, 'woocommerce_myaccount_view_order_endpoint', array( $subscriptions_endpoint_setting, $view_subscription_endpoint_setting ), 'multiple_settings' ); - if ( 'woocommerce_myaccount_view_order_endpoint' === $value['id'] ) { - $order_endpoint_found = true; - $new_settings[] = $value; - $new_settings[] = $subscriptions_endpoint_setting; - $new_settings[] = $view_subscription_endpoint_setting; - continue; - } elseif ( ! $order_endpoint_found && 'sectionend' === $value['type'] && 'account_endpoint_options' === $value['id'] ) { - // If we got to the end of the settings and didn't add our endpoints, add them to the end. - $new_settings[] = $subscriptions_endpoint_setting; - $new_settings[] = $view_subscription_endpoint_setting; - } - $new_settings[] = $value; - } - return $new_settings; + return $settings; } /** @@ -298,5 +288,17 @@ class WCS_Query extends WC_Query { } return $url; } + + /** + * Hooks into `woocommerce_get_query_vars` to make sure query vars defined in + * this class are also considered `WC_Query` query vars. + * + * @param array $query_vars + * @return array + * @since 2.3.0 + */ + public function add_wcs_query_vars( $query_vars ) { + return array_merge( $query_vars, $this->query_vars ); + } } new WCS_Query(); diff --git a/includes/class-wcs-select2.php b/includes/class-wcs-select2.php index 5381df7..79e6ef3 100755 --- a/includes/class-wcs-select2.php +++ b/includes/class-wcs-select2.php @@ -100,9 +100,17 @@ class WCS_Select2 { $html = "\n\n"; if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { - $html .= 'attributes_to_html( $this->attributes ); - $html .= '/>'; + if ( isset( $this->attributes['class'] ) && $this->attributes['class'] === 'wc-enhanced-select' ) { + $html .= ''; + } else { + $html .= 'attributes_to_html( $this->attributes ); + $html .= '/>'; + } } else { $attributes = $this->attributes; $selected_value = isset( $attributes['selected'] ) ? $attributes['selected'] : ''; diff --git a/includes/class-wcs-staging.php b/includes/class-wcs-staging.php new file mode 100755 index 0000000..2eab372 --- /dev/null +++ b/includes/class-wcs-staging.php @@ -0,0 +1,52 @@ +add_order_note( __( 'Payment processing skipped - renewal order created under staging site lock.', 'woocommerce-subscriptions' ) ); + } + } + + /** + * Add a badge to the Subscriptions submenu when a site is operating under a staging site lock. + * + * @param array $subscription_order_type_data The WC_Subscription register order type data. + * @since 2.3.0 + */ + public static function maybe_add_menu_badge( $subscription_order_type_data ) { + + if ( isset( $subscription_order_type_data['labels']['menu_name'] ) && WC_Subscriptions::is_duplicate_site() ) { + $subscription_order_type_data['labels']['menu_name'] .= '' . esc_html__( 'staging', 'woocommerce-subscriptions' ) . ''; + } + + return $subscription_order_type_data; + } +} diff --git a/includes/data-stores/class-wcs-customer-store-cached-cpt.php b/includes/data-stores/class-wcs-customer-store-cached-cpt.php new file mode 100755 index 0000000..c5ae060 --- /dev/null +++ b/includes/data-stores/class-wcs-customer-store-cached-cpt.php @@ -0,0 +1,279 @@ +post_meta_cache_manager = new WCS_Post_Meta_Cache_Manager_Many_To_One( 'shop_subscription', array( $this->get_meta_key() ) ); + } + + /** + * Attach callbacks to keep user subscription caches up-to-date and provide debug tools for managing the cache. + */ + protected function init() { + + $this->post_meta_cache_manager->init(); + + // When a user is first added, make sure the subscription cache is empty because it can not have any data yet, and we want to avoid running the query needlessly + add_filter( 'user_register', array( $this, 'set_empty_cache' ) ); + + // When the post for a subscription is change, make sure the corresponding cache is updated + add_action( 'wcs_update_post_meta_caches', array( $this, 'maybe_update_for_post_meta_change' ), 10, 5 ); + add_action( 'wcs_delete_all_post_meta_caches', array( $this, 'maybe_delete_all_for_post_meta_change' ), 10, 1 ); + + WCS_Debug_Tool_Factory::add_cache_tool( 'generator', __( 'Generate Customer Subscription Cache', 'woocommerce-subscriptions' ), __( 'This will generate the persistent cache for linking users with subscriptions. The caches will be generated overtime in the background (via Action Scheduler).', 'woocommerce-subscriptions' ), self::instance() ); + WCS_Debug_Tool_Factory::add_cache_tool( 'eraser', __( 'Delete Customer Subscription Cache', 'woocommerce-subscriptions' ), __( 'This will clear the persistent cache of all of subscriptions stored against users in your store. Expect slower performance of checkout, renewal and other subscription related functions after taking this action. The caches will be regenerated overtime as queries to find a given user\'s subscriptions are run.', 'woocommerce-subscriptions' ), self::instance() ); + } + + /* Public methods required by WCS_Customer_Store */ + + /** + * Get the IDs for a given user's subscriptions. + * + * Wrapper to support getting a user's subscription regardless of whether they are cached or not yet, + * either in the old transient cache, or new persistent cache. + * + * @param int $user_id The id of the user whose subscriptions you want. + * @return array + */ + public function get_users_subscription_ids( $user_id ) { + + $subscription_ids = $this->get_users_subscription_ids_from_cache( $user_id ); + + // get user meta returns an empty string when no matching row is found for the given key, meaning it's not set yet + if ( '' === $subscription_ids ) { + + $transient_key = "wcs_user_subscriptions_{$user_id}"; + + // We do this here rather than in get_users_subscription_ids_from_cache(), because we want to make sure the new persistent cache is updated too + $subscription_ids = wcs_get_transient_even_if_expired( $transient_key ); + + if ( false === $subscription_ids ) { + $subscription_ids = parent::get_users_subscription_ids( $user_id ); // no data in transient, query directly + } else { + rsort( $subscription_ids ); // the results from the database query are ordered by date/ID in DESC, so make sure the transient value is too + delete_transient( $transient_key ); // migrate the data to our new cache + } + + $this->update_subscription_id_cache( $user_id, $subscription_ids ); + } + + return $subscription_ids; + } + + /* Internal methods for managing the cache */ + + /** + * Find subscriptions for a given user from the cache. + * + * Applies the 'wcs_get_cached_users_subscription_ids' filter for backward compatibility with + * the now deprecated wcs_get_cached_user_subscription_ids() method. + * + * @param int $user_id The id of the user whose subscriptions you want. + * @return string|array An array of subscriptions in the cache, or an empty string when no matching row is found for the given key, meaning it's cache is not set yet or has been deleted + */ + protected function get_users_subscription_ids_from_cache( $user_id ) { + + // Empty user IDs, like 0 or '', are never cached + $subscription_ids = empty( $user_id ) ? array() : get_user_meta( $user_id, $this->cache_meta_key, true ); + + return apply_filters( 'wcs_get_cached_users_subscription_ids', $subscription_ids, $user_id ); + } + + /** + * Add a subscription ID to the cached subscriptions for a given user. + * + * @param int $user_id The user the subscription belongs to. + * @param int $subscription_id A subscription to link the user in the cache. + */ + protected function add_subscription_id_to_cache( $user_id, $subscription_id ) { + + $subscription_ids = $this->get_users_subscription_ids( $user_id ); + + if ( ! in_array( $subscription_id, $subscription_ids ) ) { + $subscription_ids[] = $subscription_id; + $this->update_subscription_id_cache( $user_id, $subscription_ids ); + } + } + + /** + * Delete a subscription ID from the cached IDs for a given user. + * + * @param int $user_id The user the subscription belongs to. + * @param int $subscription_id A subscription to link the user in the cache. + */ + protected function delete_subscription_id_from_cache( $user_id, $subscription_id ) { + + $subscription_ids = $this->get_users_subscription_ids( $user_id ); + + if ( ( $index = array_search( $subscription_id, $subscription_ids ) ) !== false ) { + unset( $subscription_ids[ $index ] ); + $this->update_subscription_id_cache( $user_id, $subscription_ids ); + } + } + + /** + * Helper function for setting subscription cache. + * + * @param int $user_id The id of the user who the subscriptions belongs to. + * @param array $subscription_ids Set of subscriptions to link with the given user. + * @return bool|int Returns meta ID if the key didn't exist; true on successful update; false on failure or if $subscription_ids is the same as the existing meta value in the database. + */ + protected function update_subscription_id_cache( $user_id, array $subscription_ids ) { + + // Never cache empty user IDs, like 0 or '' + if ( empty( $user_id ) ) { + return false; + } + + return update_user_meta( $user_id, $this->cache_meta_key, $subscription_ids ); + } + + /* Public methods used to bulk edit cache */ + + /** + * Clear all caches for all subscriptions against all users. + */ + public function delete_caches_for_all_users() { + delete_metadata( 'user', null, $this->cache_meta_key, null, true ); + } + + /* Public methods used as callbacks on hooks for managing cache */ + + /** + * Set empty subscription cache on a user. + * + * Newly registered users can't have subscriptions yet, so we set that cache to empty whenever a new user is added + * by attaching this to the 'user_register' hook. + * + * @param int $user_id The id of the user just created + */ + public function set_empty_cache( $user_id ) { + $this->update_subscription_id_cache( $user_id, array() ); + } + + /* Public methods attached to WCS_Post_Meta_Cache_Manager_Many_To_One hooks for managing the cache */ + + /** + * If there is a change to a subscription's post meta key, update the user meta cache. + * + * @param string $update_type The type of update to check. Can be 'add', 'update' or 'delete'. + * @param int $subscription_id The subscription's post ID where the customer is being changed. + * @param string $meta_key The post meta key being changed. + * @param mixed $user_id The meta value, which will be subscriber's user ID when $meta_key is '_customer_user'. + * @param mixed $old_user_id The previous value stored in the database for the subscription's '_customer_user'. Optional. + */ + public function maybe_update_for_post_meta_change( $update_type, $subscription_id, $meta_key, $user_id, $old_user_id = '' ) { + + if ( $this->get_meta_key() !== $meta_key ) { + return; + } + + switch ( $update_type ) { + case 'add' : + $this->add_subscription_id_to_cache( $user_id, $subscription_id ); + break; + case 'delete' : + // If we don't have a specific user ID, the post is being deleted as WCS_Post_Meta_Cache_Manager_Many_To_One doesn't pass the associated meta value for that event, so find the corresponding user ID from post meta directly + if ( empty( $user_id ) ) { + $user_id = get_post_meta( $subscription_id, $this->get_meta_key(), true ); + } + $this->delete_subscription_id_from_cache( $user_id, $subscription_id ); + break; + case 'update' : + if ( ! empty( $old_user_id ) ) { + $this->delete_subscription_id_from_cache( $old_user_id, $subscription_id ); + } + + $this->add_subscription_id_to_cache( $user_id, $subscription_id ); + break; + } + } + + /** + * Remove all caches for a given meta key if all entries for that meta key are being deleted. + * + * This is very unlikely to ever happen, because it would be equivalent to deleting the linked + * customer on all orders and subscriptions. But it is handled here anyway in case of things + * like removing WooCommerce entirely. + * + * @param string $meta_key The post meta key being changed. + */ + public function maybe_delete_all_for_post_meta_change( $meta_key ) { + if ( $this->get_meta_key() === $meta_key ) { + $this->delete_caches_for_all_users(); + } + } + + /** + * Get the IDs of users without a cache set. + * + * @param int $number The number of users to return. Use -1 to return all users. + * @return array + */ + protected function get_user_ids_without_cache( $number = 10 ) { + return get_users( array( + 'fields' => 'ids', + 'number' => $number, + 'meta_key' => $this->cache_meta_key, + 'meta_compare' => 'NOT EXISTS', + ) ); + } + + /** Methods to implement WCS_Cache_Updater - wrap more accurately named methods for the sake of clarity */ + + /** + * Get the items to be updated, if any. + * + * @return array An array of items to update, or empty array if there are no items to update. + */ + public function get_items_to_update() { + return $this->get_user_ids_without_cache(); + } + + /** + * Run the update for a single item. + * + * @param mixed $item The item to update. + */ + public function update_items_cache( $user_id ) { + // Getting the subscription IDs also sets the cache when it's not already set + $this->get_users_subscription_ids( $user_id ); + } + + /** + * Clear all caches. + */ + public function delete_all_caches() { + $this->delete_caches_for_all_users(); + }} diff --git a/includes/data-stores/class-wcs-customer-store-cpt.php b/includes/data-stores/class-wcs-customer-store-cpt.php new file mode 100755 index 0000000..8ce2940 --- /dev/null +++ b/includes/data-stores/class-wcs-customer-store-cpt.php @@ -0,0 +1,66 @@ +meta_key; + } + + /** + * Get the IDs for a given user's subscriptions by querying post meta. + * + * @param int $user_id The id of the user whose subscriptions you want. + * @return array + */ + public function get_users_subscription_ids( $user_id ) { + + if ( 0 === $user_id ) { + return array(); + } + + $query = new WP_Query(); + + return $query->query( array( + 'post_type' => 'shop_subscription', + 'posts_per_page' => -1, + 'post_status' => 'any', + 'orderby' => array( + 'date' => 'DESC', + 'ID' => 'DESC', + ), + 'fields' => 'ids', + 'no_found_rows' => true, + 'ignore_sticky_posts' => true, + 'meta_query' => array( + array( + 'key' => $this->get_meta_key(), + 'value' => $user_id, + ), + ), + ) ); + } +} diff --git a/includes/data-stores/class-wcs-product-variable-data-store-cpt.php b/includes/data-stores/class-wcs-product-variable-data-store-cpt.php new file mode 100755 index 0000000..9b1de73 --- /dev/null +++ b/includes/data-stores/class-wcs-product-variable-data-store-cpt.php @@ -0,0 +1,38 @@ +read_min_max_variation_data( $product ); + } + + /** + * Read min and max variation data from post meta. + * + * @param WC_Product_Variable_Subscription $product Product object. + */ + protected function read_min_max_variation_data( &$product ) { + if ( ! $product->meta_exists( '_min_max_variation_ids_hash' ) ) { + $product->set_min_and_max_variation_data(); + + update_post_meta( $product->get_id(), '_min_max_variation_data', $product->get_meta( '_min_max_variation_data', true ), true ); + update_post_meta( $product->get_id(), '_min_max_variation_ids_hash', $product->get_meta( '_min_max_variation_ids_hash', true ), true ); + } + } +} diff --git a/includes/data-stores/class-wcs-related-order-store-cached-cpt.php b/includes/data-stores/class-wcs-related-order-store-cached-cpt.php new file mode 100755 index 0000000..355ed15 --- /dev/null +++ b/includes/data-stores/class-wcs-related-order-store-cached-cpt.php @@ -0,0 +1,492 @@ +get_relation_type_for_meta_key() than using array_search(). + * + * @var array $relation_keys Post meta key => Order Relationship + */ + private $relation_keys; + + /** + * Constructor + */ + public function __construct() { + + parent::__construct(); + + foreach ( $this->get_meta_keys() as $relation_type => $meta_key ) { + $this->relation_keys[ $meta_key ] = $relation_type; + } + + $this->post_meta_cache_manager = new WCS_Post_Meta_Cache_Manager( 'shop_order', $this->get_meta_keys() ); + } + + /** + * Attach callbacks to keep related order caches up-to-date and make sure + * the cache doesn't mess with other data stores. + */ + protected function init() { + + $this->post_meta_cache_manager->init(); + + // Don't load cached related order meta data into subscriptions + add_filter( 'wcs_subscription_data_store_props_to_ignore', array( $this, 'add_related_order_cache_props' ), 10, 2 ); + + // When a subscription is first created, make sure its renewal order cache is empty because it can not have any renewals yet, and we want to avoid running the query needlessly + add_filter( 'wcs_created_subscription', array( $this, 'set_empty_renewal_order_cache' ), -1000 ); + + // When the post for a related order is deleted or untrashed, make sure the corresponding related order cache is updated + add_action( 'wcs_update_post_meta_caches', array( $this, 'maybe_update_for_post_meta_change' ), 10, 5 ); + add_action( 'wcs_delete_all_post_meta_caches', array( $this, 'maybe_delete_all_for_post_meta_change' ), 10, 1 ); + + // When copying meta from a subscription to a renewal order, don't copy cache related order meta keys. + add_filter( 'wcs_renewal_order_meta', array( $this, 'remove_related_order_cache_keys' ), 10, 1 ); + + WCS_Debug_Tool_Factory::add_cache_tool( 'generator', __( 'Generate Related Order Cache', 'woocommerce-subscriptions' ), __( 'This will generate the persistent cache of all renewal, switch, resubscribe and other order types for all subscriptions in your store. The caches will be generated overtime in the background (via Action Scheduler).', 'woocommerce-subscriptions' ), self::instance() ); + WCS_Debug_Tool_Factory::add_cache_tool( 'eraser', __( 'Delete Related Order Cache', 'woocommerce-subscriptions' ), __( 'This will clear the persistent cache of all renewal, switch, resubscribe and other order types for all subscriptions in your store. Expect slower performance of checkout, renewal and other subscription related functions after taking this action. The caches will be regenerated overtime as related order queries are run.', 'woocommerce-subscriptions' ), self::instance() ); + } + + /* Public methods required by WCS_Related_Order_Store */ + + /** + * Find orders related to a given subscription in a given way. + * + * Wrapper to support getting related orders regardless of whether they are cached or not yet, + * either in the old transient cache, or new persistent cache. + * + * @param WC_Order $subscription The ID of the subscription for which calling code wants the related orders. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + * + * @return array + */ + public function get_related_order_ids( WC_Order $subscription, $relation_type ) { + + $subscription_id = wcs_get_objects_property( $subscription, 'id' ); // We can't rely on $subscription->get_id() being available because we only require a WC_Order, not a WC_Subscription, and WC_Order does not have get_id() available with WC < 3.0 + $related_order_ids = $this->get_related_order_ids_from_cache( $subscription_id, $relation_type ); + + // get post meta returns an empty string when no matching row is found for the given key, meaning it's not set yet + if ( '' === $related_order_ids ) { + + if ( 'renewal' === $relation_type ) { + $transient_key = "wcs-related-orders-to-{$subscription_id}"; // despite the name, this transient only stores renewal orders, not all related orders, so we can only use it for finding renewal orders + + // We do this here rather than in get_related_order_ids_from_cache(), because we want to make sure the new persistent cache is updated too + $related_order_ids = wcs_get_transient_even_if_expired( $transient_key ); + } else { + $related_order_ids = false; + } + + if ( false === $related_order_ids ) { + $related_order_ids = parent::get_related_order_ids( $subscription, $relation_type ); // no data in transient, query directly + } else { + rsort( $related_order_ids ); // queries are ordered from newest ID to oldest, so make sure the transient value is too + delete_transient( $transient_key ); // we migrate the data to our new cache so want to remote this cache + } + + $this->update_related_order_id_cache( $subscription_id, $related_order_ids, $relation_type ); + } + + return $related_order_ids; + } + + /** + * Helper function for linking an order to a subscription via a given relationship. + * + * @param WC_Order $order The order to link with the subscription. + * @param WC_Order $subscription The order or subscription to link the order to. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + public function add_relation( WC_Order $order, WC_Order $subscription, $relation_type ) { + $this->add_related_order_id_to_cache( wcs_get_objects_property( $order, 'id' ), wcs_get_objects_property( $subscription, 'id' ), $relation_type ); + parent::add_relation( $order, $subscription, $relation_type ); + } + + /** + * Remove the relationship between a given order and subscription. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param WC_Order $subscription A subscription or order to unlink the order with, if a relation exists. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + public function delete_relation( WC_Order $order, WC_Order $subscription, $relation_type ) { + $this->delete_related_order_id_from_cache( wcs_get_objects_property( $order, 'id' ), wcs_get_objects_property( $subscription, 'id' ), $relation_type ); + parent::delete_relation( $order, $subscription, $relation_type ); + } + + /** + * Remove all related orders/subscriptions of a given type from an order. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + public function delete_relations( WC_Order $order, $relation_type ) { + $this->delete_related_order_id_from_caches( wcs_get_objects_property( $order, 'id' ), $relation_type ); + parent::delete_relations( $order, $relation_type ); + } + + /* Internal methods for managing the cache */ + + /** + * Find orders related to a given subscription in a given way from the cache. + * + * @param int $subscription_id The ID of the subscription for which calling code wants the related orders. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + * @return string|array An array of related orders in the cache, or an empty string when no matching row is found for the given key, meaning it's cache is not set yet or has been deleted + */ + protected function get_related_order_ids_from_cache( $subscription_id, $relation_type ) { + return get_post_meta( $subscription_id, $this->get_cache_meta_key( $relation_type ), true ); + } + + /** + * Add a related order ID to the cached related order IDs for a given order relationship. + * + * @param int $order_id An order to link with the subscription. + * @param int $subscription_id A subscription to link the order to. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + */ + protected function add_related_order_id_to_cache( $order_id, $subscription_id, $relation_type ) { + + $subscription = wcs_get_subscription( $subscription_id ); + + // If we can't get a valid subscription, we can't update its cache + if ( false === $subscription ) { + return; + } + + $related_order_ids = $this->get_related_order_ids( $subscription, $relation_type ); + + if ( ! in_array( $order_id, $related_order_ids ) ) { + // Add the new order to the beginning of the array to preserve sort order from newest to oldest + array_unshift( $related_order_ids, $order_id ); + $this->update_related_order_id_cache( $subscription_id, $related_order_ids, $relation_type ); + } + } + + /** + * Delete a related order ID from the cached related order IDs for a given order relationship. + * + * @param int $order_id The order that may be linked with subscriptions. + * @param int $subscription_id A subscription to remove a linked order from. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + */ + protected function delete_related_order_id_from_cache( $order_id, $subscription_id, $relation_type ) { + + $subscription = wcs_get_subscription( $subscription_id ); + + // If we can't get a valid subscription, we can't udpate its cache + if ( false === $subscription ) { + return; + } + + $related_order_ids = $this->get_related_order_ids( $subscription, $relation_type ); + + if ( ( $index = array_search( $order_id, $related_order_ids ) ) !== false ) { + unset( $related_order_ids[ $index ] ); + $this->update_related_order_id_cache( $subscription_id, $related_order_ids, $relation_type ); + } + } + + /** + * Helper function for setting related order cache. + * + * @param int $subscription_id A subscription to update the linked order IDs for. + * @param array $related_order_ids Set of orders related to the given subscription. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + * @return bool|int Returns related order cache's meta ID if it doesn't exist yet, otherwise returns true on success and false on failure. NOTE: If the $related_order_ids passed to this function are the same as those already in the database, this function returns false. + */ + protected function update_related_order_id_cache( $subscription_id, array $related_order_ids, $relation_type ) { + return update_post_meta( $subscription_id, $this->get_cache_meta_key( $relation_type ), $related_order_ids ); + } + + /** + * Get the meta key used to store the cache of linked order with a subscription, based on the type of relationship. + * + * @param string $relation_type The order's relationship with the subscription. Must be 'renewal', 'switch' or 'resubscribe'. + * @param string $prefix_meta_key Whether to add the underscore prefix to the meta key or not. 'prefix' to prefix the key. 'do_not_prefix' to not prefix the key. + * @return string + */ + protected function get_cache_meta_key( $relation_type, $prefix_meta_key = 'prefix' ) { + return sprintf( '%s_order_ids_cache', $this->get_meta_key( $relation_type, $prefix_meta_key ) ); + } + + /* Public methods used to bulk edit cache */ + + /** + * Clear related order caches for a given subscription. + * + * @param int $subscription_id The ID of a subscription that may have linked orders. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. Use 'any' to delete all cached. + */ + public function delete_caches_for_subscription( $subscription_id, $relation_type = 'any' ) { + foreach ( $this->get_relation_types() as $possible_relation_type ) { + if ( 'any' === $relation_type || $relation_type === $possible_relation_type ) { + delete_post_meta( $subscription_id, $this->get_cache_meta_key( $possible_relation_type ) ); + } + } + } + + /** + * Remove an order from all related order caches. + * + * @param int $order_id The order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. Use 'any' to delete all cached. + */ + public function delete_related_order_id_from_caches( $order_id, $relation_type = 'any' ) { + $relation_types = 'any' === $relation_type ? $this->get_relation_types() : array( $relation_type ); + foreach ( wcs_get_subscriptions_for_order( $order_id, array( 'order_type' => $relation_types ) ) as $subscription_id => $subscription ) { + foreach ( $relation_types as $type ) { + $this->delete_related_order_id_from_cache( $order_id, $subscription_id, $type ); + } + } + } + + /** + * Clear all related order caches for all subscriptions. + * + * @param array $relation_types The relations to clear, or an empty array to clear all relations (default). + */ + public function delete_caches_for_all_subscriptions( $relation_types = array() ) { + + if ( empty( $relation_types ) ) { + $relation_types = $this->get_relation_types(); + } + + // Set variables to workaround ambiguous parameters of delete_metadata() + $delete_all = true; + $null_post_id = $null_meta_value = null; + foreach ( $relation_types as $relation_type ) { + delete_metadata( 'post', $null_post_id, $this->get_cache_meta_key( $relation_type ), $null_meta_value, $delete_all ); + } + } + + /* Public methods used as callbacks on hooks for managing cache */ + + /** + * Add related order cache meta keys to a set of props for a subscription data store. + * + * Related order cache APIs need to be handled by querying a central data source directly, instead of using + * data set on an instance of the subscription, as it can be changed by other events outside of that instance's + * knowledge or access. For now, this is done via the database. That may be changed in future to use an object + * cache, but regardless, the prop should never be a source of that data. This method is attached to the filter + * 'wcs_subscription_data_store_props_to_ignore' so that cache keys are ignored. + * + * @param array $props_to_ignore A mapping of meta keys => prop names. + * @param WCS_Subscription_Data_Store_CPT $data_store + * @return array A mapping of meta keys => prop names, filtered by ones that should be updated. + */ + public function add_related_order_cache_props( $props_to_ignore, $data_store ) { + + if ( is_a( $data_store, 'WCS_Subscription_Data_Store_CPT' ) ) { + foreach ( $this->get_meta_keys() as $relation_type => $meta_key ) { + $props_to_ignore[ $this->get_cache_meta_key( $relation_type ) ] = $this->get_cache_meta_key( $relation_type, 'do_not_prefix' ); + } + } + + return $props_to_ignore; + } + + /** + * Set empty renewal order cache on a subscription. + * + * Newly created subscriptions can't have renewal orders yet, so we set that cache to empty whenever a new + * subscription is created. They can have switch or resubscribe orders, which may have been created before them on + * checkout, so we don't touch those caches. + * + * @param WC_Subscription $subscription A subscription to set empty renewal cache against. + * @return WC_Subscription Return the instance of the subscription, required as method is attached to the 'wcs_created_subscription' filter + */ + public function set_empty_renewal_order_cache( WC_Subscription $subscription ) { + $this->update_related_order_id_cache( $subscription->get_id(), array(), 'renewal' ); + return $subscription; + } + + /* Public methods attached to WCS_Post_Meta_Cache_Manager hooks for managing the cache */ + + /** + * If there is a change to a related order post meta key, update the cache. + * + * @param string $update_type The type of update to check. Can be 'add', 'update' or 'delete'. + * @param int $order_id The post the meta is being changed on. + * @param string $post_meta_key The post meta key being changed. + * @param mixed $subscription_id The related subscription's ID, as stored in meta value (only when the meta key is a related order meta key). + * @param mixed $old_subscription_id The previous value stored in the database for the related subscription. Optional. + */ + public function maybe_update_for_post_meta_change( $update_type, $order_id, $post_meta_key, $subscription_id, $old_subscription_id = '' ) { + + $relation_type = $this->get_relation_type_for_meta_key( $post_meta_key ); + + if ( false === $relation_type ) { + return; + } + + switch ( $update_type ) { + case 'add' : + $this->add_related_order_id_to_cache( $order_id, $subscription_id, $relation_type ); + break; + case 'delete' : + // If we don't have a specific subscription ID, the order/post is being deleted, so clear it from all caches + if ( empty( $subscription_id ) ) { + $this->delete_related_order_id_from_caches( $order_id, $relation_type ); + } else { + $this->delete_related_order_id_from_cache( $order_id, $subscription_id, $relation_type ); + } + break; + case 'update' : + if ( ! empty( $old_subscription_id ) ) { + $this->delete_related_order_id_from_cache( $order_id, $old_subscription_id, $relation_type ); + } + + $this->add_related_order_id_to_cache( $order_id, $subscription_id, $relation_type ); + break; + } + } + + /** + * Remove all caches for a given meta key if all entries for that meta key are being deleted. + * + * @param string $post_meta_key The post meta key being changed. + */ + public function maybe_delete_all_for_post_meta_change( $post_meta_key ) { + + $relation_type = $this->get_relation_type_for_meta_key( $post_meta_key ); + + if ( $relation_type ) { + $this->delete_caches_for_all_subscriptions( array( $relation_type ) ); + } + } + + /** + * Get the IDs of subscriptions without related order cache set for a give relation type or types. + * + * If more than one relation is specified, a batch of subscription IDs will be returned that are missing + * either of those relations, not both. + * + * @param array $relation_types The relations to check, or an empty array to check for any relation type (default). + * @param int $batch_size The number of subscriptions to return. Use -1 to return all subscriptions. + * @return array + */ + protected function get_subscription_ids_without_cache( $relation_types = array(), $batch_size = 10 ) { + global $wpdb; + + if ( empty( $relation_types ) ) { + $relation_types = $this->get_relation_types(); + } + + $subscription_ids = array(); + + foreach ( $relation_types as $relation_type ) { + + $limit = $batch_size - count( $subscription_ids ); + + // Use a subquery instead of a meta query with get_posts() as it's more performant than the multiple joins created by get_posts() + $post_ids = $wpdb->get_col( $wpdb->prepare( + "SELECT ID FROM $wpdb->posts + WHERE post_type = 'shop_subscription' + AND post_status NOT IN ('trash','auto-draft') + AND ID NOT IN ( + SELECT post_id FROM $wpdb->postmeta + WHERE meta_key = %s + ) + LIMIT 0, %d", + $this->get_cache_meta_key( $relation_type ), + $limit + ) ); + + if ( $post_ids ) { + $subscription_ids += $post_ids; + + if ( count( $subscription_ids ) >= $batch_size ) { + break; + } + } + } + + return $subscription_ids; + } + + /** + * Get the order relation for a given post meta key. + * + * @param string $meta_key The post meta key being changed. + * @return bool|string The order relation if it exists, or false if no such meta key exists. + */ + private function get_relation_type_for_meta_key( $meta_key ) { + return isset( $this->relation_keys[ $meta_key ] ) ? $this->relation_keys[ $meta_key ] : false; + } + + /** + * Remove related order cache meta data from order meta copied from subscriptions to renewal orders. + * + * @param array $meta An order's meta data. + * @return array Filtered order meta data to be copied. + */ + public function remove_related_order_cache_keys( $meta ) { + + $cache_meta_keys = array_map( array( $this, 'get_cache_meta_key' ), $this->get_relation_types() ); + + foreach ( $meta as $index => $meta_data ) { + if ( ! empty( $meta_data['meta_key'] ) && in_array( $meta_data['meta_key'], $cache_meta_keys ) ) { + unset( $meta[ $index ] ); + } + } + + return $meta; + } + + /** Methods to implement WCS_Cache_Updater - wrap more accurately named methods for the sake of clarity */ + + /** + * Get the items to be updated, if any. + * + * @return array An array of items to update, or empty array if there are no items to update. + */ + public function get_items_to_update() { + return $this->get_subscription_ids_without_cache(); + } + + /** + * Run the update for a single item. + * + * @param mixed $item The item to update. + */ + public function update_items_cache( $subscription_id ) { + $subscription = wcs_get_subscription( $subscription_id ); + if ( $subscription ) { + foreach ( $this->get_relation_types() as $relation_type ) { + // Getting the related IDs also sets the cache when it's not already set + $this->get_related_order_ids( $subscription, $relation_type ); + } + } + } + + /** + * Clear all caches. + */ + public function delete_all_caches() { + $this->delete_caches_for_all_subscriptions(); + } +} diff --git a/includes/data-stores/class-wcs-related-order-store-cpt.php b/includes/data-stores/class-wcs-related-order-store-cpt.php new file mode 100755 index 0000000..58ac967 --- /dev/null +++ b/includes/data-stores/class-wcs-related-order-store-cpt.php @@ -0,0 +1,264 @@ +get_related_order_ids() queries the posts table via wp_posts(), + * not the order's data store. This is unavoidable as wc_get_orders() and WC_Order_Query do not provide any way to query + * meta data abstracted from the data store. Instead, it relies on 3rd party code to add custom parameter support for meta. + * Source: https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#adding-custom-parameter-support + * + * Adding custom parameter support to order querying APIs won't help solve this issue, as the code would still directly + * query post meta by default, and require additional code for different order data stores. + * + * The solution will be to eventually move away from the use of meta data on the order to a standalone relationship table. + * This can be done already on sites running custom order data stores as WCS_Related_Order_Store::instance() is + * filterable. It will eventually also be the default implementation in a future version of Subscriptions. + * + * @version 2.3.0 + * @category Class + * @author Prospress + */ +class WCS_Related_Order_Store_CPT extends WCS_Related_Order_Store { + + /** + * Meta keys used to link an order with a subscription for each type of relationship. + * + * @since 2.3.0 + * @var array $meta_keys Relationship => Meta key + */ + private $meta_keys; + + /** + * Constructor: sets meta keys used for storing each order relation. + */ + public function __construct() { + foreach ( $this->get_relation_types() as $relation_type ) { + $this->meta_keys[ $relation_type ] = sprintf( '_subscription_%s', $relation_type ); + } + } + + /** + * Find orders related to a given subscription in a given way. + * + * This method uses the WordPress Posts API instead of the WooCommerce Order's API, because + * order's can not be queried by meta data with either wc_get_orders() or WC_Order_Query, so + * a custom query parameter would need to be added to WC_Order_Query to run that query, which + * is not something we want to add public APIs for because in future, that relationship will + * be moved out of order meta and into its own table and queries on it should come through + * here instead of the order querying API. + * + * @param WC_Order $subscription The ID of the subscription for which calling code wants the related orders. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + * + * @return array + */ + public function get_related_order_ids( WC_Order $subscription, $relation_type ) { + + $related_order_ids = get_posts( array( + 'posts_per_page' => -1, + 'post_type' => 'shop_order', + 'post_status' => 'any', + 'fields' => 'ids', + 'orderby' => array( + 'date' => 'DESC', + 'ID' => 'DESC', + ), + 'meta_query' => array( + array( + 'key' => $this->get_meta_key( $relation_type ), + 'compare' => '=', + 'value' => wcs_get_objects_property( $subscription, 'id' ), // We can't rely on get_id() being available here, because we only require a WC_Order, not a WC_Subscription, and WC_Order does not have get_id() available with WC < 3.0 + 'type' => 'numeric', + ), + ), + 'update_post_term_cache' => false, + ) ); + + return $related_order_ids; + } + + /** + * Find subscriptions related to a given order in a given way, if any. + * + * @param WC_Order $order The ID of an order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe. + * + * @return array + */ + public function get_related_subscription_ids( WC_Order $order, $relation_type ) { + $related_order_meta_key = $this->get_meta_key( $relation_type ); + if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { + $related_subscription_ids = get_post_meta( wcs_get_objects_property( $order, 'id' ), $related_order_meta_key, false ); + } else { + $related_subscription_ids = $order->get_meta( $related_order_meta_key, false ); + // Normalise the return value: WooCommerce returns a set of WC_Meta_Data objects, with values cast to strings, even if they're integers + $related_subscription_ids = wp_list_pluck( $related_subscription_ids, 'value' ); + $related_subscription_ids = array_map( 'absint', $related_subscription_ids ); + $related_subscription_ids = array_values( $related_subscription_ids ); + } + + $related_subscription_ids = $this->apply_deprecated_related_order_filter( $related_subscription_ids, $order, $relation_type ); + + return apply_filters( 'wcs_orders_related_subscription_ids', $related_subscription_ids, $order, $relation_type ); + } + + /** + * Apply the deprecated 'wcs_subscriptions_for_renewal_order' and 'wcs_subscriptions_for_resubscribe_order' filters + * to maintain backward compatibility. + * + * @param array $subscription_ids The IDs of subscription linked to the given order, if any. + * @param WC_Order $order An instance of an order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the orders. Must be 'renewal', 'switch' or 'resubscribe'. + * + * @return array + */ + protected function apply_deprecated_related_order_filter( $subscription_ids, WC_Order $order, $relation_type ) { + + $deprecated_filter_hook = "wcs_subscriptions_for_{$relation_type}_order"; + + if ( has_filter( $deprecated_filter_hook ) ) { + wcs_deprecated_function( sprintf( '"%s" hook should no longer be used and', esc_html( $deprecated_filter_hook ) ), '2.3.2', '"wcs_orders_related_subscription_ids" with a check on the 3rd param, to take advantage of the new persistent caching layer for related subscription IDs' ); + + $subscriptions = array(); + + foreach ( $subscription_ids as $subscription_id ) { + if ( wcs_is_subscription( $subscription_id ) ) { + $subscriptions[ $subscription_id ] = wcs_get_subscription( $subscription_id ); + } + } + + $filtered_subscriptions = apply_filters( $deprecated_filter_hook, $subscriptions, $order ); + + // Although this array was previously ordered by ID => instance, that key requirement wasn't enforced so it's possible 3rd party code was not using the ID as the key, and instead, numerical indexes are being used, so its safest not to rely on IDs as keys + if ( $filtered_subscriptions != $subscriptions ) { + + $subscription_ids = array(); + + foreach ( $filtered_subscriptions as $subscription ) { + $subscription_ids[] = $subscription->get_id(); + } + } + } + + return $subscription_ids; + } + + /** + * Helper function for linking an order to a subscription via a given relationship. + * + * Existing order relationships of the same type will not be overwritten. This only adds a relationship. To overwrite, + * you must also remove any existing relationship with @see $this->delete_relation(). + * + * This data store links the relationship for a renewal order and a subscription in meta data against the order. + * That's inefficient for queries, so will be changed in future with a different data store. It also leads to potential + * bugs when WooCommerce 3.0 or newer is running with a custom data store for order data, as related orders are queried + * in $this->get_related_order_ids() using post meta directly, but set here using the CRUD WC_Data::add_meta_data() method. + * This is unfortunately unavoidable. See the WCS_Related_Order_Store_CPT docblock for more details. + * + * @param WC_Order $order The order to link with the subscription. + * @param WC_Order $subscription The order or subscription to link the order to. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + public function add_relation( WC_Order $order, WC_Order $subscription, $relation_type ) { + + // We can't rely on $subscription->get_id() being available here, because we only require a WC_Order, not a WC_Subscription, and WC_Order does not have get_id() available with WC < 3.0 + $subscription_id = wcs_get_objects_property( $subscription, 'id' ); + $related_order_meta_key = $this->get_meta_key( $relation_type ); + + if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { + $order_id = wcs_get_objects_property( $order, 'id' ); + $existing_related_ids = get_post_meta( $order_id, $related_order_meta_key, false ); + + if ( empty( $existing_related_ids ) || ! in_array( $subscription_id, $existing_related_ids ) ) { + add_post_meta( $order_id, $related_order_meta_key, $subscription_id, false ); + } + } else { + // We want to allow more than one piece of meta per key on the order, but we don't want to duplicate the same meta key => value combination, so we need to check if it is set first + $existing_relations = $order->get_meta( $related_order_meta_key, false ); + $existing_related_ids = wp_list_pluck( $existing_relations, 'value' ); + + if ( empty( $existing_relations ) || ! in_array( $subscription_id, $existing_related_ids ) ) { + $order->add_meta_data( $related_order_meta_key, $subscription_id, false ); + $order->save_meta_data(); + } + } + } + + /** + * Remove the relationship between a given order and subscription. + * + * This data store links the relationship for a renewal order and a subscription in meta data against the order. + * That's inefficient for queries, so will be changed in future with a different data store. It also leads to bugs + * with custom data stores for order data, as $this->get_related_order_ids() queries post meta directly. This is + * unavoidable. See the WCS_Related_Order_Store_CPT docblock for more details. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param WC_Order $subscription A subscription or order to unlink the order with, if a relation exists. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + public function delete_relation( WC_Order $order, WC_Order $subscription, $relation_type ) { + $related_order_meta_key = $this->get_meta_key( $relation_type ); + if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { + delete_post_meta( wcs_get_objects_property( $order, 'id' ), $related_order_meta_key, wcs_get_objects_property( $subscription, 'id' ) ); + } else { + foreach ( $order->get_meta_data() as $meta ) { + if ( $meta->key == $related_order_meta_key && $meta->value == wcs_get_objects_property( $subscription, 'id' ) ) { // we can't do strict comparison here, because WC_Meta_Data casts the subscription ID to be a string + $order->delete_meta_data_by_mid( $meta->id ); + } + } + $order->save_meta_data(); + } + } + + /** + * Remove all related orders/subscriptions of a given type from an order. + * + * @param WC_Order $order An order that may be linked with subscriptions. + * @param string $relation_type The relationship between the subscription and the order. Must be 'renewal', 'switch' or 'resubscribe' unless custom relationships are implemented. + */ + public function delete_relations( WC_Order $order, $relation_type ) { + $related_order_meta_key = $this->get_meta_key( $relation_type ); + if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { + delete_post_meta( wcs_get_objects_property( $order, 'id' ), $related_order_meta_key, null ); + } else { + $order->delete_meta_data( $related_order_meta_key ); + $order->save_meta_data(); + } + } + + /** + * Get the meta keys used to link orders with subscriptions. + * + * @return array + */ + protected function get_meta_keys() { + return $this->meta_keys; + } + + /** + * Get the meta key used to link an order with a subscription based on the type of relationship. + * + * @param string $relation_type The order's relationship with the subscription. Must be 'renewal', 'switch' or 'resubscribe'. + * @param string $prefix_meta_key Whether to add the underscore prefix to the meta key or not. 'prefix' to prefix the key. 'do_not_prefix' to not prefix the key. + * @return string + */ + protected function get_meta_key( $relation_type, $prefix_meta_key = 'prefix' ) { + + $this->check_relation_type( $relation_type ); + + $meta_key = $this->meta_keys[ $relation_type ]; + + if ( 'do_not_prefix' === $prefix_meta_key ) { + $meta_key = wcs_maybe_unprefix_key( $meta_key ); + } + + return $meta_key; + } +} diff --git a/includes/data-stores/class-wcs-subscription-data-store-cpt.php b/includes/data-stores/class-wcs-subscription-data-store-cpt.php index 8e25b19..6fd8252 100755 --- a/includes/data-stores/class-wcs-subscription-data-store-cpt.php +++ b/includes/data-stores/class-wcs-subscription-data-store-cpt.php @@ -77,6 +77,29 @@ class WCS_Subscription_Data_Store_CPT extends WC_Order_Data_Store_CPT implements do_action( 'woocommerce_new_subscription', $subscription->get_id() ); } + /** + * Returns an array of meta for an object. + * + * Ignore meta data that we don't want accessible on the object via meta APIs. + * + * @since 2.3.0 + * @param WC_Data $object + * @return array + */ + public function read_meta( &$object ) { + $meta_data = parent::read_meta( $object ); + + $props_to_ignore = $this->get_props_to_ignore(); + + foreach ( $meta_data as $index => $meta_object ) { + if ( array_key_exists( $meta_object->meta_key, $props_to_ignore ) ) { + unset( $meta_data[ $index ] ); + } + } + + return $meta_data; + } + /** * Read subscription data. * @@ -331,6 +354,22 @@ class WCS_Subscription_Data_Store_CPT extends WC_Order_Data_Store_CPT implements */ protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) { $props_to_update = parent::get_props_to_update( $object, $meta_key_to_props, $meta_type ); + $props_to_ignore = $this->get_props_to_ignore(); + + foreach ( $props_to_ignore as $meta_key => $prop ) { + unset( $props_to_update[ $meta_key ] ); + } + + return $props_to_update; + } + + /** + * Get the props set on a subscription which we don't want used on a subscription, which may be + * inherited order meta data, or other values using the post meta data store but not as props. + * + * @return array A mapping of meta keys => prop names + */ + protected function get_props_to_ignore() { $props_to_ignore = array( '_transaction_id' => 'transaction_id', @@ -339,10 +378,67 @@ class WCS_Subscription_Data_Store_CPT extends WC_Order_Data_Store_CPT implements '_cart_hash' => 'cart_hash', ); - foreach ( $props_to_ignore as $meta_key => $prop ) { - unset( $props_to_update[ $meta_key ] ); + return apply_filters( 'wcs_subscription_data_store_props_to_ignore', $props_to_ignore, $this ); + } + + /** + * Search subscription data for a term and returns subscription ids + * + * @param string $term Term to search + * @return array of subscription ids + * @since 2.3.0 + */ + public function search_subscriptions( $term ) { + global $wpdb; + + $subscription_ids = array(); + + $search_fields = array_map( 'wc_clean', apply_filters( 'woocommerce_shop_subscription_search_fields', array( + '_order_key', + '_billing_address_index', + '_shipping_address_index', + '_billing_email', + ) ) ); + + if ( is_numeric( $term ) ) { + $subscription_ids[] = absint( $term ); } - return $props_to_update; + if ( ! empty( $search_fields ) ) { + + $subscription_ids = array_unique( array_merge( + $wpdb->get_col( + $wpdb->prepare( " + SELECT DISTINCT p1.post_id + FROM {$wpdb->postmeta} p1 + WHERE p1.meta_value LIKE '%%%s%%'", $wpdb->esc_like( wc_clean( $term ) ) ) . " AND p1.meta_key IN ('" . implode( "','", array_map( 'esc_sql', $search_fields ) ) . "')" + ), + $wpdb->get_col( + $wpdb->prepare( " + SELECT order_id + FROM {$wpdb->prefix}woocommerce_order_items as order_items + WHERE order_item_name LIKE '%%%s%%' + ", + $wpdb->esc_like( wc_clean( $term ) ) + ) + ), + $wpdb->get_col( + $wpdb->prepare( " + SELECT p1.ID + FROM {$wpdb->posts} p1 + INNER JOIN {$wpdb->postmeta} p2 ON p1.ID = p2.post_id + INNER JOIN {$wpdb->users} u ON p2.meta_value = u.ID + WHERE u.user_email LIKE '%%%s%%' + AND p2.meta_key = '_customer_user' + AND p1.post_type = 'shop_subscription' + ", + esc_attr( $term ) + ) + ), + $subscription_ids + ) ); + } + + return apply_filters( 'woocommerce_shop_subscription_search_results', $subscription_ids, $term, $search_fields ); } } diff --git a/includes/early-renewal/class-wcs-cart-early-renewal.php b/includes/early-renewal/class-wcs-cart-early-renewal.php new file mode 100755 index 0000000..4c62a61 --- /dev/null +++ b/includes/early-renewal/class-wcs-cart-early-renewal.php @@ -0,0 +1,395 @@ +set_order_item_id(), in order for the line item ID set by that function to be correct. + add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'set_cart_item_renewal_order_data' ), 5 ); + + // Allow customers to cancel early renewal orders from their my account page. + add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'add_cancel_order_action' ), 15, 2 ); + add_action( 'wp_loaded', array( $this, 'allow_early_renewal_order_cancellation' ), 10, 3 ); + } + + /** + * Adds a "Renew Now" button to the "View Subscription" page. + * + * @param array $actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "View Subscription" page. + * @param WC_Subscription $subscription The current subscription being viewed. + * @since 2.3.0 + * @return array $actions The subscription actions with the "Renew Now" action added if it's permitted. + */ + public function add_renew_now_action( $actions, $subscription ) { + + if ( wcs_can_user_renew_early( $subscription ) && $subscription->payment_method_supports( 'subscription_date_changes' ) && $subscription->has_status( 'active' ) ) { + + $actions['subscription_renewal_early'] = array( + 'url' => wcs_get_early_renewal_url( $subscription ), + 'name' => __( 'Renew Now', 'woocommerce-subscriptions' ), + ); + } + + return $actions; + } + + /** + * Check if a payment is being made on an early renewal order. + */ + public function maybe_setup_cart() { + global $wp; + + if ( ! isset( $_GET['subscription_renewal_early'], $_GET['wcs_nonce'] ) ) { + return; + } + + $subscription = wcs_get_subscription( absint( $_GET['subscription_renewal_early'] ) ); + $redirect_to = get_permalink( wc_get_page_id( 'myaccount' ) ); + + if ( false === wp_verify_nonce( $_GET['wcs_nonce'], 'wcs-renew-' . $subscription->get_id() ) ) { + + wc_add_notice( __( 'There was an error with your request to renew. Please try again.', 'woocommerce-subscriptions' ), 'error' ); + + } elseif ( empty( $subscription ) ) { + + wc_add_notice( __( 'That subscription does not exist. Has it been deleted?', 'woocommerce-subscriptions' ), 'error' ); + + } elseif ( ! current_user_can( 'subscribe_again', $subscription->get_id() ) ) { + + wc_add_notice( __( "That doesn't appear to be one of your subscriptions.", 'woocommerce-subscriptions' ), 'error' ); + + } elseif ( ! wcs_can_user_renew_early( $subscription ) ) { + + wc_add_notice( __( 'You can not renew this subscription early. Please contact us if you need assistance.', 'woocommerce-subscriptions' ), 'error' ); + + } else { + + wc_add_notice( __( 'Complete checkout to renew now.', 'woocommerce-subscriptions' ), 'success' ); + + $this->setup_cart( $subscription, array( + 'subscription_id' => $subscription->get_id(), + 'subscription_renewal_early' => true, + 'renewal_order_id' => $subscription->get_id(), + ) ); + + $redirect_to = wc_get_checkout_url(); + } + + wp_safe_redirect( $redirect_to ); + exit; + } + + /** + * Records an early renewal against order created on checkout (only for WooCommerce < 3.0). + * + * @param int $order_id The post_id of a shop_order post/WC_Order object. + * @param array $posted_data The data posted on checkout. + * @since 2.3.0 + */ + public function maybe_record_early_renewal( $order_id, $posted_data ) { + if ( ! WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { + wcs_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Early_Renewal::add_early_renewal_metadata_to_order( $order, $posted_data )' ); + } + + $cart_item = $this->cart_contains(); + + if ( ! $cart_item ) { + return; + } + + // Get the subscription. + $subscription = wcs_get_subscription( $cart_item[ $this->cart_item_key ]['subscription_id'] ); + + // Mark this order as a renewal. + update_post_meta( $order_id, '_subscription_renewal', $subscription->get_id() ); + + // Mark this order as an early renewal. + update_post_meta( $order_id, '_subscription_renewal_early', $subscription->get_id() ); + + // Put the subscription on hold until payment is complete. + $subscription->update_status( 'on-hold', _x( 'Customer requested to renew early:', 'used in order note as reason for why subscription status changed', 'woocommerce-subscriptions' ) ); + } + + /** + * Adds the early renewal metadata to the order created on checkout. + * + * @param WC_Order $order The WC Order object. + * @param array $data The data posted on checkout. + * @since 2.3.0 + */ + public function add_early_renewal_metadata_to_order( $order, $data ) { + + $cart_item = $this->cart_contains(); + if ( ! $cart_item ) { + return; + } + + // Get the subscription. + $subscription = wcs_get_subscription( $cart_item[ $this->cart_item_key ]['subscription_id'] ); + + // Mark this order as a renewal. + $order->update_meta_data( '_subscription_renewal', $subscription->get_id() ); + + // Mark this order as an early renewal. + $order->update_meta_data( '_subscription_renewal_early', $subscription->get_id() ); + + // Put the subscription on hold until payment is complete. + $subscription->update_status( 'on-hold', _x( 'Customer requested to renew early:', 'used in order note as reason for why subscription status changed', 'woocommerce-subscriptions' ) ); + } + + /** + * Update the next payment and end dates on a subscription to extend them and account + * for early renewal. + * + * @param int $order_id The WC Order ID which contains an early renewal. + * @since 2.3.0 + */ + public function maybe_update_dates( $order_id ) { + + $order = wc_get_order( $order_id ); + + if ( ! $order || ! wcs_order_contains_early_renewal( $order ) ) { + return; + } + + $subscription_id = wcs_get_objects_property( $order, 'subscription_renewal_early' ); + $subscription = wcs_get_subscription( $subscription_id ); + + if ( ! $subscription ) { + return; + } + + $next_payment_time = $subscription->get_time( 'next_payment' ); + $dates_to_update = array(); + + if ( $next_payment_time > 0 && $next_payment_time > current_time( 'timestamp', true ) ) { + $next_payment_timestamp = wcs_add_time( $subscription->get_billing_interval(), $subscription->get_billing_period(), $next_payment_time ); + + if ( $subscription->get_time( 'end' ) === 0 || $next_payment_timestamp < $subscription->get_time( 'end' ) ) { + $dates_to_update['next_payment'] = gmdate( 'Y-m-d H:i:s', $next_payment_timestamp ); + } else { + // Delete the next payment date if the calculated next payment date occurs after the end date. + $dates_to_update['next_payment'] = 0; + } + } elseif ( $subscription->get_time( 'end' ) > 0 ) { + $dates_to_update['end'] = gmdate( 'Y-m-d H:i:s', wcs_add_time( $subscription->get_billing_interval(), $subscription->get_billing_period(), $subscription->get_time( 'end' ) ) ); + } + + if ( ! empty( $dates_to_update ) ) { + + $order_number = sprintf( _x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), $order->get_order_number() ); + $order_link = sprintf( '%s', esc_url( wcs_get_edit_post_link( $order->get_id() ) ), $order_number ); + + try { + $subscription->update_dates( $dates_to_update ); + + // translators: placeholder contains a link to the order's edit screen. + $subscription->add_order_note( sprintf( __( 'Customer successfully renewed early with order %s.', 'woocommerce-subscriptions' ), $order_link ) ); + } catch ( Exception $e ) { + // translators: placeholder contains a link to the order's edit screen. + $subscription->add_order_note( sprintf( __( 'Failed to update subscription dates after customer renewed early with order %s.', 'woocommerce-subscriptions' ), $order_link ) ); + } + } + } + + /** + * Reactivates an on hold subscription when an early renewal order + * is cancelled by the user. + * + * @param int $order_id The WC Order ID which contains an early renewal. + * @since 2.3.0 + */ + public function maybe_reactivate_subscription( $order_id ) { + + // Get the order and make sure we have one. + $order = wc_get_order( $order_id ); + + if ( wcs_order_contains_early_renewal( $order ) ) { + + // Get the subscription and make sure we have one. + $subscription = wcs_get_subscription( wcs_get_objects_property( $order, 'subscription_renewal_early' ) ); + + if ( ! $subscription || ! $subscription->has_status( 'on-hold' ) ) { + return; + } + + // Make sure the next payment date isn't in the past. + if ( strtotime( $subscription->get_date( 'next_payment' ) ) < time() ) { + return; + } + + // Reactivate the subscription. + $subscription->update_status( 'active' ); + } + } + + /** + * Checks the cart to see if it contains a subscription renewal item. + * + * @see wcs_cart_contains_early_renewal(). + * @return bool|array The cart item containing the renewal, else false. + * @since 2.3.0 + */ + protected function cart_contains() { + return wcs_cart_contains_early_renewal(); + } + + /** + * Get the subscription object used to construct the early renewal cart. + * + * @param array The resubscribe cart item. + * @return WC_Subscription The subscription object. + * @since 2.3.0 + */ + protected function get_order( $cart_item = '' ) { + + $subscription = false; + + if ( empty( $cart_item ) ) { + $cart_item = $this->cart_contains(); + } + + if ( false !== $cart_item && isset( $cart_item[ $this->cart_item_key ] ) ) { + $subscription = wcs_get_subscription( $cart_item[ $this->cart_item_key ]['subscription_id'] ); + } + + return $subscription; + } + + /** + * Add a note to the subscription to record the creation of the early renewal order. + * + * @param int $order_id The order ID created on checkout. + * @since 2.3.0 + */ + public function add_note_to_record_early_renewal( $order_id ) { + + $cart_item = $this->cart_contains(); + + if ( ! $cart_item ) { + return; + } + + $order = wc_get_order( $order_id ); + $subscription = wcs_get_subscription( $cart_item[ $this->cart_item_key ]['subscription_id'] ); + + if ( wcs_is_order( $order ) && wcs_is_subscription( $subscription ) ) { + $order_number = sprintf( _x( '#%s', 'hash before order number', 'woocommerce-subscriptions' ), $order->get_order_number() ); + $subscription->add_order_note( sprintf( __( 'Order %s created to record early renewal.', 'woocommerce-subscriptions' ), sprintf( '%s ', esc_url( wcs_get_edit_post_link( $order_id ) ), $order_number ) ) ); + } + } + + /** + * Set the renewal order ID in early renewal order cart items. + * + * Hooked onto the 'woocommerce_checkout_update_order_meta' hook after the renewal order has been + * created on checkout. Required so the line item ID set by @see WCS_Cart_Renewal->set_order_item_id() + * matches the order. + * + * @param int $order_id The WC Order ID created on checkout. + * @since 2.3.0 + */ + public function set_cart_item_renewal_order_data( $order_id ) { + + if ( ! wcs_cart_contains_early_renewal() ) { + return; + } + + foreach ( WC()->cart->cart_contents as $key => &$cart_item ) { + if ( isset( $cart_item[ $this->cart_item_key ] ) && ! empty( $cart_item[ $this->cart_item_key ]['subscription_renewal_early'] ) ) { + $cart_item[ $this->cart_item_key ]['renewal_order_id'] = $order_id; + } + } + } + + /** + * Ensure customers can cancel early renewal orders. + * + * Renewal orders are usually not cancellable because @see WCS_Cart_Renewal::filter_my_account_my_orders_actions() prevents it. + * In the case of early renewals, the customer has opted for early renewal and so should be able to cancel it in order to reactivate their subscription. + * + * @param array $actions A list of actions customers can make on an order from their My Account page + * @param WC_Order $order The order the list of actions relate to. + * @return array $actions + * @since 2.3.0 + */ + public static function add_cancel_order_action( $actions, $order ) { + + if ( ! isset( $actions['cancel'] ) && wcs_order_contains_early_renewal( $order ) && in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) { + $redirect = wc_get_page_permalink( 'myaccount' ); + + // Redirect the customer back to the view subscription page if that is where they cancel the order from. + if ( wcs_is_view_subscription_page() ) { + global $wp; + $subscription = wcs_get_subscription( $wp->query_vars['view-subscription'] ); + + if ( wcs_is_subscription( $subscription ) ) { + $redirect = $subscription->get_view_order_url(); + } + } + + $actions['cancel'] = array( + 'url' => $order->get_cancel_order_url( $redirect ), + 'name' => __( 'Cancel', 'woocommerce-subscriptions' ), + ); + } + + return $actions; + } + + /** + * Allow customers to cancel early renewal orders from their account page. + * + * Renewal orders are usually not cancellable because @see WC_Subscriptions_Renewal_Order::prevent_cancelling_renewal_orders() prevents the request from being processed. + * In the case of early renewals, the customer has opted for early renewal and so should be able to cancel it in order to reactivate their subscription. + * + * @since 2.3.0 + */ + public static function allow_early_renewal_order_cancellation() { + if ( isset( $_GET['cancel_order'] ) && isset( $_GET['order_id'] ) && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'woocommerce-cancel_order' ) ) { + $order_id = absint( $_GET['order_id'] ); + $order = wc_get_order( $order_id ); + + if ( wcs_order_contains_early_renewal( $order ) ) { + remove_action( 'wp_loaded', 'WC_Subscriptions_Renewal_Order::prevent_cancelling_renewal_orders', 19 ); + } + } + } +} diff --git a/includes/early-renewal/class-wcs-early-renewal-manager.php b/includes/early-renewal/class-wcs-early-renewal-manager.php new file mode 100755 index 0000000..82b9d52 --- /dev/null +++ b/includes/early-renewal/class-wcs-early-renewal-manager.php @@ -0,0 +1,72 @@ + self::$setting_id, + 'name' => __( 'Early Renewal', 'woocommerce-subscriptions' ), + 'desc' => __( 'Accept Early Renewal Payments', 'woocommerce-subscriptions' ), + 'desc_tip' => __( 'With early renewals enabled, customers can renew their subscriptions before the next payment date.', 'woocommerce-subscriptions' ), + 'default' => 'no', + 'type' => 'checkbox', + ) ); + + return $settings; + } + + /** + * A helper function to check if the early renewal feature is enabled or not. + * + * If the setting hasn't been set yet, by default it is off for existing stores and on for new stores. + * + * @since 2.3.0 + * @return bool + */ + public static function is_early_renewal_enabled() { + $enabled = get_option( self::$setting_id ); + + if ( false === $enabled ) { + $enabled = wcs_do_subscriptions_exist() ? 'no' : 'yes'; + update_option( self::$setting_id, $enabled ); + } + + return apply_filters( 'wcs_is_early_renewal_enabled', 'yes' === $enabled ); + } +} diff --git a/includes/early-renewal/wcs-early-renewal-functions.php b/includes/early-renewal/wcs-early-renewal-functions.php new file mode 100755 index 0000000..536f775 --- /dev/null +++ b/includes/early-renewal/wcs-early-renewal-functions.php @@ -0,0 +1,141 @@ +has_status( array( 'active' ) ) ) { + $can_renew_early = false; + } elseif ( 0 === $subscription->get_total() ) { + $can_renew_early = false; + } elseif ( $subscription->get_time( 'trial_end' ) > gmdate( 'U' ) ) { + $can_renew_early = false; + } elseif ( ! $subscription->get_time( 'next_payment' ) ) { + $can_renew_early = false; + } elseif ( WC_Subscriptions_Synchroniser::subscription_contains_synced_product( $subscription ) ) { + $can_renew_early = false; + } elseif ( ! $subscription->payment_method_supports( 'subscription_date_changes' ) ) { + $can_renew_early = false; + } else { + // Make sure all line items still exist. + $all_line_items_exist = true; + + foreach ( $subscription->get_items() as $line_item ) { + $product = wc_get_product( wcs_get_canonical_product_id( $line_item ) ); + + if ( false === $product ) { + $all_line_items_exist = false; + break; + } + } + + $can_renew_early = $all_line_items_exist; + } + + /** + * Allow third-parties to filter whether the customer can renew a subscription early. + * + * @since 2.3.0 + * @param bool $can_renew_early Whether early renewal is permitted. + * @param WC_Subscription $subscription The subscription being renewed early. + * @param int $user_id The user's ID. + */ + return apply_filters( 'woocommerce_subscriptions_can_user_renew_early', $can_renew_early, $subscription, $user_id ); +} + +/** + * Check if a given order is a subscription renewal order. + * + * @param WC_Order|int $order The WC_Order object or ID of a WC_Order order. + * @since 2.3.0 + * @return bool True if the order contains an early renewal, otherwise false. + */ +function wcs_order_contains_early_renewal( $order ) { + + if ( ! is_object( $order ) ) { + $order = wc_get_order( $order ); + } + + $subscription_id = absint( wcs_get_objects_property( $order, 'subscription_renewal_early' ) ); + $is_early_renewal = wcs_is_order( $order ) && $subscription_id > 0; + + /** + * Allow third-parties to filter whether this order contains the early renewal flag. + * + * @since 2.3.0 + * @param bool $is_renewal True if early renewal meta was found on the order, otherwise false. + * @param WC_Order $order The WC_Order object. + */ + return apply_filters( 'woocommerce_subscriptions_is_early_renewal_order', $is_early_renewal, $order ); +} + +/** + * Returns a URL for early renewal of a subscription. + * + * @param int|WC_Subscription $subscription WC_Subscription ID, or instance of a WC_Subscription object. + * @return string The early renewal URL. + * @since 2.3.0 + */ +function wcs_get_early_renewal_url( $subscription ) { + $subscription_id = is_a( $subscription, 'WC_Subscription' ) ? $subscription->get_id() : absint( $subscription ); + + $url = add_query_arg( array( + 'subscription_renewal_early' => $subscription_id, + 'subscription_renewal' => 'true', + 'wcs_nonce' => wp_create_nonce( 'wcs-renew-' . $subscription_id ), + ), get_permalink( wc_get_page_id( 'myaccount' ) ) ); + + /** + * Allow third-parties to filter the early renewal URL. + * + * @since 2.3.0 + * @param string $url The early renewal URL. + * @param int $subscription_id The ID of the subscription to renew to. + */ + return apply_filters( 'woocommerce_subscriptions_get_early_renewal_url', $url, $subscription_id ); +} diff --git a/includes/gateways/class-wc-subscriptions-payment-gateways.php b/includes/gateways/class-wc-subscriptions-payment-gateways.php index fa8aa4e..f7135c2 100755 --- a/includes/gateways/class-wc-subscriptions-payment-gateways.php +++ b/includes/gateways/class-wc-subscriptions-payment-gateways.php @@ -73,7 +73,7 @@ class WC_Subscriptions_Payment_Gateways { if ( WC_Subscriptions_Cart::cart_contains_subscription() || ( isset( $_GET['order_id'] ) && wcs_order_contains_subscription( $_GET['order_id'] ) ) ) { $accept_manual_renewals = ( 'no' !== get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no' ) ) ? true : false; - $subscriptions_in_cart = count( WC()->cart->recurring_carts ); + $subscriptions_in_cart = is_array( WC()->cart->recurring_carts ) ? count( WC()->cart->recurring_carts ) : 0; foreach ( $available_gateways as $gateway_id => $gateway ) { diff --git a/includes/interfaces/interface-wcs-cache-updater.php b/includes/interfaces/interface-wcs-cache-updater.php new file mode 100755 index 0000000..9e6dc01 --- /dev/null +++ b/includes/interfaces/interface-wcs-cache-updater.php @@ -0,0 +1,43 @@ +prices_array[ $price_hash ]['price'] ); sort( $children ); - $min_max_data = wcs_get_min_max_variation_data( $this, $children ); + $min_max_data = $this->get_min_and_max_variation_data( $children ); $min_variation_id = $min_max_data['min']['variation_id']; $max_variation_id = $min_max_data['max']['variation_id']; @@ -223,6 +223,8 @@ class WC_Product_Variable_Subscription_Legacy extends WC_Product_Variable_Subscr $min_max_data = wcs_get_min_max_variation_data( $this, $child_variation_ids ); + $this->set_min_and_max_variation_data( $min_max_data, $child_variation_ids ); + update_post_meta( $this->id, '_min_price_variation_id', $min_max_data['min']['variation_id'] ); update_post_meta( $this->id, '_max_price_variation_id', $min_max_data['max']['variation_id'] ); @@ -378,4 +380,56 @@ class WC_Product_Variable_Subscription_Legacy extends WC_Product_Variable_Subscr public function get_default_attributes( $context = 'view' ) { return $this->get_variation_default_attributes(); } + + /** + * Set the product's min and max variation data. + * + * @param array $min_and_max_data The min and max variation data returned by @see wcs_get_min_max_variation_data(). Optional. + * @param array $variation_ids The visible child variation IDs. Optional. By default this value be generated by @see WC_Product_Variable->get_children( true ). + * @since 2.3.0 + */ + public function set_min_and_max_variation_data( $min_and_max_data = array(), $variation_ids = array() ) { + + if ( empty( $variation_ids ) ) { + $variation_ids = $this->get_children( true ); + } + + if ( empty( $min_and_max_data ) ) { + $min_and_max_data = wcs_get_min_max_variation_data( $this, $variation_ids ); + } + + update_post_meta( $this->id, '_min_max_variation_data', $min_and_max_data, true ); + update_post_meta( $this->id, '_min_max_variation_ids_hash', $this->get_variation_ids_hash( $variation_ids ), true ); + } + + /** + * Get the min and max variation data. + * + * This is a wrapper for @see wcs_get_min_max_variation_data() but to avoid calling + * that resource intensive function multiple times per request, check the value + * stored in meta or cached in memory before calling that function. + * + * @param array $variation_ids An array of variation IDs. + * @return array The variable product's min and max variation data. + * @since 2.3.0 + */ + public function get_min_and_max_variation_data( $variation_ids ) { + $variation_ids_hash = $this->get_variation_ids_hash( $variation_ids ); + + // If this variable product has no min and max variation data, set it. + if ( ! metadata_exists( 'post', $this->id, '_min_max_variation_ids_hash' ) ) { + $this->set_min_and_max_variation_data(); + } + + if ( $variation_ids_hash === $this->get_meta( '_min_max_variation_ids_hash', true ) ) { + $min_and_max_variation_data = $this->get_meta( '_min_max_variation_data', true ); + } elseif ( ! empty( $this->min_max_variation_data[ $variation_ids_hash ] ) ) { + $min_and_max_variation_data = $this->min_max_variation_data[ $variation_ids_hash ]; + } else { + $min_and_max_variation_data = wcs_get_min_max_variation_data( $this, $variation_ids ); + $this->min_max_variation_data[ $variation_ids_hash ] = $min_and_max_variation_data; + } + + return $min_and_max_variation_data; + } } diff --git a/includes/legacy/class-wc-subscription-legacy.php b/includes/legacy/class-wc-subscription-legacy.php index 4166d68..5392c61 100755 --- a/includes/legacy/class-wc-subscription-legacy.php +++ b/includes/legacy/class-wc-subscription-legacy.php @@ -28,7 +28,7 @@ class WC_Subscription_Legacy extends WC_Subscription { /** * Initialize the subscription object. * - * @param int|WC_Subscription $order + * @param int|WC_Subscription $subscription */ public function __construct( $subscription ) { @@ -423,17 +423,25 @@ class WC_Subscription_Legacy extends WC_Subscription { // Sign up is total amount paid for this item on original order when item has a free trial $sign_up_fee = $original_order_item['line_total'] / $original_order_item['qty']; - + } elseif ( isset( $original_order_item['item_meta']['_synced_sign_up_fee'] ) ) { + $sign_up_fee = $original_order_item['item_meta']['_synced_sign_up_fee'] / $original_order_item['qty']; } else { // Sign-up fee is any amount on top of recurring amount $sign_up_fee = max( $original_order_item['line_total'] / $original_order_item['qty'] - $line_item['line_total'] / $line_item['qty'], 0 ); } - // If prices inc tax, ensure that the sign up fee amount includes the tax - if ( 'inclusive_of_tax' === $tax_inclusive_or_exclusive && ! empty( $original_order_item ) && $this->get_prices_include_tax() ) { - $proportion = $sign_up_fee / ( $original_order_item['line_total'] / $original_order_item['qty'] ); - $sign_up_fee += round( $original_order_item['line_tax'] * $proportion, 2 ); + if ( ! empty( $original_order_item ) && ! empty( $sign_up_fee ) ) { + $sign_up_fee_proportion = $sign_up_fee / ( $original_order_item['line_total'] / $original_order_item['qty'] ); + $sign_up_fee_tax = wc_round_tax_total( $original_order_item['line_tax'] * $sign_up_fee_proportion ); + + // If prices don't inc tax, ensure that the sign up fee amount includes the tax. + if ( 'inclusive_of_tax' === $tax_inclusive_or_exclusive && ! $this->get_prices_include_tax() ) { + $sign_up_fee += $sign_up_fee_tax; + // If prices inc tax and the request is for prices exclusive of tax, remove the taxes. + } elseif ( 'inclusive_of_tax' !== $tax_inclusive_or_exclusive && $this->get_prices_include_tax() ) { + $sign_up_fee -= $sign_up_fee_tax; + } } } diff --git a/includes/libraries/action-scheduler/action-scheduler.php b/includes/libraries/action-scheduler/action-scheduler.php index 6b8e8d5..96595cd 100755 --- a/includes/libraries/action-scheduler/action-scheduler.php +++ b/includes/libraries/action-scheduler/action-scheduler.php @@ -1,30 +1,47 @@ . + * + */ -if ( ! function_exists( 'action_scheduler_register_1_dot_5_dot_3' ) ) { +if ( ! function_exists( 'action_scheduler_register_2_dot_0_dot_0' ) ) { if ( ! class_exists( 'ActionScheduler_Versions' ) ) { require_once( 'classes/ActionScheduler_Versions.php' ); add_action( 'plugins_loaded', array( 'ActionScheduler_Versions', 'initialize_latest_version' ), 1, 0 ); } - add_action( 'plugins_loaded', 'action_scheduler_register_1_dot_5_dot_3', 0, 0 ); + add_action( 'plugins_loaded', 'action_scheduler_register_2_dot_0_dot_0', 0, 0 ); - function action_scheduler_register_1_dot_5_dot_3() { + function action_scheduler_register_2_dot_0_dot_0() { $versions = ActionScheduler_Versions::instance(); - $versions->register( '1.5.3', 'action_scheduler_initialize_1_dot_5_dot_3' ); + $versions->register( '2.0.0', 'action_scheduler_initialize_2_dot_0_dot_0' ); } - function action_scheduler_initialize_1_dot_5_dot_3() { + function action_scheduler_initialize_2_dot_0_dot_0() { require_once( 'classes/ActionScheduler.php' ); ActionScheduler::init( __FILE__ ); } -} \ No newline at end of file +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler.php b/includes/libraries/action-scheduler/classes/ActionScheduler.php index fa08adf..5e1ad36 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler.php @@ -78,7 +78,6 @@ abstract class ActionScheduler { * * @static * @param string $plugin_file - * @return void */ public static function init( $plugin_file ) { self::$plugin_file = $plugin_file; @@ -97,6 +96,10 @@ abstract class ActionScheduler { add_action( 'init', array( $admin_view, 'init' ), 0, 0 ); // run before $store::init() require_once( self::plugin_path('functions.php') ); + + if ( defined( 'WP_CLI' ) && WP_CLI ) { + WP_CLI::add_command( 'action-scheduler', 'ActionScheduler_WPCLI_Scheduler_command' ); + } } @@ -117,4 +120,3 @@ abstract class ActionScheduler { return as_get_datetime_object( $when, $timezone ); } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Abstract_ListTable.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Abstract_ListTable.php new file mode 100755 index 0000000..de47067 --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_Abstract_ListTable.php @@ -0,0 +1,656 @@ + value pair. The + * key must much the table column name and the value is the label, which is + * automatically translated. + */ + protected $columns = array(); + + /** + * Defines the row-actions. It expects an array where the key + * is the column name and the value is an array of actions. + * + * The array of actions are key => value, where key is the method name + * (with the prefix row_action_) and the value is the label + * and title. + */ + protected $row_actions = array(); + + /** + * The Primary key of our table + */ + protected $ID = 'ID'; + + /** + * Enables sorting, it expects an array + * of columns (the column names are the values) + */ + protected $sort_by = array(); + + protected $filter_by = array(); + + /** + * @var array The status name => count combinations for this table's items. Used to display status filters. + */ + protected $status_counts = array(); + + /** + * @var array Notices to display when loading the table. Array of arrays of form array( 'class' => {updated|error}, 'message' => 'This is the notice text display.' ). + */ + protected $admin_notices = array(); + + /** + * @var string Localised string displayed in the

element above the able. + */ + protected $table_header; + + /** + * Enables bulk actions. It must be an array where the key is the action name + * and the value is the label (which is translated automatically). It is important + * to notice that it will check that the method exists (`bulk_$name`) and will throw + * an exception if it does not exists. + * + * This class will automatically check if the current request has a bulk action, will do the + * validations and afterwards will execute the bulk method, with two arguments. The first argument + * is the array with primary keys, the second argument is a string with a list of the primary keys, + * escaped and ready to use (with `IN`). + */ + protected $bulk_actions = array(); + + /** + * Makes translation easier, it basically just wraps + * `_x` with some default (the package name) + */ + protected function translate( $text, $context = '' ) { + return _x( $text, $context, $this->package ); + } + + /** + * Reads `$this->bulk_actions` and returns an array that WP_List_Table understands. It + * also validates that the bulk method handler exists. It throws an exception because + * this is a library meant for developers and missing a bulk method is a development-time error. + */ + protected function get_bulk_actions() { + $actions = array(); + + foreach ( $this->bulk_actions as $action => $label ) { + if ( ! is_callable( array( $this, 'bulk_' . $action ) ) ) { + throw new RuntimeException( "The bulk action $action does not have a callback method" ); + } + + $actions[ $action ] = $this->translate( $label ); + } + + return $actions; + } + + /** + * Checks if the current request has a bulk action. If that is the case it will validate and will + * execute the bulk method handler. Regardless if the action is valid or not it will redirect to + * the previous page removing the current arguments that makes this request a bulk action. + */ + protected function process_bulk_action() { + global $wpdb; + // Detect when a bulk action is being triggered. + $action = $this->current_action(); + + if ( ! $action ) { + return; + } + + check_admin_referer( 'bulk-' . $this->_args['plural'] ); + + $method = 'bulk_' . $action; + if ( array_key_exists( $action, $this->bulk_actions ) && is_callable( array( $this, $method ) ) && ! empty( $_GET['ID'] ) && is_array( $_GET['ID'] ) ) { + $ids_sql = '(' . implode( ',', array_fill( 0, count( $_GET['ID'] ), '%s' ) ) . ')'; + $this->$method( $_GET['ID'], $wpdb->prepare( $ids_sql, $_GET['ID'] ) ); + } + + wp_redirect( remove_query_arg( + array( '_wp_http_referer', '_wpnonce', 'ID', 'action', 'action2' ), + wp_unslash( $_SERVER['REQUEST_URI'] ) + ) ); + exit; + } + + /** + * Default code for deleting entries. We trust ids_sql because it is + * validated already by process_bulk_action() + */ + protected function bulk_delete( array $ids, $ids_sql ) { + global $wpdb; + + $wpdb->query( "DELETE FROM {$this->table_name} WHERE {$this->ID} IN $ids_sql" ); + } + + /** + * Prepares the _column_headers property which is used by WP_Table_List at rendering. + * It merges the columns and the sortable columns. + */ + protected function prepare_column_headers() { + $this->_column_headers = array( + $this->get_columns(), + array(), + $this->get_sortable_columns(), + ); + } + + /** + * Reads $this->sort_by and returns the columns name in a format that WP_Table_List + * expects + */ + public function get_sortable_columns() { + $sort_by = array(); + foreach ( $this->sort_by as $column ) { + $sort_by[ $column ] = array( $column, true ); + } + return $sort_by; + } + + /** + * Returns the columns names for rendering. It adds a checkbox for selecting everything + * as the first column + */ + public function get_columns() { + $columns = array_merge( + array( 'cb' => '' ), + array_map( array( $this, 'translate' ), $this->columns ) + ); + + return $columns; + } + + /** + * Get prepared LIMIT clause for items query + * + * @global wpdb $wpdb + * + * @return string Prepared LIMIT clause for items query. + */ + protected function get_items_query_limit() { + global $wpdb; + + $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); + return $wpdb->prepare( 'LIMIT %d', $per_page ); + } + + /** + * Returns the number of items to offset/skip for this current view. + * + * @return int + */ + protected function get_items_offset() { + $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); + $current_page = $this->get_pagenum(); + if ( 1 < $current_page ) { + $offset = $per_page * ( $current_page - 1 ); + } else { + $offset = 0; + } + + return $offset; + } + + /** + * Get prepared OFFSET clause for items query + * + * @global wpdb $wpdb + * + * @return string Prepared OFFSET clause for items query. + */ + protected function get_items_query_offset() { + global $wpdb; + + return $wpdb->prepare( 'OFFSET %d', $this->get_items_offset() ); + } + + /** + * Prepares the ORDER BY sql statement. It uses `$this->sort_by` to know which + * columns are sortable. This requests validates the orderby $_GET parameter is a valid + * column and sortable. It will also use order (ASC|DESC) using DESC by default. + */ + protected function get_items_query_order() { + if ( empty( $this->sort_by ) ) { + return ''; + } + + $orderby = esc_sql( $this->get_request_orderby() ); + $order = esc_sql( $this->get_request_order() ); + + return "ORDER BY {$orderby} {$order}"; + } + + /** + * Return the sortable column specified for this request to order the results by, if any. + * + * @return string + */ + protected function get_request_orderby() { + + $valid_sortable_columns = array_values( $this->sort_by ); + + if ( ! empty( $_GET['orderby'] ) && in_array( $_GET['orderby'], $valid_sortable_columns ) ) { + $orderby = wc_clean( $_GET['orderby'] ); + } else { + $orderby = $valid_sortable_columns[0]; + } + + return $orderby; + } + + /** + * Return the sortable column order specified for this request. + * + * @return string + */ + protected function get_request_order() { + + if ( ! empty( $_GET['order'] ) && 'desc' === strtolower( $_GET['order'] ) ) { + $order = 'DESC'; + } else { + $order = 'ASC'; + } + + return $order; + } + + /** + * Return the status filter for this request, if any. + * + * @return string + */ + protected function get_request_status() { + $status = ( ! empty( $_GET['status'] ) ) ? $_GET['status'] : ''; + return $status; + } + + /** + * Return the search filter for this request, if any. + * + * @return string + */ + protected function get_request_search_query() { + $search_query = ( ! empty( $_GET['s'] ) ) ? $_GET['s'] : ''; + return $search_query; + } + + /** + * Process and return the columns name. This is meant for using with SQL, this means it + * always includes the primary key. + * + * @return array + */ + protected function get_table_columns() { + $columns = array_keys( $this->columns ); + if ( ! in_array( $this->ID, $columns ) ) { + $columns[] = $this->ID; + } + + return $columns; + } + + /** + * Check if the current request is doing a "full text" search. If that is the case + * prepares the SQL to search texts using LIKE. + * + * If the current request does not have any search or if this list table does not support + * that feature it will return an empty string. + * + * TODO: + * - Improve search doing LIKE by word rather than by phrases. + * + * @return string + */ + protected function get_items_query_search() { + global $wpdb; + + if ( empty( $_GET['s'] ) || empty( $this->search_by ) ) { + return ''; + } + + $filter = array(); + foreach ( $this->search_by as $column ) { + $filter[] = '`' . $column . '` like "%' . $wpdb->esc_like( $_GET['s'] ) . '%"'; + } + return implode( ' OR ', $filter ); + } + + /** + * Prepares the SQL to filter rows by the options defined at `$this->filter_by`. Before trusting + * any data sent by the user it validates that it is a valid option. + */ + protected function get_items_query_filters() { + global $wpdb; + + if ( ! $this->filter_by || empty( $_GET['filter_by'] ) || ! is_array( $_GET['filter_by'] ) ) { + return ''; + } + + $filter = array(); + + foreach ( $this->filter_by as $column => $options ) { + if ( empty( $_GET['filter_by'][ $column ] ) || empty( $options[ $_GET['filter_by'][ $column ] ] ) ) { + continue; + } + + $filter[] = $wpdb->prepare( "`$column` = %s", $_GET['filter_by'][ $column ] ); + } + + return implode( ' AND ', $filter ); + + } + + /** + * Prepares the data to feed WP_Table_List. + * + * This has the core for selecting, sorting and filting data. To keep the code simple + * its logic is split among many methods (get_items_query_*). + * + * Beside populating the items this function will also count all the records that matches + * the filtering criteria and will do fill the pagination variables. + */ + public function prepare_items() { + global $wpdb; + + $this->process_bulk_action(); + + $this->process_row_actions(); + + if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { + // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter + wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); + exit; + } + + $this->prepare_column_headers(); + + $limit = $this->get_items_query_limit(); + $offset = $this->get_items_query_offset(); + $order = $this->get_items_query_order(); + $where = array_filter(array( + $this->get_items_query_search(), + $this->get_items_query_filters(), + )); + $columns = '`' . implode( '`, `', $this->get_table_columns() ) . '`'; + + if ( ! empty( $where ) ) { + $where = 'WHERE ('. implode( ') AND (', $where ) . ')'; + } else { + $where = ''; + } + + $sql = "SELECT $columns FROM {$this->table_name} {$where} {$order} {$limit} {$offset}"; + + $this->set_items( $wpdb->get_results( $sql, ARRAY_A ) ); + + $query_count = "SELECT COUNT({$this->ID}) FROM {$this->table_name} {$where}"; + $total_items = $wpdb->get_var( $query_count ); + $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); + $this->set_pagination_args( array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) ); + } + + public function extra_tablenav( $which ) { + if ( ! $this->filter_by || 'top' !== $which ) { + return; + } + + echo '
'; + + foreach ( $this->filter_by as $id => $options ) { + $default = ! empty( $_GET['filter_by'][ $id ] ) ? $_GET['filter_by'][ $id ] : ''; + if ( empty( $options[ $default ] ) ) { + $default = ''; + } + + echo ''; + } + + submit_button( $this->translate( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); + echo '
'; + } + + /** + * Set the data for displaying. It will attempt to unserialize (There is a chance that some columns + * are serialized). This can be override in child classes for futher data transformation. + */ + protected function set_items( array $items ) { + $this->items = array(); + foreach ( $items as $item ) { + $this->items[ $item[ $this->ID ] ] = array_map( 'maybe_unserialize', $item ); + } + } + + /** + * Renders the checkbox for each row, this is the first column and it is named ID regardless + * of how the primary key is named (to keep the code simpler). The bulk actions will do the proper + * name transformation though using `$this->ID`. + */ + public function column_cb( $row ) { + return ''; + } + + /** + * Renders the row-actions. + * + * This method renders the action menu, it reads the definition from the $row_actions property, + * and it checks that the row action method exists before rendering it. + * + * @param array $row Row to render + * @param $column_name Current row + * @return + */ + protected function maybe_render_actions( $row, $column_name ) { + if ( empty( $this->row_actions[ $column_name ] ) ) { + return; + } + + $row_id = $row[ $this->ID ]; + + $actions = '
'; + $action_count = 0; + foreach ( $this->row_actions[ $column_name ] as $action_key => $action ) { + + $action_count++; + + if ( ! method_exists( $this, 'row_action_' . $action_key ) ) { + continue; + } + + $action_link = ! empty( $action['link'] ) ? $action['link'] : add_query_arg( array( 'row_action' => $action_key, 'row_id' => $row_id, 'nonce' => wp_create_nonce( $action_key . '::' . $row_id ) ) ); + $span_class = ! empty( $action['class'] ) ? $action['class'] : $action_key; + $separator = ( $action_count < count( $this->row_actions[ $column_name ] ) ) ? ' | ' : ''; + + $actions .= sprintf( '', esc_attr( $span_class ) ); + $actions .= sprintf( '%3$s', esc_url( $action_link ), esc_attr( $action['desc'] ), esc_html( $action['name'] ) ); + $actions .= sprintf( '%s', $separator ); + } + $actions .= '
'; + return $actions; + } + + protected function process_row_actions() { + $parameters = array( 'row_action', 'row_id', 'nonce' ); + foreach ( $parameters as $parameter ) { + if ( empty( $_REQUEST[ $parameter ] ) ) { + return; + } + } + + $method = 'row_action_' . $_REQUEST['row_action']; + + if ( $_REQUEST['nonce'] === wp_create_nonce( $_REQUEST[ 'row_action' ] . '::' . $_REQUEST[ 'row_id' ] ) && method_exists( $this, $method ) ) { + $this->$method( $_REQUEST['row_id'] ); + } + + wp_redirect( remove_query_arg( + array( 'row_id', 'row_action', 'nonce' ), + wp_unslash( $_SERVER['REQUEST_URI'] ) + ) ); + exit; + } + + /** + * Default column formatting, it will escape everythig for security. + */ + public function column_default( $item, $column_name ) { + $column_html = esc_html( $item[ $column_name ] ); + $column_html .= $this->maybe_render_actions( $item, $column_name ); + return $column_html; + } + + /** + * Display the table heading and search query, if any + */ + protected function display_header() { + echo '

' . esc_attr( $this->table_header ) . '

'; + if ( $this->get_request_search_query() ) { + echo '' . esc_attr( $this->translate( sprintf( 'Search results for "%s"', $this->get_request_search_query() ) ) ) . ''; + } + echo '
'; + } + + /** + * Display the table heading and search query, if any + */ + protected function display_admin_notices() { + foreach ( $this->admin_notices as $notice ) { + echo '
'; + echo '

' . wp_kses_post( $notice['message'] ) . '

'; + echo '
'; + } + } + + /** + * Prints the available statuses so the user can click to filter. + */ + protected function display_filter_by_status() { + + $status_list_items = array(); + $request_status = $this->get_request_status(); + + // Helper to set 'all' filter when not set on status counts passed in + if ( ! isset( $this->status_counts['all'] ) ) { + $this->status_counts = array( 'all' => array_sum( $this->status_counts ) ) + $this->status_counts; + } + + foreach ( $this->status_counts as $status_name => $count ) { + + if ( 0 === $count ) { + continue; + } + + if ( $status_name === $request_status || ( empty( $request_status ) && 'all' === $status_name ) ) { + $status_list_item = '
  • %3$s (%4$d)
  • '; + } else { + $status_list_item = '
  • %3$s (%4$d)
  • '; + } + + $status_filter_url = ( 'all' === $status_name ) ? remove_query_arg( 'status' ) : add_query_arg( 'status', $status_name ); + $status_list_items[] = sprintf( $status_list_item, esc_attr( $status_name ), esc_url( $status_filter_url ), esc_html( ucfirst( $status_name ) ), absint( $count ) ); + } + + if ( $status_list_items ) { + echo '
      '; + echo implode( " | \n", $status_list_items ); + echo '
    '; + } + } + + /** + * Renders the table list, we override the original class to render the table inside a form + * and to render any needed HTML (like the search box). By doing so the callee of a function can simple + * forget about any extra HTML. + */ + protected function display_table() { + echo '
    '; + foreach ( $_GET as $key => $value ) { + if ( '_' === $key[0] || 'paged' === $key ) { + continue; + } + echo ''; + } + if ( ! empty( $this->search_by ) ) { + echo $this->search_box( $this->get_search_box_button_text(), 'plugin' ); // WPCS: XSS OK + } + parent::display(); + echo '
    '; + } + + /** + * Render the list table page, including header, notices, status filters and table. + */ + public function display_page() { + $this->prepare_items(); + + echo '
    '; + $this->display_header(); + $this->display_admin_notices(); + $this->display_filter_by_status(); + $this->display_table(); + echo '
    '; + } + + /** + * Get the text to display in the search box on the list table. + */ + protected function get_search_box_placeholder() { + return $this->translate( 'Search' ); + } +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Abstract_QueueRunner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Abstract_QueueRunner.php new file mode 100755 index 0000000..21f9ee0 --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_Abstract_QueueRunner.php @@ -0,0 +1,89 @@ +store = $store ? $store : ActionScheduler_Store::instance(); + $this->monitor = $monitor ? $monitor : new ActionScheduler_FatalErrorMonitor( $this->store ); + $this->cleaner = $cleaner ? $cleaner : new ActionScheduler_QueueCleaner( $this->store ); + } + + /** + * Process an individual action. + * + * @param int $action_id The action ID to process. + */ + public function process_action( $action_id ) { + try { + do_action( 'action_scheduler_before_execute', $action_id ); + $action = $this->store->fetch_action( $action_id ); + $this->store->log_execution( $action_id ); + $action->execute(); + do_action( 'action_scheduler_after_execute', $action_id ); + $this->store->mark_complete( $action_id ); + } catch ( Exception $e ) { + $this->store->mark_failure( $action_id ); + do_action( 'action_scheduler_failed_execution', $action_id, $e ); + } + $this->schedule_next_instance( $action ); + } + + /** + * Schedule the next instance of the action if necessary. + * + * @param ActionScheduler_Action $action + */ + protected function schedule_next_instance( ActionScheduler_Action $action ) { + $schedule = $action->get_schedule(); + $next = $schedule->next( as_get_datetime_object() ); + + if ( ! is_null( $next ) && $schedule->is_recurring() ) { + $this->store->save_action( $action, $next ); + } + } + + /** + * Run the queue cleaner. + * + * @author Jeremy Pry + */ + protected function run_cleanup() { + $this->cleaner->clean(); + } + + /** + * Get the number of concurrent batches a runner allows. + * + * @return int + */ + public function get_allowed_concurrent_batches() { + return apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 5 ); + } + + /** + * Process actions in the queue. + * + * @author Jeremy Pry + * @return int The number of actions processed. + */ + abstract public function run(); +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Action.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Action.php index 18ceb27..6258ba1 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_Action.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_Action.php @@ -24,7 +24,6 @@ class ActionScheduler_Action { /** * @param string $hook - * @return void */ protected function set_hook( $hook ) { $this->hook = $hook; @@ -74,4 +73,3 @@ class ActionScheduler_Action { return FALSE; } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php b/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php index f61ba48..8d97417 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php @@ -4,6 +4,46 @@ * Class ActionScheduler_ActionFactory */ class ActionScheduler_ActionFactory { + + /** + * @param string $status The action's status in the data store + * @param string $hook The hook to trigger when this action runs + * @param array $args Args to pass to callbacks when the hook is triggered + * @param ActionScheduler_Schedule $schedule The action's schedule + * @param string $group A group to put the action in + * + * @return ActionScheduler_Action An instance of the stored action + */ + public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) { + + switch ( $status ) { + case ActionScheduler_Store::STATUS_PENDING : + $action_class = 'ActionScheduler_Action'; + break; + case ActionScheduler_Store::STATUS_CANCELED : + $action_class = 'ActionScheduler_CanceledAction'; + break; + default : + $action_class = 'ActionScheduler_FinishedAction'; + break; + } + + $action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group ); + + $action = new $action_class( $hook, $args, $schedule, $group ); + + /** + * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group. + * + * @param ActionScheduler_Action $action The instantiated action. + * @param string $hook The instantiated action's hook. + * @param array $args The instantiated action's args. + * @param ActionScheduler_Schedule $schedule The instantiated action's schedule. + * @param string $group The instantiated action's group. + */ + return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group ); + } + /** * @param string $hook The hook to trigger when this action runs * @param array $args Args to pass when the hook is triggered @@ -12,7 +52,7 @@ class ActionScheduler_ActionFactory { * * @return string The ID of the stored action */ - public function single( $hook, $args = array(), $when = NULL, $group = '' ) { + public function single( $hook, $args = array(), $when = null, $group = '' ) { $date = as_get_datetime_object( $when ); $schedule = new ActionScheduler_SimpleSchedule( $date ); $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); @@ -28,7 +68,7 @@ class ActionScheduler_ActionFactory { * * @return string The ID of the stored action */ - public function recurring( $hook, $args = array(), $first = NULL, $interval = NULL, $group = '' ) { + public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) { if ( empty($interval) ) { return $this->single( $hook, $args, $first, $group ); } @@ -48,7 +88,7 @@ class ActionScheduler_ActionFactory { * * @return string The ID of the stored action */ - public function cron( $hook, $args = array(), $first = NULL, $schedule = NULL, $group = '' ) { + public function cron( $hook, $args = array(), $first = null, $schedule = null, $group = '' ) { if ( empty($schedule) ) { return $this->single( $hook, $args, $first, $group ); } @@ -69,4 +109,3 @@ class ActionScheduler_ActionFactory { return $store->save_action( $action ); } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php b/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php index fdfec0a..b1abf12 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php @@ -4,12 +4,10 @@ * Class ActionScheduler_AdminView * @codeCoverageIgnore */ -class ActionScheduler_AdminView { +class ActionScheduler_AdminView extends ActionScheduler_AdminView_Deprecated { private static $admin_view = NULL; - private static $admin_url; - /** * @return ActionScheduler_QueueRunner * @codeCoverageIgnore @@ -28,452 +26,53 @@ class ActionScheduler_AdminView { * @codeCoverageIgnore */ public function init() { - if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || false == DOING_AJAX ) ) { - add_filter( 'action_scheduler_post_type_args', array( self::instance(), 'action_scheduler_post_type_args' ) ); - } - self::$admin_url = admin_url( 'edit.php?post_type=' . ActionScheduler_wpPostStore::POST_TYPE ); - - add_filter( 'views_edit-' . ActionScheduler_wpPostStore::POST_TYPE, array( self::instance(), 'list_table_views' ) ); - - add_filter( 'bulk_actions-edit-' . ActionScheduler_wpPostStore::POST_TYPE, array( self::instance(), 'bulk_actions' ) ); - - add_filter( 'manage_' . ActionScheduler_wpPostStore::POST_TYPE . '_posts_columns', array( self::instance(), 'list_table_columns' ), 1 ); - - add_filter( 'manage_edit-' . ActionScheduler_wpPostStore::POST_TYPE . '_sortable_columns', array( self::instance(), 'list_table_sortable_columns' ) ); - - add_filter( 'manage_' . ActionScheduler_wpPostStore::POST_TYPE . '_posts_custom_column', array( self::instance(), 'list_table_column_content' ), 10, 2 ); - - add_filter( 'post_row_actions', array( self::instance(), 'row_actions' ), 10, 2 ); - - add_action( 'admin_init', array( self::instance(), 'maybe_execute_action' ), 20 ); - - add_action( 'admin_notices', array( self::instance(), 'admin_notices' ) ); - - add_filter( 'post_updated_messages', array( self::instance(), 'post_updated_messages' ) ); - - add_filter( 'posts_orderby', array( self::instance(), 'custom_orderby' ), 10, 2 ); - - add_filter( 'posts_search', array( self::instance(), 'search_post_password' ), 10, 2 ); - } - - public function action_scheduler_post_type_args( $args ) { - return array_merge( $args, array( - 'show_ui' => true, - 'show_in_menu' => 'tools.php', - 'show_in_admin_bar' => false, - ) ); - } - - /** - * Customise the post status related views displayed on the Scheduled Actions administration screen. - * - * @param array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. - * @return array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. - */ - public function list_table_views( $views ) { - - foreach ( $views as $view_key => $view ) { - if ( 'publish' == $view_key ) { - $views[ $view_key ] = str_replace( __( 'Published', 'action-scheduler' ), __( 'Complete', 'action-scheduler' ), $view ); - break; + if ( class_exists( 'WooCommerce' ) ) { + add_action( 'woocommerce_admin_status_content_action-scheduler', array( $this, 'render_admin_ui' ) ); + add_filter( 'woocommerce_admin_status_tabs', array( $this, 'register_system_status_tab' ) ); } - } - return $views; + add_action( 'admin_menu', array( $this, 'register_menu' ) ); + } + } + + + /** + * Registers action-scheduler into WooCommerce > System status. + * + * @param array $tabs An associative array of tab key => label. + * @return array $tabs An associative array of tab key => label, including Action Scheduler's tabs + */ + public function register_system_status_tab( array $tabs ) { + $tabs['action-scheduler'] = __( 'Scheduled Actions', 'action-scheduler' ); + + return $tabs; } /** - * Do not include the "Edit" action for the Scheduled Actions administration screen. + * Include Action Scheduler's administration under the Tools menu. * - * Hooked to the 'bulk_actions-edit-action-scheduler' filter. - * - * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. - * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. + * A menu under the Tools menu is important for backward compatibility (as that's + * where it started), and also provides more convenient access than the WooCommerce + * System Status page, and for sites where WooCommerce isn't active. */ - public function bulk_actions( $actions ) { - - if ( isset( $actions['edit'] ) ) { - unset( $actions['edit'] ); - } - - return $actions; - } - - /** - * Completely customer the columns displayed on the Scheduled Actions administration screen. - * - * Because we can't filter the content of the default title and date columns, we need to recreate our own - * custom columns for displaying those post fields. For the column content, @see self::list_table_column_content(). - * - * @param array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. - * @return array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. - */ - public function list_table_columns( $columns ) { - - $custom_columns = array( - 'cb' => $columns['cb'], - 'hook' => __( 'Hook', 'action-scheduler' ), // because we want to customise the inline actions - 'status' => __( 'Status', 'action-scheduler' ), - 'args' => __( 'Arguments', 'action-scheduler' ), - 'taxonomy-action-group' => __( 'Group', 'action-scheduler' ), - 'recurrence' => __( 'Recurrence', 'action-scheduler' ), - 'scheduled' => __( 'Scheduled Date', 'action-scheduler' ), // because we want to customise how the date is displayed + public function register_menu() { + add_submenu_page( + 'tools.php', + __( 'Scheduled Actions', 'action-scheduler' ), + __( 'Scheduled Actions', 'action-scheduler' ), + 'manage_options', + 'action-scheduler', + array( $this, 'render_admin_ui' ) ); - - if ( isset( $_REQUEST['post_status'] ) ) { - if ( in_array( $_REQUEST['post_status'], array( 'failed', 'in-progress' ) ) ) { - $custom_columns['modified'] = __( 'Started', 'action-scheduler' ); - } elseif ( 'publish' == $_REQUEST['post_status'] ) { - $custom_columns['modified'] = __( 'Completed', 'action-scheduler' ); - } - } - - $custom_columns['claim'] = __( 'Claim ID', 'action-scheduler' ); - $custom_columns['comments'] = __( 'Log', 'action-scheduler' ); - - return $custom_columns; } /** - * Make our custom title & date columns use defaulting title & date sorting. - * - * @param array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. - * @return array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. + * Renders the Admin UI */ - public static function list_table_sortable_columns( $columns ) { - - $columns['hook'] = 'title'; - $columns['scheduled'] = array( 'date', true ); - $columns['modified'] = 'modified'; - $columns['claim'] = 'post_password'; - - return $columns; + public function render_admin_ui() { + $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() ); + $table->display_page(); } - - /** - * Print the content for our custom columns. - * - * @param string $column_name The key for the column for which we should output our content. - * @param int $post_id The ID of the 'scheduled-action' post for which this row relates. - * @return void - */ - public static function list_table_column_content( $column_name, $post_id ) { - global $post; - - $action = ActionScheduler::store()->fetch_action( $post_id ); - - $action_title = ( 'trash' == $post->post_status ) ? $post->post_title : $action->get_hook(); - $recurrence = ( 'trash' == $post->post_status ) ? 0 : $action->get_schedule(); - $next_timestamp = as_get_datetime_object( $post->post_date_gmt )->format( 'U' ); - $status = get_post_status( $post_id ); - - switch ( $column_name ) { - case 'hook': - echo $action_title; - break; - case 'status': - if ( 'publish' == $status ) { - _e( 'Complete', 'action-scheduler' ); - } else { - echo ucfirst( $status ); - } - break; - case 'args': - $action_args = ( 'trash' == $post->post_status ) ? $post->post_content : $action->get_args(); - if ( is_array( $action_args ) ) { - foreach( $action_args as $key => $value ) { - printf( "%s => %s
    ", $key, $value ); - } - } - break; - case 'recurrence': - if ( method_exists( $recurrence, 'interval_in_seconds' ) ) { - echo self::human_interval( $recurrence->interval_in_seconds() ); - } else { - _e( 'Non-repeating', 'action-scheduler' ); - } - break; - case 'scheduled': - echo get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $next_timestamp ), 'Y-m-d H:i:s' ); - if ( gmdate( 'U' ) > $next_timestamp ) { - printf( __( ' (%s ago)', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_timestamp ) ); - } else { - echo ' (' . human_time_diff( gmdate( 'U' ), $next_timestamp ) . ')'; - } - break; - case 'modified': - echo get_post_modified_time( 'Y-m-d H:i:s' ); - $modified_timestamp = get_post_modified_time( 'U', true ); - if ( gmdate( 'U' ) > $modified_timestamp ) { - printf( __( ' (%s ago)', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $modified_timestamp ) ); - } else { - echo ' (' . human_time_diff( gmdate( 'U' ), $modified_timestamp ) . ')'; - } - break; - case 'claim': - echo $post->post_password; - break; - } - } - - /** - * Hide the inline "Edit" action for all 'scheduled-action' posts. - * - * Hooked to the 'post_row_actions' filter. - * - * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. - * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. - */ - public static function row_actions( $actions, $post ) { - - if ( ActionScheduler_wpPostStore::POST_TYPE == $post->post_type ) { - - if ( isset( $actions['edit'] ) ) { - unset( $actions['edit'] ); - } - - if ( isset( $actions['inline hide-if-no-js'] ) ) { - unset( $actions['inline hide-if-no-js'] ); - } - - if ( current_user_can( 'edit_post', $post->ID ) && ! in_array( $post->post_status, array( 'publish', 'in-progress', 'trash' ) ) ) { - $actions['process'] = "" . __( 'Run', 'action-scheduler' ) . ""; - } - - ksort( $actions ); - } - - return $actions; - } - - /** - * Retrieve a URI to execute a scheduled action. - * - * @param int $action_id The ID for a 'scheduled-action' post. - * @param string $operation To run the action (including trigger before/after hooks), log the execution and update the action's status, use 'process', to simply trigger the action, use 'execute'. Default 'execute'. - * @return string The URL for running the action. - */ - private static function get_run_action_link( $action_id, $operation = 'process' ) { - - if ( !$post = get_post( $action_id ) ) - return; - - $post_type_object = get_post_type_object( $post->post_type ); - - if ( ! $post_type_object ) - return; - - if ( ! current_user_can( 'edit_post', $post->ID ) ) - return; - - $execute_link = add_query_arg( array( 'action' => $operation, 'post_id' => $post->ID ), self::$admin_url ); - - return wp_nonce_url( $execute_link, "{$operation}-action_{$post->ID}" ); - } - - /** - * Run an action when triggered from the Action Scheduler administration screen. - * - * @codeCoverageIgnore - */ - public static function maybe_execute_action() { - - if ( ! isset( $_GET['action'] ) || 'process' != $_GET['action'] || ! isset( $_GET['post_id'] ) ){ - return; - } - - $action_id = absint( $_GET['post_id'] ); - - check_admin_referer( $_GET['action'] . '-action_' . $action_id ); - - try { - ActionScheduler::runner()->process_action( $action_id ); - $success = 1; - } catch ( Exception $e ) { - $success = 0; - } - - wp_redirect( add_query_arg( array( 'executed' => $success, 'ids' => $action_id ), self::$admin_url ) ); - exit(); - } - - /** - * Convert an interval of seconds into a two part human friendly string. - * - * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning - * even if an action is 1 day and 11 hours away, it will display "1 day". This funciton goes one step - * further to display two degrees of accuracy. - * - * Based on Crontrol::interval() funciton by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ - * - * @param int $interval A interval in seconds. - * @return string A human friendly string representation of the interval. - */ - public static function admin_notices() { - - if ( self::is_admin_page() ) { - - if ( ActionScheduler_Store::instance()->get_claim_count() >= apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 5 ) ) : ?> -
    -

    get_claim_count() ); ?>

    -
    - fetch_action( $_GET['ids'] ); - $action_hook_html = '' . $action->get_hook() . ''; - if ( 1 == $_GET['executed'] ) : ?> -
    -

    -
    - -
    -

    -
    - query['orderby'] ) && 'post_password' == $query->query['orderby'] ) { - $orderby = "$wpdb->posts.post_password " . $query->query['order']; - } - - return $orderby; - } - - /** - * Filter search queries to allow searching by Claim ID (i.e. post_password). - * - * @param string $search MySQL search string. - * @param WP_Query $query Instance of a WP_Query object - * @return string MySQL search string. - */ - public function search_post_password( $search, $query ) { - global $wpdb; - - if ( self::is_admin_page() && ! empty( $search ) ) { - - $search = ''; - - $searchand = ''; - $n = ! empty( $query->query_vars['exact'] ) ? '' : '%'; - foreach ( $query->query_vars['search_terms'] as $term ) { - $term = $wpdb->esc_like( esc_sql( $term ) ); - $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_password LIKE '{$n}{$term}{$n}'))"; - $searchand = ' AND '; - } - - if ( ! empty( $search ) ) { - $search = " AND ({$search}) "; - } - - } - - return $search; - } - - /** - * Change messages when a scheduled action is updated. - * - * @param array $messages - * @return array - */ - public function post_updated_messages( $messages ) { - global $post, $post_ID; - - $messages[ ActionScheduler_wpPostStore::POST_TYPE ] = array( - 0 => '', // Unused. Messages start at index 1. - 1 => __( 'Action updated.', 'action-scheduler' ), - 2 => __( 'Custom field updated.', 'action-scheduler' ), - 3 => __( 'Custom field deleted.', 'action-scheduler' ), - 4 => __( 'Action updated.', 'action-scheduler' ), - 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Action restored to revision from %s', 'action-scheduler' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, - 6 => __( 'Action scheduled.', 'action-scheduler' ), - 7 => __( 'Action saved.', 'action-scheduler' ), - 8 => __( 'Action submitted.', 'action-scheduler' ), - 9 => sprintf( __( 'Action scheduled for: %1$s', 'action-scheduler' ), date_i18n( __( 'M j, Y @ G:i', 'action-scheduler' ), strtotime( $post->post_date ) ) ), - 10 => __( 'Action draft updated.', 'action-scheduler' ), - ); - - return $messages; - } - - /** - * Check if the current request is for the Schedul Actions administration screen. - * - * @return bool - */ - private static function is_admin_page() { - if ( is_admin() && isset( $_GET['post_type'] ) && $_GET['post_type'] == ActionScheduler_wpPostStore::POST_TYPE ) { - return true; - } else { - return false; - } - } -} \ No newline at end of file +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView_Deprecated.php b/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView_Deprecated.php new file mode 100755 index 0000000..69b46d7 --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView_Deprecated.php @@ -0,0 +1,147 @@ +set_schedule( new ActionScheduler_NullSchedule() ); + } +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_CronSchedule.php b/includes/libraries/action-scheduler/classes/ActionScheduler_CronSchedule.php index 029c0d5..3e7db8b 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_CronSchedule.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_CronSchedule.php @@ -36,7 +36,7 @@ class ActionScheduler_CronSchedule implements ActionScheduler_Schedule { * @return array */ public function __sleep() { - $this->start_timestamp = $this->start->format('U'); + $this->start_timestamp = $this->start->getTimestamp(); return array( 'start_timestamp', 'cron' diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php b/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php new file mode 100755 index 0000000..13d8c27 --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php @@ -0,0 +1,20 @@ +format( 'U' ); + } +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_IntervalSchedule.php b/includes/libraries/action-scheduler/classes/ActionScheduler_IntervalSchedule.php index eb68a96..76068e1 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_IntervalSchedule.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_IntervalSchedule.php @@ -49,7 +49,7 @@ class ActionScheduler_IntervalSchedule implements ActionScheduler_Schedule { * @return array */ public function __sleep() { - $this->start_timestamp = $this->start->format('U'); + $this->start_timestamp = $this->start->getTimestamp(); return array( 'start_timestamp', 'interval_in_seconds' @@ -60,4 +60,3 @@ class ActionScheduler_IntervalSchedule implements ActionScheduler_Schedule { $this->start = as_get_datetime_object($this->start_timestamp); } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php b/includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php new file mode 100755 index 0000000..69dea5b --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php @@ -0,0 +1,526 @@ + label). + * + * @var array + */ + protected $columns = array(); + + /** + * Actions (name => label). + * + * @var array + */ + protected $row_actions = array(); + + /** + * The active data stores + * + * @var ActionScheduler_Store + */ + protected $store; + + /** + * A logger to use for getting action logs to display + * + * @var ActionScheduler_Logger + */ + protected $logger; + + /** + * A ActionScheduler_QueueRunner runner instance (or child class) + * + * @var ActionScheduler_QueueRunner + */ + protected $runner; + + /** + * Bulk actions. The key of the array is the method name of the implementation: + * + * bulk_(array $ids, string $sql_in). + * + * See the comments in the parent class for further details + * + * @var array + */ + protected $bulk_actions = array(); + + /** + * Flag variable to render our notifications, if any, once. + * + * @var bool + */ + protected static $did_notification = false; + + /** + * Array of seconds for common time periods, like week or month, alongside an internationalised string representation, i.e. "Day" or "Days" + * + * @var array + */ + private static $time_periods; + + /** + * Sets the current data store object into `store->action` and initialises the object. + * + * @param ActionScheduler_Store $store + * @param ActionScheduler_Logger $logger + * @param ActionScheduler_QueueRunner $runner + */ + public function __construct( ActionScheduler_Store $store, ActionScheduler_Logger $logger, ActionScheduler_QueueRunner $runner ) { + + $this->store = $store; + $this->logger = $logger; + $this->runner = $runner; + + $this->table_header = __( 'Scheduled Actions', 'action-scheduler' ); + + $this->bulk_actions = array( + 'delete' => __( 'Delete', 'action-scheduler' ), + ); + + $this->columns = array( + 'hook' => __( 'Hook', 'action-scheduler' ), + 'status' => __( 'Status', 'action-scheduler' ), + 'args' => __( 'Arguments', 'action-scheduler' ), + 'group' => __( 'Group', 'action-scheduler' ), + 'recurrence' => __( 'Recurrence', 'action-scheduler' ), + 'schedule' => __( 'Scheduled Date', 'action-scheduler' ), + 'log_entries' => __( 'Log', 'action-scheduler' ), + ); + + $this->sort_by = array( + 'schedule', + 'hook', + 'group', + ); + + $this->search_by = array( + 'hook', + 'args', + 'claim_id', + ); + + $request_status = $this->get_request_status(); + + if ( empty( $request_status ) ) { + $this->sort_by[] = 'status'; + } elseif ( in_array( $request_status, array( 'in-progress', 'failed' ) ) ) { + $this->columns += array( 'claim_id' => __( 'Claim ID', 'action-scheduler' ) ); + $this->sort_by[] = 'claim_id'; + } + + $this->row_actions = array( + 'hook' => array( + 'run' => array( + 'name' => __( 'Run', 'action-scheduler' ), + 'desc' => __( 'Process the action now as if it were run as part of a queue', 'action-scheduler' ), + ), + 'cancel' => array( + 'name' => __( 'Cancel', 'action-scheduler' ), + 'desc' => __( 'Cancel the action now to avoid it being run in future', 'action-scheduler' ), + 'class' => 'cancel trash', + ), + ), + ); + + self::$time_periods = array( + array( + 'seconds' => YEAR_IN_SECONDS, + 'names' => _n_noop( '%s year', '%s years', 'action-scheduler' ), + ), + array( + 'seconds' => MONTH_IN_SECONDS, + 'names' => _n_noop( '%s month', '%s months', 'action-scheduler' ), + ), + array( + 'seconds' => WEEK_IN_SECONDS, + 'names' => _n_noop( '%s week', '%s weeks', 'action-scheduler' ), + ), + array( + 'seconds' => DAY_IN_SECONDS, + 'names' => _n_noop( '%s day', '%s days', 'action-scheduler' ), + ), + array( + 'seconds' => HOUR_IN_SECONDS, + 'names' => _n_noop( '%s hour', '%s hours', 'action-scheduler' ), + ), + array( + 'seconds' => MINUTE_IN_SECONDS, + 'names' => _n_noop( '%s minute', '%s minutes', 'action-scheduler' ), + ), + array( + 'seconds' => 1, + 'names' => _n_noop( '%s second', '%s seconds', 'action-scheduler' ), + ), + ); + + parent::__construct( array( + 'singular' => 'action-scheduler', + 'plural' => 'action-scheduler', + 'ajax' => false, + ) ); + } + + /** + * Convert an interval of seconds into a two part human friendly string. + * + * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning + * even if an action is 1 day and 11 hours away, it will display "1 day". This function goes one step + * further to display two degrees of accuracy. + * + * Inspired by the Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ + * + * @param int $interval A interval in seconds. + * @param int $periods_to_include Depth of time periods to include, e.g. for an interval of 70, and $periods_to_include of 2, both minutes and seconds would be included. With a value of 1, only minutes would be included. + * @return string A human friendly string representation of the interval. + */ + private static function human_interval( $interval, $periods_to_include = 2 ) { + + if ( $interval <= 0 ) { + return __( 'Now!', 'action-scheduler' ); + } + + $output = ''; + + for ( $time_period_index = 0, $periods_included = 0, $seconds_remaining = $interval; $time_period_index < count( self::$time_periods ) && $seconds_remaining > 0 && $periods_included < $periods_to_include; $time_period_index++ ) { + + $periods_in_interval = floor( $seconds_remaining / self::$time_periods[ $time_period_index ]['seconds'] ); + + if ( $periods_in_interval > 0 ) { + if ( ! empty( $output ) ) { + $output .= ' '; + } + $output .= sprintf( _n( self::$time_periods[ $time_period_index ]['names'][0], self::$time_periods[ $time_period_index ]['names'][1], $periods_in_interval, 'action-scheduler' ), $periods_in_interval ); + $seconds_remaining -= $periods_in_interval * self::$time_periods[ $time_period_index ]['seconds']; + $periods_included++; + } + } + + return $output; + } + + /** + * Returns the recurrence of an action or 'Non-repeating'. The output is human readable. + * + * @param ActionScheduler_Action $action + * + * @return string + */ + protected function get_recurrence( $action ) { + $recurrence = $action->get_schedule(); + if ( method_exists( $recurrence, 'interval_in_seconds' ) ) { + return sprintf( __( 'Every %s', 'action-scheduler' ), self::human_interval( $recurrence->interval_in_seconds() ) ); + } + return __( 'Non-repeating', 'action-scheduler' ); + } + + /** + * Serializes the argument of an action to render it in a human friendly format. + * + * @param array $row The array representation of the current row of the table + * + * @return string + */ + public function column_args( array $row ) { + if ( empty( $row['args'] ) ) { + return ''; + } + + $row_html = '
      '; + foreach ( $row['args'] as $key => $value ) { + $row_html .= sprintf( '
    • %s => %s
    • ', esc_html( $key ), esc_html( $value ) ); + } + $row_html .= '
    '; + + return apply_filters( 'action_scheduler_list_table_column_args', $row_html, $row ); + } + + /** + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. + * + * @param array $row Action array. + * @return string + */ + public function column_log_entries( array $row ) { + + $log_entries_html = '
      '; + + $timezone = new DateTimezone( 'UTC' ); + + foreach ( $row['log_entries'] as $log_entry ) { + $log_entries_html .= $this->get_log_entry_html( $log_entry, $timezone ); + } + + $log_entries_html .= '
    '; + + return $log_entries_html; + } + + /** + * Prints the logs entries inline. We do so to avoid loading Javascript and other hacks to show it in a modal. + * + * @param ActionScheduler_LogEntry $log_entry + * @param DateTimezone $timezone + * @return string + */ + protected function get_log_entry_html( ActionScheduler_LogEntry $log_entry, DateTimezone $timezone ) { + $date = $log_entry->get_date(); + $date->setTimezone( $timezone ); + return sprintf( '
  • %s
    %s
  • ', esc_html( $date->format( 'Y-m-d H:i:s e' ) ), esc_html( $log_entry->get_message() ) ); + } + + /** + * Only display row actions for pending actions. + * + * @param array $row Row to render + * @param string $column_name Current row + * + * @return string + */ + protected function maybe_render_actions( $row, $column_name ) { + if ( 'pending' === strtolower( $row['status'] ) ) { + return parent::maybe_render_actions( $row, $column_name ); + } + + return ''; + } + + /** + * Renders admin notifications + * + * Notifications: + * 1. When the maximum number of tasks are being executed simultaneously + * 2. Notifications when a task us manually executed + */ + public function display_admin_notices() { + + if ( $this->store->get_claim_count() >= $this->runner->get_allowed_concurrent_batches() ) { + $this->admin_notices[] = array( + 'class' => 'updated', + 'message' => sprintf( __( 'Maximum simultaneous batches already in progress (%s queues). No actions will be processed until the current batches are complete.', 'action-scheduler' ), $this->store->get_claim_count() ), + ); + } + + $notification = get_transient( 'action_scheduler_admin_notice' ); + + if ( is_array( $notification ) ) { + delete_transient( 'action_scheduler_admin_notice' ); + + $action = $this->store->fetch_action( $notification['action_id'] ); + $action_hook_html = '' . $action->get_hook() . ''; + if ( 1 == $notification['success'] ) { + $class = 'updated'; + switch ( $notification['row_action_type'] ) { + case 'run' : + $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html ); + break; + case 'cancel' : + $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html ); + break; + default : + $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html ); + break; + } + } else { + $class = 'error'; + $action_message_html = sprintf( __( 'Could not process change for action: "%s" (ID: %d). Error: %s', 'action-scheduler' ), $action_hook_html, esc_html( $notification['action_id'] ), esc_html( $notification['error_message'] ) ); + } + + $action_message_html = apply_filters( 'action_scheduler_admin_notice_html', $action_message_html, $action, $notification ); + + $this->admin_notices[] = array( + 'class' => $class, + 'message' => $action_message_html, + ); + } + + parent::display_admin_notices(); + } + + /** + * Prints the scheduled date in a human friendly format. + * + * @param array $row The array representation of the current row of the table + * + * @return string + */ + public function column_schedule( $row ) { + return $this->get_schedule_display_string( $row['schedule'] ); + } + + /** + * Get the scheduled date in a human friendly format. + * + * @param ActionScheduler_Schedule $schedule + * @return string + */ + protected function get_schedule_display_string( ActionScheduler_Schedule $schedule ) { + + $schedule_display_string = ''; + + if ( ! $schedule->next() ) { + return $schedule_display_string; + } + + $next_timestamp = $schedule->next()->getTimestamp(); + + $schedule_display_string .= $schedule->next()->format( 'Y-m-d H:i:s e' ); + $schedule_display_string .= '
    '; + + if ( gmdate( 'U' ) > $next_timestamp ) { + $schedule_display_string .= sprintf( __( ' (%s ago)', 'action-scheduler' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) ); + } else { + $schedule_display_string .= sprintf( __( ' (%s)', 'action-scheduler' ), self::human_interval( $next_timestamp - gmdate( 'U' ) ) ); + } + + return $schedule_display_string; + } + + /** + * Bulk delete + * + * Deletes actions based on their ID. This is the handler for the bulk delete. It assumes the data + * properly validated by the callee and it will delete the actions without any extra validation. + * + * @param array $ids + * @param string $ids_sql Inherited and unused + */ + protected function bulk_delete( array $ids, $ids_sql ) { + foreach ( $ids as $id ) { + $this->store->delete_action( $id ); + } + } + + /** + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their + * parameters are valid. + * + * @param int $action_id + */ + protected function row_action_cancel( $action_id ) { + $this->process_row_action( $action_id, 'cancel' ); + } + + /** + * Implements the logic behind running an action. ActionScheduler_Abstract_ListTable validates the request and their + * parameters are valid. + * + * @param int $action_id + */ + protected function row_action_run( $action_id ) { + $this->process_row_action( $action_id, 'run' ); + } + + /** + * Implements the logic behind processing an action once an action link is clicked on the list table. + * + * @param int $action_id + * @param string $row_action_type The type of action to perform on the action. + */ + protected function process_row_action( $action_id, $row_action_type ) { + try { + switch ( $row_action_type ) { + case 'run' : + $this->runner->process_action( $action_id ); + break; + case 'cancel' : + $this->store->cancel_action( $action_id ); + break; + } + $success = 1; + $error_message = ''; + } catch ( Exception $e ) { + $success = 0; + $error_message = $e->getMessage(); + } + + set_transient( 'action_scheduler_admin_notice', compact( 'action_id', 'success', 'error_message', 'row_action_type' ), 30 ); + } + + /** + * {@inheritDoc} + */ + public function prepare_items() { + $this->process_bulk_action(); + + $this->process_row_actions(); + + if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) { + // _wp_http_referer is used only on bulk actions, we remove it to keep the $_GET shorter + wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); + exit; + } + + $this->prepare_column_headers(); + + $per_page = $this->get_items_per_page( $this->package . '_items_per_page', $this->items_per_page ); + $query = array( + 'per_page' => $per_page, + 'offset' => $this->get_items_offset(), + 'status' => $this->get_request_status(), + 'orderby' => $this->get_request_orderby(), + 'order' => $this->get_request_order(), + 'search' => $this->get_request_search_query(), + ); + + $this->items = array(); + + $total_items = $this->store->query_actions( $query, 'count' ); + + $status_labels = $this->store->get_status_labels(); + + foreach ( $this->store->query_actions( $query ) as $action_id ) { + try { + $action = $this->store->fetch_action( $action_id ); + } catch ( Exception $e ) { + continue; + } + $this->items[ $action_id ] = array( + 'ID' => $action_id, + 'hook' => $action->get_hook(), + 'status' => $status_labels[ $this->store->get_status( $action_id ) ], + 'args' => $action->get_args(), + 'group' => $action->get_group(), + 'log_entries' => $this->logger->get_logs( $action_id ), + 'claim_id' => $this->store->get_claim_id( $action_id ), + 'recurrence' => $this->get_recurrence( $action ), + 'schedule' => $action->get_schedule(), + ); + } + + $this->set_pagination_args( array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) ); + } + + /** + * Prints the available statuses so the user can click to filter. + */ + protected function display_filter_by_status() { + $this->status_counts = $this->store->action_counts(); + parent::display_filter_by_status(); + } + + /** + * Get the text to display in the search box on the list table. + */ + protected function get_search_box_button_text() { + return __( 'Search hook, args and claim ID', 'action-scheduler' ); + } +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php b/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php index 755cd6d..649636d 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php @@ -4,12 +4,56 @@ * Class ActionScheduler_LogEntry */ class ActionScheduler_LogEntry { - protected $action_id = ''; - protected $message = ''; - public function __construct( $action_id, $message ) { + /** + * @var int $action_id + */ + protected $action_id = ''; + + /** + * @var string $message + */ + protected $message = ''; + + /** + * @var Datetime $date + */ + protected $date; + + /** + * Constructor + * + * @param mixed $action_id Action ID + * @param string $message Message + * @param Datetime $date Datetime object with the time when this log entry was created. If this parameter is + * not provided a new Datetime object (with current time) will be created. + */ + public function __construct( $action_id, $message, $date = null ) { + + /* + * ActionScheduler_wpCommentLogger::get_entry() previously passed a 3rd param of $comment->comment_type + * to ActionScheduler_LogEntry::__construct(), goodness knows why, and the Follow-up Emails plugin + * hard-codes loading its own version of ActionScheduler_wpCommentLogger with that out-dated method, + * goodness knows why, so we need to guard against that here instead of using a DateTime type declaration + * for the constructor's 3rd param of $date and causing a fatal error with older versions of FUE. + */ + if ( null !== $date && ! is_a( $date, 'DateTime' ) ) { + _doing_it_wrong( __METHOD__, 'The third parameter must be a valid DateTime instance, or null.', '2.0.0' ); + $date = null; + } + $this->action_id = $action_id; - $this->message = $message; + $this->message = $message; + $this->date = $date ? $date : new Datetime; + } + + /** + * Returns the date when this log entry was created + * + * @return Datetime + */ + public function get_date() { + return $this->date; } public function get_action_id() { @@ -20,4 +64,4 @@ class ActionScheduler_LogEntry { return $this->message; } } - \ No newline at end of file + diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php index cfcfa4b..5daf11b 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php @@ -4,29 +4,76 @@ * Class ActionScheduler_QueueCleaner */ class ActionScheduler_QueueCleaner { - /** @var ActionScheduler_Store */ - private $store = NULL; - private $month_in_seconds = 2678400; // 31 days + /** @var int */ + protected $batch_size; + + /** @var ActionScheduler_Store */ + private $store = null; + + /** + * 31 days in seconds. + * + * @var int + */ + private $month_in_seconds = 2678400; + + /** + * Five minutes in seconds + * + * @var int + */ private $five_minutes = 300; - public function __construct( ActionScheduler_Store $store = NULL ) { + /** + * ActionScheduler_QueueCleaner constructor. + * + * @param ActionScheduler_Store $store The store instance. + * @param int $batch_size The batch size. + */ + public function __construct( ActionScheduler_Store $store = null, $batch_size = 20 ) { $this->store = $store ? $store : ActionScheduler_Store::instance(); + $this->batch_size = $batch_size; } public function delete_old_actions() { $lifespan = apply_filters( 'action_scheduler_retention_period', $this->month_in_seconds ); $cutoff = as_get_datetime_object($lifespan.' seconds ago'); - $actions_to_delete = $this->store->query_actions( array( - 'status' => ActionScheduler_Store::STATUS_COMPLETE, - 'modified' => $cutoff, - 'modified_compare' => '<=', - 'per_page' => apply_filters( 'action_scheduler_cleanup_batch_size', 20 ), - ) ); + $statuses_to_purge = array( + ActionScheduler_Store::STATUS_COMPLETE, + ActionScheduler_Store::STATUS_CANCELED, + ); - foreach ( $actions_to_delete as $action_id ) { - $this->store->delete_action( $action_id ); + foreach ( $statuses_to_purge as $status ) { + $actions_to_delete = $this->store->query_actions( array( + 'status' => $status, + 'modified' => $cutoff, + 'modified_compare' => '<=', + 'per_page' => $this->get_batch_size(), + ) ); + + foreach ( $actions_to_delete as $action_id ) { + try { + $this->store->delete_action( $action_id ); + } catch ( Exception $e ) { + + /** + * Notify 3rd party code of exceptions when deleting a completed action older than the retention period + * + * This hook provides a way for 3rd party code to log or otherwise handle exceptions relating to their + * actions. + * + * @since 2.0.0 + * + * @param int $action_id The scheduled actions ID in the data store + * @param Exception $e The exception thrown when attempting to delete the action from the data store + * @param int $lifespan The retention period, in seconds, for old actions + * @param int $count_of_actions_to_delete The number of old actions being deleted in this batch + */ + do_action( 'action_scheduler_failed_old_action_deletion', $action_id, $e, $lifespan, count( $actions_to_delete ) ); + } + } } } @@ -37,11 +84,11 @@ class ActionScheduler_QueueCleaner { } $cutoff = as_get_datetime_object($timeout.' seconds ago'); $actions_to_reset = $this->store->query_actions( array( - 'status' => ActionScheduler_Store::STATUS_PENDING, - 'modified' => $cutoff, + 'status' => ActionScheduler_Store::STATUS_PENDING, + 'modified' => $cutoff, 'modified_compare' => '<=', - 'claimed' => TRUE, - 'per_page' => apply_filters( 'action_scheduler_cleanup_batch_size', 20 ), + 'claimed' => true, + 'per_page' => $this->get_batch_size(), ) ); foreach ( $actions_to_reset as $action_id ) { @@ -57,10 +104,10 @@ class ActionScheduler_QueueCleaner { } $cutoff = as_get_datetime_object($timeout.' seconds ago'); $actions_to_reset = $this->store->query_actions( array( - 'status' => ActionScheduler_Store::STATUS_RUNNING, - 'modified' => $cutoff, + 'status' => ActionScheduler_Store::STATUS_RUNNING, + 'modified' => $cutoff, 'modified_compare' => '<=', - 'per_page' => apply_filters( 'action_scheduler_cleanup_batch_size', 20 ), + 'per_page' => $this->get_batch_size(), ) ); foreach ( $actions_to_reset as $action_id ) { @@ -68,5 +115,30 @@ class ActionScheduler_QueueCleaner { do_action( 'action_scheduler_failed_action', $action_id, $timeout ); } } + + /** + * Do all of the cleaning actions. + * + * @author Jeremy Pry + */ + public function clean() { + $this->delete_old_actions(); + $this->reset_timeouts(); + $this->mark_failures(); + } + + /** + * Get the batch size for cleaning the queue. + * + * @author Jeremy Pry + * @return int + */ + protected function get_batch_size() { + /** + * Filter the batch size when cleaning the queue. + * + * @param int $batch_size The number of actions to clean in one batch. + */ + return absint( apply_filters( 'action_scheduler_cleanup_batch_size', $this->batch_size ) ); + } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php index 99e8f06..387bb51 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php @@ -3,18 +3,23 @@ /** * Class ActionScheduler_QueueRunner */ -class ActionScheduler_QueueRunner { +class ActionScheduler_QueueRunner extends ActionScheduler_Abstract_QueueRunner { const WP_CRON_HOOK = 'action_scheduler_run_queue'; const WP_CRON_SCHEDULE = 'every_minute'; /** @var ActionScheduler_QueueRunner */ - private static $runner = NULL; - /** @var ActionScheduler_Store */ - private $store = NULL; + private static $runner = null; - /** @var ActionScheduler_FatalErrorMonitor */ - private $monitor = NULL; + /** + * The created time. + * + * Represents when the queue runner was constructed and used when calculating how long a PHP request has been running. + * For this reason it should be as close as possible to the PHP request start time. + * + * @var int + */ + private $created_time; /** * @return ActionScheduler_QueueRunner @@ -28,8 +33,16 @@ class ActionScheduler_QueueRunner { return self::$runner; } - public function __construct( ActionScheduler_Store $store = NULL ) { - $this->store = $store ? $store : ActionScheduler_Store::instance(); + /** + * ActionScheduler_QueueRunner constructor. + * + * @param ActionScheduler_Store $store + * @param ActionScheduler_FatalErrorMonitor $monitor + * @param ActionScheduler_QueueCleaner $cleaner + */ + public function __construct( ActionScheduler_Store $store = null, ActionScheduler_FatalErrorMonitor $monitor = null, ActionScheduler_QueueCleaner $cleaner = null ) { + parent::__construct( $store, $monitor, $cleaner ); + $this->created_time = microtime( true ); } /** @@ -53,29 +66,32 @@ class ActionScheduler_QueueRunner { do_action( 'action_scheduler_before_process_queue' ); $this->run_cleanup(); $count = 0; - if ( $this->store->get_claim_count() < apply_filters( 'action_scheduler_queue_runner_concurrent_batches', 5 ) ) { + if ( $this->store->get_claim_count() < $this->get_allowed_concurrent_batches() ) { $batch_size = apply_filters( 'action_scheduler_queue_runner_batch_size', 25 ); - $this->monitor = new ActionScheduler_FatalErrorMonitor( $this->store ); $count = $this->do_batch( $batch_size ); - unset( $this->monitor ); } do_action( 'action_scheduler_after_process_queue' ); return $count; } - protected function run_cleanup() { - $cleaner = new ActionScheduler_QueueCleaner( $this->store ); - $cleaner->delete_old_actions(); - $cleaner->reset_timeouts(); - $cleaner->mark_failures(); - } - protected function do_batch( $size = 100 ) { $claim = $this->store->stake_claim($size); $this->monitor->attach($claim); - $processed_actions = 0; + $processed_actions = 0; + $maximum_execution_time = $this->get_maximum_execution_time(); + foreach ( $claim->get_actions() as $action_id ) { + if ( 0 !== $processed_actions ) { + $time_elapsed = $this->get_execution_time(); + $average_processing_time = $time_elapsed / $processed_actions; + + // Bail early if the time it has taken to process this batch is approaching the maximum execution time. + if ( $time_elapsed + ( $average_processing_time * 2 ) > $maximum_execution_time ) { + break; + } + } + // bail if we lost the claim if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) { break; @@ -89,31 +105,6 @@ class ActionScheduler_QueueRunner { return $processed_actions; } - public function process_action( $action_id ) { - try { - do_action( 'action_scheduler_before_execute', $action_id ); - $action = $this->store->fetch_action( $action_id ); - $this->store->log_execution( $action_id ); - $action->execute(); - do_action( 'action_scheduler_after_execute', $action_id ); - $this->store->mark_complete( $action_id ); - } catch ( Exception $e ) { - $this->store->mark_failure( $action_id ); - do_action( 'action_scheduler_failed_execution', $action_id, $e ); - } - $this->schedule_next_instance( $action ); - } - - protected function schedule_next_instance( ActionScheduler_Action $action ) { - - $schedule = $action->get_schedule(); - $next = $schedule->next( as_get_datetime_object() ); - - if ( ! is_null( $next ) && $schedule->is_recurring() ) { - $this->store->save_action( $action, $next ); - } - } - /** * Running large batches can eat up memory, as WP adds data to its object cache. * @@ -121,8 +112,6 @@ class ActionScheduler_QueueRunner { * as well, so this is disabled by default. To enable: * * add_filter( 'action_scheduler_queue_runner_flush_cache', '__return_true' ); - * - * @return void */ protected function clear_caches() { if ( ! wp_using_ext_object_cache() || apply_filters( 'action_scheduler_queue_runner_flush_cache', false ) ) { @@ -138,5 +127,43 @@ class ActionScheduler_QueueRunner { return $schedules; } + + /** + * Get the maximum number of seconds a batch can run for. + * + * @return int The number of seconds. + */ + protected function get_maximum_execution_time() { + + // There are known hosts with a strict 60 second execution time. + if ( defined( 'WPENGINE_ACCOUNT' ) || defined( 'PANTHEON_ENVIRONMENT' ) ) { + $maximum_execution_time = 60; + } elseif ( false !== strpos( getenv( 'HOSTNAME' ), '.siteground.' ) ) { + $maximum_execution_time = 120; + } else { + $maximum_execution_time = ini_get( 'max_execution_time' ); + } + + return absint( apply_filters( 'action_scheduler_maximum_execution_time', $maximum_execution_time ) ); + } + + /** + * Get the number of seconds a batch has run for. + * + * @return int The number of seconds. + */ + protected function get_execution_time() { + $execution_time = microtime( true ) - $this->created_time; + + // Get the CPU time if the hosting environment uses it rather than wall-clock time to calculate a process's execution time. + if ( function_exists( 'getrusage' ) && apply_filters( 'action_scheduler_use_cpu_execution_time', defined( 'PANTHEON_ENVIRONMENT' ) ) ) { + $resource_usages = getrusage(); + + if ( isset( $resource_usages['ru_stime.tv_usec'], $resource_usages['ru_stime.tv_usec'] ) ) { + $execution_time = $resource_usages['ru_stime.tv_sec'] + ( $resource_usages['ru_stime.tv_usec'] / 1000000 ); + } + } + + return $execution_time; + } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_SimpleSchedule.php b/includes/libraries/action-scheduler/classes/ActionScheduler_SimpleSchedule.php index 8f621e1..42f789f 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_SimpleSchedule.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_SimpleSchedule.php @@ -32,7 +32,7 @@ class ActionScheduler_SimpleSchedule implements ActionScheduler_Schedule { * @return array */ public function __sleep() { - $this->timestamp = $this->date->format('U'); + $this->timestamp = $this->date->getTimestamp(); return array( 'timestamp', ); @@ -42,4 +42,3 @@ class ActionScheduler_SimpleSchedule implements ActionScheduler_Schedule { $this->date = as_get_datetime_object($this->timestamp); } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Store.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Store.php index 2d4b973..d967b59 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_Store.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_Store.php @@ -6,22 +6,23 @@ */ abstract class ActionScheduler_Store { const STATUS_COMPLETE = 'complete'; - const STATUS_PENDING = 'pending'; - const STATUS_RUNNING = 'in-progress'; - const STATUS_FAILED = 'failed'; + const STATUS_PENDING = 'pending'; + const STATUS_RUNNING = 'in-progress'; + const STATUS_FAILED = 'failed'; + const STATUS_CANCELED = 'canceled'; /** @var ActionScheduler_Store */ private static $store = NULL; /** * @param ActionScheduler_Action $action - * @param DateTime $date Optional date of the first instance + * @param DateTime $scheduled_date Optional Date of the first instance * to store. Otherwise uses the first date of the action's * schedule. * * @return string The action ID */ - abstract public function save_action( ActionScheduler_Action $action, DateTime $date = NULL ); + abstract public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ); /** * @param string $action_id @@ -44,16 +45,19 @@ abstract class ActionScheduler_Store { abstract public function query_actions( $query = array() ); /** - * @param string $action_id + * Get a count of all actions in the store, grouped by status * - * @return void + * @return array + */ + abstract public function action_counts(); + + /** + * @param string $action_id */ abstract public function cancel_action( $action_id ); /** * @param string $action_id - * - * @return void */ abstract public function delete_action( $action_id ); @@ -66,12 +70,14 @@ abstract class ActionScheduler_Store { /** - * @param int $max_actions + * @param int $max_actions * @param DateTime $before_date Claim only actions schedule before the given date. Defaults to now. + * @param array $hooks Claim only actions with a hook or hooks. + * @param string $group Claim only actions in the given group. * * @return ActionScheduler_ActionClaim */ - abstract public function stake_claim( $max_actions = 10, DateTime $before_date = NULL ); + abstract public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ); /** * @return int @@ -80,38 +86,115 @@ abstract class ActionScheduler_Store { /** * @param ActionScheduler_ActionClaim $claim - * - * @return void */ abstract public function release_claim( ActionScheduler_ActionClaim $claim ); /** * @param string $action_id - * - * @return void */ abstract public function unclaim_action( $action_id ); /** * @param string $action_id - * - * @return void */ abstract public function mark_failure( $action_id ); /** * @param string $action_id - * @return void */ abstract public function log_execution( $action_id ); /** * @param string $action_id - * - * @return void */ abstract public function mark_complete( $action_id ); + /** + * @param string $action_id + * + * @return string + */ + abstract public function get_status( $action_id ); + + /** + * @param string $action_id + * @return mixed + */ + abstract public function get_claim_id( $action_id ); + + /** + * @param string $claim_id + * @return array + */ + abstract public function find_actions_by_claim_id( $claim_id ); + + /** + * @param string $comparison_operator + * @return string + */ + protected function validate_sql_comparator( $comparison_operator ) { + if ( in_array( $comparison_operator, array('!=', '>', '>=', '<', '<=', '=') ) ) { + return $comparison_operator; + } + return '='; + } + + /** + * Get the time MySQL formated date/time string for an action's (next) scheduled date. + * + * @param ActionScheduler_Action $action + * @param DateTime $scheduled_date (optional) + * @return string + */ + protected function get_scheduled_date_string( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) { + $next = null === $scheduled_date ? $action->get_schedule()->next() : $scheduled_date; + if ( ! $next ) { + throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'action-scheduler' ) ); + } + $next->setTimezone( new DateTimeZone( 'UTC' ) ); + + return $next->format( 'Y-m-d H:i:s' ); + } + + /** + * Get the time MySQL formated date/time string for an action's (next) scheduled date. + * + * @param ActionScheduler_Action $action + * @param DateTime $scheduled_date (optional) + * @return string + */ + protected function get_scheduled_date_string_local( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) { + $next = null === $scheduled_date ? $action->get_schedule()->next() : $scheduled_date; + if ( ! $next ) { + throw new InvalidArgumentException( __( 'Invalid schedule. Cannot save action.', 'action-scheduler' ) ); + } + $next->setTimezone( $this->get_local_timezone() ); + + return $next->format( 'Y-m-d H:i:s' ); + } + + /** + * Get the site's local time. Wrapper for ActionScheduler_TimezoneHelper::get_local_timezone(). + * + * @return DateTimeZone + */ + protected function get_local_timezone() { + return ActionScheduler_TimezoneHelper::get_local_timezone(); + } + + /** + * @return array + */ + public function get_status_labels() { + return array( + self::STATUS_COMPLETE => __( 'Complete', 'action-scheduler' ), + self::STATUS_PENDING => __( 'Pending', 'action-scheduler' ), + self::STATUS_RUNNING => __( 'In-progress', 'action-scheduler' ), + self::STATUS_FAILED => __( 'Failed', 'action-scheduler' ), + self::STATUS_CANCELED => __( 'Canceled', 'action-scheduler' ), + ); + } + public function init() {} /** @@ -125,4 +208,3 @@ abstract class ActionScheduler_Store { return self::$store; } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_WPCLI_QueueRunner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_WPCLI_QueueRunner.php new file mode 100755 index 0000000..b3f1730 --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_WPCLI_QueueRunner.php @@ -0,0 +1,204 @@ +run_cleanup(); + $this->add_hooks(); + + // Check to make sure there aren't too many concurrent processes running. + $claim_count = $this->store->get_claim_count(); + $too_many = $claim_count >= $this->get_allowed_concurrent_batches(); + if ( $too_many ) { + if ( $force ) { + WP_CLI::warning( __( 'There are too many concurrent batches, but the run is forced to continue.', 'action-scheduler' ) ); + } else { + WP_CLI::error( __( 'There are too many concurrent batches.', 'action-scheduler' ) ); + } + } + + // Stake a claim and store it. + $this->claim = $this->store->stake_claim( $batch_size, null, $hooks, $group ); + $this->monitor->attach( $this->claim ); + $this->actions = $this->claim->get_actions(); + + return count( $this->actions ); + } + + /** + * Add our hooks to the appropriate actions. + * + * @author Jeremy Pry + */ + protected function add_hooks() { + add_action( 'action_scheduler_before_execute', array( $this, 'before_execute' ) ); + add_action( 'action_scheduler_after_execute', array( $this, 'after_execute' ) ); + add_action( 'action_scheduler_failed_execution', array( $this, 'action_failed' ), 10, 2 ); + } + + /** + * Set up the WP CLI progress bar. + * + * @author Jeremy Pry + */ + protected function setup_progress_bar() { + $count = count( $this->actions ); + $this->progress_bar = \WP_CLI\Utils\make_progress_bar( + sprintf( _n( 'Running %d action', 'Running %d actions', $count, 'action-scheduler' ), number_format_i18n( $count ) ), + $count + ); + } + + /** + * Process actions in the queue. + * + * @author Jeremy Pry + * @return int The number of actions processed. + */ + public function run() { + do_action( 'action_scheduler_before_process_queue' ); + $this->setup_progress_bar(); + foreach ( $this->actions as $action_id ) { + // Error if we lost the claim. + if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $this->claim->get_id() ) ) ) { + WP_CLI::warning( __( 'The claim has been lost. Aborting current batch.', 'action-scheduler' ) ); + break; + } + + $this->process_action( $action_id ); + $this->progress_bar->tick(); + + // Free up memory after every 50 items + if ( 0 === $this->progress_bar->current() % 50 ) { + $this->stop_the_insanity(); + } + } + + $completed = $this->progress_bar->current(); + $this->progress_bar->finish(); + $this->store->release_claim( $this->claim ); + do_action( 'action_scheduler_after_process_queue' ); + + return $completed; + } + + /** + * Handle WP CLI message when the action is starting. + * + * @author Jeremy Pry + * + * @param $action_id + */ + public function before_execute( $action_id ) { + /* translators: %s refers to the action ID */ + WP_CLI::log( sprintf( __( 'Started processing action %s', 'action-scheduler' ), $action_id ) ); + } + + /** + * Handle WP CLI message when the action has completed. + * + * @author Jeremy Pry + * + * @param $action_id + */ + public function after_execute( $action_id ) { + /* translators: %s refers to the action ID */ + WP_CLI::log( sprintf( __( 'Completed processing action %s', 'action-scheduler' ), $action_id ) ); + } + + /** + * Handle WP CLI message when the action has failed. + * + * @author Jeremy Pry + * + * @param int $action_id + * @param Exception $exception + * @throws \WP_CLI\ExitException With failure message. + */ + public function action_failed( $action_id, $exception ) { + WP_CLI::error( + /* translators: %1$s refers to the action ID, %2$s refers to the Exception message */ + sprintf( __( 'Error processing action %1$s: %2$s', 'action-scheduler' ), $action_id, $exception->getMessage() ), + false + ); + } + + /** + * Sleep and help avoid hitting memory limit + * + * @param int $sleep_time Amount of seconds to sleep + */ + protected function stop_the_insanity( $sleep_time = 0 ) { + if ( 0 < $sleep_time ) { + WP_CLI::warning( sprintf( 'Stopped the insanity for %d %s', $sleep_time, _n( 'second', 'seconds', $sleep_time ) ) ); + sleep( $sleep_time ); + } + + WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) ); + + /** + * @var $wpdb \wpdb + * @var $wp_object_cache \WP_Object_Cache + */ + global $wpdb, $wp_object_cache; + + $wpdb->queries = array(); + + if ( ! is_object( $wp_object_cache ) ) { + return; + } + + $wp_object_cache->group_ops = array(); + $wp_object_cache->stats = array(); + $wp_object_cache->memcache_debug = array(); + $wp_object_cache->cache = array(); + + if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) { + call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important + } + } +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_WPCLI_Scheduler_command.php b/includes/libraries/action-scheduler/classes/ActionScheduler_WPCLI_Scheduler_command.php new file mode 100755 index 0000000..30d0974 --- /dev/null +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_WPCLI_Scheduler_command.php @@ -0,0 +1,145 @@ +] + * : The maximum number of actions to run. Defaults to 100. + * + * [--batches=] + * : Limit execution to a number of batches. Defaults to 0, meaning batches will continue being executed until all actions are complete. + * + * [--cleanup-batch-size=] + * : The maximum number of actions to clean up. Defaults to the value of --batch-size. + * + * [--hooks=] + * : Only run actions with the specified hook. Omitting this option runs actions with any hook. Define multiple hooks as a comma separated string (without spaces), e.g. `--hooks=hook_one,hook_two,hook_three` + * + * [--group=] + * : Only run actions from the specified group. Omitting this option runs actions from all groups. + * + * [--force] + * : Whether to force execution despite the maximum number of concurrent processes being exceeded. + * + * @param array $args Positional arguments. + * @param array $assoc_args Keyed arguments. + * @throws \WP_CLI\ExitException When an error occurs. + */ + public function run( $args, $assoc_args ) { + // Handle passed arguments. + $batch = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) ); + $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) ); + $clean = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) ); + $hooks = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) ); + $hooks = array_filter( array_map( 'trim', $hooks ) ); + $group = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' ); + $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false ); + + $batches_completed = 0; + $actions_completed = 0; + $unlimited = $batches === 0; + + try { + // Custom queue cleaner instance. + $cleaner = new ActionScheduler_QueueCleaner( null, $clean ); + + // Get the queue runner instance + $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner ); + + // Determine how many tasks will be run in the first batch. + $total = $runner->setup( $batch, $hooks, $group, $force ); + + // Run actions for as long as possible. + while ( $total > 0 ) { + $this->print_total_actions( $total ); + $actions_completed += $runner->run(); + $batches_completed++; + + // Maybe set up tasks for the next batch. + $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0; + } + } catch ( Exception $e ) { + $this->print_error( $e ); + } + + $this->print_total_batches( $batches_completed ); + $this->print_success( $actions_completed ); + } + + /** + * Print WP CLI message about how many actions are about to be processed. + * + * @author Jeremy Pry + * + * @param int $total + */ + protected function print_total_actions( $total ) { + WP_CLI::log( + sprintf( + /* translators: %d refers to how many scheduled taks were found to run */ + _n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler' ), + number_format_i18n( $total ) + ) + ); + } + + /** + * Print WP CLI message about how many batches of actions were processed. + * + * @author Jeremy Pry + * + * @param int $batches_completed + */ + protected function print_total_batches( $batches_completed ) { + WP_CLI::log( + sprintf( + /* translators: %d refers to the total number of batches executed */ + _n( '%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler' ), + number_format_i18n( $batches_completed ) + ) + ); + } + + /** + * Convert an exception into a WP CLI error. + * + * @author Jeremy Pry + * + * @param Exception $e The error object. + * + * @throws \WP_CLI\ExitException + */ + protected function print_error( Exception $e ) { + WP_CLI::error( + sprintf( + /* translators: %s refers to the exception error message. */ + __( 'There was an error running the action scheduler: %s', 'action-scheduler' ), + $e->getMessage() + ) + ); + } + + /** + * Print a success message with the number of completed actions. + * + * @author Jeremy Pry + * + * @param int $actions_completed + */ + protected function print_success( $actions_completed ) { + WP_CLI::success( + sprintf( + /* translators: %d refers to the total number of taskes completed */ + _n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler' ), + number_format_i18n( $actions_completed ) + ) + ); + } +} diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_wpCommentLogger.php b/includes/libraries/action-scheduler/classes/ActionScheduler_wpCommentLogger.php index 58137a0..78a9c29 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_wpCommentLogger.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_wpCommentLogger.php @@ -49,7 +49,10 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger { if ( empty($comment) || $comment->comment_type != self::TYPE ) { return new ActionScheduler_NullLogEntry(); } - return new ActionScheduler_LogEntry( $comment->comment_post_ID, $comment->comment_content, $comment->comment_type ); + + $date = as_get_datetime_object( $comment->comment_date_gmt ); + $date->setTimezone( ActionScheduler_TimezoneHelper::get_local_timezone() ); + return new ActionScheduler_LogEntry( $comment->comment_post_ID, $comment->comment_content, $date ); } /** @@ -87,8 +90,6 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger { /** * @param WP_Comment_Query $query - * - * @return void */ public function filter_comment_queries( $query ) { foreach ( array('ID', 'parent', 'post_author', 'post_name', 'post_parent', 'type', 'post_type', 'post_id', 'post_ID') as $key ) { @@ -205,8 +206,6 @@ class ActionScheduler_wpCommentLogger extends ActionScheduler_Logger { /** * Delete comment count cache whenever there is new comment or the status of a comment changes. Cache * will be regenerated next time ActionScheduler_wpCommentLogger::filter_comment_count() is called. - * - * @return void */ public function delete_comment_count_cache() { delete_transient( 'as_comment_count' ); diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php b/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php index af54a36..030e65d 100755 --- a/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php +++ b/includes/libraries/action-scheduler/classes/ActionScheduler_wpPostStore.php @@ -11,9 +11,9 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { /** @var DateTimeZone */ protected $local_timezone = NULL; - public function save_action( ActionScheduler_Action $action, DateTime $date = NULL ){ + public function save_action( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ){ try { - $post_array = $this->create_post_array( $action, $date ); + $post_array = $this->create_post_array( $action, $scheduled_date ); $post_id = $this->save_post_array( $post_array ); $this->save_post_schedule( $post_id, $action->get_schedule() ); $this->save_action_group( $post_id, $action->get_group() ); @@ -24,44 +24,22 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { } } - protected function create_post_array( ActionScheduler_Action $action, DateTime $date = NULL ) { + protected function create_post_array( ActionScheduler_Action $action, DateTime $scheduled_date = NULL ) { $post = array( 'post_type' => self::POST_TYPE, 'post_title' => $action->get_hook(), 'post_content' => json_encode($action->get_args()), 'post_status' => ( $action->is_finished() ? 'publish' : 'pending' ), - 'post_date_gmt' => $this->get_timestamp($action, $date), - 'post_date' => $this->get_local_timestamp($action, $date), + 'post_date_gmt' => $this->get_scheduled_date_string( $action, $scheduled_date ), + 'post_date' => $this->get_scheduled_date_string_local( $action, $scheduled_date ), ); return $post; } - protected function get_timestamp( ActionScheduler_Action $action, DateTime $date = NULL ) { - $next = is_null($date) ? $action->get_schedule()->next() : $date; - if ( !$next ) { - throw new InvalidArgumentException(__('Invalid schedule. Cannot save action.', 'action-scheduler')); - } - $next->setTimezone(new DateTimeZone('UTC')); - return $next->format('Y-m-d H:i:s'); - } - - protected function get_local_timestamp( ActionScheduler_Action $action, DateTime $date = NULL ) { - $next = is_null($date) ? $action->get_schedule()->next() : $date; - if ( !$next ) { - throw new InvalidArgumentException(__('Invalid schedule. Cannot save action.', 'action-scheduler')); - } - $next->setTimezone($this->get_local_timezone()); - return $next->format('Y-m-d H:i:s'); - } - - protected function get_local_timezone() { - return ActionScheduler_TimezoneHelper::get_local_timezone(); - } - protected function save_post_array( $post_array ) { add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 ); $post_id = wp_insert_post($post_array); - remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 ); + remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 ); if ( is_wp_error($post_id) || empty($post_id) ) { throw new RuntimeException(__('Unable to save action.', 'action-scheduler')); @@ -93,7 +71,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { public function fetch_action( $action_id ) { $post = $this->get_post( $action_id ); - if ( empty($post) || $post->post_type != self::POST_TYPE || $post->post_status == 'trash' ) { + if ( empty($post) || $post->post_type != self::POST_TYPE ) { return $this->get_null_action(); } return $this->make_action_from_post($post); @@ -119,12 +97,59 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { } $group = wp_get_object_terms( $post->ID, self::GROUP_TAXONOMY, array('fields' => 'names') ); $group = empty( $group ) ? '' : reset($group); - if ( $post->post_status == 'pending' ) { - $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); - } else { - $action = new ActionScheduler_FinishedAction( $hook, $args, $schedule, $group ); + + return ActionScheduler::factory()->get_stored_action( $this->get_action_status_by_post_status( $post->post_status ), $hook, $args, $schedule, $group ); + } + + /** + * @param string $post_status + * + * @throws InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels() + * @return string + */ + protected function get_action_status_by_post_status( $post_status ) { + + switch ( $post_status ) { + case 'publish' : + $action_status = self::STATUS_COMPLETE; + break; + case 'trash' : + $action_status = self::STATUS_CANCELED; + break; + default : + if ( ! array_key_exists( $post_status, $this->get_status_labels() ) ) { + throw new InvalidArgumentException( sprintf( 'Invalid post status: "%s". No matching action status available.', $post_status ) ); + } + $action_status = $post_status; + break; } - return $action; + + return $action_status; + } + + /** + * @param string $action_status + * @throws InvalidArgumentException if $post_status not in known status fields returned by $this->get_status_labels() + * @return string + */ + protected function get_post_status_by_action_status( $action_status ) { + + switch ( $action_status ) { + case self::STATUS_COMPLETE : + $post_status = 'publish'; + break; + case self::STATUS_CANCELED : + $post_status = 'trash'; + break; + default : + if ( ! array_key_exists( $action_status, $this->get_status_labels() ) ) { + throw new InvalidArgumentException( sprintf( 'Invalid action status: "%s".', $action_status ) ); + } + $post_status = $action_status; + break; + } + + return $post_status; } /** @@ -157,23 +182,21 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { $query .= " AND p.post_content=%s"; $args[] = json_encode($params['args']); } + + if ( ! empty( $params['status'] ) ) { + $query .= " AND p.post_status=%s"; + $args[] = $this->get_post_status_by_action_status( $params['status'] ); + } + switch ( $params['status'] ) { case self::STATUS_COMPLETE: - $query .= " AND p.post_status='publish'"; + case self::STATUS_RUNNING: + case self::STATUS_FAILED: $order = 'DESC'; // Find the most recent action that matches break; case self::STATUS_PENDING: - $query .= " AND p.post_status='pending'"; - $order = 'ASC'; // Find the next action that matches - break; - case self::STATUS_RUNNING: - case self::STATUS_FAILED: - $query .= " AND p.post_status=%s"; - $args[] = $params['status']; - $order = 'DESC'; // Find the most recent action that matches - break; default: - $order = 'ASC'; + $order = 'ASC'; // Find the next action that matches break; } $query .= " ORDER BY post_date_gmt $order LIMIT 1"; @@ -185,10 +208,19 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { } /** - * @param array $query - * @return array The IDs of actions matching the query + * Returns the SQL statement to query (or count) actions. + * + * @param array $query Filtering options + * @param string $select_or_count Whether the SQL should select and return the IDs or just the row count + * @throws InvalidArgumentException if $select_or_count not count or select + * @return string SQL statement. The returned SQL is already properly escaped. */ - public function query_actions( $query = array() ) { + protected function get_query_actions_sql( array $query, $select_or_count = 'select' ) { + + if ( ! in_array( $select_or_count, array( 'select', 'count' ) ) ) { + throw new InvalidArgumentException(__('Invalid schedule. Cannot save action.', 'action-scheduler')); + } + $query = wp_parse_args( $query, array( 'hook' => '', 'args' => NULL, @@ -203,17 +235,23 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { 'offset' => 0, 'orderby' => 'date', 'order' => 'ASC', + 'search' => '', ) ); /** @var wpdb $wpdb */ global $wpdb; - $sql = "SELECT p.ID FROM {$wpdb->posts} p"; + $sql = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID '; + $sql .= "FROM {$wpdb->posts} p"; $sql_params = array(); - if ( !empty($query['group']) ) { + if ( ! empty( $query['group'] ) || 'group' === $query['orderby'] ) { $sql .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID"; $sql .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id"; - $sql .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id AND t.slug=%s"; - $sql_params[] = $query['group']; + $sql .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id"; + + if ( ! empty( $query['group'] ) ) { + $sql .= " AND t.slug=%s"; + $sql_params[] = $query['group']; + } } $sql .= " WHERE post_type=%s"; $sql_params[] = self::POST_TYPE; @@ -226,16 +264,9 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { $sql_params[] = json_encode($query['args']); } - switch ( $query['status'] ) { - case self::STATUS_COMPLETE: - $sql .= " AND p.post_status='publish'"; - break; - case self::STATUS_PENDING: - case self::STATUS_RUNNING: - case self::STATUS_FAILED: - $sql .= " AND p.post_status=%s"; - $sql_params[] = $query['status']; - break; + if ( ! empty( $query['status'] ) ) { + $sql .= " AND p.post_status=%s"; + $sql_params[] = $this->get_post_status_by_action_status( $query['status'] ); } if ( $query['date'] instanceof DateTime ) { @@ -265,51 +296,97 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { $sql_params[] = $query['claimed']; } - switch ( $query['orderby'] ) { - case 'hook': - $orderby = 'p.title'; - break; - case 'group': - $orderby = 't.name'; - break; - case 'modified': - $orderby = 'p.post_modified'; - break; - case 'date': - default: - $orderby = 'p.post_date_gmt'; - break; - } - if ( strtoupper($query['order']) == 'ASC' ) { - $order = 'ASC'; - } else { - $order = 'DESC'; - } - $sql .= " ORDER BY $orderby $order"; - if ( $query['per_page'] > 0 ) { - $sql .= " LIMIT %d, %d"; - $sql_params[] = $query['offset']; - $sql_params[] = $query['per_page']; + if ( ! empty( $query['search'] ) ) { + $sql .= " AND (p.post_title LIKE %s OR p.post_content LIKE %s OR p.post_password LIKE %s)"; + for( $i = 0; $i < 3; $i++ ) { + $sql_params[] = sprintf( '%%%s%%', $query['search'] ); + } } - $sql = $wpdb->prepare( $sql, $sql_params ); + if ( 'select' === $select_or_count ) { + switch ( $query['orderby'] ) { + case 'hook': + $orderby = 'p.post_title'; + break; + case 'group': + $orderby = 't.name'; + break; + case 'status': + $orderby = 'p.post_status'; + break; + case 'modified': + $orderby = 'p.post_modified'; + break; + case 'claim_id': + $orderby = 'p.post_password'; + break; + case 'schedule': + case 'date': + default: + $orderby = 'p.post_date_gmt'; + break; + } + if ( 'ASC' === strtoupper( $query['order'] ) ) { + $order = 'ASC'; + } else { + $order = 'DESC'; + } + $sql .= " ORDER BY $orderby $order"; + if ( $query['per_page'] > 0 ) { + $sql .= " LIMIT %d, %d"; + $sql_params[] = $query['offset']; + $sql_params[] = $query['per_page']; + } + } - $id = $wpdb->get_col($sql); - return $id; + return $wpdb->prepare( $sql, $sql_params ); } - private function validate_sql_comparator( $comp ) { - if ( in_array($comp, array('!=', '>', '>=', '<', '<=', '=')) ) { - return $comp; + /** + * @param array $query + * @param string $query_type Whether to select or count the results. Default, select. + * @return string|array The IDs of actions matching the query + */ + public function query_actions( $query = array(), $query_type = 'select' ) { + /** @var wpdb $wpdb */ + global $wpdb; + + $sql = $this->get_query_actions_sql( $query, $query_type ); + + return ( 'count' === $query_type ) ? $wpdb->get_var( $sql ) : $wpdb->get_col( $sql ); + } + + /** + * Get a count of all actions in the store, grouped by status + * + * @return array + */ + public function action_counts() { + + $action_counts_by_status = array(); + $action_stati_and_labels = $this->get_status_labels(); + $posts_count_by_status = (array) wp_count_posts( self::POST_TYPE, 'readable' ); + + foreach ( $posts_count_by_status as $post_status_name => $count ) { + + try { + $action_status_name = $this->get_action_status_by_post_status( $post_status_name ); + } catch ( Exception $e ) { + // Ignore any post statuses that aren't for actions + continue; + } + if ( array_key_exists( $action_status_name, $action_stati_and_labels ) ) { + $action_counts_by_status[ $action_status_name ] = $count; + } } - return '='; + + return $action_counts_by_status; } /** * @param string $action_id * * @throws InvalidArgumentException - * @return void */ public function cancel_action( $action_id ) { $post = get_post($action_id); @@ -359,15 +436,20 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { } /** - * @param int $max_actions + * @param int $max_actions * @param DateTime $before_date Jobs must be schedule before this date. Defaults to now. + * @param array $hooks Claim only actions with a hook or hooks. + * @param string $group Claim only actions in the given group. * * @return ActionScheduler_ActionClaim + * @throws RuntimeException When there is an error staking a claim. + * @throws InvalidArgumentException When the given group is not valid. */ - public function stake_claim( $max_actions = 10, DateTime $before_date = NULL ){ + public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) { $claim_id = $this->generate_claim_id(); - $this->claim_actions( $claim_id, $max_actions, $before_date ); + $this->claim_actions( $claim_id, $max_actions, $before_date, $hooks, $group ); $action_ids = $this->find_actions_by_claim_id( $claim_id ); + return new ActionScheduler_ActionClaim( $claim_id, $action_ids ); } @@ -389,25 +471,134 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { } /** - * @param string $claim_id - * @param int $limit + * @param string $claim_id + * @param int $limit * @param DateTime $before_date Should use UTC timezone. + * @param array $hooks Claim only actions with a hook or hooks. + * @param string $group Claim only actions in the given group. + * * @return int The number of actions that were claimed - * @throws RuntimeException + * @throws RuntimeException When there is a database error. + * @throws InvalidArgumentException When the group is invalid. */ - protected function claim_actions( $claim_id, $limit, DateTime $before_date = NULL ) { + protected function claim_actions( $claim_id, $limit, DateTime $before_date = null, $hooks = array(), $group = '' ) { + // Set up initial variables. + $date = null === $before_date ? as_get_datetime_object() : clone $before_date; + $limit_ids = ! empty( $group ); + $ids = $limit_ids ? $this->get_actions_by_group( $group, $limit, $date ) : array(); + + // If limiting by IDs and no posts found, then return early since we have nothing to update. + if ( $limit_ids && 0 === count( $ids ) ) { + return 0; + } + /** @var wpdb $wpdb */ global $wpdb; - $date = is_null($before_date) ? as_get_datetime_object() : clone $before_date; - // can't use $wpdb->update() because of the <= condition, using post_modified to take advantage of indexes - $sql = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s WHERE post_type = %s AND post_status = %s AND post_password = '' AND post_date_gmt <= %s ORDER BY menu_order ASC, post_date_gmt ASC LIMIT %d"; - $sql = $wpdb->prepare( $sql, array( $claim_id, current_time('mysql', true), current_time('mysql'), self::POST_TYPE, 'pending', $date->format('Y-m-d H:i:s'), $limit ) ); - $rows_affected = $wpdb->query($sql); - if ( $rows_affected === false ) { - throw new RuntimeException(__('Unable to claim actions. Database error.', 'action-scheduler')); + /* + * Build up custom query to update the affected posts. Parameters are built as a separate array + * to make it easier to identify where they are in the query. + * + * We can't use $wpdb->update() here because of the "ID IN ..." clause. + */ + $update = "UPDATE {$wpdb->posts} SET post_password = %s, post_modified_gmt = %s, post_modified = %s"; + $params = array( + $claim_id, + current_time( 'mysql', true ), + current_time( 'mysql' ), + ); + + // Build initial WHERE clause. + $where = "WHERE post_type = %s AND post_status = %s AND post_password = ''"; + $params[] = self::POST_TYPE; + $params[] = ActionScheduler_Store::STATUS_PENDING; + + if ( ! empty( $hooks ) ) { + $placeholders = array_fill( 0, count( $hooks ), '%s' ); + $where .= ' AND post_title IN (' . join( ', ', $placeholders ) . ')'; + $params = array_merge( $params, array_values( $hooks ) ); } - return (int)$rows_affected; + + /* + * Add the IDs to the WHERE clause. IDs not escaped because they came directly from a prior DB query. + * + * If we're not limiting by IDs, then include the post_date_gmt clause. + */ + if ( $limit_ids ) { + $where .= ' AND ID IN (' . join( ',', $ids ) . ')'; + } else { + $where .= ' AND post_date_gmt <= %s'; + $params[] = $date->format( 'Y-m-d H:i:s' ); + } + + // Add the ORDER BY clause and,ms limit. + $order = 'ORDER BY menu_order ASC, post_date_gmt ASC, ID ASC LIMIT %d'; + $params[] = $limit; + + // Run the query and gather results. + $rows_affected = $wpdb->query( $wpdb->prepare( "{$update} {$where} {$order}", $params ) ); + if ( $rows_affected === false ) { + throw new RuntimeException( __( 'Unable to claim actions. Database error.', 'action-scheduler' ) ); + } + + return (int) $rows_affected; + } + + /** + * Get IDs of actions within a certain group and up to a certain date/time. + * + * @param string $group The group to use in finding actions. + * @param int $limit The number of actions to retrieve. + * @param DateTime $date DateTime object representing cutoff time for actions. Actions retrieved will be + * up to and including this DateTime. + * + * @return array IDs of actions in the appropriate group and before the appropriate time. + * @throws InvalidArgumentException When the group does not exist. + */ + protected function get_actions_by_group( $group, $limit, DateTime $date ) { + // Ensure the group exists before continuing. + if ( ! term_exists( $group, self::GROUP_TAXONOMY )) { + throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'action-scheduler' ), $group ) ); + } + + // Set up a query for post IDs to use later. + $query = new WP_Query(); + $query_args = array( + 'fields' => 'ids', + 'post_type' => self::POST_TYPE, + 'post_status' => ActionScheduler_Store::STATUS_PENDING, + 'has_password' => false, + 'posts_per_page' => $limit * 3, + 'suppress_filters' => true, + 'no_found_rows' => true, + 'orderby' => array( + 'menu_order' => 'ASC', + 'date' => 'ASC', + 'ID' => 'ASC', + ), + 'date_query' => array( + 'column' => 'post_date', + array( + 'compare' => '<=', + 'year' => $date->format( 'Y' ), + 'month' => $date->format( 'n' ), + 'day' => $date->format( 'j' ), + 'hour' => $date->format( 'G' ), + 'minute' => $date->format( 'i' ), + 'second' => $date->format( 's' ), + ), + ), + 'tax_query' => array( + array( + 'taxonomy' => self::GROUP_TAXONOMY, + 'field' => 'slug', + 'terms' => $group, + 'include_children' => false, + ), + ), + ); + + return $query->query( $query_args ); } /** @@ -441,8 +632,6 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { /** * @param string $action_id - * - * @return void */ public function unclaim_action( $action_id ) { /** @var wpdb $wpdb */ @@ -467,9 +656,39 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { } /** - * @param string $action_id + * Return an action's claim ID, as stored in the post password column * - * @return void + * @param string $action_id + * @return mixed + */ + public function get_claim_id( $action_id ) { + return $this->get_post_column( $action_id, 'post_password' ); + } + + /** + * Return an action's status, as stored in the post status column + * + * @param string $action_id + * @return mixed + */ + public function get_status( $action_id ) { + $status = $this->get_post_column( $action_id, 'post_status' ); + + if ( $status === null ) { + throw new \InvalidArgumentException( __( 'Invalid action ID. No status found.', 'action-scheduler' ) ); + } + + return $this->get_action_status_by_post_status( $status ); + } + + private function get_post_column( $action_id, $column_name ) { + /** @var \wpdb $wpdb */ + global $wpdb; + return $wpdb->get_var( $wpdb->prepare( "SELECT {$column_name} FROM {$wpdb->posts} WHERE ID=%d AND post_type=%s", $action_id, self::POST_TYPE ) ); + } + + /** + * @param string $action_id */ public function log_execution( $action_id ) { /** @var wpdb $wpdb */ @@ -491,7 +710,7 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { 'ID' => $action_id, 'post_status' => 'publish', ), TRUE); - remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 ); + remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 ); if ( is_wp_error($result) ) { throw new RuntimeException($result->get_error_message()); } @@ -511,4 +730,3 @@ class ActionScheduler_wpPostStore extends ActionScheduler_Store { $taxonomy_registrar->register(); } } - \ No newline at end of file diff --git a/includes/libraries/action-scheduler/composer.json b/includes/libraries/action-scheduler/composer.json index 1eb77f7..fa07bc6 100755 --- a/includes/libraries/action-scheduler/composer.json +++ b/includes/libraries/action-scheduler/composer.json @@ -1,9 +1,12 @@ { "name": "prospress/action-scheduler", - "version": "1.5.3", + "version": "2.0.0", "description": "Action Scheduler for WordPress and WooCommerce", "type": "wordpress-plugin", "license": "GPL-3.0", "minimum-stability": "dev", - "require": {} + "require": {}, + "require-dev": { + "wp-cli/wp-cli": "^1.3" + } } diff --git a/includes/libraries/action-scheduler/composer.lock b/includes/libraries/action-scheduler/composer.lock new file mode 100755 index 0000000..de44d81 --- /dev/null +++ b/includes/libraries/action-scheduler/composer.lock @@ -0,0 +1,2909 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "f4556531e7b95173d1b769b3d7350926", + "packages": [], + "packages-dev": [ + { + "name": "composer/ca-bundle", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/composer/ca-bundle.git", + "reference": "b17e6153cb7f33c7e44eb59578dc12eee5dc8e12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/b17e6153cb7f33c7e44eb59578dc12eee5dc8e12", + "reference": "b17e6153cb7f33c7e44eb59578dc12eee5dc8e12", + "shasum": "" + }, + "require": { + "ext-openssl": "*", + "ext-pcre": "*", + "php": "^5.3.2 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5", + "psr/log": "^1.0", + "symfony/process": "^2.5 || ^3.0" + }, + "suggest": { + "symfony/process": "This is necessary to reliably check whether openssl_x509_parse is vulnerable on older php versions, but can be ignored on PHP 5.5.6+" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\CaBundle\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.", + "keywords": [ + "cabundle", + "cacert", + "certificate", + "ssl", + "tls" + ], + "time": "2017-03-06T11:59:08+00:00" + }, + { + "name": "composer/composer", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/composer/composer.git", + "reference": "82c27a68bc5cb76f3d00b82c27496e3cdbb6d4ff" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/composer/zipball/82c27a68bc5cb76f3d00b82c27496e3cdbb6d4ff", + "reference": "82c27a68bc5cb76f3d00b82c27496e3cdbb6d4ff", + "shasum": "" + }, + "require": { + "composer/ca-bundle": "^1.0", + "composer/semver": "^1.0", + "composer/spdx-licenses": "^1.0", + "justinrainbow/json-schema": "^3.0 || ^4.0 || ^5.0", + "php": "^5.3.2 || ^7.0", + "psr/log": "^1.0", + "seld/cli-prompt": "^1.0", + "seld/jsonlint": "^1.4", + "seld/phar-utils": "^1.0", + "symfony/console": "^2.7 || ^3.0", + "symfony/filesystem": "^2.7 || ^3.0", + "symfony/finder": "^2.7 || ^3.0", + "symfony/process": "^2.7 || ^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5 || ^5.0.5", + "phpunit/phpunit-mock-objects": "^2.3 || ^3.0" + }, + "suggest": { + "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages", + "ext-zip": "Enabling the zip extension allows you to unzip archives", + "ext-zlib": "Allow gzip compression of HTTP requests" + }, + "bin": [ + "bin/composer" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\": "src/Composer" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "Composer helps you declare, manage and install dependencies of PHP projects, ensuring you have the right stack everywhere.", + "homepage": "https://getcomposer.org/", + "keywords": [ + "autoload", + "dependency", + "package" + ], + "time": "2017-08-09T14:23:46+00:00" + }, + { + "name": "composer/semver", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "7ea669582e6396857cf6d1c0a6cd2728f4e7e383" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/7ea669582e6396857cf6d1c0a6cd2728f4e7e383", + "reference": "7ea669582e6396857cf6d1c0a6cd2728f4e7e383", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5 || ^5.0.5", + "phpunit/phpunit-mock-objects": "2.3.0 || ^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "time": "2017-05-15T12:49:06+00:00" + }, + { + "name": "composer/spdx-licenses", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/composer/spdx-licenses.git", + "reference": "2603a0d7ddc00a015deb576fa5297ca43dee6b1c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/2603a0d7ddc00a015deb576fa5297ca43dee6b1c", + "reference": "2603a0d7ddc00a015deb576fa5297ca43dee6b1c", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5 || ^5.0.5", + "phpunit/phpunit-mock-objects": "2.3.0 || ^3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Spdx\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "SPDX licenses list and validation library.", + "keywords": [ + "license", + "spdx", + "validator" + ], + "time": "2017-04-03T19:08:52+00:00" + }, + { + "name": "justinrainbow/json-schema", + "version": "5.x-dev", + "source": { + "type": "git", + "url": "https://github.com/justinrainbow/json-schema.git", + "reference": "36ed4d935f8f5eb958dbd29e1fa5a241ec3ece4d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/36ed4d935f8f5eb958dbd29e1fa5a241ec3ece4d", + "reference": "36ed4d935f8f5eb958dbd29e1fa5a241ec3ece4d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.1", + "json-schema/json-schema-test-suite": "1.2.0", + "phpunit/phpunit": "^4.8.22" + }, + "bin": [ + "bin/validate-json" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "JsonSchema\\": "src/JsonSchema/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bruno Prieto Reis", + "email": "bruno.p.reis@gmail.com" + }, + { + "name": "Justin Rainbow", + "email": "justin.rainbow@gmail.com" + }, + { + "name": "Igor Wiedler", + "email": "igor@wiedler.ch" + }, + { + "name": "Robert Schönthal", + "email": "seroscho@googlemail.com" + } + ], + "description": "A library to validate a json schema.", + "homepage": "https://github.com/justinrainbow/json-schema", + "keywords": [ + "json", + "schema" + ], + "time": "2017-06-23T11:43:36+00:00" + }, + { + "name": "mustache/mustache", + "version": "v2.12.0", + "source": { + "type": "git", + "url": "https://github.com/bobthecow/mustache.php.git", + "reference": "fe8fe72e9d580591854de404cc59a1b83ca4d19e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/fe8fe72e9d580591854de404cc59a1b83ca4d19e", + "reference": "fe8fe72e9d580591854de404cc59a1b83ca4d19e", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~1.11", + "phpunit/phpunit": "~3.7|~4.0|~5.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Mustache": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Justin Hileman", + "email": "justin@justinhileman.info", + "homepage": "http://justinhileman.com" + } + ], + "description": "A Mustache implementation in PHP.", + "homepage": "https://github.com/bobthecow/mustache.php", + "keywords": [ + "mustache", + "templating" + ], + "time": "2017-07-11T12:54:05+00:00" + }, + { + "name": "nb/oxymel", + "version": "v0.1.0", + "source": { + "type": "git", + "url": "https://github.com/nb/oxymel.git", + "reference": "cbe626ef55d5c4cc9b5e6e3904b395861ea76e3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nb/oxymel/zipball/cbe626ef55d5c4cc9b5e6e3904b395861ea76e3c", + "reference": "cbe626ef55d5c4cc9b5e6e3904b395861ea76e3c", + "shasum": "" + }, + "require": { + "php": ">=5.2.4" + }, + "type": "library", + "autoload": { + "psr-0": { + "Oxymel": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nikolay Bachiyski", + "email": "nb@nikolay.bg", + "homepage": "http://extrapolate.me/" + } + ], + "description": "A sweet XML builder", + "homepage": "https://github.com/nb/oxymel", + "keywords": [ + "xml" + ], + "time": "2013-02-24T15:01:54+00:00" + }, + { + "name": "psr/container", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "2cc4a01788191489dc7459446ba832fa79a216a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/2cc4a01788191489dc7459446ba832fa79a216a7", + "reference": "2cc4a01788191489dc7459446ba832fa79a216a7", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "time": "2017-06-28T15:35:32+00:00" + }, + { + "name": "psr/log", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, + { + "name": "ramsey/array_column", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/ramsey/array_column.git", + "reference": "f8e52eb28e67eb50e613b451dd916abcf783c1db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ramsey/array_column/zipball/f8e52eb28e67eb50e613b451dd916abcf783c1db", + "reference": "f8e52eb28e67eb50e613b451dd916abcf783c1db", + "shasum": "" + }, + "require-dev": { + "jakub-onderka/php-parallel-lint": "0.8.*", + "phpunit/phpunit": "~4.5", + "satooshi/php-coveralls": "0.6.*", + "squizlabs/php_codesniffer": "~2.2" + }, + "type": "library", + "autoload": { + "files": [ + "src/array_column.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ben Ramsey", + "homepage": "http://benramsey.com" + } + ], + "description": "Provides functionality for array_column() to projects using PHP earlier than version 5.5.", + "homepage": "https://github.com/ramsey/array_column", + "keywords": [ + "array", + "array_column", + "column" + ], + "time": "2015-03-20T22:07:39+00:00" + }, + { + "name": "rmccue/requests", + "version": "v1.7.0", + "source": { + "type": "git", + "url": "https://github.com/rmccue/Requests.git", + "reference": "87932f52ffad70504d93f04f15690cf16a089546" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rmccue/Requests/zipball/87932f52ffad70504d93f04f15690cf16a089546", + "reference": "87932f52ffad70504d93f04f15690cf16a089546", + "shasum": "" + }, + "require": { + "php": ">=5.2" + }, + "require-dev": { + "requests/test-server": "dev-master" + }, + "type": "library", + "autoload": { + "psr-0": { + "Requests": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "ISC" + ], + "authors": [ + { + "name": "Ryan McCue", + "homepage": "http://ryanmccue.info" + } + ], + "description": "A HTTP library written in PHP, for human beings.", + "homepage": "http://github.com/rmccue/Requests", + "keywords": [ + "curl", + "fsockopen", + "http", + "idna", + "ipv6", + "iri", + "sockets" + ], + "time": "2016-10-13T00:11:37+00:00" + }, + { + "name": "seld/cli-prompt", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/cli-prompt.git", + "reference": "a19a7376a4689d4d94cab66ab4f3c816019ba8dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/cli-prompt/zipball/a19a7376a4689d4d94cab66ab4f3c816019ba8dd", + "reference": "a19a7376a4689d4d94cab66ab4f3c816019ba8dd", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Seld\\CliPrompt\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + } + ], + "description": "Allows you to prompt for user input on the command line, and optionally hide the characters they type", + "keywords": [ + "cli", + "console", + "hidden", + "input", + "prompt" + ], + "time": "2017-03-18T11:32:45+00:00" + }, + { + "name": "seld/jsonlint", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/jsonlint.git", + "reference": "50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77", + "reference": "50d63f2858d87c4738d5b76a7dcbb99fa8cf7c77", + "shasum": "" + }, + "require": { + "php": "^5.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.5" + }, + "bin": [ + "bin/jsonlint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Seld\\JsonLint\\": "src/Seld/JsonLint/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "JSON Linter", + "keywords": [ + "json", + "linter", + "parser", + "validator" + ], + "time": "2017-06-18T15:11:04+00:00" + }, + { + "name": "seld/phar-utils", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/phar-utils.git", + "reference": "7009b5139491975ef6486545a39f3e6dad5ac30a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/phar-utils/zipball/7009b5139491975ef6486545a39f3e6dad5ac30a", + "reference": "7009b5139491975ef6486545a39f3e6dad5ac30a", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Seld\\PharUtils\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + } + ], + "description": "PHAR file format utilities, for when PHP phars you up", + "keywords": [ + "phra" + ], + "time": "2015-10-13T18:44:15+00:00" + }, + { + "name": "symfony/config", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/config.git", + "reference": "d668d8c0502d2b485c00d107db65fdbc56c26282" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/config/zipball/d668d8c0502d2b485c00d107db65fdbc56c26282", + "reference": "d668d8c0502d2b485c00d107db65fdbc56c26282", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/filesystem": "~2.8|~3.0|~4.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.3", + "symfony/finder": "<3.3" + }, + "require-dev": { + "symfony/dependency-injection": "~3.3|~4.0", + "symfony/finder": "~3.3|~4.0", + "symfony/yaml": "~3.0|~4.0" + }, + "suggest": { + "symfony/yaml": "To use the yaml reference dumper" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Config\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Config Component", + "homepage": "https://symfony.com", + "time": "2017-08-05T17:34:46+00:00" + }, + { + "name": "symfony/console", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "0e283478c2d68c9bf9cc52592ad1ef1834083a85" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/0e283478c2d68c9bf9cc52592ad1ef1834083a85", + "reference": "0e283478c2d68c9bf9cc52592ad1ef1834083a85", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.3", + "symfony/process": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3|~4.0", + "symfony/dependency-injection": "~3.3|~4.0", + "symfony/event-dispatcher": "~2.8|~3.0|~4.0", + "symfony/http-kernel": "~2.8|~3.0|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.3|~4.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2017-08-10T07:07:17+00:00" + }, + { + "name": "symfony/debug", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "50bda5b4b8641616d45254c6855bcd45f2f64187" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/50bda5b4b8641616d45254c6855bcd45f2f64187", + "reference": "50bda5b4b8641616d45254c6855bcd45f2f64187", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/http-kernel": "~2.8|~3.0|~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2017-08-10T07:07:17+00:00" + }, + { + "name": "symfony/dependency-injection", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/dependency-injection.git", + "reference": "aaee88765cb21a838e8da26d6acda4ca2ae3a2ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/aaee88765cb21a838e8da26d6acda4ca2ae3a2ea", + "reference": "aaee88765cb21a838e8da26d6acda4ca2ae3a2ea", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "psr/container": "^1.0" + }, + "conflict": { + "symfony/config": "<3.3.1", + "symfony/finder": "<3.3", + "symfony/proxy-manager-bridge": "<3.4", + "symfony/yaml": "<3.4" + }, + "provide": { + "psr/container-implementation": "1.0" + }, + "require-dev": { + "symfony/config": "~3.3|~4.0", + "symfony/expression-language": "~2.8|~3.0|~4.0", + "symfony/yaml": "~3.4|~4.0" + }, + "suggest": { + "symfony/config": "", + "symfony/expression-language": "For using expressions in service container configuration", + "symfony/finder": "For using double-star glob patterns or when GLOB_BRACE portability is required", + "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\DependencyInjection\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "https://symfony.com", + "time": "2017-08-10T19:43:00+00:00" + }, + { + "name": "symfony/event-dispatcher", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "cd8b015f859e6b60933324db00067c2f060b4d18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/cd8b015f859e6b60933324db00067c2f060b4d18", + "reference": "cd8b015f859e6b60933324db00067c2f060b4d18", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "conflict": { + "symfony/dependency-injection": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0|~4.0", + "symfony/dependency-injection": "~3.3|~4.0", + "symfony/expression-language": "~2.8|~3.0|~4.0", + "symfony/stopwatch": "~2.8|~3.0|~4.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2017-08-03T09:34:20+00:00" + }, + { + "name": "symfony/filesystem", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "e4d366b620c8b6e2d4977c154f6a1d5b416db4dd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/e4d366b620c8b6e2d4977c154f6a1d5b416db4dd", + "reference": "e4d366b620c8b6e2d4977c154f6a1d5b416db4dd", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2017-08-03T09:34:20+00:00" + }, + { + "name": "symfony/finder", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "bf0450cfe7282c5f06539c4733ba64273e91e918" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/bf0450cfe7282c5f06539c4733ba64273e91e918", + "reference": "bf0450cfe7282c5f06539c4733ba64273e91e918", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2017-08-03T09:34:20+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-14T15:44:48+00:00" + }, + { + "name": "symfony/process", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "9794f948d9af3be0157185051275d78b24d68b92" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/9794f948d9af3be0157185051275d78b24d68b92", + "reference": "9794f948d9af3be0157185051275d78b24d68b92", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2017-08-03T09:34:20+00:00" + }, + { + "name": "symfony/translation", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/translation.git", + "reference": "62bb068e004874bbe39624101e1aae70ca7c05cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/translation/zipball/62bb068e004874bbe39624101e1aae70ca7c05cd", + "reference": "62bb068e004874bbe39624101e1aae70ca7c05cd", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/config": "<2.8", + "symfony/dependency-injection": "<3.4", + "symfony/yaml": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~2.8|~3.0|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/intl": "^2.8.18|^3.2.5|~4.0", + "symfony/yaml": "~3.3|~4.0" + }, + "suggest": { + "psr/log": "To use logging capability in translator", + "symfony/config": "", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Translation\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Translation Component", + "homepage": "https://symfony.com", + "time": "2017-08-03T12:04:31+00:00" + }, + { + "name": "symfony/yaml", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "1395ddba6f65bf46cdf1d80d59223cbab8ff3ccc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/1395ddba6f65bf46cdf1d80d59223cbab8ff3ccc", + "reference": "1395ddba6f65bf46cdf1d80d59223cbab8ff3ccc", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "require-dev": { + "symfony/console": "~2.8|~3.0|~4.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2017-08-04T13:29:48+00:00" + }, + { + "name": "wp-cli/autoload-splitter", + "version": "v0.1.5", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/autoload-splitter.git", + "reference": "fb4302da26390811d2631c62b42b75976d224bb8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/autoload-splitter/zipball/fb4302da26390811d2631c62b42b75976d224bb8", + "reference": "fb4302da26390811d2631c62b42b75976d224bb8", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.1" + }, + "type": "composer-plugin", + "extra": { + "class": "WP_CLI\\AutoloadSplitter\\ComposerPlugin" + }, + "autoload": { + "psr-4": { + "WP_CLI\\AutoloadSplitter\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Alain Schlesser", + "email": "alain.schlesser@gmail.com", + "homepage": "https://www.alainschlesser.com" + } + ], + "description": "Composer plugin for splitting a generated autoloader into two distinct parts.", + "homepage": "https://wp-cli.org", + "time": "2017-08-03T08:40:16+00:00" + }, + { + "name": "wp-cli/cache-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/cache-command.git", + "reference": "485f7cc6630ecabe22bbf9fa9e827958e95a2d21" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/cache-command/zipball/485f7cc6630ecabe22bbf9fa9e827958e95a2d21", + "reference": "485f7cc6630ecabe22bbf9fa9e827958e95a2d21", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "cache", + "transient" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "cache-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage object and transient caches.", + "homepage": "https://github.com/wp-cli/cache-command", + "time": "2017-08-04T11:37:19+00:00" + }, + { + "name": "wp-cli/checksum-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/checksum-command.git", + "reference": "88ccde2e82de5c2232842a9fccc2e6ade232dec6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/checksum-command/zipball/88ccde2e82de5c2232842a9fccc2e6ade232dec6", + "reference": "88ccde2e82de5c2232842a9fccc2e6ade232dec6", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "checksum core" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "checksum-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Verify WordPress core checksums.", + "homepage": "https://github.com/wp-cli/checksum-command", + "time": "2017-08-09T23:34:29+00:00" + }, + { + "name": "wp-cli/config-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/config-command.git", + "reference": "ca83ade8fb2d059b561744610947e38123b10c22" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/config-command/zipball/ca83ade8fb2d059b561744610947e38123b10c22", + "reference": "ca83ade8fb2d059b561744610947e38123b10c22", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "config", + "config create", + "config get", + "config path" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "config-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage the wp-config.php file.", + "homepage": "https://github.com/wp-cli/config-command", + "time": "2017-08-04T23:41:35+00:00" + }, + { + "name": "wp-cli/core-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/core-command.git", + "reference": "fb743dab792e21b57163c5c0f563987d1471c152" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/core-command/zipball/fb743dab792e21b57163c5c0f563987d1471c152", + "reference": "fb743dab792e21b57163c5c0f563987d1471c152", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "core check-update", + "core download", + "core install", + "core is-installed", + "core multisite-convert", + "core multisite-install", + "core update", + "core update-db", + "core version" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "core-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Download, install, update and manage a WordPress install.", + "homepage": "https://github.com/wp-cli/core-command", + "time": "2017-08-04T12:31:18+00:00" + }, + { + "name": "wp-cli/cron-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/cron-command.git", + "reference": "92114b695ab0253bb705d9bd3e6d2fb47b51fad2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/cron-command/zipball/92114b695ab0253bb705d9bd3e6d2fb47b51fad2", + "reference": "92114b695ab0253bb705d9bd3e6d2fb47b51fad2", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "cron test", + "cron event delete", + "cron event list", + "cron event run", + "cron event schedule", + "cron schedule list" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "cron-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage WP-Cron events and schedules.", + "homepage": "https://github.com/wp-cli/cron-command", + "time": "2017-08-04T12:45:50+00:00" + }, + { + "name": "wp-cli/db-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/db-command.git", + "reference": "5c597abb642bcaf329e7da0801c69f4405d41c23" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/db-command/zipball/5c597abb642bcaf329e7da0801c69f4405d41c23", + "reference": "5c597abb642bcaf329e7da0801c69f4405d41c23", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "db create", + "db drop", + "db reset", + "db check", + "db optimize", + "db prefix", + "db repair", + "db cli", + "db query", + "db export", + "db import", + "db search", + "db tables", + "db size" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "db-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Perform basic database operations using credentials stored in wp-config.php.", + "homepage": "https://github.com/wp-cli/db-command", + "time": "2017-08-04T23:21:46+00:00" + }, + { + "name": "wp-cli/entity-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/entity-command.git", + "reference": "d0cd99c14e4d01aad368328da97231df0c01f9dc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/entity-command/zipball/d0cd99c14e4d01aad368328da97231df0c01f9dc", + "reference": "d0cd99c14e4d01aad368328da97231df0c01f9dc", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "phpunit/phpunit": "^4.8", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "comment", + "comment meta", + "menu", + "menu item", + "menu location", + "network meta", + "option", + "option add", + "option delete", + "option get", + "option list", + "option update", + "post", + "post meta", + "post term", + "post-type", + "site", + "taxonomy", + "term", + "term meta", + "user", + "user meta", + "user term" + ] + }, + "autoload": { + "psr-4": { + "": "src/", + "WP_CLI\\": "src/WP_CLI" + }, + "files": [ + "entity-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage WordPress core entities.", + "homepage": "https://github.com/wp-cli/entity-command", + "time": "2017-08-11T11:53:04+00:00" + }, + { + "name": "wp-cli/eval-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/eval-command.git", + "reference": "e3d9502a4f8b8f582130dbb3b8ede76e17ac05a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/eval-command/zipball/e3d9502a4f8b8f582130dbb3b8ede76e17ac05a4", + "reference": "e3d9502a4f8b8f582130dbb3b8ede76e17ac05a4", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "eval", + "eval-file" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "eval-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Execute arbitrary PHP code.", + "homepage": "https://github.com/wp-cli/eval-command", + "time": "2017-08-04T12:46:58+00:00" + }, + { + "name": "wp-cli/export-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/export-command.git", + "reference": "f5647155830d1275de4cb69cfb79748b9449b8ab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/export-command/zipball/f5647155830d1275de4cb69cfb79748b9449b8ab", + "reference": "f5647155830d1275de4cb69cfb79748b9449b8ab", + "shasum": "" + }, + "require": { + "nb/oxymel": "~0.1.0", + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "export" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "export-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Export WordPress content to a WXR file.", + "homepage": "https://github.com/wp-cli/export-command", + "time": "2017-08-04T13:13:08+00:00" + }, + { + "name": "wp-cli/extension-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/extension-command.git", + "reference": "08bf48e842b9e1cb579b50cec1b6897cebf65bda" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/extension-command/zipball/08bf48e842b9e1cb579b50cec1b6897cebf65bda", + "reference": "08bf48e842b9e1cb579b50cec1b6897cebf65bda", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "plugin activate", + "plugin deactivate", + "plugin delete", + "plugin get", + "plugin install", + "plugin is-installed", + "plugin list", + "plugin path", + "plugin search", + "plugin status", + "plugin toggle", + "plugin uninstall", + "plugin update", + "theme activate", + "theme delete", + "theme disable", + "theme enable", + "theme get", + "theme install", + "theme is-installed", + "theme list", + "theme mod get", + "theme mod set", + "theme mod remove", + "theme path", + "theme search", + "theme status", + "theme update" + ] + }, + "autoload": { + "psr-4": { + "": "src/", + "WP_CLI\\": "src/WP_CLI" + }, + "files": [ + "extension-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage WordPress plugins and themes.", + "homepage": "https://github.com/wp-cli/extension-command", + "time": "2017-08-04T13:43:53+00:00" + }, + { + "name": "wp-cli/import-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/import-command.git", + "reference": "89d14aa4b8b621effbe7f9bacad2ea8a096598a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/import-command/zipball/89d14aa4b8b621effbe7f9bacad2ea8a096598a7", + "reference": "89d14aa4b8b621effbe7f9bacad2ea8a096598a7", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "bundled": true, + "commands": [ + "import" + ] + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "import-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Import content from a WXR file.", + "homepage": "https://github.com/wp-cli/import-command", + "time": "2017-08-04T13:45:57+00:00" + }, + { + "name": "wp-cli/language-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/language-command.git", + "reference": "aff3fb6c6d7698008c7e5d33a97b25457091ae1b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/language-command/zipball/aff3fb6c6d7698008c7e5d33a97b25457091ae1b", + "reference": "aff3fb6c6d7698008c7e5d33a97b25457091ae1b", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "language core activate", + "language core install", + "language core list", + "language core uninstall", + "language core update" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "language-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage language packs.", + "homepage": "https://github.com/wp-cli/language-command", + "time": "2017-08-04T23:23:03+00:00" + }, + { + "name": "wp-cli/media-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/media-command.git", + "reference": "4a19de54a11c96b21c10719e2b7f9dd131c4261e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/media-command/zipball/4a19de54a11c96b21c10719e2b7f9dd131c4261e", + "reference": "4a19de54a11c96b21c10719e2b7f9dd131c4261e", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "media import", + "media regenerate" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "media-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Import new attachments or regenerate existing ones.", + "homepage": "https://github.com/wp-cli/media-command", + "time": "2017-08-05T04:54:48+00:00" + }, + { + "name": "wp-cli/mustangostang-spyc", + "version": "0.6.3", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/spyc.git", + "reference": "6aa0b4da69ce9e9a2c8402dab8d43cf32c581cc7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/spyc/zipball/6aa0b4da69ce9e9a2c8402dab8d43cf32c581cc7", + "reference": "6aa0b4da69ce9e9a2c8402dab8d43cf32c581cc7", + "shasum": "" + }, + "require": { + "php": ">=5.3.1" + }, + "require-dev": { + "phpunit/phpunit": "4.3.*@dev" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Mustangostang\\": "src/" + }, + "files": [ + "includes/functions.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "mustangostang", + "email": "vlad.andersen@gmail.com" + } + ], + "description": "A simple YAML loader/dumper class for PHP (WP-CLI fork)", + "homepage": "https://github.com/mustangostang/spyc/", + "time": "2017-04-25T11:26:20+00:00" + }, + { + "name": "wp-cli/package-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/package-command.git", + "reference": "744692180a4240ddc75a3196934cafe396dd9178" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/package-command/zipball/744692180a4240ddc75a3196934cafe396dd9178", + "reference": "744692180a4240ddc75a3196934cafe396dd9178", + "shasum": "" + }, + "require": { + "composer/composer": "^1.2.0", + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "package browse", + "package install", + "package list", + "package update", + "package uninstall" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "package-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage WP-CLI packages.", + "homepage": "https://github.com/wp-cli/package-command", + "time": "2017-08-07T12:21:11+00:00" + }, + { + "name": "wp-cli/php-cli-tools", + "version": "v0.11.6", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/php-cli-tools.git", + "reference": "d2a4e2eca9f1cd62a5d30f192d10f74e73eb3a05" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/d2a4e2eca9f1cd62a5d30f192d10f74e73eb3a05", + "reference": "d2a4e2eca9f1cd62a5d30f192d10f74e73eb3a05", + "shasum": "" + }, + "require": { + "php": ">= 5.3.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "cli": "lib/" + }, + "files": [ + "lib/cli/cli.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "James Logsdon", + "email": "jlogsdon@php.net", + "role": "Developer" + }, + { + "name": "Daniel Bachhuber", + "email": "daniel@handbuilt.co", + "role": "Maintainer" + } + ], + "description": "Console utilities for PHP", + "homepage": "http://github.com/wp-cli/php-cli-tools", + "keywords": [ + "cli", + "console" + ], + "time": "2017-08-04T10:42:04+00:00" + }, + { + "name": "wp-cli/rewrite-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/rewrite-command.git", + "reference": "e858feac8d3fe053e052d8af43c090ff0b2a4e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/rewrite-command/zipball/e858feac8d3fe053e052d8af43c090ff0b2a4e8a", + "reference": "e858feac8d3fe053e052d8af43c090ff0b2a4e8a", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "rewrite flush", + "rewrite list", + "rewrite structure" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "rewrite-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage rewrite rules.", + "homepage": "https://github.com/wp-cli/rewrite-command", + "time": "2017-08-04T15:15:53+00:00" + }, + { + "name": "wp-cli/role-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/role-command.git", + "reference": "85ddf53525b14ab040830f385710f4493058d295" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/role-command/zipball/85ddf53525b14ab040830f385710f4493058d295", + "reference": "85ddf53525b14ab040830f385710f4493058d295", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "role create", + "role delete", + "role exists", + "role list", + "role reset", + "cap add", + "cap list", + "cap remove" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "role-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage user roles and capabilities.", + "homepage": "https://github.com/wp-cli/role-command", + "time": "2017-08-04T15:17:29+00:00" + }, + { + "name": "wp-cli/scaffold-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/scaffold-command.git", + "reference": "41f1e1aa41af76b70d6cf3d21d52995e854acf4c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/scaffold-command/zipball/41f1e1aa41af76b70d6cf3d21d52995e854acf4c", + "reference": "41f1e1aa41af76b70d6cf3d21d52995e854acf4c", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "scaffold", + "scaffold _s", + "scaffold child-theme", + "scaffold plugin", + "scaffold plugin-tests", + "scaffold post-type", + "scaffold taxonomy", + "scaffold theme-tests" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "scaffold-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Generate code for post types, taxonomies, plugins, child themes, etc.", + "homepage": "https://github.com/wp-cli/scaffold-command", + "time": "2017-08-11T08:07:10+00:00" + }, + { + "name": "wp-cli/search-replace-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/search-replace-command.git", + "reference": "3e7499a65354e3a322d4d1043123b3fa55ef4f12" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/search-replace-command/zipball/3e7499a65354e3a322d4d1043123b3fa55ef4f12", + "reference": "3e7499a65354e3a322d4d1043123b3fa55ef4f12", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "search-replace" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/", + "WP_CLI\\": "src/WP_CLI" + }, + "files": [ + "search-replace-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Search/replace strings in the database.", + "homepage": "https://github.com/wp-cli/search-replace-command", + "time": "2017-08-08T16:41:49+00:00" + }, + { + "name": "wp-cli/server-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/server-command.git", + "reference": "ce93df07c33e716adbbd2d329c311a3c1dd3a0b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/server-command/zipball/ce93df07c33e716adbbd2d329c311a3c1dd3a0b0", + "reference": "ce93df07c33e716adbbd2d329c311a3c1dd3a0b0", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "server" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "server-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Launch PHP's built-in web server for this specific WordPress installation.", + "homepage": "https://github.com/wp-cli/server-command", + "time": "2017-08-04T15:19:26+00:00" + }, + { + "name": "wp-cli/shell-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/shell-command.git", + "reference": "70681666302cc193a1bd41bade9ecc61e74a8c83" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/shell-command/zipball/70681666302cc193a1bd41bade9ecc61e74a8c83", + "reference": "70681666302cc193a1bd41bade9ecc61e74a8c83", + "shasum": "" + }, + "require": { + "wp-cli/wp-cli": "*" + }, + "require-dev": { + "behat/behat": "~2.5" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "shell" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/", + "WP_CLI\\": "src/WP_CLI" + }, + "files": [ + "shell-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Interactive PHP console.", + "homepage": "https://github.com/wp-cli/shell-command", + "time": "2017-08-04T15:21:52+00:00" + }, + { + "name": "wp-cli/super-admin-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/super-admin-command.git", + "reference": "b650836d13762c764df2bbe70ad34212c0b773cd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/super-admin-command/zipball/b650836d13762c764df2bbe70ad34212c0b773cd", + "reference": "b650836d13762c764df2bbe70ad34212c0b773cd", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "super-admin add", + "super-admin list", + "super-admin remove" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "super-admin-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage super admins on WordPress multisite.", + "homepage": "https://github.com/wp-cli/super-admin-command", + "time": "2017-08-04T15:45:41+00:00" + }, + { + "name": "wp-cli/widget-command", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/widget-command.git", + "reference": "727af7c7b661031bc8c04ad176d4f24b862e3402" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/widget-command/zipball/727af7c7b661031bc8c04ad176d4f24b862e3402", + "reference": "727af7c7b661031bc8c04ad176d4f24b862e3402", + "shasum": "" + }, + "require-dev": { + "behat/behat": "~2.5", + "wp-cli/wp-cli": "*" + }, + "type": "wp-cli-package", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + }, + "commands": [ + "widget add", + "widget deactivate", + "widget delete", + "widget list", + "widget move", + "widget reset", + "widget update", + "sidebar list" + ], + "bundled": true + }, + "autoload": { + "psr-4": { + "": "src/" + }, + "files": [ + "widget-command.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Bachhuber", + "email": "daniel@runcommand.io", + "homepage": "https://runcommand.io" + } + ], + "description": "Manage widgets and sidebars.", + "homepage": "https://github.com/wp-cli/widget-command", + "time": "2017-08-04T15:24:29+00:00" + }, + { + "name": "wp-cli/wp-cli", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/wp-cli/wp-cli.git", + "reference": "4ab0d99da0ad5e6ca39453ff5c82d4f06aecb086" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/4ab0d99da0ad5e6ca39453ff5c82d4f06aecb086", + "reference": "4ab0d99da0ad5e6ca39453ff5c82d4f06aecb086", + "shasum": "" + }, + "require": { + "composer/composer": "^1.2.0", + "composer/semver": "~1.0", + "mustache/mustache": "~2.4", + "php": ">=5.3.29", + "ramsey/array_column": "~1.1", + "rmccue/requests": "~1.6", + "symfony/config": "^2.7|^3.0", + "symfony/console": "^2.7|^3.0", + "symfony/debug": "^2.7|^3.0", + "symfony/dependency-injection": "^2.7|^3.0", + "symfony/event-dispatcher": "^2.7|^3.0", + "symfony/filesystem": "^2.7|^3.0", + "symfony/finder": "^2.7|^3.0", + "symfony/process": "^2.1|^3.0", + "symfony/translation": "^2.7|^3.0", + "symfony/yaml": "^2.7|^3.0", + "wp-cli/autoload-splitter": "^0.1.5", + "wp-cli/cache-command": "^1.0", + "wp-cli/checksum-command": "^1.0", + "wp-cli/config-command": "^1.0", + "wp-cli/core-command": "^1.0", + "wp-cli/cron-command": "^1.0", + "wp-cli/db-command": "^1.0", + "wp-cli/entity-command": "^1.0", + "wp-cli/eval-command": "^1.0", + "wp-cli/export-command": "^1.0", + "wp-cli/extension-command": "^1.0", + "wp-cli/import-command": "^1.0", + "wp-cli/language-command": "^1.0", + "wp-cli/media-command": "^1.0", + "wp-cli/mustangostang-spyc": "^0.6.3", + "wp-cli/package-command": "^1.0", + "wp-cli/php-cli-tools": "~0.11.2", + "wp-cli/rewrite-command": "^1.0", + "wp-cli/role-command": "^1.0", + "wp-cli/scaffold-command": "^1.0", + "wp-cli/search-replace-command": "^1.0", + "wp-cli/server-command": "^1.0", + "wp-cli/shell-command": "^1.0", + "wp-cli/super-admin-command": "^1.0", + "wp-cli/widget-command": "^1.0" + }, + "require-dev": { + "behat/behat": "2.5.*", + "phpunit/phpunit": "3.7.*", + "roave/security-advisories": "dev-master" + }, + "suggest": { + "psy/psysh": "Enhanced `wp shell` functionality" + }, + "bin": [ + "bin/wp.bat", + "bin/wp" + ], + "type": "library", + "extra": { + "autoload-splitter": { + "splitter-logic": "WP_CLI\\AutoloadSplitter", + "splitter-location": "php/WP_CLI/AutoloadSplitter.php", + "split-target-prefix-true": "autoload_commands", + "split-target-prefix-false": "autoload_framework" + } + }, + "autoload": { + "psr-0": { + "WP_CLI": "php" + }, + "psr-4": { + "": "php/commands/src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A command line interface for WordPress", + "homepage": "http://wp-cli.org", + "keywords": [ + "cli", + "wordpress" + ], + "time": "2017-08-08T14:28:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/includes/libraries/action-scheduler/functions.php b/includes/libraries/action-scheduler/functions.php index feb8f02..567ba68 100755 --- a/includes/libraries/action-scheduler/functions.php +++ b/includes/libraries/action-scheduler/functions.php @@ -64,8 +64,6 @@ function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), * @param string $hook The hook that the job will trigger * @param array $args Args that would have been passed to the job * @param string $group - * - * @return void */ function wc_unschedule_action( $hook, $args = array(), $group = '' ) { $params = array(); @@ -174,15 +172,15 @@ function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { * @param mixed $date_string A date/time string. Valid formats are explained in http://php.net/manual/en/datetime.formats.php * @param string $timezone A timezone identifier, like UTC or Europe/Lisbon. The list of valid identifiers is available http://php.net/manual/en/timezones.php * - * @return DateTime + * @return ActionScheduler_DateTime */ function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) { - if ( is_object($date_string) && $date_string instanceof DateTime ) { - $date = $date_string->setTimezone(new DateTimeZone( $timezone ) ); + if ( is_object( $date_string ) && $date_string instanceof DateTime ) { + $date = new ActionScheduler_DateTime( $date_string->format( 'Y-m-d H:i:s' ), new DateTimeZone( $timezone ) ); } elseif ( is_numeric( $date_string ) ) { - $date = new DateTime( '@'.$date_string, new DateTimeZone( $timezone ) ); + $date = new ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) ); } else { - $date = new DateTime( $date_string, new DateTimeZone( $timezone ) ); + $date = new ActionScheduler_DateTime( $date_string, new DateTimeZone( $timezone ) ); } return $date; } diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php index 43443ff..7f33c37 100755 --- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php +++ b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php @@ -240,10 +240,10 @@ class CronExpression $currentTime = new DateTime($currentTime); $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0); $currentDate = $currentTime->format('Y-m-d H:i'); - $currentTime = (int)($currentTime->format('U')); + $currentTime = (int)($currentTime->getTimestamp()); } - return $this->getNextRunDate($currentDate, 0, true)->format('U') == $currentTime; + return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime; } /** diff --git a/includes/libraries/action-scheduler/license.txt b/includes/libraries/action-scheduler/license.txt new file mode 100755 index 0000000..20d40b6 --- /dev/null +++ b/includes/libraries/action-scheduler/license.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/includes/libraries/tlc-transients/LICENSE b/includes/libraries/tlc-transients/LICENSE deleted file mode 100755 index ecbc059..0000000 --- a/includes/libraries/tlc-transients/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. \ No newline at end of file diff --git a/includes/libraries/tlc-transients/class-tlc-transient-update-server.php b/includes/libraries/tlc-transients/class-tlc-transient-update-server.php deleted file mode 100755 index a6bc93a..0000000 --- a/includes/libraries/tlc-transients/class-tlc-transient-update-server.php +++ /dev/null @@ -1,25 +0,0 @@ -expires_in( $update[2] ) - ->extend_on_fail( $update[5] ) - ->updates_with( $update[3], (array) $update[4] ) - ->set_lock( $update[0] ) - ->fetch_and_cache(); - } - exit(); - } - } -} \ No newline at end of file diff --git a/includes/libraries/tlc-transients/class-tlc-transient.php b/includes/libraries/tlc-transients/class-tlc-transient.php deleted file mode 100755 index efba218..0000000 --- a/includes/libraries/tlc-transients/class-tlc-transient.php +++ /dev/null @@ -1,146 +0,0 @@ -raw_key = $key; - $this->key = md5( $key ); - } - - public function get() { - $data = $this->raw_get(); - if ( false === $data ) { - // Hard expiration - if ( $this->force_background_updates ) { - // In this mode, we never do a just-in-time update - // We return false, and schedule a fetch on shutdown - $this->schedule_background_fetch(); - return false; - } - else { - // Bill O'Reilly mode: "We'll do it live!" - return $this->fetch_and_cache(); - } - } - else { - // Soft expiration - if ( $data[0] !== 0 && $data[0] < time() ) - $this->schedule_background_fetch(); - return $data[1]; - } - } - - private function raw_get() { - return get_transient( 'tlc__' . $this->key ); - } - - private function schedule_background_fetch() { - if ( ! $this->has_update_lock() ) { - set_transient( 'tlc_up__' . $this->key, array( $this->new_update_lock(), $this->raw_key, $this->expiration, $this->callback, $this->params, $this->extend_on_fail ), 300 ); - add_action( 'shutdown', array( $this, 'spawn_server' ) ); - } - return $this; - } - - private function has_update_lock() { - return (bool) $this->get_update_lock(); - } - - private function get_update_lock() { - $lock = get_transient( 'tlc_up__' . $this->key ); - if ( $lock ) - return $lock[0]; - else - return false; - } - - private function new_update_lock() { - $this->lock = uniqid( 'tlc_lock_', true ); - return $this->lock; - } - - public function fetch_and_cache() { - // If you don't supply a callback, we can't update it for you! - if ( empty( $this->callback ) ) - return false; - if ( $this->has_update_lock() && ! $this->owns_update_lock() ) - return; // Race... let the other process handle it - try { - $data = call_user_func_array( $this->callback, $this->params ); - $this->set( $data ); - } catch ( Exception $e ) { - if ( $this->extend_on_fail > 0 ) { - $data = $this->raw_get(); - if ( $data ) { - $data = $data[1]; - $old_expiration = $this->expiration; - $this->expiration = $this->extend_on_fail; - $this->set( $data ); - $this->expiration = $old_expiration; - } - } - else { - $data = false; - } - } - $this->release_update_lock(); - return $data; - } - - private function owns_update_lock() { - return $this->lock == $this->get_update_lock(); - } - - public function set( $data ) { - // We set the timeout as part of the transient data. - // The actual transient has a far-future TTL. This allows for soft expiration. - $expiration = ( $this->expiration > 0 ) ? time() + $this->expiration : 0; - $transient_expiration = ( $this->expiration > 0 ) ? $this->expiration + 31536000 : 0; // 31536000 = 60*60*24*365 ~= one year - set_transient( 'tlc__' . $this->key, array( $expiration, $data ), $transient_expiration ); - return $this; - } - - private function release_update_lock() { - delete_transient( 'tlc_up__' . $this->key ); - } - - public function spawn_server() { - $server_url = home_url( '/?tlc_transients_request' ); - wp_remote_post( $server_url, array( 'body' => array( '_tlc_update' => $this->lock, 'key' => $this->raw_key ), 'timeout' => 0.01, 'blocking' => false, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ) ) ); - } - - public function updates_with( $callback, $params = array() ) { - $this->callback = $callback; - if ( is_array( $params ) ) - $this->params = $params; - return $this; - } - - public function expires_in( $seconds ) { - $this->expiration = (int) $seconds; - return $this; - } - - public function extend_on_fail( $seconds ) { - $this->extend_on_fail = (int) $seconds; - return $this; - } - - public function set_lock( $lock ) { - $this->lock = $lock; - return $this; - } - - public function background_only() { - $this->force_background_updates = true; - return $this; - } -} \ No newline at end of file diff --git a/includes/libraries/tlc-transients/composer.json b/includes/libraries/tlc-transients/composer.json deleted file mode 100755 index c153d91..0000000 --- a/includes/libraries/tlc-transients/composer.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name" : "markjaquith/wp-tlc-transients", - "description": "A WP transients interface with support for soft-expiration, background updating of the transients.", - "keywords" : ["wordpress", "cache"], - "homepage" : "https://github.com/markjaquith/WP-TLC-Transients", - "license" : "GPL-2.0+", - "authors" : [ - { - "name" : "Mark Jaquith", - "homepage": "http://markjaquith.com/" - } - ], - "support" : { - "issues": "https://github.com/markjaquith/WP-TLC-Transients/issues", - "source": "https://github.com/markjaquith/WP-TLC-Transients" - }, - "autoload" : { - "classmap": ["class-tlc-transient.php", "class-tlc-transient-update-server.php"], - "files" : ["functions.php"] - } -} \ No newline at end of file diff --git a/includes/libraries/tlc-transients/functions.php b/includes/libraries/tlc-transients/functions.php deleted file mode 100755 index eaff4e4..0000000 --- a/includes/libraries/tlc-transients/functions.php +++ /dev/null @@ -1,9 +0,0 @@ - 30 ) ) ); - $f .= $append; - return $f; -} - -function test_tlc_transient() { - $t = tlc_transient( 'foo' ) - ->expires_in( 30 ) - ->background_only() - ->updates_with( 'sample_fetch_and_append', array( 'http://coveredwebservices.com/tools/long-running-request.php', ' appendfooparam ' ) ) - ->get(); - var_dump( $t ); - if ( !$t ) - echo "The request is false, because it isn't yet in the cache. It'll be there in about 10 seconds. Keep refreshing!"; -} - -add_action( 'wp_footer', 'test_tlc_transient' ); -*/ diff --git a/includes/payment-retry/class-wcs-retry-admin.php b/includes/payment-retry/class-wcs-retry-admin.php index 656ebb6..4a7303f 100755 --- a/includes/payment-retry/class-wcs-retry-admin.php +++ b/includes/payment-retry/class-wcs-retry-admin.php @@ -30,6 +30,8 @@ class WCS_Retry_Admin { // Display the number of retries in the Orders list table add_action( 'manage_shop_order_posts_custom_column', __CLASS__ . '::add_column_content', 20, 2 ); + + add_filter( 'wcs_system_status', array( $this, 'add_system_status_content' ) ); } } @@ -141,4 +143,51 @@ class WCS_Retry_Admin { return $settings; } + + /** + * Add system status information about custom retry rules. + * + * @param array $data + * @return array + */ + public static function add_system_status_content( $data ) { + $has_custom_retry_rules = has_action( 'wcs_default_retry_rules' ); + $has_custom_retry_rule_class = has_action( 'wcs_retry_rule_class' ); + $has_custom_raw_retry_rule = has_action( 'wcs_get_retry_rule_raw' ); + $has_custom_retry_rule = has_action( 'wcs_get_retry_rule' ); + + $data['wcs_retry_rules_overridden'] = array( + 'name' => _x( 'Custom Retry Rules', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Custom Retry Rules', + 'mark_icon' => $has_custom_retry_rules ? 'warning' : 'yes', + 'note' => $has_custom_retry_rules ? 'Yes' : 'No', + 'success' => ! $has_custom_retry_rules, + ); + + $data['wcs_retry_rule_class_overridden'] = array( + 'name' => _x( 'Custom Retry Rule Class', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Custom Retry Rule Class', + 'mark_icon' => $has_custom_retry_rule_class ? 'warning' : 'yes', + 'note' => $has_custom_retry_rule_class ? 'Yes' : 'No', + 'success' => ! $has_custom_retry_rule_class, + ); + + $data['wcs_raw_retry_rule_overridden'] = array( + 'name' => _x( 'Custom Raw Retry Rule', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Custom Raw Retry Rule', + 'mark_icon' => $has_custom_raw_retry_rule ? 'warning' : 'yes', + 'note' => $has_custom_raw_retry_rule ? 'Yes' : 'No', + 'success' => ! $has_custom_raw_retry_rule, + ); + + $data['wcs_retry_rule_overridden'] = array( + 'name' => _x( 'Custom Retry Rule', 'label for the system status page', 'woocommerce-subscriptions' ), + 'label' => 'Custom Retry Rule', + 'mark_icon' => $has_custom_retry_rule ? 'warning' : 'yes', + 'note' => $has_custom_retry_rule ? 'Yes' : 'No', + 'success' => ! $has_custom_retry_rule, + ); + + return $data; + } } diff --git a/includes/upgrades/class-wc-subscriptions-upgrader.php b/includes/upgrades/class-wc-subscriptions-upgrader.php index 5558d2e..333c6c7 100755 --- a/includes/upgrades/class-wc-subscriptions-upgrader.php +++ b/includes/upgrades/class-wc-subscriptions-upgrader.php @@ -30,6 +30,11 @@ class WC_Subscriptions_Upgrader { public static $updated_to_wc_2_0; + /** + * @var array An array of WCS_Background_Updater objects used to run upgrade scripts in the background. + */ + protected static $background_updaters = array(); + /** * Hooks upgrade function to init. * @@ -92,6 +97,13 @@ class WC_Subscriptions_Upgrader { add_action( 'wcs_repair_end_of_prepaid_term_actions', __CLASS__ . '::repair_end_of_prepaid_term_actions' ); add_action( 'wcs_repair_subscriptions_containing_synced_variations', __CLASS__ . '::repair_subscription_contains_sync_meta' ); + + // When WC is updated from a version prior to 3.0 to a version after 3.0, add subscription address indexes. Must be hooked on before WC runs its updates, which occur on priority 5. + add_action( 'init', array( __CLASS__, 'maybe_add_subscription_address_indexes' ), 2 ); + + add_action( 'admin_notices', array( __CLASS__, 'maybe_add_downgrade_notice' ) ); + + add_action( 'init', array( __CLASS__, 'initialise_background_updaters' ), 0 ); } /** @@ -200,6 +212,16 @@ class WC_Subscriptions_Upgrader { WCS_Upgrade_2_2_9::schedule_repair(); } + // Repair subscriptions suspended via PayPal. + if ( version_compare( self::$active_version, '2.1.4', '>=' ) && version_compare( self::$active_version, '2.3.0', '<' ) ) { + self::$background_updaters['2.3']['suspended_paypal_repair']->schedule_repair(); + } + + // If the store is running WC 3.0, repair subscriptions with missing address indexes. + if ( '0' !== self::$active_version && version_compare( self::$active_version, '2.3.0', '<' ) && version_compare( WC()->version, '3.0', '>=' ) ) { + self::$background_updaters['2.3']['address_indexes_repair']->schedule_repair(); + } + self::upgrade_complete(); } @@ -766,6 +788,65 @@ class WC_Subscriptions_Upgrader { WCS_Upgrade_2_2_9::repair_subscriptions_containing_synced_variations(); } + /** + * Display an admin notice if the database version is greater than the active version of the plugin by at least one minor release (eg 1.1 and 1.0). + * + * @since 2.3.0 + */ + public static function maybe_add_downgrade_notice() { + + // If there's no downgrade, exit early. self::$active_version is a bit of a misnomer here but in an upgrade context it refers to the database version of the plugin. + if ( ! version_compare( wcs_get_minor_version_string( self::$active_version ), wcs_get_minor_version_string( WC_Subscriptions::$version ), '>' ) ) { + return; + } + + $admin_notice = new WCS_Admin_Notice( 'error' ); + $admin_notice->set_simple_content( sprintf( esc_html__( '%1$sWarning!%2$s It appears that you have downgraded %1$sWooCommerce Subscriptions%2$s from %3$s to %4$s. Downgrading the plugin in this way may cause issues. Please update to %3$s or higher, or %5$sopen a new support ticket%6$s for further assistance.', 'woocommerce-subscriptions' ), + '', '', + '' . self::$active_version . '', + '' . WC_Subscriptions::$version . '', + '', '' + ) ); + + $admin_notice->display(); + } + + /** + * When updating WC to a version after 3.0 from a version prior to 3.0, schedule the repair script to add address indexes. + * + * @since 2.3.0 + */ + public static function maybe_add_subscription_address_indexes() { + $woocommerce_active_version = WC()->version; + $woocommerce_database_version = get_option( 'woocommerce_version' ); + + if ( $woocommerce_active_version !== $woocommerce_database_version && version_compare( $woocommerce_active_version, '3.0', '>=' ) && version_compare( $woocommerce_database_version, '3.0', '<' ) ) { + self::$background_updaters['2.3']['address_indexes_repair']->schedule_repair(); + } + } + + /** + * Load and initialise the background updaters. + * + * @since 2.3.0 + */ + public static function initialise_background_updaters() { + $logger = new WC_logger(); + + include_once( dirname( __FILE__ ) . '/class-wcs-repair-suspended-paypal-subscriptions.php' ); + include_once( dirname( __FILE__ ) . '/class-wcs-repair-subscription-address-indexes.php' ); + + self::$background_updaters['2.3']['suspended_paypal_repair'] = new WCS_Repair_Suspended_PayPal_Subscriptions( $logger ); + self::$background_updaters['2.3']['address_indexes_repair'] = new WCS_Repair_Subscription_Address_Indexes( $logger ); + + // Init the updaters + foreach ( self::$background_updaters as $version => $updaters ) { + foreach ( $updaters as $updater ) { + $updater->init(); + } + } + } + /** * Used to check if a user ID is greater than the last user upgraded to version 1.4. * diff --git a/includes/upgrades/class-wcs-repair-subscription-address-indexes.php b/includes/upgrades/class-wcs-repair-subscription-address-indexes.php new file mode 100755 index 0000000..8c21059 --- /dev/null +++ b/includes/upgrades/class-wcs-repair-subscription-address-indexes.php @@ -0,0 +1,75 @@ +scheduled_hook = 'wcs_add_missing_subscription_address_indexes'; + $this->log_handle = 'wcs-add-subscription-address-indexes'; + $this->logger = $logger; + } + + /** + * Update a subscription, setting its address indexes. + * + * @since 2.3.0 + */ + protected function update_item( $subscription_id ) { + try { + $subscription = wcs_get_subscription( $subscription_id ); + + if ( false === $subscription ) { + throw new Exception( 'Failed to instantiate subscription object' ); + } + + // Saving the subscription sets the address indexes if they don't exist. + $subscription->save(); + + $this->log( sprintf( 'Subscription ID %d address index(es) added.', $subscription_id ) ); + } catch ( Exception $e ) { + $this->log( sprintf( '--- Exception caught repairing subscription %d - exception message: %s ---', $subscription_id, $e->getMessage() ) ); + } + } + + /** + * Get a batch of subscriptions which need address indexes. + * + * @since 2.3.0 + * @return array A list of subscription ids which need address indexes. + */ + protected function get_items_to_update() { + return get_posts( array( + 'post_type' => 'shop_subscription', + 'posts_per_page' => 20, + 'post_status' => 'any', + 'fields' => 'ids', + 'meta_query' => array( + array( + 'key' => '_billing_address_index', + 'compare' => 'NOT EXISTS', + ), + ), + ) ); + } +} diff --git a/includes/upgrades/class-wcs-repair-suspended-paypal-subscriptions.php b/includes/upgrades/class-wcs-repair-suspended-paypal-subscriptions.php new file mode 100755 index 0000000..bb149cc --- /dev/null +++ b/includes/upgrades/class-wcs-repair-suspended-paypal-subscriptions.php @@ -0,0 +1,88 @@ +scheduled_hook = 'wcs_repair_subscriptions_suspended_paypal_not_woocommerce'; + $this->log_handle = 'wcs-upgrade-subscriptions-paypal-suspended'; + $this->logger = $logger; + } + + /** + * Repair a subscription that was suspended in PayPal, but not suspended in WooCommerce. + * + * @param int $subscription_id The ID of a shop_subscription/WC_Subscription object. + */ + protected function update_item( $subscription_id ) { + try { + $subscription = wcs_get_subscription( $subscription_id ); + + if ( ! $subscription ) { + throw new Exception( 'Failed to instantiate subscription object' ); + } + + $subscription->update_status( 'on-hold', __( 'Subscription suspended by Database repair script. This subscription was suspended via PayPal.', 'woocommerce-subscriptions' ) ); + + $this->log( sprintf( 'Subscription ID %d suspended from 2.3.0 PayPal database repair script.', $subscription_id ) ); + } catch ( Exception $e ) { + $this->log( sprintf( '--- Exception caught repairing subscription %d - exception message: %s ---', $subscription_id, $e->getMessage() ) ); + } + } + + /** + * Get a list of subscriptions to repair. + * + * @since 2.3.0 + * @return array A list of subscription ids which may need to be repaired. + */ + protected function get_items_to_update() { + return get_posts( array( + 'posts_per_page' => 20, + 'post_type' => 'shop_subscription', + 'post_status' => wcs_sanitize_subscription_status_key( 'active' ), + 'fields' => 'ids', + 'meta_query' => array( + array( + 'key' => '_schedule_next_payment', + 'value' => date( 'Y-m-d H:i:s', wcs_strtotime_dark_knight( '-3 days' ) ), + 'compare' => '<=', + 'type' => 'DATETIME', + ), + array( + 'key' => '_payment_method', + 'value' => 'paypal', + ), + array( + 'key' => '_paypal_subscription_id', + 'value' => 'B-%', + 'compare' => 'NOT LIKE', + ), + ), + ) ); + } +} diff --git a/includes/upgrades/class-wcs-upgrade-2-0.php b/includes/upgrades/class-wcs-upgrade-2-0.php index b5c74b2..e865410 100755 --- a/includes/upgrades/class-wcs-upgrade-2-0.php +++ b/includes/upgrades/class-wcs-upgrade-2-0.php @@ -116,10 +116,10 @@ class WCS_Upgrade_2_0 { self::migrate_order_items( $new_subscription->get_id(), wcs_get_objects_property( $original_order, 'id' ) ); // Update renewal orders to link via post meta key instead of post_parent column - self::migrate_renewal_orders( $new_subscription->get_id(), wcs_get_objects_property( $original_order, 'id' ) ); + self::migrate_renewal_orders( $new_subscription, wcs_get_objects_property( $original_order, 'id' ) ); // Make sure the resubscribe meta data is migrated to use the new subscription ID + meta key - self::migrate_resubscribe_orders( $new_subscription->get_id(), wcs_get_objects_property( $original_order, 'id' ) ); + self::migrate_resubscribe_orders( $new_subscription, $original_order ); // If the order for this subscription contains a switch, make sure the switch meta data is migrated to use the new subscription ID + meta key self::migrate_switch_meta( $new_subscription, $original_order, $subscription_item_id ); @@ -223,7 +223,7 @@ class WCS_Upgrade_2_0 { } $meta_key = str_replace( '_subscription', '', $raw_subscription->meta_key ); - $meta_key = substr( $meta_key, 0, 1 ) == '_' ? substr( $meta_key, 1 ) : $meta_key; + $meta_key = wcs_maybe_unprefix_key( $meta_key ); if ( 'product_id' === $meta_key ) { $subscriptions[ $raw_subscription->order_item_id ]['subscription_key'] = $subscriptions[ $raw_subscription->order_item_id ]['order_id'] . '_' . $raw_subscription->meta_value; @@ -758,12 +758,12 @@ class WCS_Upgrade_2_0 { * order's ID, to 0, and then the new subscription's ID should be set as the '_subscription_renewal' post meta value on * the renewal order. * - * @param int $subscription_id The ID of a 'shop_subscription' post type + * @param WC_Subscription $subscription An instance of a 'shop_subscription' post type * @param int $order_id The ID of a 'shop_order' which created this susbcription * @return null * @since 2.0 */ - private static function migrate_renewal_orders( $subscription_id, $order_id ) { + private static function migrate_renewal_orders( $subscription, $order_id ) { global $wpdb; // Get the renewal order IDs @@ -777,10 +777,10 @@ class WCS_Upgrade_2_0 { // Set the post meta foreach ( $renewal_order_ids as $renewal_order_id ) { - wcs_set_objects_property( wc_get_order( $renewal_order_id ), 'subscription_renewal', $subscription_id ); + WCS_Related_Order_Store::instance()->add_relation( wc_get_order( $renewal_order_id ), $subscription, 'renewal' ); } - WCS_Upgrade_Logger::add( sprintf( 'For subscription %d: migrated data for renewal orders %s', $subscription_id, implode( ', ', $renewal_order_ids ) ) ); + WCS_Upgrade_Logger::add( sprintf( 'For subscription %d: migrated data for renewal orders %s', $subscription->get_id(), implode( ', ', $renewal_order_ids ) ) ); $rows_affected = $wpdb->update( $wpdb->posts, @@ -795,7 +795,7 @@ class WCS_Upgrade_2_0 { array( '%d', '%s' ) ); - WCS_Upgrade_Logger::add( sprintf( 'For subscription %d: %d rows of renewal order post_parent values changed', $subscription_id, count( $renewal_order_ids ) ) ); + WCS_Upgrade_Logger::add( sprintf( 'For subscription %d: %d rows of renewal order post_parent values changed', $subscription->get_id(), count( $renewal_order_ids ) ) ); } /** @@ -804,21 +804,24 @@ class WCS_Upgrade_2_0 { * original order's ID, to 0, and then the new subscription's ID should be set as the '_subscription_resubscribe' post meta value * on the resubscribe order. * - * @param int $subscription_id The ID of a 'shop_subscription' post type - * @param int $resubscribe_order_id The ID of a 'shop_order' which created this susbcription + * @param WC_Subscription $new_subscription An instance of a 'shop_subscription' post type + * @param WC_Order $resubscribe_order An instance of a 'shop_order' post type which created this subscription * @return null * @since 2.0 */ - private static function migrate_resubscribe_orders( $new_subscription_id, $resubscribe_order_id ) { + private static function migrate_resubscribe_orders( $new_subscription, $resubscribe_order ) { global $wpdb; + $resubscribe_order_id = wcs_get_objects_property( $resubscribe_order, 'id' ); + $new_subscription_id = wcs_get_objects_property( $new_subscription, 'id' ); + // Set the post meta on the new subscription and old order foreach ( get_post_meta( $resubscribe_order_id, '_original_order', false ) as $original_order_id ) { // Because self::get_subscriptions() orders by order ID, it's safe to use wcs_get_subscriptions_for_order() here because the subscription in the new format will have been created for the original order (because its ID will be < the resubscribe order's ID) foreach ( wcs_get_subscriptions_for_order( $original_order_id ) as $old_subscription ) { - update_post_meta( $resubscribe_order_id, '_subscription_resubscribe', $old_subscription->get_id(), true ); - update_post_meta( $new_subscription_id, '_subscription_resubscribe', $old_subscription->get_id(), true ); + WCS_Related_Order_Store::instance()->add_relation( $resubscribe_order, $old_subscription, 'resubscribe' ); + WCS_Related_Order_Store::instance()->add_relation( $new_subscription, $old_subscription, 'resubscribe' ); } $wpdb->query( $wpdb->prepare( @@ -891,7 +894,8 @@ class WCS_Upgrade_2_0 { if ( wcs_is_subscription( $old_subscription ) ) { // Link the old subscription's ID to the switch order using the new switch meta key - wcs_set_objects_property( $switch_order, 'subscription_switch', $old_subscription->get_id() ); + + WCS_Related_Order_Store::instance()->add_relation( $switch_order, $old_subscription, 'switch' ); // Now store the new/old item IDs for record keeping foreach ( $old_subscription->get_items() as $item_id => $item ) { diff --git a/includes/upgrades/class-wcs-upgrade-notice-manager.php b/includes/upgrades/class-wcs-upgrade-notice-manager.php new file mode 100755 index 0000000..cdcd5b5 --- /dev/null +++ b/includes/upgrades/class-wcs-upgrade-notice-manager.php @@ -0,0 +1,157 @@ +=' ) ) { + update_option( self::$option_name, array( + 'version' => self::$version, + 'display_count' => 0, + ) ); + } + } + + /** + * Display the upgrade notice including details about the update if it hasn't been dismissed. + * + * @since 2.3.0 + */ + public static function maybe_show_admin_notice() { + + if ( isset( $_GET['_wcsnonce'] ) && wp_verify_nonce( $_GET['_wcsnonce'], 'dismiss_upgrade_notice' ) && ! empty( $_GET['dismiss_upgrade_notice'] ) && self::$version === $_GET['dismiss_upgrade_notice'] ) { + delete_option( self::$option_name ); + return; + } + + if ( ! self::display_notice() ) { + return; + } + + $version = _x( '2.3', 'plugin version number used in admin notice', 'woocommerce-subscriptions' ); + $dismiss_url = wp_nonce_url( add_query_arg( 'dismiss_upgrade_notice', self::$version ), 'dismiss_upgrade_notice', '_wcsnonce' ); + $notice = new WCS_Admin_Notice( 'notice notice-info', array(), $dismiss_url ); + $features = array( + array( + 'title' => __( 'New Subscription Coupon Features', 'woocommerce-subscriptions' ), + 'description' => __( 'Want to offer customers coupons which apply for 6 months? You can now define the number of cycles discounts would be applied.', 'woocommerce-subscriptions' ), + ), + array( + 'title' => __( 'New Signup Pricing Options for Synchronized Subscriptions', 'woocommerce-subscriptions' ), + 'description' => __( 'Charge the full recurring price at the time of sign up for synchronized subscriptions. Your customers can now receive their products straight away.', 'woocommerce-subscriptions' ), + ), + array( + 'title' => __( 'Link Parent Orders to Subscriptions', 'woocommerce-subscriptions' ), + // translators: placeholders are opening and closing tags linking to documentation. + 'description' => sprintf( __( 'For subscriptions with no parent order, shop managers can now choose a parent order via the Edit Subscription screen. This makes it possible to set a parent order on %smanually created subscriptions%s. The order can also be sent to customers to act as an invoice that needs to be paid to activate the subscription.', 'woocommerce-subscriptions' ), '', '' ), + ), + array( + 'title' => __( 'Early Renewal', 'woocommerce-subscriptions' ), + 'description' => __( 'Customers can now renew their subscriptions before the scheduled next payment date. Why not use this to email your customers a coupon a month before their annual subscription renewals to get access to that revenue sooner?', 'woocommerce-subscriptions' ), + ), + ); + + // translators: placeholder is Subscription version string ('2.3') + $notice->set_heading( sprintf( __( 'Welcome to Subscriptions %s', 'woocommerce-subscriptions' ), $version ) ); + $notice->set_content_template( 'update-welcome-notice.php', plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'includes/upgrades/templates/', array( + 'version' => $version, + 'features' => $features, + ) ); + $notice->set_actions( array( + array( + 'name' => __( 'Learn More', 'woocommerce-subscriptions' ), + 'url' => 'https://docs.woocommerce.com/document/subscriptions/version-2-3/', + ), + ) ); + + $notice->display(); + self::increment_display_count(); + } + + /** + * Determine if this admin notice should be displayed. + * + * @return bool Whether this admin notice should be displayed. + * @since 2.3.0 + */ + protected static function display_notice() { + $option = get_option( self::$option_name ); + $display_notice = false; + + if ( isset( $option['version'] ) ) { + $display_notice = $option['version'] === self::$version; + } + + return $display_notice; + } + + /** + * Increment the notice display counter signalling the notice has been displayed. + * + * The option triggering this notice will be deleted if the display count has been reached. + * + * @since 2.3.0 + */ + protected static function increment_display_count() { + $option = get_option( self::$option_name ); + $count = isset( $option['display_count'] ) ? (int) $option['display_count'] : 0; + $count++; + + // If we've reached the display count, delete the option so the notice isn't displayed again. + if ( $count >= self::$display_count ) { + delete_option( self::$option_name ); + } else { + $option['display_count'] = $count; + update_option( self::$option_name, $option ); + } + } +} diff --git a/includes/upgrades/templates/update-welcome-notice.php b/includes/upgrades/templates/update-welcome-notice.php new file mode 100755 index 0000000..d380317 --- /dev/null +++ b/includes/upgrades/templates/update-welcome-notice.php @@ -0,0 +1,16 @@ + +

    +

    + tags ?> + ', '' ) ); ?> + +

    +

    +
      + +
    • + +
    +
    + +

    diff --git a/includes/upgrades/templates/wcs-about.php b/includes/upgrades/templates/wcs-about.php index 74260e5..83e7e5d 100755 --- a/includes/upgrades/templates/wcs-about.php +++ b/includes/upgrades/templates/wcs-about.php @@ -106,7 +106,7 @@ if ( ! defined( 'ABSPATH' ) ) {

    -

    +

    @@ -114,10 +114,10 @@ if ( ! defined( 'ABSPATH' ) ) {

    -

    +

    ) tags - printf( esc_html__( '%sLearn more »%s', 'woocommerce-subscriptions' ), '', '' ); ?> + printf( esc_html__( '%sLearn more »%s', 'woocommerce-subscriptions' ), '', '' ); ?>

    diff --git a/includes/wcs-cart-functions.php b/includes/wcs-cart-functions.php index 1d4b01c..c7d4e85 100755 --- a/includes/wcs-cart-functions.php +++ b/includes/wcs-cart-functions.php @@ -70,7 +70,7 @@ function wcs_cart_totals_shipping_html() { } elseif ( in_array( $chosen_initial_method, $package['rates'] ) ) { $chosen_recurring_method = $chosen_initial_method; } else { - $chosen_recurring_method = current( $package['rates'] )->id; + $chosen_recurring_method = empty( $package['rates'] ) ? '' : current( $package['rates'] )->id; } $shipping_selection_displayed = false; @@ -206,6 +206,18 @@ function wcs_cart_totals_taxes_total_html( $cart ) { echo wp_kses_post( apply_filters( 'wcs_cart_totals_taxes_total_html', wcs_cart_price_string( $value, $cart ), $cart ) ); } +/** + * Display the remove link for a coupon. + * + * @access public + * + * @param WC_Coupon $coupon + */ +function wcs_cart_coupon_remove_link_html( $coupon ) { + $html = '' . __( '[Remove]', 'woocommerce-subscriptions' ) . ''; + echo wp_kses( $html, array_replace_recursive( wp_kses_allowed_html( 'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) ); +} + /** * Display a recurring coupon's value. * diff --git a/includes/wcs-deprecated-functions.php b/includes/wcs-deprecated-functions.php index efbc9cf..9dc2dc2 100755 --- a/includes/wcs-deprecated-functions.php +++ b/includes/wcs-deprecated-functions.php @@ -206,27 +206,16 @@ function wcs_get_subscription_in_deprecated_structure( WC_Subscription $subscrip } } - $paid_renewal_order_ids = get_posts( array( - 'posts_per_page' => -1, - 'post_status' => $subscription->get_paid_order_statuses(), - 'post_type' => 'shop_order', - 'orderby' => 'date', - 'order' => 'desc', - 'fields' => 'ids', - 'meta_query' => array( - array( - 'key' => '_subscription_renewal', - 'compare' => '=', - 'value' => $subscription->get_id(), - 'type' => 'numeric', - ), - ), - ) ); + foreach ( $subscription->get_related_orders( 'all', 'renewal' ) as $renewal_order ) { - foreach ( $paid_renewal_order_ids as $paid_renewal_order_id ) { - $date_created = wcs_get_objects_property( wc_get_order( $paid_renewal_order_id ), 'date_created' ); - if ( ! is_null( $date_created ) ) { - $completed_payments[] = wcs_get_datetime_utc_string( $date_created ); + // Not all gateways would call $order->payment_complete() with WC < 3.0, so we need to find renewal orders with a paid status or a paid date (WC 3.0+ takes care of setting the paid date when payment_complete() wasn't called) + if ( null !== wcs_get_objects_property( $renewal_order, 'date_paid' ) || $renewal_order->has_status( $subscription->get_paid_order_statuses() ) ) { + + $date_created = wcs_get_objects_property( $renewal_order, 'date_created' ); + + if ( ! is_null( $date_created ) ) { + $completed_payments[] = wcs_get_datetime_utc_string( $date_created ); + } } } } diff --git a/includes/wcs-helper-functions.php b/includes/wcs-helper-functions.php index 85798b2..7a3bebc 100755 --- a/includes/wcs-helper-functions.php +++ b/includes/wcs-helper-functions.php @@ -171,6 +171,18 @@ function wcs_maybe_prefix_key( $key, $prefix = '_' ) { return ( substr( $key, 0, strlen( $prefix ) ) != $prefix ) ? $prefix . $key : $key; } +/** + * Remove a prefix from a string if has it + * + * @param string $key + * @param string $prefix + * @since 2.2.0 + * @return string + */ +function wcs_maybe_unprefix_key( $key, $prefix = '_' ) { + return ( substr( $key, 0, strlen( $prefix ) ) === $prefix ) ? substr( $key, strlen( $prefix ) ) : $key; +} + /** * Find the name of the function which called the function which called this function. * @@ -186,3 +198,36 @@ function wcs_get_calling_function_name() { return $calling_function; } + +/** + * Get the value of a transient, even if it has expired. + * + * Handy when data cached in a transient will be valid even if the transient has expired. + * + * @param string $transient_key The key used to set/get the transient via get_transient()/set_transient() + * @return mixed If data exists in a transient, the value of the transient, else boolean false. + */ +function wcs_get_transient_even_if_expired( $transient_key ) { + + // First, check if the transient exists via the Options API to access the value in the database without WordPress checking the transient's expiration time (and returning false if it's < now) + $transient_value = get_option( sprintf( '_transient_%s', $transient_key ) ); + + if ( false === $transient_value ) { + $transient_value = get_transient( $transient_key ); + } + + return $transient_value; +} + +/** + * Get a minor version string from a full version string. + * + * @param string $version Version string (eg 1.0.1). + * @return string The minor release version string (eg 1.0). + * @since 2.3.0 + */ +function wcs_get_minor_version_string( $version ) { + $version_parts = array_pad( array_map( 'intval', explode( '.', $version ) ), 2, 0 ); + + return $version_parts[0] . '.' . $version_parts[1]; +} diff --git a/includes/wcs-limit-functions.php b/includes/wcs-limit-functions.php index 67db4af..9c9339d 100755 --- a/includes/wcs-limit-functions.php +++ b/includes/wcs-limit-functions.php @@ -24,7 +24,13 @@ function wcs_get_product_limitation( $product ) { $product = wc_get_product( $product ); } - return apply_filters( 'woocommerce_subscriptions_product_limitation', WC_Subscriptions_Product::get_meta_data( $product, 'subscription_limit', 'no', 'use_default_value' ), $product ); + if ( $product->is_type( 'variation' ) ) { + $parent_product = wc_get_product( $product->get_parent_id() ); + } else { + $parent_product = $product; + } + + return apply_filters( 'woocommerce_subscriptions_product_limitation', WC_Subscriptions_Product::get_meta_data( $parent_product, 'subscription_limit', 'no', 'use_default_value' ), $product ); } /** diff --git a/includes/wcs-order-functions.php b/includes/wcs-order-functions.php index 0e04c7e..9612ea1 100755 --- a/includes/wcs-order-functions.php +++ b/includes/wcs-order-functions.php @@ -13,9 +13,9 @@ if ( ! defined( 'ABSPATH' ) ) { } /** - * A wrapper for @see wcs_get_subscriptions() which accepts simply an order ID + * Get the subscription related to an order, if any. * - * @param int|WC_Order $order_id The post_id of a shop_order post or an instance of a WC_Order object + * @param WC_Order|int $order An instance of a WC_Order object or the ID of an order * @param array $args A set of name value pairs to filter the returned value. * 'subscriptions_per_page' The number of subscriptions to return. Default set to -1 to return all. * 'offset' An optional number of subscription to displace or pass over. Default 0. @@ -29,14 +29,19 @@ if ( ! defined( 'ABSPATH' ) ) { * @return array Subscription details in post_id => WC_Subscription form. * @since 2.0 */ -function wcs_get_subscriptions_for_order( $order_id, $args = array() ) { +function wcs_get_subscriptions_for_order( $order, $args = array() ) { - if ( is_object( $order_id ) ) { - $order_id = wcs_get_objects_property( $order_id, 'id' ); + $subscriptions = array(); + + if ( ! is_a( $order, 'WC_Abstract_Order' ) ) { + $order = wc_get_order( $order ); + } + + if ( ! is_a( $order, 'WC_Abstract_Order' ) ) { + return $subscriptions; } $args = wp_parse_args( $args, array( - 'order_id' => $order_id, 'subscriptions_per_page' => -1, 'order_type' => array( 'parent', 'switch' ), ) @@ -47,23 +52,29 @@ function wcs_get_subscriptions_for_order( $order_id, $args = array() ) { $args['order_type'] = array( $args['order_type'] ); } - $subscriptions = array(); - $get_all = ( in_array( 'any', $args['order_type'] ) ) ? true : false; + $get_all = ( in_array( 'any', $args['order_type'] ) ) ? true : false; - if ( $order_id && in_array( 'parent', $args['order_type'] ) || $get_all ) { - $subscriptions = wcs_get_subscriptions( $args ); + if ( $get_all || in_array( 'parent', $args['order_type'] ) ) { + + $get_subscriptions_args = array_merge( $args, array( + 'order_id' => wcs_get_objects_property( $order, 'id' ), + ) ); + + $subscriptions = wcs_get_subscriptions( $get_subscriptions_args ); } - if ( ( in_array( 'resubscribe', $args['order_type'] ) || $get_all ) && wcs_order_contains_resubscribe( $order_id ) ) { - $subscriptions += wcs_get_subscriptions_for_resubscribe_order( $order_id ); - } + $all_relation_types = WCS_Related_Order_Store::instance()->get_relation_types(); + $relation_types = $get_all ? $all_relation_types : array_intersect( $all_relation_types, $args['order_type'] ); - if ( ( in_array( 'renewal', $args['order_type'] ) || $get_all ) && wcs_order_contains_renewal( $order_id ) ) { - $subscriptions += wcs_get_subscriptions_for_renewal_order( $order_id ); - } + foreach ( $relation_types as $relation_type ) { - if ( ( in_array( 'switch', $args['order_type'] ) || $get_all ) && wcs_order_contains_switch( $order_id ) ) { - $subscriptions += wcs_get_subscriptions_for_switch_order( $order_id ); + $subscription_ids = WCS_Related_Order_Store::instance()->get_related_subscription_ids( $order, $relation_type ); + + foreach ( $subscription_ids as $subscription_id ) { + if ( wcs_is_subscription( $subscription_id ) ) { + $subscriptions[ $subscription_id ] = wcs_get_subscription( $subscription_id ); + } + } } return $subscriptions; @@ -139,7 +150,7 @@ function wcs_copy_order_meta( $from_order, $to_order, $type = 'subscription' ) { throw new InvalidArgumentException( _x( 'Invalid data. Type of copy is not a string.', 'Refers to the type of the copy being performed: "copy_order", "subscription", "renewal_order", "resubscribe_order"', 'woocommerce-subscriptions' ) ); } - if ( ! in_array( $type, array( 'subscription', 'renewal_order', 'resubscribe_order' ) ) ) { + if ( ! in_array( $type, array( 'subscription', 'parent', 'renewal_order', 'resubscribe_order' ) ) ) { $type = 'copy_order'; } @@ -165,7 +176,12 @@ function wcs_copy_order_meta( $from_order, $to_order, $type = 'subscription' ) { '_subscription_renewal', '_subscription_switch', '_payment_method', - '_payment_method_title' + '_payment_method_title', + '_suspension_count', + '_requires_manual_renewal', + '_cancelled_email_sent', + '_trial_period', + '_created_via' )", wcs_get_objects_property( $from_order, 'id' ) ); @@ -197,7 +213,7 @@ function wcs_copy_order_meta( $from_order, $to_order, $type = 'subscription' ) { * * @param WC_Subscription|int $subscription Subscription we're basing the order off of * @param string $type Type of new order. Default values are 'renewal_order'|'resubscribe_order' - * @return WC_Order New order + * @return WC_Order|WP_Error New order or error object. */ function wcs_create_order_from_subscription( $subscription, $type ) { @@ -220,18 +236,19 @@ function wcs_create_order_from_subscription( $subscription, $type ) { $new_order = wc_create_order( array( 'customer_id' => $subscription->get_user_id(), 'customer_note' => $subscription->get_customer_note(), + 'created_via' => 'subscription', ) ); wcs_copy_order_meta( $subscription, $new_order, $type ); // Copy over line items and allow extensions to add/remove items or item meta $items = apply_filters( 'wcs_new_order_items', $subscription->get_items( array( 'line_item', 'fee', 'shipping', 'tax', 'coupon' ) ), $new_order, $subscription ); - $items = apply_filters( 'wcs_' . $type . '_items', $items, $new_order, $subscription ); + $items = apply_filters( "wcs_{$type}_items", $items, $new_order, $subscription ); foreach ( $items as $item_index => $item ) { $item_name = apply_filters( 'wcs_new_order_item_name', $item['name'], $item, $subscription ); - $item_name = apply_filters( 'wcs_' . $type . '_item_name', $item_name, $item, $subscription ); + $item_name = apply_filters( "wcs_{$type}_item_name", $item_name, $item, $subscription ); // Create order line item on the renewal order $order_item_id = wc_add_order_item( wcs_get_objects_property( $new_order, 'id' ), array( @@ -342,15 +359,14 @@ function wcs_get_new_order_title( $type ) { * if not actually string. * * @param string $type type of new order - * @return string the same type thing if no problems are found + * @return string|WP_Error the same type thing if no problems are found, or WP_Error. */ function wcs_validate_new_order_type( $type ) { if ( ! is_string( $type ) ) { return new WP_Error( 'order_from_subscription_type_type', sprintf( __( '$type passed to the function was not a string.', 'woocommerce-subscriptions' ), $type ) ); - } - if ( ! in_array( $type, apply_filters( 'wcs_new_order_types', array( 'renewal_order', 'resubscribe_order' ) ) ) ) { + if ( ! in_array( $type, apply_filters( 'wcs_new_order_types', array( 'renewal_order', 'resubscribe_order', 'parent' ) ) ) ) { return new WP_Error( 'order_from_subscription_type', sprintf( __( '"%s" is not a valid new order type.', 'woocommerce-subscriptions' ), $type ) ); } @@ -739,9 +755,8 @@ function wcs_display_item_downloads( $item, $order ) { * Copy the order item data and meta data from one item to another. * * @since 2.2.0 - * @param WC_Order_Item The order item to copy data from - * @param WC_Order_Item The order item to copy data to - * @return void + * @param WC_Order_Item $from_item The order item to copy data from + * @param WC_Order_Item $to_item The order item to copy data to */ function wcs_copy_order_item( $from_item, &$to_item ) { @@ -756,6 +771,7 @@ function wcs_copy_order_item( $from_item, &$to_item ) { switch ( $from_item->get_type() ) { case 'line_item': + /** @var WC_Order_Item_Product $from_item */ $to_item->set_props( array( 'product_id' => $from_item->get_product_id(), 'variation_id' => $from_item->get_variation_id(), @@ -767,6 +783,7 @@ function wcs_copy_order_item( $from_item, &$to_item ) { ) ); break; case 'shipping': + /** @var WC_Order_Item_Shipping $from_item */ $to_item->set_props( array( 'method_id' => $from_item->get_method_id(), 'total' => $from_item->get_total(), @@ -774,6 +791,7 @@ function wcs_copy_order_item( $from_item, &$to_item ) { ) ); break; case 'tax': + /** @var WC_Order_Item_Tax $from_item */ $to_item->set_props( array( 'rate_id' => $from_item->get_rate_id(), 'label' => $from_item->get_label(), @@ -783,6 +801,7 @@ function wcs_copy_order_item( $from_item, &$to_item ) { ) ); break; case 'fee': + /** @var WC_Order_Item_Fee $from_item */ $to_item->set_props( array( 'tax_class' => $from_item->get_tax_class(), 'tax_status' => $from_item->get_tax_status(), @@ -791,6 +810,7 @@ function wcs_copy_order_item( $from_item, &$to_item ) { ) ); break; case 'coupon': + /** @var WC_Order_Item_Coupon $from_item */ $to_item->set_props( array( 'discount' => $from_item->get_discount(), 'discount_tax' => $from_item->get_discount_tax(), diff --git a/includes/wcs-product-functions.php b/includes/wcs-product-functions.php index f9afa9a..d37dda4 100755 --- a/includes/wcs-product-functions.php +++ b/includes/wcs-product-functions.php @@ -94,7 +94,7 @@ function wcs_get_variation_prices( $variation, $variable_product ) { * Get an array of the minimum and maximum priced variations based on subscription billing terms. * * @param array $child_variation_ids the IDs of product variation children ids - * @return array() Array containing the min and max variation prices and billing data + * @return array Array containing the min and max variation prices and billing data * @since 2.2.0 */ function wcs_get_min_max_variation_data( $variable_product, $child_variation_ids = array() ) { diff --git a/includes/wcs-renewal-functions.php b/includes/wcs-renewal-functions.php index caaabea..4692926 100755 --- a/includes/wcs-renewal-functions.php +++ b/includes/wcs-renewal-functions.php @@ -33,7 +33,7 @@ function wcs_create_renewal_order( $subscription ) { return new WP_Error( 'renewal-order-error', $renewal_order->get_error_message() ); } - wcs_set_objects_property( $renewal_order, 'subscription_renewal', $subscription->get_id(), 'save' ); + WCS_Related_Order_Store::instance()->add_relation( $renewal_order, $subscription, 'renewal' ); return apply_filters( 'wcs_renewal_order_created', $renewal_order, $subscription ); } @@ -50,7 +50,9 @@ function wcs_order_contains_renewal( $order ) { $order = wc_get_order( $order ); } - if ( wcs_is_order( $order ) && wcs_get_objects_property( $order, 'subscription_renewal' ) ) { + $related_subscriptions = wcs_get_subscriptions_for_renewal_order( $order ); + + if ( wcs_is_order( $order ) && ! empty( $related_subscriptions ) ) { $is_renewal = true; } else { $is_renewal = false; @@ -107,29 +109,11 @@ function wcs_cart_contains_failed_renewal_order_payment() { } /** - * Get the subscription to which a renewal order relates. + * Get the subscription/s to which a resubscribe order relates. * * @param WC_Order|int $order The WC_Order object or ID of a WC_Order order. * @since 2.0 */ function wcs_get_subscriptions_for_renewal_order( $order ) { - - if ( ! is_a( $order, 'WC_Abstract_Order' ) ) { - $order = wc_get_order( $order ); - } - - $subscriptions = array(); - - // Only use the order if we actually found a valid order object - if ( is_a( $order, 'WC_Abstract_Order' ) ) { - $subscription_ids = wcs_get_objects_property( $order, 'subscription_renewal', 'multiple' ); - - foreach ( $subscription_ids as $subscription_id ) { - if ( wcs_is_subscription( $subscription_id ) ) { - $subscriptions[ $subscription_id ] = wcs_get_subscription( $subscription_id ); - } - } - } - - return apply_filters( 'wcs_subscriptions_for_renewal_order', $subscriptions, $order ); + return wcs_get_subscriptions_for_order( $order, array( 'order_type' => 'renewal' ) ); } diff --git a/includes/wcs-resubscribe-functions.php b/includes/wcs-resubscribe-functions.php index a0dbd7d..70e6d71 100755 --- a/includes/wcs-resubscribe-functions.php +++ b/includes/wcs-resubscribe-functions.php @@ -26,7 +26,9 @@ function wcs_order_contains_resubscribe( $order ) { $order = wc_get_order( $order ); } - if ( wcs_get_objects_property( $order, 'subscription_resubscribe' ) ) { + $related_subscriptions = wcs_get_subscriptions_for_resubscribe_order( $order ); + + if ( wcs_is_order( $order ) && ! empty( $related_subscriptions ) ) { $is_resubscribe_order = true; } else { $is_resubscribe_order = false; @@ -54,8 +56,7 @@ function wcs_create_resubscribe_order( $subscription ) { return new WP_Error( 'resubscribe-order-error', $resubscribe_order->get_error_message() ); } - // Keep a record of the original subscription's ID on the new order - wcs_set_objects_property( $resubscribe_order, 'subscription_resubscribe', $subscription->get_id(), true ); + WCS_Related_Order_Store::instance()->add_relation( $resubscribe_order, $subscription, 'resubscribe' ); do_action( 'wcs_resubscribe_order_created', $resubscribe_order, $subscription ); @@ -137,21 +138,7 @@ function wcs_cart_contains_resubscribe( $cart = '' ) { * @since 2.0 */ function wcs_get_subscriptions_for_resubscribe_order( $order ) { - - if ( ! is_a( $order, 'WC_Abstract_Order' ) ) { - $order = wc_get_order( $order ); - } - - $subscriptions = array(); - $subscription_ids = wcs_get_objects_property( $order, 'subscription_resubscribe', 'multiple' ); - - foreach ( $subscription_ids as $subscription_id ) { - if ( wcs_is_subscription( $subscription_id ) ) { - $subscriptions[ $subscription_id ] = wcs_get_subscription( $subscription_id ); - } - } - - return apply_filters( 'wcs_subscriptions_for_resubscribe_order', $subscriptions, $order ); + return wcs_get_subscriptions_for_order( $order, array( 'order_type' => 'resubscribe' ) ); } /** @@ -201,18 +188,7 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) { } else { - $resubscribe_orders = get_posts( array( - 'meta_query' => array( - array( - 'key' => '_subscription_resubscribe', - 'compare' => '=', - 'value' => $subscription->get_id(), - 'type' => 'numeric', - ), - ), - 'post_type' => 'shop_order', - 'post_status' => 'any', - ) ); + $resubscribe_order_ids = $subscription->get_related_orders( 'ids', 'resubscribe' ); // Make sure all line items still exist $all_line_items_exist = true; @@ -229,13 +205,21 @@ function wcs_can_user_resubscribe_to( $subscription, $user_id = '' ) { break; } - if ( 'active' == wcs_get_product_limitation( $product ) && ( wcs_user_has_subscription( $user_id, $product->get_id(), 'on-hold' ) || wcs_user_has_subscription( $user_id, $product->get_id(), 'active' ) ) ) { - $has_active_limited_subscription = true; - break; + if ( 'active' === wcs_get_product_limitation( $product ) ) { + if ( $product->is_type( 'variation' ) ) { + $limited_product_id = $product->get_parent_id(); + } else { + $limited_product_id = $product->get_id(); + } + + if ( wcs_user_has_subscription( $user_id, $limited_product_id, 'on-hold' ) || wcs_user_has_subscription( $user_id, $limited_product_id, 'active' ) ) { + $has_active_limited_subscription = true; + break; + } } } - if ( empty( $resubscribe_orders ) && $subscription->get_completed_payment_count() > 0 && true === $all_line_items_exist && false === $has_active_limited_subscription ) { + if ( empty( $resubscribe_order_ids ) && $subscription->get_completed_payment_count() > 0 && true === $all_line_items_exist && false === $has_active_limited_subscription ) { $can_user_resubscribe = true; } else { $can_user_resubscribe = false; diff --git a/includes/wcs-switch-functions.php b/includes/wcs-switch-functions.php index 9ffae0d..48d61e4 100755 --- a/includes/wcs-switch-functions.php +++ b/includes/wcs-switch-functions.php @@ -50,24 +50,7 @@ function wcs_order_contains_switch( $order ) { * @since 2.0 */ function wcs_get_subscriptions_for_switch_order( $order ) { - - if ( ! is_a( $order, 'WC_Abstract_Order' ) ) { - $order = wc_get_order( $order ); - } - - $subscriptions = array(); - $subscription_ids = wcs_get_objects_property( $order, 'subscription_switch', 'multiple' ); - - foreach ( $subscription_ids as $subscription_id ) { - - $subscription = wcs_get_subscription( $subscription_id ); - - if ( $subscription ) { - $subscriptions[ $subscription_id ] = $subscription; - } - } - - return $subscriptions; + return wcs_get_subscriptions_for_order( $order, array( 'order_type' => 'switch' ) ); } /** @@ -78,28 +61,8 @@ function wcs_get_subscriptions_for_switch_order( $order ) { * @since 2.0 */ function wcs_get_switch_orders_for_subscription( $subscription_id ) { - - $orders = array(); - - // Select the orders which switched item/s from this subscription - $order_ids = get_posts( array( - 'post_type' => 'shop_order', - 'post_status' => 'any', - 'fields' => 'ids', - 'posts_per_page' => -1, - 'meta_query' => array( - array( - 'key' => '_subscription_switch', - 'value' => $subscription_id, - ), - ), - ) ); - - foreach ( $order_ids as $order_id ) { - $orders[ $order_id ] = wc_get_order( $order_id ); - } - - return $orders; + $subscription = wcs_get_subscription( $subscription_id ); + return $subscription->get_related_orders( 'all', 'switch' ); } /** @@ -124,24 +87,22 @@ function wcs_is_product_switchable_type( $product ) { } else { // back compat for parent products - $parent_id = wcs_get_objects_property( $product, 'parent_id' ); - - if ( $product->is_type( 'subscription_variation' ) && ! empty( $parent_id ) ) { + if ( $product->is_type( 'subscription_variation' ) && $product->get_parent_id() ) { $variation = $product; - $product = wc_get_product( $parent_id );; + $product = wc_get_product( $product->get_parent_id() ); } $allow_switching = get_option( WC_Subscriptions_Admin::$option_prefix . '_allow_switching', 'no' ); switch ( $allow_switching ) { case 'variable' : - $is_product_switchable = ( $product->is_type( array( 'variable-subscription', 'subscription_variation' ) ) ) ? true : false; + $is_product_switchable = $product->is_type( array( 'variable-subscription', 'subscription_variation' ) ) && 'publish' === wcs_get_objects_property( $product, 'post_status' ); break; case 'grouped' : - $is_product_switchable = ( WC_Subscriptions_Product::get_parent_ids( $product ) ) ? true : false; + $is_product_switchable = (bool) WC_Subscriptions_Product::get_visible_grouped_parent_product_ids( $product ); break; case 'variable_grouped' : - $is_product_switchable = ( $product->is_type( array( 'variable-subscription', 'subscription_variation' ) ) || WC_Subscriptions_Product::get_parent_ids( $product ) ) ? true : false; + $is_product_switchable = ( $product->is_type( array( 'variable-subscription', 'subscription_variation' ) ) && 'publish' === wcs_get_objects_property( $product, 'post_status' ) ) || WC_Subscriptions_Product::get_visible_grouped_parent_product_ids( $product ); break; case 'no' : default: diff --git a/includes/wcs-time-functions.php b/includes/wcs-time-functions.php index 60d7fe6..1b54c3e 100755 --- a/includes/wcs-time-functions.php +++ b/includes/wcs-time-functions.php @@ -266,8 +266,8 @@ function wcs_add_months( $from_timestamp, $months_to_add ) { * * @param int $start_timestamp A Unix timestamp * @param int $end_timestamp A Unix timestamp at some time in the future - * @param string $end_timestamp A unit of time, either day, week month or year. - * @param string $unit_of_time A rounding method, either ceil (default) or floor for anything else + * @param string $unit_of_time A unit of time, either day, week month or year. + * @param string $rounding_method A rounding method, either ceil (default) or floor for anything else * @since 2.0 */ function wcs_estimate_periods_between( $start_timestamp, $end_timestamp, $unit_of_time = 'month', $rounding_method = 'ceil' ) { diff --git a/includes/wcs-user-functions.php b/includes/wcs-user-functions.php index 0249f99..93d3e3e 100755 --- a/includes/wcs-user-functions.php +++ b/includes/wcs-user-functions.php @@ -174,16 +174,21 @@ function wcs_get_users_subscriptions( $user_id = 0 ) { $user_id = get_current_user_id(); } - $subscriptions = apply_filters( 'wcs_pre_get_users_subscriptions', array(), $user_id ); + $subscriptions = array(); + + if ( has_filter( 'wcs_pre_get_users_subscriptions' ) ) { + wcs_deprecated_function( 'The "wcs_pre_get_users_subscriptions" hook should no longer be used. A persistent caching layer is now in place. Because of this, "wcs_pre_get_users_subscriptions"', '2.3.0' ); + $subscriptions = apply_filters( 'wcs_pre_get_users_subscriptions', $subscriptions, $user_id ); + } if ( empty( $subscriptions ) && 0 !== $user_id && ! empty( $user_id ) ) { - $post_ids = wcs_get_cached_user_subscription_ids( $user_id ); + $subscription_ids = WCS_Customer_Store::instance()->get_users_subscription_ids( $user_id ); - foreach ( $post_ids as $post_id ) { - $subscription = wcs_get_subscription( $post_id ); + foreach ( $subscription_ids as $subscription_id ) { + $subscription = wcs_get_subscription( $subscription_id ); if ( $subscription ) { - $subscriptions[ $post_id ] = $subscription; + $subscriptions[ $subscription_id ] = $subscription; } } } @@ -201,24 +206,8 @@ function wcs_get_users_subscriptions( $user_id = 0 ) { * @return array Array of Subscription IDs. */ function wcs_get_users_subscription_ids( $user_id ) { - $query = new WP_Query(); - - return $query->query( array( - 'post_type' => 'shop_subscription', - 'posts_per_page' => -1, - 'post_status' => 'any', - 'orderby' => 'date', - 'order' => 'desc', - 'fields' => 'ids', - 'no_found_rows' => true, - 'ignore_sticky_posts' => true, - 'meta_query' => array( - array( - 'key' => '_customer_user', - 'value' => $user_id, - ), - ), - ) ); + wcs_deprecated_function( __FUNCTION__, '2.3.0', 'WCS_Customer_Store::instance()->get_users_subscription_ids()' ); + return WCS_Customer_Store::instance()->get_users_subscription_ids( $user_id ); } /** @@ -231,23 +220,15 @@ function wcs_get_users_subscription_ids( $user_id ) { * @return array Array of subscription IDs. */ function wcs_get_cached_user_subscription_ids( $user_id = 0 ) { + wcs_deprecated_function( __FUNCTION__, '2.3.0', 'WCS_Customer_Store::instance()->get_users_subscription_ids()' ); + $user_id = absint( $user_id ); + if ( 0 === $user_id ) { $user_id = get_current_user_id(); } - // If the user ID is still zero, bail early. - if ( 0 === $user_id ) { - return apply_filters( 'wcs_get_cached_users_subscription_ids', array(), $user_id ); - } - - $subscription_ids = WC_Subscriptions::$cache->cache_and_get( - "wcs_user_subscriptions_{$user_id}", - 'wcs_get_users_subscription_ids', - array( $user_id ) - ); - - return apply_filters( 'wcs_get_cached_users_subscription_ids', $subscription_ids, $user_id ); + return WCS_Customer_Store::instance()->get_users_subscription_ids( $user_id ); } /** @@ -322,6 +303,11 @@ function wcs_can_user_put_subscription_on_hold( $subscription, $user = '' ) { * Retrieve available actions that a user can perform on the subscription * * @since 2.0 + * + * @param WC_Subscription $subscription The subscription. + * @param int $user_id The user. + * + * @return array */ function wcs_get_all_user_actions_for_subscription( $subscription, $user_id ) { diff --git a/languages/woocommerce-subscriptions.pot b/languages/woocommerce-subscriptions.pot index 8ebd434..e951398 100755 --- a/languages/woocommerce-subscriptions.pot +++ b/languages/woocommerce-subscriptions.pot @@ -2,10 +2,10 @@ # This file is distributed under the same license as the WooCommerce Subscriptions package. msgid "" msgstr "" -"Project-Id-Version: WooCommerce Subscriptions 2.2.21\n" +"Project-Id-Version: WooCommerce Subscriptions 2.3.2\n" "Report-Msgid-Bugs-To: " "https://github.com/Prospress/woocommerce-subscriptions/issues\n" -"POT-Creation-Date: 2018-05-30 06:00:10+00:00\n" +"POT-Creation-Date: 2018-07-10 05:08:52+00:00\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -15,74 +15,78 @@ msgstr "" "X-Generator: grunt-wp-i18n 0.5.4\n" "Language: en_US\n" -#: includes/admin/class-wc-subscriptions-admin.php:179 +#: includes/abstracts/abstract-wcs-related-order-store.php:138 +msgid "Invalid relation type: %s. Order relationship type must be one of: %s." +msgstr "" + +#: includes/admin/class-wc-subscriptions-admin.php:181 msgid "Simple subscription" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:180 +#: includes/admin/class-wc-subscriptions-admin.php:182 msgid "Variable subscription" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:198 +#: includes/admin/class-wc-subscriptions-admin.php:200 msgid "Choose the subscription price, billing interval and period." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:211 +#: includes/admin/class-wc-subscriptions-admin.php:213 #: templates/admin/html-variation-price.php:44 #. translators: placeholder is a currency symbol / code msgid "Subscription price (%s)" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:214 +#: includes/admin/class-wc-subscriptions-admin.php:216 msgid "Subscription interval" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:220 -#: includes/admin/class-wc-subscriptions-admin.php:356 +#: includes/admin/class-wc-subscriptions-admin.php:222 +#: includes/admin/class-wc-subscriptions-admin.php:358 msgid "Subscription period" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:234 -#: includes/admin/class-wc-subscriptions-admin.php:357 +#: includes/admin/class-wc-subscriptions-admin.php:236 +#: includes/admin/class-wc-subscriptions-admin.php:359 #: templates/admin/html-variation-price.php:66 msgid "Expire after" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:237 +#: includes/admin/class-wc-subscriptions-admin.php:239 msgid "" "Automatically expire the subscription after this length of time. This " "length is in addition to any free trial or amount of time provided before a " "synchronised first renewal date." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:246 +#: includes/admin/class-wc-subscriptions-admin.php:248 #: templates/admin/html-variation-price.php:20 #. translators: %s is a currency symbol / code msgid "Sign-up fee (%s)" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:248 +#: includes/admin/class-wc-subscriptions-admin.php:250 msgid "" "Optionally include an amount to be charged at the outset of the " "subscription. The sign-up fee will be charged immediately, even if the " "product has a free trial or the payment dates are synced." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:260 +#: includes/admin/class-wc-subscriptions-admin.php:262 #: templates/admin/html-variation-price.php:25 msgid "Free trial" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:263 +#: includes/admin/class-wc-subscriptions-admin.php:265 #: templates/admin/deprecated/html-variation-price.php:115 msgid "Subscription Trial Period" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:295 +#: includes/admin/class-wc-subscriptions-admin.php:297 msgid "One time shipping" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:296 +#: includes/admin/class-wc-subscriptions-admin.php:298 msgid "" "Shipping for subscription products is normally charged on the initial order " "and all renewal orders. Enable this to only charge shipping once on the " @@ -90,53 +94,57 @@ msgid "" "not have a free trial or a synced renewal date." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:353 +#: includes/admin/class-wc-subscriptions-admin.php:355 msgid "Subscription pricing" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:354 +#: includes/admin/class-wc-subscriptions-admin.php:356 msgid "Subscription sign-up fee" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:355 +#: includes/admin/class-wc-subscriptions-admin.php:357 msgid "Subscription billing interval" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:358 +#: includes/admin/class-wc-subscriptions-admin.php:360 msgid "Free trial length" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:359 +#: includes/admin/class-wc-subscriptions-admin.php:361 msgid "Free trial period" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:680 +#: includes/admin/class-wc-subscriptions-admin.php:682 msgid "" "Unable to change subscription status to \"%s\". Please assign a customer to " "the subscription to activate it." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:722 +#: includes/admin/class-wc-subscriptions-admin.php:724 msgid "" "Trashing this order will also trash the subscriptions purchased with the " "order." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:735 +#: includes/admin/class-wc-subscriptions-admin.php:737 msgid "Enter the new period, either day, week, month or year:" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:736 +#: includes/admin/class-wc-subscriptions-admin.php:738 msgid "Enter a new length (e.g. 5):" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:737 +#: includes/admin/class-wc-subscriptions-admin.php:739 msgid "" "Enter a new interval as a single number (e.g. to charge every 2nd month, " "enter 2):" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:742 +#: includes/admin/class-wc-subscriptions-admin.php:740 +msgid "Delete all variations without a subscription" +msgstr "" + +#: includes/admin/class-wc-subscriptions-admin.php:745 msgid "" "You are about to trash one or more orders which contain a subscription.\n" "\n" @@ -144,7 +152,7 @@ msgid "" "orders." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:755 +#: includes/admin/class-wc-subscriptions-admin.php:758 msgid "" "WARNING: Bad things are about to happen!\n" "\n" @@ -156,13 +164,13 @@ msgid "" "gateway." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:756 +#: includes/admin/class-wc-subscriptions-admin.php:759 msgid "" "You are deleting a subscription item. You will also need to manually cancel " "and trash the subscription on the Manage Subscriptions screen." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:763 +#: includes/admin/class-wc-subscriptions-admin.php:766 msgid "" "Warning: Deleting a user will also delete the user's subscriptions. The " "user's orders will remain but be reassigned to the 'Guest' user.\n" @@ -171,61 +179,61 @@ msgid "" "subscriptions?" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:826 +#: includes/admin/class-wc-subscriptions-admin.php:829 msgid "Active subscriber?" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:869 +#: includes/admin/class-wc-subscriptions-admin.php:872 msgid "Manage Subscriptions" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:873 -#: woocommerce-subscriptions.php:240 +#: includes/admin/class-wc-subscriptions-admin.php:876 +#: woocommerce-subscriptions.php:312 msgid "Search Subscriptions" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:893 -#: includes/admin/class-wc-subscriptions-admin.php:989 +#: includes/admin/class-wc-subscriptions-admin.php:896 +#: includes/admin/class-wc-subscriptions-admin.php:992 #: includes/admin/class-wcs-admin-reports.php:51 -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:658 -#: includes/class-wcs-query.php:102 includes/class-wcs-query.php:123 -#: includes/class-wcs-query.php:244 +#: includes/admin/class-wcs-admin-system-status.php:55 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:689 +#: includes/class-wcs-query.php:108 includes/class-wcs-query.php:129 +#: includes/class-wcs-query.php:248 #: includes/privacy/class-wcs-privacy-exporters.php:51 -#: templates/admin/status.php:21 woocommerce-subscriptions.php:231 -#: woocommerce-subscriptions.php:244 +#: woocommerce-subscriptions.php:303 woocommerce-subscriptions.php:316 msgid "Subscriptions" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1029 +#: includes/admin/class-wc-subscriptions-admin.php:1032 msgid "Button Text" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1036 +#: includes/admin/class-wc-subscriptions-admin.php:1039 msgid "Add to Cart Button Text" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1037 +#: includes/admin/class-wc-subscriptions-admin.php:1040 msgid "" "A product displays a button with the text \"Add to Cart\". By default, a " "subscription changes this to \"Sign Up Now\". You can customise the button " "text for subscriptions here." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1041 -#: includes/admin/class-wc-subscriptions-admin.php:1052 +#: includes/admin/class-wc-subscriptions-admin.php:1044 +#: includes/admin/class-wc-subscriptions-admin.php:1055 #: includes/class-wc-product-subscription-variation.php:98 #: includes/class-wc-product-subscription.php:72 -#: includes/class-wc-product-variable-subscription.php:63 +#: includes/class-wc-product-variable-subscription.php:73 #: includes/class-wc-subscriptions-product.php:99 -#: woocommerce-subscriptions.php:516 +#: woocommerce-subscriptions.php:614 msgid "Sign Up Now" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1047 +#: includes/admin/class-wc-subscriptions-admin.php:1050 msgid "Place Order Button Text" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1048 +#: includes/admin/class-wc-subscriptions-admin.php:1051 msgid "" "Use this field to customise the text displayed on the checkout button when " "an order contains a subscription. Normally the checkout submission button " @@ -233,11 +241,11 @@ msgid "" "changed to \"Sign Up Now\"." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1060 +#: includes/admin/class-wc-subscriptions-admin.php:1063 msgid "Roles" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1063 +#: includes/admin/class-wc-subscriptions-admin.php:1066 #. translators: placeholders are tags msgid "" "Choose the default roles to assign to active and inactive subscribers. For " @@ -246,46 +254,46 @@ msgid "" "allocated these roles to prevent locking out administrators." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1068 +#: includes/admin/class-wc-subscriptions-admin.php:1071 msgid "Subscriber Default Role" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1069 +#: includes/admin/class-wc-subscriptions-admin.php:1072 msgid "" "When a subscription is activated, either manually or after a successful " "purchase, new users will be assigned this role." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1080 +#: includes/admin/class-wc-subscriptions-admin.php:1083 msgid "Inactive Subscriber Role" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1081 +#: includes/admin/class-wc-subscriptions-admin.php:1084 msgid "" "If a subscriber's subscription is manually cancelled or expires, she will " "be assigned this role." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1101 +#: includes/admin/class-wc-subscriptions-admin.php:1104 msgid "Manual Renewal Payments" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1102 +#: includes/admin/class-wc-subscriptions-admin.php:1105 msgid "Accept Manual Renewals" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1107 +#: includes/admin/class-wc-subscriptions-admin.php:1110 #. translators: placeholders are opening and closing link tags msgid "" "With manual renewals, a customer's subscription is put on-hold until they " "login and pay to renew it. %sLearn more%s." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1113 +#: includes/admin/class-wc-subscriptions-admin.php:1116 msgid "Turn off Automatic Payments" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1118 +#: includes/admin/class-wc-subscriptions-admin.php:1121 #. translators: placeholders are opening and closing link tags msgid "" "If you don't want new subscription purchases to automatically charge " @@ -294,11 +302,11 @@ msgid "" "more%s." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1133 +#: includes/admin/class-wc-subscriptions-admin.php:1136 msgid "Customer Suspensions" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1140 +#: includes/admin/class-wc-subscriptions-admin.php:1143 msgid "" "Set a maximum number of times a customer can suspend their account for each " "billing period. For example, for a value of 3 and a subscription billed " @@ -308,30 +316,30 @@ msgid "" "this to 0 to turn off the customer suspension feature completely." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1144 +#: includes/admin/class-wc-subscriptions-admin.php:1147 msgid "Mixed Checkout" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1145 +#: includes/admin/class-wc-subscriptions-admin.php:1148 msgid "Allow multiple subscriptions and products to be purchased simultaneously." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1149 +#: includes/admin/class-wc-subscriptions-admin.php:1152 msgid "" "Allow a subscription product to be purchased with other products and " "subscriptions in the same transaction." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1153 +#: includes/admin/class-wc-subscriptions-admin.php:1156 #: includes/upgrades/templates/wcs-about-2-0.php:108 msgid "Drip Downloadable Content" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1154 +#: includes/admin/class-wc-subscriptions-admin.php:1157 msgid "Enable dripping for downloadable content on subscription products." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1158 +#: includes/admin/class-wc-subscriptions-admin.php:1161 msgid "" "Enabling this grants access to new downloadable files added to a product " "only after the next renewal is processed.%sBy default, access to new " @@ -339,7 +347,7 @@ msgid "" "customer that has an active subscription with that product." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1194 +#: includes/admin/class-wc-subscriptions-admin.php:1197 #. translators: $1-$2: opening and closing tags, $3-$4: opening and #. closing tags msgid "" @@ -347,73 +355,73 @@ msgid "" "start selling subscriptions!%4$s" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1199 +#: includes/admin/class-wc-subscriptions-admin.php:1202 msgid "Add a Subscription Product" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1200 +#: includes/admin/class-wc-subscriptions-admin.php:1203 #: includes/upgrades/templates/wcs-about-2-0.php:35 #: includes/upgrades/templates/wcs-about.php:34 -#: woocommerce-subscriptions.php:1064 +#: woocommerce-subscriptions.php:1185 msgid "Settings" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1286 +#: includes/admin/class-wc-subscriptions-admin.php:1289 #. translators: placeholder is a number msgid "We can't find a subscription with ID #%d. Perhaps it was deleted?" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1319 -#: includes/admin/class-wc-subscriptions-admin.php:1324 +#: includes/admin/class-wc-subscriptions-admin.php:1322 +#: includes/admin/class-wc-subscriptions-admin.php:1327 #. translators: placeholders are opening link tag, ID of sub, and closing link #. tag msgid "Showing orders for %sSubscription %s%s" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1348 +#: includes/admin/class-wc-subscriptions-admin.php:1351 #. translators: number of 1$: days, 2$: weeks, 3$: months, 4$: years msgid "The trial period can not exceed: %1s, %2s, %3s or %4s." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1353 +#: includes/admin/class-wc-subscriptions-admin.php:1356 #. translators: placeholder is a time period (e.g. "4 weeks") msgid "The trial period can not exceed %s." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1412 -#: includes/admin/class-wc-subscriptions-admin.php:1448 -#: includes/admin/class-wc-subscriptions-admin.php:1501 -#: includes/admin/reports/class-wcs-report-cache-manager.php:340 +#: includes/admin/class-wc-subscriptions-admin.php:1419 +#: includes/admin/class-wc-subscriptions-admin.php:1472 +#: includes/admin/class-wcs-admin-system-status.php:94 +#: includes/admin/reports/class-wcs-report-cache-manager.php:341 msgid "Yes" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1412 -#: includes/admin/class-wc-subscriptions-admin.php:1448 -#: includes/admin/reports/class-wcs-report-cache-manager.php:340 +#: includes/admin/class-wc-subscriptions-admin.php:1419 +#: includes/admin/class-wcs-admin-system-status.php:94 +#: includes/admin/reports/class-wcs-report-cache-manager.php:341 msgid "No" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1484 +#: includes/admin/class-wc-subscriptions-admin.php:1455 msgid "Automatic Recurring Payments" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1501 +#: includes/admin/class-wc-subscriptions-admin.php:1472 msgid "" "Supports automatic renewal payments with the WooCommerce Subscriptions " "extension." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1581 +#: includes/admin/class-wc-subscriptions-admin.php:1552 msgid "Subscription items can no longer be edited." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1585 +#: includes/admin/class-wc-subscriptions-admin.php:1556 msgid "" "This subscription is no longer editable because the payment gateway does " "not allow modification of recurring amounts." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1604 +#: includes/admin/class-wc-subscriptions-admin.php:1575 #. translators: $1-2: opening and closing tags of a link that takes to Woo #. marketplace / Stripe product page msgid "" @@ -422,18 +430,18 @@ msgid "" "the %1$sfree Stripe extension%2$s." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1609 +#: includes/admin/class-wc-subscriptions-admin.php:1580 msgid "Recurring Payments" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1617 +#: includes/admin/class-wc-subscriptions-admin.php:1588 #. translators: placeholders are opening and closing link tags msgid "" "Payment gateways which don't support automatic recurring payments can be " "used to process %smanual subscription renewal payments%s." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1624 +#: includes/admin/class-wc-subscriptions-admin.php:1595 #. translators: $1-$2: opening and closing tags. Link to documents->payment #. gateways, 3$-4$: opening and closing tags. Link to WooCommerce extensions #. shop page @@ -442,38 +450,42 @@ msgid "" "the official %3$sWooCommerce Marketplace%4$s." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:62 -#: includes/admin/class-wcs-admin-meta-boxes.php:66 +#: includes/admin/class-wc-subscriptions-admin.php:1697 +msgid "Note that purchasing a subscription still requires an account." +msgstr "" + +#: includes/admin/class-wcs-admin-meta-boxes.php:63 +#: includes/admin/class-wcs-admin-meta-boxes.php:67 #: templates/myaccount/related-orders.php:15 msgid "Related Orders" msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:105 +#: includes/admin/class-wcs-admin-meta-boxes.php:107 msgid "Please enter a start date in the past." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:106 +#: includes/admin/class-wcs-admin-meta-boxes.php:108 msgid "Please enter a date at least one hour into the future." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:107 +#: includes/admin/class-wcs-admin-meta-boxes.php:109 msgid "Please enter a date after the trial end." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:108 -#: includes/admin/class-wcs-admin-meta-boxes.php:109 +#: includes/admin/class-wcs-admin-meta-boxes.php:110 +#: includes/admin/class-wcs-admin-meta-boxes.php:111 msgid "Please enter a date after the start date." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:110 +#: includes/admin/class-wcs-admin-meta-boxes.php:112 msgid "Please enter a date before the next payment." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:111 +#: includes/admin/class-wcs-admin-meta-boxes.php:113 msgid "Please enter a date after the next payment." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:112 +#: includes/admin/class-wcs-admin-meta-boxes.php:114 msgid "" "Are you sure you want to process a renewal?\n" "\n" @@ -481,7 +493,7 @@ msgid "" "are enabled)." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:121 +#: includes/admin/class-wcs-admin-meta-boxes.php:124 msgid "" "Are you sure you want to retry payment for this renewal order?\n" "\n" @@ -489,26 +501,34 @@ msgid "" "emails are enabled)." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:140 +#: includes/admin/class-wcs-admin-meta-boxes.php:153 msgid "Process renewal" msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:143 +#: includes/admin/class-wcs-admin-meta-boxes.php:157 msgid "Create pending renewal order" msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:146 +#: includes/admin/class-wcs-admin-meta-boxes.php:159 +msgid "Create pending parent order" +msgstr "" + +#: includes/admin/class-wcs-admin-meta-boxes.php:162 msgid "Retry Renewal Payment" msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:160 +#: includes/admin/class-wcs-admin-meta-boxes.php:176 msgid "Process renewal order action requested by admin." msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:179 +#: includes/admin/class-wcs-admin-meta-boxes.php:200 msgid "Create pending renewal order requested by admin action." msgstr "" +#: includes/admin/class-wcs-admin-meta-boxes.php:229 +msgid "Create pending parent order requested by admin action." +msgstr "" + #: includes/admin/class-wcs-admin-post-types.php:201 msgid "Search for a product…" msgstr "" @@ -548,7 +568,7 @@ msgstr "" #: templates/emails/subscription-info.php:18 #: templates/myaccount/my-subscriptions.php:25 #: templates/myaccount/related-subscriptions.php:20 -#: woocommerce-subscriptions.php:232 +#: woocommerce-subscriptions.php:304 msgid "Subscription" msgstr "" @@ -581,12 +601,12 @@ msgid "End Date" msgstr "" #: includes/admin/class-wcs-admin-post-types.php:458 -#: includes/wcs-user-functions.php:343 +#: includes/wcs-user-functions.php:329 msgid "Reactivate" msgstr "" #: includes/admin/class-wcs-admin-post-types.php:459 -#: includes/wcs-user-functions.php:338 +#: includes/wcs-user-functions.php:324 msgid "Suspend" msgstr "" @@ -601,12 +621,12 @@ msgid "Delete Permanently" msgstr "" #: includes/admin/class-wcs-admin-post-types.php:474 -#: includes/class-wc-subscriptions-product.php:738 +#: includes/class-wc-subscriptions-product.php:746 msgid "Restore this item from the Trash" msgstr "" #: includes/admin/class-wcs-admin-post-types.php:474 -#: includes/class-wc-subscriptions-product.php:739 +#: includes/class-wc-subscriptions-product.php:747 msgid "Restore" msgstr "" @@ -649,61 +669,61 @@ msgstr[1] "" msgid "Via %s" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:602 +#: includes/admin/class-wcs-admin-post-types.php:624 msgid "Y/m/d g:i:s A" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:605 +#: includes/admin/class-wcs-admin-post-types.php:627 msgid "" "This date should be treated as an estimate only. The payment gateway for " "this subscription controls when payments are processed." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:878 -#: includes/admin/class-wcs-admin-post-types.php:881 -#: includes/admin/class-wcs-admin-post-types.php:884 +#: includes/admin/class-wcs-admin-post-types.php:830 +#: includes/admin/class-wcs-admin-post-types.php:833 +#: includes/admin/class-wcs-admin-post-types.php:836 msgid "Subscription updated." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:879 +#: includes/admin/class-wcs-admin-post-types.php:831 msgid "Custom field updated." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:880 +#: includes/admin/class-wcs-admin-post-types.php:832 msgid "Custom field deleted." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:885 +#: includes/admin/class-wcs-admin-post-types.php:837 msgid "Subscription saved." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:886 +#: includes/admin/class-wcs-admin-post-types.php:838 msgid "Subscription submitted." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:888 +#: includes/admin/class-wcs-admin-post-types.php:840 #. translators: php date string msgid "Subscription scheduled for: %1$s." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:889 +#: includes/admin/class-wcs-admin-post-types.php:841 msgid "Subscription draft updated." msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:925 +#: includes/admin/class-wcs-admin-post-types.php:877 msgid "Any Payment Method" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:926 +#: includes/admin/class-wcs-admin-post-types.php:878 msgid "None" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:1119 +#: includes/admin/class-wcs-admin-post-types.php:1071 #. translators: 1: user display name 2: user ID 3: user email msgid "%1$s (#%2$s – %3$s)" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:1126 +#: includes/admin/class-wcs-admin-post-types.php:1078 #: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:79 msgid "Search for a customer…" msgstr "" @@ -737,6 +757,43 @@ msgstr "" msgid "WooCommerce" msgstr "" +#: includes/admin/class-wcs-admin-system-status.php:56 +msgid "This section shows any information about Subscriptions." +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:60 +msgid "Store Setup" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:61 +msgid "This section shows general information about the store." +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:65 +msgid "Subscriptions by Payment Gateway" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:66 +msgid "This section shows information about Subscription payment methods." +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:70 +msgid "Payment Gateway Support" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:71 +msgid "This section shows information about payment gateway feature support." +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:128 +msgid "%sLearn how to update%s" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:174 +#. translators: %1$s is the file version, %2$s is the core version +msgid "version %1$s is out of date. The core version is %2$s" +msgstr "" + #: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:54 msgid "Customer:" msgstr "" @@ -749,63 +806,79 @@ msgstr "" msgid "Subscription status:" msgstr "" +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:104 +msgid "Parent order: " +msgstr "" + #: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:106 +msgid "#%1$s" +msgstr "" + +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:112 +msgid "Parent order:" +msgstr "" + +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:118 +msgid "Select an order…" +msgstr "" + +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:128 msgid "Billing Details" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:107 -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:179 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:129 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:201 #: includes/payment-retry/class-wcs-retry-post-store.php:38 msgid "Edit" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:108 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:130 msgid "Load billing address" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:115 -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:117 -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:188 -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:190 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:137 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:139 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:210 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:212 msgid "Address" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:117 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:139 msgid "No billing address set." msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:137 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:159 #: includes/class-wcs-change-payment-method-admin.php:38 #: includes/class-wcs-change-payment-method-admin.php:51 msgid "Payment Method" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:178 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:200 msgid "Shipping Details" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:180 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:202 msgid "Copy from billing" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:181 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:203 msgid "Load shipping address" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:190 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:212 msgid "No shipping address set." msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:212 -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:242 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:234 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:264 msgid "Customer Provided Note" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:243 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:265 msgid "Customer's notes about the order" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:315 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:350 #. translators: placeholder is error message from the payment gateway or #. subscriptions when updating the status msgid "Error updating some information: %s" @@ -826,7 +899,7 @@ msgid "Relationship" msgstr "" #: includes/admin/meta-boxes/views/html-related-orders-table.php:19 -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:519 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:550 #: includes/admin/reports/class-wcs-report-subscription-payment-retry.php:173 #: includes/admin/reports/class-wcs-report-upcoming-recurring-revenue.php:205 #: templates/myaccount/related-orders.php:23 @@ -881,8 +954,7 @@ msgid "" msgstr "" #: includes/admin/meta-boxes/views/html-subscription-schedule.php:22 -#: includes/admin/meta-boxes/views/html-subscription-schedule.php:41 -msgid "Recurring:" +msgid "Payment:" msgstr "" #: includes/admin/meta-boxes/views/html-subscription-schedule.php:32 @@ -890,6 +962,10 @@ msgstr "" msgid "Billing Period" msgstr "" +#: includes/admin/meta-boxes/views/html-subscription-schedule.php:41 +msgid "Recurring:" +msgstr "" + #: includes/admin/meta-boxes/views/html-subscription-schedule.php:61 msgid "Timezone:" msgstr "" @@ -905,11 +981,11 @@ msgid "" "site's timezone." msgstr "" -#: includes/admin/reports/class-wcs-report-cache-manager.php:344 +#: includes/admin/reports/class-wcs-report-cache-manager.php:345 msgid "Cache Update Failures" msgstr "" -#: includes/admin/reports/class-wcs-report-cache-manager.php:346 +#: includes/admin/reports/class-wcs-report-cache-manager.php:348 #. translators: %d refers to the number of times we have detected cache update #. failures msgid "%d failures" @@ -1020,219 +1096,220 @@ msgstr "" msgid "No products found." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:84 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:89 msgid "Subscription Product" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:85 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:90 msgid "Subscription Count %s" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:85 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:90 msgid "" "The number of subscriptions that include this product as a line item and " "have a status other than pending or trashed." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:86 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:91 msgid "Average Recurring Line Total %s" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:86 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:91 msgid "The average line total for this product on each subscription." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:87 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:92 msgid "Average Lifetime Value %s" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:87 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:92 msgid "The average line total on all orders for this product line item." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-by-product.php:246 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:297 +#: includes/admin/reports/class-wcs-report-subscription-by-product.php:337 msgid "subscriptions" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:368 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:399 msgid "%s signup revenue in this period" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:369 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:400 msgid "" "The sum of all subscription parent orders, including other items, fees, tax " "and shipping." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:375 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:406 msgid "%s renewal revenue in this period" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:376 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:407 msgid "The sum of all renewal orders including tax and shipping." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:382 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:413 msgid "%s resubscribe revenue in this period" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:383 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:414 msgid "The sum of all resubscribe orders including tax and shipping." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:389 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:420 msgid "%s new subscriptions" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:390 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:421 msgid "" "The number of subscriptions created during this period, either by being " "manually created, imported or a customer placing an order." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:396 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:427 msgid "%s subscription signups" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:397 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:428 msgid "" "The number of subscription parent orders created during this period. This " "represents the new subscriptions created by customers placing an order via " "checkout." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:403 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:434 msgid "%s subscription resubscribes" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:404 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:435 msgid "The number of resubscribe orders processed during this period." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:410 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:441 msgid "%s subscription renewals" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:411 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:442 msgid "The number of renewal orders processed during this period." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:417 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:448 msgid "%s subscription switches" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:418 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:449 msgid "" "The number of subscriptions upgraded, downgraded or cross-graded during " "this period." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:424 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:455 msgid "%s subscription cancellations" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:425 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:456 msgid "" "The number of subscriptions cancelled by the customer or store manager " "during this period. The pre-paid term may not yet have ended during this " "period." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:431 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:462 msgid "%s subscriptions ended" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:432 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:463 msgid "" "The number of subscriptions which have either expired or reached the end of " "the prepaid term if it was previously cancelled." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:438 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:469 msgid "%s current subscriptions" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:439 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:470 msgid "" "The number of subscriptions during this period with an end date in the " "future and a status other than pending." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:455 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:486 msgid "%s net subscription gain" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:457 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:488 msgid "%s net subscription loss" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:462 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:493 msgid "Change in subscriptions between the start and end of the period." msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:476 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:507 #: includes/admin/reports/class-wcs-report-subscription-payment-retry.php:137 msgid "Year" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:477 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:508 #: includes/admin/reports/class-wcs-report-subscription-payment-retry.php:138 msgid "Last Month" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:478 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:509 #: includes/admin/reports/class-wcs-report-subscription-payment-retry.php:139 msgid "This Month" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:479 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:510 #: includes/admin/reports/class-wcs-report-subscription-payment-retry.php:140 msgid "Last 7 Days" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:523 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:554 #: includes/admin/reports/class-wcs-report-subscription-payment-retry.php:177 #: includes/admin/reports/class-wcs-report-upcoming-recurring-revenue.php:209 msgid "Export CSV" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:580 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:611 msgid "Switched subscriptions" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:596 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:627 msgid "New Subscriptions" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:612 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:643 msgid "Subscriptions signups" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:627 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:658 msgid "Number of resubscribes" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:642 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:673 msgid "Number of renewals" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:674 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:705 msgid "Subscriptions Ended" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:690 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:721 msgid "Cancellations" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:705 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:736 msgid "Signup Totals" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:725 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:756 msgid "Resubscribe Totals" msgstr "" -#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:745 +#: includes/admin/reports/class-wcs-report-subscription-events-by-date.php:776 msgid "Renewal Totals" msgstr "" @@ -1441,116 +1518,126 @@ msgstr "" msgid "Cannot create subscription: %s." msgstr "" -#: includes/class-wc-subscription.php:418 +#: includes/class-wc-subscription.php:398 msgid "Unable to change subscription status to \"%s\"." msgstr "" -#: includes/class-wc-subscription.php:520 +#: includes/class-wc-subscription.php:500 msgid "Unable to change subscription status to \"%s\". Exception: %s" msgstr "" -#: includes/class-wc-subscription.php:542 +#: includes/class-wc-subscription.php:522 #. translators: 1: old subscription status 2: new subscription status msgid "Status changed from %1$s to %2$s." msgstr "" -#: includes/class-wc-subscription.php:554 +#: includes/class-wc-subscription.php:534 #. translators: %s: new order status msgid "Status set to %s." msgstr "" -#: includes/class-wc-subscription.php:1148 +#: includes/class-wc-subscription.php:1085 #: includes/class-wc-subscriptions-manager.php:2279 #: includes/wcs-formatting-functions.php:228 #. translators: placeholder is human time diff (e.g. "3 weeks") msgid "In %s" msgstr "" -#: includes/class-wc-subscription.php:1151 +#: includes/class-wc-subscription.php:1088 #: includes/wcs-formatting-functions.php:231 #. translators: placeholder is human time diff (e.g. "3 weeks") msgid "%s ago" msgstr "" -#: includes/class-wc-subscription.php:1158 +#: includes/class-wc-subscription.php:1095 msgid "Not yet ended" msgstr "" -#: includes/class-wc-subscription.php:1161 +#: includes/class-wc-subscription.php:1098 msgid "Not cancelled" msgstr "" -#: includes/class-wc-subscription.php:1276 +#: includes/class-wc-subscription.php:1213 msgid "The start date of a subscription can not be deleted, only updated." msgstr "" -#: includes/class-wc-subscription.php:1280 +#: includes/class-wc-subscription.php:1217 msgid "The %s date of a subscription can not be deleted. You must delete the order." msgstr "" -#: includes/class-wc-subscription.php:1288 -#: includes/class-wc-subscription.php:2353 +#: includes/class-wc-subscription.php:1225 +#: includes/class-wc-subscription.php:2301 msgid "Subscription #%d: " msgstr "" -#: includes/class-wc-subscription.php:1694 +#: includes/class-wc-subscription.php:1631 msgid "Payment status marked complete." msgstr "" -#: includes/class-wc-subscription.php:1722 +#: includes/class-wc-subscription.php:1659 msgid "Payment failed." msgstr "" -#: includes/class-wc-subscription.php:1727 +#: includes/class-wc-subscription.php:1664 msgid "Subscription Cancelled: maximum number of failed payments reached." msgstr "" -#: includes/class-wc-subscription.php:1936 +#: includes/class-wc-subscription.php:1774 +msgid "" +"The \"all\" value for $order_type parameter is deprecated. It was a " +"misnomer, as it did not return resubscribe orders. It was also inconsistent " +"with order type values accepted by wcs_get_subscription_orders(). Use " +"array( \"parent\", \"renewal\", \"switch\" ) to maintain previous " +"behaviour, or \"any\" to receive all order types, including switch and " +"resubscribe." +msgstr "" + +#: includes/class-wc-subscription.php:1876 #: includes/class-wcs-change-payment-method-admin.php:155 msgid "Manual Renewal" msgstr "" -#: includes/class-wc-subscription.php:2015 +#: includes/class-wc-subscription.php:1955 msgid "Payment method meta must be an array." msgstr "" -#: includes/class-wc-subscription.php:2251 +#: includes/class-wc-subscription.php:2199 msgid "Invalid format. First parameter needs to be an array." msgstr "" -#: includes/class-wc-subscription.php:2255 +#: includes/class-wc-subscription.php:2203 msgid "Invalid data. First parameter was empty when passed to update_dates()." msgstr "" -#: includes/class-wc-subscription.php:2262 +#: includes/class-wc-subscription.php:2210 msgid "" "Invalid data. First parameter has a date that is not in the registered date " "types." msgstr "" -#: includes/class-wc-subscription.php:2326 +#: includes/class-wc-subscription.php:2274 msgid "The %s date must occur after the cancellation date." msgstr "" -#: includes/class-wc-subscription.php:2331 +#: includes/class-wc-subscription.php:2279 msgid "The %s date must occur after the last payment date." msgstr "" -#: includes/class-wc-subscription.php:2335 +#: includes/class-wc-subscription.php:2283 msgid "The %s date must occur after the next payment date." msgstr "" -#: includes/class-wc-subscription.php:2340 +#: includes/class-wc-subscription.php:2288 msgid "The %s date must occur after the trial end date." msgstr "" -#: includes/class-wc-subscription.php:2344 +#: includes/class-wc-subscription.php:2292 msgid "The %s date must occur after the start date." msgstr "" -#: includes/class-wc-subscription.php:2373 +#: includes/class-wc-subscription.php:2321 #: includes/class-wc-subscriptions-checkout.php:325 -#: includes/wcs-order-functions.php:288 +#: includes/wcs-order-functions.php:305 msgid "Backordered" msgstr "" @@ -1570,21 +1657,21 @@ msgstr "" msgid "Update the %1$s used for %2$sall%3$s of my active subscriptions" msgstr "" -#: includes/class-wc-subscriptions-cart.php:899 +#: includes/class-wc-subscriptions-cart.php:901 msgid "Please enter a valid postcode/ZIP." msgstr "" -#: includes/class-wc-subscriptions-cart.php:1070 +#: includes/class-wc-subscriptions-cart.php:1072 msgid "" "That subscription product can not be added to your cart as it already " "contains a subscription renewal." msgstr "" -#: includes/class-wc-subscriptions-cart.php:1158 +#: includes/class-wc-subscriptions-cart.php:1160 msgid "Invalid recurring shipping method." msgstr "" -#: includes/class-wc-subscriptions-cart.php:1947 +#: includes/class-wc-subscriptions-cart.php:1983 msgid "now" msgstr "" @@ -1631,6 +1718,7 @@ msgstr "" #: includes/class-wcs-cart-resubscribe.php:78 #: includes/class-wcs-cart-resubscribe.php:129 #: includes/class-wcs-user-change-status-handler.php:103 +#: includes/early-renewal/class-wcs-cart-early-renewal.php:96 msgid "That doesn't appear to be one of your subscriptions." msgstr "" @@ -1672,80 +1760,113 @@ msgstr "" msgid "Error %d: Unable to create order. Please try again." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:65 +#: includes/class-wc-subscriptions-coupon.php:151 msgid "Sign Up Fee Discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:66 +#: includes/class-wc-subscriptions-coupon.php:152 msgid "Sign Up Fee % Discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:67 +#: includes/class-wc-subscriptions-coupon.php:153 msgid "Recurring Product Discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:68 +#: includes/class-wc-subscriptions-coupon.php:154 msgid "Recurring Product % Discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:358 +#: includes/class-wc-subscriptions-coupon.php:444 msgid "" "Sorry, this coupon is only valid for an initial payment and the cart does " "not require an initial payment." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:364 +#: includes/class-wc-subscriptions-coupon.php:450 msgid "Sorry, this coupon is only valid for new subscriptions." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:369 +#: includes/class-wc-subscriptions-coupon.php:455 msgid "Sorry, this coupon is only valid for subscription products." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:375 +#: includes/class-wc-subscriptions-coupon.php:461 #. translators: 1$: coupon code that is being removed msgid "Sorry, the \"%1$s\" coupon is only valid for renewals." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:380 +#: includes/class-wc-subscriptions-coupon.php:466 msgid "" "Sorry, this coupon is only valid for subscription products with a sign-up " "fee." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:406 +#: includes/class-wc-subscriptions-coupon.php:492 msgid "" "Sorry, recurring coupons can only be applied to subscriptions or " "subscription orders." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:410 +#: includes/class-wc-subscriptions-coupon.php:496 #. translators: placeholder is coupon code msgid "" "Sorry, \"%s\" can only be applied to subscription parent orders which " "contain a product with signup fees." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:413 +#: includes/class-wc-subscriptions-coupon.php:499 msgid "Sorry, only recurring coupons can only be applied to subscriptions." msgstr "" -#: includes/class-wc-subscriptions-coupon.php:636 +#: includes/class-wc-subscriptions-coupon.php:669 msgid "Renewal % discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:637 +#: includes/class-wc-subscriptions-coupon.php:670 msgid "Renewal product discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:638 +#: includes/class-wc-subscriptions-coupon.php:671 msgid "Renewal cart discount" msgstr "" -#: includes/class-wc-subscriptions-coupon.php:655 +#: includes/class-wc-subscriptions-coupon.php:688 msgid "Renewal Discount" msgstr "" +#: includes/class-wc-subscriptions-coupon.php:866 +msgid "" +"Sorry, it seems there are no available payment methods which support the " +"recurring coupon you are using. Please contact us if you require assistance " +"or wish to make alternate arrangements." +msgstr "" + +#: includes/class-wc-subscriptions-coupon.php:881 +msgid "Active for x payments" +msgstr "" + +#: includes/class-wc-subscriptions-coupon.php:882 +msgid "Unlimited payments" +msgstr "" + +#: includes/class-wc-subscriptions-coupon.php:883 +msgid "" +"Coupon will be limited to the given number of payments. It will then be " +"automatically removed from the subscription. \"Payments\" also includes the " +"initial subscription payment." +msgstr "" + +#: includes/class-wc-subscriptions-coupon.php:1015 +#. translators: %d refers to the number of payments the coupon can be used for. +msgid "Active for %d payment" +msgid_plural "Active for %d payments" +msgstr[0] "" +msgstr[1] "" + +#: includes/class-wc-subscriptions-coupon.php:1019 +msgid "Active for unlimited payments" +msgstr "" + #: includes/class-wc-subscriptions-manager.php:123 msgid "Error: Unable to create renewal order with note \"%s\"" msgstr "" @@ -1867,12 +1988,18 @@ msgstr "" msgid "All orders types" msgstr "" -#: includes/class-wc-subscriptions-order.php:965 +#: includes/class-wc-subscriptions-order.php:972 #. translators: $1: opening link tag, $2: order number, $3: closing link tag msgid "Subscription cancelled for refunded order %1$s#%2$s%3$s." msgstr "" -#: includes/class-wc-subscriptions-product.php:319 +#: includes/class-wc-subscriptions-product.php:318 +#. translators: %1$s refers to the price. This string is meant to prefix +#. another string below, e.g. "$5 now, and $5 on March 15th each year" +msgid "%1$s now, and " +msgstr "" + +#: includes/class-wc-subscriptions-product.php:327 #: includes/wcs-formatting-functions.php:102 #: includes/wcs-formatting-functions.php:186 #. translators: 1$: recurring amount string, 2$: day of the week (e.g. "$10 @@ -1880,34 +2007,34 @@ msgstr "" msgid "%1$s every %2$s" msgstr "" -#: includes/class-wc-subscriptions-product.php:322 +#: includes/class-wc-subscriptions-product.php:330 #: includes/wcs-formatting-functions.php:111 #. translators: 1$: recurring amount string, 2$: period, 3$: day of the week #. (e.g. "$10 every 2nd week on Wednesday") msgid "%1$s every %2$s on %3$s" msgstr "" -#: includes/class-wc-subscriptions-product.php:329 +#: includes/class-wc-subscriptions-product.php:337 #: includes/wcs-formatting-functions.php:129 #. translators: placeholder is recurring amount msgid "%s on the last day of each month" msgstr "" -#: includes/class-wc-subscriptions-product.php:332 +#: includes/class-wc-subscriptions-product.php:340 #: includes/wcs-formatting-functions.php:132 #. translators: 1$: recurring amount, 2$: day of the month (e.g. "23rd") (e.g. #. "$5 every 23rd of each month") msgid "%1$s on the %2$s of each month" msgstr "" -#: includes/class-wc-subscriptions-product.php:337 +#: includes/class-wc-subscriptions-product.php:345 #: includes/wcs-formatting-functions.php:148 #. translators: 1$: recurring amount, 2$: interval (e.g. "3rd") (e.g. "$10 on #. the last day of every 3rd month") msgid "%1$s on the last day of every %2$s month" msgstr "" -#: includes/class-wc-subscriptions-product.php:340 +#: includes/class-wc-subscriptions-product.php:348 #: includes/wcs-formatting-functions.php:151 #. translators: 1$: on the, 2$: day of every, 3$: #. month (e.g. "$10 on the 23rd day of every 2nd month") @@ -1916,7 +2043,7 @@ msgstr "" msgid "%1$s on the %2$s day of every %3$s month" msgstr "" -#: includes/class-wc-subscriptions-product.php:347 +#: includes/class-wc-subscriptions-product.php:355 #: includes/wcs-formatting-functions.php:164 #. translators: 1$: on, 2$: , 3$: each year (e.g. "$15 on #. March 15th each year") @@ -1925,14 +2052,14 @@ msgstr "" msgid "%1$s on %2$s %3$s each year" msgstr "" -#: includes/class-wc-subscriptions-product.php:350 +#: includes/class-wc-subscriptions-product.php:358 #: includes/wcs-formatting-functions.php:173 #. translators: 1$: recurring amount, 2$: month (e.g. "March"), 3$: day of the #. month (e.g. "23rd") (e.g. "$15 on March 15th every 3rd year") msgid "%1$s on %2$s %3$s every %4$s year" msgstr "" -#: includes/class-wc-subscriptions-product.php:356 +#: includes/class-wc-subscriptions-product.php:364 #: includes/wcs-formatting-functions.php:184 #. translators: 1$: recurring amount, 2$: subscription period (e.g. "month" or #. "3 months") (e.g. "$15 / month" or "$15 every 2nd month") @@ -1941,32 +2068,32 @@ msgid_plural " %1$s every %2$s" msgstr[0] "" msgstr[1] "" -#: includes/class-wc-subscriptions-product.php:362 +#: includes/class-wc-subscriptions-product.php:370 #. translators: billing period (e.g. "every week") msgid "every %s" msgstr "" -#: includes/class-wc-subscriptions-product.php:370 +#: includes/class-wc-subscriptions-product.php:378 #: includes/wcs-formatting-functions.php:194 #. translators: 1$: subscription string (e.g. "$10 up front then $5 on March #. 23rd every 3rd year"), 2$: length (e.g. "4 years") msgid "%1$s for %2$s" msgstr "" -#: includes/class-wc-subscriptions-product.php:376 +#: includes/class-wc-subscriptions-product.php:384 #. translators: 1$: subscription string (e.g. "$15 on March 15th every 3 years #. for 6 years"), 2$: trial length (e.g.: "with 4 months free trial") msgid "%1$s with %2$s free trial" msgstr "" -#: includes/class-wc-subscriptions-product.php:381 +#: includes/class-wc-subscriptions-product.php:389 #. translators: 1$: subscription string (e.g. "$15 on March 15th every 3 years #. for 6 years with 2 months free trial"), 2$: signup fee price (e.g. "and a #. $30 sign-up fee") msgid "%1$s and a %2$s sign-up fee" msgstr "" -#: includes/class-wc-subscriptions-product.php:923 +#: includes/class-wc-subscriptions-product.php:952 msgid "" "This variation can not be removed because it is associated with active " "subscriptions. To remove this variation, please cancel and delete the " @@ -1982,18 +2109,18 @@ msgstr "" msgid "Subscription renewal orders cannot be cancelled." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:174 +#: includes/class-wc-subscriptions-switcher.php:171 msgid "" "You have a subscription to this product. Choosing a new subscription will " "replace your existing subscription." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:176 +#: includes/class-wc-subscriptions-switcher.php:173 msgid "Choose a new subscription." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:198 -#: includes/class-wc-subscriptions-switcher.php:1009 +#: includes/class-wc-subscriptions-switcher.php:195 +#: includes/class-wc-subscriptions-switcher.php:1006 msgid "" "Your cart contained an invalid subscription switch request. It has been " "removed." @@ -2003,13 +2130,13 @@ msgid_plural "" msgstr[0] "" msgstr[1] "" -#: includes/class-wc-subscriptions-switcher.php:240 +#: includes/class-wc-subscriptions-switcher.php:237 msgid "" "You have already subscribed to this product and it is limited to one per " "customer. You can not purchase the product again." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:249 +#: includes/class-wc-subscriptions-switcher.php:246 #. translators: 1$: is the "You have already subscribed to this product" #. notice, 2$-4$: opening/closing link tags, 3$: an order number msgid "" @@ -2017,186 +2144,197 @@ msgid "" "subscription." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:344 +#: includes/class-wc-subscriptions-switcher.php:341 msgid "Switching" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:347 +#: includes/class-wc-subscriptions-switcher.php:344 #. translators: placeholders are opening and closing link tags msgid "" "Allow subscribers to switch (upgrade or downgrade) between different " "subscriptions. %sLearn more%s." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:352 +#: includes/class-wc-subscriptions-switcher.php:349 msgid "Allow Switching" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:353 +#: includes/class-wc-subscriptions-switcher.php:350 msgid "" "Allow subscribers to switch between subscriptions combined in a grouped " "product, different variations of a Variable subscription or don't allow " "switching." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:369 +#: includes/class-wc-subscriptions-switcher.php:366 msgid "Prorate Recurring Payment" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:370 +#: includes/class-wc-subscriptions-switcher.php:367 msgid "" "When switching to a subscription with a different recurring payment or " "billing period, should the price paid for the existing billing period be " "prorated when switching to the new subscription?" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:387 +#: includes/class-wc-subscriptions-switcher.php:384 msgid "Prorate Sign up Fee" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:388 +#: includes/class-wc-subscriptions-switcher.php:385 msgid "" "When switching to a subscription with a sign up fee, you can require the " "customer pay only the gap between the existing subscription's sign up fee " "and the new subscription's sign up fee (if any)." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:403 +#: includes/class-wc-subscriptions-switcher.php:400 msgid "Prorate Subscription Length" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:404 +#: includes/class-wc-subscriptions-switcher.php:401 msgid "" "When switching to a subscription with a length, you can take into account " "the payments already completed by the customer when determining how many " "payments the subscriber needs to make for the new subscription." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:419 +#: includes/class-wc-subscriptions-switcher.php:416 msgid "Switch Button Text" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:420 +#: includes/class-wc-subscriptions-switcher.php:417 msgid "" "Customise the text displayed on the button next to the subscription on the " "subscriber's account page. The default is \"Switch Subscription\", but you " "may wish to change this to \"Upgrade\" or \"Change Subscription\"." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:424 -#: includes/class-wc-subscriptions-switcher.php:450 -#: includes/class-wc-subscriptions-switcher.php:2470 +#: includes/class-wc-subscriptions-switcher.php:421 +#: includes/class-wc-subscriptions-switcher.php:447 +#: includes/class-wc-subscriptions-switcher.php:2439 msgid "Upgrade or Downgrade" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:874 +#: includes/class-wc-subscriptions-switcher.php:871 msgid "Switch order cancelled due to a new switch order being created #%s." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:961 +#: includes/class-wc-subscriptions-switcher.php:958 msgid "Switch Order" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:976 +#: includes/class-wc-subscriptions-switcher.php:973 msgid "Switched Subscription" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1081 +#: includes/class-wc-subscriptions-switcher.php:1078 msgid "You can only switch to a subscription product." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1087 +#: includes/class-wc-subscriptions-switcher.php:1084 msgid "We can not find your old subscription item." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1109 +#: includes/class-wc-subscriptions-switcher.php:1106 msgid "You can not switch to the same subscription." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1156 +#: includes/class-wc-subscriptions-switcher.php:1153 msgid "" "You can not switch this subscription. It appears you do not own the " "subscription." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1197 +#: includes/class-wc-subscriptions-switcher.php:1194 msgid "There was an error locating the switch details." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1918 -#: includes/class-wc-subscriptions-switcher.php:2262 +#: includes/class-wc-subscriptions-switcher.php:1889 +#: includes/class-wc-subscriptions-switcher.php:2233 msgid "The original subscription item being switched cannot be found." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1920 +#: includes/class-wc-subscriptions-switcher.php:1891 msgid "The item on the switch order cannot be found." msgstr "" -#: includes/class-wc-subscriptions-switcher.php:2299 +#: includes/class-wc-subscriptions-switcher.php:2270 msgid "Failed to update the subscription shipping method." msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:47 +#: includes/class-wc-subscriptions-synchroniser.php:48 msgid "Synchronise renewals" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:48 +#: includes/class-wc-subscriptions-synchroniser.php:49 msgid "" "Align the payment date for all customers who purchase this subscription to " "a specific day of the week or month." msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:151 +#: includes/class-wc-subscriptions-synchroniser.php:207 msgid "Synchronisation" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:160 +#: includes/class-wc-subscriptions-synchroniser.php:216 msgid "Align Subscription Renewal Day" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:167 -msgid "Prorate First Payment" +#: includes/class-wc-subscriptions-synchroniser.php:223 +msgid "Prorate First Renewal" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:168 +#: includes/class-wc-subscriptions-synchroniser.php:224 msgid "" "If a subscription is synchronised to a specific day of the week, month or " "year, charge a prorated amount for the subscription at the time of sign up." msgstr "" #: includes/class-wc-subscriptions-synchroniser.php:239 +msgid "Sign-up grace period" +msgstr "" + +#: includes/class-wc-subscriptions-synchroniser.php:244 +msgid "" +"Subscriptions created within this many days prior to the Renewal Day will " +"not be charged at sign-up. Set to zero for all new Subscriptions to be " +"charged the full recurring amount. Must be a positive number." +msgstr "" + +#: includes/class-wc-subscriptions-synchroniser.php:305 msgid "Month for Synchronisation" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:596 +#: includes/class-wc-subscriptions-synchroniser.php:725 msgid "Do not synchronise" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:604 +#: includes/class-wc-subscriptions-synchroniser.php:733 #. translators: placeholder is a day of the week msgid "%s each week" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:610 +#: includes/class-wc-subscriptions-synchroniser.php:739 #. translators: placeholder is a number of day with language specific suffix #. applied (e.g. "1st", "3rd", "5th", etc...) msgid "%s day of the month" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:612 +#: includes/class-wc-subscriptions-synchroniser.php:741 msgid "Last day of the month" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:660 +#: includes/class-wc-subscriptions-synchroniser.php:789 msgid "Today!" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:667 +#: includes/class-wc-subscriptions-synchroniser.php:796 #. translators: placeholder is a date msgid "First payment prorated. Next payment: %s" msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:670 +#: includes/class-wc-subscriptions-synchroniser.php:799 #. translators: placeholder is a date msgid "First payment: %s" msgstr "" @@ -2213,32 +2351,49 @@ msgstr "" msgid "View and manage subscriptions" msgstr "" -#: includes/class-wcs-cached-data-manager.php:241 +#: includes/class-wcs-cached-data-manager.php:76 +msgid "Related order caching is now handled by %1$s." +msgstr "" + +#: includes/class-wcs-cached-data-manager.php:83 +msgid "Customer subscription caching is now handled by %1$s." +msgstr "" + +#: includes/class-wcs-cached-data-manager.php:107 +#: includes/class-wcs-cached-data-manager.php:237 +msgid "Customer subscription caching is now handled by %1$s and %2$s." +msgstr "" + +#: includes/class-wcs-cached-data-manager.php:124 +msgid "new related order methods in WCS_Related_Order_Store" +msgstr "" + +#: includes/class-wcs-cached-data-manager.php:222 msgid "Weekly" msgstr "" -#: includes/class-wcs-cart-initial-payment.php:56 -#: includes/class-wcs-cart-renewal.php:176 +#: includes/class-wcs-cart-initial-payment.php:59 +#: includes/class-wcs-cart-renewal.php:179 msgid "That doesn't appear to be your order." msgstr "" -#: includes/class-wcs-cart-renewal.php:204 +#: includes/class-wcs-cart-renewal.php:207 msgid "Complete checkout to renew your subscription." msgstr "" -#: includes/class-wcs-cart-renewal.php:285 +#: includes/class-wcs-cart-renewal.php:288 #. translators: placeholder is an item name msgid "" "The %s product has been deleted and can no longer be renewed. Please choose " "a new product or contact us for assistance." msgstr "" -#: includes/class-wcs-cart-renewal.php:319 +#: includes/class-wcs-cart-renewal.php:322 #. translators: %s is subscription's number msgid "Subscription #%s has not been added to the cart." msgstr "" -#: includes/class-wcs-cart-renewal.php:450 +#: includes/class-wcs-cart-renewal.php:455 msgid "" "We couldn't find the original subscription for an item in your cart. The " "item was removed." @@ -2248,7 +2403,7 @@ msgid_plural "" msgstr[0] "" msgstr[1] "" -#: includes/class-wcs-cart-renewal.php:457 +#: includes/class-wcs-cart-renewal.php:462 msgid "" "We couldn't find the original renewal order for an item in your cart. The " "item was removed." @@ -2258,7 +2413,7 @@ msgid_plural "" msgstr[0] "" msgstr[1] "" -#: includes/class-wcs-cart-renewal.php:732 +#: includes/class-wcs-cart-renewal.php:737 msgid "All linked subscription items have been removed from the cart." msgstr "" @@ -2267,6 +2422,7 @@ msgid "There was an error with your request to resubscribe. Please try again." msgstr "" #: includes/class-wcs-cart-resubscribe.php:74 +#: includes/early-renewal/class-wcs-cart-early-renewal.php:92 msgid "That subscription does not exist. Has it been deleted?" msgstr "" @@ -2363,23 +2519,29 @@ msgstr "" msgid "%s ending in %s" msgstr "" -#: includes/class-wcs-query.php:100 +#: includes/class-wcs-post-meta-cache-manager.php:198 +msgid "" +"Invalid update type: %s. Post update types supported are \"add\" or " +"\"delete\". Updates are done on post meta directly." +msgstr "" + +#: includes/class-wcs-query.php:106 msgid "Subscriptions (page %d)" msgstr "" -#: includes/class-wcs-query.php:121 +#: includes/class-wcs-query.php:127 msgid "My Subscription" msgstr "" -#: includes/class-wcs-query.php:245 +#: includes/class-wcs-query.php:249 msgid "Endpoint for the My Account → Subscriptions page" msgstr "" -#: includes/class-wcs-query.php:253 +#: includes/class-wcs-query.php:257 msgid "View subscription" msgstr "" -#: includes/class-wcs-query.php:254 +#: includes/class-wcs-query.php:258 msgid "Endpoint for the My Account → View Subscription page" msgstr "" @@ -2412,6 +2574,14 @@ msgid "" "not support removing an item." msgstr "" +#: includes/class-wcs-staging.php:34 +msgid "Payment processing skipped - renewal order created under staging site lock." +msgstr "" + +#: includes/class-wcs-staging.php:47 +msgid "staging" +msgstr "" + #: includes/class-wcs-user-change-status-handler.php:60 msgid "" "You can not reactivate that subscription until paying to renew it. Please " @@ -2451,6 +2621,107 @@ msgstr "" msgid " Subscription Switched" msgstr "" +#: includes/data-stores/class-wcs-customer-store-cached-cpt.php:54 +msgid "Generate Customer Subscription Cache" +msgstr "" + +#: includes/data-stores/class-wcs-customer-store-cached-cpt.php:54 +msgid "" +"This will generate the persistent cache for linking users with " +"subscriptions. The caches will be generated overtime in the background (via " +"Action Scheduler)." +msgstr "" + +#: includes/data-stores/class-wcs-customer-store-cached-cpt.php:55 +msgid "Delete Customer Subscription Cache" +msgstr "" + +#: includes/data-stores/class-wcs-customer-store-cached-cpt.php:55 +msgid "" +"This will clear the persistent cache of all of subscriptions stored against " +"users in your store. Expect slower performance of checkout, renewal and " +"other subscription related functions after taking this action. The caches " +"will be regenerated overtime as queries to find a given user's " +"subscriptions are run." +msgstr "" + +#: includes/data-stores/class-wcs-related-order-store-cached-cpt.php:69 +msgid "Generate Related Order Cache" +msgstr "" + +#: includes/data-stores/class-wcs-related-order-store-cached-cpt.php:69 +msgid "" +"This will generate the persistent cache of all renewal, switch, resubscribe " +"and other order types for all subscriptions in your store. The caches will " +"be generated overtime in the background (via Action Scheduler)." +msgstr "" + +#: includes/data-stores/class-wcs-related-order-store-cached-cpt.php:70 +msgid "Delete Related Order Cache" +msgstr "" + +#: includes/data-stores/class-wcs-related-order-store-cached-cpt.php:70 +msgid "" +"This will clear the persistent cache of all renewal, switch, resubscribe " +"and other order types for all subscriptions in your store. Expect slower " +"performance of checkout, renewal and other subscription related functions " +"after taking this action. The caches will be regenerated overtime as " +"related order queries are run." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:66 +msgid "Renew Now" +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:88 +msgid "There was an error with your request to renew. Please try again." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:100 +msgid "" +"You can not renew this subscription early. Please contact us if you need " +"assistance." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:104 +msgid "Complete checkout to renew now." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:224 +#. translators: placeholder contains a link to the order's edit screen. +msgid "Customer successfully renewed early with order %s." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:227 +#. translators: placeholder contains a link to the order's edit screen. +msgid "" +"Failed to update subscription dates after customer renewed early with order " +"%s." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:315 +msgid "Order %s created to record early renewal." +msgstr "" + +#: includes/early-renewal/class-wcs-cart-early-renewal.php:370 +msgid "Cancel" +msgstr "" + +#: includes/early-renewal/class-wcs-early-renewal-manager.php:44 +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:98 +msgid "Early Renewal" +msgstr "" + +#: includes/early-renewal/class-wcs-early-renewal-manager.php:45 +msgid "Accept Early Renewal Payments" +msgstr "" + +#: includes/early-renewal/class-wcs-early-renewal-manager.php:46 +msgid "" +"With early renewals enabled, customers can renew their subscriptions before " +"the next payment date." +msgstr "" + #: includes/emails/class-wcs-email-cancelled-subscription.php:27 msgid "Cancelled Subscription" msgstr "" @@ -2860,49 +3131,49 @@ msgstr "" msgid "PayPal API error - credentials are incorrect." msgstr "" -#: includes/payment-retry/class-wcs-retry-admin.php:46 +#: includes/payment-retry/class-wcs-retry-admin.php:48 msgid "Automatic Failed Payment Retries" msgstr "" -#: includes/payment-retry/class-wcs-retry-admin.php:97 +#: includes/payment-retry/class-wcs-retry-admin.php:99 msgid "%d Pending Payment Retry" msgid_plural "%d Pending Payment Retries" msgstr[0] "" msgstr[1] "" -#: includes/payment-retry/class-wcs-retry-admin.php:100 +#: includes/payment-retry/class-wcs-retry-admin.php:102 msgid "%d Processing Payment Retry" msgid_plural "%d Processing Payment Retries" msgstr[0] "" msgstr[1] "" -#: includes/payment-retry/class-wcs-retry-admin.php:103 +#: includes/payment-retry/class-wcs-retry-admin.php:105 msgid "%d Failed Payment Retry" msgid_plural "%d Failed Payment Retries" msgstr[0] "" msgstr[1] "" -#: includes/payment-retry/class-wcs-retry-admin.php:106 +#: includes/payment-retry/class-wcs-retry-admin.php:108 msgid "%d Successful Payment Retry" msgid_plural "%d Successful Payment Retries" msgstr[0] "" msgstr[1] "" -#: includes/payment-retry/class-wcs-retry-admin.php:109 +#: includes/payment-retry/class-wcs-retry-admin.php:111 msgid "%d Cancelled Payment Retry" msgid_plural "%d Cancelled Payment Retries" msgstr[0] "" msgstr[1] "" -#: includes/payment-retry/class-wcs-retry-admin.php:133 +#: includes/payment-retry/class-wcs-retry-admin.php:135 msgid "Retry Failed Payments" msgstr "" -#: includes/payment-retry/class-wcs-retry-admin.php:134 +#: includes/payment-retry/class-wcs-retry-admin.php:136 msgid "Enable automatic retry of failed recurring payments" msgstr "" -#: includes/payment-retry/class-wcs-retry-admin.php:138 +#: includes/payment-retry/class-wcs-retry-admin.php:140 msgid "" "Attempt to recover recurring revenue that would otherwise be lost due to " "payment methods being declined only temporarily. %sLearn more%s." @@ -2974,8 +3245,8 @@ msgid "Created Date" msgstr "" #: includes/privacy/class-wcs-privacy-exporters.php:79 -#: templates/checkout/recurring-totals.php:122 #: templates/checkout/recurring-totals.php:123 +#: templates/checkout/recurring-totals.php:124 msgid "Recurring Total" msgstr "" @@ -2991,11 +3262,11 @@ msgstr "" msgid "Browser User Agent" msgstr "" -#: includes/privacy/class-wcs-privacy-exporters.php:83 wcs-functions.php:258 +#: includes/privacy/class-wcs-privacy-exporters.php:83 wcs-functions.php:274 msgid "Billing Address" msgstr "" -#: includes/privacy/class-wcs-privacy-exporters.php:84 wcs-functions.php:257 +#: includes/privacy/class-wcs-privacy-exporters.php:84 wcs-functions.php:273 msgid "Shipping Address" msgstr "" @@ -3100,13 +3371,13 @@ msgstr "" msgid "N/A" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:292 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:314 #. translators: placeholder is a list of version numbers (e.g. "1.3 & 1.4 & #. 1.5") msgid "Database updated to version %s" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:315 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:337 #. translators: 1$: number of action scheduler hooks upgraded, 2$: #. "{execution_time}", will be replaced on front end with actual time msgid "" @@ -3114,51 +3385,137 @@ msgid "" "seconds)." msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:331 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:353 #. translators: 1$: number of subscriptions upgraded, 2$: "{execution_time}", #. will be replaced on front end with actual time it took msgid "Migrated %1$s subscriptions to the new structure (in %2$s seconds)." msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:344 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:366 #. translators: 1$: error message, 2$: opening link tag, 3$: closing link tag msgid "" "Unable to upgrade subscriptions.
    Error: %1$s
    Please refresh the " "page and try again. If problem persists, %2$scontact support%3$s." msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:599 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:621 msgid "Welcome to WooCommerce Subscriptions 2.1" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:599 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:621 msgid "About WooCommerce Subscriptions" msgstr "" +#: includes/upgrades/class-wc-subscriptions-upgrader.php:804 +msgid "" +"%1$sWarning!%2$s It appears that you have downgraded %1$sWooCommerce " +"Subscriptions%2$s from %3$s to %4$s. Downgrading the plugin in this way may " +"cause issues. Please update to %3$s or higher, or %5$sopen a new support " +"ticket%6$s for further assistance." +msgstr "" + +#: includes/upgrades/class-wcs-repair-suspended-paypal-subscriptions.php:49 +msgid "" +"Subscription suspended by Database repair script. This subscription was " +"suspended via PayPal." +msgstr "" + #: includes/upgrades/class-wcs-upgrade-2-2-7.php:60 msgid "Subscription end date in the past" msgstr "" -#: includes/upgrades/templates/wcs-about-2-0.php:20 -msgid "Welcome to Subscriptions 2.0" +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:85 +msgid "New Subscription Coupon Features" msgstr "" +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:86 +msgid "" +"Want to offer customers coupons which apply for 6 months? You can now " +"define the number of cycles discounts would be applied." +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:89 +msgid "New Signup Pricing Options for Synchronized Subscriptions" +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:90 +msgid "" +"Charge the full recurring price at the time of sign up for synchronized " +"subscriptions. Your customers can now receive their products straight away." +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:93 +msgid "Link Parent Orders to Subscriptions" +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:95 +#. translators: placeholders are opening and closing tags linking to +#. documentation. +msgid "" +"For subscriptions with no parent order, shop managers can now choose a " +"parent order via the Edit Subscription screen. This makes it possible to " +"set a parent order on %smanually created subscriptions%s. The order can " +"also be sent to customers to act as an invoice that needs to be paid to " +"activate the subscription." +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:99 +msgid "" +"Customers can now renew their subscriptions before the scheduled next " +"payment date. Why not use this to email your customers a coupon a month " +"before their annual subscription renewals to get access to that revenue " +"sooner?" +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:104 +#. translators: placeholder is Subscription version string ('2.3') +msgid "Welcome to Subscriptions %s" +msgstr "" + +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:111 +msgid "Learn More" +msgstr "" + +#: includes/upgrades/templates/update-welcome-notice.php:2 #: includes/upgrades/templates/wcs-about-2-0.php:23 #: includes/upgrades/templates/wcs-about.php:22 +#. translators: placeholder is Subscription version string ('2.3') msgid "Thank you for updating to the latest version of WooCommerce Subscriptions." msgstr "" +#: includes/upgrades/templates/update-welcome-notice.php:5 +#. translators: placeholder $1 is the Subscription version string ('2.3'), $2-3 +#. are opening and closing tags +msgid "" +"Version %1$s brings some great new features requested by store managers " +"just like you (and possibly even by %2$syou%3$s)." +msgstr "" + +#: includes/upgrades/templates/update-welcome-notice.php:6 +#: includes/upgrades/templates/wcs-about-2-0.php:25 +#: includes/upgrades/templates/wcs-about.php:24 +msgid "We hope you enjoy it!" +msgstr "" + +#: includes/upgrades/templates/update-welcome-notice.php:8 +msgid "What's New?" +msgstr "" + +#: includes/upgrades/templates/update-welcome-notice.php:16 +#. translators: placeholder is Subscription version string ('2.3') +msgid "Want to know more about %s and these new features?" +msgstr "" + +#: includes/upgrades/templates/wcs-about-2-0.php:20 +msgid "Welcome to Subscriptions 2.0" +msgstr "" + #: includes/upgrades/templates/wcs-about-2-0.php:24 msgid "" "Version 2.0 has been in development for more than a year. We've reinvented " "the extension to take into account 3 years of feedback from store managers." msgstr "" -#: includes/upgrades/templates/wcs-about-2-0.php:25 -#: includes/upgrades/templates/wcs-about.php:24 -msgid "We hope you enjoy it!" -msgstr "" - #: includes/upgrades/templates/wcs-about-2-0.php:31 #: includes/upgrades/templates/wcs-about.php:30 #. translators: placeholder is version number @@ -3486,8 +3843,8 @@ msgstr "" #: includes/upgrades/templates/wcs-about.php:109 msgid "" "That's not all we've working on for the last 12 months when it comes to " -"Subscriptions. We've also released free mini-extensions to help you get the " -"most from your subscription store." +"Subscriptions. We've also released mini-extensions to help you get the most " +"from your subscription store." msgstr "" #: includes/upgrades/templates/wcs-about.php:115 @@ -3502,7 +3859,7 @@ msgstr "" #: includes/upgrades/templates/wcs-about.php:117 msgid "" -"The free Gifting extension makes it possible for one person to purchase a " +"The Gifting extension makes it possible for one person to purchase a " "subscription product for someone else. It then shares control of the " "subscription between the purchaser and recipient, allowing both to manage " "the subscription over its lifecycle." @@ -3772,11 +4129,15 @@ msgid_plural "Shipping %d" msgstr[0] "" msgstr[1] "" -#: includes/wcs-cart-functions.php:235 +#: includes/wcs-cart-functions.php:217 +msgid "[Remove]" +msgstr "" + +#: includes/wcs-cart-functions.php:247 msgid "Free shipping coupon" msgstr "" -#: includes/wcs-cart-functions.php:340 +#: includes/wcs-cart-functions.php:352 #. translators: placeholder is a date msgid "First renewal: %s" msgstr "" @@ -3886,27 +4247,27 @@ msgstr "" msgid "MM" msgstr "" -#: includes/wcs-order-functions.php:327 +#: includes/wcs-order-functions.php:344 msgid "Subscription Renewal Order – %s" msgstr "" -#: includes/wcs-order-functions.php:330 +#: includes/wcs-order-functions.php:347 msgid "Resubscribe Order – %s" msgstr "" -#: includes/wcs-order-functions.php:349 +#: includes/wcs-order-functions.php:366 msgid "$type passed to the function was not a string." msgstr "" -#: includes/wcs-order-functions.php:354 +#: includes/wcs-order-functions.php:370 msgid "\"%s\" is not a valid new order type." msgstr "" -#: includes/wcs-order-functions.php:541 +#: includes/wcs-order-functions.php:557 msgid "Invalid data. No valid subscription / order was passed in." msgstr "" -#: includes/wcs-order-functions.php:545 +#: includes/wcs-order-functions.php:561 msgid "Invalid data. No valid item id was passed in." msgstr "" @@ -3934,7 +4295,7 @@ msgid_plural "a %s-year" msgstr[0] "" msgstr[1] "" -#: includes/wcs-user-functions.php:350 +#: includes/wcs-user-functions.php:336 #: templates/single-product/add-to-cart/subscription.php:43 #: templates/single-product/add-to-cart/variable-subscription.php:29 msgid "Resubscribe" @@ -4000,19 +4361,6 @@ msgstr "" msgid "Billing Period:" msgstr "" -#: templates/admin/status.php:22 -msgid "This section shows any information about Subscriptions." -msgstr "" - -#: templates/admin/status.php:74 -#. translators: %1$s is the file version, %2$s is the core version -msgid "version %1$s is out of date. The core version is %2$s" -msgstr "" - -#: templates/admin/status.php:87 -msgid "Learn how to update" -msgstr "" - #: templates/cart/cart-recurring-shipping.php:19 msgid "Recurring shipping options can be selected on checkout." msgstr "" @@ -4242,87 +4590,87 @@ msgstr "" msgid "Clear" msgstr "" -#: wcs-functions.php:230 +#: wcs-functions.php:246 msgid "Can not get status name. Status is not a string." msgstr "" -#: wcs-functions.php:253 +#: wcs-functions.php:269 msgid "Can not get address type display name. Address type is not a string." msgstr "" -#: wcs-functions.php:316 +#: wcs-functions.php:332 msgid "Date type is not a string." msgstr "" -#: wcs-functions.php:318 +#: wcs-functions.php:334 msgid "Date type can not be an empty string." msgstr "" -#: woocommerce-subscriptions.php:246 +#: woocommerce-subscriptions.php:318 msgid "This is where subscriptions are stored." msgstr "" -#: woocommerce-subscriptions.php:291 +#: woocommerce-subscriptions.php:363 msgid "No Subscriptions found" msgstr "" -#: woocommerce-subscriptions.php:293 +#: woocommerce-subscriptions.php:365 msgid "" "Subscriptions will appear here for you to view and manage once purchased by " "a customer." msgstr "" -#: woocommerce-subscriptions.php:295 +#: woocommerce-subscriptions.php:367 #. translators: placeholders are opening and closing link tags msgid "%sLearn more about managing subscriptions »%s" msgstr "" -#: woocommerce-subscriptions.php:297 +#: woocommerce-subscriptions.php:369 #. translators: placeholders are opening and closing link tags msgid "%sAdd a subscription product »%s" msgstr "" -#: woocommerce-subscriptions.php:425 +#: woocommerce-subscriptions.php:523 msgid "" "A subscription renewal has been removed from your cart. Multiple " "subscriptions can not be purchased at the same time." msgstr "" -#: woocommerce-subscriptions.php:431 +#: woocommerce-subscriptions.php:529 msgid "" "A subscription has been removed from your cart. Due to payment gateway " "restrictions, different subscription products can not be purchased at the " "same time." msgstr "" -#: woocommerce-subscriptions.php:437 +#: woocommerce-subscriptions.php:535 msgid "" "A subscription has been removed from your cart. Products and subscriptions " "can not be purchased at the same time." msgstr "" -#: woocommerce-subscriptions.php:585 woocommerce-subscriptions.php:602 +#: woocommerce-subscriptions.php:683 woocommerce-subscriptions.php:700 #. translators: placeholder is a number, this is for the teens #. translators: placeholder is a number, numbers ending in 4-9, 0 msgid "%sth" msgstr "" -#: woocommerce-subscriptions.php:590 +#: woocommerce-subscriptions.php:688 #. translators: placeholder is a number, numbers ending in 1 msgid "%sst" msgstr "" -#: woocommerce-subscriptions.php:594 +#: woocommerce-subscriptions.php:692 #. translators: placeholder is a number, numbers ending in 2 msgid "%snd" msgstr "" -#: woocommerce-subscriptions.php:598 +#: woocommerce-subscriptions.php:696 #. translators: placeholder is a number, numbers ending in 3 msgid "%srd" msgstr "" -#: woocommerce-subscriptions.php:628 +#: woocommerce-subscriptions.php:726 #. translators: 1$-2$: opening and closing tags, 3$-4$: link tags, #. takes to woocommerce plugin on wp.org, 5$-6$: opening and closing link tags, #. leads to plugins.php in admin @@ -4332,7 +4680,7 @@ msgid "" "%5$sinstall & activate WooCommerce »%6$s" msgstr "" -#: woocommerce-subscriptions.php:635 +#: woocommerce-subscriptions.php:733 #. translators: 1$-2$: opening and closing tags, 3$-4$: opening and #. closing link tags, leads to plugin admin msgid "" @@ -4341,11 +4689,24 @@ msgid "" "WooCommerce to version 2.4 or newer »%4$s" msgstr "" -#: woocommerce-subscriptions.php:661 +#: woocommerce-subscriptions.php:759 msgid "Variable Subscription" msgstr "" -#: woocommerce-subscriptions.php:857 +#: woocommerce-subscriptions.php:902 +msgid "" +"%1$sWarning!%2$s We can see the %1$sWooCommerce Subscriptions Early " +"Renewal%2$s plugin is active. Version %3$s of %1$sWooCommerce " +"Subscriptions%2$s comes with that plugin's functionality packaged into the " +"core plugin. Please deactivate WooCommerce Subscriptions Early Renewal to " +"avoid any conflicts." +msgstr "" + +#: woocommerce-subscriptions.php:905 +msgid "Installed Plugins" +msgstr "" + +#: woocommerce-subscriptions.php:978 #. translators: 1$-2$: opening and closing tags, 3$-4$: opening and #. closing link tags. Leads to duplicate site article on docs msgid "" @@ -4355,19 +4716,19 @@ msgid "" "environment. %3$sLearn more »%4$s." msgstr "" -#: woocommerce-subscriptions.php:859 +#: woocommerce-subscriptions.php:980 msgid "Quit nagging me (but don't enable automatic payments)" msgstr "" -#: woocommerce-subscriptions.php:860 +#: woocommerce-subscriptions.php:981 msgid "Enable automatic payments" msgstr "" -#: woocommerce-subscriptions.php:1066 +#: woocommerce-subscriptions.php:1187 msgid "Support" msgstr "" -#: woocommerce-subscriptions.php:1151 +#: woocommerce-subscriptions.php:1272 #. translators: placeholders are opening and closing tags. Leads to docs on #. version 2 msgid "" @@ -4378,14 +4739,14 @@ msgid "" "2.0 »%s" msgstr "" -#: woocommerce-subscriptions.php:1166 +#: woocommerce-subscriptions.php:1287 msgid "" "Warning! You are running version %s of WooCommerce Subscriptions plugin " "code but your database has been upgraded to Subscriptions version 2.0. This " "will cause major problems on your store." msgstr "" -#: woocommerce-subscriptions.php:1167 +#: woocommerce-subscriptions.php:1288 msgid "" "Please upgrade the WooCommerce Subscriptions plugin to version 2.0 or newer " "immediately. If you need assistance, after upgrading to Subscriptions v2.0, " @@ -4410,7 +4771,7 @@ msgstr "" msgid "http://prospress.com/" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:200 +#: includes/admin/class-wc-subscriptions-admin.php:202 #. translators: placeholder is trial period validation message if passed an #. invalid value (e.g. "Trial period can not exceed 4 weeks") msgctxt "Trial period field tooltip on Edit Product administration screen" @@ -4420,12 +4781,12 @@ msgid "" "subscription. %s" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:213 +#: includes/admin/class-wc-subscriptions-admin.php:215 msgctxt "example price" msgid "e.g. 5.90" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:247 +#: includes/admin/class-wc-subscriptions-admin.php:249 #: templates/admin/deprecated/html-variation-price.php:31 #: templates/admin/deprecated/html-variation-price.php:86 #: templates/admin/html-variation-price.php:21 @@ -4434,7 +4795,7 @@ msgctxt "example price" msgid "e.g. 9.90" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:781 +#: includes/admin/class-wc-subscriptions-admin.php:784 #. translators: placeholders are for HTML tags. They are 1$: "

    ", 2$: #. "

    ", 3$: "

    ", 4$: "", 5$: "", 6$: "", 7$: "", 8$: #. "

    " @@ -4445,7 +4806,7 @@ msgid "" "%6$sVariable subscription%7$s.%8$s" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:783 +#: includes/admin/class-wc-subscriptions-admin.php:786 #. translators: placeholders are for HTML tags. They are 1$: "

    ", 2$: #. "

    ", 3$: "

    ", 4$: "

    " msgctxt "used in admin pointer script params in javascript as price pointer content" @@ -4455,58 +4816,58 @@ msgid "" "sign-up fee and free trial.%4$s" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1094 +#: includes/admin/class-wc-subscriptions-admin.php:1097 msgctxt "option section heading" msgid "Renewals" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1126 +#: includes/admin/class-wc-subscriptions-admin.php:1129 msgctxt "options section heading" msgid "Miscellaneous" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1134 +#: includes/admin/class-wc-subscriptions-admin.php:1137 msgctxt "there's a number immediately in front of this text" msgid "suspensions per billing period." msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1411 -#: includes/admin/class-wc-subscriptions-admin.php:1447 +#: includes/class-wc-subscriptions-synchroniser.php:240 +msgctxt "there's a number immediately in front of this text" +msgid "days prior to Renewal Day" +msgstr "" + +#: includes/admin/class-wc-subscriptions-admin.php:1418 +#: includes/admin/class-wcs-admin-system-status.php:92 msgctxt "label that indicates whether debugging is turned on for the plugin" msgid "WCS_DEBUG" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1417 -#: includes/admin/class-wc-subscriptions-admin.php:1453 +#: includes/admin/class-wc-subscriptions-admin.php:1424 +#: includes/admin/class-wcs-admin-system-status.php:104 msgctxt "Live or Staging, Label on WooCommerce -> System Status page" msgid "Subscriptions Mode" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1418 -#: includes/admin/class-wc-subscriptions-admin.php:1454 +#: includes/admin/class-wc-subscriptions-admin.php:1425 +#: includes/admin/class-wcs-admin-system-status.php:106 msgctxt "refers to staging site" msgid "Staging" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1418 -#: includes/admin/class-wc-subscriptions-admin.php:1454 +#: includes/admin/class-wc-subscriptions-admin.php:1425 +#: includes/admin/class-wcs-admin-system-status.php:106 msgctxt "refers to live site" msgid "Live" msgstr "" -#: includes/admin/class-wc-subscriptions-admin.php:1424 -msgctxt "label for the system status page" -msgid "Subscriptions Template Theme Overrides" -msgstr "" - -#: includes/admin/class-wcs-admin-meta-boxes.php:56 +#: includes/admin/class-wcs-admin-meta-boxes.php:57 msgctxt "meta box title" msgid "Subscription Data" msgstr "" -#: includes/admin/class-wcs-admin-meta-boxes.php:58 +#: includes/admin/class-wcs-admin-meta-boxes.php:59 msgctxt "meta box title" -msgid "Billing Schedule" +msgid "Schedule" msgstr "" #: includes/admin/class-wcs-admin-post-types.php:245 @@ -4522,8 +4883,8 @@ msgstr "" #: includes/admin/class-wcs-admin-post-types.php:247 #: includes/admin/class-wcs-admin-post-types.php:460 #: includes/class-wc-subscriptions-manager.php:1829 -#: includes/wcs-user-functions.php:359 -#: templates/myaccount/related-orders.php:67 +#: includes/wcs-user-functions.php:345 +#: templates/myaccount/related-orders.php:73 msgctxt "an action on a subscription" msgid "Cancel" msgstr "" @@ -4550,33 +4911,93 @@ msgctxt "Subscription title on admin table. (e.g.: #211 for John Doe)" msgid "%1$s#%2$s%3$s for %4$s" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:883 +#: includes/admin/class-wcs-admin-post-types.php:835 #. translators: placeholder is previous post title msgctxt "used in post updated messages" msgid "Subscription restored to revision from %s" msgstr "" -#: includes/admin/class-wcs-admin-post-types.php:888 +#: includes/admin/class-wcs-admin-post-types.php:840 msgctxt "used in \"Subscription scheduled for \"" msgid "M j, Y @ G:i" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:84 +#: includes/admin/class-wcs-admin-system-status.php:119 +msgctxt "label for the system status page" +msgid "Subscriptions Template Theme Overrides" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:204 +msgctxt "label for the system status page" +msgid "Subscription Statuses" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:225 +msgctxt "label for the system status page" +msgid "WooCommerce Account Connected" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:248 +msgctxt "label for the system status page" +msgid "Active Product Key" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:278 +msgctxt "label for the system status page" +msgid "Other" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:312 +msgctxt "label for the system status page" +msgid "PayPal Reference Transactions Enabled" +msgstr "" + +#: includes/admin/class-wcs-admin-system-status.php:340 +msgctxt "label for the system status page" +msgid "Country / State" +msgstr "" + +#: includes/payment-retry/class-wcs-retry-admin.php:160 +msgctxt "label for the system status page" +msgid "Custom Retry Rules" +msgstr "" + +#: includes/payment-retry/class-wcs-retry-admin.php:168 +msgctxt "label for the system status page" +msgid "Custom Retry Rule Class" +msgstr "" + +#: includes/payment-retry/class-wcs-retry-admin.php:176 +msgctxt "label for the system status page" +msgid "Custom Raw Retry Rule" +msgstr "" + +#: includes/payment-retry/class-wcs-retry-admin.php:184 +msgctxt "label for the system status page" +msgid "Custom Retry Rule" +msgstr "" + +#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:78 msgctxt "relation to order" msgid "Resubscribed Subscription" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:92 +#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:78 +msgctxt "relation to order" +msgid "Resubscribe Order" +msgstr "" + +#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:87 msgctxt "relation to order" msgid "Initial Subscription" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:101 +#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:96 msgctxt "relation to order" msgid "Parent Order" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:111 +#: includes/admin/meta-boxes/class-wcs-meta-box-related-orders.php:106 msgctxt "relation to order" msgid "Renewal Order" msgstr "" @@ -4587,7 +5008,7 @@ msgctxt "edit subscription header" msgid "Subscription #%s details" msgstr "" -#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:141 +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:163 #: includes/class-wcs-change-payment-method-admin.php:52 msgctxt "" "The gateway ID displayed on the Edit Subscriptions screen when editing " @@ -4595,8 +5016,15 @@ msgctxt "" msgid "Gateway ID: [%s]" msgstr "" +#: includes/admin/meta-boxes/class-wcs-meta-box-subscription-data.php:336 +msgctxt "subscription note after linking to a parent order" +msgid "Subscription linked to parent order %s via admin." +msgstr "" + #: includes/admin/meta-boxes/views/html-related-orders-row.php:19 #: includes/class-wc-subscriptions-renewal-order.php:157 +#: includes/early-renewal/class-wcs-cart-early-renewal.php:217 +#: includes/early-renewal/class-wcs-cart-early-renewal.php:314 #: templates/myaccount/my-subscriptions.php:38 #: templates/myaccount/related-orders.php:39 #: templates/myaccount/related-subscriptions.php:32 @@ -4604,7 +5032,7 @@ msgctxt "hash before order number" msgid "#%s" msgstr "" -#: includes/class-wcs-query.php:96 +#: includes/class-wcs-query.php:102 msgctxt "hash before order number" msgid "Subscription #%s" msgstr "" @@ -4632,19 +5060,19 @@ msgstr "" #: templates/emails/cancelled-subscription.php:28 #: templates/emails/expired-subscription.php:28 -#: templates/emails/on-hold-subscription.php:28 wcs-functions.php:279 +#: templates/emails/on-hold-subscription.php:28 wcs-functions.php:295 msgctxt "table heading" msgid "Last Order Date" msgstr "" #: templates/emails/subscription-info.php:19 -#: templates/myaccount/subscription-details.php:22 wcs-functions.php:276 +#: templates/myaccount/subscription-details.php:22 wcs-functions.php:292 msgctxt "table heading" msgid "Start Date" msgstr "" #: templates/emails/subscription-info.php:20 -#: templates/myaccount/subscription-details.php:28 wcs-functions.php:281 +#: templates/myaccount/subscription-details.php:28 wcs-functions.php:297 msgctxt "table heading" msgid "End Date" msgstr "" @@ -4657,17 +5085,17 @@ msgstr "" #: templates/myaccount/my-subscriptions.php:27 #: templates/myaccount/my-subscriptions.php:44 #: templates/myaccount/related-subscriptions.php:22 -#: templates/myaccount/related-subscriptions.php:38 wcs-functions.php:278 +#: templates/myaccount/related-subscriptions.php:38 wcs-functions.php:294 msgctxt "table heading" msgid "Next Payment" msgstr "" -#: wcs-functions.php:277 +#: wcs-functions.php:293 msgctxt "table heading" msgid "Trial End" msgstr "" -#: wcs-functions.php:280 +#: wcs-functions.php:296 msgctxt "table heading" msgid "Cancelled Date" msgstr "" @@ -4703,12 +5131,12 @@ msgctxt "API response confirming order note deleted from a subscription" msgid "Permanently deleted subscription note" msgstr "" -#: includes/class-wc-subscription.php:1166 +#: includes/class-wc-subscription.php:1103 msgctxt "original denotes there is no date to display" msgid "-" msgstr "" -#: includes/class-wc-subscription.php:2289 +#: includes/class-wc-subscription.php:2237 #. translators: placeholder is date type (e.g. "end", "next_payment"...) msgctxt "appears in an error message if date is wrong format" msgid "Invalid %s date. The date must be of the format: \"Y-m-d H:i:s\"." @@ -4743,22 +5171,28 @@ msgctxt "used in order note as reason for why subscription status changed" msgid "Subscription renewal payment retry:" msgstr "" -#: includes/class-wc-subscriptions-manager.php:1040 wcs-functions.php:209 +#: includes/early-renewal/class-wcs-cart-early-renewal.php:147 +#: includes/early-renewal/class-wcs-cart-early-renewal.php:174 +msgctxt "used in order note as reason for why subscription status changed" +msgid "Customer requested to renew early:" +msgstr "" + +#: includes/class-wc-subscriptions-manager.php:1040 wcs-functions.php:225 msgctxt "Subscription status" msgid "Active" msgstr "" -#: includes/class-wc-subscriptions-manager.php:1043 wcs-functions.php:211 +#: includes/class-wc-subscriptions-manager.php:1043 wcs-functions.php:227 msgctxt "Subscription status" msgid "Cancelled" msgstr "" -#: includes/class-wc-subscriptions-manager.php:1046 wcs-functions.php:213 +#: includes/class-wc-subscriptions-manager.php:1046 wcs-functions.php:229 msgctxt "Subscription status" msgid "Expired" msgstr "" -#: includes/class-wc-subscriptions-manager.php:1049 wcs-functions.php:208 +#: includes/class-wc-subscriptions-manager.php:1049 wcs-functions.php:224 msgctxt "Subscription status" msgid "Pending" msgstr "" @@ -4773,17 +5207,17 @@ msgctxt "Subscription status" msgid "On-hold" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:2611 wcs-functions.php:212 +#: includes/class-wc-subscriptions-switcher.php:2580 wcs-functions.php:228 msgctxt "Subscription status" msgid "Switched" msgstr "" -#: wcs-functions.php:210 +#: wcs-functions.php:226 msgctxt "Subscription status" msgid "On hold" msgstr "" -#: wcs-functions.php:214 +#: wcs-functions.php:230 msgctxt "Subscription status" msgid "Pending Cancellation" msgstr "" @@ -4825,106 +5259,115 @@ msgctxt "An order type" msgid "Non-subscription" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:360 -#: includes/class-wc-subscriptions-switcher.php:377 -#: includes/class-wc-subscriptions-switcher.php:411 -#: includes/class-wc-subscriptions-synchroniser.php:174 +#: includes/class-wc-subscriptions-switcher.php:357 +#: includes/class-wc-subscriptions-switcher.php:374 +#: includes/class-wc-subscriptions-switcher.php:408 msgctxt "when to allow a setting" msgid "Never" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:361 +#: includes/class-wc-subscriptions-switcher.php:358 msgctxt "when to allow switching" msgid "Between Subscription Variations" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:362 +#: includes/class-wc-subscriptions-switcher.php:359 msgctxt "when to allow switching" msgid "Between Grouped Subscriptions" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:363 +#: includes/class-wc-subscriptions-switcher.php:360 msgctxt "when to allow switching" msgid "Between Both Variations & Grouped Subscriptions" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:378 +#: includes/class-wc-subscriptions-switcher.php:375 msgctxt "when to prorate recurring fee when switching" msgid "For Upgrades of Virtual Subscription Products Only" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:379 +#: includes/class-wc-subscriptions-switcher.php:376 msgctxt "when to prorate recurring fee when switching" msgid "For Upgrades of All Subscription Products" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:380 +#: includes/class-wc-subscriptions-switcher.php:377 msgctxt "when to prorate recurring fee when switching" msgid "For Upgrades & Downgrades of Virtual Subscription Products Only" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:381 +#: includes/class-wc-subscriptions-switcher.php:378 msgctxt "when to prorate recurring fee when switching" msgid "For Upgrades & Downgrades of All Subscription Products" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:395 +#: includes/class-wc-subscriptions-switcher.php:392 msgctxt "when to prorate signup fee when switching" msgid "Never (do not charge a sign up fee)" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:396 +#: includes/class-wc-subscriptions-switcher.php:393 msgctxt "when to prorate signup fee when switching" msgid "Never (charge the full sign up fee)" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:397 +#: includes/class-wc-subscriptions-switcher.php:394 msgctxt "when to prorate signup fee when switching" msgid "Always" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:412 -#: includes/class-wc-subscriptions-synchroniser.php:175 +#: includes/class-wc-subscriptions-switcher.php:409 +#: includes/class-wc-subscriptions-synchroniser.php:232 msgctxt "when to prorate first payment / subscription length" msgid "For Virtual Subscription Products Only" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:413 -#: includes/class-wc-subscriptions-synchroniser.php:176 +#: includes/class-wc-subscriptions-switcher.php:410 +#: includes/class-wc-subscriptions-synchroniser.php:233 msgctxt "when to prorate first payment / subscription length" msgid "For All Subscription Products" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1804 +#: includes/class-wc-subscriptions-synchroniser.php:230 +msgctxt "when to prorate first payment / subscription length" +msgid "Never (do not charge any recurring amount)" +msgstr "" + +#: includes/class-wc-subscriptions-synchroniser.php:231 +msgctxt "when to prorate first payment / subscription length" +msgid "Never (charge the full recurring amount at sign-up)" +msgstr "" + +#: includes/class-wc-subscriptions-switcher.php:1775 msgctxt "a switch order" msgid "Downgrade" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1807 +#: includes/class-wc-subscriptions-switcher.php:1778 msgctxt "a switch order" msgid "Upgrade" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1810 +#: includes/class-wc-subscriptions-switcher.php:1781 msgctxt "a switch order" msgid "Crossgrade" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1815 +#: includes/class-wc-subscriptions-switcher.php:1786 #. translators: %1: product subtotal, %2: HTML span tag, %3: direction #. (upgrade, downgrade, crossgrade), %4: closing HTML span tag msgctxt "product subtotal string" msgid "%1$s %2$s(%3$s)%4$s" msgstr "" -#: includes/class-wc-subscriptions-switcher.php:1931 -#: includes/class-wc-subscriptions-switcher.php:2273 +#: includes/class-wc-subscriptions-switcher.php:1902 +#: includes/class-wc-subscriptions-switcher.php:2244 #. translators: 1$: old item, 2$: new item when switching msgctxt "used in order notes" msgid "Customer switched from: %1$s to %2$s." msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:50 +#: includes/class-wc-subscriptions-synchroniser.php:51 #. translators: placeholder is a year (e.g. "2016") msgctxt "used in subscription product edit screen" msgid "" @@ -4934,7 +5377,7 @@ msgid "" "product." msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:154 +#: includes/class-wc-subscriptions-synchroniser.php:210 #. translators: placeholders are opening and closing link tags msgctxt "used in the general subscription options page" msgid "" @@ -4942,14 +5385,14 @@ msgid "" "For example, the first day of the month. %sLearn more%s." msgstr "" -#: includes/class-wc-subscriptions-synchroniser.php:237 +#: includes/class-wc-subscriptions-synchroniser.php:303 #: templates/admin/deprecated/html-variation-synchronisation.php:36 #: templates/admin/html-variation-synchronisation.php:36 msgctxt "input field placeholder for day field for annual subscriptions" msgid "Day" msgstr "" -#: includes/class-wcs-cart-renewal.php:761 +#: includes/class-wcs-cart-renewal.php:766 msgctxt "" "Used in WooCommerce by removed item notification: \"_All linked " "subscription items were_ removed. Undo?\" Filter for item title." @@ -5221,21 +5664,21 @@ msgctxt "Admin menu name" msgid "Renewal Payment Retries" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:303 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:325 #. translators: placeholder is number of upgraded subscriptions msgctxt "used in the subscriptions upgrader" msgid "Marked %s subscription products as \"sold individually\"." msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:334 -#: includes/upgrades/class-wc-subscriptions-upgrader.php:384 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:356 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:406 #. translators: placeholder is "{time_left}", will be replaced on front end #. with actual time msgctxt "Message that gets sent to front end." msgid "Estimated time left (minutes:seconds): %s" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:363 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:385 #. translators: placeholder is the number of subscriptions repaired msgctxt "Repair message that gets sent to front end." msgid "" @@ -5243,7 +5686,7 @@ msgid "" "customer notes." msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:369 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:391 #. translators: placeholder is number of subscriptions that were checked and #. did not need repairs. There's a space at the beginning! msgctxt "Repair message that gets sent to front end." @@ -5252,14 +5695,14 @@ msgid_plural "%d other subscriptions were checked and did not need any repairs." msgstr[0] "" msgstr[1] "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:373 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:395 #. translators: placeholder is "{execution_time}", which will be replaced on #. front end with actual time msgctxt "Repair message that gets sent to front end." msgid "(in %s seconds)" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:376 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:398 #. translators: $1: "Repaired x subs with incorrect dates...", $2: "X others #. were checked and no repair needed", $3: "(in X seconds)". Ordering for RTL #. languages. @@ -5267,7 +5710,7 @@ msgctxt "The assembled repair message that gets sent to front end." msgid "%1$s%2$s %3$s" msgstr "" -#: includes/upgrades/class-wc-subscriptions-upgrader.php:395 +#: includes/upgrades/class-wc-subscriptions-upgrader.php:417 #. translators: 1$: error message, 2$: opening link tag, 3$: closing link tag msgctxt "Error message that gets sent to front end when upgrading Subscriptions" msgid "" @@ -5275,8 +5718,13 @@ msgid "" "and try again. If problem persists, %2$scontact support%3$s." msgstr "" +#: includes/upgrades/class-wcs-upgrade-notice-manager.php:80 +msgctxt "plugin version number used in admin notice" +msgid "2.3" +msgstr "" + #: includes/upgrades/templates/wcs-about-2-0.php:36 -#: woocommerce-subscriptions.php:1065 +#: woocommerce-subscriptions.php:1186 msgctxt "short for documents" msgid "Docs" msgstr "" @@ -5321,7 +5769,7 @@ msgctxt "shipping method price" msgid "Free" msgstr "" -#: includes/wcs-cart-functions.php:271 +#: includes/wcs-cart-functions.php:283 #. translators: placeholder is price string, denotes tax included in cart/order #. total msgctxt "includes tax" @@ -5333,21 +5781,21 @@ msgctxt "initial payment on a subscription" msgid "up front" msgstr "" -#: includes/wcs-order-functions.php:135 +#: includes/wcs-order-functions.php:146 msgctxt "" "In wcs_copy_order_meta error message. Refers to origin and target order " "objects." msgid "Invalid data. Orders expected aren't orders." msgstr "" -#: includes/wcs-order-functions.php:139 +#: includes/wcs-order-functions.php:150 msgctxt "" "Refers to the type of the copy being performed: \"copy_order\", " "\"subscription\", \"renewal_order\", \"resubscribe_order\"" msgid "Invalid data. Type of copy is not a string." msgstr "" -#: includes/wcs-order-functions.php:323 wcs-functions.php:155 +#: includes/wcs-order-functions.php:340 wcs-functions.php:155 #. translators: Order date parsed by strftime msgctxt "Used in subscription post title. \"Subscription renewal order - \"" msgid "%b %d, %Y @ %I:%M %p" @@ -5702,7 +6150,7 @@ msgid "Total" msgstr "" #: templates/myaccount/my-subscriptions.php:59 -#: templates/myaccount/related-orders.php:73 +#: templates/myaccount/related-orders.php:79 #: templates/myaccount/related-subscriptions.php:45 msgctxt "view a subscription" msgid "View" @@ -5754,68 +6202,68 @@ msgctxt "The post title for the new subscription" msgid "Subscription – %s" msgstr "" -#: woocommerce-subscriptions.php:233 +#: woocommerce-subscriptions.php:305 msgctxt "custom post type setting" msgid "Add Subscription" msgstr "" -#: woocommerce-subscriptions.php:234 +#: woocommerce-subscriptions.php:306 msgctxt "custom post type setting" msgid "Add New Subscription" msgstr "" -#: woocommerce-subscriptions.php:235 +#: woocommerce-subscriptions.php:307 msgctxt "custom post type setting" msgid "Edit" msgstr "" -#: woocommerce-subscriptions.php:236 +#: woocommerce-subscriptions.php:308 msgctxt "custom post type setting" msgid "Edit Subscription" msgstr "" -#: woocommerce-subscriptions.php:237 +#: woocommerce-subscriptions.php:309 msgctxt "custom post type setting" msgid "New Subscription" msgstr "" -#: woocommerce-subscriptions.php:238 woocommerce-subscriptions.php:239 +#: woocommerce-subscriptions.php:310 woocommerce-subscriptions.php:311 msgctxt "custom post type setting" msgid "View Subscription" msgstr "" -#: woocommerce-subscriptions.php:242 +#: woocommerce-subscriptions.php:314 msgctxt "custom post type setting" msgid "No Subscriptions found in trash" msgstr "" -#: woocommerce-subscriptions.php:243 +#: woocommerce-subscriptions.php:315 msgctxt "custom post type setting" msgid "Parent Subscriptions" msgstr "" -#: woocommerce-subscriptions.php:311 +#: woocommerce-subscriptions.php:383 msgctxt "post status label including post count" msgid "Active (%s)" msgid_plural "Active (%s)" msgstr[0] "" msgstr[1] "" -#: woocommerce-subscriptions.php:312 +#: woocommerce-subscriptions.php:384 msgctxt "post status label including post count" msgid "Switched (%s)" msgid_plural "Switched (%s)" msgstr[0] "" msgstr[1] "" -#: woocommerce-subscriptions.php:313 +#: woocommerce-subscriptions.php:385 msgctxt "post status label including post count" msgid "Expired (%s)" msgid_plural "Expired (%s)" msgstr[0] "" msgstr[1] "" -#: woocommerce-subscriptions.php:314 +#: woocommerce-subscriptions.php:386 msgctxt "post status label including post count" msgid "Pending Cancellation (%s)" msgid_plural "Pending Cancellation (%s)" diff --git a/readme.txt b/readme.txt index a1926ba..d763d26 100755 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,8 @@ Contributors: prospress, jconroy, mattallan, thenbrent Tags: woocommerce, subscriptions, ecommerce, e-commerce, commerce, wordpress ecommerce Requires at least: 4.0 -Tested up to: 4.5 +Tested up to: 4.8 +Requires PHP: 5.6 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html WC requires at least: 2.5 diff --git a/templates/admin/html-admin-notice.php b/templates/admin/html-admin-notice.php new file mode 100755 index 0000000..3149748 --- /dev/null +++ b/templates/admin/html-admin-notice.php @@ -0,0 +1,29 @@ + +
    diff --git a/templates/admin/status.php b/templates/admin/status.php index 1dd5aa6..1b35da7 100755 --- a/templates/admin/status.php +++ b/templates/admin/status.php @@ -2,7 +2,7 @@ /** * Outputs the Status section for Subscriptions. * - * @version 2.2.17 + * @version 2.3.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -17,9 +17,9 @@ if ( ! isset( $debug_data ) || ! is_array( $debug_data ) ) { - @@ -42,53 +42,43 @@ if ( ! isset( $debug_data ) || ! is_array( $debug_data ) ) { } else { $mark_icon = 'no-alt'; } - ?> - + diff --git a/templates/checkout/form-change-payment-method.php b/templates/checkout/form-change-payment-method.php index b492a1d..3241054 100755 --- a/templates/checkout/form-change-payment-method.php +++ b/templates/checkout/form-change-payment-method.php @@ -79,7 +79,7 @@ if ( ! defined( 'ABSPATH' ) ) {
    -

    +

    diff --git a/templates/checkout/recurring-totals.php b/templates/checkout/recurring-totals.php index 285792d..7118ad2 100755 --- a/templates/checkout/recurring-totals.php +++ b/templates/checkout/recurring-totals.php @@ -44,7 +44,8 @@ $display_th = true; - + diff --git a/templates/myaccount/related-orders.php b/templates/myaccount/related-orders.php index 344ff27..48c7592 100755 --- a/templates/myaccount/related-orders.php +++ b/templates/myaccount/related-orders.php @@ -62,8 +62,14 @@ if ( ! defined( 'ABSPATH' ) ) { } if ( in_array( $order->get_status(), apply_filters( 'woocommerce_valid_order_statuses_for_cancel', array( 'pending', 'failed' ), $order ) ) ) { + $redirect = wc_get_page_permalink( 'myaccount' ); + + if ( wcs_is_view_subscription_page() ) { + $redirect = $subscription->get_view_order_url(); + } + $actions['cancel'] = array( - 'url' => $order->get_cancel_order_url( wc_get_page_permalink( 'myaccount' ) ), + 'url' => $order->get_cancel_order_url( $redirect ), 'name' => esc_html_x( 'Cancel', 'an action on a subscription', 'woocommerce-subscriptions' ), ); } diff --git a/templates/single-product/add-to-cart/variable-subscription.php b/templates/single-product/add-to-cart/variable-subscription.php index 856dca3..bb77575 100755 --- a/templates/single-product/add-to-cart/variable-subscription.php +++ b/templates/single-product/add-to-cart/variable-subscription.php @@ -79,7 +79,14 @@ do_action( 'woocommerce_before_add_to_cart_form' ); ?> ?> - + diff --git a/wcs-functions.php b/wcs-functions.php index e3aad98..7cae7f2 100755 --- a/wcs-functions.php +++ b/wcs-functions.php @@ -193,7 +193,23 @@ function wcs_create_subscription( $args = array() ) { update_post_meta( $subscription_id, '_customer_user', $args['customer_id'] ); update_post_meta( $subscription_id, '_order_version', $args['order_version'] ); - return wcs_get_subscription( $subscription_id ); + /** + * Filter the newly created subscription object. + * + * @since 2.2.22 + * @param WC_Subscription $subscription + */ + $subscription = apply_filters( 'wcs_created_subscription', wcs_get_subscription( $subscription_id ) ); + + /** + * Triggered after a new subscription is created. + * + * @since 2.2.22 + * @param WC_Subscription $subscription + */ + do_action( 'wcs_create_subscription', $subscription ); + + return $subscription; } /** @@ -674,3 +690,91 @@ function wcs_is_view_subscription_page() { function wcs_get_image_asset_url( $file_name ) { return plugins_url( "/assets/images/{$file_name}", WC_Subscriptions::$plugin_file ); } + +/** + * Search subscriptions + * + * @param string $term Term to search + * @return array of subscription ids + * @since 2.3.0 + */ +function wcs_subscription_search( $term ) { + global $wpdb; + + $subscription_ids = array(); + + if ( ! WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) { + + $data_store = WC_Data_Store::load( 'subscription' ); + $subscription_ids = $data_store->search_subscriptions( str_replace( 'Order #', '', wc_clean( $term ) ) ); + + } else { + + $search_order_id = str_replace( 'Order #', '', $term ); + if ( ! is_numeric( $search_order_id ) ) { + $search_order_id = 0; + } + + $search_fields = array_map( 'wc_clean', apply_filters( 'woocommerce_shop_subscription_search_fields', array( + '_order_key', + '_billing_company', + '_billing_address_1', + '_billing_address_2', + '_billing_city', + '_billing_postcode', + '_billing_country', + '_billing_state', + '_billing_email', + '_billing_phone', + '_shipping_address_1', + '_shipping_address_2', + '_shipping_city', + '_shipping_postcode', + '_shipping_country', + '_shipping_state', + ) ) ); + + $subscription_ids = array_unique( array_merge( + $wpdb->get_col( + $wpdb->prepare( " + SELECT p1.post_id + FROM {$wpdb->postmeta} p1 + INNER JOIN {$wpdb->postmeta} p2 ON p1.post_id = p2.post_id + WHERE + ( p1.meta_key = '_billing_first_name' AND p2.meta_key = '_billing_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' ) + OR + ( p1.meta_key = '_shipping_first_name' AND p2.meta_key = '_shipping_last_name' AND CONCAT(p1.meta_value, ' ', p2.meta_value) LIKE '%%%s%%' ) + OR + ( p1.meta_key IN ('" . implode( "','", esc_sql( $search_fields ) ) . "') AND p1.meta_value LIKE '%%%s%%' ) + ", + esc_attr( $term ), esc_attr( $term ), esc_attr( $term ) + ) + ), + $wpdb->get_col( + $wpdb->prepare( " + SELECT order_id + FROM {$wpdb->prefix}woocommerce_order_items as order_items + WHERE order_item_name LIKE '%%%s%%' + ", + esc_attr( $term ) + ) + ), + $wpdb->get_col( + $wpdb->prepare( " + SELECT p1.ID + FROM {$wpdb->posts} p1 + INNER JOIN {$wpdb->postmeta} p2 ON p1.ID = p2.post_id + INNER JOIN {$wpdb->users} u ON p2.meta_value = u.ID + WHERE u.user_email LIKE '%%%s%%' + AND p2.meta_key = '_customer_user' + AND p1.post_type = 'shop_subscription' + ", + esc_attr( $term ) + ) + ), + array( $search_order_id ) + ) ); + } + + return $subscription_ids; +} diff --git a/woocommerce-subscriptions.php b/woocommerce-subscriptions.php index ea483c6..d0959a7 100755 --- a/woocommerce-subscriptions.php +++ b/woocommerce-subscriptions.php @@ -5,9 +5,9 @@ * Description: Sell products and services with recurring payments in your WooCommerce Store. * Author: Prospress Inc. * Author URI: http://prospress.com/ - * Version: 2.2.21 + * Version: 2.3.2 * - * WC requires at least: 2.5 + * WC requires at least: 2.6 * WC tested up to: 3.4 * Woo: 27147:6115e6d7e297b623a169fdcf5728b224 * @@ -48,11 +48,13 @@ woothemes_queue_update( plugin_basename( __FILE__ ), '6115e6d7e297b623a169fdcf57 * * @since 1.0 */ -if ( ! is_woocommerce_active() || version_compare( get_option( 'woocommerce_db_version' ), '2.5', '<' ) ) { +if ( ! is_woocommerce_active() || version_compare( get_option( 'woocommerce_db_version' ), '2.6', '<' ) ) { add_action( 'admin_notices', 'WC_Subscriptions::woocommerce_inactive_notice' ); return; } +define( 'WCS_INIT_TIMESTAMP', gmdate( 'U' ) ); + require_once( 'wcs-functions.php' ); require_once( 'includes/class-wc-subscriptions-coupon.php' ); @@ -89,8 +91,6 @@ require_once( 'includes/upgrades/class-wc-subscriptions-upgrader.php' ); require_once( 'includes/upgrades/class-wcs-upgrade-logger.php' ); -require_once( 'includes/libraries/tlc-transients/tlc-transients.php' ); - require_once( 'includes/libraries/action-scheduler/action-scheduler.php' ); require_once( 'includes/abstracts/abstract-wcs-scheduler.php' ); @@ -101,6 +101,10 @@ require_once( 'includes/abstracts/abstract-wcs-cache-manager.php' ); require_once( 'includes/class-wcs-cached-data-manager.php' ); +require_once( 'includes/class-wcs-post-meta-cache-manager.php' ); + +require_once( 'includes/class-wcs-post-meta-cache-manager-many-to-one.php' ); + require_once( 'includes/class-wcs-cart-renewal.php' ); require_once( 'includes/class-wcs-cart-resubscribe.php' ); @@ -115,10 +119,44 @@ require_once( 'includes/class-wcs-cart-switch.php' ); require_once( 'includes/class-wcs-limiter.php' ); +require_once( 'includes/interfaces/interface-wcs-cache-updater.php' ); + +require_once( 'includes/abstracts/abstract-wcs-related-order-store.php' ); + +require_once( 'includes/data-stores/class-wcs-related-order-store-cpt.php' ); + +require_once( 'includes/data-stores/class-wcs-related-order-store-cached-cpt.php' ); + +require_once( 'includes/abstracts/abstract-wcs-customer-store.php' ); + +require_once( 'includes/data-stores/class-wcs-customer-store-cpt.php' ); + +require_once( 'includes/data-stores/class-wcs-customer-store-cached-cpt.php' ); + require_once( 'includes/legacy/class-wcs-array-property-post-meta-black-magic.php' ); require_once( 'includes/class-wcs-failed-scheduled-action-manager.php' ); +require_once( dirname( __FILE__ ) . '/includes/admin/class-wcs-admin-system-status.php' ); + +require_once( 'includes/abstracts/abstract-wcs-debug-tool.php' ); + +require_once( 'includes/abstracts/abstract-wcs-background-updater.php' ); + +require_once( 'includes/admin/debug-tools/class-wcs-debug-tool-factory.php' ); + +require_once( 'includes/admin/class-wcs-admin-notice.php' ); + +require_once( 'includes/upgrades/class-wcs-upgrade-notice-manager.php' ); + +require_once( 'includes/abstracts/abstract-wcs-background-upgrader.php' ); + +require_once( 'includes/class-wcs-staging.php' ); + +WCS_Admin_System_Status::init(); +WCS_Upgrade_Notice_Manager::init(); +WCS_Staging::init(); + /** * The main subscriptions class. * @@ -132,7 +170,7 @@ class WC_Subscriptions { public static $plugin_file = __FILE__; - public static $version = '2.2.21'; + public static $version = '2.3.2'; private static $total_subscription_count = null; @@ -175,12 +213,21 @@ class WC_Subscriptions { // Load translation files add_action( 'init', __CLASS__ . '::load_plugin_textdomain', 3 ); + // Load frontend scripts + add_action( 'wp_enqueue_scripts', __CLASS__ . '::enqueue_frontend_scripts', 3 ); + // Load dependent files add_action( 'plugins_loaded', __CLASS__ . '::load_dependant_classes' ); // Attach hooks which depend on WooCommerce constants add_action( 'plugins_loaded', __CLASS__ . '::attach_dependant_hooks' ); + // Make sure the related order data store instance is loaded and initialised so that cache management will function + add_action( 'plugins_loaded', 'WCS_Related_Order_Store::instance' ); + + // Make sure the related order data store instance is loaded and initialised so that cache management will function + add_action( 'plugins_loaded', 'WCS_Customer_Store::instance' ); + // Staging site or site migration notice add_action( 'admin_notices', __CLASS__ . '::woocommerce_site_change_notice' ); @@ -191,6 +238,9 @@ class WC_Subscriptions { add_action( 'in_plugin_update_message-' . plugin_basename( __FILE__ ), __CLASS__ . '::update_notice', 10, 2 ); + // get details of orders of a customer + add_action( 'wp_ajax_wcs_get_customer_orders', __CLASS__ . '::get_customer_orders' ); + self::$cache = WCS_Cache_Manager::get_instance(); $scheduler_class = apply_filters( 'woocommerce_subscriptions_scheduler', 'WCS_Action_Scheduler' ); @@ -198,18 +248,40 @@ class WC_Subscriptions { self::$scheduler = new $scheduler_class(); } + /** + * Get customer's order details via ajax. + */ + public static function get_customer_orders() { + check_ajax_referer( 'get-customer-orders', 'security' ); + + if ( ! current_user_can( 'edit_shop_orders' ) ) { + wp_die( -1 ); + } + + $user_id = absint( $_POST['user_id'] ); + + $orders = wc_get_orders( array( 'customer' => $user_id, 'post_type' => 'shop_order', 'posts_per_page' => '-1' ) ); + + $customer_orders = array(); + foreach ( $orders as $order ) { + $customer_orders[ wcs_get_objects_property( $order, 'id' ) ] = $order->get_order_number(); + } + + wp_send_json( $customer_orders ); + } + /** * Register data stores for WooCommerce 3.0+ * * @since 2.2.0 */ public static function add_data_stores( $data_stores ) { - + // Our custom data stores. $data_stores['subscription'] = 'WCS_Subscription_Data_Store_CPT'; + $data_stores['product-variable-subscription'] = 'WCS_Product_Variable_Data_Store_CPT'; - // Use WC core data stores for our products - $data_stores['product-variable-subscription'] = 'WC_Product_Variable_Data_Store_CPT'; - $data_stores['product-subscription_variation'] = 'WC_Product_Variation_Data_Store_CPT'; + // Use WC core data stores for our products. + $data_stores['product-subscription_variation'] = 'WC_Product_Variation_Data_Store_CPT'; $data_stores['order-item-line_item_pending_switch'] = 'WC_Order_Item_Product_Data_Store'; return $data_stores; @@ -330,6 +402,19 @@ class WC_Subscriptions { } } + /** + * Enqueues scripts for frontend + * + * @since 2.3 + */ + public static function enqueue_frontend_scripts() { + $dependencies = array( 'jquery' ); + + if ( is_cart() || is_checkout() ) { + wp_enqueue_script( 'wcs-cart', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/frontend/wcs-cart.js', $dependencies, WC_Subscriptions::$version, true ); + } + } + /** * Enqueues stylesheet for the My Subscriptions table on the My Account page. * @@ -383,12 +468,25 @@ class WC_Subscriptions { */ public static function redirect_ajax_add_to_cart( $fragments ) { - $data = array( - 'error' => true, - 'product_url' => wc_get_cart_url(), - ); + $fragments['error'] = true; + $fragments['product_url'] = wc_get_cart_url(); - return $data; + # Force error on add_to_cart() to redirect + add_filter( 'woocommerce_add_to_cart_validation', '__return_false', 10 ); + add_filter( 'woocommerce_cart_redirect_after_error', __CLASS__ . '::redirect_to_cart', 10, 2 ); + do_action( 'wc_ajax_add_to_cart' ); + + return $fragments; + } + + /** + * Return a url for cart redirect. + * + * @since 2.3.0 + */ + public static function redirect_to_cart( $permalink, $product_id ) { + + return wc_get_cart_url(); } /** @@ -436,8 +534,8 @@ class WC_Subscriptions { wc_add_notice( __( 'A subscription has been removed from your cart. Products and subscriptions can not be purchased at the same time.', 'woocommerce-subscriptions' ), 'notice' ); - if ( WC_Subscriptions::is_woocommerce_pre( '3.0.8' ) ) { - // Redirect to cart page to remove subscription & notify shopper + // Redirect to cart page to remove subscription & notify shopper + if ( self::is_woocommerce_pre( '3.0.8' ) ) { add_filter( 'add_to_cart_fragments', __CLASS__ . '::redirect_ajax_add_to_cart' ); } else { add_filter( 'woocommerce_add_to_cart_fragments', __CLASS__ . '::redirect_ajax_add_to_cart' ); @@ -777,10 +875,9 @@ class WC_Subscriptions { } } else { require_once( 'includes/class-wc-order-item-pending-switch.php' ); - require_once( 'includes/data-stores/class-wcs-subscription-data-store-cpt.php' ); - require_once( 'includes/deprecated/class-wcs-deprecated-filter-hooks.php' ); + require_once( 'includes/data-stores/class-wcs-product-variable-data-store-cpt.php' ); } // Provide a hook to enable running deprecation handling for stores that might want to check for deprecated code @@ -799,6 +896,30 @@ class WC_Subscriptions { require_once( 'includes/deprecated/class-wcs-dynamic-filter-deprecator.php' ); } + if ( class_exists( 'WCS_Early_Renewal' ) ) { + $notice = new WCS_Admin_Notice( 'error' ); + + $notice->set_simple_content( sprintf( __( '%1$sWarning!%2$s We can see the %1$sWooCommerce Subscriptions Early Renewal%2$s plugin is active. Version %3$s of %1$sWooCommerce Subscriptions%2$s comes with that plugin\'s functionality packaged into the core plugin. Please deactivate WooCommerce Subscriptions Early Renewal to avoid any conflicts.', 'woocommerce-subscriptions' ), '', '', self::$version ) ); + $notice->set_actions( array( + array( + 'name' => __( 'Installed Plugins', 'woocommerce-subscriptions' ), + 'url' => admin_url( 'plugins.php' ), + ), + ) ); + + $notice->display(); + } else { + require_once( dirname( __FILE__ ) . '/includes/early-renewal/class-wcs-early-renewal-manager.php' ); + WCS_Early_Renewal_Manager::init(); + + if ( WCS_Early_Renewal_Manager::is_early_renewal_enabled() ) { + require_once( dirname( __FILE__ ) . '/includes/early-renewal/class-wcs-cart-early-renewal.php' ); + require_once( dirname( __FILE__ ) . '/includes/early-renewal/wcs-early-renewal-functions.php' ); + + new WCS_Cart_Early_Renewal(); + } + } + $failed_scheduled_action_manager = new WCS_Failed_Scheduled_Action_Manager( new WC_Logger() ); $failed_scheduled_action_manager->init();
    -

    - +

    +

    +

    ::   - - - - - %s ', esc_html( $override['file'] ) ); - if ( $override['is_outdated'] ) { - printf( - /* translators: %1$s is the file version, %2$s is the core version */ - esc_html__( 'version %1$s is out of date. The core version is %2$s', 'woocommerce-subscriptions' ), - '' . esc_html( $override['version'] ) . '', - '' . esc_html( $override['core_version'] ) . '' - ); + if ( empty( $data['data'] ) ) { + echo '–'; + continue; } - echo '
    '; - } - if ( $data['data']['has_outdated_templates'] ) { - ?> -
    - - - - - '; + $row_number--; + } + } + if ( isset( $data['note'] ) ) { + if ( empty( $mark ) ) { + echo wp_kses_post( $data['note'] ); + } else { ?> + '; + } + echo wp_kses_post( $data['note'] );?> +
    +