From 50b02db3314ce937e9a670b4215fa4cced7652cf Mon Sep 17 00:00:00 2001
From: Remco Tolsma <869674+remcotolsma@users.noreply.github.com>
Date: Fri, 21 Oct 2022 13:34:45 +0200
Subject: [PATCH] 4.6.0
---
assets/js/admin/admin-pointers.js | 57 -
assets/js/admin/admin.js | 831 --
assets/js/admin/meta-boxes-subscription.js | 239 -
assets/js/admin/reports.js | 2 +-
assets/js/admin/wcs-meta-boxes-order.js | 8 -
assets/js/wcs-upgrade.js | 206 -
changelog.txt | 203 +
includes/admin/class-wcs-admin-meta-boxes.php | 329 -
includes/admin/class-wcs-admin-reports.php | 20 +-
.../class-wcs-report-cache-manager.php | 7 +-
.../reports/class-wcs-report-dashboard.php | 33 +-
.../class-wcs-report-retention-rate.php | 6 +-
...ss-wcs-report-subscription-by-customer.php | 9 +
...ass-wcs-report-subscription-by-product.php | 13 +-
...wcs-report-subscription-events-by-date.php | 19 +-
...-wcs-report-subscription-payment-retry.php | 6 +-
...-wcs-report-upcoming-recurring-revenue.php | 15 +-
...-wc-rest-subscription-notes-controller.php | 35 +-
...est-subscription-system-status-manager.php | 148 +
...class-wc-rest-subscriptions-controller.php | 1076 +-
.../api/legacy/class-wc-api-subscriptions.php | 9 +-
...class-wc-rest-subscriptions-controller.php | 2 +-
...-rest-subscription-notes-v1-controller.php | 36 +
...ss-wc-rest-subscriptions-v1-controller.php | 786 ++
includes/class-wc-subscriptions-plugin.php | 223 +
includes/class-wcs-api.php | 45 +-
includes/class-wcs-autoloader.php | 381 +-
...wcs-call-to-action-button-text-manager.php | 94 +
.../class-wcs-customer-suspension-manager.php | 126 +
includes/class-wcs-drip-downloads-manager.php | 76 +
...s-wcs-limited-recurring-coupon-manager.php | 415 +
includes/class-wcs-manual-renewal-manager.php | 91 +
includes/class-wcs-staging.php | 99 -
.../class-wcs-subscriber-role-manager.php | 98 +
includes/class-wcs-template-loader.php | 117 -
.../class-wcs-upgrade-notice-manager.php | 26 +-
includes/class-wcs-webhooks.php | 21 +-
...-zero-initial-payment-checkout-manager.php | 85 +
.../class-wcs-cart-early-renewal.php | 15 +-
.../class-wcs-early-renewal-modal-handler.php | 6 +-
.../wcs-early-renewal-functions.php | 26 -
...lass-wc-subscriptions-payment-gateways.php | 286 +-
.../action-scheduler/action-scheduler.php | 53 -
.../classes/ActionScheduler_ActionClaim.php | 23 -
.../classes/ActionScheduler_ActionFactory.php | 179 -
.../classes/ActionScheduler_AdminView.php | 137 -
...tionScheduler_AsyncRequest_QueueRunner.php | 96 -
.../classes/ActionScheduler_Compatibility.php | 99 -
.../ActionScheduler_DataController.php | 177 -
.../classes/ActionScheduler_DateTime.php | 76 -
.../classes/ActionScheduler_Exception.php | 11 -
.../ActionScheduler_FatalErrorMonitor.php | 55 -
...ActionScheduler_InvalidActionException.php | 47 -
.../classes/ActionScheduler_ListTable.php | 559 -
.../classes/ActionScheduler_LogEntry.php | 67 -
.../classes/ActionScheduler_NullLogEntry.php | 11 -
.../classes/ActionScheduler_OptionLock.php | 49 -
.../classes/ActionScheduler_QueueCleaner.php | 155 -
.../classes/ActionScheduler_QueueRunner.php | 185 -
.../classes/ActionScheduler_Versions.php | 62 -
.../ActionScheduler_WPCommentCleaner.php | 108 -
.../ActionScheduler_wcSystemStatus.php | 147 -
.../ActionScheduler_WPCLI_QueueRunner.php | 197 -
...ctionScheduler_WPCLI_Scheduler_command.php | 158 -
.../classes/WP_CLI/Migration_Command.php | 148 -
.../classes/WP_CLI/ProgressBar.php | 119 -
.../classes/abstracts/ActionScheduler.php | 269 -
.../ActionScheduler_Abstract_ListTable.php | 674 -
.../ActionScheduler_Abstract_QueueRunner.php | 232 -
...onScheduler_Abstract_RecurringSchedule.php | 102 -
.../ActionScheduler_Abstract_Schedule.php | 83 -
.../ActionScheduler_Abstract_Schema.php | 133 -
.../abstracts/ActionScheduler_Lock.php | 62 -
.../abstracts/ActionScheduler_Logger.php | 176 -
.../abstracts/ActionScheduler_Store.php | 345 -
.../ActionScheduler_TimezoneHelper.php | 152 -
.../actions/ActionScheduler_Action.php | 75 -
.../ActionScheduler_CanceledAction.php | 23 -
.../ActionScheduler_FinishedAction.php | 16 -
.../actions/ActionScheduler_NullAction.php | 16 -
.../data-stores/ActionScheduler_DBLogger.php | 146 -
.../data-stores/ActionScheduler_DBStore.php | 803 --
.../ActionScheduler_HybridStore.php | 380 -
.../ActionScheduler_wpCommentLogger.php | 240 -
.../ActionScheduler_wpPostStore.php | 858 --
...eduler_wpPostStore_PostStatusRegistrar.php | 58 -
...cheduler_wpPostStore_PostTypeRegistrar.php | 50 -
...cheduler_wpPostStore_TaxonomyRegistrar.php | 26 -
.../classes/migration/ActionMigrator.php | 109 -
.../ActionScheduler_DBStoreMigrator.php | 47 -
.../classes/migration/BatchFetcher.php | 86 -
.../classes/migration/Config.php | 168 -
.../classes/migration/Controller.php | 206 -
.../migration/DryRun_ActionMigrator.php | 28 -
.../classes/migration/DryRun_LogMigrator.php | 23 -
.../classes/migration/LogMigrator.php | 49 -
.../classes/migration/Runner.php | 136 -
.../classes/migration/Scheduler.php | 128 -
.../ActionScheduler_CanceledSchedule.php | 57 -
.../ActionScheduler_CronSchedule.php | 102 -
.../ActionScheduler_IntervalSchedule.php | 81 -
.../ActionScheduler_NullSchedule.php | 28 -
.../schedules/ActionScheduler_Schedule.php | 18 -
.../ActionScheduler_SimpleSchedule.php | 71 -
.../schema/ActionScheduler_LoggerSchema.php | 48 -
.../schema/ActionScheduler_StoreSchema.php | 82 -
...eduler_Abstract_QueueRunner_Deprecated.php | 27 -
.../ActionScheduler_AdminView_Deprecated.php | 147 -
.../ActionScheduler_Schedule_Deprecated.php | 29 -
.../ActionScheduler_Store_Deprecated.php | 49 -
.../action-scheduler/deprecated/functions.php | 126 -
.../libraries/action-scheduler/functions.php | 251 -
.../action-scheduler/lib/WP_Async_Request.php | 170 -
.../lib/cron-expression/CronExpression.php | 318 -
.../CronExpression_AbstractField.php | 100 -
.../CronExpression_DayOfMonthField.php | 110 -
.../CronExpression_DayOfWeekField.php | 124 -
.../CronExpression_FieldFactory.php | 55 -
.../CronExpression_FieldInterface.php | 39 -
.../CronExpression_HoursField.php | 47 -
.../CronExpression_MinutesField.php | 39 -
.../CronExpression_MonthField.php | 55 -
.../CronExpression_YearField.php | 43 -
includes/libraries/class-wc-datetime.php | 73 -
.../class-wcs-meta-box-payment-retries.php | 2 +-
.../{ => admin}/class-wcs-retry-admin.php | 0
.../admin}/html-retries-table.php | 0
.../class-wcs-retry-manager.php | 11 +-
.../data-stores}/abstract-wcs-retry-store.php | 0
.../class-wcs-retry-database-store.php | 0
.../class-wcs-retry-hybrid-store.php | 0
.../class-wcs-retry-post-store.php | 0
.../class-wcs-retry-stores.php | 0
...class-wcs-email-customer-payment-retry.php | 2 +-
.../emails/class-wcs-email-payment-retry.php | 2 +-
.../{ => emails}/class-wcs-retry-email.php | 0
.../class-wc-order-item-pending-switch.php | 0
.../class-wc-subscriptions-switcher.php | 287 +-
.../class-wcs-add-cart-item.php | 11 +
.../{ => switching}/class-wcs-cart-switch.php | 30 +-
.../class-wcs-switch-cart-item.php | 97 +-
.../class-wcs-switch-totals-calculator.php | 52 +-
languages/woocommerce-subscriptions-fr.mo | Bin 0 -> 190575 bytes
languages/woocommerce-subscriptions-fr.po | 8189 ++++++++++++
languages/woocommerce-subscriptions.pot | 10688 ++++++++--------
phpcs.xml | 37 -
readme.txt | 11 -
templates/checkout/recurring-totals.php | 157 -
vendor/autoload.php | 7 +
vendor/composer/ClassLoader.php | 572 +
vendor/composer/InstalledVersions.php | 350 +
.../composer}/LICENSE | 12 +-
vendor/composer/autoload_classmap.php | 112 +
vendor/composer/autoload_namespaces.php | 9 +
vendor/composer/autoload_psr4.php | 10 +
vendor/composer/autoload_real.php | 57 +
vendor/composer/autoload_static.php | 138 +
vendor/composer/installed.json | 220 +
vendor/composer/installed.php | 53 +
.../workflows/continuous-integration.yml | 76 +
.../installers/.github/workflows/lint.yml | 30 +
.../installers/.github/workflows/phpstan.yml | 51 +
vendor/composer/installers/LICENSE | 19 +
vendor/composer/installers/composer.json | 122 +
vendor/composer/installers/phpstan.neon.dist | 10 +
.../src/Composer/Installers/AglInstaller.php | 21 +
.../Composer/Installers/AimeosInstaller.php | 9 +
.../Installers/AnnotateCmsInstaller.php | 11 +
.../Composer/Installers/AsgardInstaller.php | 49 +
.../Composer/Installers/AttogramInstaller.php | 9 +
.../src/Composer/Installers/BaseInstaller.php | 137 +
.../Composer/Installers/BitrixInstaller.php | 126 +
.../Composer/Installers/BonefishInstaller.php | 9 +
.../Composer/Installers/CakePHPInstaller.php | 66 +
.../src/Composer/Installers/ChefInstaller.php | 11 +
.../Composer/Installers/CiviCrmInstaller.php | 9 +
.../Installers/ClanCatsFrameworkInstaller.php | 10 +
.../Composer/Installers/CockpitInstaller.php | 32 +
.../Installers/CodeIgniterInstaller.php | 11 +
.../Installers/Concrete5Installer.php | 13 +
.../Composer/Installers/CraftInstaller.php | 35 +
.../Composer/Installers/CroogoInstaller.php | 21 +
.../Composer/Installers/DecibelInstaller.php | 10 +
.../Composer/Installers/DframeInstaller.php | 10 +
.../Composer/Installers/DokuWikiInstaller.php | 50 +
.../Composer/Installers/DolibarrInstaller.php | 16 +
.../Composer/Installers/DrupalInstaller.php | 22 +
.../src/Composer/Installers/ElggInstaller.php | 9 +
.../Composer/Installers/EliasisInstaller.php | 12 +
.../Installers/ExpressionEngineInstaller.php | 29 +
.../Installers/EzPlatformInstaller.php | 10 +
.../src/Composer/Installers/FuelInstaller.php | 11 +
.../Composer/Installers/FuelphpInstaller.php | 9 +
.../src/Composer/Installers/GravInstaller.php | 30 +
.../Composer/Installers/HuradInstaller.php | 25 +
.../Composer/Installers/ImageCMSInstaller.php | 11 +
.../src/Composer/Installers/Installer.php | 298 +
.../src/Composer/Installers/ItopInstaller.php | 9 +
.../Composer/Installers/JoomlaInstaller.php | 15 +
.../Composer/Installers/KanboardInstaller.php | 18 +
.../Composer/Installers/KirbyInstaller.php | 11 +
.../Composer/Installers/KnownInstaller.php | 11 +
.../Composer/Installers/KodiCMSInstaller.php | 10 +
.../Composer/Installers/KohanaInstaller.php | 9 +
.../LanManagementSystemInstaller.php | 27 +
.../Composer/Installers/LaravelInstaller.php | 9 +
.../Composer/Installers/LavaLiteInstaller.php | 10 +
.../Composer/Installers/LithiumInstaller.php | 10 +
.../Installers/MODULEWorkInstaller.php | 9 +
.../Composer/Installers/MODXEvoInstaller.php | 16 +
.../Composer/Installers/MagentoInstaller.php | 11 +
.../Composer/Installers/MajimaInstaller.php | 37 +
.../src/Composer/Installers/MakoInstaller.php | 9 +
.../Composer/Installers/MantisBTInstaller.php | 23 +
.../Composer/Installers/MauticInstaller.php | 48 +
.../src/Composer/Installers/MayaInstaller.php | 33 +
.../Installers/MediaWikiInstaller.php | 51 +
.../Composer/Installers/MiaoxingInstaller.php | 10 +
.../Installers/MicroweberInstaller.php | 119 +
.../src/Composer/Installers/ModxInstaller.php | 12 +
.../Composer/Installers/MoodleInstaller.php | 59 +
.../Composer/Installers/OctoberInstaller.php | 48 +
.../Composer/Installers/OntoWikiInstaller.php | 24 +
.../Composer/Installers/OsclassInstaller.php | 14 +
.../src/Composer/Installers/OxidInstaller.php | 59 +
.../src/Composer/Installers/PPIInstaller.php | 9 +
.../Composer/Installers/PantheonInstaller.php | 12 +
.../Composer/Installers/PhiftyInstaller.php | 11 +
.../Composer/Installers/PhpBBInstaller.php | 11 +
.../Composer/Installers/PimcoreInstaller.php | 21 +
.../Composer/Installers/PiwikInstaller.php | 32 +
.../Installers/PlentymarketsInstaller.php | 29 +
.../src/Composer/Installers/Plugin.php | 27 +
.../Composer/Installers/PortoInstaller.php | 9 +
.../Installers/PrestashopInstaller.php | 10 +
.../Installers/ProcessWireInstaller.php | 22 +
.../Composer/Installers/PuppetInstaller.php | 11 +
.../Composer/Installers/PxcmsInstaller.php | 63 +
.../Composer/Installers/RadPHPInstaller.php | 24 +
.../Composer/Installers/ReIndexInstaller.php | 10 +
.../Composer/Installers/Redaxo5Installer.php | 10 +
.../Composer/Installers/RedaxoInstaller.php | 10 +
.../Installers/RoundcubeInstaller.php | 22 +
.../src/Composer/Installers/SMFInstaller.php | 10 +
.../Composer/Installers/ShopwareInstaller.php | 60 +
.../Installers/SilverStripeInstaller.php | 35 +
.../Installers/SiteDirectInstaller.php | 25 +
.../Composer/Installers/StarbugInstaller.php | 12 +
.../Composer/Installers/SyDESInstaller.php | 47 +
.../Composer/Installers/SyliusInstaller.php | 9 +
.../Composer/Installers/Symfony1Installer.php | 26 +
.../Composer/Installers/TYPO3CmsInstaller.php | 16 +
.../Installers/TYPO3FlowInstaller.php | 38 +
.../src/Composer/Installers/TaoInstaller.php | 30 +
.../Installers/TastyIgniterInstaller.php | 32 +
.../Composer/Installers/TheliaInstaller.php | 12 +
.../src/Composer/Installers/TuskInstaller.php | 14 +
.../Installers/UserFrostingInstaller.php | 9 +
.../Composer/Installers/VanillaInstaller.php | 10 +
.../Composer/Installers/VgmcpInstaller.php | 49 +
.../Composer/Installers/WHMCSInstaller.php | 21 +
.../Composer/Installers/WinterInstaller.php | 58 +
.../Composer/Installers/WolfCMSInstaller.php | 9 +
.../Installers/WordPressInstaller.php | 12 +
.../Composer/Installers/YawikInstaller.php | 32 +
.../src/Composer/Installers/ZendInstaller.php | 11 +
.../Composer/Installers/ZikulaInstaller.php | 10 +
vendor/composer/installers/src/bootstrap.php | 13 +
vendor/composer/platform_check.php | 26 +
vendor/woocommerce/subscriptions-core/.nvmrc | 1 +
.../subscriptions-core/assets}/css/about.css | 79 +-
.../assets}/css/admin-order-statuses.css | 4 +-
.../subscriptions-core/assets}/css/admin.css | 432 +-
.../assets}/css/checkout.css | 11 +-
.../subscriptions-core/assets}/css/modal.css | 21 +-
.../assets}/css/view-subscription.css | 17 +-
.../assets}/css/wcs-upgrade.css | 14 +-
.../images/add-edit-subscription-screen.png | Bin
.../images/admin-change-payment-method.jpg | Bin
.../assets}/images/ajax-loader.gif | Bin
.../assets}/images/ajax-loader@2x.gif | Bin
.../images/billing-schedules-meta-box.png | Bin
.../images/checkout-recurring-totals.png | Bin
.../images/drip-downloadable-content.jpg | Bin
.../assets}/images/gift-subscription.png | Bin
.../assets}/images/renewal-retry-settings.png | Bin
.../images/subscribe-all-the-things.png | Bin
.../assets}/images/subscription-reports.png | Bin
.../images/subscription-suspended-email.jpg | Bin
.../subscriptions-importer-exporter.png | Bin
.../assets}/images/view-subscription.png | Bin
.../images/woocommerce_subscriptions_logo.png | Bin
.../assets/js/admin/admin-pointers.js | 66 +
.../assets/js/admin/admin.js | 1373 ++
.../assets}/js/admin/jstz.js | 0
.../assets}/js/admin/jstz.min.js | 0
.../assets}/js/admin/meta-boxes-coupon.js | 15 +-
.../js/admin/meta-boxes-subscription.js | 354 +
.../assets}/js/admin/moment.js | 0
.../assets}/js/admin/moment.min.js | 0
.../js/admin/payment-method-restrictions.js | 109 +
.../assets/js/admin/wcs-meta-boxes-order.js | 43 +
.../assets/js/frontend/payment-methods.js | 22 +
.../assets}/js/frontend/single-product.js | 19 +-
.../assets}/js/frontend/view-subscription.js | 105 +-
.../assets}/js/frontend/wcs-cart.js | 14 +-
.../subscriptions-core/assets}/js/modal.js | 24 +-
.../assets/js/wcs-upgrade.js | 273 +
.../subscriptions-core/build/index.asset.php | 1 +
.../subscriptions-core/build/index.css | 2 +
.../subscriptions-core/build/index.js | 26 +
.../subscriptions-core/changelog.txt | 100 +
.../abstract-wcs-background-repairer.php | 0
.../abstract-wcs-background-updater.php | 3 +-
.../abstract-wcs-background-upgrader.php | 0
.../abstracts/abstract-wcs-cache-manager.php | 2 +-
.../abstracts/abstract-wcs-customer-store.php | 2 +-
.../abstract-wcs-debug-tool-cache-updater.php | 0
.../abstracts/abstract-wcs-debug-tool.php | 0
...tract-wcs-deprecated-functions-handler.php | 121 +
.../abstract-wcs-dynamic-hook-deprecator.php | 0
.../abstract-wcs-hook-deprecator.php | 4 +-
.../abstracts/abstract-wcs-migrator.php | 0
.../abstract-wcs-related-order-store.php | 2 +-
.../abstracts/abstract-wcs-scheduler.php | 0
.../abstracts/abstract-wcs-table-maker.php | 2 +-
.../admin/class-wc-subscriptions-admin.php | 432 +-
.../admin/class-wcs-admin-meta-boxes.php | 650 +
.../admin/class-wcs-admin-notice.php | 2 +-
.../admin/class-wcs-admin-post-types.php | 56 +-
...cs-admin-product-import-export-manager.php | 107 +
.../admin/class-wcs-admin-system-status.php | 93 +-
.../admin/class-wcs-wc-admin-manager.php | 31 +-
...cs-debug-tool-cache-background-updater.php | 0
.../class-wcs-debug-tool-cache-eraser.php | 0
.../class-wcs-debug-tool-cache-generator.php | 0
.../class-wcs-debug-tool-factory.php | 0
.../class-wcs-meta-box-related-orders.php | 2 +
.../class-wcs-meta-box-schedule.php | 0
.../class-wcs-meta-box-subscription-data.php | 4 +-
.../views/html-related-orders-row.php | 26 +-
.../views/html-related-orders-table.php | 0
.../views/html-subscription-schedule.php | 0
.../views/html-unknown-related-orders-row.php | 7 +-
.../includes}/admin/wcs-admin-functions.php | 0
...lass-wc-product-subscription-variation.php | 2 +-
.../class-wc-product-subscription.php | 0
...class-wc-product-variable-subscription.php | 6 +-
...ubscription-item-coupon-pending-switch.php | 0
...c-subscription-item-fee-pending-switch.php | 0
...lass-wc-subscription-line-item-removed.php | 0
...ass-wc-subscription-line-item-switched.php | 0
.../includes}/class-wc-subscription.php | 43 +-
.../class-wc-subscriptions-addresses.php | 58 +-
.../class-wc-subscriptions-cart-validator.php | 42 +-
.../includes}/class-wc-subscriptions-cart.php | 771 +-
...c-subscriptions-change-payment-gateway.php | 147 +-
.../class-wc-subscriptions-checkout.php | 378 +-
.../class-wc-subscriptions-core-plugin.php | 587 +
.../class-wc-subscriptions-coupon.php | 616 +-
.../class-wc-subscriptions-email.php | 6 +-
...wc-subscriptions-extend-store-endpoint.php | 617 +
...lass-wc-subscriptions-frontend-scripts.php | 88 +
.../class-wc-subscriptions-manager.php | 28 +-
.../class-wc-subscriptions-order.php | 183 +-
.../class-wc-subscriptions-product.php | 56 +-
.../class-wc-subscriptions-renewal-order.php | 2 +-
.../class-wc-subscriptions-synchroniser.php | 42 +-
.../class-wc-subscriptions-tracker.php | 4 +-
.../includes}/class-wcs-action-scheduler.php | 0
.../includes/class-wcs-blocks-integration.php | 100 +
.../class-wcs-cached-data-manager.php | 2 +-
.../class-wcs-cart-initial-payment.php | 37 +-
.../includes}/class-wcs-cart-renewal.php | 258 +-
.../includes}/class-wcs-cart-resubscribe.php | 55 +-
.../class-wcs-change-payment-method-admin.php | 11 +-
.../includes/class-wcs-core-autoloader.php | 254 +
.../class-wcs-custom-order-item-manager.php | 0
.../class-wcs-dependent-hook-manager.php | 0
.../includes}/class-wcs-download-handler.php | 47 +-
...ss-wcs-failed-scheduled-action-manager.php | 42 +-
.../class-wcs-initial-cart-stock-manager.php | 0
.../includes}/class-wcs-limiter.php | 107 +-
.../includes}/class-wcs-modal.php | 8 +-
...class-wcs-my-account-auto-renew-toggle.php | 0
.../class-wcs-my-account-payment-methods.php | 79 +-
.../includes}/class-wcs-object-sorter.php | 0
.../includes}/class-wcs-payment-tokens.php | 23 +-
.../includes}/class-wcs-permalink-manager.php | 0
...cs-post-meta-cache-manager-many-to-one.php | 0
.../class-wcs-post-meta-cache-manager.php | 6 +-
.../includes}/class-wcs-query.php | 80 +-
.../includes}/class-wcs-remove-item.php | 0
.../class-wcs-renewal-cart-stock-manager.php | 0
.../includes}/class-wcs-select2.php | 4 +-
.../includes/class-wcs-sql-transaction.php | 115 +
.../includes/class-wcs-staging.php | 285 +
.../includes/class-wcs-template-loader.php | 423 +
.../class-wcs-user-change-status-handler.php | 0
.../class-wcs-customer-store-cached-cpt.php | 33 +-
.../class-wcs-customer-store-cpt.php | 0
...ss-wcs-product-variable-data-store-cpt.php | 0
...ass-wcs-related-order-store-cached-cpt.php | 6 +-
.../class-wcs-related-order-store-cpt.php | 8 +-
.../class-wcs-subscription-data-store-cpt.php | 0
.../class-wcs-action-deprecator.php | 0
.../class-wcs-deprecated-filter-hooks.php | 0
.../class-wcs-dynamic-action-deprecator.php | 0
.../class-wcs-dynamic-filter-deprecator.php | 0
.../class-wcs-filter-deprecator.php | 0
...s-wc-subscriptions-deprecation-handler.php | 328 +
...class-wcs-email-cancelled-subscription.php | 2 +-
...lass-wcs-email-completed-renewal-order.php | 4 +-
...class-wcs-email-completed-switch-order.php | 4 +-
...s-email-customer-on-hold-renewal-order.php | 2 +-
...ass-wcs-email-customer-renewal-invoice.php | 2 +-
.../class-wcs-email-expired-subscription.php | 2 +-
.../class-wcs-email-new-renewal-order.php | 4 +-
.../class-wcs-email-new-switch-order.php | 5 +-
.../class-wcs-email-on-hold-subscription.php | 2 +-
...ass-wcs-email-processing-renewal-order.php | 4 +-
...wc-subscriptions-core-payment-gateways.php | 407 +
...criptions-gateway-restrictions-manager.php | 71 +
.../gateways/paypal/class-wcs-paypal.php | 4 +-
.../abstracts/abstract-wcs-sv-api-base.php | 0
.../includes/admin/class-wcs-paypal-admin.php | 6 +-
...wcs-paypal-change-payment-method-admin.php | 0
...ypal-reference-transaction-api-request.php | 0
...saction-api-response-billing-agreement.php | 0
...ence-transaction-api-response-checkout.php | 0
...rence-transaction-api-response-payment.php | 0
...saction-api-response-recurring-payment.php | 0
...pal-reference-transaction-api-response.php | 0
...s-wcs-paypal-reference-transaction-api.php | 0
...ypal-reference-transaction-ipn-handler.php | 0
...-paypal-standard-change-payment-method.php | 0
...cs-paypal-standard-ipn-failure-handler.php | 0
.../class-wcs-paypal-standard-ipn-handler.php | 9 +-
.../class-wcs-paypal-standard-request.php | 6 +-
.../class-wcs-paypal-standard-switcher.php | 63 +-
.../class-wcs-paypal-status-manager.php | 6 +-
.../includes/class-wcs-paypal-supports.php | 15 +-
...class-wc-paypal-standard-subscriptions.php | 0
.../includes/templates/admin-notices.php | 0
.../templates/html-ipn-failure-notice.php | 0
.../paypal/includes/wcs-paypal-functions.php | 0
.../interface-wcs-cache-updater.php | 0
.../class-wc-product-subscription-legacy.php | 0
...-product-subscription-variation-legacy.php | 0
...c-product-variable-subscription-legacy.php | 0
.../legacy/class-wc-subscription-legacy.php | 0
...s-array-property-post-meta-black-magic.php | 0
.../legacy/class-wcs-product-legacy.php | 2 +-
.../class-wcs-privacy-background-updater.php | 2 +-
.../privacy/class-wcs-privacy-erasers.php | 0
.../privacy/class-wcs-privacy-exporters.php | 0
.../includes}/privacy/class-wcs-privacy.php | 0
.../class-wc-subscriptions-upgrader.php | 121 +-
.../upgrades/class-wcs-repair-2-0-2.php | 0
.../upgrades/class-wcs-repair-2-0.php | 0
...ss-wcs-repair-line-item-has-trial-meta.php | 0
.../class-wcs-repair-start-date-metadata.php | 0
...cs-repair-subscription-address-indexes.php | 0
...air-subtracted-base-tax-line-item-meta.php | 121 +
...-repair-suspended-paypal-subscriptions.php | 0
.../upgrades/class-wcs-upgrade-1-2.php | 6 +-
.../upgrades/class-wcs-upgrade-1-3.php | 0
.../upgrades/class-wcs-upgrade-1-4.php | 0
.../upgrades/class-wcs-upgrade-1-5.php | 0
.../upgrades/class-wcs-upgrade-2-0.php | 0
.../upgrades/class-wcs-upgrade-2-1.php | 0
.../upgrades/class-wcs-upgrade-2-2-7.php | 0
.../upgrades/class-wcs-upgrade-2-2-9.php | 0
.../upgrades/class-wcs-upgrade-3-1-0.php | 45 +
.../upgrades/class-wcs-upgrade-logger.php | 2 +-
...s-wcs-upgrade-subscription-post-author.php | 0
.../templates/update-welcome-notice.php | 0
.../upgrades/templates/wcs-about-2-0.php | 0
.../upgrades/templates/wcs-about.php | 0
.../templates/wcs-upgrade-in-progress.php | 2 +-
.../upgrades/templates/wcs-upgrade.php | 6 +-
.../includes}/wcs-cart-functions.php | 152 +-
.../includes}/wcs-compatibility-functions.php | 134 +-
.../includes}/wcs-conditional-functions.php | 1 +
.../includes}/wcs-deprecated-functions.php | 12 +-
.../includes}/wcs-formatting-functions.php | 60 +-
.../includes}/wcs-helper-functions.php | 31 +-
.../includes}/wcs-limit-functions.php | 0
.../includes}/wcs-order-functions.php | 124 +-
.../includes}/wcs-product-functions.php | 10 +-
.../includes}/wcs-renewal-functions.php | 20 +
.../includes}/wcs-resubscribe-functions.php | 0
.../includes}/wcs-switch-functions.php | 22 +
.../includes}/wcs-time-functions.php | 60 +-
.../includes}/wcs-user-functions.php | 69 +-
.../languages/woocommerce-subscriptions-fr.mo | Bin 0 -> 190575 bytes
.../languages/woocommerce-subscriptions-fr.po | 8189 ++++++++++++
.../languages/woocommerce-subscriptions.pot | 6896 ++++++++++
.../subscriptions-core}/license.txt | 396 +-
.../admin/deprecated/html-variation-price.php | 0
.../html-variation-synchronisation.php | 0
.../admin/deprecated/order-shipping-html.php | 0
.../admin/deprecated/order-tax-html.php | 0
.../templates}/admin/html-admin-notice.php | 0
.../html-failed-scheduled-action-notice.php | 0
.../templates}/admin/html-variation-price.php | 0
.../admin/html-variation-synchronisation.php | 0
.../templates}/admin/status.php | 0
.../cart/cart-recurring-shipping.php | 0
.../checkout/form-change-payment-method.php | 3 +-
.../checkout/recurring-coupon-totals.php | 34 +
.../checkout/recurring-fee-totals.php | 19 +
.../recurring-itemized-tax-totals.php | 49 +
.../recurring-subscription-totals.php | 24 +
.../checkout/recurring-subtotals.php | 23 +
.../checkout/recurring-tax-totals.php | 38 +
.../templates/checkout/recurring-totals.php | 57 +
.../checkout/subscription-receipt.php | 0
.../emails/admin-new-renewal-order.php | 0
.../emails/admin-new-switch-order.php | 0
.../templates}/emails/admin-payment-retry.php | 0
.../emails/cancelled-subscription.php | 0
.../customer-completed-renewal-order.php | 0
.../customer-completed-switch-order.php | 0
.../emails/customer-on-hold-renewal-order.php | 0
.../emails/customer-payment-retry.php | 0
.../customer-processing-renewal-order.php | 0
.../emails/customer-renewal-invoice.php | 0
.../templates}/emails/email-order-details.php | 0
.../emails/expired-subscription.php | 0
.../emails/on-hold-subscription.php | 0
.../emails/plain/admin-new-renewal-order.php | 0
.../emails/plain/admin-new-switch-order.php | 0
.../emails/plain/admin-payment-retry.php | 0
.../emails/plain/cancelled-subscription.php | 0
.../customer-completed-renewal-order.php | 0
.../plain/customer-completed-switch-order.php | 0
.../plain/customer-on-hold-renewal-order.php | 0
.../emails/plain/customer-payment-retry.php | 0
.../customer-processing-renewal-order.php | 0
.../emails/plain/customer-renewal-invoice.php | 0
.../emails/plain/email-order-details.php | 0
.../emails/plain/expired-subscription.php | 0
.../emails/plain/on-hold-subscription.php | 0
.../emails/plain/subscription-info.php | 2 +-
.../templates}/emails/subscription-info.php | 2 +-
.../templates}/html-modal.php | 0
.../templates}/myaccount/my-subscriptions.php | 0
.../templates}/myaccount/related-orders.php | 0
.../myaccount/related-subscriptions.php | 0
.../myaccount/subscription-details.php | 4 +-
.../myaccount/subscription-totals-table.php | 0
.../myaccount/subscription-totals.php | 0
.../templates}/myaccount/subscriptions.php | 2 +-
.../myaccount/view-subscription.php | 0
.../add-to-cart/subscription.php | 0
.../add-to-cart/variable-subscription.php | 4 +-
.../subscriptions-core/wcs-functions.php | 21 +-
.../woocommerce-subscriptions-core.php | 10 +
.../subscriptions-core/wpml-config.xml | 53 +
woo-includes/woo-functions.php | 32 -
woocommerce-subscriptions.php | 1374 +-
562 files changed, 47883 insertions(+), 23303 deletions(-)
delete mode 100644 assets/js/admin/admin-pointers.js
delete mode 100644 assets/js/admin/admin.js
delete mode 100644 assets/js/admin/meta-boxes-subscription.js
delete mode 100644 assets/js/admin/wcs-meta-boxes-order.js
delete mode 100644 assets/js/wcs-upgrade.js
delete mode 100644 includes/admin/class-wcs-admin-meta-boxes.php
create mode 100644 includes/api/class-wc-rest-subscription-system-status-manager.php
create mode 100644 includes/api/v1/class-wc-rest-subscription-notes-v1-controller.php
create mode 100644 includes/api/v1/class-wc-rest-subscriptions-v1-controller.php
create mode 100644 includes/class-wc-subscriptions-plugin.php
create mode 100644 includes/class-wcs-call-to-action-button-text-manager.php
create mode 100644 includes/class-wcs-customer-suspension-manager.php
create mode 100644 includes/class-wcs-drip-downloads-manager.php
create mode 100644 includes/class-wcs-limited-recurring-coupon-manager.php
create mode 100644 includes/class-wcs-manual-renewal-manager.php
delete mode 100644 includes/class-wcs-staging.php
create mode 100644 includes/class-wcs-subscriber-role-manager.php
delete mode 100644 includes/class-wcs-template-loader.php
rename includes/{upgrades => }/class-wcs-upgrade-notice-manager.php (74%)
create mode 100644 includes/class-wcs-zero-initial-payment-checkout-manager.php
delete mode 100644 includes/libraries/action-scheduler/action-scheduler.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_FatalErrorMonitor.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_ListTable.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_OptionLock.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php
delete mode 100644 includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php
delete mode 100644 includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_QueueRunner.php
delete mode 100644 includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php
delete mode 100644 includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php
delete mode 100644 includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php
delete mode 100644 includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php
delete mode 100644 includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php
delete mode 100644 includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php
delete mode 100644 includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php
delete mode 100644 includes/libraries/action-scheduler/classes/actions/ActionScheduler_NullAction.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php
delete mode 100644 includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/ActionMigrator.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/BatchFetcher.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/Config.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/Controller.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/DryRun_LogMigrator.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/LogMigrator.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/Runner.php
delete mode 100644 includes/libraries/action-scheduler/classes/migration/Scheduler.php
delete mode 100644 includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php
delete mode 100644 includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php
delete mode 100644 includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php
delete mode 100644 includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php
delete mode 100644 includes/libraries/action-scheduler/deprecated/ActionScheduler_AdminView_Deprecated.php
delete mode 100644 includes/libraries/action-scheduler/deprecated/ActionScheduler_Schedule_Deprecated.php
delete mode 100644 includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php
delete mode 100644 includes/libraries/action-scheduler/deprecated/functions.php
delete mode 100644 includes/libraries/action-scheduler/functions.php
delete mode 100644 includes/libraries/action-scheduler/lib/WP_Async_Request.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php
delete mode 100755 includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php
delete mode 100644 includes/libraries/class-wc-datetime.php
rename includes/{admin/meta-boxes => payment-retry/admin}/class-wcs-meta-box-payment-retries.php (90%)
rename includes/payment-retry/{ => admin}/class-wcs-retry-admin.php (100%)
rename includes/{admin/meta-boxes/views => payment-retry/admin}/html-retries-table.php (100%)
rename includes/{ => payment-retry}/class-wcs-retry-manager.php (98%)
rename includes/{abstracts => payment-retry/data-stores}/abstract-wcs-retry-store.php (100%)
rename includes/payment-retry/{ => data-stores}/class-wcs-retry-database-store.php (100%)
rename includes/payment-retry/{ => data-stores}/class-wcs-retry-hybrid-store.php (100%)
rename includes/payment-retry/{ => data-stores}/class-wcs-retry-post-store.php (100%)
rename includes/payment-retry/{ => data-stores}/class-wcs-retry-stores.php (100%)
rename includes/{ => payment-retry}/emails/class-wcs-email-customer-payment-retry.php (97%)
rename includes/{ => payment-retry}/emails/class-wcs-email-payment-retry.php (97%)
rename includes/payment-retry/{ => emails}/class-wcs-retry-email.php (100%)
rename includes/{ => switching}/class-wc-order-item-pending-switch.php (100%)
rename includes/{ => switching}/class-wc-subscriptions-switcher.php (94%)
rename includes/{ => switching}/class-wcs-add-cart-item.php (84%)
rename includes/{ => switching}/class-wcs-cart-switch.php (82%)
rename includes/{ => switching}/class-wcs-switch-cart-item.php (75%)
rename includes/{ => switching}/class-wcs-switch-totals-calculator.php (88%)
mode change 100644 => 100755
create mode 100644 languages/woocommerce-subscriptions-fr.mo
create mode 100644 languages/woocommerce-subscriptions-fr.po
delete mode 100644 phpcs.xml
delete mode 100644 readme.txt
delete mode 100644 templates/checkout/recurring-totals.php
create mode 100644 vendor/autoload.php
create mode 100644 vendor/composer/ClassLoader.php
create mode 100644 vendor/composer/InstalledVersions.php
rename {includes/libraries/action-scheduler/lib/cron-expression => vendor/composer}/LICENSE (81%)
mode change 100755 => 100644
create mode 100644 vendor/composer/autoload_classmap.php
create mode 100644 vendor/composer/autoload_namespaces.php
create mode 100644 vendor/composer/autoload_psr4.php
create mode 100644 vendor/composer/autoload_real.php
create mode 100644 vendor/composer/autoload_static.php
create mode 100644 vendor/composer/installed.json
create mode 100644 vendor/composer/installed.php
create mode 100644 vendor/composer/installers/.github/workflows/continuous-integration.yml
create mode 100644 vendor/composer/installers/.github/workflows/lint.yml
create mode 100644 vendor/composer/installers/.github/workflows/phpstan.yml
create mode 100644 vendor/composer/installers/LICENSE
create mode 100644 vendor/composer/installers/composer.json
create mode 100644 vendor/composer/installers/phpstan.neon.dist
create mode 100644 vendor/composer/installers/src/Composer/Installers/AglInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/AimeosInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/AnnotateCmsInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/AsgardInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/AttogramInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/BaseInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/BitrixInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/BonefishInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ChefInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/CiviCrmInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ClanCatsFrameworkInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/CockpitInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/CodeIgniterInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/Concrete5Installer.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/CraftInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/CroogoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/DecibelInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/DframeInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/DokuWikiInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/DolibarrInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/DrupalInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ElggInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/EliasisInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ExpressionEngineInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/EzPlatformInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/FuelInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/FuelphpInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/GravInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/HuradInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ImageCMSInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/Installer.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ItopInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/JoomlaInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/KanboardInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/KirbyInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/KnownInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/KodiCMSInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/KohanaInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/LanManagementSystemInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/LaravelInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/LavaLiteInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/LithiumInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MODULEWorkInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MODXEvoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MagentoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MajimaInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MakoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MantisBTInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MauticInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MayaInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MediaWikiInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MiaoxingInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MicroweberInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ModxInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/MoodleInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/OctoberInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/OntoWikiInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/OsclassInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/OxidInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PPIInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PantheonInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PhiftyInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PhpBBInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PimcoreInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PiwikInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PlentymarketsInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/Plugin.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PortoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PrestashopInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ProcessWireInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PuppetInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/PxcmsInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/RadPHPInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ReIndexInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/Redaxo5Installer.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/RedaxoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/RoundcubeInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/SMFInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ShopwareInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/SilverStripeInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/SiteDirectInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/StarbugInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/SyDESInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/SyliusInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/Symfony1Installer.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/TYPO3CmsInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/TYPO3FlowInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/TaoInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/TastyIgniterInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/TheliaInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/TuskInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/UserFrostingInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/VanillaInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/VgmcpInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/WHMCSInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/WinterInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/WolfCMSInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/WordPressInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/YawikInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ZendInstaller.php
create mode 100644 vendor/composer/installers/src/Composer/Installers/ZikulaInstaller.php
create mode 100644 vendor/composer/installers/src/bootstrap.php
create mode 100644 vendor/composer/platform_check.php
create mode 100644 vendor/woocommerce/subscriptions-core/.nvmrc
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/about.css (63%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/admin-order-statuses.css (91%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/admin.css (62%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/checkout.css (73%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/modal.css (88%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/view-subscription.css (81%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/css/wcs-upgrade.css (72%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/add-edit-subscription-screen.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/admin-change-payment-method.jpg (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/ajax-loader.gif (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/ajax-loader@2x.gif (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/billing-schedules-meta-box.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/checkout-recurring-totals.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/drip-downloadable-content.jpg (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/gift-subscription.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/renewal-retry-settings.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/subscribe-all-the-things.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/subscription-reports.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/subscription-suspended-email.jpg (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/subscriptions-importer-exporter.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/view-subscription.png (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/images/woocommerce_subscriptions_logo.png (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js
create mode 100644 vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/admin/jstz.js (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/admin/jstz.min.js (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/admin/meta-boxes-coupon.js (81%)
create mode 100644 vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/admin/moment.js (100%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/admin/moment.min.js (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js
create mode 100644 vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js
create mode 100755 vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/frontend/single-product.js (69%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/frontend/view-subscription.js (54%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/frontend/wcs-cart.js (66%)
rename {assets => vendor/woocommerce/subscriptions-core/assets}/js/modal.js (88%)
create mode 100644 vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js
create mode 100644 vendor/woocommerce/subscriptions-core/build/index.asset.php
create mode 100644 vendor/woocommerce/subscriptions-core/build/index.css
create mode 100644 vendor/woocommerce/subscriptions-core/build/index.js
create mode 100644 vendor/woocommerce/subscriptions-core/changelog.txt
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-background-repairer.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-background-updater.php (95%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-background-upgrader.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-cache-manager.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-customer-store.php (94%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-debug-tool-cache-updater.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-debug-tool.php (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/abstracts/abstract-wcs-deprecated-functions-handler.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-dynamic-hook-deprecator.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-hook-deprecator.php (95%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-migrator.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-related-order-store.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-scheduler.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/abstracts/abstract-wcs-table-maker.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/class-wc-subscriptions-admin.php (82%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/admin/class-wcs-admin-meta-boxes.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/class-wcs-admin-notice.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/class-wcs-admin-post-types.php (95%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/admin/class-wcs-admin-product-import-export-manager.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/class-wcs-admin-system-status.php (87%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/class-wcs-wc-admin-manager.php (64%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/debug-tools/class-wcs-debug-tool-cache-background-updater.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/debug-tools/class-wcs-debug-tool-cache-eraser.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/debug-tools/class-wcs-debug-tool-cache-generator.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/debug-tools/class-wcs-debug-tool-factory.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/class-wcs-meta-box-related-orders.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/class-wcs-meta-box-schedule.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/class-wcs-meta-box-subscription-data.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/views/html-related-orders-row.php (65%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/views/html-related-orders-table.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/views/html-subscription-schedule.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/meta-boxes/views/html-unknown-related-orders-row.php (64%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/admin/wcs-admin-functions.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-product-subscription-variation.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-product-subscription.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-product-variable-subscription.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscription-item-coupon-pending-switch.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscription-item-fee-pending-switch.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscription-line-item-removed.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscription-line-item-switched.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscription.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-addresses.php (76%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-cart-validator.php (79%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-cart.php (80%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-change-payment-gateway.php (89%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-checkout.php (65%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-core-plugin.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-coupon.php (81%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-email.php (97%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-extend-store-endpoint.php
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wc-subscriptions-frontend-scripts.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-manager.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-order.php (95%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-product.php (96%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-renewal-order.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-synchroniser.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wc-subscriptions-tracker.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-action-scheduler.php (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wcs-blocks-integration.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-cached-data-manager.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-cart-initial-payment.php (82%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-cart-renewal.php (86%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-cart-resubscribe.php (87%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-change-payment-method-admin.php (91%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wcs-core-autoloader.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-custom-order-item-manager.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-dependent-hook-manager.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-download-handler.php (95%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-failed-scheduled-action-manager.php (73%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-initial-cart-stock-manager.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-limiter.php (75%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-modal.php (90%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-my-account-auto-renew-toggle.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-my-account-payment-methods.php (70%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-object-sorter.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-payment-tokens.php (86%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-permalink-manager.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-post-meta-cache-manager-many-to-one.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-post-meta-cache-manager.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-query.php (86%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-remove-item.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-renewal-cart-stock-manager.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-select2.php (94%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wcs-sql-transaction.php
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wcs-staging.php
create mode 100644 vendor/woocommerce/subscriptions-core/includes/class-wcs-template-loader.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/class-wcs-user-change-status-handler.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/data-stores/class-wcs-customer-store-cached-cpt.php (93%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/data-stores/class-wcs-customer-store-cpt.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/data-stores/class-wcs-product-variable-data-store-cpt.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/data-stores/class-wcs-related-order-store-cached-cpt.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/data-stores/class-wcs-related-order-store-cpt.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/data-stores/class-wcs-subscription-data-store-cpt.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/deprecated/class-wcs-action-deprecator.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/deprecated/class-wcs-deprecated-filter-hooks.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/deprecated/class-wcs-dynamic-action-deprecator.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/deprecated/class-wcs-dynamic-filter-deprecator.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/deprecated/class-wcs-filter-deprecator.php (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/deprecated/deprecation-handlers/class-wc-subscriptions-deprecation-handler.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-cancelled-subscription.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-completed-renewal-order.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-completed-switch-order.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-customer-on-hold-renewal-order.php (96%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-customer-renewal-invoice.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-expired-subscription.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-new-renewal-order.php (96%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-new-switch-order.php (96%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-on-hold-subscription.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/emails/class-wcs-email-processing-renewal-order.php (96%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/gateways/class-wc-subscriptions-core-payment-gateways.php
create mode 100644 vendor/woocommerce/subscriptions-core/includes/gateways/class-wc-subscriptions-gateway-restrictions-manager.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/class-wcs-paypal.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/abstracts/abstract-wcs-sv-api-base.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/admin/class-wcs-paypal-admin.php (96%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/admin/class-wcs-paypal-change-payment-method-admin.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-request.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-response-billing-agreement.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-response-checkout.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-response-payment.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-response-recurring-payment.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api-response.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-api.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-reference-transaction-ipn-handler.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-standard-change-payment-method.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-standard-ipn-failure-handler.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-standard-ipn-handler.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-standard-request.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-standard-switcher.php (75%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-status-manager.php (89%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/class-wcs-paypal-supports.php (86%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/deprecated/class-wc-paypal-standard-subscriptions.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/templates/admin-notices.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/templates/html-ipn-failure-notice.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/gateways/paypal/includes/wcs-paypal-functions.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/interfaces/interface-wcs-cache-updater.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/legacy/class-wc-product-subscription-legacy.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/legacy/class-wc-product-subscription-variation-legacy.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/legacy/class-wc-product-variable-subscription-legacy.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/legacy/class-wc-subscription-legacy.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/legacy/class-wcs-array-property-post-meta-black-magic.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/legacy/class-wcs-product-legacy.php (84%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/privacy/class-wcs-privacy-background-updater.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/privacy/class-wcs-privacy-erasers.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/privacy/class-wcs-privacy-exporters.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/privacy/class-wcs-privacy.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wc-subscriptions-upgrader.php (89%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-repair-2-0-2.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-repair-2-0.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-repair-line-item-has-trial-meta.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-repair-start-date-metadata.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-repair-subscription-address-indexes.php (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/upgrades/class-wcs-repair-subtracted-base-tax-line-item-meta.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-repair-suspended-paypal-subscriptions.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-1-2.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-1-3.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-1-4.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-1-5.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-2-0.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-2-1.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-2-2-7.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-2-2-9.php (100%)
create mode 100644 vendor/woocommerce/subscriptions-core/includes/upgrades/class-wcs-upgrade-3-1-0.php
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-logger.php (98%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/class-wcs-upgrade-subscription-post-author.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/templates/update-welcome-notice.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/templates/wcs-about-2-0.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/templates/wcs-about.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/templates/wcs-upgrade-in-progress.php (92%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/upgrades/templates/wcs-upgrade.php (93%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-cart-functions.php (69%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-compatibility-functions.php (86%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-conditional-functions.php (99%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-deprecated-functions.php (97%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-formatting-functions.php (87%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-helper-functions.php (90%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-limit-functions.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-order-functions.php (90%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-product-functions.php (95%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-renewal-functions.php (87%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-resubscribe-functions.php (100%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-switch-functions.php (79%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-time-functions.php (94%)
rename {includes => vendor/woocommerce/subscriptions-core/includes}/wcs-user-functions.php (88%)
create mode 100644 vendor/woocommerce/subscriptions-core/languages/woocommerce-subscriptions-fr.mo
create mode 100644 vendor/woocommerce/subscriptions-core/languages/woocommerce-subscriptions-fr.po
create mode 100644 vendor/woocommerce/subscriptions-core/languages/woocommerce-subscriptions.pot
rename {includes/libraries/action-scheduler => vendor/woocommerce/subscriptions-core}/license.txt (66%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/deprecated/html-variation-price.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/deprecated/html-variation-synchronisation.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/deprecated/order-shipping-html.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/deprecated/order-tax-html.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/html-admin-notice.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/html-failed-scheduled-action-notice.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/html-variation-price.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/html-variation-synchronisation.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/admin/status.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/cart/cart-recurring-shipping.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/checkout/form-change-payment-method.php (95%)
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-coupon-totals.php
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-fee-totals.php
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-itemized-tax-totals.php
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-subscription-totals.php
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-subtotals.php
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-tax-totals.php
create mode 100644 vendor/woocommerce/subscriptions-core/templates/checkout/recurring-totals.php
rename {templates => vendor/woocommerce/subscriptions-core/templates}/checkout/subscription-receipt.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/admin-new-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/admin-new-switch-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/admin-payment-retry.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/cancelled-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/customer-completed-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/customer-completed-switch-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/customer-on-hold-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/customer-payment-retry.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/customer-processing-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/customer-renewal-invoice.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/email-order-details.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/expired-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/on-hold-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/admin-new-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/admin-new-switch-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/admin-payment-retry.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/cancelled-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/customer-completed-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/customer-completed-switch-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/customer-on-hold-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/customer-payment-retry.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/customer-processing-renewal-order.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/customer-renewal-invoice.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/email-order-details.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/expired-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/on-hold-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/plain/subscription-info.php (98%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/emails/subscription-info.php (97%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/html-modal.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/my-subscriptions.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/related-orders.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/related-subscriptions.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/subscription-details.php (97%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/subscription-totals-table.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/subscription-totals.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/subscriptions.php (76%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/myaccount/view-subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/single-product/add-to-cart/subscription.php (100%)
rename {templates => vendor/woocommerce/subscriptions-core/templates}/single-product/add-to-cart/variable-subscription.php (97%)
rename wcs-functions.php => vendor/woocommerce/subscriptions-core/wcs-functions.php (98%)
create mode 100644 vendor/woocommerce/subscriptions-core/woocommerce-subscriptions-core.php
create mode 100644 vendor/woocommerce/subscriptions-core/wpml-config.xml
diff --git a/assets/js/admin/admin-pointers.js b/assets/js/admin/admin-pointers.js
deleted file mode 100644
index d32fd3d..0000000
--- a/assets/js/admin/admin-pointers.js
+++ /dev/null
@@ -1,57 +0,0 @@
-jQuery(document).ready(function($){
-
- if(arePointersEnabled()){
- setTimeout(showSubscriptionPointers, 800); // give TinyMCE a chance to finish loading
- }
-
- $('select#product-type').change(function(){
- if(arePointersEnabled()){
- $('#product-type').pointer('close');
- }
- });
-
- $('#_subscription_price, #_subscription_period, #_subscription_length').change(function(){
- if(arePointersEnabled()){
- $('.options_group.subscription_pricing').pointer('close');
- $('#product-type').pointer('close');
- }
- });
-
- function arePointersEnabled(){
- if($.getParameterByName('subscription_pointers')=='true'){
- return true;
- } else {
- return false;
- }
- }
-
- function showSubscriptionPointers(){
- $('#product-type').pointer({
- content: WCSPointers.typePointerContent,
- position: {
- edge: 'left',
- align: 'center'
- },
- close: function() {
- if ($('select#product-type').val()==WCSubscriptions.productType){
- $('.options_group.subscription_pricing:not(".subscription_sync")').pointer({
- content: WCSPointers.pricePointerContent,
- position: 'bottom',
- close: function() {
- dismissSubscriptionPointer();
- }
- }).pointer('open');
- }
- dismissSubscriptionPointer();
- }
- }).pointer('open');
- }
-
- function dismissSubscriptionPointer(){
- $.post( ajaxurl, {
- pointer: 'wcs_pointer',
- action: 'dismiss-wp-pointer'
- });
- }
-
-});
\ No newline at end of file
diff --git a/assets/js/admin/admin.js b/assets/js/admin/admin.js
deleted file mode 100644
index 0de3752..0000000
--- a/assets/js/admin/admin.js
+++ /dev/null
@@ -1,831 +0,0 @@
-jQuery(document).ready(function($){
-
- $.extend({
- getParameterByName: function(name) {
- name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');
- var regexS = '[\\?&]' + name + '=([^]*)';
- var regex = new RegExp(regexS);
- var results = regex.exec(window.location.search);
- if(results == null) {
- return '';
- } else {
- return decodeURIComponent(results[1].replace(/\+/g, ' '));
- }
- },
- daysInMonth: function( month ) {
- // Intentionally choose a non-leap year because we want february to have only 28 days.
- return new Date(Date.UTC(2001, month, 0)).getUTCDate();
- },
- showHideSubscriptionMeta: function(){
- if ($('select#product-type').val()==WCSubscriptions.productType) {
- $('.show_if_simple').show();
- $('.grouping_options').hide();
- $('.options_group.pricing ._regular_price_field').hide();
- $('#sale-price-period').show();
- $('.hide_if_subscription').hide();
- $( 'input#_manage_stock' ).change();
-
- if('day' == $('#_subscription_period').val()) {
- $('.subscription_sync').hide();
- }
- } else {
- $('.options_group.pricing ._regular_price_field').show();
- $('#sale-price-period').hide();
- }
- },
- showHideVariableSubscriptionMeta: function(){
- // In order for WooCommerce not to show the stock_status_field on variable subscriptions, make sure it has the hide if variable subscription class.
- $( 'p.stock_status_field' ).addClass( 'hide_if_variable-subscription' );
-
- if ($('select#product-type').val()=='variable-subscription') {
-
- $( 'input#_downloadable' ).prop( 'checked', false );
- $( 'input#_virtual' ).removeAttr( 'checked' );
-
- $('.show_if_variable').show();
- $('.hide_if_variable').hide();
- $('.show_if_variable-subscription').show();
- $('.hide_if_variable-subscription').hide();
- $.showOrHideStockFields();
-
- // Make the sale price row full width
- $('.sale_price_dates_fields').prev('.form-row').addClass('form-row-full').removeClass('form-row-last');
-
- } else {
-
- if ( 'variable' === $('select#product-type').val() ) {
- $( '.show_if_variable-subscription' ).hide();
- $( '.show_if_variable' ).show();
- $( '.hide_if_variable' ).hide();
- $.showOrHideStockFields();
- }
-
- // Restore the sale price row width to half
- $('.sale_price_dates_fields').prev('.form-row').removeClass('form-row-full').addClass('form-row-last');
- }
- },
- showOrHideStockFields : function(){
- if ( $( 'input#_manage_stock' ).is( ':checked' ) ) {
- $( 'div.stock_fields' ).show();
- } else {
- $( 'div.stock_fields' ).hide();
- }
- },
- setSubscriptionLengths: function(){
- $('[name^="_subscription_length"], [name^="variable_subscription_length"]').each(function(){
- var $lengthElement = $(this),
- selectedLength = $lengthElement.val(),
- hasSelectedLength = false,
- matches = $lengthElement.attr('name').match(/\[(.*?)\]/),
- periodSelector,
- interval;
-
- if (matches) { // Variation
- periodSelector = '[name="variable_subscription_period['+matches[1]+']"]';
- billingInterval = parseInt($('[name="variable_subscription_period_interval['+matches[1]+']"]').val());
- } else {
- periodSelector = '#_subscription_period';
- billingInterval = parseInt($('#_subscription_period_interval').val());
- }
-
- $lengthElement.empty();
-
- $.each(WCSubscriptions.subscriptionLengths[ $(periodSelector).val() ], function(length,description) {
- if(parseInt(length) == 0 || 0 == (parseInt(length) % billingInterval)) {
- $lengthElement.append($(' ').attr('value',length).text(description));
- }
- });
-
- $lengthElement.children('option').each(function(){
- if (this.value == selectedLength) {
- hasSelectedLength = true;
- return false;
- }
- });
-
- if(hasSelectedLength){
- $lengthElement.val(selectedLength);
- } else {
- $lengthElement.val(0);
- }
-
- });
- },
- setTrialPeriods: function(){
- $('[name^="_subscription_trial_length"], [name^="variable_subscription_trial_length"]').each(function(){
- var $trialLengthElement = $(this),
- trialLength = $trialLengthElement.val(),
- matches = $trialLengthElement.attr('name').match(/\[(.*?)\]/),
- periodStrings;
-
- if (matches) { // Variation
- $trialPeriodElement = $('[name="variable_subscription_trial_period['+matches[1]+']"]');
- } else {
- $trialPeriodElement = $('#_subscription_trial_period');
- }
-
- selectedTrialPeriod = $trialPeriodElement.val();
-
- $trialPeriodElement.empty();
-
- if( parseInt(trialLength) == 1 ) {
- periodStrings = WCSubscriptions.trialPeriodSingular;
- } else {
- periodStrings = WCSubscriptions.trialPeriodPlurals;
- }
-
- $.each(periodStrings, function(key,description) {
- $trialPeriodElement.append($(' ').attr('value',key).text(description));
- });
-
- $trialPeriodElement.val(selectedTrialPeriod);
- });
- },
- setSalePeriod: function(){
- $('#sale-price-period').fadeOut(80,function(){
- $('#sale-price-period').text($('#_subscription_period_interval option:selected').text()+' '+$('#_subscription_period option:selected').text());
- $('#sale-price-period').fadeIn(180);
- });
- },
- setSyncOptions: function(periodField) {
-
- if ( typeof periodField != 'undefined' ) {
-
- if ($('select#product-type').val()=='variable-subscription') {
- var $container = periodField.closest('.woocommerce_variable_attributes').find('.variable_subscription_sync');
- } else {
- $container = periodField.closest('#general_product_data').find('.subscription_sync');
- }
-
- var $syncWeekMonthContainer = $container.find('.subscription_sync_week_month'),
- $syncWeekMonthSelect = $syncWeekMonthContainer.find('select'),
- $syncAnnualContainer = $container.find('.subscription_sync_annual'),
- $varSubField = $container.find('[name^="variable_subscription_payment_sync_date"]'),
- billingPeriod;
-
- if ($varSubField.length > 0) { // Variation
- var matches = $varSubField.attr('name').match(/\[(.*?)\]/);
- $subscriptionPeriodElement = $('[name="variable_subscription_period['+matches[1]+']"]');
- } else {
- $subscriptionPeriodElement = $('#_subscription_period');
- }
-
- billingPeriod = $subscriptionPeriodElement.val();
-
- if('day'==billingPeriod) {
- $syncWeekMonthSelect.val(0);
- $syncAnnualContainer.find('input[type="number"]').val(0).trigger('change');
- } else {
- if('year'==billingPeriod) {
- // Make sure the year sync fields are reset
- $syncAnnualContainer.find('input[type="number"]').val(0).trigger('change');
- // And the week/month field has no option selected
- $syncWeekMonthSelect.val(0);
- } else {
- // Make sure the year sync value is 0
- $syncAnnualContainer.find('input[type="number"]').val(0).trigger('change');
-
- // And the week/month field has the appropriate options
- $syncWeekMonthSelect.empty();
- $.each(WCSubscriptions.syncOptions[billingPeriod], function(key,description) {
- $syncWeekMonthSelect.append($(' ').attr('value',key).text(description));
- });
- }
- }
- }
- },
- showHideSyncOptions: function(){
- if($('#_subscription_payment_sync_date').length > 0 || $('.wc_input_subscription_payment_sync').length > 0){
- $('.subscription_sync, .variable_subscription_sync').each(function(){ // loop through all sync field groups
- var $syncWeekMonthContainer = $(this).find('.subscription_sync_week_month'),
- $syncWeekMonthSelect = $syncWeekMonthContainer.find('select'),
- $syncAnnualContainer = $(this).find('.subscription_sync_annual'),
- $varSubField = $(this).find('[name^="variable_subscription_payment_sync_date"]'),
- $slideSwitch = false, // stop the general sync field group sliding down if editing a variable subscription
- billingPeriod;
-
- if ($varSubField.length > 0) { // Variation
- var matches = $varSubField.attr('name').match(/\[(.*?)\]/);
- $subscriptionPeriodElement = $('[name="variable_subscription_period['+matches[1]+']"]');
-
- if ($('select#product-type').val()=='variable-subscription') {
- $slideSwitch = true;
- }
- } else {
- $subscriptionPeriodElement = $('#_subscription_period');
- if ($('select#product-type').val()==WCSubscriptions.productType) {
- $slideSwitch = true;
- }
- }
-
- billingPeriod = $subscriptionPeriodElement.val();
-
- if('day'==billingPeriod) {
- $(this).slideUp(400);
- } else {
- if ( $slideSwitch ) {
- $(this).slideDown(400);
- if('year'==billingPeriod) {
- // Make sure the year sync fields are visible
- $syncAnnualContainer.slideDown(400);
- // And the week/month field is hidden
- $syncWeekMonthContainer.slideUp(400);
- } else {
- // Make sure the year sync fields are hidden
- $syncAnnualContainer.slideUp(400);
- // And the week/month field is visible
- $syncWeekMonthContainer.slideDown(400);
- }
- }
- }
- });
- }
- },
- moveSubscriptionVariationFields: function(){
- $('#variable_product_options .variable_subscription_pricing').not('wcs_moved').each(function(){
- var $regularPriceRow = $(this).siblings('.variable_pricing'),
- $trialSignUpRow = $(this).siblings('.variable_subscription_trial_sign_up'),
- $saleDatesRow;
-
- $saleDatesRow = $(this).siblings('.variable_pricing');
-
- // Add the subscription price fields above the standard price fields
- $(this).insertBefore($regularPriceRow);
-
- $trialSignUpRow.insertBefore($(this));
-
- // Replace the regular price field with the trial period field
- $regularPriceRow.children(':first').addClass('hide_if_variable-subscription');
-
- $(this).addClass('wcs_moved');
- });
- },
- getVariationBulkEditValue: function(variation_action){
- var value;
-
- switch( variation_action ) {
- case 'variable_subscription_period':
- case 'variable_subscription_trial_period':
- value = prompt( WCSubscriptions.bulkEditPeriodMessage );
- break;
- case 'variable_subscription_period_interval':
- value = prompt( WCSubscriptions.bulkEditIntervalhMessage );
- break;
- case 'variable_subscription_trial_length':
- case 'variable_subscription_length':
- value = prompt( WCSubscriptions.bulkEditLengthMessage );
- break;
- case 'variable_subscription_sign_up_fee':
- value = prompt( woocommerce_admin_meta_boxes_variations.i18n_enter_a_value );
- value = accounting.unformat( value, woocommerce_admin.mon_decimal_point );
- break;
- }
-
- return value;
- },
- disableEnableOneTimeShipping: function() {
- var is_synced_or_has_trial = false;
-
- if ( 'variable-subscription' == $( 'select#product-type' ).val() ) {
- var variations = $( '.woocommerce_variations .woocommerce_variation' ),
- variations_checked = {},
- number_of_pages = $( '.woocommerce_variations' ).attr( 'data-total_pages' );
-
- $(variations).each(function() {
- var period_field = $( this ).find( '.wc_input_subscription_period' ),
- variation_index = $( period_field ).attr( 'name' ).match(/\[(.*?)\]/),
- variation_id = $( '[name="variable_post_id['+variation_index[1]+']"]' ).val(),
- period = period_field.val(),
- trial = $( this ).find( '.wc_input_subscription_trial_length' ).val(),
- sync_date = 0;
-
- if ( 0 != trial ) {
- is_synced_or_has_trial = true;
-
- // break
- return false;
- }
-
- if ( $( this ).find( '.variable_subscription_sync' ).length ) {
- if ( 'month' == period || 'week' == period ) {
- sync_date = $( '[name="variable_subscription_payment_sync_date['+variation_index[1]+']"]' ).val();
- } else if ( 'year' == period ) {
- sync_date = $( '[name="variable_subscription_payment_sync_date_day['+variation_index[1]+']"]' ).val();
- }
-
- if ( 0 != sync_date ) {
- is_synced_or_has_trial = true;
-
- // break
- return false;
- }
- }
-
- variations_checked[ variation_index[1] ] = variation_id;
- });
-
- // if we haven't found a variation synced or with a trial at this point check the backend for other product variations
- if ( ( number_of_pages > 1 || 0 == variations.length ) && false == is_synced_or_has_trial ) {
-
- var data = {
- action: 'wcs_product_has_trial_or_is_synced',
- product_id: woocommerce_admin_meta_boxes_variations.post_id,
- variations_checked: variations_checked,
- nonce: WCSubscriptions.oneTimeShippingCheckNonce,
- };
-
- $.ajax({
- url: WCSubscriptions.ajaxUrl,
- data: data,
- type: 'POST',
- success : function( response ) {
- $( '#_subscription_one_time_shipping' ).prop( 'disabled', response.is_synced_or_has_trial );
- // trigger an event now we have determined the one time shipping availability, in case we need to update the backend
- $( '#_subscription_one_time_shipping' ).trigger( 'subscription_one_time_shipping_updated', [ response.is_synced_or_has_trial ] );
- }
- });
- } else {
- // trigger an event now we have determined the one time shipping availability, in case we need to update the backend
- $( '#_subscription_one_time_shipping' ).trigger( 'subscription_one_time_shipping_updated', [ is_synced_or_has_trial ] );
- }
- } else {
- var trial = $( '#general_product_data #_subscription_trial_length' ).val();
-
- if ( 0 != trial ) {
- is_synced_or_has_trial = true;
- }
-
- if ( $( '.subscription_sync' ).length && false == is_synced_or_has_trial ) {
- var period = $( '#_subscription_period' ).val(),
- sync_date = 0;
-
- if ( 'month' == period || 'week' == period ) {
- sync_date = $( '#_subscription_payment_sync_date' ).val();
- } else if ( 'year' == period ) {
- sync_date = $( '#_subscription_payment_sync_date_day' ).val();
- }
-
- if ( 0 != sync_date ) {
- is_synced_or_has_trial = true;
- }
- }
- }
-
- $( '#_subscription_one_time_shipping' ).prop( 'disabled', is_synced_or_has_trial );
- },
- showHideSubscriptionsPanels: function() {
- var tab = $( 'div.panel-wrap' ).find( 'ul.wc-tabs li' ).eq( 0 ).find( 'a' );
- var panel = tab.attr( 'href' );
- var visible = $( panel ).children( '.options_group' ).filter( function() {
- return 'none' != $( this ).css( 'display' );
- });
- if ( 0 != visible.length ) {
- tab.click().parent().show();
- }
- },
- maybeDisableRemoveLinks: function() {
- $( '#variable_product_options .woocommerce_variation' ).each( function() {
- var $removeLink = $( this ).find( '.remove_variation' );
- var can_remove_variation = ( '1' === $( this ).find( 'input.wcs-can-remove-variation').val() );
- var $msg = $( this ).find( '.wcs-can-not-remove-variation-msg' );
-
- if ( ! can_remove_variation ) {
- $msg.text( $removeLink.text() );
- $removeLink.replaceWith( $msg );
- }
- } );
- },
- });
-
- $('.options_group.pricing ._sale_price_field .description').prepend(' ');
-
- // Move the subscription pricing section to the same location as the normal pricing section
- $('.options_group.subscription_pricing').not('.variable_subscription_pricing .options_group.subscription_pricing').insertBefore($('.options_group.pricing:first'));
- $('.show_if_subscription.clear').insertAfter($('.options_group.subscription_pricing'));
-
- // Move the subscription variation pricing section to a better location in the DOM on load
- if($('#variable_product_options .variable_subscription_pricing').length > 0) {
- $.moveSubscriptionVariationFields();
- }
- // When a variation is added
- $('#woocommerce-product-data').on('woocommerce_variations_added woocommerce_variations_loaded',function(){
- $.moveSubscriptionVariationFields();
- $.showHideVariableSubscriptionMeta();
- $.showHideSyncOptions();
- $.setSubscriptionLengths();
- });
-
- if($('.options_group.pricing').length > 0) {
- $.setSalePeriod();
- $.showHideSubscriptionMeta();
- $.showHideVariableSubscriptionMeta();
- $.setSubscriptionLengths();
- $.setTrialPeriods();
- $.showHideSyncOptions();
- $.disableEnableOneTimeShipping();
- $.showHideSubscriptionsPanels();
- }
-
- // Update subscription ranges when subscription period or interval is changed
- $('#woocommerce-product-data').on('change','[name^="_subscription_period"], [name^="_subscription_period_interval"], [name^="variable_subscription_period"], [name^="variable_subscription_period_interval"]',function(){
- $.setSubscriptionLengths();
- $.showHideSyncOptions();
- $.setSyncOptions( $(this) );
- $.setSalePeriod();
- $.disableEnableOneTimeShipping();
- });
-
- $('#woocommerce-product-data').on('propertychange keyup input paste change','[name^="_subscription_trial_length"], [name^="variable_subscription_trial_length"]',function(){
- $.setTrialPeriods();
- });
-
- // Handles changes to sync date select/input for yearly subscription products.
- $('#woocommerce-product-data').on('change', '[name^="_subscription_payment_sync_date_day"], [name^="variable_subscription_payment_sync_date_day"]', function() {
- if ( 0 == $(this).val() ) {
- $(this).siblings('[name^="_subscription_payment_sync_date_month"], [name^="variable_subscription_payment_sync_date_month"]').val(0);
- $(this).prop('disabled', true);
- }
- }).on('change', '[name^="_subscription_payment_sync_date_month"], [name^="variable_subscription_payment_sync_date_month"]', function() {
- var $syncDayOfMonthInput = $(this).siblings('[name^="_subscription_payment_sync_date_day"], [name^="variable_subscription_payment_sync_date_day"]');
-
- if ( 0 < $(this).val() ) {
- $syncDayOfMonthInput.val(1).attr({step: "1", min: "1", max: $.daysInMonth($(this).val())}).prop('disabled', false);
- } else {
- $syncDayOfMonthInput.val(0).trigger('change');
- }
- });
-
- $('body').bind('woocommerce-product-type-change',function(){
- $.showHideSubscriptionMeta();
- $.showHideVariableSubscriptionMeta();
- $.showHideSyncOptions();
- $.showHideSubscriptionsPanels();
- });
-
- $('input#_downloadable, input#_virtual').change(function(){
- $.showHideSubscriptionMeta();
- $.showHideVariableSubscriptionMeta();
- });
-
- // Make sure the "Used for variations" checkbox is visible when adding attributes to a variable subscription
- $('body').on('woocommerce_added_attribute', function(){
- $.showHideVariableSubscriptionMeta();
- });
-
- if($.getParameterByName('select_subscription')=='true'){
- $('select#product-type option[value="'+WCSubscriptions.productType+'"]').attr('selected', 'selected');
- $('select#product-type').select().change();
- }
-
- // Before saving a subscription product, validate the trial period
- $('#post').submit(function(e){
- if ( WCSubscriptions.subscriptionLengths !== undefined ){
- var trialLength = $('#_subscription_trial_length').val(),
- selectedTrialPeriod = $('#_subscription_trial_period').val();
-
- if ( parseInt(trialLength) >= WCSubscriptions.subscriptionLengths[selectedTrialPeriod].length ) {
- alert(WCSubscriptions.trialTooLongMessages[selectedTrialPeriod]);
- $('#ajax-loading').hide();
- $('#publish').removeClass('button-primary-disabled');
- e.preventDefault();
- }
- }
- });
-
- // Notify store manager that deleting an order via the Orders screen also deletes subscriptions associated with the orders
- $('#posts-filter').submit(function(){
- if($('[name="post_type"]').val()=='shop_order'&&($('[name="action"]').val()=='trash'||$('[name="action2"]').val()=='trash')){
- var containsSubscription = false;
- $('[name="post[]"]:checked').each(function(){
- if(true===$('.contains_subscription',$('#post-'+$(this).val())).data('contains_subscription')){
- containsSubscription = true;
- }
- return (false === containsSubscription);
- });
- if(containsSubscription){
- return confirm(WCSubscriptions.bulkTrashWarning);
- }
- }
- });
-
- $('.order_actions .submitdelete').click(function(){
- if($('[name="contains_subscription"]').val()=='true'){
- return confirm(WCSubscriptions.trashWarning);
- }
- });
-
- $( '#variable_product_options' ).on( 'click', '.delete.wcs-can-not-remove-variation-msg', function( e ) {
- e.preventDefault();
- e.stopPropagation();
- } );
-
- // Notify the store manager that trashing an order via the admin orders table row action also deletes the associated subscription if it exists
- $( '.row-actions .submitdelete' ).click( function() {
- var order = $( this ).closest( '.type-shop_order' ).attr( 'id' );
-
- if ( true === $( '.contains_subscription', $( '#' + order ) ).data( 'contains_subscription' ) ) {
- return confirm( WCSubscriptions.trashWarning );
- }
- });
-
- // Editing a variable product
- $('#variable_product_options').on('change','[name^="variable_regular_price"]',function(){
- var matches = $(this).attr('name').match(/\[(.*?)\]/);
-
- if (matches) {
- var loopIndex = matches[1];
- $('[name="variable_subscription_price['+loopIndex+']"]').val($(this).val());
- }
- });
-
- // Editing a variable product
- $('#variable_product_options').on('change','[name^="variable_subscription_price"]',function(){
- var matches = $(this).attr('name').match(/\[(.*?)\]/);
-
- if (matches) {
- var loopIndex = matches[1];
- $('[name="variable_regular_price['+loopIndex+']"]').val($(this).val());
- }
- });
-
- // Update hidden regular price when subscription price is update on simple products
- $('#general_product_data').on('change', '[name^="_subscription_price"]', function() {
- $('[name="_regular_price"]').val($(this).val());
- });
-
- // Notify store manager that deleting an user via the Users screen also removed them from any subscriptions.
- $('.users-php .submitdelete').on('click',function(){
- return confirm(WCSubscriptions.deleteUserWarning);
- });
-
- // WC 2.4+ variation bulk edit handling
- $('select.variation_actions').on('variable_subscription_sign_up_fee_ajax_data variable_subscription_period_interval_ajax_data variable_subscription_period_ajax_data variable_subscription_trial_period_ajax_data variable_subscription_trial_length_ajax_data variable_subscription_length_ajax_data', function(event, data) {
- bulk_action = event.type.replace(/_ajax_data/g,'');
- value = $.getVariationBulkEditValue( bulk_action );
-
- if ( 'variable_subscription_trial_length' == bulk_action ) {
- // After variations have their trial length bulk updated in the backend, flag the One Time Shipping field as needing to be updated
- $( '#_subscription_one_time_shipping' ).addClass( 'wcs_ots_needs_update' );
- }
-
- if ( value != null ) {
- data.value = value;
- }
- return data;
- });
-
- var $allowSwitching = $( document.getElementById( 'woocommerce_subscriptions_allow_switching' ) ),
- $syncRenewals = $( document.getElementById( 'woocommerce_subscriptions_sync_payments' ) );
-
- // We're on the Subscriptions settings page
- if ( $allowSwitching.length > 0 ) {
- var allowSwitchingEnabled = $allowSwitching.find( 'input:checked' ).length,
- $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 ( 0 === allowSwitchingEnabled ) {
- $switchSettingsRows.hide();
- }
-
- $allowSwitching.find( 'input' ).on( 'change', function() {
-
- var isEnabled = $allowSwitching.find( 'input:checked' ).length;
-
- if ( 0 === isEnabled ) {
- $switchSettingsRows.fadeOut();
- } else if ( 0 === allowSwitchingEnabled ) { // switching was previously disabled, so settings will be hidden
- $switchSettingsRows.fadeIn();
- }
- allowSwitchingEnabled = isEnabled;
- } );
-
- // Show/hide suspension extension setting
- $( '#woocommerce_subscriptions_max_customer_suspensions' ).on( 'change', function() {
- if ( $( this ).val() > 0 ) {
- $suspensionExtensionRow.show();
- } else {
- $suspensionExtensionRow.hide();
- }
- } ).change();
-
- // No animation when initially hiding prorated rows.
- if ( ! $syncRenewals.is( ':checked' ) ) {
- $syncRows.hide();
- } else if ( 'recurring' !== $prorateFirstRenewal.val() ) {
- $daysNoFeeRow.hide();
- }
-
- // Animate showing and hiding the synchronization rows.
- $syncRenewals.on( 'change', function(){
- if ( $( this ).is( ':checked' ) ) {
- $syncRows.not( $daysNoFeeRow ).fadeIn();
- $prorateFirstRenewal.change();
- } else {
- $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
- $( 'body' ).on( 'woocommerce-display-product-type-alert', function(e, select_val) {
- if (select_val=='variable-subscription') {
- return false;
- }
- });
-
- $('.wcs_payment_method_selector').on('change', function() {
-
- var payment_method = $(this).val();
-
- $('.wcs_payment_method_meta_fields').hide();
- $('#wcs_' + payment_method + '_fields').show();
- });
-
- // After variations have been saved/updated in the backend, flag the One Time Shipping field as needing to be updated
- $( '#woocommerce-product-data' ).on( 'woocommerce_variations_saved', function() {
- $( '#_subscription_one_time_shipping' ).addClass( 'wcs_ots_needs_update' );
- });
-
- // After variations have been loaded and if the One Time Shipping field needs updating, check if One Time Shipping is still available
- $( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', function() {
- if ( $( '.wcs_ots_needs_update' ).length ) {
- $.disableEnableOneTimeShipping();
- }
- });
-
- // After variations have been loaded, check which ones are tied to subscriptions to prevent them from being deleted.
- $( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', function() {
- $.maybeDisableRemoveLinks();
- } );
-
- // Triggered by $.disableEnableOneTimeShipping() after One Time shipping has been enabled or disabled for variations.
- // If the One Time Shipping field needs updating, send the ajax request to update the product setting in the backend
- $( '#_subscription_one_time_shipping' ).on( 'subscription_one_time_shipping_updated', function( event, is_synced_or_has_trial ) {
-
- if ( $( '.wcs_ots_needs_update' ).length ) {
- var data = {
- action: 'wcs_update_one_time_shipping',
- product_id: woocommerce_admin_meta_boxes_variations.post_id,
- one_time_shipping_enabled: ! is_synced_or_has_trial,
- one_time_shipping_selected: $( '#_subscription_one_time_shipping' ).prop( 'checked' ),
- nonce: WCSubscriptions.oneTimeShippingCheckNonce,
- };
-
- $.ajax({
- url: WCSubscriptions.ajaxUrl,
- data: data,
- type: 'POST',
- success : function( response ) {
- // remove the flag requiring the one time shipping field to be updated
- $( '#_subscription_one_time_shipping' ).removeClass( 'wcs_ots_needs_update' );
- $( '#_subscription_one_time_shipping' ).prop( 'checked', response.one_time_shipping == 'yes' ? true : false );
- }
- });
- }
- });
-
- $( '#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();
-
- /*
- * Prevents changing of the product type for subscription products in use by a subscription.
- */
- var wcs_prevent_product_type_change = {
- init: function() {
- if ( 'yes' !== WCSubscriptions.productHasSubscriptions ) {
- return;
- }
-
- var $select = $( 'select#product-type' );
- var $options = $select.find( 'option' );
- var $selection = $options.filter( 'option:selected' );
-
- if ( 'subscription' !== $selection.val() && 'variable-subscription' !== $selection.val() ) {
- return;
- }
-
- $options.not( $selection ).prop( 'disabled', true );
- $select.addClass( 'tips' ).attr( 'data-tip', WCSubscriptions.productTypeWarning );
- },
- };
- wcs_prevent_product_type_change.init();
-
- /*
- * Handles enabling and disabling PayPal Standard for Subscriptions.
- */
- var wcs_paypal_standard_settings = {
-
- init: function() {
- if ( 0 === $( '#woocommerce_paypal_enabled' ).length ) {
- return;
- }
-
- $( '#woocommerce_paypal_enabled' ).on( 'change', this.paypal_enabled_change );
- $( '#woocommerce_paypal_enabled_for_subscriptions' ).on( 'change', this.paypal_for_subscriptions_enabled );
- this.paypal_enabled_change();
- },
-
- /**
- * Show and hide the enable PayPal for Subscriptions checkbox when PayPal is enabled or disabled.
- */
- paypal_enabled_change: function() {
- var $enabled_for_subscriptions_element = $( '#woocommerce_paypal_enabled_for_subscriptions' ).closest( 'tr' );
-
- if ( $( '#woocommerce_paypal_enabled' ).is( ':checked' ) ) {
- $enabled_for_subscriptions_element.show();
- } else {
- $enabled_for_subscriptions_element.hide();
- }
- },
-
- /**
- * Display a confirm dialog when PayPal for Subscriptions is enabled (checked).
- */
- paypal_for_subscriptions_enabled: function() {
- if ( $( this ).is( ':checked' ) && ! confirm( WCSubscriptions.enablePayPalWarning ) ) {
- $( this ).removeAttr( 'checked' );
- }
- }
- };
- wcs_paypal_standard_settings.init();
-
-});
diff --git a/assets/js/admin/meta-boxes-subscription.js b/assets/js/admin/meta-boxes-subscription.js
deleted file mode 100644
index 4e9d919..0000000
--- a/assets/js/admin/meta-boxes-subscription.js
+++ /dev/null
@@ -1,239 +0,0 @@
-jQuery(document).ready(function($){
- var timezone = jstz.determine();
-
- // Display the timezone for date changes
- $( '#wcs-timezone' ).text( timezone.name() );
-
- // Display times in client's timezone (based on UTC)
- $( '.woocommerce-subscriptions.date-picker' ).each(function(){
- var $date_input = $(this),
- date_type = $date_input.attr( 'id' ),
- $hour_input = $( '#'+date_type+'_hour' ),
- $minute_input = $( '#'+date_type+'_minute' ),
- time = $('#'+date_type+'_timestamp_utc').val(),
- date = moment.unix(time);
-
- if ( time > 0 ) {
- date.local();
- $date_input.val( date.year() + '-' + ( zeroise( date.months() + 1 ) ) + '-' + ( date.format( 'DD' ) ) );
- $hour_input.val( date.format( 'HH' ) );
- $minute_input.val( date.format( 'mm' ) );
- }
- });
-
- // Make sure start date picker is in the past
- $( '.woocommerce-subscriptions.date-picker#start' ).datepicker( 'option','maxDate',moment().toDate());
-
- // Make sure other date pickers are in the future
- $( '.woocommerce-subscriptions.date-picker:not(#start)' ).datepicker( 'option','minDate',moment().add(1,'hours').toDate());
-
- // Validate date when hour/minute inputs change
- $( '[name$="_hour"], [name$="_minute"]' ).on( 'change', function() {
- $( '#' + $(this).attr( 'name' ).replace( '_hour', '' ).replace( '_minute', '' ) ).change();
- });
-
- // Validate entire date
- $( '.woocommerce-subscriptions.date-picker' ).on( 'change',function(){
-
- // The date was deleted, clear hour/minute inputs values and set the UTC timestamp to 0
- if( '' == $(this).val() ) {
- $( '#' + $(this).attr( 'id' ) + '_hour' ).val('');
- $( '#' + $(this).attr( 'id' ) + '_minute' ).val('');
- $( '#' + $(this).attr( 'id' ) + '_timestamp_utc' ).val(0);
- return;
- }
-
- var time_now = moment(),
- one_hour_from_now = moment().add(1,'hours' ),
- $date_input = $(this),
- date_type = $date_input.attr( 'id' ),
- date_pieces = $date_input.val().split( '-' ),
- $hour_input = $( '#'+date_type+'_hour' ),
- $minute_input = $( '#'+date_type+'_minute' ),
- chosen_hour = (0 == $hour_input.val().length) ? one_hour_from_now.format( 'HH' ) : $hour_input.val(),
- chosen_minute = (0 == $minute_input.val().length) ? one_hour_from_now.format( 'mm' ) : $minute_input.val(),
- chosen_date = moment({
- years: date_pieces[0],
- months: (date_pieces[1] - 1),
- date: (date_pieces[2]),
- hours: chosen_hour,
- minutes: chosen_minute,
- seconds: one_hour_from_now.format( 'ss' )
- });
-
- // Make sure start date is before now.
- if ( 'start' == date_type ) {
-
- if ( false === chosen_date.isBefore( time_now ) ) {
- alert( wcs_admin_meta_boxes.i18n_start_date_notice );
- $date_input.val( time_now.year() + '-' + ( zeroise( time_now.months() + 1 ) ) + '-' + ( time_now.format( 'DD' ) ) );
- $hour_input.val( time_now.format( 'HH' ) );
- $minute_input.val( time_now.format( 'mm' ) );
- }
-
- }
-
- // Make sure trial end and next payment are after start date
- if ( ( 'trial_end' == date_type || 'next_payment' == date_type ) && '' != $( '#start_timestamp_utc' ).val() ) {
- var change_date = false,
- start = moment.unix( $('#start_timestamp_utc').val() );
-
- // Make sure trial end is after start date
- if ( 'trial_end' == date_type && chosen_date.isBefore( start, 'minute' ) ) {
-
- if ( 'trial_end' == date_type ) {
- alert( wcs_admin_meta_boxes.i18n_trial_end_start_notice );
- } else if ( 'next_payment' == date_type ) {
- alert( wcs_admin_meta_boxes.i18n_next_payment_start_notice );
- }
-
- // Change the date
- $date_input.val( start.year() + '-' + ( zeroise( start.months() + 1 ) ) + '-' + ( start.format( 'DD' ) ) );
- $hour_input.val( start.format( 'HH' ) );
- $minute_input.val( start.format( 'mm' ) );
- }
- }
-
- // Make sure next payment is after trial end
- if ( 'next_payment' == date_type && '' != $( '#trial_end_timestamp_utc' ).val() ) {
- var trial_end = moment.unix( $('#trial_end_timestamp_utc').val() );
-
- if ( chosen_date.isBefore( trial_end, 'minute' ) ) {
- alert( wcs_admin_meta_boxes.i18n_next_payment_trial_notice );
- $date_input.val( trial_end.year() + '-' + ( zeroise( trial_end.months() + 1 ) ) + '-' + ( trial_end.format( 'DD' ) ) );
- $hour_input.val( trial_end.format( 'HH' ) );
- $minute_input.val( trial_end.format( 'mm' ) );
- }
- }
-
- // Make sure trial end is before next payment and expiration is after next payment date
- else if ( ( 'trial_end' == date_type || 'end' == date_type ) && '' != $( '#next_payment' ).val() ) {
- var change_date = false,
- next_payment = moment.unix( $('#next_payment_timestamp_utc').val() );
-
- // Make sure trial end is before or equal to next payment
- if ( 'trial_end' == date_type && next_payment.isBefore( chosen_date, 'minute' ) ) {
- alert( wcs_admin_meta_boxes.i18n_trial_end_next_notice );
- change_date = true;
- }
- // Make sure end date is after next payment date
- else if ( 'end' == date_type && chosen_date.isBefore( next_payment, 'minute' ) ) {
- alert( wcs_admin_meta_boxes.i18n_end_date_notice );
- change_date = true;
- }
-
- if ( true === change_date ) {
- $date_input.val( next_payment.year() + '-' + ( zeroise( next_payment.months() + 1 ) ) + '-' + ( next_payment.format( 'DD' ) ) );
- $hour_input.val( next_payment.format( 'HH' ) );
- $minute_input.val( next_payment.format( 'mm' ) );
- }
- }
-
- // Make sure the date is more than an hour in the future
- if ( 'trial_end' != date_type && 'start' != date_type && chosen_date.unix() < one_hour_from_now.unix() ) {
-
- alert( wcs_admin_meta_boxes.i18n_past_date_notice );
-
- // Set date to current day
- $date_input.val( one_hour_from_now.year() + '-' + ( zeroise( one_hour_from_now.months() + 1 ) ) + '-' + ( one_hour_from_now.format( 'DD' ) ) );
-
- // Set time if current time is in the past
- if ( chosen_date.hours() < one_hour_from_now.hours() || ( chosen_date.hours() == one_hour_from_now.hours() && chosen_date.minutes() < one_hour_from_now.minutes() ) ) {
- $hour_input.val( one_hour_from_now.format( 'HH' ) );
- $minute_input.val( one_hour_from_now.format( 'mm' ) );
- }
- }
-
- if( 0 == $hour_input.val().length ){
- $hour_input.val(one_hour_from_now.format( 'HH' ));
- }
-
- if( 0 == $minute_input.val().length ){
- $minute_input.val(one_hour_from_now.format( 'mm' ));
- }
-
- // Update the UTC timestamp sent to the server
- date_pieces = $date_input.val().split( '-' );
-
- $('#'+date_type+'_timestamp_utc').val(moment({
- years: date_pieces[0],
- months: (date_pieces[1] - 1),
- date: (date_pieces[2]),
- hours: $hour_input.val(),
- minutes: $minute_input.val(),
- seconds: one_hour_from_now.format( 'ss' )
- }).utc().unix());
-
- $( 'body' ).trigger( 'wcs-updated-date',date_type);
- });
-
- 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()) {
- return confirm(wcs_admin_meta_boxes.process_renewal_action_warning);
- }
- });
-
- $('body.post-type-shop_subscription #post').submit(function(){
- if ( typeof wcs_admin_meta_boxes.change_payment_method_warning != 'undefined' && wcs_admin_meta_boxes.payment_method != $('#_payment_method').val() ) {
- return confirm(wcs_admin_meta_boxes.change_payment_method_warning);
- }
- });
-});
diff --git a/assets/js/admin/reports.js b/assets/js/admin/reports.js
index 418e592..5866702 100644
--- a/assets/js/admin/reports.js
+++ b/assets/js/admin/reports.js
@@ -1,4 +1,4 @@
-jQuery(function($) {
+jQuery( function( $ ) {
$.extend({
wcs_format_money: function(value,decimal_precision) {
diff --git a/assets/js/admin/wcs-meta-boxes-order.js b/assets/js/admin/wcs-meta-boxes-order.js
deleted file mode 100644
index c99b87b..0000000
--- a/assets/js/admin/wcs-meta-boxes-order.js
+++ /dev/null
@@ -1,8 +0,0 @@
-jQuery(document).ready(function($){
-
- $('body.post-type-shop_order #post').submit(function(){
- if('wcs_retry_renewal_payment' == $( "body.post-type-shop_order select[name='wc_order_action']" ).val()) {
- return confirm(wcs_admin_order_meta_boxes.retry_renewal_payment_action_warning);
- }
- });
-});
diff --git a/assets/js/wcs-upgrade.js b/assets/js/wcs-upgrade.js
deleted file mode 100644
index 1ee2b8d..0000000
--- a/assets/js/wcs-upgrade.js
+++ /dev/null
@@ -1,206 +0,0 @@
-jQuery(document).ready(function($){
- var upgrade_start_time = null,
- total_subscriptions = wcs_update_script_data.subscription_count;
-
- $('#update-messages').slideUp();
- $('#upgrade-step-3').slideUp();
-
- $('form#subscriptions-upgrade').on('submit',function(e){
- $('#update-welcome').slideUp(600);
- $('#update-messages').slideDown(600);
- if('true'==wcs_update_script_data.really_old_version){
- wcs_ajax_update_really_old_version();
- } else if('true'==wcs_update_script_data.upgrade_to_1_5){
- wcs_ajax_update_products();
- wcs_ajax_update_hooks();
- } else if('true'==wcs_update_script_data.upgrade_to_2_0){
- wcs_ajax_update_subscriptions();
- } else if('true'==wcs_update_script_data.repair_2_0){
- wcs_ajax_repair_subscriptions();
- } else {
- wcs_ajax_update_complete();
- }
- e.preventDefault();
- });
- function wcs_ajax_update_really_old_version(){
- $.ajax({
- url: wcs_update_script_data.ajax_url,
- type: 'POST',
- data: {
- action: 'wcs_upgrade',
- upgrade_step: 'really_old_version',
- nonce: wcs_update_script_data.upgrade_nonce
- },
- success: function(results) {
- $('#update-messages ol').append($('
').text(results.message));
- wcs_ajax_update_products();
- wcs_ajax_update_hooks();
- },
- error: function(results,status,errorThrown){
- wcs_ajax_update_error();
- }
- });
- }
- function wcs_ajax_update_products(){
- $.ajax({
- url: wcs_update_script_data.ajax_url,
- type: 'POST',
- data: {
- action: 'wcs_upgrade',
- upgrade_step: 'products',
- nonce: wcs_update_script_data.upgrade_nonce
- },
- success: function(results) {
- $('#update-messages ol').append($(' ').text(results.message));
- },
- error: function(results,status,errorThrown){
- wcs_ajax_update_error();
- }
- });
- }
- function wcs_ajax_update_hooks() {
- var start_time = new Date();
- $.ajax({
- url: wcs_update_script_data.ajax_url,
- type: 'POST',
- data: {
- action: 'wcs_upgrade',
- upgrade_step: 'hooks',
- nonce: wcs_update_script_data.upgrade_nonce
- },
- success: function(results) {
- if(results.message){
- var end_time = new Date(),
- execution_time = Math.ceil( ( end_time.getTime() - start_time.getTime() ) / 1000 );
- $('#update-messages ol').append($(' ').text(results.message.replace('{execution_time}',execution_time)));
- }
- if( undefined == typeof(results.upgraded_count) || parseInt(results.upgraded_count) <= ( wcs_update_script_data.hooks_per_request - 1 ) ){
- wcs_ajax_update_subscriptions();
- } else {
- wcs_ajax_update_hooks();
- }
- },
- error: function(results,status,errorThrown){
- wcs_ajax_update_error();
- }
- });
- }
- function wcs_ajax_update_subscriptions() {
- var start_time = new Date();
-
- if ( null === upgrade_start_time ) {
- upgrade_start_time = start_time;
- }
-
- $.ajax({
- url: wcs_update_script_data.ajax_url,
- type: 'POST',
- data: {
- action: 'wcs_upgrade',
- upgrade_step: 'subscriptions',
- nonce: wcs_update_script_data.upgrade_nonce
- },
- success: function(results) {
- if('success'==results.status){
- var end_time = new Date(),
- execution_time = Math.ceil( ( end_time.getTime() - start_time.getTime() ) / 1000 );
-
- $('#update-messages ol').append($(' ').text(results.message.replace('{execution_time}',execution_time)));
-
- wcs_update_script_data.subscription_count -= results.upgraded_count;
-
- if( "undefined" === typeof(results.upgraded_count) || parseInt(wcs_update_script_data.subscription_count) <= 0 ) {
- wcs_ajax_update_complete();
- } else {
- wcs_ajax_update_estimated_time(results.time_message);
- wcs_ajax_update_subscriptions();
- }
- } else {
- wcs_ajax_update_error(results.message);
- }
- },
- error: function(results,status,errorThrown){
- $('Error: ' + results.status + ' ' + errorThrown + ' ').appendTo('#update-error p');
- wcs_ajax_update_error( $('#update-error p').html() );
- }
- });
- }
- function wcs_ajax_repair_subscriptions() {
- var start_time = new Date();
-
- if ( null === upgrade_start_time ) {
- upgrade_start_time = start_time;
- }
-
- $.ajax({
- url: wcs_update_script_data.ajax_url,
- type: 'POST',
- data: {
- action: 'wcs_upgrade',
- upgrade_step: 'subscription_dates_repair',
- nonce: wcs_update_script_data.upgrade_nonce
- },
- success: function(results) {
- if('success'==results.status){
- var end_time = new Date(),
- execution_time = Math.ceil( ( end_time.getTime() - start_time.getTime() ) / 1000 );
-
- $('#update-messages ol').append($(' ').text(results.message.replace('{execution_time}',execution_time)));
-
- wcs_update_script_data.subscription_count -= results.repaired_count;
- wcs_update_script_data.subscription_count -= results.unrepaired_count;
-
- if( parseInt(wcs_update_script_data.subscription_count) <= 0 ) {
- wcs_ajax_update_complete();
- } else {
- wcs_ajax_update_estimated_time(results.time_message);
- wcs_ajax_repair_subscriptions();
- }
- } else {
- wcs_ajax_update_error(results.message);
- }
- },
- error: function(results,status,errorThrown){
- $('Error: ' + results.status + ' ' + errorThrown + ' ').appendTo('#update-error p');
- wcs_ajax_update_error( $('#update-error p').html() );
- }
- });
- }
- function wcs_ajax_update_complete() {
- $('#update-ajax-loader, #estimated_time').slideUp(function(){
- $('#update-complete').slideDown();
- });
- }
- function wcs_ajax_update_error(message) {
- message = message || '';
- if ( message.length > 0 ){
- $('#update-error p').html(message);
- }
- $('#update-ajax-loader, #estimated_time').slideUp(function(){
- $('#update-error').slideDown();
- });
- }
- function wcs_ajax_update_estimated_time(message) {
- var total_updated = total_subscriptions - wcs_update_script_data.subscription_count,
- now = new Date(),
- execution_time,
- time_per_update,
- time_left,
- time_left_minutes,
- time_left_seconds;
-
- execution_time = Math.ceil( ( now.getTime() - upgrade_start_time.getTime() ) / 1000 );
- time_per_update = execution_time / total_updated;
-
- time_left = Math.floor( wcs_update_script_data.subscription_count * time_per_update );
- time_left_minutes = Math.floor( time_left / 60 );
- time_left_seconds = time_left % 60;
-
- $('#estimated_time').html(message.replace( '{time_left}', time_left_minutes + ":" + zeropad(time_left_seconds) ));
- }
- function zeropad(number) {
- var pad_char = 0,
- pad = new Array(3).join(pad_char);
- return (pad + number).slice(-pad.length);
- }
-});
\ No newline at end of file
diff --git a/changelog.txt b/changelog.txt
index 74e2ccc..6f271cb 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,4 +1,207 @@
*** WooCommerce Subscriptions Changelog ***
+2022-10-11 - version 4.6.0
+* Add: Declare incompatibility with WooCommerce High-Performance Order Storage (HPOS).
+* Fix: Move One Time Shipping metabox fields to use the woocommerce_product_options_shipping_product_data hook introduced in WC 6.0.
+* Update: Improve handling of bulk action execution.
+* Dev: Update subscriptions-core to 2.3.0
+
+2022-08-26 - version 4.5.1
+* Fix - Fatal Error caused in rare cases where quantity is zero during renewal, builds upon fix released in 4.4.0.
+
+2022-08-04 - version 4.5.0
+* Dev: Add missing `woocommerce_subscriptions_switch_link_text` and `woocommerce_subscriptions_switch_link_classes` filters for finer control of switch link. PR#4382
+* Fix: Update subscription address when changed with renewals on block checkout.
+
+2022-06-07 - version 4.4.0
+* Fix - Fatal Error caused in rare cases where quantity is zero during renewal.
+
+2022-05-24 - version 4.3.0
+* Dev: Retrieving users subscriptions order has been updated to use the WooCommerce specific APIs in WC_Subscriptions_Order.
+* Dev: Deprecate the WC_Subscriptions_Order::get_meta() function. Use wcs_get_objects_property( $order, $meta_key, "single", $default ) instead.
+* Dev: Update the wcs_get_objects_property() function to prevent calls to get_post_meta() on objects that support calling the get_meta() function.
+* Dev: Replace the get_post_meta() calls in WCS_Post_Meta_Cache_Manager with WC_Order::get_meta().
+* Dev: Replace code using get_post_type( $order_id ) with WC Data Store get_order_type().
+* Dev: Replace all cases of update_post_meta() where an Order ID is passed to use WC_Order::update_meta_data() instead.
+
+2022-04-29 - version 4.2.0
+* Fix: Remove WooThemes helper/updater admin notice/banner. PR#4328
+* Fix: Remove PHP/deprecation notices during the early renewal and switch process when using WooCommerce Blocks 7.2. PR#4341
+* Fix: Display subscription billing details in the Cart Block when purchasing products with subscription plans created using the All Products extension. subscriptions-core#149
+* Update: Switch to global functions to remove deprecation warnings originating from WooCommerce Blocks. subscriptions-core#124
+* Dev: Update subscriptions-core to 1.9.0. PR#4345
+
+2022-03-22 - version 4.1.0
+* Fix: Undefined variable `user_can_suspend` when a customer suspension limit is defined and the max number of suspensions has been reached. PR#4318
+* Fix: Sets up subscriptions integration with the Mini Cart Block and adds new hook to filter compatible blocks. subscriptions-core#103
+* Fix: When using a WooCommerce Blocks powered checkout, fix an issue that led to limited products being removed from the cart when completing a switch or renewal order. subscriptions-core#119
+* Fix: When there is only one Shipping Method available in the recurring shipping package, make sure that this method is treated as selected in the current session and the `woocommerce_after_shipping_rate` action runs. subscriptions-core#115
+* Fix: Don't anonymize new subscriptions related to old subscriptions via a resubscribe relationship. subscriptions-core#121
+* Fix: Content that appears on the My account > Payment methods page should be translatable. subscriptions-core#125
+* Dev: Update subscriptions-core to 1.7.0. PR#4319
+
+2022-02-07 - version 4.0.2
+* Dev: Update subscriptions-core to 1.6.3. PR#4307
+* Fix: Replace uses of is_ajax() with wp_doing_ajax(). wcs#4296 PR#4307
+* Improve handling of session data.
+
+2022-01-19 - version 4.0.1
+* Fix: Prevent fatal error when too few arguments passed to widget_title filter. PR#4302
+* Dev: Update subscriptions-core to 1.6.2. PR#4302
+
+2022-01-19 - version 4.0.0
+* New: Update the minimum required WooCommerce version from 3.9 to 4.4. PR#4282
+* Fix: Unable to remove subscription line items via the REST API. PR#4258
+* Fix: Don't show subscription related product fields when the custom variable type products are created. PR#4215
+* Fix: Add consistent margins to the recurring taxes totals row on the Checkout and Cart block. PR#4273
+* Fix: Fatal error due to order with no created date in order row template. PR#4273
+* Fix: Fatal error on the customer payment page for renewal orders with deleted products. PR#4273
+* Fix: Prevent fatal errors on the admin subscriptions screen when a subscription fails to load. PR#4290
+* Fix: Incorrect message on the subscriptions table when filtering returns no results. PR#4290
+* Fix: Update Cart and Checkout Block hooks to prevent deprecation warnings. PR#4280
+* Tweak: Update tooltip wording when deleting product variation. PR#4273
+* Tweak: Don't show an admin error notice when a store downgrades to a previous minor version of Subscriptions. PR#4273
+* Tweak: Misleading order note on payment method change. PR#4273
+* Dev: Moved subscription core files moved into a new subscriptions-core library (loaded from vendor/woocommerce/subscriptions-core). PR#4121
+* Dev: New `WC_Subscriptions_Plugin` class to be the main Subscriptions plugin handler class. PR#4116
+* Dev: Moved and deprecated 33 functions from class `WC_Subscriptions` to more suitable classes. PR#4114
+* Dev: Moved switching feature related classes into its own directory (`includes/switching/`). PR#4122
+* Dev: Moved payment retry feature related classes into its own directory (`includes/payment-retry/`). PR#4146
+* Dev: Moved early renewal feature related classes into its own directory (`includes/early-renewals/`). PR#4148
+* Dev: Moved the "Accept manual renewals" feature and settings to a new `WCS_Manual_Renewal_Manager` class. PR#4124
+* Dev: Moved the "Customer Suspensions" feature and settings code to a new `WCS_Customer_Suspension_Manager` class. PR#4138
+* Dev: Moved the "Drip Downloadable Content" feature and settings to a new `WCS_Drip_Downloads_Manager` class. PR#4142
+* Dev: Moved the "Allow $0 initial checkout without a payment method" feature and settings to a new `WCS_Zero_Initial_Payment_Checkout_Manager` class. PR#4145
+* Dev: Moved the "Limited payment recurring coupon" feature to a new `WCS_Limited_Recurring_Coupon_Manager` class. PR#4150
+* Dev: Moved the custom subscription product and checkout button text feature to a new `WCS_Call_To_Action_Button_Text_Manager` class. PR#4152
+* Dev: Moved the custom active and inactive subscriber roles feature to a new `WCS_Subscriber_Role_Manager` class. PR#4153
+* Dev: Removed the Action Scheduler library from WC Subscriptions since it has been included in WooCommerce core since version 3.0. PR#4202
+
+2021-10-06 - version 3.1.6
+* Fix: Add back the limited subscription setting for simple subscription products (introduced in v3.1.5). PR#4214
+
+2021-09-28 - version 3.1.5
+* Fix: Update subtracted tax amounts to account for quantity changes. PR#4107
+* Fix: Correctly remove limited coupons (i.e. "Active for x payments") when the coupon code is made up of only numeric characters. PR#4139
+* Fix: Only set subtracted taxes on new items when the rates don't match the base location. PR#4177
+* Fix: Hide variable subscription meta fields on the Edit Product page of custom variable products. PR#4193
+* Fix: Use the shipping fields to get and save the edit subscription shipping field data. PR#4161
+* Fix: Fix TypeError exceptions by checking for WC_Order types inside wcs_get_subscriptions_for_order(). PR#4188
+* Fix: Incorrect subtracted tax calculations when updating the subscription when the store currency uses a comma decimal separator. PR#4182
+* Fix: Hide the shipping address fields on checkout when the cart contains a subscription product and the 'Force shipping to billing address' setting is selected. PR#4172
+* Fix: Get the signup fee for coupon calculation inclusive or excluding tax depending on store settings. PR#4166
+
+2021-07-22 - version 3.1.4
+* Fix: Points and Rewards discounts (including WC Coupons when Points and Rewards is active) being removed from the cart when applied on the checkout page. PR#4158
+* Fix: Subscriptions with one-time shipping having shipping charged on all renewal orders. PR#4156
+* Fix: Rare fatal error caused by missing WC_Query class. PR#4155
+* Fix: Make loading the variation edit product tab more performant on large sites. PR#4144
+* Fix: Add a primary key to the last payment temporary table to improve compatibility with some hosts on larger sites. PR#4151
+* Tweak: Update the wording when a customer edits their subscription address that this applies to "future renewals". PR#4118
+* Dev: Add missing `woocommerce_rest_pre_insert_shop_subscription_object` filter to prepare_object_for_database() within the Subscriptions REST API controller class. PR#4119
+* Dev: Add a `data-payment-method` attribute to the Early Renewal modal button action. PR#4123
+
+2021-06-09 - version 3.1.3
+* Fix: Switch calculations not correctly charging the full sign up fee when the "Prorate Sign up Fee" option is set to "Never (charge the full sign up fee)". PR#4096
+* Fix: Fixes PayPal Reference Transactions integration with Checkout blocks. PR#4105
+* Fix: Set the updated payment token on all pending-payment renewals so that manually retrying a failed payment uses the updated token set on the subscription. PR#4108
+* Dev: Moved the `WC_Subscriptions::enqueue_scripts` and` WC_Subscriptions::equeue_styles` static functions to the new `WC_Subscriptions_Frontend_Scripts` class (deprecated existing functions). PR#4104
+
+2021-05-19 - version 3.1.2
+* Fix: Don't show recurring shipping method selection when the rates and options match the initial cart options. PR#4091
+* Fix: Update the recurring shipping totals on selection and fix invalid recurring shipping method notices. PR#4099
+* Fix: Update the subscription shipping address after on switch. PR#4095
+
+2021-05-12 - version 3.1.1
+* Fix: "Invalid recurring shipping method" error on checkout when attempting to purchase a subscription with one-time shipping. PR#4088
+* Fix: Rework subscription webhook migration script added in 3.1 to clear cached webhook data. PR#4082
+
+2021-05-10 - version 3.1.0
+* New: Add support for WooCommerce Cart and Checkout blocks. PR#3993
+* New: Support v3 subscription endpoints. PR#4001
+* New: Add woocommerce_inbox_variant option. PR#4084
+* New: Update the WC minimum required version to WC 3.7. PR#3914
+* New: Add a new Accounts setting to allow admin to enable registration on checkout of subscription customers. PR#3883
+* New: Display switch, renewal and resubscribe context in the 'Add to cart' and 'Place order' buttons. PR#3624
+* Fix: Fix customer subscription caching errors on multisite installations. PR#4074
+* Fix: Update the `_subtracted_base_location_taxes` when an admin edits the subscription line item subtotal. PR#4068
+* Fix: Migrate existing v3 subscription webhooks to v1 when upgrading to 3.1 to maintain the same payload delivered. PR#4079
+* Fix: Fatal error when processing an initial PayPal Standard payment on a manually created subscription that has no parent order. PR#4033
+* Fix: Only allow reactivation of pending-canceled subscription when end date is in the future. PR#4037
+* Fix: Don't add a free trial period when resubscribing to a synced subscription. PR#4045
+* Fix: Catch exceptions thrown when updating a subscription's payment method. PR#4051
+* Fix: Incorrect sign-up fee discount amount calculated when the customer is outside of all tax zones and prices are entered with tax included. PR#4052
+* Fix: Allow paying for pending parent orders that contain a limited subscription product where the subscription is already active. PR#4061
+* Fix: Show recurring shipping totals/options when a virtual product is the last product added to the cart. PR#4053
+* Fix: Refactor how `_subtracted_base_location_tax` order item meta is stored on subscription items to avoid calculation issues when the quantity is changed. PR#4062
+* Fix: Fixes PHP notices when using the v1/subscriptions/ID/orders REST endpoint on a subscription where one of its related orders was directly deleted from the database. PR#4058
+* Tweak: Always show the delete save card button but now display a notice when trying to delete a card tied to an active subscription. PR#4076
+* Tweak: Update the subscription order note to when the PayPal Standard subscription is suspended and migrated over to PayPal Reference Transactions during a switch request. PR#4057
+* Tweak: Display orders in the related orders admin table sorted by date. PR#3575
+* Dev: Refactor the recurring totals template. PR#3550
+
+2021-04-16 - version 3.0.15
+* Tweak: Improve compatibility with WPML. PR#4034
+* Dev: Introduce filter to allow third-parties gateways to filter whether a token meta was updated. PR#4030
+* Fix: Fixes for endpoint in "My Account".
+
+2021-04-07 - version 3.0.14
+* New: Add support for importing and exporting subscription variations via the WooCommerce > Products > Export/Import tools. PR#3970
+* Fix: Only show one Subscriptions settings menu item on the WC Admin navigation. PR#4054
+* Fix: Prevent PHP notices on the Edit Subscription page caused accessing an undefined index. PR#4056
+* Fix: Existing variations will no longer be deleted when updating a regular variable product to a subscription variable product. PR#3795
+* Fix: Update the `_subtracted_base_location_tax` meta data when a subscription's line item quantity is modified. PR#4039
+* Fix: Next payment date calculations when the start date and last payment date are the same. PR#4017
+* Dev: Update jQuery 3.0 deprecations. PR#4015
+
+2021-02-16 - version 3.0.13
+* Fix: Pass an order status array to get_order_report_data() to prevent possible fatals by 3rd parties. PR#3930
+* Fix: Change logic to allow customers to pay for failed order with limited product. PR#3947
+* Fix: Prevent base length from being saved in the DB when retrieved in 'apportion_length'. PR#3954
+* Fix: Prevent errors when using Product Bundles (which uses WCS_Add_Cart_Item) by introducing a WCS_Add_Cart_Item::is_switch_after_fully_reduced_prepaid_term() function. PR#3957
+* Fix: Introduce an SQL Transactions helper with automatic commit/rollback on shutdown. Prevents strange behaviour when a shutdown occurs during a SQL transaction. PR#3827
+* Fix: [PHP 8.0] Change maybe_retry_payment() arg name to prevent unknown variable name errors. PR#3984
+* Fix: Delete '_switch_totals_calc_base_length' meta incorrectly saved in the database on upgrade. PR#3958
+* Fix: Prevent WC_Order_Item_Coupon::offsetGet errors during renewal. PR#4009
+* Dev: Introduce new hooks to various Switch_Totals_Calculator functions. PR#3872
+
+2021-01-06 - version 3.0.12
+* New: Add an order note when subscriptions are deleted after the customer is deleted. PR#3783
+* New: [WC Admin] Register items in new navigation menu. PR#3868
+* New: [WC Admin] Add the Subscriptions setting to WC Admin's Settings navigation list. PR#3911
+* Tweak: Fix capitalisation of Subscription webhook topic names so they match WooCommerce core. PR#3902
+* Tweak: Refactor `wcs_help_tip()` to enable custom tooltip classes. PR#3871
+* Tweak: Replace remaining uses of new WC_Order() with wc_get_order() to get an order instance. PR#3858
+* Fix: Fix the amount customers are charged after switching after a previous switch which reduced the pre-paid term fully. PR#3805
+* Fix: Calculate a gap payment when switching to a subscription with one length and no payment date to extend. PR#3879
+* Fix: Only require cart payment if there's a subscription with a next payment date. PR#3899
+* Fix: Only display the failed scheduled action warning to admin users who can view subscriptions. PR#3905
+* Fix: Prefix attribute keys correctly before getting switch url. Fixes issues with auto-switch redirects removing pre-exisiting URL params. PR#3913
+* Fix: Prevent reducing stock while saving a subscription on the admin edit subscription screen. PR#3926
+* Fix: Use product object to read the original, unmodified length of a cart item during a switch. PR#3929
+* Dev: Trigger create/update webhooks during Subscription REST API calls. PR#3919
+* Dev: Add filters to enable third-parties to change the new and old payment method titles used in subscription changed payment method notes. PR#3908
+
+2020-11-25 - version 3.0.11
+* Tweak: Improve the missing customer error message displayed for third-party built checkouts when registration is disabled on checkout. PR#3893
+* Fix: Remove the possibility of a negative calculation of prepaid days on subscription downgrades. PR#3881
+* Fix: Fix issues preventing stores using the $0 Initial Checkout feature from being able to checkout. PR#3887
+* Fix: Remove potential fatal error when processing end-of-prepaid term scheduled actions caused by the subscription not existing. PR#3875
+* Fix: Trigger payment complete actions after renewing early via modal. PR#3888
+* Fix: Performance improvements to limited products running slow queries on the shop page. PR#3895
+* Fix: [PHP 8.0] Only pass array values to call_user_func_array calls. PR#3884
+* Fix: [PHP 8.0] Replaces certain uses of method_exists() with is_callable(). PR#3892
+
+2020-11-10 - version 3.0.10
+* Fix: Store shipping line item instance ID separately and copy it to renewal line item meta. PR#3712
+* Fix: Account for the base store tax rates subtracted from line items when paying for renewals manually. PR#3745
+* Fix: Update the persistent cart while paying for renewal orders via the checkout. Fixes division by zero errors while manually renewing. PR#3824
+* Fix: Clear report cache data before regenerating new preset date results preventing infinitely growing report caches. PR#3800
+* Fix: Remove subscription period string transient caching to fix issues after translating. PR#3770
+* Fix: WC 4.7 compatibility. Use filter to change endpoint titles in My Account. PR#3857
+* Fix: When generating product price strings fallback to a default period string if no period is set. PR#3848
+* Fix: Remove uses of jQuery( document ).ready() which was deprecated. PR#3846
+* New: Add option to enable admin to lock in increased parent order line item prices. PR#3816
+* Tweak: Allow admin to set a next payment date in 2 minutes via the edit subscription screen on staging sites. PR#3778
2020-09-29 - version 3.0.9
* Fix: Offset subscription next payment date calculations based on site time. All dates still remain in UTC, but calculations on the 1st and last day of the month will now take into account the site timezone. PR#3708
diff --git a/includes/admin/class-wcs-admin-meta-boxes.php b/includes/admin/class-wcs-admin-meta-boxes.php
deleted file mode 100644
index 3f956f5..0000000
--- a/includes/admin/class-wcs-admin-meta-boxes.php
+++ /dev/null
@@ -1,329 +0,0 @@
-post_type ) {
- remove_action( 'woocommerce_process_shop_order_meta', 'WC_Meta_Box_Order_Data::save', 40 );
- }
- }
-
- /**
- * Print admin styles/scripts
- */
- public function enqueue_styles_scripts() {
- global $post;
-
- // Get admin screen id
- $screen = get_current_screen();
- $screen_id = isset( $screen->id ) ? $screen->id : '';
-
- if ( 'shop_subscription' == $screen_id ) {
-
- wp_register_script( 'jstz', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/jstz.min.js' );
-
- wp_register_script( 'momentjs', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/moment.min.js' );
-
- wp_enqueue_script( 'wcs-admin-meta-boxes-subscription', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/meta-boxes-subscription.js', array( 'wc-admin-meta-boxes', 'jstz', 'momentjs' ), WC_VERSION );
-
- wp_localize_script( 'wcs-admin-meta-boxes-subscription', 'wcs_admin_meta_boxes', apply_filters( 'woocommerce_subscriptions_admin_meta_boxes_script_parameters', array(
- 'i18n_start_date_notice' => __( 'Please enter a start date in the past.', 'woocommerce-subscriptions' ),
- 'i18n_past_date_notice' => __( 'Please enter a date at least one hour into the future.', 'woocommerce-subscriptions' ),
- 'i18n_next_payment_start_notice' => __( 'Please enter a date after the trial end.', 'woocommerce-subscriptions' ),
- 'i18n_next_payment_trial_notice' => __( 'Please enter a date after the start date.', 'woocommerce-subscriptions' ),
- 'i18n_trial_end_start_notice' => __( 'Please enter a date after the start date.', 'woocommerce-subscriptions' ),
- 'i18n_trial_end_next_notice' => __( 'Please enter a date before the next payment.', 'woocommerce-subscriptions' ),
- 'i18n_end_date_notice' => __( 'Please enter a date after the next payment.', 'woocommerce-subscriptions' ),
- '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 ) {
-
- wp_enqueue_script( 'wcs-admin-meta-boxes-order', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/wcs-meta-boxes-order.js' );
-
- wp_localize_script(
- 'wcs-admin-meta-boxes-order',
- 'wcs_admin_order_meta_boxes',
- array(
- 'retry_renewal_payment_action_warning' => __( "Are you sure you want to retry payment for this renewal order?\n\nThis will attempt to charge the customer and send renewal order emails (if emails are enabled).", 'woocommerce-subscriptions' ),
- )
- );
- }
-
- // 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
- );
- }
- }
-
- /**
- * Adds actions to the admin edit subscriptions page, if the subscription hasn't ended and the payment method supports them.
- *
- * @param array $actions An array of available actions
- * @return array An array of updated actions
- * @since 2.0
- */
- public static function add_subscription_actions( $actions ) {
- global $theorder;
-
- if ( wcs_is_subscription( $theorder ) ) {
- if ( ! WC_Subscriptions::is_woocommerce_pre( '3.2' ) ) {
- unset( $actions['send_order_details'], $actions['send_order_details_admin'] );
- }
-
- if ( ! $theorder->has_status( wcs_get_subscription_ended_statuses() ) ) {
- if ( $theorder->payment_method_supports( 'subscription_date_changes' ) && $theorder->has_status( 'active' ) ) {
- $actions['wcs_process_renewal'] = esc_html__( 'Process renewal', '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' );
- }
-
- return $actions;
- }
-
- /**
- * Handles the action request to process a renewal order.
- *
- * @param array $subscription
- * @since 2.0
- */
- public static function process_renewal_action_request( $subscription ) {
- $subscription->add_order_note( __( 'Process renewal order action requested by admin.', 'woocommerce-subscriptions' ), false, true );
- do_action( 'woocommerce_scheduled_subscription_payment', $subscription->get_id() );
- }
-
- /**
- * Handles the action request to create a pending renewal order.
- *
- * @param array $subscription
- * @since 2.0
- */
- public static function create_pending_renewal_action_request( $subscription ) {
- $subscription->add_order_note( __( 'Create pending renewal order requested by admin action.', 'woocommerce-subscriptions' ), false, true );
- $subscription->update_status( 'on-hold' );
-
- $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();
- }
- }
- }
-
- /**
- * 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();
- }
- }
-
- wc_maybe_reduce_stock_levels( $parent_order );
- $subscription->add_order_note( __( 'Create pending parent order requested by admin action.', 'woocommerce-subscriptions' ), false, true );
- }
-
- /**
- * Removes order related emails from the available actions.
- *
- * @param array $available_emails
- * @since 2.0
- */
- public static function remove_order_email_actions( $email_actions ) {
- global $theorder;
-
- if ( wcs_is_subscription( $theorder ) ) {
- $email_actions = array();
- }
-
- return $email_actions;
- }
-
- /**
- * Process the action request to retry renewal payment for failed renewal orders.
- *
- * @param WC_Order $order
- * @since 2.1
- */
- public static function process_retry_renewal_payment_action_request( $order ) {
-
- if ( self::can_renewal_order_be_retried( $order ) ) {
- // init payment gateways
- WC()->payment_gateways();
-
- $order->add_order_note( __( 'Retry renewal payment action requested by admin.', 'woocommerce-subscriptions' ), false, true );
- do_action( 'woocommerce_scheduled_subscription_payment_' . wcs_get_objects_property( $order, 'payment_method' ), $order->get_total(), $order );
- }
- }
-
- /**
- * Determines if a renewal order payment can be retried. A renewal order payment can only be retried when:
- * - Order is a renewal order
- * - Order status is failed
- * - Order payment method isn't empty
- * - Order total > 0
- * - Subscription/s aren't manual
- * - Subscription payment method supports date changes
- * - Order payment method has_action('woocommerce_scheduled_subscription_payment_..')
- *
- * @param WC_Order $order
- * @return bool
- * @since 2.1
- */
- private static function can_renewal_order_be_retried( $order ) {
-
- $can_be_retried = false;
-
- if ( wcs_order_contains_renewal( $order ) && $order->needs_payment() && '' != wcs_get_objects_property( $order, 'payment_method' ) ) {
- $supports_date_changes = false;
- $order_payment_gateway = wc_get_payment_gateway_by_order( $order );
- $order_payment_gateway_supports = ( isset( $order_payment_gateway->id ) ) ? has_action( 'woocommerce_scheduled_subscription_payment_' . $order_payment_gateway->id ) : false;
-
- foreach ( wcs_get_subscriptions_for_renewal_order( $order ) as $subscription ) {
- $supports_date_changes = $subscription->payment_method_supports( 'subscription_date_changes' );
- $is_automatic = ! $subscription->is_manual();
- break;
- }
-
- $can_be_retried = $order_payment_gateway_supports && $supports_date_changes && $is_automatic;
- }
-
- return $can_be_retried;
- }
-
- /**
- * Disables stock managment while adding items to a subscription via the edit subscription screen.
- *
- * @since 3.0.6
- *
- * @param string $manage_stock The default manage stock setting.
- * @return string Whether the stock should be managed.
- */
- public static function override_stock_management( $manage_stock ) {
-
- // Override stock management while adding line items to a subscription via AJAX.
- if ( isset( $_POST['order_id'] ) && wp_verify_nonce( $_REQUEST['security'], 'order-item' ) && doing_action( 'wp_ajax_woocommerce_add_order_item' ) && wcs_is_subscription( absint( wp_unslash( $_POST['order_id'] ) ) ) ) {
- $manage_stock = 'no';
- }
-
- return $manage_stock;
- }
-}
diff --git a/includes/admin/class-wcs-admin-reports.php b/includes/admin/class-wcs-admin-reports.php
index 0d8cf13..7abe099 100644
--- a/includes/admin/class-wcs-admin-reports.php
+++ b/includes/admin/class-wcs-admin-reports.php
@@ -96,17 +96,15 @@ class WCS_Admin_Reports {
* @since 1.5
*/
public static function reports_scripts() {
- global $wp_query, $post;
-
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
-
- $screen = get_current_screen();
- $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce-subscriptions' ) );
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
+ $screen = get_current_screen();
+ $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce-subscriptions' ) );
+ $version = WC_Subscriptions_Plugin::instance()->get_plugin_version();
// Reports Subscriptions Pages
if ( in_array( $screen->id, apply_filters( 'woocommerce_reports_screen_ids', array( $wc_screen_id . '_page_wc-reports', 'toplevel_page_wc-reports', 'dashboard' ) ) ) && isset( $_GET['tab'] ) && 'subscriptions' == $_GET['tab'] ) {
- wp_enqueue_script( 'wcs-reports', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/reports.js', array( 'jquery', 'jquery-ui-datepicker', 'wc-reports', 'accounting' ), WC_Subscriptions::$version );
+ wp_enqueue_script( 'wcs-reports', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/js/admin/reports.js' ), array( 'jquery', 'jquery-ui-datepicker', 'wc-reports', 'accounting' ), $version );
// Add currency localisation params for axis label
wp_localize_script( 'wcs-reports', 'wcs_reports', array(
@@ -117,12 +115,12 @@ class WCS_Admin_Reports {
'currency_format' => esc_js( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS
) );
- wp_enqueue_script( 'flot-order', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/jquery.flot.orderBars' . $suffix . '.js', array( 'jquery', 'flot' ), WC_Subscriptions::$version );
- wp_enqueue_script( 'flot-axis-labels', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/jquery.flot.axislabels' . $suffix . '.js', array( 'jquery', 'flot' ), WC_Subscriptions::$version );
+ wp_enqueue_script( 'flot-order', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/js/admin/jquery.flot.orderBars' ) . $suffix . '.js', array( 'jquery', 'flot' ), $version );
+ wp_enqueue_script( 'flot-axis-labels', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/js/admin/jquery.flot.axislabels' ) . $suffix . '.js', array( 'jquery', 'flot' ), $version );
// Add tracks script if tracking is enabled.
if ( 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ) ) {
- wp_enqueue_script( 'wcs-tracks', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/js/admin/tracks.js', array( 'jquery' ), WC_Subscriptions::$version, true );
+ wp_enqueue_script( 'wcs-tracks', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/js/admin/tracks.js' ), array( 'jquery' ), $version, true );
}
}
}
@@ -174,7 +172,7 @@ class WCS_Admin_Reports {
$properties = array(
'orders_count' => array_sum( (array) wp_count_posts( 'shop_order' ) ),
'subscriptions_count' => array_sum( (array) wp_count_posts( 'shop_subscription' ) ),
- 'subscriptions_version' => WC_Subscriptions::$version,
+ 'subscriptions_version' => WC_Subscriptions_Plugin::instance()->get_plugin_version(),
);
if ( in_array( $name, array( 'subscription-events-by-date', 'upcoming-recurring-revenue', 'subscription-payment-retry' ), true ) ) {
diff --git a/includes/admin/reports/class-wcs-report-cache-manager.php b/includes/admin/reports/class-wcs-report-cache-manager.php
index 7a98aaf..79b763f 100644
--- a/includes/admin/reports/class-wcs-report-cache-manager.php
+++ b/includes/admin/reports/class-wcs-report-cache-manager.php
@@ -80,7 +80,7 @@ class WCS_Report_Cache_Manager {
public function __construct() {
// Use the old hooks
- if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( wcs_is_woocommerce_pre( '3.0' ) ) {
$hooks = array(
'woocommerce_order_add_product' => 'woocommerce_new_order_item',
@@ -218,12 +218,11 @@ class WCS_Report_Cache_Manager {
// Some report classes extend WP_List_Table which has a constructor using methods not available on WP-Cron (and unable to be loaded with a __doing_it_wrong() notice), so they have a static get_data() method and do not need to be instantiated
if ( $reflector->isStatic() ) {
-
+ call_user_func( array( $report_class, 'clear_cache' ) );
call_user_func( array( $report_class, 'get_data' ), array( 'no_cache' => true ) );
-
} else {
-
$report = new $report_class();
+ $report->clear_cache();
// Classes with a non-static get_data() method can be displayed for different time series, so we need to update the cache for each of those ranges
foreach ( array( 'year', 'last_month', 'month', '7day' ) as $range ) {
diff --git a/includes/admin/reports/class-wcs-report-dashboard.php b/includes/admin/reports/class-wcs-report-dashboard.php
index e2e5e5f..01866aa 100644
--- a/includes/admin/reports/class-wcs-report-dashboard.php
+++ b/includes/admin/reports/class-wcs-report-dashboard.php
@@ -39,10 +39,10 @@ class WCS_Report_Dashboard {
'no_cache' => false,
);
- $args = apply_filters( 'wcs_reports_subscription_dashboard_args', $args );
- $args = wp_parse_args( $args, $default_args );
-
- $offset = get_option( 'gmt_offset' );
+ $args = apply_filters( 'wcs_reports_subscription_dashboard_args', $args );
+ $args = wp_parse_args( $args, $default_args );
+ $offset = get_option( 'gmt_offset' );
+ $update_cache = false;
// Use this once it is merged - wcs_get_gmt_offset_string();
// Convert from Decimal format(eg. 11.5) to a suitable format(eg. +11:30) for CONVERT_TZ() of SQL query.
@@ -72,7 +72,7 @@ class WCS_Report_Dashboard {
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_signup_query', $query ) );
- set_transient( strtolower( __CLASS__ ), $cached_results, WEEK_IN_SECONDS );
+ $update_cache = true;
}
$report_data->signup_count = $cached_results[ $query_hash ];
@@ -103,7 +103,7 @@ class WCS_Report_Dashboard {
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_signup_revenue_query', $query ) );
- set_transient( strtolower( __CLASS__ ), $cached_results, HOUR_IN_SECONDS );
+ $update_cache = true;
}
$report_data->signup_revenue = $cached_results[ $query_hash ];
@@ -131,7 +131,7 @@ class WCS_Report_Dashboard {
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_renewal_query', $query ) );
- set_transient( strtolower( __CLASS__ ), $cached_results, HOUR_IN_SECONDS );
+ $update_cache = true;
}
$report_data->renewal_count = $cached_results[ $query_hash ];
@@ -165,7 +165,7 @@ class WCS_Report_Dashboard {
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_renewal_revenue_query', $query ) );
- set_transient( strtolower( __CLASS__ ), $cached_results, HOUR_IN_SECONDS );
+ $update_cache = true;
}
$report_data->renewal_revenue = $cached_results[ $query_hash ];
@@ -188,11 +188,15 @@ class WCS_Report_Dashboard {
if ( $args['no_cache'] || false === $cached_results || ! isset( $cached_results[ $query_hash ] ) ) {
$wpdb->query( 'SET SESSION SQL_BIG_SELECTS=1' );
$cached_results[ $query_hash ] = $wpdb->get_var( apply_filters( 'woocommerce_subscription_dashboard_status_widget_cancellation_query', $query ) );
- set_transient( strtolower( __CLASS__ ), $cached_results, HOUR_IN_SECONDS );
+ $update_cache = true;
}
$report_data->cancel_count = $cached_results[ $query_hash ];
+ if ( $update_cache ) {
+ set_transient( strtolower( __CLASS__ ), $cached_results, HOUR_IN_SECONDS );
+ }
+
return $report_data;
}
@@ -254,6 +258,15 @@ class WCS_Report_Dashboard {
* @since 2.1
*/
public static function dashboard_scripts() {
- wp_enqueue_style( 'wcs-dashboard-report', plugin_dir_url( WC_Subscriptions::$plugin_file ) . 'assets/css/dashboard.css', array(), WC_Subscriptions::$version );
+ wp_enqueue_style( 'wcs-dashboard-report', WC_Subscriptions_Plugin::instance()->get_plugin_directory_url( 'assets/css/dashboard.css' ), array(), WC_Subscriptions_Plugin::instance()->get_plugin_version() );
+ }
+
+ /**
+ * Clears the cached report data.
+ *
+ * @since 3.0.10
+ */
+ public static function clear_cache() {
+ delete_transient( strtolower( __CLASS__ ) );
}
}
diff --git a/includes/admin/reports/class-wcs-report-retention-rate.php b/includes/admin/reports/class-wcs-report-retention-rate.php
index d7f1bca..26418cf 100644
--- a/includes/admin/reports/class-wcs-report-retention-rate.php
+++ b/includes/admin/reports/class-wcs-report-retention-rate.php
@@ -129,7 +129,7 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
* @return null
*/
public function output_report() {
- include( plugin_dir_path( WC_Subscriptions::$plugin_file ) . '/includes/admin/views/html-report-by-period.php' );
+ include( WC_Subscriptions_Plugin::instance()->get_plugin_directory( 'includes/admin/views/html-report-by-period.php' ) );
}
/**
@@ -172,7 +172,7 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
var main_chart;
jQuery(function(){
- var subscription_lifespans = jQuery.parseJSON( '' ),
+ var subscription_lifespans = JSON.parse( '' ),
unended_subscriptions = report_data->unended_subscriptions ); ?>;
var drawGraph = function( highlight ) {
@@ -232,7 +232,7 @@ class WCS_Report_Retention_Rate extends WC_Admin_Report {
}
);
- jQuery('.chart-placeholder').resize();
+ jQuery('.chart-placeholder').trigger( 'resize' );
}
drawGraph();
diff --git a/includes/admin/reports/class-wcs-report-subscription-by-customer.php b/includes/admin/reports/class-wcs-report-subscription-by-customer.php
index 24412f2..20f0d60 100644
--- a/includes/admin/reports/class-wcs-report-subscription-by-customer.php
+++ b/includes/admin/reports/class-wcs-report-subscription-by-customer.php
@@ -280,4 +280,13 @@ class WCS_Report_Subscription_By_Customer extends WP_List_Table {
return $customer_totals;
}
+
+ /**
+ * Clears the cached report data.
+ *
+ * @since 3.0.10
+ */
+ public static function clear_cache() {
+ delete_transient( strtolower( __CLASS__ ) );
+ }
}
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 fe2a3a2..b1d6249 100644
--- a/includes/admin/reports/class-wcs-report-subscription-by-product.php
+++ b/includes/admin/reports/class-wcs-report-subscription-by-product.php
@@ -304,7 +304,7 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
}
}
);
- jQuery('.chart-placeholder.variation_breakdown_chart').resize();
+ jQuery('.chart-placeholder.variation_breakdown_chart').trigger( 'resize' );
jQuery.plot(
jQuery('.chart-placeholder.product_breakdown_chart'),
[
@@ -346,9 +346,18 @@ class WCS_Report_Subscription_By_Product extends WP_List_Table {
}
}
);
- jQuery('.chart-placeholder.product_breakdown_chart').resize();
+ jQuery('.chart-placeholder.product_breakdown_chart').trigger( 'resize' );
});
$this->group_by_query,
- 'order_status' => '',
+ 'order_status' => array(),
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
@@ -467,7 +467,7 @@ class WCS_Report_Subscription_Events_By_Date extends WC_Admin_Report {
set_transient( strtolower( get_class( $this ) ), $cached_results, WEEK_IN_SECONDS );
// Remove this class from the list of classes WC updates on shutdown. Introduced in WC 3.7
- if ( ! WC_Subscriptions::is_woocommerce_pre( '3.7' ) ) {
+ if ( ! wcs_is_woocommerce_pre( '3.7' ) ) {
unset( WC_Admin_Report::$transients_to_update[ strtolower( get_class( $this ) ) ] );
}
}
@@ -832,7 +832,7 @@ class WCS_Report_Subscription_Events_By_Date extends WC_Admin_Report {
var main_chart;
jQuery(function(){
- var order_data = jQuery.parseJSON( '' );
+ var order_data = JSON.parse( '' );
var drawGraph = function( highlight ) {
var series = [
{
@@ -1107,12 +1107,12 @@ class WCS_Report_Subscription_Events_By_Date extends WC_Admin_Report {
}
);
- jQuery('.chart-placeholder').resize();
+ jQuery('.chart-placeholder').trigger( 'resize' );
}
drawGraph();
- jQuery('.highlight_series').hover(
+ jQuery('.highlight_series').on( 'hover',
function() {
drawGraph( jQuery(this).data('series') );
},
@@ -1205,4 +1205,13 @@ class WCS_Report_Subscription_Events_By_Date extends WC_Admin_Report {
return $prepared_data;
}
+
+ /**
+ * Clears the cached report data.
+ *
+ * @since 3.0.10
+ */
+ public function clear_cache() {
+ delete_transient( strtolower( get_class( $this ) ) );
+ }
}
diff --git a/includes/admin/reports/class-wcs-report-subscription-payment-retry.php b/includes/admin/reports/class-wcs-report-subscription-payment-retry.php
index d1a8874..e77504c 100644
--- a/includes/admin/reports/class-wcs-report-subscription-payment-retry.php
+++ b/includes/admin/reports/class-wcs-report-subscription-payment-retry.php
@@ -239,7 +239,7 @@ class WCS_Report_Subscription_Payment_Retry extends WC_Admin_Report {
var main_chart;
jQuery(function(){
- var chart_data = jQuery.parseJSON( '' );
+ var chart_data = JSON.parse( '' );
var drawGraph = function( highlight ) {
var series = [
@@ -378,12 +378,12 @@ class WCS_Report_Subscription_Payment_Retry extends WC_Admin_Report {
}
);
- jQuery('.chart-placeholder').resize();
+ jQuery('.chart-placeholder').trigger( 'resize' );
}
drawGraph();
- jQuery('.highlight_series').hover(
+ jQuery('.highlight_series').on( 'hover',
function() {
drawGraph( jQuery(this).data('series') );
},
diff --git a/includes/admin/reports/class-wcs-report-upcoming-recurring-revenue.php b/includes/admin/reports/class-wcs-report-upcoming-recurring-revenue.php
index a4065e8..a2b0a35 100644
--- a/includes/admin/reports/class-wcs-report-upcoming-recurring-revenue.php
+++ b/includes/admin/reports/class-wcs-report-upcoming-recurring-revenue.php
@@ -240,7 +240,7 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
var main_chart;
jQuery(function(){
- var order_data = jQuery.parseJSON( '' );
+ var order_data = JSON.parse( '' );
var drawGraph = function( highlight ) {
var series = [
{
@@ -331,12 +331,12 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
}
);
- jQuery('.chart-placeholder').resize();
+ jQuery('.chart-placeholder').trigger( 'resize' );
}
drawGraph();
- jQuery('.highlight_series').hover(
+ jQuery('.highlight_series').on( 'hover',
function() {
drawGraph( jQuery(this).data('series') );
},
@@ -430,4 +430,13 @@ class WCS_Report_Upcoming_Recurring_Revenue extends WC_Admin_Report {
return $current_range;
}
+
+ /**
+ * Clears the cached query results.
+ *
+ * @since 3.0.10
+ */
+ public function clear_cache() {
+ delete_transient( strtolower( get_class( $this ) ) );
+ }
}
diff --git a/includes/api/class-wc-rest-subscription-notes-controller.php b/includes/api/class-wc-rest-subscription-notes-controller.php
index fb12433..509ee8d 100644
--- a/includes/api/class-wc-rest-subscription-notes-controller.php
+++ b/includes/api/class-wc-rest-subscription-notes-controller.php
@@ -1,23 +1,16 @@
/notes endpoint.
+ * Handles requests to the /subscriptions//notes endpoint.
*
- * @author Prospress
- * @since 2.1
+ * @package WooCommerce Subscriptions\Rest Api
+ * @since 3.1.0
*/
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
-/**
- * REST API Subscription Notes controller class.
- *
- * @package WooCommerce_Subscriptions/API
- * @extends WC_REST_Order_Notes_Controller
- */
-class WC_REST_Subscription_Notes_Controller extends WC_REST_Order_Notes_V1_Controller {
+defined( 'ABSPATH' ) || exit;
+
+class WC_REST_Subscription_notes_Controller extends WC_REST_Order_Notes_Controller {
/**
* Route base.
@@ -33,4 +26,18 @@ class WC_REST_Subscription_Notes_Controller extends WC_REST_Order_Notes_V1_Contr
*/
protected $post_type = 'shop_subscription';
+ /**
+ * Prepare links for the request.
+ *
+ * @since 3.1.0
+ *
+ * @param WP_Comment $note
+ * @return array Links for the given order note.
+ */
+ protected function prepare_links( $note ) {
+ $links = parent::prepare_links( $note );
+ $links['up'] = array( 'href' => rest_url( sprintf( '/%s/subscriptions/%d', $this->namespace, (int) $note->comment_post_ID ) ) );
+
+ return $links;
+ }
}
diff --git a/includes/api/class-wc-rest-subscription-system-status-manager.php b/includes/api/class-wc-rest-subscription-system-status-manager.php
new file mode 100644
index 0000000..cdd29b8
--- /dev/null
+++ b/includes/api/class-wc-rest-subscription-system-status-manager.php
@@ -0,0 +1,148 @@
+/system_status endpoint.
+ *
+ * @package WooCommerce Subscriptions\Rest Api
+ * @since 3.1.0
+ */
+
+defined( 'ABSPATH' ) || exit;
+
+class WC_REST_Subscription_System_Status_Manager {
+
+ /**
+ * Attach callbacks.
+ */
+ public static function init() {
+ add_filter( 'woocommerce_rest_prepare_system_status', array( __CLASS__, 'add_subscription_fields_to_reponse' ) );
+ add_filter( 'woocommerce_rest_system_status_schema', array( __CLASS__, 'add_additional_fields_to_schema' ) );
+ }
+
+ /**
+ * Adds subscription fields to System Status response.
+ *
+ * @since 3.1.0
+ *
+ * @param WP_REST_Response $response The base system status response.
+ * @return WP_REST_Response
+ */
+ public static function add_subscription_fields_to_reponse( $response ) {
+ $response->data['subscriptions'] = array(
+ 'wcs_debug' => defined( 'WCS_DEBUG' ) ? WCS_DEBUG : false,
+ 'mode' => ( WCS_Staging::is_duplicate_site() ) ? __( 'staging', 'woocommerce-subscriptions' ) : __( 'live', 'woocommerce-subscriptions' ),
+ 'live_url' => esc_url( WCS_Staging::get_site_url_from_source( 'subscriptions_install' ) ),
+ 'statuses' => array_filter( (array) wp_count_posts( 'shop_subscription' ) ),
+ 'report_cache_enabled' => ( 'yes' === get_option( 'woocommerce_subscriptions_cache_updates_enabled', 'yes' ) ),
+ 'cache_update_failures' => absint( get_option( 'woocommerce_subscriptions_cache_updates_failures', 0 ) ),
+ 'subscriptions_by_payment_gateway' => WCS_Admin_System_Status::get_subscriptions_by_gateway(),
+ 'payment_gateway_feature_support' => self::get_payment_gateway_feature_support(),
+ );
+
+ return $response;
+ }
+
+ /**
+ * Gets the store's payment gateways and the features they support.
+ *
+ * @since 3.1.0
+ * @return array Payment gateway and their features.
+ */
+ private static function get_payment_gateway_feature_support() {
+ $gateway_features = array();
+
+ foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway_id => $gateway ) {
+ // Some gateways include array keys. For consistancy, only send the values.
+ $gateway_features[ $gateway_id ] = array_values( (array) apply_filters( 'woocommerce_subscriptions_payment_gateway_features_list', $gateway->supports, $gateway ) );
+
+ if ( 'paypal' === $gateway_id && WCS_PayPal::are_reference_transactions_enabled() ) {
+ $gateway_features[ $gateway_id ][] = 'paypal_reference_transactions';
+ }
+ }
+
+ return $gateway_features;
+ }
+
+ /**
+ * Adds subscription system status fields the system status schema.
+ *
+ * @since 3.1.0
+ * @param array $schema
+ *
+ * @return array the system status schema.
+ */
+ public static function add_additional_fields_to_schema( $schema ) {
+
+ $schema['properties']['subscriptions'] = array(
+ array(
+ 'description' => __( 'Subscriptions.', 'woocommerce-subscriptions' ),
+ 'type' => 'object',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ 'properties' => array(
+ 'wcs_debug_enabled' => array(
+ 'description' => __( 'WCS debug constant.', 'woocommerce-subscriptions' ),
+ 'type' => 'boolean',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'mode' => array(
+ 'description' => __( 'Subscriptions Mode', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'live_url' => array(
+ 'description' => __( 'Subscriptions Live Site URL', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'format' => 'uri',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'statuses' => array(
+ 'description' => __( 'Subscriptions broken down by status.', 'woocommerce-subscriptions' ),
+ 'type' => 'array',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ 'items' => array(
+ 'type' => 'string',
+ ),
+ ),
+ 'report_cache_enabled' => array(
+ 'description' => __( 'Whether the Report Cache is enabled.', 'woocommerce-subscriptions' ),
+ 'type' => 'boolean',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'cache_update_failures' => array(
+ 'description' => __( 'Number of report cache failures.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'subscriptions_by_payment_gateway' => array(
+ 'description' => __( 'Subscriptions by Payment Gateway.', 'woocommerce-subscriptions' ),
+ 'type' => 'array',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ 'items' => array(
+ 'type' => 'string',
+ ),
+ ),
+ 'payment_gateway_feature_support' => array(
+ 'description' => __( 'Payment Gateway Feature Support.', 'woocommerce-subscriptions' ),
+ 'type' => 'array',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ 'items' => array(
+ 'type' => 'string',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ return $schema;
+ }
+}
diff --git a/includes/api/class-wc-rest-subscriptions-controller.php b/includes/api/class-wc-rest-subscriptions-controller.php
index 58907a3..01c72f7 100644
--- a/includes/api/class-wc-rest-subscriptions-controller.php
+++ b/includes/api/class-wc-rest-subscriptions-controller.php
@@ -2,23 +2,15 @@
/**
* REST API Subscriptions controller
*
- * Handles requests to the /subscription endpoint.
+ * Handles requests to the /subscriptions endpoint.
*
- * @author Prospress
- * @since 2.1
+ * @package WooCommerce Subscriptions\Rest Api
+ * @since 3.1.0
*/
-if ( ! defined( 'ABSPATH' ) ) {
- exit;
-}
+defined( 'ABSPATH' ) || exit;
-/**
- * REST API Subscriptions controller class.
- *
- * @package WooCommerce_Subscriptions/API
- * @extends WC_REST_Orders_Controller
- */
-class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
+class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
/**
* Route base.
@@ -28,28 +20,38 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
protected $rest_base = 'subscriptions';
/**
- * Post type.
+ * The post type.
*
* @var string
*/
protected $post_type = 'shop_subscription';
/**
- * Initialize subscription actions and filters
- */
- public function __construct() {
- add_filter( 'woocommerce_rest_prepare_shop_subscription', array( $this, 'filter_get_subscription_response' ), 10, 3 );
-
- add_filter( 'woocommerce_rest_shop_subscription_query', array( $this, 'query_args' ), 10, 2 );
- }
-
- /**
- * Register the routes for subscriptions.
+ * Register the routes for the subscriptions endpoint.
+ *
+ * -- Inherited --
+ * GET|POST /subscriptions
+ * GET|PUT|DELETE /subscriptions/
+ *
+ * -- Subscription specific --
+ * GET /subscriptions/status
+ * GET /subscriptions//orders
+ *
+ * @since 3.1.0
*/
public function register_routes() {
parent::register_routes();
- register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)/orders', array(
+ register_rest_route( $this->namespace, "/{$this->rest_base}/statuses", array(
+ array(
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => array( $this, 'get_statuses' ),
+ 'permission_callback' => '__return_true',
+ ),
+ 'schema' => array( $this, 'get_public_item_schema' ),
+ ) );
+
+ register_rest_route( $this->namespace, "/{$this->rest_base}/(?P[\d]+)/orders", array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_subscription_orders' ),
@@ -58,259 +60,130 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
-
- register_rest_route( $this->namespace, '/' . $this->rest_base . '/statuses', array(
- array(
- 'methods' => WP_REST_Server::READABLE,
- 'callback' => array( $this, 'get_statuses' ),
- 'permission_callback' => '__return_true',
- ),
- 'schema' => array( $this, 'get_public_item_schema' ),
- ) );
}
/**
- * Filter WC_REST_Orders_Controller::get_item response for subscription post types
+ * Gets the request object. Return false if the ID is not a subscription.
*
- * @since 2.1
- * @param WP_REST_Response $response
- * @param WP_POST $post
- * @param WP_REST_Request $request
+ * @since 3.1.0
+ * @param int $id Object ID.
+ * @return WC_Subscription|bool
*/
- public function filter_get_subscription_response( $response, $post, $request ) {
- $decimal_places = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] );
+ protected function get_object( $id ) {
+ $subscription = wcs_get_subscription( $id );
- if ( ! empty( $post->post_type ) && ! empty( $post->ID ) && 'shop_subscription' == $post->post_type ) {
- $subscription = wcs_get_subscription( $post->ID );
-
- $response->data['billing_period'] = $subscription->get_billing_period();
- $response->data['billing_interval'] = $subscription->get_billing_interval();
-
- // Send resubscribe data
- $resubscribed_subscriptions = array_filter( $subscription->get_related_orders( 'ids', 'resubscribe' ), 'wcs_is_subscription' );
- $response->data['resubscribed_from'] = strval( wcs_get_objects_property( $subscription, 'subscription_resubscribe' ) );
- $response->data['resubscribed_subscription'] = strval( reset( $resubscribed_subscriptions ) ); // Subscriptions can only be resubscribed to once so return the first and only element.
-
- foreach ( array( 'start', 'trial_end', 'next_payment', 'end' ) as $date_type ) {
- $date = $subscription->get_date( $date_type );
- $response->data[ $date_type . '_date' ] = ( ! empty( $date ) ) ? wc_rest_prepare_date_response( $date ) : '';
- }
-
- // v1 API includes some date types in site time, include those dates in UTC as well.
- $response->data['date_completed_gmt'] = wc_rest_prepare_date_response( $subscription->get_date_completed() );
- $response->data['date_paid_gmt'] = wc_rest_prepare_date_response( $subscription->get_date_paid() );
- $response->data['removed_line_items'] = array();
-
- // Include removed line items of a subscription
- foreach ( $subscription->get_items( 'line_item_removed' ) as $item_id => $item ) {
- $product = $item->get_product();
- $product_id = 0;
- $variation_id = 0;
- $product_sku = null;
-
- // Check if the product exists.
- if ( is_object( $product ) ) {
- $product_id = $item->get_product_id();
- $variation_id = $item->get_variation_id();
- $product_sku = $product->get_sku();
- }
-
- $item_meta = array();
-
- $hideprefix = 'true' === $request['all_item_meta'] ? null : '_';
-
- foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) {
- $item_meta[] = array(
- 'key' => $formatted_meta->key,
- 'label' => $formatted_meta->display_key,
- 'value' => wc_clean( $formatted_meta->display_value ),
- );
- }
-
- $line_item = array(
- 'id' => $item_id,
- 'name' => $item['name'],
- 'sku' => $product_sku,
- 'product_id' => (int) $product_id,
- 'variation_id' => (int) $variation_id,
- 'quantity' => wc_stock_amount( $item['qty'] ),
- 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '',
- 'price' => wc_format_decimal( $subscription->get_item_total( $item, false, false ), $decimal_places ),
- 'subtotal' => wc_format_decimal( $subscription->get_line_subtotal( $item, false, false ), $decimal_places ),
- 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $decimal_places ),
- 'total' => wc_format_decimal( $subscription->get_line_total( $item, false, false ), $decimal_places ),
- 'total_tax' => wc_format_decimal( $item['line_tax'], $decimal_places ),
- 'taxes' => array(),
- 'meta' => $item_meta,
- );
-
- $item_line_taxes = maybe_unserialize( $item['line_tax_data'] );
- if ( isset( $item_line_taxes['total'] ) ) {
- $line_tax = array();
-
- foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) {
- $line_tax[ $tax_rate_id ] = array(
- 'id' => $tax_rate_id,
- 'total' => $tax,
- 'subtotal' => '',
- );
- }
-
- foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) {
- $line_tax[ $tax_rate_id ]['subtotal'] = $tax;
- }
-
- $line_item['taxes'] = array_values( $line_tax );
- }
-
- $response->data['removed_line_items'][] = $line_item;
- }
+ if ( ! $subscription || ! is_a( $subscription, 'WC_Subscription' ) ) {
+ return false;
}
+ return $subscription;
+ }
+
+ /**
+ * Prepare a single subscription output for response.
+ *
+ * @since 3.1.0
+ *
+ * @param WC_Data $object Subscription object.
+ * @param WP_REST_Request $request Request object.
+ * @return WP_REST_Response
+ */
+ public function prepare_object_for_response( $object, $request ) {
+ $response = parent::prepare_object_for_response( $object, $request );
+
+ // When generating the `/subscriptions/[id]/orders` response this function is called to generate related-order data so exit early if this isn't a subscription.
+ if ( ! wcs_is_subscription( $object ) ) {
+ return $response;
+ }
+
+ // Add subscription specific data to the base order response data.
+ $response->data['billing_period'] = $object->get_billing_period();
+ $response->data['billing_interval'] = $object->get_billing_interval();
+
+ foreach ( wcs_get_subscription_date_types() as $date_type => $date_name ) {
+ $date = $object->get_date( wcs_normalise_date_type_key( $date_type ) );
+ $response->data[ $date_type . '_date_gmt' ] = ( ! empty( $date ) ) ? wc_rest_prepare_date_response( $date ) : '';
+ }
+
+ // Some base WC_Order dates need to be pulled from the subscription object to be correct.
+ $response->data['date_paid'] = wc_rest_prepare_date_response( $object->get_date_paid(), false );
+ $response->data['date_paid_gmt'] = wc_rest_prepare_date_response( $object->get_date_paid() );
+ $response->data['date_completed'] = wc_rest_prepare_date_response( $object->get_date_completed(), false );
+ $response->data['date_completed_gmt'] = wc_rest_prepare_date_response( $object->get_date_completed() );
+
+ // Include resubscribe data.
+ $resubscribed_subscriptions = array_filter( $object->get_related_orders( 'ids', 'resubscribe' ), 'wcs_is_subscription' );
+ $response->data['resubscribed_from'] = strval( $object->get_meta( '_subscription_resubscribe' ) );
+ $response->data['resubscribed_subscription'] = strval( reset( $resubscribed_subscriptions ) ); // Subscriptions can only be resubscribed to once so return the first and only element.
+
+ // Include the removed line items.
+ $response->data['removed_line_items'] = array();
+
+ foreach ( $object->get_items( 'line_item_removed' ) as $item ) {
+ $response->data['removed_line_items'][] = $this->get_order_item_data( $item );
+ }
+
+ // Remove non-subscription properties
+ unset( $response->data['cart_hash'] );
+ unset( $response->data['transaction_id'] );
+
return $response;
}
/**
- * Sets the order_total value on the subscription after WC_REST_Orders_Controller::create_order
- * calls calculate_totals(). This allows store admins to create a recurring payment via the api
- * without needing to attach a product to the subscription.
+ * Gets the /subscriptions/statuses response.
*
- * @since 2.1
- * @param WP_REST_Request $request
+ * @since 3.1.0
+ * @return WP_REST_Response The response object.
*/
- protected function create_order( $request ) {
- try {
- if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] && false === get_user_by( 'id', $request['customer_id'] ) ) {
- throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce-subscriptions' ), 400 );
- }
-
- // If the start date is not set in the request, set its default to now
- if ( ! isset( $request['start_date'] ) ) {
- $request['start_date'] = gmdate( 'Y-m-d H:i:s' );
- }
-
- // prepare all subscription data from the request
- $subscription = $this->prepare_item_for_database( $request );
- $subscription->set_created_via( 'rest-api' );
- $subscription->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
- $subscription->calculate_totals();
-
- // allow the order total to be overriden (i.e. if you want to have a subscription with no order items but a flat $10.00 recurring payment )
- if ( isset( $request['order_total'] ) ) {
- $subscription->set_total( wc_format_decimal( $request['order_total'], get_option( 'woocommerce_price_num_decimals' ) ) );
- }
-
- // Store the post meta on the subscription after it's saved, this is to avoid compat. issue with the filters in WC_Subscriptions::set_payment_method_meta() expecting the $subscription to have an ID (therefore it needs to be called after the WC_Subscription has been saved)
- $payment_data = ( ! empty( $request['payment_details'] ) ) ? $request['payment_details'] : array();
- if ( empty( $payment_data['payment_details']['method_id'] ) && ! empty( $request['payment_method'] ) ) {
- $payment_data['method_id'] = $request['payment_method'];
- }
-
- $this->update_payment_method( $subscription, $payment_data );
-
- $subscription->save();
-
- // Handle set paid.
- if ( true === $request['set_paid'] ) {
- $subscription->payment_complete( $request['transaction_id'] );
- }
-
- return $subscription->get_id();
- } catch ( WC_Data_Exception $e ) {
- return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
- } catch ( WC_REST_Exception $e ) {
- return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
- }
+ public function get_statuses() {
+ return rest_ensure_response( wcs_get_subscription_statuses() );
}
/**
- * Overrides WC_REST_Orders_Controller::update_order to update subscription specific meta
- * calls parent::update_order to update the rest.
+ * Gets the /subscriptions/[id]/orders response.
*
- * @since 2.1
- * @param WP_REST_Request $request
- * @param WP_POST $post
- */
- protected function update_order( $request ) {
- try {
- $subscription = $this->prepare_item_for_database( $request );
-
- // If any line items have changed, recalculate subscription totals.
- if ( isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
- $subscription->calculate_totals();
- }
-
- // allow the order total to be overriden (i.e. if you want to have a subscription with no order items but a flat $10.00 recurring payment )
- if ( isset( $request['order_total'] ) ) {
- $subscription->set_total( wc_format_decimal( $request['order_total'], get_option( 'woocommerce_price_num_decimals' ) ) );
- }
-
- $subscription->save();
-
- // Update the post meta on the subscription after it's saved, this is to avoid compat. issue with the filters in WC_Subscriptions::set_payment_method_meta() expecting the $subscription to have an ID (therefore it needs to be called after the WC_Subscription has been saved)
- $payment_data = ( ! empty( $request['payment_details'] ) ) ? $request['payment_details'] : array();
- $existing_payment_method_id = $subscription->get_payment_method();
-
- if ( empty( $payment_data['method_id'] ) && isset( $request['payment_method'] ) ) {
- $payment_data['method_id'] = $request['payment_method'];
-
- } elseif ( ! empty( $existing_payment_method_id ) ) {
- $payment_data['method_id'] = $existing_payment_method_id;
- }
-
- if ( isset( $payment_data['method_id'] ) ) {
- $this->update_payment_method( $subscription, $payment_data, true );
- }
-
- // Handle set paid.
- if ( $subscription->needs_payment() && true === $request['set_paid'] ) {
- $subscription->payment_complete();
- }
-
- return $subscription->get_id();
- } catch ( WC_Data_Exception $e ) {
- return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
- } catch ( WC_REST_Exception $e ) {
- return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
- }
- }
-
- /**
- * Get subscription orders
+ * @since 3.1.0
*
- * @since 2.1
- * @param WP_REST_Request $request
- * @return WP_Error|WP_REST_Response $response
+ * @param WP_REST_Request $request The request object.
+ * @return WP_Error|WP_REST_Response $response The response or an error if one occurs.
*/
public function get_subscription_orders( $request ) {
- $id = (int) $request['id'];
+ $id = absint( $request['id'] );
if ( empty( $id ) || ! wcs_is_subscription( $id ) ) {
- return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription id.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
+ return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription ID.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
}
- $this->post_type = 'shop_order';
- $subscription = wcs_get_subscription( $id );
- $subscription_orders = $subscription->get_related_orders();
+ $subscription = wcs_get_subscription( $id );
+
+ if ( ! $subscription ) {
+ return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', sprintf( __( 'Failed to load subscription object with the ID %d.', 'woocommerce-subscriptions' ), $id ), array( 'status' => 404 ) );
+ }
$orders = array();
- foreach ( $subscription_orders as $order_id ) {
- $post = get_post( $order_id );
- if ( ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
- continue;
- }
+ foreach ( array( 'parent', 'renewal', 'switch' ) as $order_type ) {
+ foreach ( $subscription->get_related_orders( 'ids', $order_type ) as $order_id ) {
- $response = $this->prepare_item_for_response( $post, $request );
-
- foreach ( array( 'parent', 'renewal', 'switch' ) as $order_type ) {
- if ( wcs_order_contains_subscription( $order_id, $order_type ) ) {
- $response->data['order_type'] = $order_type . '_order';
- break;
+ if ( ! wc_rest_check_post_permissions( 'shop_order', 'read', $order_id ) ) {
+ continue;
}
- }
- $orders[] = $this->prepare_response_for_collection( $response );
+ // Validate that the order can be loaded before trying to generate a response object for it.
+ $order = wc_get_order( $order_id );
+
+ if ( ! $order ) {
+ continue;
+ }
+
+ $response = $this->prepare_object_for_response( $order, $request );
+
+ // Add the order's relationship to the response.
+ $response->data['order_type'] = $order_type . '_order';
+
+ $orders[] = $this->prepare_response_for_collection( $response );
+ }
}
$response = rest_ensure_response( $orders );
@@ -320,77 +193,318 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
return apply_filters( 'wcs_rest_subscription_orders_response', $response, $request );
}
- /**
- * Get subscription statuses
- *
- * @since 2.1
- */
- public function get_statuses() {
- return rest_ensure_response( wcs_get_subscription_statuses() );
- }
-
/**
* Overrides WC_REST_Orders_Controller::get_order_statuses() so that subscription statuses are
- * validated correctly in WC_REST_Orders_Controller::get_collection_params()
+ * validated correctly.
*
- * @since 2.1
+ * @since 3.1.0
+ * @return array An array of valid subscription statuses.
*/
protected function get_order_statuses() {
$subscription_statuses = array();
- foreach ( array_keys( wcs_get_subscription_statuses() ) as $status ) {
+ foreach ( wcs_get_subscription_statuses() as $status => $status_name ) {
$subscription_statuses[] = str_replace( 'wc-', '', $status );
}
+
return $subscription_statuses;
}
/**
- * Validate and update payment method on a subscription
+ * Prepares a single subscription for creation or update.
*
- * @since 2.1
- * @param WC_Subscription $subscription
- * @param array $data
- * @param bool $updating
+ * @since 3.1.0
+ *
+ * @param WP_REST_Request $request Request object.
+ * @param bool $creating If the request is for creating a new object.
+ * @return WP_Error|WC_Subscription
*/
- public function update_payment_method( $subscription, $data, $updating = false ) {
- $payment_method = ( ! empty( $data['method_id'] ) ) ? $data['method_id'] : '';
+ public function prepare_object_for_database( $request, $creating = false ) {
+ $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
+ $subscription = new WC_Subscription( $id );
+ $schema = $this->get_item_schema();
+ $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
- try {
- if ( $updating && ! array_key_exists( $payment_method, WCS_Change_Payment_Method_Admin::get_valid_payment_methods( $subscription ) ) ) {
- throw new Exception( __( 'Gateway does not support admin changing the payment method on a Subscription.', 'woocommerce-subscriptions' ) );
+ // Prepare variables for properties which need to be saved late (like status) or in a group (dates and payment data).
+ $status = '';
+ $payment_method = '';
+ $payment_meta = array();
+ $dates = array();
+
+ // If the start date is not set in the request, set its default to now.
+ if ( ! isset( $request['start_date'] ) ) {
+ $request['start_date'] = gmdate( 'Y-m-d H:i:s' );
+ }
+
+ // Both setting (set_status()) and updating (update_status()) are valid ways for requests to set a subscription's status.
+ $status_transition = 'set';
+
+ foreach ( $data_keys as $i => $key ) {
+ $value = $request[ $key ];
+
+ if ( is_null( $value ) ) {
+ continue;
}
- $payment_method_meta = apply_filters( 'woocommerce_subscription_payment_meta', array(), $subscription );
-
- // Reload the subscription to update the meta values.
- // In particular, the update_post_meta() called while _stripe_card_id is updated to _stripe_source_id
- $subscription = wcs_get_subscription( $subscription->get_id() );
-
- if ( isset( $payment_method_meta[ $payment_method ] ) ) {
- $payment_method_meta = $payment_method_meta[ $payment_method ];
-
- if ( ! empty( $payment_method_meta ) ) {
-
- foreach ( $payment_method_meta as $meta_table => &$meta ) {
- if ( ! is_array( $meta ) ) {
- continue;
- }
-
- foreach ( $meta as $meta_key => &$meta_data ) {
-
- if ( isset( $data[ $meta_table ][ $meta_key ] ) ) {
- $meta_data['value'] = $data[ $meta_table ][ $meta_key ];
+ switch ( $key ) {
+ case 'parent_id':
+ $subscription->set_parent_id( $value );
+ break;
+ case 'transition_status':
+ $status_transition = 'update';
+ case 'status':
+ // This needs to be done later so status changes take into account other data like dates.
+ $status = $value;
+ break;
+ case 'billing':
+ case 'shipping':
+ $this->update_address( $subscription, $value, $key );
+ break;
+ case 'start_date':
+ case 'trial_end':
+ case 'next_payment_date':
+ case 'cancelled_date':
+ case 'end_date':
+ // Group all the subscription date properties so they can be validated together.
+ $dates[ $key ] = $value;
+ break;
+ case 'payment_method':
+ $payment_method = $value;
+ break;
+ case 'payment_details':
+ // Format the value in a way payment gateways expect so it can be validated.
+ $payment_meta = $value;
+ break;
+ case 'line_items':
+ case 'shipping_lines':
+ case 'fee_lines':
+ if ( is_array( $value ) ) {
+ foreach ( $value as $item ) {
+ if ( is_array( $item ) ) {
+ if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
+ if ( isset( $item['id'] ) ) {
+ $subscription->remove_item( $item['id'] );
+ }
+ } else {
+ $this->set_item( $subscription, $key, $item );
+ }
}
}
}
+ break;
+ case 'meta_data':
+ if ( is_array( $value ) ) {
+ foreach ( $value as $meta ) {
+ $subscription->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
+ }
+ }
+ break;
+ default:
+ if ( is_callable( array( $subscription, "set_{$key}" ) ) ) {
+ $subscription->{"set_{$key}"}( $value );
+ }
+ break;
+ }
+ }
+
+ if ( ! empty( $payment_method ) ) {
+ $this->update_payment_method( $subscription, $payment_method, $payment_meta );
+ }
+
+ if ( ! empty( $dates ) ) {
+ // If the start date is not set in the request when a subscription is created with an active status, set its default to now.
+ if ( 'active' === $status && empty( $id ) && ! isset( $dates['start_date'] ) ) {
+ $dates['start_date'] = gmdate( 'Y-m-d H:i:s' );
+ }
+
+ try {
+ $subscription->update_dates( $dates );
+ } catch ( Exception $e ) {
+ throw new WC_REST_Exception( 'woocommerce_rest_invalid_payment_data', sprintf( __( 'Subscription dates could not be set. Error message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
+ }
+ }
+
+ if ( ! empty( $status ) ) {
+ if ( 'set' === $status_transition ) {
+ $subscription->set_status( $status );
+ } else {
+ $subscription->update_status( $status );
+ $request['status'] = $status; // Set the request status so parent::save_object() doesn't set it to the default 'pending' status.
+ }
+ }
+
+ /**
+ * Filters an object before it is inserted via the REST API.
+ *
+ * The dynamic portion of the hook name, `$this->post_type`,
+ * refers to the object type slug.
+ *
+ * @param WC_Subscription $subscription The subscription object.
+ * @param WP_REST_Request $request Request object.
+ * @param bool $creating If is creating a new object.
+ */
+ return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}_object", $subscription, $request, $creating );
+ }
+
+ /**
+ * Adds additional item schema information for subscription requests.
+ *
+ * @since 3.1.0
+ * @return array
+ */
+ public function get_item_schema() {
+ $schema = parent::get_item_schema();
+
+ // Base order schema overrides.
+ $schema['properties']['status']['description'] = __( 'Subscription status.', 'woocommerce-subscriptions' );
+ $schema['properties']['status']['enum'] = $this->get_order_statuses();
+
+ $schema['properties']['created_via']['description'] = __( 'Where the subscription was created.', 'woocommerce-subscriptions' );
+ $schema['properties']['currency']['description'] = __( 'Currency the subscription was created with, in ISO format.', 'woocommerce-subscriptions' );
+ $schema['properties']['date_created']['description'] = __( "The date the subscription was created, in the site's timezone.", 'woocommerce-subscriptions' );
+ $schema['properties']['date_created_gmt']['description'] = __( 'The date the subscription was created, as GMT.', 'woocommerce-subscriptions' );
+ $schema['properties']['date_modified']['description'] = __( "The date the subscription was last modified, in the site's timezone.", 'woocommerce-subscriptions' );
+ $schema['properties']['date_modified_gmt']['description'] = __( 'The date the subscription was last modified, as GMT.', 'woocommerce-subscriptions' );
+ $schema['properties']['customer_id']['description'] = __( 'User ID who owns the subscription.', 'woocommerce-subscriptions' );
+
+ unset( $schema['properties']['transaction_id'] );
+ unset( $schema['properties']['refunds'] );
+ unset( $schema['properties']['set_paid'] );
+ unset( $schema['properties']['cart_hash'] );
+
+ // Add subscription schema.
+ $schema['properties'] += array(
+ 'transition_status' => array(
+ 'description' => __( 'The status to transition a subscription to.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'edit' ),
+ 'enum' => $this->get_order_statuses(),
+ ),
+ 'billing_interval' => array(
+ 'description' => __( 'The number of billing periods between subscription renewals.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'billing_period' => array(
+ 'description' => __( 'Billing period for the subscription.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'enum' => array_keys( wcs_get_subscription_period_strings() ),
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'payment_details' => array(
+ 'description' => __( 'Subscription payment details.', 'woocommerce-subscriptions' ),
+ 'type' => 'object',
+ 'context' => array( 'edit' ),
+ 'properties' => array(
+ 'post_meta' => array(
+ 'description' => __( 'Payment method meta and token in a post_meta_key: token format.', 'woocommerce-subscriptions' ),
+ 'type' => 'object',
+ 'context' => array( 'edit' ),
+ ),
+ 'user_meta' => array(
+ 'description' => __( 'Payment method meta and token in a user_meta_key : token format.', 'woocommerce-subscriptions' ),
+ 'type' => 'object',
+ 'context' => array( 'view' ),
+ ),
+ ),
+ ),
+ 'start_date' => array(
+ 'description' => __( "The subscription's start date, as GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'trial_date' => array(
+ 'description' => __( "The subscription's trial date, as GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'next_payment_date' => array(
+ 'description' => __( "The subscription's next payment date, as GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'cancelled_date' => array(
+ 'description' => __( "The subscription's cancelled date, as GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'end_date' => array(
+ 'description' => __( "The subscription's end date, as GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ );
+
+ return $schema;
+ }
+
+ /**
+ * Get the query params for collections.
+ *
+ * @since 3.1.0
+ * @return array
+ */
+ public function get_collection_params() {
+ $params = parent::get_collection_params();
+
+ // Override the base order status description to be subscription specific.
+ $params['status']['description'] = __( 'Limit result set to subscriptions which have specific statuses.', 'woocommerce-subscriptions' );
+ return $params;
+ }
+
+ /**
+ * Gets an object's links to include in the response.
+ *
+ * Because this class also handles retreiving order data, we need
+ * to edit the links generated so the correct REST API href is included
+ * when its generated for an order.
+ *
+ * @since 3.1.0
+ *
+ * @param WC_Data $object Object data.
+ * @param WP_REST_Request $request Request object.
+ * @return array Links for the given object.
+ */
+ protected function prepare_links( $object, $request ) {
+ $links = parent::prepare_links( $object, $request );
+
+ if ( isset( $links['self'] ) && wcs_is_order( $object ) ) {
+ $links['self'] = array(
+ 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, 'orders', $object->get_id() ) ),
+ );
+ }
+
+ return $links;
+ }
+
+ /**
+ * Updates a subscription's payment method and meta from data provided in a REST API request.
+ *
+ * @since 3.1.0
+ *
+ * @param WC_Subscription $subscription The subscription to update.
+ * @param string $payment_method The ID of the payment method to set.
+ * @param array $payment_meta The payment method meta.
+ */
+ public function update_payment_method( $subscription, $payment_method, $payment_meta ) {
+ $updating_subscription = (bool) $subscription->get_id();
+
+ try {
+ if ( $updating_subscription && ! array_key_exists( $payment_method, WCS_Change_Payment_Method_Admin::get_valid_payment_methods( $subscription ) ) ) {
+ // translators: placeholder is the payment method ID.
+ throw new Exception( sprintf( __( 'The %s payment gateway does not support admin changing the payment method.', 'woocommerce-subscriptions' ), $payment_method ) );
+ }
+
+ // Format the payment meta in the way payment gateways expect so it can be validated.
+ $payment_method_meta = array();
+
+ foreach ( $payment_meta as $table => $meta ) {
+ foreach ( $meta as $meta_key => $value ) {
+ $payment_method_meta[ $table ][ $meta_key ] = array( 'value' => $value );
}
}
$subscription->set_payment_method( $payment_method, $payment_method_meta );
-
- // Save the subscription to reflect the new values
- $subscription->save();
-
} catch ( Exception $e ) {
$subscription->set_payment_method();
$subscription->save();
@@ -398,380 +512,4 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_V1_Controller {
throw new WC_REST_Exception( 'woocommerce_rest_invalid_payment_data', sprintf( __( 'Subscription payment method could not be set to %1$s with error message: %2$s', 'woocommerce-subscriptions' ), $payment_method, $e->getMessage() ), 400 );
}
}
-
- /**
- * Prepare a single subscription for create.
- *
- * @param WP_REST_Request $request Request object.
- * @return WP_Error|WC_Subscription $data Object.
- */
- protected function prepare_item_for_database( $request ) {
- $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
- $subscription = new WC_Subscription( $id );
- $schema = $this->get_item_schema();
- $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
-
- $dates_to_update = array();
-
- // Handle all writable props
- foreach ( $data_keys as $key ) {
- $value = $request[ $key ];
-
- if ( ! is_null( $value ) ) {
- switch ( $key ) {
- case 'billing':
- case 'shipping':
- $this->update_address( $subscription, $value, $key );
- break;
- case 'line_items':
- case 'shipping_lines':
- case 'fee_lines':
- case 'coupon_lines':
- if ( is_array( $value ) ) {
- foreach ( $value as $item ) {
- if ( is_array( $item ) ) {
- if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
- $subscription->remove_item( $item['id'] );
- } else {
- $this->set_item( $subscription, $key, $item );
- }
- }
- }
- }
- break;
- case 'transition_status':
- $subscription->update_status( $value );
- break;
- case 'start_date':
- case 'trial_end_date':
- case 'next_payment_date':
- case 'end_date':
- $dates_to_update[ $key ] = $value;
- break;
- default:
- if ( is_callable( array( $subscription, "set_{$key}" ) ) ) {
- $subscription->{"set_{$key}"}( $value );
- }
- break;
- }
- }
- }
-
- $subscription->save();
-
- try {
- if ( ! empty( $dates_to_update ) ) {
- $subscription->update_dates( $dates_to_update );
- }
- } catch ( Exception $e ) {
- // translators: placeholder is an error message.
- throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_subscription_dates', sprintf( __( 'Updating subscription dates errored with message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
- }
-
- /**
- * Filter the data for the insert.
- *
- * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
- * prepared for the response.
- *
- * @param WC_Subscription $subscription The subscription object.
- * @param WP_REST_Request $request Request object.
- */
- return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $subscription, $request );
- }
-
- /**
- * Adds additional item schema information for subscription requests
- *
- * @since 2.1
- */
- public function get_item_schema() {
- $schema = parent::get_item_schema();
-
- $subscriptions_schema = array(
- 'transition_status' => array(
- 'description' => __( 'The status to transition the subscription to. Unlike the "status" param, this will calculate and update the subscription dates.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'enum' => $this->get_order_statuses(),
- 'context' => array( 'edit' ),
- ),
- 'billing_interval' => array(
- 'description' => __( 'The number of billing periods between subscription renewals.', 'woocommerce-subscriptions' ),
- 'type' => 'integer',
- 'context' => array( 'view', 'edit' ),
- ),
- 'billing_period' => array(
- 'description' => __( 'Billing period for the subscription.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'enum' => array_keys( wcs_get_subscription_period_strings() ),
- 'context' => array( 'view', 'edit' ),
- ),
- 'payment_details' => array(
- 'description' => __( 'Subscription payment details.', 'woocommerce-subscriptions' ),
- 'type' => 'object',
- 'context' => array( 'edit' ),
- 'properties' => array(
- 'method_id' => array(
- 'description' => __( 'Payment gateway ID.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'edit' ),
- ),
- ),
- ),
- 'start_date' => array(
- 'description' => __( "The subscription's start date.", 'woocommerce-subscriptions' ),
- 'type' => 'date-time',
- 'context' => array( 'view', 'edit' ),
- ),
- 'trial_end_date' => array(
- 'description' => __( "The subscription's trial date", 'woocommerce-subscriptions' ),
- 'type' => 'date-time',
- 'context' => array( 'view', 'edit' ),
- ),
- 'next_payment_date' => array(
- 'description' => __( "The subscription's next payment date.", 'woocommerce-subscriptions' ),
- 'type' => 'date-time',
- 'context' => array( 'view', 'edit' ),
- ),
- 'end_date' => array(
- 'description' => __( "The subscription's end date.", 'woocommerce-subscriptions' ),
- 'type' => 'date-time',
- 'context' => array( 'view', 'edit' ),
- ),
- 'resubscribed_from' => array(
- 'description' => __( "The subscription's original subscription ID if this is a resubscribed subscription.", 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view' ),
- 'readonly' => true,
- ),
- 'resubscribed_subscription' => array(
- 'description' => __( "The subscription's resubscribed subscription ID.", 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view' ),
- 'readonly' => true,
- ),
- 'date_completed_gmt' => array(
- 'description' => __( "The date the subscription's latest order was completed, in GMT.", 'woocommerce-subscriptions' ),
- 'type' => 'date-time',
- 'context' => array( 'view' ),
- 'readonly' => true,
- ),
- 'date_paid_gmt' => array(
- 'description' => __( "The date the subscription's latest order was paid, in GMT.", 'woocommerce-subscriptions' ),
- 'type' => 'date-time',
- 'context' => array( 'view' ),
- 'readonly' => true,
- ),
- 'removed_line_items' => array(
- 'description' => __( 'Removed line items data.', 'woocommerce-subscriptions' ),
- 'type' => 'array',
- 'context' => array( 'view', 'edit' ),
- 'items' => array(
- 'type' => 'object',
- 'properties' => array(
- 'id' => array(
- 'description' => __( 'Item ID.', 'woocommerce-subscriptions' ),
- 'type' => 'integer',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'name' => array(
- 'description' => __( 'Product name.', 'woocommerce-subscriptions' ),
- 'type' => 'mixed',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'sku' => array(
- 'description' => __( 'Product SKU.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'product_id' => array(
- 'description' => __( 'Product ID.', 'woocommerce-subscriptions' ),
- 'type' => 'mixed',
- 'context' => array( 'view', 'edit' ),
- ),
- 'variation_id' => array(
- 'description' => __( 'Variation ID, if applicable.', 'woocommerce-subscriptions' ),
- 'type' => 'integer',
- 'context' => array( 'view', 'edit' ),
- ),
- 'quantity' => array(
- 'description' => __( 'Quantity ordered.', 'woocommerce-subscriptions' ),
- 'type' => 'integer',
- 'context' => array( 'view', 'edit' ),
- ),
- 'tax_class' => array(
- 'description' => __( 'Tax class of product.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'price' => array(
- 'description' => __( 'Product price.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'subtotal' => array(
- 'description' => __( 'Line subtotal (before discounts).', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- ),
- 'subtotal_tax' => array(
- 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- ),
- 'total' => array(
- 'description' => __( 'Line total (after discounts).', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- ),
- 'total_tax' => array(
- 'description' => __( 'Line total tax (after discounts).', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- ),
- 'taxes' => array(
- 'description' => __( 'Line taxes.', 'woocommerce-subscriptions' ),
- 'type' => 'array',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- 'items' => array(
- 'type' => 'object',
- 'properties' => array(
- 'id' => array(
- 'description' => __( 'Tax rate ID.', 'woocommerce-subscriptions' ),
- 'type' => 'integer',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'total' => array(
- 'description' => __( 'Tax total.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'subtotal' => array(
- 'description' => __( 'Tax subtotal.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- ),
- ),
- ),
- 'meta' => array(
- 'description' => __( 'Removed line item meta data.', 'woocommerce-subscriptions' ),
- 'type' => 'array',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- 'items' => array(
- 'type' => 'object',
- 'properties' => array(
- 'key' => array(
- 'description' => __( 'Meta key.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'label' => array(
- 'description' => __( 'Meta label.', 'woocommerce-subscriptions' ),
- 'type' => 'string',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- 'value' => array(
- 'description' => __( 'Meta value.', 'woocommerce-subscriptions' ),
- 'type' => 'mixed',
- 'context' => array( 'view', 'edit' ),
- 'readonly' => true,
- ),
- ),
- ),
- ),
- ),
- ),
- ),
- );
-
- $schema['properties'] += $subscriptions_schema;
- return $schema;
- }
-
- /**
- * Deprecated functions
- */
-
- /**
- * Prepare subscription data for create.
- *
- * Now that we override WC_REST_Orders_V1_Controller::prepare_item_for_database() function,
- * we no longer need to prepare these args
- *
- * @since 2.1
- * @param stdClass $data
- * @param WP_REST_Request $request Request object.
- * @return stdClass
- * @deprecated 2.2
- */
- public function prepare_subscription_args( $data, $request ) {
- wcs_deprecated_function( __METHOD__, '2.2' );
-
- $data->billing_interval = $request['billing_interval'];
- $data->billing_period = $request['billing_period'];
-
- foreach ( array( 'start', 'trial_end', 'end', 'next_payment' ) as $date_type ) {
- if ( ! empty( $request[ $date_type . '_date' ] ) ) {
- $date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type . '_date';
- $data->{$date_type_key} = $request[ $date_type . '_date' ];
- }
- }
-
- $data->payment_details = ! empty( $request['payment_details'] ) ? $request['payment_details'] : '';
- $data->payment_method = ! empty( $request['payment_method'] ) ? $request['payment_method'] : '';
-
- return $data;
- }
-
- /**
- * Update or set the subscription schedule with the request data.
- *
- *
- * @since 2.1
- * @param WC_Subscription $subscription
- * @param array $data
- * @deprecated 2.2
- */
- public function update_schedule( $subscription, $data ) {
- wcs_deprecated_function( __METHOD__, '2.2', 'WC_REST_Subscriptions_Controller::prepare_item_for_database() now prepares the billing interval/period and dates' );
-
- if ( isset( $data['billing_interval'] ) ) {
- $subscription->set_billing_interval( absint( $data['billing_interval'] ) );
- }
-
- if ( ! empty( $data['billing_period'] ) ) {
- $subscription->set_billing_period( $data['billing_period'] );
- }
-
- try {
- $dates_to_update = array();
-
- foreach ( array( 'start', 'trial_end', 'end', 'next_payment' ) as $date_type ) {
- if ( isset( $data[ $date_type . '_date' ] ) ) {
- $date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type;
- $dates_to_update[ $date_type_key ] = $data[ $date_type . '_date' ];
- }
- }
-
- if ( ! empty( $dates_to_update ) ) {
- $subscription->update_dates( $dates_to_update );
- }
- } catch ( Exception $e ) {
- // translators: placeholder is an error message.
- throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_subscription_dates', sprintf( __( 'Updating subscription dates errored with message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
- }
- }
}
diff --git a/includes/api/legacy/class-wc-api-subscriptions.php b/includes/api/legacy/class-wc-api-subscriptions.php
index 02dc8df..b875b66 100644
--- a/includes/api/legacy/class-wc-api-subscriptions.php
+++ b/includes/api/legacy/class-wc-api-subscriptions.php
@@ -302,14 +302,13 @@ class WC_API_Subscriptions extends WC_API_Orders {
* @since 2.0
*/
public function update_payment_method( $subscription, $payment_details, $updating ) {
- global $wpdb;
-
$payment_gateways = WC()->payment_gateways->get_available_payment_gateways();
$payment_method = ( ! empty( $payment_details['method_id'] ) ) ? $payment_details['method_id'] : 'manual';
$payment_gateway = ( isset( $payment_gateways[ $payment_details['method_id'] ] ) ) ? $payment_gateways[ $payment_details['method_id'] ] : '';
try {
- $wpdb->query( 'START TRANSACTION' );
+ $transaction = new WCS_SQL_Transaction();
+ $transaction->start();
if ( $updating && ! array_key_exists( $payment_method, WCS_Change_Payment_Method_Admin::get_valid_payment_methods( $subscription ) ) ) {
throw new Exception( 'wcs_api_edit_subscription_error', __( 'Gateway does not support admin changing the payment method on a Subscription.', 'woocommerce-subscriptions' ) );
@@ -344,10 +343,10 @@ class WC_API_Subscriptions extends WC_API_Orders {
$subscription->set_payment_method( $payment_gateway, $payment_method_meta );
- $wpdb->query( 'COMMIT' );
+ $transaction->commit();
} catch ( Exception $e ) {
- $wpdb->query( 'ROLLBACK' );
+ $transaction->rollback();
// translators: 1$: gateway id, 2$: error message
throw new Exception( sprintf( __( 'Subscription payment method could not be set to %1$s and has been set to manual with error message: %2$s', 'woocommerce-subscriptions' ), ( ! empty( $payment_gateway->id ) ) ? $payment_gateway->id : 'manual', $e->getMessage() ) );
diff --git a/includes/api/legacy/class-wc-rest-subscriptions-controller.php b/includes/api/legacy/class-wc-rest-subscriptions-controller.php
index af0aac4..82fe7d5 100644
--- a/includes/api/legacy/class-wc-rest-subscriptions-controller.php
+++ b/includes/api/legacy/class-wc-rest-subscriptions-controller.php
@@ -166,7 +166,7 @@ class WC_REST_Subscriptions_Controller extends WC_REST_Orders_Controller {
* @return WP_Error|WP_REST_Response $response
*/
public function get_subscription_orders( $request ) {
- $id = (int) $request['id'];
+ $id = absint( $request['id'] );
if ( empty( $id ) || ! wcs_is_subscription( $id ) ) {
return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription id.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
diff --git a/includes/api/v1/class-wc-rest-subscription-notes-v1-controller.php b/includes/api/v1/class-wc-rest-subscription-notes-v1-controller.php
new file mode 100644
index 0000000..e85746f
--- /dev/null
+++ b/includes/api/v1/class-wc-rest-subscription-notes-v1-controller.php
@@ -0,0 +1,36 @@
+/notes endpoint.
+ *
+ * @author Prospress
+ * @since 2.1
+ */
+
+if ( ! defined( 'ABSPATH' ) ) {
+ exit;
+}
+/**
+ * REST API Subscription Notes controller class.
+ *
+ * @package WooCommerce_Subscriptions/API
+ * @extends WC_REST_Order_Notes_Controller
+ */
+class WC_REST_Subscription_Notes_V1_Controller extends WC_REST_Order_Notes_V1_Controller {
+
+ /**
+ * Route base.
+ *
+ * @var string
+ */
+ protected $rest_base = 'subscriptions/(?P[\d]+)/notes';
+
+ /**
+ * Post type.
+ *
+ * @var string
+ */
+ protected $post_type = 'shop_subscription';
+
+}
diff --git a/includes/api/v1/class-wc-rest-subscriptions-v1-controller.php b/includes/api/v1/class-wc-rest-subscriptions-v1-controller.php
new file mode 100644
index 0000000..ea99587
--- /dev/null
+++ b/includes/api/v1/class-wc-rest-subscriptions-v1-controller.php
@@ -0,0 +1,786 @@
+namespace, '/' . $this->rest_base . '/(?P[\d]+)/orders', array(
+ array(
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => array( $this, 'get_subscription_orders' ),
+ 'permission_callback' => array( $this, 'get_items_permissions_check' ),
+ 'args' => $this->get_collection_params(),
+ ),
+ 'schema' => array( $this, 'get_public_item_schema' ),
+ ) );
+
+ register_rest_route( $this->namespace, '/' . $this->rest_base . '/statuses', array(
+ array(
+ 'methods' => WP_REST_Server::READABLE,
+ 'callback' => array( $this, 'get_statuses' ),
+ 'permission_callback' => '__return_true',
+ ),
+ 'schema' => array( $this, 'get_public_item_schema' ),
+ ) );
+ }
+
+ /**
+ * Filter WC_REST_Orders_Controller::get_item response for subscription post types
+ *
+ * @since 2.1
+ * @param WP_REST_Response $response
+ * @param WP_POST $post
+ * @param WP_REST_Request $request
+ */
+ public function filter_get_subscription_response( $response, $post, $request ) {
+ $decimal_places = is_null( $request['dp'] ) ? wc_get_price_decimals() : absint( $request['dp'] );
+
+ if ( ! empty( $post->post_type ) && ! empty( $post->ID ) && 'shop_subscription' == $post->post_type ) {
+ $subscription = wcs_get_subscription( $post->ID );
+
+ $response->data['billing_period'] = $subscription->get_billing_period();
+ $response->data['billing_interval'] = $subscription->get_billing_interval();
+
+ // Send resubscribe data
+ $resubscribed_subscriptions = array_filter( $subscription->get_related_orders( 'ids', 'resubscribe' ), 'wcs_is_subscription' );
+ $response->data['resubscribed_from'] = strval( wcs_get_objects_property( $subscription, 'subscription_resubscribe' ) );
+ $response->data['resubscribed_subscription'] = strval( reset( $resubscribed_subscriptions ) ); // Subscriptions can only be resubscribed to once so return the first and only element.
+
+ foreach ( array( 'start', 'trial_end', 'next_payment', 'end' ) as $date_type ) {
+ $date = $subscription->get_date( $date_type );
+ $response->data[ $date_type . '_date' ] = ( ! empty( $date ) ) ? wc_rest_prepare_date_response( $date ) : '';
+ }
+
+ // v1 API includes some date types in site time, include those dates in UTC as well.
+ $response->data['date_completed_gmt'] = wc_rest_prepare_date_response( $subscription->get_date_completed() );
+ $response->data['date_paid_gmt'] = wc_rest_prepare_date_response( $subscription->get_date_paid() );
+ $response->data['removed_line_items'] = array();
+
+ // Include removed line items of a subscription
+ foreach ( $subscription->get_items( 'line_item_removed' ) as $item_id => $item ) {
+ $product = $item->get_product();
+ $product_id = 0;
+ $variation_id = 0;
+ $product_sku = null;
+
+ // Check if the product exists.
+ if ( is_object( $product ) ) {
+ $product_id = $item->get_product_id();
+ $variation_id = $item->get_variation_id();
+ $product_sku = $product->get_sku();
+ }
+
+ $item_meta = array();
+
+ $hideprefix = 'true' === $request['all_item_meta'] ? null : '_';
+
+ foreach ( $item->get_formatted_meta_data( $hideprefix, true ) as $meta_key => $formatted_meta ) {
+ $item_meta[] = array(
+ 'key' => $formatted_meta->key,
+ 'label' => $formatted_meta->display_key,
+ 'value' => wc_clean( $formatted_meta->display_value ),
+ );
+ }
+
+ $line_item = array(
+ 'id' => $item_id,
+ 'name' => $item['name'],
+ 'sku' => $product_sku,
+ 'product_id' => (int) $product_id,
+ 'variation_id' => (int) $variation_id,
+ 'quantity' => wc_stock_amount( $item['qty'] ),
+ 'tax_class' => ! empty( $item['tax_class'] ) ? $item['tax_class'] : '',
+ 'price' => wc_format_decimal( $subscription->get_item_total( $item, false, false ), $decimal_places ),
+ 'subtotal' => wc_format_decimal( $subscription->get_line_subtotal( $item, false, false ), $decimal_places ),
+ 'subtotal_tax' => wc_format_decimal( $item['line_subtotal_tax'], $decimal_places ),
+ 'total' => wc_format_decimal( $subscription->get_line_total( $item, false, false ), $decimal_places ),
+ 'total_tax' => wc_format_decimal( $item['line_tax'], $decimal_places ),
+ 'taxes' => array(),
+ 'meta' => $item_meta,
+ );
+
+ $item_line_taxes = maybe_unserialize( $item['line_tax_data'] );
+ if ( isset( $item_line_taxes['total'] ) ) {
+ $line_tax = array();
+
+ foreach ( $item_line_taxes['total'] as $tax_rate_id => $tax ) {
+ $line_tax[ $tax_rate_id ] = array(
+ 'id' => $tax_rate_id,
+ 'total' => $tax,
+ 'subtotal' => '',
+ );
+ }
+
+ foreach ( $item_line_taxes['subtotal'] as $tax_rate_id => $tax ) {
+ $line_tax[ $tax_rate_id ]['subtotal'] = $tax;
+ }
+
+ $line_item['taxes'] = array_values( $line_tax );
+ }
+
+ $response->data['removed_line_items'][] = $line_item;
+ }
+ }
+
+ return $response;
+ }
+
+ /**
+ * Sets the order_total value on the subscription after WC_REST_Orders_Controller::create_order
+ * calls calculate_totals(). This allows store admins to create a recurring payment via the api
+ * without needing to attach a product to the subscription.
+ *
+ * @since 2.1
+ * @param WP_REST_Request $request
+ */
+ protected function create_order( $request ) {
+ try {
+ if ( ! is_null( $request['customer_id'] ) && 0 !== $request['customer_id'] && false === get_user_by( 'id', $request['customer_id'] ) ) {
+ throw new WC_REST_Exception( 'woocommerce_rest_invalid_customer_id', __( 'Customer ID is invalid.', 'woocommerce-subscriptions' ), 400 );
+ }
+
+ // If the start date is not set in the request, set its default to now
+ if ( ! isset( $request['start_date'] ) ) {
+ $request['start_date'] = gmdate( 'Y-m-d H:i:s' );
+ }
+
+ // prepare all subscription data from the request
+ $subscription = $this->prepare_item_for_database( $request );
+ $subscription->set_created_via( 'rest-api' );
+ $subscription->set_prices_include_tax( 'yes' === get_option( 'woocommerce_prices_include_tax' ) );
+ $subscription->calculate_totals();
+
+ // allow the order total to be overriden (i.e. if you want to have a subscription with no order items but a flat $10.00 recurring payment )
+ if ( isset( $request['order_total'] ) ) {
+ $subscription->set_total( wc_format_decimal( $request['order_total'], get_option( 'woocommerce_price_num_decimals' ) ) );
+ }
+
+ // Store the post meta on the subscription after it's saved, this is to avoid compat. issue with the filters in WC_Subscription::set_payment_method_meta() expecting the $subscription to have an ID (therefore it needs to be called after the WC_Subscription has been saved)
+ $payment_data = ( ! empty( $request['payment_details'] ) ) ? $request['payment_details'] : array();
+ if ( empty( $payment_data['payment_details']['method_id'] ) && ! empty( $request['payment_method'] ) ) {
+ $payment_data['method_id'] = $request['payment_method'];
+ }
+
+ $this->update_payment_method( $subscription, $payment_data );
+
+ $subscription->save();
+
+ // Handle set paid.
+ if ( true === $request['set_paid'] ) {
+ $subscription->payment_complete( $request['transaction_id'] );
+ }
+
+ do_action( 'wcs_api_subscription_created', $subscription->get_id() );
+
+ return $subscription->get_id();
+ } catch ( WC_Data_Exception $e ) {
+ return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
+ } catch ( WC_REST_Exception $e ) {
+ return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
+ }
+ }
+
+ /**
+ * Overrides WC_REST_Orders_Controller::update_order to update subscription specific meta
+ * calls parent::update_order to update the rest.
+ *
+ * @since 2.1
+ * @param WP_REST_Request $request
+ * @param WP_POST $post
+ */
+ protected function update_order( $request ) {
+ try {
+ $subscription = $this->prepare_item_for_database( $request );
+
+ // If any line items have changed, recalculate subscription totals.
+ if ( isset( $request['line_items'] ) || isset( $request['shipping_lines'] ) || isset( $request['fee_lines'] ) || isset( $request['coupon_lines'] ) ) {
+ $subscription->calculate_totals();
+ }
+
+ // allow the order total to be overriden (i.e. if you want to have a subscription with no order items but a flat $10.00 recurring payment )
+ if ( isset( $request['order_total'] ) ) {
+ $subscription->set_total( wc_format_decimal( $request['order_total'], get_option( 'woocommerce_price_num_decimals' ) ) );
+ }
+
+ $subscription->save();
+
+ // Update the post meta on the subscription after it's saved, this is to avoid compat. issue with the filters in WC_Subscription::set_payment_method_meta() expecting the $subscription to have an ID (therefore it needs to be called after the WC_Subscription has been saved)
+ $payment_data = ( ! empty( $request['payment_details'] ) ) ? $request['payment_details'] : array();
+ $existing_payment_method_id = $subscription->get_payment_method();
+
+ if ( empty( $payment_data['method_id'] ) && isset( $request['payment_method'] ) ) {
+ $payment_data['method_id'] = $request['payment_method'];
+
+ } elseif ( ! empty( $existing_payment_method_id ) ) {
+ $payment_data['method_id'] = $existing_payment_method_id;
+ }
+
+ if ( isset( $payment_data['method_id'] ) ) {
+ $this->update_payment_method( $subscription, $payment_data, true );
+ }
+
+ // Handle set paid.
+ if ( $subscription->needs_payment() && true === $request['set_paid'] ) {
+ $subscription->payment_complete();
+ }
+
+ do_action( 'wcs_api_subscription_updated', $subscription->get_id() );
+
+ return $subscription->get_id();
+ } catch ( WC_Data_Exception $e ) {
+ return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() );
+ } catch ( WC_REST_Exception $e ) {
+ return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
+ }
+ }
+
+ /**
+ * Get subscription orders
+ *
+ * @since 2.1
+ * @param WP_REST_Request $request
+ * @return WP_Error|WP_REST_Response $response
+ */
+ public function get_subscription_orders( $request ) {
+ $id = (int) $request['id'];
+
+ if ( empty( $id ) || ! wcs_is_subscription( $id ) ) {
+ return new WP_Error( 'woocommerce_rest_invalid_shop_subscription_id', __( 'Invalid subscription id.', 'woocommerce-subscriptions' ), array( 'status' => 404 ) );
+ }
+
+ $this->post_type = 'shop_order';
+ $subscription = wcs_get_subscription( $id );
+ $subscription_orders = $subscription->get_related_orders();
+
+ $orders = array();
+
+ foreach ( $subscription_orders as $order_id ) {
+ $post = get_post( $order_id );
+
+ // Validate that the order can be loaded before trying to generate a response object for it.
+ $order = wc_get_order( $order_id );
+
+ if ( ! $order || ! wc_rest_check_post_permissions( $this->post_type, 'read', $post->ID ) ) {
+ continue;
+ }
+
+ $response = $this->prepare_item_for_response( $post, $request );
+
+ foreach ( array( 'parent', 'renewal', 'switch' ) as $order_type ) {
+ if ( wcs_order_contains_subscription( $order_id, $order_type ) ) {
+ $response->data['order_type'] = $order_type . '_order';
+ break;
+ }
+ }
+
+ $orders[] = $this->prepare_response_for_collection( $response );
+ }
+
+ $response = rest_ensure_response( $orders );
+ $response->header( 'X-WP-Total', count( $orders ) );
+ $response->header( 'X-WP-TotalPages', 1 );
+
+ return apply_filters( 'wcs_rest_subscription_orders_response', $response, $request );
+ }
+
+ /**
+ * Get subscription statuses
+ *
+ * @since 2.1
+ */
+ public function get_statuses() {
+ return rest_ensure_response( wcs_get_subscription_statuses() );
+ }
+
+ /**
+ * Overrides WC_REST_Orders_Controller::get_order_statuses() so that subscription statuses are
+ * validated correctly in WC_REST_Orders_Controller::get_collection_params()
+ *
+ * @since 2.1
+ */
+ protected function get_order_statuses() {
+ $subscription_statuses = array();
+
+ foreach ( array_keys( wcs_get_subscription_statuses() ) as $status ) {
+ $subscription_statuses[] = str_replace( 'wc-', '', $status );
+ }
+ return $subscription_statuses;
+ }
+
+ /**
+ * Validate and update payment method on a subscription
+ *
+ * @since 2.1
+ * @param WC_Subscription $subscription
+ * @param array $data
+ * @param bool $updating
+ */
+ public function update_payment_method( $subscription, $data, $updating = false ) {
+ $payment_method = ( ! empty( $data['method_id'] ) ) ? $data['method_id'] : '';
+
+ try {
+ if ( $updating && ! array_key_exists( $payment_method, WCS_Change_Payment_Method_Admin::get_valid_payment_methods( $subscription ) ) ) {
+ throw new Exception( __( 'Gateway does not support admin changing the payment method on a Subscription.', 'woocommerce-subscriptions' ) );
+ }
+
+ $payment_method_meta = apply_filters( 'woocommerce_subscription_payment_meta', array(), $subscription );
+
+ // Reload the subscription to update the meta values.
+ // In particular, the update_post_meta() called while _stripe_card_id is updated to _stripe_source_id
+ $subscription = wcs_get_subscription( $subscription->get_id() );
+
+ if ( isset( $payment_method_meta[ $payment_method ] ) ) {
+ $payment_method_meta = $payment_method_meta[ $payment_method ];
+
+ if ( ! empty( $payment_method_meta ) ) {
+
+ foreach ( $payment_method_meta as $meta_table => &$meta ) {
+ if ( ! is_array( $meta ) ) {
+ continue;
+ }
+
+ foreach ( $meta as $meta_key => &$meta_data ) {
+
+ if ( isset( $data[ $meta_table ][ $meta_key ] ) ) {
+ $meta_data['value'] = $data[ $meta_table ][ $meta_key ];
+ }
+ }
+ }
+ }
+ }
+
+ $subscription->set_payment_method( $payment_method, $payment_method_meta );
+
+ // Save the subscription to reflect the new values
+ $subscription->save();
+
+ } catch ( Exception $e ) {
+ $subscription->set_payment_method();
+ $subscription->save();
+ // translators: 1$: gateway id, 2$: error message
+ throw new WC_REST_Exception( 'woocommerce_rest_invalid_payment_data', sprintf( __( 'Subscription payment method could not be set to %1$s with error message: %2$s', 'woocommerce-subscriptions' ), $payment_method, $e->getMessage() ), 400 );
+ }
+ }
+
+ /**
+ * Prepare a single subscription for create.
+ *
+ * @param WP_REST_Request $request Request object.
+ * @return WP_Error|WC_Subscription $data Object.
+ */
+ protected function prepare_item_for_database( $request ) {
+ $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
+ $subscription = new WC_Subscription( $id );
+ $schema = $this->get_item_schema();
+ $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
+
+ $dates_to_update = array();
+
+ // Handle all writable props
+ foreach ( $data_keys as $key ) {
+ $value = $request[ $key ];
+
+ if ( ! is_null( $value ) ) {
+ switch ( $key ) {
+ case 'billing':
+ case 'shipping':
+ $this->update_address( $subscription, $value, $key );
+ break;
+ case 'line_items':
+ case 'shipping_lines':
+ case 'fee_lines':
+ case 'coupon_lines':
+ if ( is_array( $value ) ) {
+ foreach ( $value as $item ) {
+ if ( is_array( $item ) ) {
+ if ( $this->item_is_null( $item ) || ( isset( $item['quantity'] ) && 0 === $item['quantity'] ) ) {
+ $subscription->remove_item( $item['id'] );
+ } else {
+ $this->set_item( $subscription, $key, $item );
+ }
+ }
+ }
+ }
+ break;
+ case 'transition_status':
+ $subscription->update_status( $value );
+ break;
+ case 'start_date':
+ case 'trial_end_date':
+ case 'next_payment_date':
+ case 'end_date':
+ $dates_to_update[ $key ] = $value;
+ break;
+ default:
+ if ( is_callable( array( $subscription, "set_{$key}" ) ) ) {
+ $subscription->{"set_{$key}"}( $value );
+ }
+ break;
+ }
+ }
+ }
+
+ $subscription->save();
+
+ try {
+ if ( ! empty( $dates_to_update ) ) {
+ $subscription->update_dates( $dates_to_update );
+ }
+ } catch ( Exception $e ) {
+ // translators: placeholder is an error message.
+ throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_subscription_dates', sprintf( __( 'Updating subscription dates errored with message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
+ }
+
+ /**
+ * Filter the data for the insert.
+ *
+ * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being
+ * prepared for the response.
+ *
+ * @param WC_Subscription $subscription The subscription object.
+ * @param WP_REST_Request $request Request object.
+ */
+ return apply_filters( "woocommerce_rest_pre_insert_{$this->post_type}", $subscription, $request );
+ }
+
+ /**
+ * Adds additional item schema information for subscription requests
+ *
+ * @since 2.1
+ */
+ public function get_item_schema() {
+ $schema = parent::get_item_schema();
+
+ $subscriptions_schema = array(
+ 'transition_status' => array(
+ 'description' => __( 'The status to transition the subscription to. Unlike the "status" param, this will calculate and update the subscription dates.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'enum' => $this->get_order_statuses(),
+ 'context' => array( 'edit' ),
+ ),
+ 'billing_interval' => array(
+ 'description' => __( 'The number of billing periods between subscription renewals.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'billing_period' => array(
+ 'description' => __( 'Billing period for the subscription.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'enum' => array_keys( wcs_get_subscription_period_strings() ),
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'payment_details' => array(
+ 'description' => __( 'Subscription payment details.', 'woocommerce-subscriptions' ),
+ 'type' => 'object',
+ 'context' => array( 'edit' ),
+ 'properties' => array(
+ 'method_id' => array(
+ 'description' => __( 'Payment gateway ID.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'edit' ),
+ ),
+ ),
+ ),
+ 'start_date' => array(
+ 'description' => __( "The subscription's start date.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'trial_end_date' => array(
+ 'description' => __( "The subscription's trial date", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'next_payment_date' => array(
+ 'description' => __( "The subscription's next payment date.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'end_date' => array(
+ 'description' => __( "The subscription's end date.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'resubscribed_from' => array(
+ 'description' => __( "The subscription's original subscription ID if this is a resubscribed subscription.", 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'resubscribed_subscription' => array(
+ 'description' => __( "The subscription's resubscribed subscription ID.", 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'date_completed_gmt' => array(
+ 'description' => __( "The date the subscription's latest order was completed, in GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'date_paid_gmt' => array(
+ 'description' => __( "The date the subscription's latest order was paid, in GMT.", 'woocommerce-subscriptions' ),
+ 'type' => 'date-time',
+ 'context' => array( 'view' ),
+ 'readonly' => true,
+ ),
+ 'removed_line_items' => array(
+ 'description' => __( 'Removed line items data.', 'woocommerce-subscriptions' ),
+ 'type' => 'array',
+ 'context' => array( 'view', 'edit' ),
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'id' => array(
+ 'description' => __( 'Item ID.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'name' => array(
+ 'description' => __( 'Product name.', 'woocommerce-subscriptions' ),
+ 'type' => 'mixed',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'sku' => array(
+ 'description' => __( 'Product SKU.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'product_id' => array(
+ 'description' => __( 'Product ID.', 'woocommerce-subscriptions' ),
+ 'type' => 'mixed',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'variation_id' => array(
+ 'description' => __( 'Variation ID, if applicable.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'quantity' => array(
+ 'description' => __( 'Quantity ordered.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'tax_class' => array(
+ 'description' => __( 'Tax class of product.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'price' => array(
+ 'description' => __( 'Product price.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'subtotal' => array(
+ 'description' => __( 'Line subtotal (before discounts).', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'subtotal_tax' => array(
+ 'description' => __( 'Line subtotal tax (before discounts).', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'total' => array(
+ 'description' => __( 'Line total (after discounts).', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'total_tax' => array(
+ 'description' => __( 'Line total tax (after discounts).', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ ),
+ 'taxes' => array(
+ 'description' => __( 'Line taxes.', 'woocommerce-subscriptions' ),
+ 'type' => 'array',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'id' => array(
+ 'description' => __( 'Tax rate ID.', 'woocommerce-subscriptions' ),
+ 'type' => 'integer',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'total' => array(
+ 'description' => __( 'Tax total.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'subtotal' => array(
+ 'description' => __( 'Tax subtotal.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ ),
+ ),
+ ),
+ 'meta' => array(
+ 'description' => __( 'Removed line item meta data.', 'woocommerce-subscriptions' ),
+ 'type' => 'array',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'key' => array(
+ 'description' => __( 'Meta key.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'label' => array(
+ 'description' => __( 'Meta label.', 'woocommerce-subscriptions' ),
+ 'type' => 'string',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ 'value' => array(
+ 'description' => __( 'Meta value.', 'woocommerce-subscriptions' ),
+ 'type' => 'mixed',
+ 'context' => array( 'view', 'edit' ),
+ 'readonly' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $schema['properties'] += $subscriptions_schema;
+ return $schema;
+ }
+
+ /**
+ * Deprecated functions
+ */
+
+ /**
+ * Prepare subscription data for create.
+ *
+ * Now that we override WC_REST_Orders_V1_Controller::prepare_item_for_database() function,
+ * we no longer need to prepare these args
+ *
+ * @since 2.1
+ * @param stdClass $data
+ * @param WP_REST_Request $request Request object.
+ * @return stdClass
+ * @deprecated 2.2
+ */
+ public function prepare_subscription_args( $data, $request ) {
+ wcs_deprecated_function( __METHOD__, '2.2' );
+
+ $data->billing_interval = $request['billing_interval'];
+ $data->billing_period = $request['billing_period'];
+
+ foreach ( array( 'start', 'trial_end', 'end', 'next_payment' ) as $date_type ) {
+ if ( ! empty( $request[ $date_type . '_date' ] ) ) {
+ $date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type . '_date';
+ $data->{$date_type_key} = $request[ $date_type . '_date' ];
+ }
+ }
+
+ $data->payment_details = ! empty( $request['payment_details'] ) ? $request['payment_details'] : '';
+ $data->payment_method = ! empty( $request['payment_method'] ) ? $request['payment_method'] : '';
+
+ return $data;
+ }
+
+ /**
+ * Update or set the subscription schedule with the request data.
+ *
+ *
+ * @since 2.1
+ * @param WC_Subscription $subscription
+ * @param array $data
+ * @deprecated 2.2
+ */
+ public function update_schedule( $subscription, $data ) {
+ wcs_deprecated_function( __METHOD__, '2.2', 'WC_REST_Subscriptions_Controller::prepare_item_for_database() now prepares the billing interval/period and dates' );
+
+ if ( isset( $data['billing_interval'] ) ) {
+ $subscription->set_billing_interval( absint( $data['billing_interval'] ) );
+ }
+
+ if ( ! empty( $data['billing_period'] ) ) {
+ $subscription->set_billing_period( $data['billing_period'] );
+ }
+
+ try {
+ $dates_to_update = array();
+
+ foreach ( array( 'start', 'trial_end', 'end', 'next_payment' ) as $date_type ) {
+ if ( isset( $data[ $date_type . '_date' ] ) ) {
+ $date_type_key = ( 'start' === $date_type ) ? 'date_created' : $date_type;
+ $dates_to_update[ $date_type_key ] = $data[ $date_type . '_date' ];
+ }
+ }
+
+ if ( ! empty( $dates_to_update ) ) {
+ $subscription->update_dates( $dates_to_update );
+ }
+ } catch ( Exception $e ) {
+ // translators: placeholder is an error message.
+ throw new WC_REST_Exception( 'woocommerce_rest_cannot_update_subscription_dates', sprintf( __( 'Updating subscription dates errored with message: %s', 'woocommerce-subscriptions' ), $e->getMessage() ), 400 );
+ }
+ }
+}
diff --git a/includes/class-wc-subscriptions-plugin.php b/includes/class-wc-subscriptions-plugin.php
new file mode 100644
index 0000000..f77c24e
--- /dev/null
+++ b/includes/class-wc-subscriptions-plugin.php
@@ -0,0 +1,223 @@
+ tags, 3: Subscriptions version.
+ $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' ), '', ' ', $this->get_plugin_version() ) );
+ $notice->set_actions(
+ array(
+ array(
+ 'name' => __( 'Installed Plugins', 'woocommerce-subscriptions' ),
+ 'url' => admin_url( 'plugins.php' ),
+ ),
+ )
+ );
+
+ $notice->display();
+ } else {
+ WCS_Early_Renewal_Manager::init();
+
+ require_once $this->get_plugin_directory( 'includes/early-renewal/wcs-early-renewal-functions.php' );
+
+ if ( WCS_Early_Renewal_Manager::is_early_renewal_enabled() ) {
+ new WCS_Cart_Early_Renewal();
+ }
+ }
+ }
+
+ /**
+ * Gets the plugin's directory url.
+ *
+ * @since 4.0.0
+ * @param string $path Optional. The path to append.
+ * @return string
+ */
+ public function get_plugin_directory_url( $path = '' ) {
+ return plugin_dir_url( WC_Subscriptions::$plugin_file ) . $path;
+ }
+
+ /**
+ * Gets the plugin's directory.
+ *
+ * @since 4.0.0
+ * @param string $path Optional. The path to append.
+ * @return string
+ */
+ public function get_plugin_directory( $path = '' ) {
+ return plugin_dir_path( WC_Subscriptions::$plugin_file ) . $path;
+ }
+
+ /**
+ * Gets the activation transient name.
+ *
+ * @since 4.0.0
+ * @return string The transient name used to record when the plugin was activated.
+ */
+ public function get_activation_transient() {
+ return WC_Subscriptions::$activation_transient;
+ }
+
+ /**
+ * Gets the product type name.
+ *
+ * @since 4.0.0
+ * @return string The product type name.
+ */
+ public function get_product_type_name() {
+ return WC_Subscriptions::$name;
+ }
+
+ /**
+ * Gets the plugin's version
+ *
+ * @since 4.0.0
+ * @return string The plugin version.
+ */
+ public function get_plugin_version() {
+ return WC_Subscriptions::$version;
+ }
+
+ /**
+ * Gets the plugin file name
+ *
+ * @since 4.0.0
+ * @return string The plugin file
+ */
+ public function get_plugin_file() {
+ return WC_Subscriptions::$plugin_file;
+ }
+
+ /**
+ * Gets the Payment Gateways handler class
+ *
+ * @since 4.0.0
+ * @return string
+ */
+ public function get_gateways_handler_class() {
+ return 'WC_Subscriptions_Payment_Gateways';
+ }
+
+
+ /**
+ * Adds welcome message after activating the plugin
+ */
+ public function maybe_show_welcome_message() {
+ $plugin_has_just_been_activated = (bool) get_transient( WC_Subscriptions_Core_Plugin::instance()->get_activation_transient() );
+
+ // Maybe add the admin notice.
+ if ( $plugin_has_just_been_activated ) {
+
+ $woocommerce_plugin_dir_file = WC_Subscriptions_Admin::get_woocommerce_plugin_dir_file();
+
+ // check if subscription products exist in the store.
+ $subscription_product = wc_get_products(
+ array(
+ 'type' => array( 'subscription', 'variable-subscription' ),
+ 'limit' => 1,
+ 'return' => 'ids',
+ )
+ );
+
+ if ( ! empty( $woocommerce_plugin_dir_file ) && 0 === count( $subscription_product ) ) {
+
+ wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', $woocommerce_plugin_dir_file ), [], WC_Subscriptions_Core_Plugin::instance()->get_plugin_version() );
+
+ if ( ! isset( $_GET['page'] ) || 'wcs-about' !== $_GET['page'] ) {
+ add_action( 'admin_notices', array( $this, 'admin_installed_notice' ) );
+ }
+ }
+ delete_transient( WC_Subscriptions_Core_Plugin::instance()->get_activation_transient() );
+ }
+ }
+
+ /**
+ * Outputs a welcome message. Called when the Subscriptions extension is activated.
+ *
+ * @since 1.0
+ */
+ public function admin_installed_notice() {
+ ?>
+
+
+
+ tags, $3-$4: opening and closing tags.
+ __(
+ '%1$sWooCommerce Subscriptions Installed%2$s – %3$sYou\'re ready to start selling subscriptions!%4$s',
+ 'woocommerce-subscriptions'
+ ),
+ '',
+ ' ',
+ '',
+ ' '
+ ),
+ [
+ 'strong' => true,
+ 'em' => true,
+ ]
+ );
+ ?>
+
+
+
+
+
+
+
+
+
+
+ register_routes();
}
}
+ /**
+ * Register classes which override base endpoints.
+ *
+ * @since 3.1.0
+ */
+ public static function register_route_overrides() {
+ if ( ! self::is_wp_compatible() ) {
+ return;
+ }
+
+ WC_REST_Subscription_System_Status_Manager::init();
+ }
+
+ /**
+ * Determines if a WP version compatible with REST API requests.
+ *
+ * @since 3.1.0
+ * @return boolean
+ */
+ protected static function is_wp_compatible() {
+ global $wp_version;
+ return version_compare( $wp_version, '4.4', '>=' );
+ }
}
diff --git a/includes/class-wcs-autoloader.php b/includes/class-wcs-autoloader.php
index 01097b1..940921b 100644
--- a/includes/class-wcs-autoloader.php
+++ b/includes/class-wcs-autoloader.php
@@ -1,23 +1,14 @@
base_path = untrailingslashit( $base_path );
- }
+ private $classes = array(
+ 'wc_subscriptions_plugin' => true,
+ 'wc_subscriptions_switcher' => true,
+ 'wcs_cart_switch' => true,
+ 'wcs_switch_totals_calculator' => true,
+ 'wcs_switch_cart_item' => true,
+ 'wcs_add_cart_item' => true,
+ 'wc_order_item_pending_switch' => true,
+ 'wcs_manual_renewal_manager' => true,
+ 'wcs_customer_suspension_manager' => true,
+ 'wcs_drip_downloads_manager' => true,
+ 'wcs_zero_initial_payment_checkout_manager' => true,
+ 'wcs_meta_box_payment_retries' => true,
+ 'wcs_limited_recurring_coupon_manager' => true,
+ 'wcs_call_to_action_button_text_manager' => true,
+ 'wcs_subscriber_role_manager' => true,
+ 'wc_subscriptions_payment_gateways' => true,
+ 'wcs_api' => true,
+ 'wcs_webhooks' => true,
+ 'wcs_auth' => true,
+ 'wcs_upgrade_notice_manager' => true,
+ );
/**
- * Destructor.
+ * The substrings of the classes that the Subscriptions plugin has ownership of.
+ *
+ * @var array
*/
- public function __destruct() {
- $this->unregister();
- }
+ private $class_substrings = array(
+ 'wc_reports',
+ 'report',
+ 'retry',
+ 'early_renewal',
+ 'rest_subscription',
+ 'wc_api_subscriptions',
+ );
/**
- * Register the autoloader.
+ * Gets the class's base path.
*
- * @author Jeremy Pry
- */
- public function register() {
- spl_autoload_register( array( $this, 'autoload' ) );
- }
-
- /**
- * Unregister the autoloader.
- */
- public function unregister() {
- spl_autoload_unregister( array( $this, 'autoload' ) );
- }
-
- /**
- * Autoload a class.
+ * If the a class is one the plugin is responsible for, we return the plugin's path. Otherwise we let the library handle it.
*
- * @author Jeremy Pry
- *
- * @param string $class The class name to autoload.
+ * @since 4.0.0
+ * @return string
*/
- public function autoload( $class ) {
- $class = strtolower( $class );
-
- if ( ! $this->should_autoload( $class ) ) {
- return;
+ public function get_class_base_path( $class ) {
+ if ( $this->is_plugin_class( $class ) ) {
+ return dirname( WC_Subscriptions::$plugin_file );
}
- $full_path = $this->base_path . $this->get_relative_class_path( $class ) . $this->get_file_name( $class );
- if ( is_readable( $full_path ) ) {
- require_once( $full_path );
- }
- }
-
- /**
- * Determine whether we should autoload a given class.
- *
- * @author Jeremy Pry
- *
- * @param string $class The class name.
- *
- * @return bool
- */
- protected function should_autoload( $class ) {
- // We're not using namespaces, so if the class has namespace separators, skip.
- if ( false !== strpos( $class, '\\' ) ) {
- return false;
- }
-
- // There are some legacy classes without WCS or Subscription in the name.
- static $legacy = array(
- 'wc_order_item_pending_switch' => 1,
- 'wc_report_retention_rate' => 1,
- 'wc_report_upcoming_recurring_revenue' => 1,
- );
- if ( isset( $legacy[ $class ] ) ) {
- return true;
- }
-
- return false !== strpos( $class, 'wcs_' ) || 0 === strpos( $class, 'wc_subscription' ) || ( false !== strpos( $class, 'wc_' ) && false !== strpos( $class, 'subscription' ) );
- }
-
- /**
- * Convert the class name into an appropriate file name.
- *
- * @author Jeremy Pry
- *
- * @param string $class The class name.
- *
- * @return string The file name.
- */
- protected function get_file_name( $class ) {
- $file_prefix = 'class-';
-
- if ( $this->is_class_abstract( $class ) ) {
- $file_prefix = 'abstract-';
- } elseif ( $this->is_class_interface( $class ) ) {
- $file_prefix = 'interface-';
- }
-
- return $file_prefix . str_replace( '_', '-', $class ) . '.php';
- }
-
- /**
- * Determine if the class is one of our abstract classes.
- *
- * @author Jeremy Pry
- *
- * @param string $class The class name.
- *
- * @return bool
- */
- protected function is_class_abstract( $class ) {
- static $abstracts = array(
- 'wcs_background_repairer' => true,
- 'wcs_background_updater' => true,
- 'wcs_background_upgrader' => true,
- 'wcs_cache_manager' => true,
- 'wcs_debug_tool' => true,
- 'wcs_debug_tool_cache_updater' => true,
- 'wcs_dynamic_hook_deprecator' => true,
- 'wcs_hook_deprecator' => true,
- 'wcs_retry_store' => true,
- 'wcs_scheduler' => true,
- 'wcs_sv_api_base' => true,
- 'wcs_customer_store' => true,
- 'wcs_related_order_store' => true,
- 'wcs_migrator' => true,
- 'wcs_table_maker' => true,
- );
-
- return isset( $abstracts[ $class ] );
- }
-
- /**
- * Determine if the class is one of our class interfaces.
- *
- * @param string $class The class name.
-
- * @return bool
- */
- protected function is_class_interface( $class ) {
- static $interfaces = array(
- 'wcs_cache_updater' => true,
- );
-
- return isset( $interfaces[ $class ] );
- }
-
- /**
- * Determine if the class is one of our data stores.
- *
- * @param string $class The class name.
-
- * @return bool
- */
- protected function is_class_data_store( $class ) {
- static $data_stores = array(
- 'wcs_related_order_store_cached_cpt' => true,
- 'wcs_related_order_store_cpt' => true,
- 'wcs_customer_store_cached_cpt' => true,
- 'wcs_customer_store_cpt' => true,
- 'wcs_product_variable_data_store_cpt' => true,
- 'wcs_subscription_data_store_cpt' => true,
- );
-
- return isset( $data_stores[ $class ] );
+ return parent::get_class_base_path( $class );
}
/**
* Get the relative path for the class location.
*
- * This handles all of the special class locations and exceptions.
- *
- * @author Jeremy Pry
- *
* @param string $class The class name.
- *
* @return string The relative path (from the plugin root) to the class file.
*/
protected function get_relative_class_path( $class ) {
- $path = '/includes';
- $is_admin = ( false !== strpos( $class, 'admin' ) );
+ if ( ! $this->is_plugin_class( $class ) ) {
+ return parent::get_relative_class_path( $class );
+ }
- if ( $this->is_class_abstract( $class ) ) {
- if ( 'wcs_sv_api_base' === $class ) {
- $path .= '/gateways/paypal/includes/abstracts';
- } else {
- $path .= '/abstracts';
- }
- } elseif ( $this->is_class_interface( $class ) ) {
- $path .= '/interfaces';
- } elseif ( false !== strpos( $class, 'paypal' ) ) {
- $path .= '/gateways/paypal';
- if ( 'wcs_paypal' === $class ) {
- $path .= '';
- } elseif ( 'wcs_repair_suspended_paypal_subscriptions' === $class ) {
- // Deliberately avoid concatenation for this class, using the base path.
- $path = '/includes/upgrades';
- } elseif ( $is_admin ) {
- $path .= '/includes/admin';
- } elseif ( 'wc_paypal_standard_subscriptions' === $class ) {
- $path .= '/includes/deprecated';
- } else {
- $path .= '/includes';
- }
- } elseif ( 0 === strpos( $class, 'wcs_retry' ) && 'wcs_retry_manager' !== $class ) {
- $path .= '/payment-retry';
- } elseif ( $is_admin && 'wcs_change_payment_method_admin' !== $class ) {
- $path .= '/admin';
- } elseif ( false !== strpos( $class, 'meta_box' ) ) {
- $path .= '/admin/meta-boxes';
+ $path = '/includes';
+
+ if ( stripos( $class, 'switch' ) !== false || 'wcs_add_cart_item' === $class ) {
+ $path .= '/switching';
} elseif ( false !== strpos( $class, 'wc_report' ) ) {
$path .= '/admin/reports/deprecated';
- } elseif ( false !== strpos( $class, 'report' ) ) {
+ } elseif ( false !== strpos( $class, 'wcs_report' ) ) {
$path .= '/admin/reports';
- } elseif ( false !== strpos( $class, 'debug_tool' ) ) {
- $path .= '/admin/debug-tools';
- } elseif ( false !== strpos( $class, 'rest' ) ) {
- $path .= $this->legacy_api ? '/api/legacy' : '/api';
- } elseif ( false !== strpos( $class, 'api' ) && 'wcs_api' !== $class ) {
- $path .= '/api/legacy';
- } elseif ( $this->is_class_data_store( $class ) ) {
- $path .= '/data-stores';
- } elseif ( false !== strpos( $class, 'deprecat' ) ) {
- $path .= '/deprecated';
- } elseif ( false !== strpos( $class, 'email' ) && 'wc_subscriptions_email' !== $class ) {
- $path .= '/emails';
- } elseif ( false !== strpos( $class, 'gateway' ) && 'wc_subscriptions_change_payment_gateway' !== $class ) {
- $path .= '/gateways';
- } elseif ( false !== strpos( $class, 'legacy' ) || 'wcs_array_property_post_meta_black_magic' === $class ) {
- $path .= '/legacy';
- } elseif ( false !== strpos( $class, 'privacy' ) ) {
- $path .= '/privacy';
- } elseif ( false !== strpos( $class, 'upgrade' ) || false !== strpos( $class, 'repair' ) ) {
- $path .= '/upgrades';
+ } elseif ( false !== strpos( $class, 'retry' ) || false !== strpos( $class, 'retries' ) ) {
+ $path .= $this->get_payment_retry_class_relative_path( $class );
+ } elseif ( false !== strpos( $class, 'admin' ) ) {
+ $path .= '/admin';
} elseif ( false !== strpos( $class, 'early' ) ) {
$path .= '/early-renewal';
+ } elseif ( false !== strpos( $class, 'gateways' ) ) {
+ $path .= '/gateways';
+ } elseif ( false !== strpos( $class, 'rest' ) ) {
+ $path .= $this->legacy_api ? '/api/legacy' : $this->get_rest_api_directory( $class );
+ } elseif ( false !== strpos( $class, 'api' ) && 'wcs_api' !== $class ) {
+ $path .= '/api/legacy';
}
return trailingslashit( $path );
}
+ /**
+ * Determine whether we should autoload a given class.
+ *
+ * @param string $class The class name.
+ * @return bool
+ */
+ protected function should_autoload( $class ) {
+ static $legacy = array(
+ 'wc_order_item_pending_switch' => 1,
+ 'wc_report_retention_rate' => 1,
+ 'wc_report_upcoming_recurring_revenue' => 1,
+ );
+
+ return isset( $legacy[ $class ] ) ? true : parent::should_autoload( $class );
+
+ }
+
+ /**
+ * Is the given class found in the Subscriptions plugin
+ *
+ * @since 4.0.0
+ * @param string $class
+ * @return bool
+ */
+ private function is_plugin_class( $class ) {
+ if ( isset( $this->classes[ $class ] ) ) {
+ return true;
+ }
+
+ foreach ( $this->class_substrings as $substring ) {
+ if ( false !== stripos( $class, $substring ) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Gets a retry class's relative path.
+ *
+ * @param string $class The retry class being loaded.
+ * @return string The relative path to the retry class.
+ */
+ private function get_payment_retry_class_relative_path( $class ) {
+ $relative_path = '/payment-retry';
+
+ if ( false !== strpos( $class, 'admin' ) || false !== strpos( $class, 'meta_box' ) ) {
+ $relative_path .= '/admin';
+ } elseif ( false !== strpos( $class, 'email' ) ) {
+ $relative_path .= '/emails';
+ } elseif ( false !== strpos( $class, 'store' ) ) {
+ $relative_path .= '/data-stores';
+ }
+
+ return $relative_path;
+ }
+
+ /**
+ * Determine if the class is one of our abstract classes.
+ *
+ * @param string $class The class name.
+ * @return bool
+ */
+ protected function is_class_abstract( $class ) {
+ static $abstracts = array(
+ 'wcs_retry_store' => true,
+ );
+
+ return isset( $abstracts[ $class ] ) || parent::is_class_abstract( $class );
+ }
+
/**
* Set whether the legacy API should be used.
*
@@ -281,4 +199,23 @@ class WCS_Autoloader {
return $this;
}
+
+ /**
+ * Gets the correct subdirectory for a version of the a REST API class.
+ *
+ * @param string $class The rest API class name.
+ * @return string The subdirectory for a rest API class.
+ */
+ protected function get_rest_api_directory( $class ) {
+ $directory = '/api';
+
+ // Check for an API version in the class name.
+ preg_match( '/v\d/', $class, $matches );
+
+ if ( ! empty( $matches ) ) {
+ $directory .= "/{$matches[0]}";
+ }
+
+ return $directory;
+ }
}
diff --git a/includes/class-wcs-call-to-action-button-text-manager.php b/includes/class-wcs-call-to-action-button-text-manager.php
new file mode 100644
index 0000000..ed80e6a
--- /dev/null
+++ b/includes/class-wcs-call-to-action-button-text-manager.php
@@ -0,0 +1,94 @@
+ __( 'Button Text', 'woocommerce-subscriptions' ),
+ 'type' => 'title',
+ 'desc' => '',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_button_text',
+ ),
+ array(
+ 'name' => __( 'Add to Cart Button Text', 'woocommerce-subscriptions' ),
+ 'desc' => __( '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.', 'woocommerce-subscriptions' ),
+ 'tip' => '',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text',
+ 'css' => 'min-width:150px;',
+ 'default' => __( 'Sign up now', 'woocommerce-subscriptions' ),
+ 'type' => 'text',
+ 'desc_tip' => true,
+ 'placeholder' => __( 'Sign up now', 'woocommerce-subscriptions' ),
+ ),
+ array(
+ 'name' => __( 'Place Order Button Text', 'woocommerce-subscriptions' ),
+ 'desc' => __( 'Use this field to customise the text displayed on the checkout button when an order contains a subscription. Normally the checkout submission button displays "Place order". When the cart contains a subscription, this is changed to "Sign up now".', 'woocommerce-subscriptions' ),
+ 'tip' => '',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_order_button_text',
+ 'css' => 'min-width:150px;',
+ 'default' => __( 'Sign up now', 'woocommerce-subscriptions' ),
+ 'type' => 'text',
+ 'desc_tip' => true,
+ 'placeholder' => __( 'Sign up now', 'woocommerce-subscriptions' ),
+ ),
+ array(
+ 'type' => 'sectionend',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_button_text',
+ ),
+ );
+
+ return array_merge( $button_text_settings, $settings );
+ }
+
+ /**
+ * Filters subscription products add to cart text to honour the setting.
+ *
+ * @since 4.0.0
+ *
+ * @param string $add_to_cart_text The product's add to cart text.
+ * @param WC_Abstract_Product $product The product.
+ *
+ * @return string
+ */
+ public static function filter_add_to_cart_text( $add_to_cart_text ) {
+ return get_option( WC_Subscriptions_Admin::$option_prefix . '_add_to_cart_button_text', $add_to_cart_text );
+ }
+
+ /**
+ * Filters the place order text while there's a subscription in the cart.
+ *
+ * @since 4.0.0
+ *
+ * @param string $button_text The default place order button text.
+ * @return string The button text.
+ */
+ public static function filter_place_subscription_order_text( $button_text ) {
+ return get_option( WC_Subscriptions_Admin::$option_prefix . '_order_button_text', $button_text );
+ }
+}
diff --git a/includes/class-wcs-customer-suspension-manager.php b/includes/class-wcs-customer-suspension-manager.php
new file mode 100644
index 0000000..3b7b8f0
--- /dev/null
+++ b/includes/class-wcs-customer-suspension-manager.php
@@ -0,0 +1,126 @@
+ __( 'Customer Suspensions', 'woocommerce-subscriptions' ),
+ 'desc' => _x( 'suspensions per billing period.', 'there\'s a number immediately in front of this text', 'woocommerce-subscriptions' ),
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_max_customer_suspensions',
+ 'css' => 'min-width:50px;',
+ 'default' => 0,
+ 'type' => 'select',
+ 'options' => apply_filters( 'woocommerce_subscriptions_max_customer_suspension_range', array_merge( range( 0, 12 ), array( 'unlimited' => 'Unlimited' ) ) ),
+ 'desc_tip' => __( '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 yearly, if the customer has suspended their account 3 times, they will not be presented with the option to suspend their account until the next year. Store managers will always be able to suspend an active subscription. Set this to 0 to turn off the customer suspension feature completely.', 'woocommerce-subscriptions' ),
+ );
+
+ WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_miscellaneous', $suspension_setting );
+ return $settings;
+ }
+
+ /**
+ * Filters whether the current user can suspend the subscription.
+ *
+ * Allows the customer to suspend the subscription if the _max_customer_suspensions setting hasn't been reached.
+ *
+ * @since 4.0.0
+ *
+ * @param bool $can_user_suspend Whether the current user can suspend the subscrption determined by @see wcs_can_user_put_subscription_on_hold().
+ * @param WC_Subscription $subscription The subscription.
+ * @param WP_User $user The current user.
+ *
+ * @return bool Whether the subscription can be suspended by the user.
+ */
+ public static function can_customer_put_subscription_on_hold( $can_user_suspend, $subscription, $user ) {
+
+ // Exit early if the customer can already suspend the subscription.
+ if ( $can_user_suspend ) {
+ return $can_user_suspend;
+ }
+
+ // We're only interested in the customer who owns the subscription.
+ if ( $subscription->get_user_id() !== $user->ID ) {
+ return $can_user_suspend;
+ }
+
+ // Make sure subscription suspension count hasn't been reached
+ $suspension_count = intval( $subscription->get_suspension_count() );
+ $allowed_suspensions = self::get_allowed_customer_suspensions();
+
+ if ( 'unlimited' === $allowed_suspensions || $allowed_suspensions > $suspension_count ) { // 0 not > anything so prevents a customer ever being able to suspend
+ $can_user_suspend = true;
+ }
+
+ return $can_user_suspend;
+ }
+
+ /**
+ * Adds the customer suspension action, if allowed.
+ *
+ * @since 4.0.0
+ *
+ * @param array $actions The actions a customer/user can make with a subscription.
+ * @param WC_Subscription $subscription The subscription.
+ * @param int $user_id The user viewing the subscription.
+ *
+ * @return array The customer's subscription actions.
+ */
+ public static function add_customer_suspension_action( $actions, $subscription, $user_id ) {
+
+ if ( ! $subscription->can_be_updated_to( 'on-hold' ) ) {
+ return $actions;
+ }
+
+ if ( ! user_can( $user_id, 'edit_shop_subscription_status', $subscription->get_id() ) ) {
+ return $actions;
+ }
+
+ if ( '0' === self::get_allowed_customer_suspensions() ) {
+ return $actions;
+ }
+
+ if ( current_user_can( 'manage_woocommerce' ) || wcs_can_user_put_subscription_on_hold( $subscription, $user_id ) ) {
+ $actions['suspend'] = array(
+ 'url' => wcs_get_users_change_status_link( $subscription->get_id(), 'on-hold', $subscription->get_status() ),
+ 'name' => __( 'Suspend', 'woocommerce-subscriptions' ),
+ );
+ }
+
+ return $actions;
+ }
+
+ /**
+ * Gets the number of suspensions a customer can make per billing period.
+ *
+ * @since 4.0.0
+ * @return string The number of suspensions a customer can make per billing period. Can 'unlimited' or the number of suspensions allowed.
+ */
+ public static function get_allowed_customer_suspensions() {
+ return get_option( WC_Subscriptions_Admin::$option_prefix . '_max_customer_suspensions', '0' );
+ }
+}
diff --git a/includes/class-wcs-drip-downloads-manager.php b/includes/class-wcs-drip-downloads-manager.php
new file mode 100644
index 0000000..43eec3b
--- /dev/null
+++ b/includes/class-wcs-drip-downloads-manager.php
@@ -0,0 +1,76 @@
+get_id() ) || wcs_order_contains_subscription( $order, 'any' ) ) ) {
+ $grant_access = false;
+ }
+
+ return $grant_access;
+ }
+
+ /**
+ * Adds the Drip Downloadable Content setting.
+ *
+ * @since 4.0.0
+ *
+ * @param array $settings The WC Subscriptions settings array.
+ * @return array Settings.
+ */
+ public static function add_setting( $settings ) {
+ $setting = array(
+ 'name' => __( 'Drip Downloadable Content', 'woocommerce-subscriptions' ),
+ 'desc' => __( 'Enable dripping for downloadable content on subscription products.', 'woocommerce-subscriptions' ),
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_drip_downloadable_content_on_renewal',
+ 'default' => 'no',
+ 'type' => 'checkbox',
+ // translators: %s is a line break.
+ 'desc_tip' => sprintf( __( 'Enabling this grants access to new downloadable files added to a product only after the next renewal is processed.%sBy default, access to new downloadable files added to a product is granted immediately to any customer that has an active subscription with that product.', 'woocommerce-subscriptions' ), ' ' ),
+ );
+
+ WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_miscellaneous', $setting );
+ return $settings;
+ }
+}
diff --git a/includes/class-wcs-limited-recurring-coupon-manager.php b/includes/class-wcs-limited-recurring-coupon-manager.php
new file mode 100644
index 0000000..ffa5ae5
--- /dev/null
+++ b/includes/class-wcs-limited-recurring-coupon-manager.php
@@ -0,0 +1,415 @@
+ '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 ),
+ ) );
+ }
+
+ /**
+ * Saves our custom coupon fields.
+ *
+ * @since 4.0.0
+ * @param int $id The coupon's ID.
+ */
+ public static function save_coupon_fields( $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( $id );
+ $coupon->add_meta_data( self::$coupons_renewals, wc_clean( $_POST['wcs_number_payments'] ), true );
+ $coupon->save();
+ }
+
+ /**
+ * Get the number of renewals for a limited coupon.
+ *
+ * @since 4.0.0
+ * @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 ( wcs_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 ( WC_Subscriptions_Coupon::is_renewal_cart_coupon( $coupon_type ) ) {
+ $coupon = WC_Subscriptions_Coupon::map_virtual_coupon( $code );
+ $coupon_type = $coupon->get_discount_type();
+ }
+
+ $limited = $coupon->get_meta( self::$coupons_renewals );
+
+ return WC_Subscriptions_Coupon::is_recurring_coupon( $coupon_type ) ? intval( $limited ) : false;
+ }
+
+ /**
+ * Determines if a given coupon is limited to a certain number of renewals.
+ *
+ * @since 4.0.0
+ *
+ * @param string $code The coupon code.
+ * @return bool
+ */
+ public static function coupon_is_limited( $code ) {
+ return (bool) self::get_coupon_limit( $code );
+ }
+
+ /**
+ * Determines whether the cart contains a recurring coupon with set number of renewals.
+ *
+ * @since 4.0.0
+ * @return bool Whether the cart contains a limited recurring coupon.
+ */
+ 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;
+ }
+
+ /**
+ * Determines if a given order has a limited use coupon.
+ *
+ * @since 4.0.0
+ * @param WC_Order|WC_Subscription $order
+ *
+ * @return bool Whether the order contains a limited recurring coupon.
+ */
+ public static function order_has_limited_recurring_coupon( $order ) {
+ $has_coupon = false;
+
+ foreach ( wcs_get_used_coupon_codes( $order ) as $code ) {
+ if ( self::coupon_is_limited( $code ) ) {
+ $has_coupon = true;
+ break;
+ }
+ }
+
+ return $has_coupon;
+ }
+
+ /**
+ * Limits payment gateways to those that support changing subscription amounts.
+ *
+ * @since 4.0.0
+ * @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;
+ }
+
+ /**
+ * Determines how many subscription renewals the coupon has been applied to and removes coupons which have reached their expiry.
+ *
+ * @since 4.0.0
+ * @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 = wcs_get_used_coupon_codes( $subscription );
+ 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 ] = array(
+ 'code' => $code,
+ 'count' => 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 ( $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() ]['count']++;
+ }
+ }
+ }
+
+ // Check each coupon to see if it needs to be removed.
+ foreach ( $limited_coupons as $limited_coupon ) {
+ if ( self::get_coupon_limit( $limited_coupon['code'] ) <= $limited_coupon['count'] ) {
+ $subscription->remove_coupon( $limited_coupon['code'] );
+ $subscription->add_order_note( sprintf(
+ /* translators: %1$s is the coupon code, %2$d is the number of payment usages */
+ _n(
+ '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.',
+ $limited_coupon['count'],
+ 'woocommerce-subscriptions'
+ ),
+ $limited_coupon['code'],
+ number_format_i18n( $limited_coupon['count'] )
+ ) );
+ }
+ }
+ }
+
+ /**
+ * Add our limited coupon data to the Coupon list table.
+ *
+ * @since 4.0.0
+ *
+ * @param string $column_name The name of the current column in the table.
+ * @param int $id The coupon ID.
+ */
+ public static function add_limit_to_list_table( $column_name, $id ) {
+ if ( 'usage' !== $column_name ) {
+ return;
+ }
+
+ $limit = self::get_coupon_limit( wc_get_coupon_code_by_id( $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' );
+ }
+ }
+
+ /**
+ * Determines if a given recurring cart contains a limited use coupon which when applied to a subscription will reach its usage limit within the subscription's length.
+ *
+ * @since 4.0.0
+ *
+ * @param WC_Cart $recurring_cart The recurring cart object.
+ * @return bool
+ */
+ public static function recurring_cart_contains_expiring_coupon( $recurring_cart ) {
+ $limited_recurring_coupons = array();
+
+ if ( isset( $recurring_cart->applied_coupons ) ) {
+ $limited_recurring_coupons = array_filter( $recurring_cart->applied_coupons, array( __CLASS__, 'coupon_is_limited' ) );
+ }
+
+ // Bail early if there are no limited coupons applied to the recurring cart or if there is no discount provided.
+ if ( empty( $limited_recurring_coupons ) || ! $recurring_cart->discount_cart ) {
+ return false;
+ }
+
+ $has_expiring_coupon = false;
+ $subscription_length = wcs_cart_pluck( $recurring_cart, 'subscription_length' );
+ $subscription_payments = $subscription_length / wcs_cart_pluck( $recurring_cart, 'subscription_period_interval' );
+
+ // Limited recurring coupons will always expire at some point on subscriptions with no length.
+ if ( empty( $subscription_length ) ) {
+ $has_expiring_coupon = true;
+ } else {
+ foreach ( $limited_recurring_coupons as $code ) {
+ if ( WC_Subscriptions_Coupon::get_coupon_limit( $code ) < $subscription_payments ) {
+ $has_expiring_coupon = true;
+ break;
+ }
+ }
+ }
+
+ return $has_expiring_coupon;
+ }
+
+ /**
+ * Filters the available gateways when there is a recurring coupon.
+ *
+ * @since 4.0.0
+ *
+ * @param WC_Payment_Gateway[] $gateways The available payment gateways.
+ * @return WC_Payment_Gateway[] The filtered payment gateways.
+ */
+ public static function gateways_subscription_amount_changes( $gateways ) {
+
+ // If there are already no gateways or we're on the order-pay screen, bail early.
+ if ( empty( $gateways ) || is_wc_endpoint_url( 'order-pay' ) ) {
+ 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.
+ *
+ * @since 4.0.0
+ *
+ * @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() {
+ 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' );
+ }
+
+ /**
+ * Removes limited coupons from the recurring cart if the coupons limit is reached in the initial cart.
+ *
+ * @since 4.0.0
+ *
+ * @param bool $bypass_default_checks Whether to bypass WC Subscriptions default conditions for removing a coupon.
+ * @param WC_Coupon $coupon The coupon to check.
+ * @param string $coupon_type The coupon's type.
+ * @param string $calculation_type The WC Subscriptions cart calculation mode. Can be 'recurring_total' or 'none'. @see WC_Subscriptions_Cart::get_calculation_type()
+ *
+ * @return bool Whether to bypass WC Subscriptions default conditions for removing a coupon.
+ */
+ public static function maybe_remove_coupons_from_recurring_cart( $bypass_default_checks, $coupon, $coupon_type, $calculation_type, $cart ) {
+
+ // Bypass this check if a third-party has already opted to bypass default conditions.
+ if ( $bypass_default_checks ) {
+ return $bypass_default_checks;
+ }
+
+ if ( 'recurring_total' !== $calculation_type ) {
+ return $bypass_default_checks;
+ }
+
+ if ( ! WC_Subscriptions_Coupon::is_recurring_coupon( $coupon_type ) ) {
+ return $bypass_default_checks;
+ }
+
+ // Special handling for a single payment coupon.
+ if ( 1 === self::get_coupon_limit( $coupon->get_code() ) && 0 < WC()->cart->get_coupon_discount_amount( $coupon->get_code() ) ) {
+ $cart->remove_coupon( $coupon->get_code() );
+ }
+
+ return $bypass_default_checks;
+ }
+}
diff --git a/includes/class-wcs-manual-renewal-manager.php b/includes/class-wcs-manual-renewal-manager.php
new file mode 100644
index 0000000..174b7fd
--- /dev/null
+++ b/includes/class-wcs-manual-renewal-manager.php
@@ -0,0 +1,91 @@
+ _x( 'Renewals', 'option section heading', 'woocommerce-subscriptions' ),
+ 'type' => 'title',
+ 'desc' => '',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_renewal_options',
+ ),
+ array(
+ 'name' => __( 'Manual Renewal Payments', 'woocommerce-subscriptions' ),
+ 'desc' => __( 'Accept Manual Renewals', 'woocommerce-subscriptions' ),
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals',
+ 'default' => 'no',
+ 'type' => 'checkbox',
+ // translators: placeholders are opening and closing link tags
+ 'desc_tip' => sprintf( __( 'With manual renewals, a customer\'s subscription is put on-hold until they login and pay to renew it. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '', ' ' ),
+ 'checkboxgroup' => 'start',
+ 'show_if_checked' => 'option',
+ ),
+
+ array(
+ 'desc' => __( 'Turn off Automatic Payments', 'woocommerce-subscriptions' ),
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments',
+ 'default' => 'no',
+ 'type' => 'checkbox',
+ // translators: placeholders are opening and closing link tags
+ 'desc_tip' => sprintf( __( 'If you don\'t want new subscription purchases to automatically charge renewal payments, you can turn off automatic payments. Existing automatic subscriptions will continue to charge customers automatically. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '', ' ' ),
+ 'checkboxgroup' => 'end',
+ 'show_if_checked' => 'yes',
+ ),
+
+ array(
+ 'type' => 'sectionend',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_renewal_options',
+ ),
+ );
+
+ if ( ! WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_role_options', $manual_renewal_settings, 'multiple_settings', 'sectionend' ) ) {
+ $settings = array_merge( $settings, $manual_renewal_settings );
+ }
+
+ return $settings;
+ }
+
+ /**
+ * Checks if manual renewals are required - automatic renewals are disabled.
+ *
+ * @since 4.0.0
+ * @return bool Weather manual renewal is required.
+ */
+ public static function is_manual_renewal_required() {
+ return 'yes' === get_option( WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no' );
+ }
+
+ /**
+ * Checks if manual renewals are enabled.
+ *
+ * @since 4.0.0
+ * @return bool Weather manual renewal is enabled.
+ */
+ public static function is_manual_renewal_enabled() {
+ return 'yes' === get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no' );
+ }
+}
diff --git a/includes/class-wcs-staging.php b/includes/class-wcs-staging.php
deleted file mode 100644
index 89c8626..0000000
--- a/includes/class-wcs-staging.php
+++ /dev/null
@@ -1,99 +0,0 @@
- tags - linked to staging site, 3: link to live site.
- $message = sprintf( __( 'Payment processing skipped - renewal order created on %1$sstaging site%2$s under staging site lock. Live site is at %3$s', 'woocommerce-subscriptions' ), '', ' ', '' . $wcs_site_url . ' ' );
-
- $renewal_order->add_order_note( $message );
- }
- }
-
- /**
- * 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;
- }
-
- /**
- * Handles admin requests to redisplay the staging site admin notice.
- *
- * @since 2.5.5
- */
- public static function maybe_reset_admin_notice() {
- if ( isset( $_REQUEST['wcs_display_staging_notice'] ) && is_admin() && current_user_can( 'manage_options' ) ) {
- delete_option( 'wcs_ignore_duplicate_siteurl_notice' );
- wp_safe_redirect( remove_query_arg( array( 'wcs_display_staging_notice' ) ) );
- }
- }
-
- /**
- * Displays a note under the edit subscription payment method field to explain why the subscription is set to Manual Renewal.
- *
- * @param WC_Subscription $subscription
- * @since 2.6.0
- */
- public static function maybe_add_payment_method_note( $subscription ) {
- if ( wcs_is_subscription( $subscription ) && WC_Subscriptions::is_duplicate_site() && $subscription->has_payment_gateway() && ! $subscription->get_requires_manual_renewal() ) {
- printf(
- '%s
',
- esc_html__( 'Subscription locked to Manual Renewal while the store is in staging mode. Payment method changes will take effect in live mode.', 'woocommerce-subscriptions' )
- );
- }
- }
-
- /**
- * Returns the content for a tooltip explaining a subscription's payment method while in staging mode.
- *
- * @param WC_Subscription $subscription
- * @return string HTML content for a tooltip.
- * @since 2.6.0
- */
- public static function get_payment_method_tooltip( $subscription ) {
- // translators: placeholder is a payment method title.
- return '
';
- }
-}
diff --git a/includes/class-wcs-subscriber-role-manager.php b/includes/class-wcs-subscriber-role-manager.php
new file mode 100644
index 0000000..1f8c46c
--- /dev/null
+++ b/includes/class-wcs-subscriber-role-manager.php
@@ -0,0 +1,98 @@
+ $details ) {
+ $roles_options[ $role ] = translate_user_role( $details['name'] );
+ }
+
+ $role_settings = array(
+ array(
+ 'name' => __( 'Roles', 'woocommerce-subscriptions' ),
+ 'type' => 'title',
+ // translators: placeholders are tags
+ 'desc' => sprintf( __( 'Choose the default roles to assign to active and inactive subscribers. For record keeping purposes, a user account must be created for subscribers. Users with the %1$sadministrator%2$s role, such as yourself, will never be allocated these roles to prevent locking out administrators.', 'woocommerce-subscriptions' ), '', ' ' ),
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_role_options',
+ ),
+ array(
+ 'name' => __( 'Subscriber Default Role', 'woocommerce-subscriptions' ),
+ 'desc' => __( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'woocommerce-subscriptions' ),
+ 'tip' => '',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_subscriber_role',
+ 'css' => 'min-width:150px;',
+ 'default' => 'subscriber',
+ 'type' => 'select',
+ 'options' => $roles_options,
+ 'desc_tip' => true,
+ ),
+ array(
+ 'name' => __( 'Inactive Subscriber Role', 'woocommerce-subscriptions' ),
+ 'desc' => __( 'If a subscriber\'s subscription is manually cancelled or expires, she will be assigned this role.', 'woocommerce-subscriptions' ),
+ 'tip' => '',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_cancelled_role',
+ 'css' => 'min-width:150px;',
+ 'default' => 'customer',
+ 'type' => 'select',
+ 'options' => $roles_options,
+ 'desc_tip' => true,
+ ),
+ array(
+ 'type' => 'sectionend',
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_role_options',
+ ),
+ );
+
+ WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_button_text', $role_settings, 'multiple_settings', 'sectionend' );
+ return $settings;
+ }
+
+ /**
+ * Gets the subscriber role.
+ *
+ * @since 4.0.0
+ *
+ * @return string The role to apply to subscribers.
+ */
+ public static function get_subscriber_role() {
+ return get_option( WC_Subscriptions_Admin::$option_prefix . '_subscriber_role', 'subscriber' );
+ }
+
+ /**
+ * Gets the inactive subscriber role.
+ *
+ * @since 4.0.0
+ *
+ * @return string The role to apply to inactive subscribers.
+ */
+ public static function get_inactive_subscriber_role() {
+ return get_option( WC_Subscriptions_Admin::$option_prefix . '_cancelled_role', 'customer' );
+ }
+}
diff --git a/includes/class-wcs-template-loader.php b/includes/class-wcs-template-loader.php
deleted file mode 100644
index 155e8d7..0000000
--- a/includes/class-wcs-template-loader.php
+++ /dev/null
@@ -1,117 +0,0 @@
-get_id() ) ) {
- echo '';
- return;
- }
-
- wc_get_template( 'myaccount/view-subscription.php', compact( 'subscription' ), '', plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/' );
- }
-
- /**
- * Get the subscription details template, which is part of the view subscription page.
- *
- * @param WC_Subscription $subscription Subscription object
- * @since 2.2.19
- */
- public static function get_subscription_details_template( $subscription ) {
- wc_get_template( 'myaccount/subscription-details.php', array( 'subscription' => $subscription ), '', plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/' );
- }
-
- /**
- * Get the subscription totals template, which is part of the view subscription page.
- *
- * @param WC_Subscription $subscription Subscription object
- * @since 2.2.19
- */
- public static function get_subscription_totals_template( $subscription ) {
- wc_get_template( 'myaccount/subscription-totals.php', array( 'subscription' => $subscription ), '', plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/' );
- }
-
- /**
- * Get the order downloads template, which is part of the view subscription page.
- *
- * @param WC_Subscription $subscription Subscription object
- * @since 2.5.0
- */
- public static function get_order_downloads_template( $subscription ) {
- if ( $subscription->has_downloadable_item() && $subscription->is_download_permitted() ) {
- wc_get_template(
- 'order/order-downloads.php',
- array(
- 'downloads' => $subscription->get_downloadable_items(),
- 'show_title' => true,
- )
- );
- }
- }
-
- /**
- * Gets the subscription totals table.
- *
- * @since 2.6.0
- *
- * @param WC_Subscription $subscription The subscription to print the totals table for.
- * @param bool $include_item_removal_links Whether the remove line item links should be included.
- * @param array $totals The subscription totals rows to be displayed.
- * @param bool $include_switch_links Whether the line item switch links should be included.
- */
- public static function get_subscription_totals_table_template( $subscription, $include_item_removal_links, $totals, $include_switch_links = true ) {
-
- // If the switch links shouldn't be printed, remove the callback which prints them.
- if ( false === $include_switch_links ) {
- $callback_detached = remove_action( 'woocommerce_order_item_meta_end', 'WC_Subscriptions_Switcher::print_switch_link' );
- }
-
- wc_get_template(
- 'myaccount/subscription-totals-table.php',
- array(
- 'subscription' => $subscription,
- 'allow_item_removal' => $include_item_removal_links,
- 'totals' => $totals,
- ),
- '',
- plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/'
- );
-
- // Reattach the callback if it was successfully removed.
- if ( false === $include_switch_links && $callback_detached ) {
- add_action( 'woocommerce_order_item_meta_end', 'WC_Subscriptions_Switcher::print_switch_link', 10, 3 );
- }
- }
-
- /**
- * Gets the subscription receipt template content.
- *
- * @since 3.0.0
- *
- * @param WC_Subscription $subscription The subscription to display the receipt for.
- */
- public static function get_subscription_receipt_template( $subscription ) {
- wc_get_template( 'checkout/subscription-receipt.php', array( 'subscription' => $subscription ), '', plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/' );
- }
-}
diff --git a/includes/upgrades/class-wcs-upgrade-notice-manager.php b/includes/class-wcs-upgrade-notice-manager.php
similarity index 74%
rename from includes/upgrades/class-wcs-upgrade-notice-manager.php
rename to includes/class-wcs-upgrade-notice-manager.php
index e7ccce7..e008f83 100644
--- a/includes/upgrades/class-wcs-upgrade-notice-manager.php
+++ b/includes/class-wcs-upgrade-notice-manager.php
@@ -19,7 +19,7 @@ class WCS_Upgrade_Notice_Manager {
*
* @var string
*/
- protected static $version = '3.0.0';
+ protected static $version = '3.1.0';
/**
* The number of times the notice will be displayed before being dismissed automatically.
@@ -77,34 +77,40 @@ class WCS_Upgrade_Notice_Manager {
return;
}
- $version = _x( '3.0', 'plugin version number used in admin notice', 'woocommerce-subscriptions' );
+ $version = _x( '3.1', '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' => __( 'Improved scheduled action data storage', 'woocommerce-subscriptions' ),
- 'description' => __( 'Scheduled action data, which was previously stored in the WordPress post tables, has been moved to a custom database table. Amongst other benefits, this will greatly improve the performance of processing scheduled actions such as subscription payments.', 'woocommerce-subscriptions' ),
+ 'title' => __( 'v3 REST API endpoint support', 'woocommerce-subscriptions' ),
+ 'description' => sprintf(
+ // translators: 1-3: opening/closing tags - link to documentation.
+ __( 'Webhook and REST API users can now use v3 subscription endpoints. Click here to %1$slearn more%2$s about the REST API and check out the technical API docs %3$shere%2$s.', 'woocommerce-subscriptions' ),
+ ' ',
+ ' ',
+ ''
+ ),
),
array(
- 'title' => __( 'Increased processing rate for scheduled payments', 'woocommerce-subscriptions' ),
+ 'title' => __( 'WooCommerce checkout and cart blocks integration', 'woocommerce-subscriptions' ),
'description' => sprintf(
// translators: 1-2: opening/closing tags - link to documentation.
- __( 'Previous versions of Subscriptions relied on %1$sWP Cron%2$s to process subscription payments and other scheduled events. In 3.0, these events will now run on admin request with loopback support. This will significantly increase the throughput of payment processing.', 'woocommerce-subscriptions' ),
- ' ', ' '
+ __( 'Subscriptions is now compatible with the WooCommerce cart and checkout blocks. You can learn more about the compatibility status of the cart & checkout blocks %1$shere%2$s.', 'woocommerce-subscriptions' ),
+ '', ' '
),
),
);
- // translators: placeholder is Subscription version string ('2.3')
+ // translators: placeholder is Subscription version string ('3.1')
$notice->set_heading( sprintf( __( 'Welcome to WooCommerce Subscriptions %s!', 'woocommerce-subscriptions' ), $version ) );
- $notice->set_content_template( 'update-welcome-notice.php', plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'includes/upgrades/templates/', array(
+ $notice->set_content_template( 'update-welcome-notice.php', WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory() . '/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/whats-new-in-subscriptions-3-0/',
+ 'url' => 'https://docs.woocommerce.com/document/subscriptions/whats-new-in-subscriptions-3-1/',
),
) );
diff --git a/includes/class-wcs-webhooks.php b/includes/class-wcs-webhooks.php
index 5a09c18..97e11cc 100644
--- a/includes/class-wcs-webhooks.php
+++ b/includes/class-wcs-webhooks.php
@@ -107,10 +107,10 @@ class WCS_Webhooks {
public static function add_topics_admin_menu( $topics ) {
$front_end_topics = array(
- 'subscription.created' => __( ' Subscription Created', 'woocommerce-subscriptions' ),
- 'subscription.updated' => __( ' Subscription Updated', 'woocommerce-subscriptions' ),
- 'subscription.deleted' => __( ' Subscription Deleted', 'woocommerce-subscriptions' ),
- 'subscription.switched' => __( ' Subscription Switched', 'woocommerce-subscriptions' ),
+ 'subscription.created' => __( ' Subscription created', 'woocommerce-subscriptions' ),
+ 'subscription.updated' => __( ' Subscription updated', 'woocommerce-subscriptions' ),
+ 'subscription.deleted' => __( ' Subscription deleted', 'woocommerce-subscriptions' ),
+ 'subscription.switched' => __( ' Subscription switched', 'woocommerce-subscriptions' ),
);
return array_merge( $topics, $front_end_topics );
@@ -125,27 +125,28 @@ class WCS_Webhooks {
if ( 'subscription' == $resource && empty( $payload ) && wcs_is_subscription( $resource_id ) ) {
$webhook = new WC_Webhook( $id );
- $event = $webhook->get_event();
$current_user = get_current_user_id();
wp_set_current_user( $webhook->get_user_id() );
- $webhook_api_version = ( method_exists( $webhook, 'get_api_version' ) ) ? $webhook->get_api_version() : 'legacy_v3';
-
- switch ( $webhook_api_version ) {
+ switch ( $webhook->get_api_version() ) {
case 'legacy_v3':
WC()->api->WC_API_Subscriptions->register_routes( array() );
$payload = WC()->api->WC_API_Subscriptions->get_subscription( $resource_id );
break;
case 'wp_api_v1':
case 'wp_api_v2':
- case 'wp_api_v3':
+ // There is no v2 subscritpion endpoint support so they fall back to v1.
$request = new WP_REST_Request( 'GET' );
- $controller = new WC_REST_Subscriptions_Controller;
+ $controller = new WC_REST_Subscriptions_v1_Controller();
$request->set_param( 'id', $resource_id );
$result = $controller->get_item( $request );
$payload = isset( $result->data ) ? $result->data : array();
+
+ break;
+ case 'wp_api_v3':
+ $payload = wc()->api->get_endpoint_data( "/wc/v3/subscriptions/{$resource_id}" );
break;
}
diff --git a/includes/class-wcs-zero-initial-payment-checkout-manager.php b/includes/class-wcs-zero-initial-payment-checkout-manager.php
new file mode 100644
index 0000000..87064e7
--- /dev/null
+++ b/includes/class-wcs-zero-initial-payment-checkout-manager.php
@@ -0,0 +1,85 @@
+ __( '$0 Initial Checkout', 'woocommerce-subscriptions' ),
+ 'desc' => __( 'Allow $0 initial checkout without a payment method.', 'woocommerce-subscriptions' ),
+ 'id' => WC_Subscriptions_Admin::$option_prefix . '_zero_initial_payment_requires_payment',
+ 'default' => 'no',
+ 'type' => 'checkbox',
+ 'desc_tip' => __( 'Allow a subscription product with a $0 initial payment to be purchased without providing a payment method. The customer will be required to provide a payment method at the end of the initial period to keep the subscription active.', 'woocommerce-subscriptions' ),
+ );
+
+ WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Admin::$option_prefix . '_miscellaneous', $setting );
+ return $settings;
+ }
+
+ /**
+ * Checks if a $0 checkout requires a payment method.
+ *
+ * @since 4.0.0
+ * @return bool Whether a $0 initial checkout requires a payment method.
+ */
+ public static function zero_initial_checkout_requires_payment() {
+ return 'yes' !== get_option( WC_Subscriptions_Admin::$option_prefix . '_zero_initial_payment_requires_payment', 'no' );
+ }
+
+ /**
+ * Unhooks core Subscriptions functionality that requires payment on checkout for $0 subscription purchases,
+ * if the store has opted to bypass that via this feature.
+ *
+ * @since 4.0.0
+ *
+ * @param bool $cart_needs_payment Whether the cart requires payment.
+ * @return bool
+ */
+ public static function cart_needs_payment( $cart_needs_payment ) {
+ if ( ! self::zero_initial_checkout_requires_payment() ) {
+ remove_filter( 'woocommerce_cart_needs_payment', 'WC_Subscriptions_Cart::cart_needs_payment', 10, 2 );
+ }
+
+ return $cart_needs_payment;
+ }
+
+ /**
+ * Unhooks core Subscriptions functionality that requires payment for a $0 subscription order,
+ * if the store has opted to bypass that via this feature.
+ *
+ * @since 4.0.0
+ *
+ * @param bool $needs_payment
+ * @return bool
+ */
+ public static function order_needs_payment( $needs_payment ) {
+ if ( ! self::zero_initial_checkout_requires_payment() ) {
+ remove_filter( 'woocommerce_order_needs_payment', 'WC_Subscriptions_Order::order_needs_payment', 10, 3 );
+ }
+
+ return $needs_payment;
+ }
+}
diff --git a/includes/early-renewal/class-wcs-cart-early-renewal.php b/includes/early-renewal/class-wcs-cart-early-renewal.php
index 2fec4bc..50a40da 100644
--- a/includes/early-renewal/class-wcs-cart-early-renewal.php
+++ b/includes/early-renewal/class-wcs-cart-early-renewal.php
@@ -27,10 +27,19 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
add_action( 'woocommerce_checkout_create_order', array( $this, 'copy_subscription_meta_to_order' ), 90 );
// Record early renewal payments.
- if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( wcs_is_woocommerce_pre( '3.0' ) ) {
add_action( 'woocommerce_checkout_order_processed', array( $this, 'maybe_record_early_renewal' ), 100, 2 );
} else {
add_action( 'woocommerce_checkout_create_order', array( $this, 'add_early_renewal_metadata_to_order' ), 100, 2 );
+ if ( class_exists( 'Automattic\WooCommerce\Blocks\Package' ) ) {
+ if ( version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '7.2.0', '>=' ) ) {
+ add_action( 'woocommerce_store_api_checkout_update_order_meta', array( $this, 'add_early_renewal_metadata_to_order' ), 100, 1 );
+ } elseif ( version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '6.3.0', '>=' ) ) {
+ add_action( 'woocommerce_blocks_checkout_update_order_meta', array( $this, 'add_early_renewal_metadata_to_order' ), 100, 1 );
+ } else {
+ add_action( '__experimental_woocommerce_blocks_checkout_update_order_meta', array( $this, 'add_early_renewal_metadata_to_order' ), 100, 1 );
+ }
+ }
}
// Process early renewal by making sure subscription's dates are updated.
@@ -127,7 +136,7 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
* @since 2.3.0
*/
public function maybe_record_early_renewal( $order_id, $posted_data ) {
- if ( ! WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( ! wcs_is_woocommerce_pre( '3.0' ) ) {
wcs_deprecated_function( __METHOD__, '2.0', 'WCS_Cart_Early_Renewal::add_early_renewal_metadata_to_order( $order, $posted_data )' );
}
@@ -178,7 +187,7 @@ class WCS_Cart_Early_Renewal extends WCS_Cart_Renewal {
* @param array $data The data posted on checkout.
* @since 2.3.0
*/
- public function add_early_renewal_metadata_to_order( $order, $data ) {
+ public function add_early_renewal_metadata_to_order( $order, $data = array() ) {
$cart_item = $this->cart_contains();
if ( ! $cart_item ) {
diff --git a/includes/early-renewal/class-wcs-early-renewal-modal-handler.php b/includes/early-renewal/class-wcs-early-renewal-modal-handler.php
index a918c33..d6c900b 100644
--- a/includes/early-renewal/class-wcs-early-renewal-modal-handler.php
+++ b/includes/early-renewal/class-wcs-early-renewal-modal-handler.php
@@ -45,6 +45,7 @@ class WCS_Early_Renewal_Modal_Handler {
'process_early_renewal' => true,
'wcs_nonce' => wp_create_nonce( 'wcs-renew-early-modal-' . $subscription->get_id() ),
) ),
+ 'data-payment-method' => $subscription->get_payment_method(),
),
);
@@ -88,7 +89,7 @@ class WCS_Early_Renewal_Modal_Handler {
'new_next_payment_date' => $new_next_payment_date,
),
'',
- plugin_dir_path( WC_Subscriptions::$plugin_file ) . '/templates/'
+ WC_Subscriptions_Plugin::instance()->get_plugin_directory( 'templates/' )
);
}
@@ -146,6 +147,9 @@ class WCS_Early_Renewal_Modal_Handler {
wp_redirect( wcs_get_early_renewal_url( $subscription ) );
exit();
} else {
+ // Trigger the subscription payment complete hooks and reset suspension counts and user roles.
+ $subscription->payment_complete();
+
wcs_update_dates_after_early_renewal( $subscription, $renewal_order );
wc_add_notice( __( 'Your early renewal order was successful.', 'woocommerce-subscriptions' ), 'success' );
}
diff --git a/includes/early-renewal/wcs-early-renewal-functions.php b/includes/early-renewal/wcs-early-renewal-functions.php
index 9a5c3af..50e264c 100644
--- a/includes/early-renewal/wcs-early-renewal-functions.php
+++ b/includes/early-renewal/wcs-early-renewal-functions.php
@@ -95,32 +95,6 @@ function wcs_can_user_renew_early( $subscription, $user_id = 0 ) {
return apply_filters( 'woocommerce_subscriptions_can_user_renew_early', $can_renew_early, $subscription, $user_id, $reason );
}
-/**
- * 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.
*
diff --git a/includes/gateways/class-wc-subscriptions-payment-gateways.php b/includes/gateways/class-wc-subscriptions-payment-gateways.php
index 46bbdf1..b61c933 100644
--- a/includes/gateways/class-wc-subscriptions-payment-gateways.php
+++ b/includes/gateways/class-wc-subscriptions-payment-gateways.php
@@ -10,67 +10,27 @@
* @author Brent Shepherd
* @since 1.0
*/
-class WC_Subscriptions_Payment_Gateways {
-
- protected static $one_gateway_supports = array();
+class WC_Subscriptions_Payment_Gateways extends WC_Subscriptions_Core_Payment_Gateways {
/**
- * Bootstraps the class and hooks required actions & filters.
+ * Init WC_Subscriptions_Payment_Gateways actions & filters.
*
- * @since 1.0
+ * @since 4.0.0
*/
public static function init() {
-
- add_action( 'init', __CLASS__ . '::init_paypal', 5 ); // run before default priority 10 in case the site is using ALTERNATE_WP_CRON to avoid https://core.trac.wordpress.org/ticket/24160.
-
- add_filter( 'woocommerce_available_payment_gateways', __CLASS__ . '::get_available_payment_gateways' );
-
- add_filter( 'woocommerce_no_available_payment_methods_message', __CLASS__ . '::no_available_payment_methods_message' );
-
- add_filter( 'woocommerce_payment_gateways_renewal_support_status_html', __CLASS__ . '::payment_gateways_support_tooltip', 11, 2 );
-
+ parent::init();
// Trigger a hook for gateways to charge recurring payments.
- add_action( 'woocommerce_scheduled_subscription_payment', __CLASS__ . '::gateway_scheduled_subscription_payment', 10, 1 );
+ add_action( 'woocommerce_scheduled_subscription_payment', array( __CLASS__, 'gateway_scheduled_subscription_payment' ), 10, 1 );
- // Create a gateway specific hooks for subscription events.
- add_action( 'woocommerce_subscription_status_updated', __CLASS__ . '::trigger_gateway_status_updated_hook', 10, 2 );
+ add_filter( 'woocommerce_subscriptions_admin_recurring_payment_information', array( __CLASS__, 'add_recurring_payment_gateway_information' ), 10, 2 );
}
/**
- * Instantiate our custom PayPal class
- *
- * @since 2.0
- */
- public static function init_paypal() {
- WCS_PayPal::init();
- }
-
- /**
- * Returns a payment gateway object by gateway's ID, or false if it could not find the gateway.
- *
- * @since 1.2.4
- */
- public static function get_payment_gateway( $gateway_id ) {
- $found_gateway = false;
-
- if ( WC()->payment_gateways ) {
- foreach ( WC()->payment_gateways->payment_gateways() as $gateway ) {
- if ( $gateway_id == $gateway->id ) {
- $found_gateway = $gateway;
- }
- }
- }
-
- return $found_gateway;
- }
-
- /**
- * Only display the gateways which support subscriptions if manual payments are not allowed.
+ * Display the gateways which support subscriptions if manual payments are not allowed.
*
* @since 1.0
*/
public static function get_available_payment_gateways( $available_gateways ) {
-
// We don't want to filter the available payment methods while the customer is paying for a standard order via the order-pay screen.
if ( is_wc_endpoint_url( 'order-pay' ) ) {
return $available_gateways;
@@ -80,7 +40,7 @@ class WC_Subscriptions_Payment_Gateways {
return $available_gateways;
}
- $accept_manual_renewals = ( 'no' !== get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no' ) );
+ $accept_manual_renewals = wcs_is_manual_renewal_enabled();
$subscriptions_in_cart = is_array( WC()->cart->recurring_carts ) ? count( WC()->cart->recurring_carts ) : 0;
foreach ( $available_gateways as $gateway_id => $gateway ) {
@@ -101,79 +61,25 @@ class WC_Subscriptions_Payment_Gateways {
}
/**
- * Helper function to check if at least one payment gateway on the site supports a certain subscription feature.
+ * Fire a gateway specific hook for when a subscription payment is due.
*
- * @since 2.0
+ * @since 1.0
*/
- public static function one_gateway_supports( $supports_flag ) {
-
- // Only check if we haven't already run the check
- if ( ! isset( self::$one_gateway_supports[ $supports_flag ] ) ) {
-
- self::$one_gateway_supports[ $supports_flag ] = false;
-
- foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) {
- if ( $gateway->supports( $supports_flag ) ) {
- self::$one_gateway_supports[ $supports_flag ] = true;
- break;
- }
- }
+ public static function gateway_scheduled_subscription_payment( $subscription_id, $deprecated = null ) {
+ if ( ! is_object( $subscription_id ) ) {
+ $subscription = wcs_get_subscription( $subscription_id );
+ } else {
+ $subscription = $subscription_id;
}
- return self::$one_gateway_supports[ $supports_flag ];
- }
-
- /**
- * Improve message displayed on checkout when a subscription is in the cart but not gateways support subscriptions.
- *
- * @since 1.5.2
- */
- public static function no_available_payment_methods_message( $no_gateways_message ) {
- if ( WC_Subscriptions_Cart::cart_contains_subscription() && 'no' == get_option( WC_Subscriptions_Admin::$option_prefix . '_accept_manual_renewals', 'no' ) ) {
- if ( current_user_can( 'manage_woocommerce' ) ) {
- // translators: 1-2: opening/closing tags - link to documentation.
- $no_gateways_message = sprintf( __( 'Sorry, it seems there are no available payment methods which support subscriptions. Please see %1$sEnabling Payment Gateways for Subscriptions%2$s if you require assistance.', 'woocommerce-subscriptions' ), '', ' ' );
- } else {
- $no_gateways_message = __( 'Sorry, it seems there are no available payment methods which support subscriptions. Please contact us if you require assistance or wish to make alternate arrangements.', 'woocommerce-subscriptions' );
- }
+ if ( false === $subscription ) {
+ // translators: %d: subscription ID.
+ throw new InvalidArgumentException( sprintf( __( 'Subscription doesn\'t exist in scheduled action: %d', 'woocommerce-subscriptions' ), $subscription_id ) );
}
- return $no_gateways_message;
- }
-
- /**
- * Fire a gateway specific whenever a subscription's status is changed.
- *
- * @since 2.0
- */
- public static function trigger_gateway_status_updated_hook( $subscription, $new_status ) {
-
- if ( $subscription->is_manual() ) {
- return;
+ if ( ! $subscription->is_manual() && ! $subscription->has_status( wcs_get_subscription_ended_statuses() ) ) {
+ self::trigger_gateway_renewal_payment_hook( $subscription->get_last_order( 'all', 'renewal' ) );
}
-
- switch ( $new_status ) {
- case 'active':
- $hook_prefix = 'woocommerce_subscription_activated_';
- break;
- case 'on-hold':
- $hook_prefix = 'woocommerce_subscription_on-hold_';
- break;
- case 'pending-cancel':
- $hook_prefix = 'woocommerce_subscription_pending-cancel_';
- break;
- case 'cancelled':
- $hook_prefix = 'woocommerce_subscription_cancelled_';
- break;
- case 'expired':
- $hook_prefix = 'woocommerce_subscription_expired_';
- break;
- default:
- $hook_prefix = apply_filters( 'woocommerce_subscriptions_gateway_status_updated_hook_prefix', 'woocommerce_subscription_status_updated_', $subscription, $new_status );
- break;
- }
-
- do_action( $hook_prefix . $subscription->get_payment_method(), $subscription );
}
/**
@@ -193,147 +99,37 @@ class WC_Subscriptions_Payment_Gateways {
}
/**
- * Fire a gateway specific hook for when a subscription payment is due.
+ * Returns whether the subscription payment gateway has an available gateway.
*
- * @since 1.0
+ * @since 4.0.0
+ * @param WC_Subscription $subscription Subscription to check if the gateway is available.
+ * @return bool
*/
- public static function gateway_scheduled_subscription_payment( $subscription_id, $deprecated = null ) {
-
- // Passing the old $user_id/$subscription_key parameters
- if ( null != $deprecated ) {
- _deprecated_argument( __METHOD__, '2.0', 'Second parameter is deprecated' );
- $subscription = wcs_get_subscription_from_key( $deprecated );
- } elseif ( ! is_object( $subscription_id ) ) {
- $subscription = wcs_get_subscription( $subscription_id );
- } else {
- // Support receiving a full subscription object for unit testing
- $subscription = $subscription_id;
- }
-
- if ( false === $subscription ) {
- // translators: %d: subscription ID.
- throw new InvalidArgumentException( sprintf( __( 'Subscription doesn\'t exist in scheduled action: %d', 'woocommerce-subscriptions' ), $subscription_id ) );
- }
-
- if ( ! $subscription->is_manual() && ! $subscription->has_status( wcs_get_subscription_ended_statuses() ) ) {
- self::trigger_gateway_renewal_payment_hook( $subscription->get_last_order( 'all', 'renewal' ) );
- }
+ public static function has_available_payment_method( $subscription ) {
+ return wc_get_payment_gateway_by_order( $subscription ) ? true : false;
}
/**
- * Display a list of each gateway supported features in a tooltip
+ * Returns whether the gateway supports subscriptions and automatic renewals.
*
- * @since 2.5.0
+ * @since 4.0.0
+ * @param WC_Gateway $gateway Gateway to check if it supports subscriptions.
+ * @return bool
*/
- public static function payment_gateways_support_tooltip( $status_html, $gateway ) {
-
- if ( ( ! is_array( $gateway->supports ) || ! in_array( 'subscriptions', $gateway->supports ) ) && 'paypal' !== $gateway->id ) {
- return $status_html;
- }
-
- $core_features = (array) apply_filters( 'woocommerce_subscriptions_payment_gateway_features_list', $gateway->supports, $gateway );
- $subscription_features = $change_payment_method_features = array();
-
- foreach ( $core_features as $key => $feature ) {
-
- // Skip any non-subscription related features.
- if ( 'gateway_scheduled_payments' !== $feature && false === strpos( $feature, 'subscription' ) ) {
- continue;
- }
-
- $feature = str_replace( 'subscription_', '', $feature );
-
- if ( 0 === strpos( $feature, 'payment_method' ) ) {
- switch ( $feature ) {
- case 'payment_method_change':
- $change_payment_method_features[] = 'payment method change';
- break;
-
- case 'payment_method_change_customer':
- $change_payment_method_features[] = 'customer change payment';
- break;
-
- case 'payment_method_change_admin':
- $change_payment_method_features[] = 'admin change payment';
- break;
-
- default:
- $change_payment_method_features[] = str_replace( 'payment_method', ' ', $feature );
- break;
- }
- } else {
- $subscription_features[] = $feature;
- }
-
- unset( $core_features[ $key ] );
- }
-
- $status_html .= ' ';
-
- $allowed_html = wp_kses_allowed_html( 'post' );
- $allowed_html['span']['data-tip'] = true;
-
- return wp_kses( $status_html, $allowed_html );
+ public static function gateway_supports_subscriptions( $gateway ) {
+ return ( is_array( $gateway->supports ) && in_array( 'subscriptions', $gateway->supports, true ) ) || 'paypal' === $gateway->id;
}
/**
- * Fire a gateway specific hook for when a subscription is activated.
- *
- * @since 1.0
+ * Add links to find additional payment gateways to information after the Settings->Payments->Payment Methods table.
*/
- public static function trigger_gateway_activated_subscription_hook( $user_id, $subscription_key ) {
- _deprecated_function( __METHOD__, '2.0', __CLASS__ . '::trigger_gateway_status_updated_hook()' );
- self::trigger_gateway_status_updated_hook( wcs_get_subscription_from_key( $subscription_key ), 'active' );
- }
-
- /**
- * Fire a gateway specific hook for when a subscription is activated.
- *
- * @since 1.0
- */
- public static function trigger_gateway_reactivated_subscription_hook( $user_id, $subscription_key ) {
- _deprecated_function( __METHOD__, '2.0', __CLASS__ . '::trigger_gateway_status_updated_hook()' );
- self::trigger_gateway_status_updated_hook( wcs_get_subscription_from_key( $subscription_key ), 'active' );
- }
-
- /**
- * Fire a gateway specific hook for when a subscription is on-hold.
- *
- * @since 1.2
- */
- public static function trigger_gateway_subscription_put_on_hold_hook( $user_id, $subscription_key ) {
- _deprecated_function( __METHOD__, '2.0', __CLASS__ . '::trigger_gateway_status_updated_hook()' );
- self::trigger_gateway_status_updated_hook( wcs_get_subscription_from_key( $subscription_key ), 'on-hold' );
- }
-
- /**
- * Fire a gateway specific when a subscription is cancelled.
- *
- * @since 1.0
- */
- public static function trigger_gateway_cancelled_subscription_hook( $user_id, $subscription_key ) {
- _deprecated_function( __METHOD__, '2.0', __CLASS__ . '::trigger_gateway_status_updated_hook()' );
- self::trigger_gateway_status_updated_hook( wcs_get_subscription_from_key( $subscription_key ), 'cancelled' );
- }
-
- /**
- * Fire a gateway specific hook when a subscription expires.
- *
- * @since 1.0
- */
- public static function trigger_gateway_subscription_expired_hook( $user_id, $subscription_key ) {
- _deprecated_function( __METHOD__, '2.0', __CLASS__ . '::trigger_gateway_status_updated_hook()' );
- self::trigger_gateway_status_updated_hook( wcs_get_subscription_from_key( $subscription_key ), 'expired' );
+ public static function add_recurring_payment_gateway_information( $settings, $option_prefix ) {
+ $settings[] = array(
+ // translators: $1-$2: opening and closing tags. Link to documents->payment gateways, 3$-4$: opening and closing tags. Link to WooCommerce extensions shop page
+ 'desc' => sprintf( __( 'Find new gateways that %1$ssupport automatic subscription payments%2$s in the official %3$sWooCommerce Marketplace%4$s.', 'woocommerce-subscriptions' ), '', ' ', '', ' ' ),
+ 'id' => $option_prefix . '_payment_gateways_additional',
+ 'type' => 'informational',
+ );
+ return $settings;
}
}
diff --git a/includes/libraries/action-scheduler/action-scheduler.php b/includes/libraries/action-scheduler/action-scheduler.php
deleted file mode 100644
index 4ffb266..0000000
--- a/includes/libraries/action-scheduler/action-scheduler.php
+++ /dev/null
@@ -1,53 +0,0 @@
-.
- *
- */
-
-if ( ! function_exists( 'action_scheduler_register_3_dot_0_dot_1' ) ) {
-
- 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_3_dot_0_dot_1', 0, 0 );
-
- function action_scheduler_register_3_dot_0_dot_1() {
- $versions = ActionScheduler_Versions::instance();
- $versions->register( '3.0.1', 'action_scheduler_initialize_3_dot_0_dot_1' );
- }
-
- function action_scheduler_initialize_3_dot_0_dot_1() {
- require_once( 'classes/abstracts/ActionScheduler.php' );
- ActionScheduler::init( __FILE__ );
- }
-
- // Support usage in themes - load this version if no plugin has loaded a version yet.
- if ( did_action( 'plugins_loaded' ) && ! class_exists( 'ActionScheduler' ) ) {
- action_scheduler_register_3_dot_0_dot_1();
- do_action( 'action_scheduler_pre_theme_init' );
- ActionScheduler_Versions::initialize_latest_version();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php b/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php
deleted file mode 100644
index 8b56816..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_ActionClaim.php
+++ /dev/null
@@ -1,23 +0,0 @@
-id = $id;
- $this->action_ids = $action_ids;
- }
-
- public function get_id() {
- return $this->id;
- }
-
- public function get_actions() {
- return $this->action_ids;
- }
-}
-
\ 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
deleted file mode 100644
index 890e8a6..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_ActionFactory.php
+++ /dev/null
@@ -1,179 +0,0 @@
-get_date() );
- }
- 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 );
- }
-
- /**
- * Enqueue an action to run one time, as soon as possible (rather a specific scheduled time).
- *
- * This method creates a new action with the NULLSchedule. This schedule maps to a MySQL datetime string of
- * 0000-00-00 00:00:00. This is done to create a psuedo "async action" type that is fully backward compatible.
- * Existing queries to claim actions claim by date, meaning actions scheduled for 0000-00-00 00:00:00 will
- * always be claimed prior to actions scheduled for a specific date. This makes sure that any async action is
- * given priority in queue processing. This has the added advantage of making sure async actions can be
- * claimed by both the existing WP Cron and WP CLI runners, as well as a new async request runner.
- *
- * @param string $hook The hook to trigger when this action runs
- * @param array $args Args to pass when the hook is triggered
- * @param string $group A group to put the action in
- *
- * @return string The ID of the stored action
- */
- public function async( $hook, $args = array(), $group = '' ) {
- $schedule = new ActionScheduler_NullSchedule();
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
- return $this->store( $action );
- }
-
- /**
- * @param string $hook The hook to trigger when this action runs
- * @param array $args Args to pass when the hook is triggered
- * @param int $when Unix timestamp when the action will run
- * @param string $group A group to put the action in
- *
- * @return string The ID of the stored action
- */
- 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 );
- return $this->store( $action );
- }
-
- /**
- * Create the first instance of an action recurring on a given interval.
- *
- * @param string $hook The hook to trigger when this action runs
- * @param array $args Args to pass when the hook is triggered
- * @param int $first Unix timestamp for the first run
- * @param int $interval Seconds between runs
- * @param string $group A group to put the action in
- *
- * @return string The ID of the stored action
- */
- public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) {
- if ( empty($interval) ) {
- return $this->single( $hook, $args, $first, $group );
- }
- $date = as_get_datetime_object( $first );
- $schedule = new ActionScheduler_IntervalSchedule( $date, $interval );
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
- return $this->store( $action );
- }
-
- /**
- * Create the first instance of an action recurring on a Cron schedule.
- *
- * @param string $hook The hook to trigger when this action runs
- * @param array $args Args to pass when the hook is triggered
- * @param int $base_timestamp The first instance of the action will be scheduled
- * to run at a time calculated after this timestamp matching the cron
- * expression. This can be used to delay the first instance of the action.
- * @param int $schedule A cron definition string
- * @param string $group A group to put the action in
- *
- * @return string The ID of the stored action
- */
- public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) {
- if ( empty($schedule) ) {
- return $this->single( $hook, $args, $base_timestamp, $group );
- }
- $date = as_get_datetime_object( $base_timestamp );
- $cron = CronExpression::factory( $schedule );
- $schedule = new ActionScheduler_CronSchedule( $date, $cron );
- $action = new ActionScheduler_Action( $hook, $args, $schedule, $group );
- return $this->store( $action );
- }
-
- /**
- * Create a successive instance of a recurring or cron action.
- *
- * Importantly, the action will be rescheduled to run based on the current date/time.
- * That means when the action is scheduled to run in the past, the next scheduled date
- * will be pushed forward. For example, if a recurring action set to run every hour
- * was scheduled to run 5 seconds ago, it will be next scheduled for 1 hour in the
- * future, which is 1 hour and 5 seconds from when it was last scheduled to run.
- *
- * Alternatively, if the action is scheduled to run in the future, and is run early,
- * likely via manual intervention, then its schedule will change based on the time now.
- * For example, if a recurring action set to run every day, and is run 12 hours early,
- * it will run again in 24 hours, not 36 hours.
- *
- * This slippage is less of an issue with Cron actions, as the specific run time can
- * be set for them to run, e.g. 1am each day. In those cases, and entire period would
- * need to be missed before there was any change is scheduled, e.g. in the case of an
- * action scheduled for 1am each day, the action would need to run an entire day late.
- *
- * @param ActionScheduler_Action $action The existing action.
- *
- * @return string The ID of the stored action
- * @throws InvalidArgumentException If $action is not a recurring action.
- */
- public function repeat( $action ) {
- $schedule = $action->get_schedule();
- $next = $schedule->get_next( as_get_datetime_object() );
-
- if ( is_null( $next ) || ! $schedule->is_recurring() ) {
- throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'action-scheduler' ) );
- }
-
- $schedule_class = get_class( $schedule );
- $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() );
- $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() );
- return $this->store( $new_action );
- }
-
- /**
- * @param ActionScheduler_Action $action
- *
- * @return string The ID of the stored action
- */
- protected function store( ActionScheduler_Action $action ) {
- $store = ActionScheduler_Store::instance();
- return $store->save_action( $action );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php b/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php
deleted file mode 100644
index b46ddc2..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_AdminView.php
+++ /dev/null
@@ -1,137 +0,0 @@
-render();
- }
-
- /**
- * 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;
- }
-
- /**
- * Include Action Scheduler's administration under the Tools menu.
- *
- * 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 register_menu() {
- $hook_suffix = add_submenu_page(
- 'tools.php',
- __( 'Scheduled Actions', 'action-scheduler' ),
- __( 'Scheduled Actions', 'action-scheduler' ),
- 'manage_options',
- 'action-scheduler',
- array( $this, 'render_admin_ui' )
- );
- add_action( 'load-' . $hook_suffix , array( $this, 'process_admin_ui' ) );
- }
-
- /**
- * Triggers processing of any pending actions.
- */
- public function process_admin_ui() {
- $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
- $table->process_actions();
- }
-
- /**
- * Renders the Admin UI
- */
- public function render_admin_ui() {
- $table = new ActionScheduler_ListTable( ActionScheduler::store(), ActionScheduler::logger(), ActionScheduler::runner() );
- $table->display_page();
- }
-
- /**
- * Provide more information about the screen and its data in the help tab.
- */
- public function add_help_tabs() {
- $screen = get_current_screen();
-
- if ( ! $screen || self::$screen_id != $screen->id ) {
- return;
- }
-
- $screen->add_help_tab(
- array(
- 'id' => 'action_scheduler_about',
- 'title' => __( 'About', 'action-scheduler' ),
- 'content' =>
- '' . __( 'About Action Scheduler', 'action-scheduler' ) . ' ' .
- '' .
- __( 'Action Scheduler is a scalable, traceable job queue for background processing large sets of actions. Action Scheduler works by triggering an action hook to run at some time in the future. Scheduled actions can also be scheduled to run on a recurring schedule.', 'action-scheduler' ) .
- '
',
- )
- );
-
- $screen->add_help_tab(
- array(
- 'id' => 'action_scheduler_columns',
- 'title' => __( 'Columns', 'action-scheduler' ),
- 'content' =>
- '' . __( 'Scheduled Action Columns', 'action-scheduler' ) . ' ' .
- '' .
- sprintf( '%1$s : %2$s ', __( 'Hook', 'action-scheduler' ), __( 'Name of the action hook that will be triggered.', 'action-scheduler' ) ) .
- sprintf( '%1$s : %2$s ', __( 'Status', 'action-scheduler' ), __( 'Action statuses are Pending, Complete, Canceled, Failed', 'action-scheduler' ) ) .
- sprintf( '%1$s : %2$s ', __( 'Arguments', 'action-scheduler' ), __( 'Optional data array passed to the action hook.', 'action-scheduler' ) ) .
- sprintf( '%1$s : %2$s ', __( 'Group', 'action-scheduler' ), __( 'Optional action group.', 'action-scheduler' ) ) .
- sprintf( '%1$s : %2$s ', __( 'Recurrence', 'action-scheduler' ), __( 'The action\'s schedule frequency.', 'action-scheduler' ) ) .
- sprintf( '%1$s : %2$s ', __( 'Scheduled', 'action-scheduler' ), __( 'The date/time the action is/was scheduled to run.', 'action-scheduler' ) ) .
- sprintf( '%1$s : %2$s ', __( 'Log', 'action-scheduler' ), __( 'Activity log for the action.', 'action-scheduler' ) ) .
- ' ',
- )
- );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php
deleted file mode 100644
index c1ab036..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_AsyncRequest_QueueRunner.php
+++ /dev/null
@@ -1,96 +0,0 @@
-store = $store;
- }
-
- /**
- * Handle async requests
- *
- * Run a queue, and maybe dispatch another async request to run another queue
- * if there are still pending actions after completing a queue in this request.
- */
- protected function handle() {
- do_action( 'action_scheduler_run_queue', 'Async Request' ); // run a queue in the same way as WP Cron, but declare the Async Request context
-
- $sleep_seconds = $this->get_sleep_seconds();
-
- if ( $sleep_seconds ) {
- sleep( $sleep_seconds );
- }
-
- $this->maybe_dispatch();
- }
-
- /**
- * If the async request runner is needed and allowed to run, dispatch a request.
- */
- public function maybe_dispatch() {
- if ( ! $this->allow() ) {
- return;
- }
-
- $this->dispatch();
- }
-
- /**
- * Only allow async requests when needed.
- *
- * Also allow 3rd party code to disable running actions via async requests.
- */
- protected function allow() {
-
- if ( ! has_action( 'action_scheduler_run_queue' ) || ActionScheduler::runner()->has_maximum_concurrent_batches() || ! $this->store->has_pending_actions_due() ) {
- $allow = false;
- } else {
- $allow = true;
- }
-
- return apply_filters( 'action_scheduler_allow_async_request_runner', $allow );
- }
-
- /**
- * Chaining async requests can crash MySQL. A brief sleep call in PHP prevents that.
- */
- protected function get_sleep_seconds() {
- return apply_filters( 'action_scheduler_async_request_sleep_seconds', 1, $this );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php
deleted file mode 100644
index c06e5a4..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_Compatibility.php
+++ /dev/null
@@ -1,99 +0,0 @@
- $wp_max_limit_int && $filtered_limit_int > $current_limit_int ) ) {
- if ( false !== @ini_set( 'memory_limit', $filtered_limit ) ) {
- return $filtered_limit;
- } else {
- return false;
- }
- } elseif ( -1 === $wp_max_limit_int || $wp_max_limit_int > $current_limit_int ) {
- if ( false !== @ini_set( 'memory_limit', $wp_max_limit ) ) {
- return $wp_max_limit;
- } else {
- return false;
- }
- }
- return false;
- }
-
- /**
- * Attempts to raise the PHP timeout for time intensive processes.
- *
- * Only allows raising the existing limit and prevents lowering it. Wrapper for wc_set_time_limit(), when available.
- *
- * @param int The time limit in seconds.
- */
- public static function raise_time_limit( $limit = 0 ) {
- if ( $limit < ini_get( 'max_execution_time' ) ) {
- return;
- }
-
- if ( function_exists( 'wc_set_time_limit' ) ) {
- wc_set_time_limit( $limit );
- } elseif ( function_exists( 'set_time_limit' ) && false === strpos( ini_get( 'disable_functions' ), 'set_time_limit' ) && ! ini_get( 'safe_mode' ) ) {
- @set_time_limit( $limit );
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php b/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php
deleted file mode 100644
index d2c889b..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_DataController.php
+++ /dev/null
@@ -1,177 +0,0 @@
-=' );
- return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
- }
-
- /**
- * Get a flag indicating whether the migration is complete.
- *
- * @return bool Whether the flag has been set marking the migration as complete
- */
- public static function is_migration_complete() {
- return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE;
- }
-
- /**
- * Mark the migration as complete.
- */
- public static function mark_migration_complete() {
- update_option( self::STATUS_FLAG, self::STATUS_COMPLETE );
- }
-
- /**
- * Set the action store class name.
- *
- * @param string $class Classname of the store class.
- *
- * @return string
- */
- public static function set_store_class( $class ) {
- return self::DATASTORE_CLASS;
- }
-
- /**
- * Set the action logger class name.
- *
- * @param string $class Classname of the logger class.
- *
- * @return string
- */
- public static function set_logger_class( $class ) {
- return self::LOGGER_CLASS;
- }
-
- /**
- * Set the sleep time in seconds.
- *
- * @param integer $sleep_time The number of seconds to pause before resuming operation.
- */
- public static function set_sleep_time( $sleep_time ) {
- self::$sleep_time = $sleep_time;
- }
-
- /**
- * Set the tick count required for freeing memory.
- *
- * @param integer $free_ticks The number of ticks to free memory on.
- */
- public static function set_free_ticks( $free_ticks ) {
- self::$free_ticks = $free_ticks;
- }
-
- /**
- * Free memory if conditions are met.
- *
- * @param int $ticks Current tick count.
- */
- public static function maybe_free_memory( $ticks ) {
- if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) {
- self::free_memory();
- }
- }
-
- /**
- * Reduce memory footprint by clearing the database query and object caches.
- */
- public static function free_memory() {
- if ( 0 < self::$sleep_time ) {
- /* translators: %d: amount of time */
- \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) );
- sleep( self::$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_a( $wp_object_cache, '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
- }
- }
-
- /**
- * Connect to table datastores if migration is complete.
- * Otherwise, proceed with the migration if the dependencies have been met.
- */
- public static function init() {
- if ( self::is_migration_complete() ) {
- add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 );
- add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 );
- } elseif ( self::dependencies_met() ) {
- Controller::init();
- }
-
- add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) );
- }
-
- /**
- * Singleton factory.
- */
- public static function instance() {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new static();
- }
-
- return self::$instance;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php b/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php
deleted file mode 100644
index 5e8743c..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_DateTime.php
+++ /dev/null
@@ -1,76 +0,0 @@
-format( 'U' );
- }
-
- /**
- * Set the UTC offset.
- *
- * This represents a fixed offset instead of a timezone setting.
- *
- * @param $offset
- */
- public function setUtcOffset( $offset ) {
- $this->utcOffset = intval( $offset );
- }
-
- /**
- * Returns the timezone offset.
- *
- * @return int
- * @link http://php.net/manual/en/datetime.getoffset.php
- */
- public function getOffset() {
- return $this->utcOffset ? $this->utcOffset : parent::getOffset();
- }
-
- /**
- * Set the TimeZone associated with the DateTime
- *
- * @param DateTimeZone $timezone
- *
- * @return static
- * @link http://php.net/manual/en/datetime.settimezone.php
- */
- public function setTimezone( $timezone ) {
- $this->utcOffset = 0;
- parent::setTimezone( $timezone );
-
- return $this;
- }
-
- /**
- * Get the timestamp with the WordPress timezone offset added or subtracted.
- *
- * @since 3.0.0
- * @return int
- */
- public function getOffsetTimestamp() {
- return $this->getTimestamp() + $this->getOffset();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php
deleted file mode 100644
index 353d3c0..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_Exception.php
+++ /dev/null
@@ -1,11 +0,0 @@
-store = $store;
- }
-
- public function attach( ActionScheduler_ActionClaim $claim ) {
- $this->claim = $claim;
- add_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
- add_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0, 1 );
- add_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0, 0 );
- add_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0, 0 );
- add_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0, 0 );
- }
-
- public function detach() {
- $this->claim = NULL;
- $this->untrack_action();
- remove_action( 'shutdown', array( $this, 'handle_unexpected_shutdown' ) );
- remove_action( 'action_scheduler_before_execute', array( $this, 'track_current_action' ), 0 );
- remove_action( 'action_scheduler_after_execute', array( $this, 'untrack_action' ), 0 );
- remove_action( 'action_scheduler_execution_ignored', array( $this, 'untrack_action' ), 0 );
- remove_action( 'action_scheduler_failed_execution', array( $this, 'untrack_action' ), 0 );
- }
-
- public function track_current_action( $action_id ) {
- $this->action_id = $action_id;
- }
-
- public function untrack_action() {
- $this->action_id = 0;
- }
-
- public function handle_unexpected_shutdown() {
- if ( $error = error_get_last() ) {
- if ( in_array( $error['type'], array( E_ERROR, E_PARSE, E_COMPILE_ERROR, E_USER_ERROR, E_RECOVERABLE_ERROR ) ) ) {
- if ( !empty($this->action_id) ) {
- $this->store->mark_failure( $this->action_id );
- do_action( 'action_scheduler_unexpected_shutdown', $this->action_id, $error );
- }
- }
- $this->store->release_claim( $this->claim );
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php b/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php
deleted file mode 100644
index 40b4559..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_InvalidActionException.php
+++ /dev/null
@@ -1,47 +0,0 @@
- 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,
- /* translators: %s: amount of time */
- 'names' => _n_noop( '%s year', '%s years', 'action-scheduler' ),
- ),
- array(
- 'seconds' => MONTH_IN_SECONDS,
- /* translators: %s: amount of time */
- 'names' => _n_noop( '%s month', '%s months', 'action-scheduler' ),
- ),
- array(
- 'seconds' => WEEK_IN_SECONDS,
- /* translators: %s: amount of time */
- 'names' => _n_noop( '%s week', '%s weeks', 'action-scheduler' ),
- ),
- array(
- 'seconds' => DAY_IN_SECONDS,
- /* translators: %s: amount of time */
- 'names' => _n_noop( '%s day', '%s days', 'action-scheduler' ),
- ),
- array(
- 'seconds' => HOUR_IN_SECONDS,
- /* translators: %s: amount of time */
- 'names' => _n_noop( '%s hour', '%s hours', 'action-scheduler' ),
- ),
- array(
- 'seconds' => MINUTE_IN_SECONDS,
- /* translators: %s: amount of time */
- 'names' => _n_noop( '%s minute', '%s minutes', 'action-scheduler' ),
- ),
- array(
- 'seconds' => 1,
- /* translators: %s: amount of time */
- '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 ) {
- $schedule = $action->get_schedule();
- if ( $schedule->is_recurring() ) {
- $recurrence = $schedule->get_recurrence();
-
- if ( is_numeric( $recurrence ) ) {
- /* translators: %s: time interval */
- return sprintf( __( 'Every %s', 'action-scheduler' ), self::human_interval( $recurrence ) );
- } else {
- return $recurrence;
- }
- }
-
- 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( var_export( $key, true ) ), esc_html( var_export( $value, true ) ) );
- }
- $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 O' ) ), 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->runner->has_maximum_concurrent_batches() ) {
- $this->admin_notices[] = array(
- 'class' => 'updated',
- 'message' => sprintf(
- /* translators: %s: amount of claims */
- __( 'Maximum simultaneous queues already in progress (%s queues). No additional queues will begin processing until the current queues are complete.', 'action-scheduler' ),
- $this->store->get_claim_count()
- ),
- );
- } elseif ( $this->store->has_pending_actions_due() ) {
-
- $async_request_lock_expiration = ActionScheduler::lock()->get_expiration( 'async-request-runner' );
-
- // No lock set or lock expired
- if ( false === $async_request_lock_expiration || $async_request_lock_expiration < time() ) {
- $in_progress_url = add_query_arg( 'status', 'in-progress', remove_query_arg( 'status' ) );
- /* translators: %s: process URL */
- $async_request_message = sprintf( __( 'A new queue has begun processing. View actions in-progress » ', 'action-scheduler' ), esc_url( $in_progress_url ) );
- } else {
- /* translators: %d: seconds */
- $async_request_message = sprintf( __( 'The next queue will begin processing in approximately %d seconds.', 'action-scheduler' ), $async_request_lock_expiration - time() );
- }
-
- $this->admin_notices[] = array(
- 'class' => 'notice notice-info',
- 'message' => $async_request_message,
- );
- }
-
- $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' :
- /* translators: %s: action HTML */
- $action_message_html = sprintf( __( 'Successfully executed action: %s', 'action-scheduler' ), $action_hook_html );
- break;
- case 'cancel' :
- /* translators: %s: action HTML */
- $action_message_html = sprintf( __( 'Successfully canceled action: %s', 'action-scheduler' ), $action_hook_html );
- break;
- default :
- /* translators: %s: action HTML */
- $action_message_html = sprintf( __( 'Successfully processed change for action: %s', 'action-scheduler' ), $action_hook_html );
- break;
- }
- } else {
- $class = 'error';
- /* translators: 1: action HTML 2: action ID 3: error message */
- $action_message_html = sprintf( __( 'Could not process change for action: "%1$s" (ID: %2$d). Error: %3$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->get_date() ) {
- return '0000-00-00 00:00:00';
- }
-
- $next_timestamp = $schedule->get_date()->getTimestamp();
-
- $schedule_display_string .= $schedule->get_date()->format( 'Y-m-d H:i:s O' );
- $schedule_display_string .= ' ';
-
- if ( gmdate( 'U' ) > $next_timestamp ) {
- /* translators: %s: date interval */
- $schedule_display_string .= sprintf( __( ' (%s ago)', 'action-scheduler' ), self::human_interval( gmdate( 'U' ) - $next_timestamp ) );
- } else {
- /* translators: %s: date interval */
- $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, 'Admin List Table' );
- 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->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
deleted file mode 100644
index 649636d..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_LogEntry.php
+++ /dev/null
@@ -1,67 +0,0 @@
-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->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() {
- return $this->action_id;
- }
-
- public function get_message() {
- return $this->message;
- }
-}
-
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php b/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php
deleted file mode 100644
index 6f8f218..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_NullLogEntry.php
+++ /dev/null
@@ -1,11 +0,0 @@
-maybe_dispatch_async_request() uses a lock to avoid
- * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown',
- * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count()
- * to find the current number of claims in the database.
- *
- * @param string $lock_type A string to identify different lock types.
- * @bool True if lock value has changed, false if not or if set failed.
- */
- public function set( $lock_type ) {
- return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) );
- }
-
- /**
- * If a lock is set, return the timestamp it was set to expiry.
- *
- * @param string $lock_type A string to identify different lock types.
- * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
- */
- public function get_expiration( $lock_type ) {
- return get_option( $this->get_key( $lock_type ) );
- }
-
- /**
- * Get the key to use for storing the lock in the transient
- *
- * @param string $lock_type A string to identify different lock types.
- * @return string
- */
- protected function get_key( $lock_type ) {
- return sprintf( 'action_scheduler_lock_%s', $lock_type );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php
deleted file mode 100644
index 1da13ab..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueCleaner.php
+++ /dev/null
@@ -1,155 +0,0 @@
-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');
-
- $statuses_to_purge = array(
- ActionScheduler_Store::STATUS_COMPLETE,
- ActionScheduler_Store::STATUS_CANCELED,
- );
-
- 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 ) );
- }
- }
- }
- }
-
- /**
- * Unclaim pending actions that have not been run within a given time limit.
- *
- * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
- * as a parameter is 10x the time limit used for queue processing.
- *
- * @param int $time_limit The number of seconds to allow a queue to run before unclaiming its pending actions. Default 300 (5 minutes).
- */
- public function reset_timeouts( $time_limit = 300 ) {
- $timeout = apply_filters( 'action_scheduler_timeout_period', $time_limit );
- if ( $timeout < 0 ) {
- return;
- }
- $cutoff = as_get_datetime_object($timeout.' seconds ago');
- $actions_to_reset = $this->store->query_actions( array(
- 'status' => ActionScheduler_Store::STATUS_PENDING,
- 'modified' => $cutoff,
- 'modified_compare' => '<=',
- 'claimed' => true,
- 'per_page' => $this->get_batch_size(),
- ) );
-
- foreach ( $actions_to_reset as $action_id ) {
- $this->store->unclaim_action( $action_id );
- do_action( 'action_scheduler_reset_action', $action_id );
- }
- }
-
- /**
- * Mark actions that have been running for more than a given time limit as failed, based on
- * the assumption some uncatachable and unloggable fatal error occurred during processing.
- *
- * When called by ActionScheduler_Abstract_QueueRunner::run_cleanup(), the time limit passed
- * as a parameter is 10x the time limit used for queue processing.
- *
- * @param int $time_limit The number of seconds to allow an action to run before it is considered to have failed. Default 300 (5 minutes).
- */
- public function mark_failures( $time_limit = 300 ) {
- $timeout = apply_filters( 'action_scheduler_failure_period', $time_limit );
- if ( $timeout < 0 ) {
- return;
- }
- $cutoff = as_get_datetime_object($timeout.' seconds ago');
- $actions_to_reset = $this->store->query_actions( array(
- 'status' => ActionScheduler_Store::STATUS_RUNNING,
- 'modified' => $cutoff,
- 'modified_compare' => '<=',
- 'per_page' => $this->get_batch_size(),
- ) );
-
- foreach ( $actions_to_reset as $action_id ) {
- $this->store->mark_failure( $action_id );
- do_action( 'action_scheduler_failed_action', $action_id, $timeout );
- }
- }
-
- /**
- * Do all of the cleaning actions.
- *
- * @param int $time_limit The number of seconds to use as the timeout and failure period. Default 300 (5 minutes).
- * @author Jeremy Pry
- */
- public function clean( $time_limit = 300 ) {
- $this->delete_old_actions();
- $this->reset_timeouts( $time_limit );
- $this->mark_failures( $time_limit );
- }
-
- /**
- * 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 ) );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php
deleted file mode 100644
index 25073c7..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_QueueRunner.php
+++ /dev/null
@@ -1,185 +0,0 @@
-store );
- }
-
- $this->async_request = $async_request;
- }
-
- /**
- * @codeCoverageIgnore
- */
- public function init() {
-
- add_filter( 'cron_schedules', array( self::instance(), 'add_wp_cron_schedule' ) );
-
- $cron_context = array( 'WP Cron' );
-
- if ( ! wp_next_scheduled( self::WP_CRON_HOOK, $cron_context ) ) {
-
- // Check for and remove any WP Cron hook scheduled by Action Scheduler < 3.0.0, which didn't include the $context param
- $next_timestamp = wp_next_scheduled( self::WP_CRON_HOOK );
- if ( $next_timestamp ) {
- wp_unschedule_event( $next_timestamp, self::WP_CRON_HOOK );
- }
-
- $schedule = apply_filters( 'action_scheduler_run_schedule', self::WP_CRON_SCHEDULE );
- wp_schedule_event( time(), $schedule, self::WP_CRON_HOOK, $cron_context );
- }
-
- add_action( self::WP_CRON_HOOK, array( self::instance(), 'run' ) );
-
- add_filter( 'shutdown', array( $this, 'maybe_dispatch_async_request' ) );
- }
-
- /**
- * Check if we should dispatch an async request to process actions.
- *
- * This method is attached to 'shutdown', so is called frequently. To avoid slowing down
- * the site, it mitigates the work performed in each request by:
- * 1. checking if it's in the admin context and then
- * 2. haven't run on the 'shutdown' hook within the lock time (60 seconds by default)
- * 3. haven't exceeded the number of allowed batches.
- *
- * The order of these checks is important, because they run from a check on a value:
- * 1. in memory - is_admin() maps to $GLOBALS or the WP_ADMIN constant
- * 2. in memory - transients use autoloaded options by default
- * 3. from a database query - has_maximum_concurrent_batches() run the query
- * $this->store->get_claim_count() to find the current number of claims in the DB.
- *
- * If all of these conditions are met, then we request an async runner check whether it
- * should dispatch a request to process pending actions.
- */
- public function maybe_dispatch_async_request() {
- if ( is_admin() && ! ActionScheduler::lock()->is_locked( 'async-request-runner' ) ) {
- // Only start an async queue at most once every 60 seconds
- ActionScheduler::lock()->set( 'async-request-runner' );
- $this->async_request->maybe_dispatch();
- }
- }
-
- /**
- * Process actions in the queue. Attached to self::WP_CRON_HOOK i.e. 'action_scheduler_run_queue'
- *
- * The $context param of this method defaults to 'WP Cron', because prior to Action Scheduler 3.0.0
- * that was the only context in which this method was run, and the self::WP_CRON_HOOK hook had no context
- * passed along with it. New code calling this method directly, or by triggering the self::WP_CRON_HOOK,
- * should set a context as the first parameter. For an example of this, refer to the code seen in
- * @see ActionScheduler_AsyncRequest_QueueRunner::handle()
- *
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
- * Generally, this should be capitalised and not localised as it's a proper noun.
- * @return int The number of actions processed.
- */
- public function run( $context = 'WP Cron' ) {
- ActionScheduler_Compatibility::raise_memory_limit();
- ActionScheduler_Compatibility::raise_time_limit( $this->get_time_limit() );
- do_action( 'action_scheduler_before_process_queue' );
- $this->run_cleanup();
- $processed_actions = 0;
- if ( false === $this->has_maximum_concurrent_batches() ) {
- $batch_size = apply_filters( 'action_scheduler_queue_runner_batch_size', 25 );
- do {
- $processed_actions_in_batch = $this->do_batch( $batch_size, $context );
- $processed_actions += $processed_actions_in_batch;
- } while ( $processed_actions_in_batch > 0 && ! $this->batch_limits_exceeded( $processed_actions ) ); // keep going until we run out of actions, time, or memory
- }
-
- do_action( 'action_scheduler_after_process_queue' );
- return $processed_actions;
- }
-
- /**
- * Process a batch of actions pending in the queue.
- *
- * Actions are processed by claiming a set of pending actions then processing each one until either the batch
- * size is completed, or memory or time limits are reached, defined by @see $this->batch_limits_exceeded().
- *
- * @param int $size The maximum number of actions to process in the batch.
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
- * Generally, this should be capitalised and not localised as it's a proper noun.
- * @return int The number of actions processed.
- */
- protected function do_batch( $size = 100, $context = '' ) {
- $claim = $this->store->stake_claim($size);
- $this->monitor->attach($claim);
- $processed_actions = 0;
-
- foreach ( $claim->get_actions() as $action_id ) {
- // bail if we lost the claim
- if ( ! in_array( $action_id, $this->store->find_actions_by_claim_id( $claim->get_id() ) ) ) {
- break;
- }
- $this->process_action( $action_id, $context );
- $processed_actions++;
-
- if ( $this->batch_limits_exceeded( $processed_actions ) ) {
- break;
- }
- }
- $this->store->release_claim($claim);
- $this->monitor->detach();
- $this->clear_caches();
- return $processed_actions;
- }
-
- /**
- * Running large batches can eat up memory, as WP adds data to its object cache.
- *
- * If using a persistent object store, this has the side effect of flushing that
- * as well, so this is disabled by default. To enable:
- *
- * add_filter( 'action_scheduler_queue_runner_flush_cache', '__return_true' );
- */
- protected function clear_caches() {
- if ( ! wp_using_ext_object_cache() || apply_filters( 'action_scheduler_queue_runner_flush_cache', false ) ) {
- wp_cache_flush();
- }
- }
-
- public function add_wp_cron_schedule( $schedules ) {
- $schedules['every_minute'] = array(
- 'interval' => 60, // in seconds
- 'display' => __( 'Every minute', 'action-scheduler' ),
- );
-
- return $schedules;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php b/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php
deleted file mode 100644
index 915c2e6..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_Versions.php
+++ /dev/null
@@ -1,62 +0,0 @@
-versions[$version_string]) ) {
- return FALSE;
- }
- $this->versions[$version_string] = $initialization_callback;
- return TRUE;
- }
-
- public function get_versions() {
- return $this->versions;
- }
-
- public function latest_version() {
- $keys = array_keys($this->versions);
- if ( empty($keys) ) {
- return false;
- }
- uasort( $keys, 'version_compare' );
- return end($keys);
- }
-
- public function latest_version_callback() {
- $latest = $this->latest_version();
- if ( empty($latest) || !isset($this->versions[$latest]) ) {
- return '__return_null';
- }
- return $this->versions[$latest];
- }
-
- /**
- * @return ActionScheduler_Versions
- * @codeCoverageIgnore
- */
- public static function instance() {
- if ( empty(self::$instance) ) {
- self::$instance = new self();
- }
- return self::$instance;
- }
-
- /**
- * @codeCoverageIgnore
- */
- public static function initialize_latest_version() {
- $self = self::instance();
- call_user_func($self->latest_version_callback());
- }
-}
-
\ No newline at end of file
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php b/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php
deleted file mode 100644
index ceef177..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_WPCommentCleaner.php
+++ /dev/null
@@ -1,108 +0,0 @@
- Status administration screen
- add_action( 'load-tools_page_action-scheduler', array( __CLASS__, 'print_admin_notice' ) );
- add_action( 'load-woocommerce_page_wc-status', array( __CLASS__, 'print_admin_notice' ) );
- }
-
- /**
- * Determines if there are log entries in the wp comments table.
- *
- * Uses the flag set on migration completion set by @see self::maybe_schedule_cleanup().
- *
- * @return boolean Whether there are scheduled action comments in the comments table.
- */
- public static function has_logs() {
- return 'yes' === get_option( self::$has_logs_option_key );
- }
-
- /**
- * Schedules the WP Post comment table cleanup to run in 6 months if it's not already scheduled.
- * Attached to the migration complete hook 'action_scheduler/migration_complete'.
- */
- public static function maybe_schedule_cleanup() {
- if ( (bool) get_comments( array( 'type' => ActionScheduler_wpCommentLogger::TYPE, 'number' => 1, 'fields' => 'ids' ) ) ) {
- update_option( self::$has_logs_option_key, 'yes' );
-
- if ( ! as_next_scheduled_action( self::$cleanup_hook ) ) {
- as_schedule_single_action( gmdate( 'U' ) + ( 6 * MONTH_IN_SECONDS ), self::$cleanup_hook );
- }
- }
- }
-
- /**
- * Delete all action comments from the WP Comments table.
- */
- public static function delete_all_action_comments() {
- global $wpdb;
- $wpdb->delete( $wpdb->comments, array( 'comment_type' => ActionScheduler_wpCommentLogger::TYPE, 'comment_agent' => ActionScheduler_wpCommentLogger::AGENT ) );
- delete_option( self::$has_logs_option_key );
- }
-
- /**
- * Prints details about the orphaned action logs and includes information on where to learn more.
- */
- public static function print_admin_notice() {
- $next_cleanup_message = '';
- $next_scheduled_cleanup_hook = as_next_scheduled_action( self::$cleanup_hook );
-
- if ( $next_scheduled_cleanup_hook ) {
- /* translators: %s: date interval */
- $next_cleanup_message = sprintf( __( 'This data will be deleted in %s.', 'action-scheduler' ), human_time_diff( gmdate( 'U' ), $next_scheduled_cleanup_hook ) );
- }
-
- $notice = sprintf(
- /* translators: 1: next cleanup message 2: github issue URL */
- __( 'Action Scheduler has migrated data to custom tables; however, orphaned log entries exist in the WordPress Comments table. %1$s Learn more » ', 'action-scheduler' ),
- $next_cleanup_message,
- 'https://github.com/woocommerce/action-scheduler/issues/368'
- );
-
- echo '' . wp_kses_post( $notice ) . '
';
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php b/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php
deleted file mode 100644
index 1fc7541..0000000
--- a/includes/libraries/action-scheduler/classes/ActionScheduler_wcSystemStatus.php
+++ /dev/null
@@ -1,147 +0,0 @@
-store = $store;
- }
-
- /**
- * Display action data, including number of actions grouped by status and the oldest & newest action in each status.
- *
- * Helpful to identify issues, like a clogged queue.
- */
- public function render() {
- $action_counts = $this->store->action_counts();
- $status_labels = $this->store->get_status_labels();
- $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) );
-
- $this->get_template( $status_labels, $action_counts, $oldest_and_newest );
- }
-
- /**
- * Get oldest and newest scheduled dates for a given set of statuses.
- *
- * @param array $status_keys Set of statuses to find oldest & newest action for.
- * @return array
- */
- protected function get_oldest_and_newest( $status_keys ) {
-
- $oldest_and_newest = array();
-
- foreach ( $status_keys as $status ) {
- $oldest_and_newest[ $status ] = array(
- 'oldest' => '–',
- 'newest' => '–',
- );
-
- if ( 'in-progress' === $status ) {
- continue;
- }
-
- $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' );
- $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' );
- }
-
- return $oldest_and_newest;
- }
-
- /**
- * Get oldest or newest scheduled date for a given status.
- *
- * @param string $status Action status label/name string.
- * @param string $date_type Oldest or Newest.
- * @return DateTime
- */
- protected function get_action_status_date( $status, $date_type = 'oldest' ) {
-
- $order = 'oldest' === $date_type ? 'ASC' : 'DESC';
-
- $action = $this->store->query_actions( array(
- 'claimed' => false,
- 'status' => $status,
- 'per_page' => 1,
- 'order' => $order,
- ) );
-
- if ( ! empty( $action ) ) {
- $date_object = $this->store->get_date( $action[0] );
- $action_date = $date_object->format( 'Y-m-d H:i:s O' );
- } else {
- $action_date = '–';
- }
-
- return $action_date;
- }
-
- /**
- * Get oldest or newest scheduled date for a given status.
- *
- * @param array $status_labels Set of statuses to find oldest & newest action for.
- * @param array $action_counts Number of actions grouped by status.
- * @param array $oldest_and_newest Date of the oldest and newest action with each status.
- */
- protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) {
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $count ) {
- // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column.
- printf(
- '%1$s %2$s, Oldest: %3$s, Newest: %4$s %3$s %4$s ',
- esc_html( $status_labels[ $status ] ),
- number_format_i18n( $count ),
- $oldest_and_newest[ $status ]['oldest'],
- $oldest_and_newest[ $status ]['newest']
- );
- }
- ?>
-
-
-
- run_cleanup();
- $this->add_hooks();
-
- // Check to make sure there aren't too many concurrent processes running.
- if ( $this->has_maximum_concurrent_batches() ) {
- 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' ), 10, 2 );
- 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 = new ProgressBar(
- /* translators: %d: amount of actions */
- sprintf( _n( 'Running %d action', 'Running %d actions', $count, 'action-scheduler' ), number_format_i18n( $count ) ),
- $count
- );
- }
-
- /**
- * Process actions in the queue.
- *
- * @author Jeremy Pry
- *
- * @param string $context Optional runner context. Default 'WP CLI'.
- *
- * @return int The number of actions processed.
- */
- public function run( $context = 'WP CLI' ) {
- 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, $context );
- $this->progress_bar->tick();
- }
-
- $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 int $action_id
- * @param null|ActionScheduler_Action $action The instance of the action. Default to null for backward compatibility.
- */
- public function after_execute( $action_id, $action = null ) {
- // backward compatibility
- if ( null === $action ) {
- $action = $this->store->fetch_action( $action_id );
- }
- /* translators: 1: action ID 2: hook name */
- WP_CLI::log( sprintf( __( 'Completed processing action %1$s with hook: %2$s', 'action-scheduler' ), $action_id, $action->get_hook() ) );
- }
-
- /**
- * 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: action ID 2: 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
- * @deprecated 3.0.0
- */
- protected function stop_the_insanity( $sleep_time = 0 ) {
- _deprecated_function( 'ActionScheduler_WPCLI_QueueRunner::stop_the_insanity', '3.0.0', 'ActionScheduler_DataController::free_memory' );
-
- ActionScheduler_DataController::free_memory();
- }
-
- /**
- * Maybe trigger the stop_the_insanity() method to free up memory.
- */
- protected function maybe_stop_the_insanity() {
- // The value returned by progress_bar->current() might be padded. Remove padding, and convert to int.
- $current_iteration = intval( trim( $this->progress_bar->current() ) );
- if ( 0 === $current_iteration % 50 ) {
- $this->stop_the_insanity();
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php b/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php
deleted file mode 100644
index c27008b..0000000
--- a/includes/libraries/action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php
+++ /dev/null
@@ -1,158 +0,0 @@
-]
- * : 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.
- *
- * [--free-memory-on=]
- * : The number of actions to process between freeing memory. 0 disables freeing memory. Default 50.
- *
- * [--pause=]
- * : The number of seconds to pause when freeing memory. Default no pause.
- *
- * [--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.
- *
- * @subcommand run
- */
- 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', '' );
- $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', '' );
- $sleep = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', '' );
- $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
-
- ActionScheduler_DataController::set_free_ticks( $free_on );
- ActionScheduler_DataController::set_sleep_time( $sleep );
-
- $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/WP_CLI/Migration_Command.php b/includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php
deleted file mode 100644
index 066697e..0000000
--- a/includes/libraries/action-scheduler/classes/WP_CLI/Migration_Command.php
+++ /dev/null
@@ -1,148 +0,0 @@
- 'Migrates actions to the DB tables store',
- 'synopsis' => [
- [
- 'type' => 'assoc',
- 'name' => 'batch-size',
- 'optional' => true,
- 'default' => 100,
- 'description' => 'The number of actions to process in each batch',
- ],
- [
- 'type' => 'assoc',
- 'name' => 'free-memory-on',
- 'optional' => true,
- 'default' => 50,
- 'description' => 'The number of actions to process between freeing memory. 0 disables freeing memory',
- ],
- [
- 'type' => 'assoc',
- 'name' => 'pause',
- 'optional' => true,
- 'default' => 0,
- 'description' => 'The number of seconds to pause when freeing memory',
- ],
- [
- 'type' => 'flag',
- 'name' => 'dry-run',
- 'optional' => true,
- 'description' => 'Reports on the actions that would have been migrated, but does not change any data',
- ],
- ],
- ] );
- }
-
- /**
- * Process the data migration.
- *
- * @param array $positional_args Required for WP CLI. Not used in migration.
- * @param array $assoc_args Optional arguments.
- *
- * @return void
- */
- public function migrate( $positional_args, $assoc_args ) {
- $this->init_logging();
-
- $config = $this->get_migration_config( $assoc_args );
- $runner = new Runner( $config );
- $runner->init_destination();
-
- $batch_size = isset( $assoc_args[ 'batch-size' ] ) ? (int) $assoc_args[ 'batch-size' ] : 100;
- $free_on = isset( $assoc_args[ 'free-memory-on' ] ) ? (int) $assoc_args[ 'free-memory-on' ] : 50;
- $sleep = isset( $assoc_args[ 'pause' ] ) ? (int) $assoc_args[ 'pause' ] : 0;
- \ActionScheduler_DataController::set_free_ticks( $free_on );
- \ActionScheduler_DataController::set_sleep_time( $sleep );
-
- do {
- $actions_processed = $runner->run( $batch_size );
- $this->total_processed += $actions_processed;
- } while ( $actions_processed > 0 );
-
- if ( ! $config->get_dry_run() ) {
- // let the scheduler know that there's nothing left to do
- $scheduler = new Scheduler();
- $scheduler->mark_complete();
- }
-
- WP_CLI::success( sprintf( '%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed ) );
- }
-
- /**
- * Build the config object used to create the Runner
- *
- * @param array $args Optional arguments.
- *
- * @return ActionScheduler\Migration\Config
- */
- private function get_migration_config( $args ) {
- $args = wp_parse_args( $args, [
- 'dry-run' => false,
- ] );
-
- $config = Controller::instance()->get_migration_config_object();
- $config->set_dry_run( ! empty( $args[ 'dry-run' ] ) );
-
- return $config;
- }
-
- /**
- * Hook command line logging into migration actions.
- */
- private function init_logging() {
- add_action( 'action_scheduler/migrate_action_dry_run', function ( $action_id ) {
- WP_CLI::debug( sprintf( 'Dry-run: migrated action %d', $action_id ) );
- }, 10, 1 );
- add_action( 'action_scheduler/no_action_to_migrate', function ( $action_id ) {
- WP_CLI::debug( sprintf( 'No action found to migrate for ID %d', $action_id ) );
- }, 10, 1 );
- add_action( 'action_scheduler/migrate_action_failed', function ( $action_id ) {
- WP_CLI::warning( sprintf( 'Failed migrating action with ID %d', $action_id ) );
- }, 10, 1 );
- add_action( 'action_scheduler/migrate_action_incomplete', function ( $source_id, $destination_id ) {
- WP_CLI::warning( sprintf( 'Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id ) );
- }, 10, 2 );
- add_action( 'action_scheduler/migrated_action', function ( $source_id, $destination_id ) {
- WP_CLI::debug( sprintf( 'Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id ) );
- }, 10, 2 );
- add_action( 'action_scheduler/migration_batch_starting', function ( $batch ) {
- WP_CLI::debug( 'Beginning migration of batch: ' . print_r( $batch, true ) );
- }, 10, 1 );
- add_action( 'action_scheduler/migration_batch_complete', function ( $batch ) {
- WP_CLI::log( sprintf( 'Completed migration of %d actions', count( $batch ) ) );
- }, 10, 1 );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php b/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php
deleted file mode 100644
index c86c74e..0000000
--- a/includes/libraries/action-scheduler/classes/WP_CLI/ProgressBar.php
+++ /dev/null
@@ -1,119 +0,0 @@
-total_ticks = 0;
- $this->message = $message;
- $this->count = $count;
- $this->interval = $interval;
- }
-
- /**
- * Increment the progress bar ticks.
- */
- public function tick() {
- if ( null === $this->progress_bar ) {
- $this->setup_progress_bar();
- }
-
- $this->progress_bar->tick();
- $this->total_ticks++;
-
- do_action( 'action_scheduler/progress_tick', $this->total_ticks );
- }
-
- /**
- * Get the progress bar tick count.
- *
- * @return int
- */
- public function current() {
- return $this->progress_bar ? $this->progress_bar->current() : 0;
- }
-
- /**
- * Finish the current progress bar.
- */
- public function finish() {
- if ( null !== $this->progress_bar ) {
- $this->progress_bar->finish();
- }
-
- $this->progress_bar = null;
- }
-
- /**
- * Set the message used when creating the progress bar.
- *
- * @param string $message The message to be used when the next progress bar is created.
- */
- public function set_message( $message ) {
- $this->message = $message;
- }
-
- /**
- * Set the count for a new progress bar.
- *
- * @param integer $count The total number of ticks expected to complete.
- */
- public function set_count( $count ) {
- $this->count = $count;
- $this->finish();
- }
-
- /**
- * Set up the progress bar.
- */
- protected function setup_progress_bar() {
- $this->progress_bar = \WP_CLI\Utils\make_progress_bar(
- $this->message,
- $this->count,
- $this->interval
- );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php
deleted file mode 100644
index f009e42..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler.php
+++ /dev/null
@@ -1,269 +0,0 @@
-allow_migration() ) {
- $command = new Migration_Command();
- $command->register();
- }
- }
-
- /**
- * Handle WP comment cleanup after migration.
- */
- if ( is_a( $logger, 'ActionScheduler_DBLogger' ) && ActionScheduler_DataController::is_migration_complete() && ActionScheduler_WPCommentCleaner::has_logs() ) {
- ActionScheduler_WPCommentCleaner::init();
- }
-
- add_action( 'action_scheduler/migration_complete', 'ActionScheduler_WPCommentCleaner::maybe_schedule_cleanup' );
- }
-
- /**
- * Determine if the class is one of our abstract classes.
- *
- * @since 3.0.0
- *
- * @param string $class The class name.
- *
- * @return bool
- */
- protected static function is_class_abstract( $class ) {
- static $abstracts = array(
- 'ActionScheduler' => true,
- 'ActionScheduler_Abstract_ListTable' => true,
- 'ActionScheduler_Abstract_QueueRunner' => true,
- 'ActionScheduler_Abstract_Schedule' => true,
- 'ActionScheduler_Abstract_RecurringSchedule' => true,
- 'ActionScheduler_Lock' => true,
- 'ActionScheduler_Logger' => true,
- 'ActionScheduler_Abstract_Schema' => true,
- 'ActionScheduler_Store' => true,
- 'ActionScheduler_TimezoneHelper' => true,
- );
-
- return isset( $abstracts[ $class ] ) && $abstracts[ $class ];
- }
-
- /**
- * Determine if the class is one of our migration classes.
- *
- * @since 3.0.0
- *
- * @param string $class The class name.
- *
- * @return bool
- */
- protected static function is_class_migration( $class ) {
- static $migration_segments = array(
- 'ActionMigrator' => true,
- 'BatchFetcher' => true,
- 'DBStoreMigrator' => true,
- 'DryRun' => true,
- 'LogMigrator' => true,
- 'Config' => true,
- 'Controller' => true,
- 'Runner' => true,
- 'Scheduler' => true,
- );
-
- $segments = explode( '_', $class );
- $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class;
-
- return isset( $migration_segments[ $segment ] ) && $migration_segments[ $segment ];
- }
-
- /**
- * Determine if the class is one of our WP CLI classes.
- *
- * @since 3.0.0
- *
- * @param string $class The class name.
- *
- * @return bool
- */
- protected static function is_class_cli( $class ) {
- static $cli_segments = array(
- 'QueueRunner' => true,
- 'Command' => true,
- 'ProgressBar' => true,
- );
-
- $segments = explode( '_', $class );
- $segment = isset( $segments[ 1 ] ) ? $segments[ 1 ] : $class;
-
- return isset( $cli_segments[ $segment ] ) && $cli_segments[ $segment ];
- }
-
- final public function __clone() {
- trigger_error("Singleton. No cloning allowed!", E_USER_ERROR);
- }
-
- final public function __wakeup() {
- trigger_error("Singleton. No serialization allowed!", E_USER_ERROR);
- }
-
- final private function __construct() {}
-
- /** Deprecated **/
-
- public static function get_datetime_object( $when = null, $timezone = 'UTC' ) {
- _deprecated_function( __METHOD__, '2.0', 'wcs_add_months()' );
- return as_get_datetime_object( $when, $timezone );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php
deleted file mode 100644
index fc6520f..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_ListTable.php
+++ /dev/null
@@ -1,674 +0,0 @@
- 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).
- *
- * @deprecated 3.0.0
- */
- protected function translate( $text, $context = '' ) {
- return $text;
- }
-
- /**
- * 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 ] = $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' => ' ' ),
- $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 = sanitize_text_field( $_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[] = $wpdb->prepare('`' . $column . '` like "%%s%"', $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 '';
-
- foreach ( $options as $value => $label ) {
- echo ''
- . esc_html( $label )
- . ' ';
- }
-
- echo ' ';
- }
-
- submit_button( esc_html__( 'Filter', 'action-scheduler' ), '', '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() ) {
- /* translators: %s: search query */
- echo '' . esc_attr( sprintf( __( 'Search results for "%s"', 'action-scheduler' ), $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 '';
- }
-
- /**
- * Process any pending actions.
- */
- public function process_actions() {
- $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;
- }
- }
-
- /**
- * 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 esc_html__( 'Search', 'action-scheduler' );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
deleted file mode 100644
index 7cfb3df..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_QueueRunner.php
+++ /dev/null
@@ -1,232 +0,0 @@
-created_time = microtime( true );
-
- $this->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.
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
- * Generally, this should be capitalised and not localised as it's a proper noun.
- */
- public function process_action( $action_id, $context = '' ) {
- try {
- do_action( 'action_scheduler_before_execute', $action_id, $context );
-
- if ( ActionScheduler_Store::STATUS_PENDING !== $this->store->get_status( $action_id ) ) {
- do_action( 'action_scheduler_execution_ignored', $action_id, $context );
- return;
- }
-
- $action = $this->store->fetch_action( $action_id );
- $this->store->log_execution( $action_id );
- $action->execute();
- do_action( 'action_scheduler_after_execute', $action_id, $action, $context );
- $this->store->mark_complete( $action_id );
- } catch ( Exception $e ) {
- $this->store->mark_failure( $action_id );
- do_action( 'action_scheduler_failed_execution', $action_id, $e, $context );
- }
-
- if ( isset( $action ) && is_a( $action, 'ActionScheduler_Action' ) && $action->get_schedule()->is_recurring() ) {
- $this->schedule_next_instance( $action, $action_id );
- }
- }
-
- /**
- * Schedule the next instance of the action if necessary.
- *
- * @param ActionScheduler_Action $action
- * @param int $action_id
- */
- protected function schedule_next_instance( ActionScheduler_Action $action, $action_id ) {
- try {
- ActionScheduler::factory()->repeat( $action );
- } catch ( Exception $e ) {
- do_action( 'action_scheduler_failed_to_schedule_next_instance', $action_id, $e, $action );
- }
- }
-
- /**
- * Run the queue cleaner.
- *
- * @author Jeremy Pry
- */
- protected function run_cleanup() {
- $this->cleaner->clean( 10 * $this->get_time_limit() );
- }
-
- /**
- * 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', 1 );
- }
-
- /**
- * Check if the number of allowed concurrent batches is met or exceeded.
- *
- * @return bool
- */
- public function has_maximum_concurrent_batches() {
- return $this->store->get_claim_count() >= $this->get_allowed_concurrent_batches();
- }
-
- /**
- * Get the maximum number of seconds a batch can run for.
- *
- * @return int The number of seconds.
- */
- protected function get_time_limit() {
-
- $time_limit = 30;
-
- // Apply deprecated filter from deprecated get_maximum_execution_time() method
- if ( has_filter( 'action_scheduler_maximum_execution_time' ) ) {
- _deprecated_function( 'action_scheduler_maximum_execution_time', '2.1.1', 'action_scheduler_queue_runner_time_limit' );
- $time_limit = apply_filters( 'action_scheduler_maximum_execution_time', $time_limit );
- }
-
- return absint( apply_filters( 'action_scheduler_queue_runner_time_limit', $time_limit ) );
- }
-
- /**
- * Get the number of seconds the process has been running.
- *
- * @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;
- }
-
- /**
- * Check if the host's max execution time is (likely) to be exceeded if processing more actions.
- *
- * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
- * @return bool
- */
- protected function time_likely_to_be_exceeded( $processed_actions ) {
-
- $execution_time = $this->get_execution_time();
- $max_execution_time = $this->get_time_limit();
- $time_per_action = $execution_time / $processed_actions;
- $estimated_time = $execution_time + ( $time_per_action * 3 );
- $likely_to_be_exceeded = $estimated_time > $max_execution_time;
-
- return apply_filters( 'action_scheduler_maximum_execution_time_likely_to_be_exceeded', $likely_to_be_exceeded, $this, $processed_actions, $execution_time, $max_execution_time );
- }
-
- /**
- * Get memory limit
- *
- * Based on WP_Background_Process::get_memory_limit()
- *
- * @return int
- */
- protected function get_memory_limit() {
- if ( function_exists( 'ini_get' ) ) {
- $memory_limit = ini_get( 'memory_limit' );
- } else {
- $memory_limit = '128M'; // Sensible default, and minimum required by WooCommerce
- }
-
- if ( ! $memory_limit || -1 === $memory_limit || '-1' === $memory_limit ) {
- // Unlimited, set to 32GB.
- $memory_limit = '32G';
- }
-
- return ActionScheduler_Compatibility::convert_hr_to_bytes( $memory_limit );
- }
-
- /**
- * Memory exceeded
- *
- * Ensures the batch process never exceeds 90% of the maximum WordPress memory.
- *
- * Based on WP_Background_Process::memory_exceeded()
- *
- * @return bool
- */
- protected function memory_exceeded() {
-
- $memory_limit = $this->get_memory_limit() * 0.90;
- $current_memory = memory_get_usage( true );
- $memory_exceeded = $current_memory >= $memory_limit;
-
- return apply_filters( 'action_scheduler_memory_exceeded', $memory_exceeded, $this );
- }
-
- /**
- * See if the batch limits have been exceeded, which is when memory usage is almost at
- * the maximum limit, or the time to process more actions will exceed the max time limit.
- *
- * Based on WC_Background_Process::batch_limits_exceeded()
- *
- * @param int $processed_actions The number of actions processed so far - used to determine the likelihood of exceeding the time limit if processing another action
- * @return bool
- */
- protected function batch_limits_exceeded( $processed_actions ) {
- return $this->memory_exceeded() || $this->time_likely_to_be_exceeded( $processed_actions );
- }
-
- /**
- * Process actions in the queue.
- *
- * @author Jeremy Pry
- * @param string $context Optional identifer for the context in which this action is being processed, e.g. 'WP CLI' or 'WP Cron'
- * Generally, this should be capitalised and not localised as it's a proper noun.
- * @return int The number of actions processed.
- */
- abstract public function run( $context = '' );
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php
deleted file mode 100644
index 131d475..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_RecurringSchedule.php
+++ /dev/null
@@ -1,102 +0,0 @@
-start - and logic to calculate the next run date after
- * that - @see $this->calculate_next(). The $first_date property also keeps a record of when the very
- * first instance of this chain of schedules ran.
- *
- * @var DateTime
- */
- private $first_date = NULL;
-
- /**
- * Timestamp equivalent of @see $this->first_date
- *
- * @var int
- */
- protected $first_timestamp = NULL;
-
- /**
- * The recurrance between each time an action is run using this schedule.
- * Used to calculate the start date & time. Can be a number of seconds, in the
- * case of ActionScheduler_IntervalSchedule, or a cron expression, as in the
- * case of ActionScheduler_CronSchedule. Or something else.
- *
- * @var mixed
- */
- protected $recurrence;
-
- /**
- * @param DateTime $date The date & time to run the action.
- * @param mixed $recurrence The data used to determine the schedule's recurrance.
- * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
- */
- public function __construct( DateTime $date, $recurrence, DateTime $first = null ) {
- parent::__construct( $date );
- $this->first_date = empty( $first ) ? $date : $first;
- $this->recurrence = $recurrence;
- }
-
- /**
- * @return bool
- */
- public function is_recurring() {
- return true;
- }
-
- /**
- * Get the date & time of the first schedule in this recurring series.
- *
- * @return DateTime|null
- */
- public function get_first_date() {
- return clone $this->first_date;
- }
-
- /**
- * @return string
- */
- public function get_recurrence() {
- return $this->recurrence;
- }
-
- /**
- * For PHP 5.2 compat, since DateTime objects can't be serialized
- * @return array
- */
- public function __sleep() {
- $sleep_params = parent::__sleep();
- $this->first_timestamp = $this->first_date->getTimestamp();
- return array_merge( $sleep_params, array(
- 'first_timestamp',
- 'recurrence'
- ) );
- }
-
- /**
- * Unserialize recurring schedules serialized/stored prior to AS 3.0.0
- *
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
- * was the same as ActionScheduler_SimpleSchedule::timestamp. This was addressed in
- * Action Scheduler 3.0.0, where properties and property names were aligned for better
- * inheritance. To maintain backward compatibility with scheduled serialized and stored
- * prior to 3.0, we need to correctly map the old property names.
- */
- public function __wakeup() {
- parent::__wakeup();
- if ( $this->first_timestamp > 0 ) {
- $this->first_date = as_get_datetime_object( $this->first_timestamp );
- } else {
- $this->first_date = $this->get_date();
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php
deleted file mode 100644
index 2631ef5..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php
+++ /dev/null
@@ -1,83 +0,0 @@
-scheduled_date
- *
- * @var int
- */
- protected $scheduled_timestamp = NULL;
-
- /**
- * @param DateTime $date The date & time to run the action.
- */
- public function __construct( DateTime $date ) {
- $this->scheduled_date = $date;
- }
-
- /**
- * Check if a schedule should recur.
- *
- * @return bool
- */
- abstract public function is_recurring();
-
- /**
- * Calculate when the next instance of this schedule would run based on a given date & time.
- *
- * @param DateTime $after
- * @return DateTime
- */
- abstract protected function calculate_next( DateTime $after );
-
- /**
- * Get the next date & time when this schedule should run after a given date & time.
- *
- * @param DateTime $after
- * @return DateTime|null
- */
- public function get_next( DateTime $after ) {
- $after = clone $after;
- if ( $after > $this->scheduled_date ) {
- $after = $this->calculate_next( $after );
- return $after;
- }
- return clone $this->scheduled_date;
- }
-
- /**
- * Get the date & time the schedule is set to run.
- *
- * @return DateTime|null
- */
- public function get_date() {
- return $this->scheduled_date;
- }
-
- /**
- * For PHP 5.2 compat, since DateTime objects can't be serialized
- * @return array
- */
- public function __sleep() {
- $this->scheduled_timestamp = $this->scheduled_date->getTimestamp();
- return array(
- 'scheduled_timestamp',
- );
- }
-
- public function __wakeup() {
- $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
- unset( $this->scheduled_timestamp );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php
deleted file mode 100644
index f02c84d..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schema.php
+++ /dev/null
@@ -1,133 +0,0 @@
-tables as $table ) {
- $wpdb->tables[] = $table;
- $name = $this->get_full_table_name( $table );
- $wpdb->$table = $name;
- }
-
- // create the tables
- if ( $this->schema_update_required() ) {
- foreach ( $this->tables as $table ) {
- $this->update_table( $table );
- }
- $this->mark_schema_update_complete();
- }
- }
-
- /**
- * @param string $table The name of the table
- *
- * @return string The CREATE TABLE statement, suitable for passing to dbDelta
- */
- abstract protected function get_table_definition( $table );
-
- /**
- * Determine if the database schema is out of date
- * by comparing the integer found in $this->schema_version
- * with the option set in the WordPress options table
- *
- * @return bool
- */
- private function schema_update_required() {
- $option_name = 'schema-' . static::class;
- $version_found_in_db = get_option( $option_name, 0 );
-
- // Check for schema option stored by the Action Scheduler Custom Tables plugin in case site has migrated from that plugin with an older schema
- if ( 0 === $version_found_in_db ) {
-
- $plugin_option_name = 'schema-';
-
- switch ( static::class ) {
- case 'ActionScheduler_StoreSchema' :
- $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Store_Table_Maker';
- break;
- case 'ActionScheduler_LoggerSchema' :
- $plugin_option_name .= 'Action_Scheduler\Custom_Tables\DB_Logger_Table_Maker';
- break;
- }
-
- $version_found_in_db = get_option( $plugin_option_name, 0 );
-
- delete_option( $plugin_option_name );
- }
-
- return version_compare( $version_found_in_db, $this->schema_version, '<' );
- }
-
- /**
- * Update the option in WordPress to indicate that
- * our schema is now up to date
- *
- * @return void
- */
- private function mark_schema_update_complete() {
- $option_name = 'schema-' . static::class;
-
- // work around race conditions and ensure that our option updates
- $value_to_save = (string) $this->schema_version . '.0.' . time();
-
- update_option( $option_name, $value_to_save );
- }
-
- /**
- * Update the schema for the given table
- *
- * @param string $table The name of the table to update
- *
- * @return void
- */
- private function update_table( $table ) {
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
- $definition = $this->get_table_definition( $table );
- if ( $definition ) {
- $updated = dbDelta( $definition );
- foreach ( $updated as $updated_table => $update_description ) {
- if ( strpos( $update_description, 'Created table' ) === 0 ) {
- do_action( 'action_scheduler/created_table', $updated_table, $table );
- }
- }
- }
- }
-
- /**
- * @param string $table
- *
- * @return string The full name of the table, including the
- * table prefix for the current blog
- */
- protected function get_full_table_name( $table ) {
- return $GLOBALS[ 'wpdb' ]->prefix . $table;
- }
-}
\ No newline at end of file
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php
deleted file mode 100644
index 86e8528..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Lock.php
+++ /dev/null
@@ -1,62 +0,0 @@
-get_expiration( $lock_type ) >= time() );
- }
-
- /**
- * Set a lock.
- *
- * @param string $lock_type A string to identify different lock types.
- * @return bool
- */
- abstract public function set( $lock_type );
-
- /**
- * If a lock is set, return the timestamp it was set to expiry.
- *
- * @param string $lock_type A string to identify different lock types.
- * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire.
- */
- abstract public function get_expiration( $lock_type );
-
- /**
- * Get the amount of time to set for a given lock. 60 seconds by default.
- *
- * @param string $lock_type A string to identify different lock types.
- * @return int
- */
- protected function get_duration( $lock_type ) {
- return apply_filters( 'action_scheduler_lock_duration', self::$lock_duration, $lock_type );
- }
-
- /**
- * @return ActionScheduler_Lock
- */
- public static function instance() {
- if ( empty( self::$locker ) ) {
- $class = apply_filters( 'action_scheduler_lock_class', 'ActionScheduler_OptionLock' );
- self::$locker = new $class();
- }
- return self::$locker;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php
deleted file mode 100644
index f200195..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Logger.php
+++ /dev/null
@@ -1,176 +0,0 @@
-hook_stored_action();
- add_action( 'action_scheduler_canceled_action', array( $this, 'log_canceled_action' ), 10, 1 );
- add_action( 'action_scheduler_before_execute', array( $this, 'log_started_action' ), 10, 2 );
- add_action( 'action_scheduler_after_execute', array( $this, 'log_completed_action' ), 10, 3 );
- add_action( 'action_scheduler_failed_execution', array( $this, 'log_failed_action' ), 10, 3 );
- add_action( 'action_scheduler_failed_action', array( $this, 'log_timed_out_action' ), 10, 2 );
- add_action( 'action_scheduler_unexpected_shutdown', array( $this, 'log_unexpected_shutdown' ), 10, 2 );
- add_action( 'action_scheduler_reset_action', array( $this, 'log_reset_action' ), 10, 1 );
- add_action( 'action_scheduler_execution_ignored', array( $this, 'log_ignored_action' ), 10, 2 );
- add_action( 'action_scheduler_failed_fetch_action', array( $this, 'log_failed_fetch_action' ), 10, 2 );
- add_action( 'action_scheduler_failed_to_schedule_next_instance', array( $this, 'log_failed_schedule_next_instance' ), 10, 2 );
- add_action( 'action_scheduler_bulk_cancel_actions', array( $this, 'bulk_log_cancel_actions' ), 10, 1 );
- }
-
- public function hook_stored_action() {
- add_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
- }
-
- public function unhook_stored_action() {
- remove_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
- }
-
- public function log_stored_action( $action_id ) {
- $this->log( $action_id, __( 'action created', 'action-scheduler' ) );
- }
-
- public function log_canceled_action( $action_id ) {
- $this->log( $action_id, __( 'action canceled', 'action-scheduler' ) );
- }
-
- public function log_started_action( $action_id, $context = '' ) {
- if ( ! empty( $context ) ) {
- /* translators: %s: context */
- $message = sprintf( __( 'action started via %s', 'action-scheduler' ), $context );
- } else {
- $message = __( 'action started', 'action-scheduler' );
- }
- $this->log( $action_id, $message );
- }
-
- public function log_completed_action( $action_id, $action = NULL, $context = '' ) {
- if ( ! empty( $context ) ) {
- /* translators: %s: context */
- $message = sprintf( __( 'action complete via %s', 'action-scheduler' ), $context );
- } else {
- $message = __( 'action complete', 'action-scheduler' );
- }
- $this->log( $action_id, $message );
- }
-
- public function log_failed_action( $action_id, Exception $exception, $context = '' ) {
- if ( ! empty( $context ) ) {
- /* translators: 1: context 2: exception message */
- $message = sprintf( __( 'action failed via %1$s: %2$s', 'action-scheduler' ), $context, $exception->getMessage() );
- } else {
- /* translators: %s: exception message */
- $message = sprintf( __( 'action failed: %s', 'action-scheduler' ), $exception->getMessage() );
- }
- $this->log( $action_id, $message );
- }
-
- public function log_timed_out_action( $action_id, $timeout ) {
- /* translators: %s: amount of time */
- $this->log( $action_id, sprintf( __( 'action timed out after %s seconds', 'action-scheduler' ), $timeout ) );
- }
-
- public function log_unexpected_shutdown( $action_id, $error ) {
- if ( ! empty( $error ) ) {
- /* translators: 1: error message 2: filename 3: line */
- $this->log( $action_id, sprintf( __( 'unexpected shutdown: PHP Fatal error %1$s in %2$s on line %3$s', 'action-scheduler' ), $error['message'], $error['file'], $error['line'] ) );
- }
- }
-
- public function log_reset_action( $action_id ) {
- $this->log( $action_id, __( 'action reset', 'action-scheduler' ) );
- }
-
- public function log_ignored_action( $action_id, $context = '' ) {
- if ( ! empty( $context ) ) {
- /* translators: %s: context */
- $message = sprintf( __( 'action ignored via %s', 'action-scheduler' ), $context );
- } else {
- $message = __( 'action ignored', 'action-scheduler' );
- }
- $this->log( $action_id, __( 'action ignored', 'action-scheduler' ) );
- }
-
- /**
- * @param string $action_id
- * @param Exception|NULL $exception The exception which occured when fetching the action. NULL by default for backward compatibility.
- *
- * @return ActionScheduler_LogEntry[]
- */
- public function log_failed_fetch_action( $action_id, Exception $exception = NULL ) {
-
- if ( ! is_null( $exception ) ) {
- /* translators: %s: exception message */
- $log_message = sprintf( __( 'There was a failure fetching this action: %s', 'action-scheduler' ), $exception->getMessage() );
- } else {
- $log_message = __( 'There was a failure fetching this action', 'action-scheduler' );
- }
-
- $this->log( $action_id, $log_message );
- }
-
- public function log_failed_schedule_next_instance( $action_id, Exception $exception ) {
- /* translators: %s: exception message */
- $this->log( $action_id, sprintf( __( 'There was a failure scheduling the next instance of this action: %s', 'action-scheduler' ), $exception->getMessage() ) );
- }
-
- /**
- * Bulk add cancel action log entries.
- *
- * Implemented here for backward compatibility. Should be implemented in parent loggers
- * for more performant bulk logging.
- *
- * @param array $action_ids List of action ID.
- */
- public function bulk_log_cancel_actions( $action_ids ) {
- if ( empty( $action_ids ) ) {
- return;
- }
-
- foreach ( $action_ids as $action_id ) {
- $this->log_canceled_action( $action_id );
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php
deleted file mode 100644
index 252b701..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_Store.php
+++ /dev/null
@@ -1,345 +0,0 @@
-', '>=', '<', '<=', '=') ) ) {
- 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()->get_date() : $scheduled_date;
- if ( ! $next ) {
- return '0000-00-00 00:00:00';
- }
- $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()->get_date() : $scheduled_date;
- if ( ! $next ) {
- return '0000-00-00 00:00:00';
- }
-
- ActionScheduler_TimezoneHelper::set_local_timezone( $next );
- return $next->format( 'Y-m-d H:i:s' );
- }
-
- /**
- * Validate that we could decode action arguments.
- *
- * @param mixed $args The decoded arguments.
- * @param int $action_id The action ID.
- *
- * @throws ActionScheduler_InvalidActionException When the decoded arguments are invalid.
- */
- protected function validate_args( $args, $action_id ) {
- // Ensure we have an array of args.
- if ( ! is_array( $args ) ) {
- throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id );
- }
-
- // Validate JSON decoding if possible.
- if ( function_exists( 'json_last_error' ) && JSON_ERROR_NONE !== json_last_error() ) {
- throw ActionScheduler_InvalidActionException::from_decoding_args( $action_id, $args );
- }
- }
-
- /**
- * Validate a ActionScheduler_Schedule object.
- *
- * @param mixed $schedule The unserialized ActionScheduler_Schedule object.
- * @param int $action_id The action ID.
- *
- * @throws ActionScheduler_InvalidActionException When the schedule is invalid.
- */
- protected function validate_schedule( $schedule, $action_id ) {
- if ( empty( $schedule ) || ! is_a( $schedule, 'ActionScheduler_Schedule' ) ) {
- throw ActionScheduler_InvalidActionException::from_schedule( $action_id, $schedule );
- }
- }
-
- /**
- * InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.
- *
- * Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However,
- * as we prepare to move to custom tables, and can use an indexed VARCHAR column instead, we want to warn
- * developers of this impending requirement.
- *
- * @param ActionScheduler_Action $action
- */
- protected function validate_action( ActionScheduler_Action $action ) {
- if ( strlen( json_encode( $action->get_args() ) ) > self::$max_index_length ) {
- throw new InvalidArgumentException( __( 'ActionScheduler_Action::$args too long. To ensure the args column can be indexed, action args should not be more than 191 characters when encoded as JSON.', 'action-scheduler' ) );
- }
- }
-
- /**
- * Cancel pending actions by hook.
- *
- * @since 3.0.0
- *
- * @param string $hook Hook name.
- *
- * @return void
- */
- public function cancel_actions_by_hook( $hook ) {
- $action_ids = true;
- while ( ! empty( $action_ids ) ) {
- $action_ids = $this->query_actions(
- array(
- 'hook' => $hook,
- 'status' => self::STATUS_PENDING,
- 'per_page' => 1000,
- )
- );
-
- $this->bulk_cancel_actions( $action_ids );
- }
- }
-
- /**
- * Cancel pending actions by group.
- *
- * @since 3.0.0
- *
- * @param string $group Group slug.
- *
- * @return void
- */
- public function cancel_actions_by_group( $group ) {
- $action_ids = true;
- while ( ! empty( $action_ids ) ) {
- $action_ids = $this->query_actions(
- array(
- 'group' => $group,
- 'status' => self::STATUS_PENDING,
- 'per_page' => 1000,
- )
- );
-
- $this->bulk_cancel_actions( $action_ids );
- }
- }
-
- /**
- * Cancel a set of action IDs.
- *
- * @since 3.0.0
- *
- * @param array $action_ids List of action IDs.
- *
- * @return void
- */
- private function bulk_cancel_actions( $action_ids ) {
- foreach ( $action_ids as $action_id ) {
- $this->cancel_action( $action_id );
- }
-
- do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
- }
-
- /**
- * @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' ),
- );
- }
-
- /**
- * Check if there are any pending scheduled actions due to run.
- *
- * @param ActionScheduler_Action $action
- * @param DateTime $scheduled_date (optional)
- * @return string
- */
- public function has_pending_actions_due() {
- $pending_actions = $this->query_actions( array(
- 'date' => as_get_datetime_object(),
- 'status' => ActionScheduler_Store::STATUS_PENDING,
- ) );
-
- return ! empty( $pending_actions );
- }
-
- /**
- * Callable initialization function optionally overridden in derived classes.
- */
- public function init() {}
-
- /**
- * Callable function to mark an action as migrated optionally overridden in derived classes.
- */
- public function mark_migrated( $action_id ) {}
-
- /**
- * @return ActionScheduler_Store
- */
- public static function instance() {
- if ( empty( self::$store ) ) {
- $class = apply_filters( 'action_scheduler_store_class', self::DEFAULT_CLASS );
- self::$store = new $class();
- }
- return self::$store;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php b/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php
deleted file mode 100644
index fd01449..0000000
--- a/includes/libraries/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php
+++ /dev/null
@@ -1,152 +0,0 @@
-format( 'U' ) );
- }
-
- if ( get_option( 'timezone_string' ) ) {
- $date->setTimezone( new DateTimeZone( self::get_local_timezone_string() ) );
- } else {
- $date->setUtcOffset( self::get_local_timezone_offset() );
- }
-
- return $date;
- }
-
- /**
- * Helper to retrieve the timezone string for a site until a WP core method exists
- * (see https://core.trac.wordpress.org/ticket/24730).
- *
- * Adapted from wc_timezone_string() and https://secure.php.net/manual/en/function.timezone-name-from-abbr.php#89155.
- *
- * If no timezone string is set, and its not possible to match the UTC offset set for the site to a timezone
- * string, then an empty string will be returned, and the UTC offset should be used to set a DateTime's
- * timezone.
- *
- * @since 2.1.0
- * @return string PHP timezone string for the site or empty if no timezone string is available.
- */
- protected static function get_local_timezone_string( $reset = false ) {
- // If site timezone string exists, return it.
- $timezone = get_option( 'timezone_string' );
- if ( $timezone ) {
- return $timezone;
- }
-
- // Get UTC offset, if it isn't set then return UTC.
- $utc_offset = intval( get_option( 'gmt_offset', 0 ) );
- if ( 0 === $utc_offset ) {
- return 'UTC';
- }
-
- // Adjust UTC offset from hours to seconds.
- $utc_offset *= 3600;
-
- // Attempt to guess the timezone string from the UTC offset.
- $timezone = timezone_name_from_abbr( '', $utc_offset );
- if ( $timezone ) {
- return $timezone;
- }
-
- // Last try, guess timezone string manually.
- foreach ( timezone_abbreviations_list() as $abbr ) {
- foreach ( $abbr as $city ) {
- if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) {
- return $city['timezone_id'];
- }
- }
- }
-
- // No timezone string
- return '';
- }
-
- /**
- * Get timezone offset in seconds.
- *
- * @since 2.1.0
- * @return float
- */
- protected static function get_local_timezone_offset() {
- $timezone = get_option( 'timezone_string' );
-
- if ( $timezone ) {
- $timezone_object = new DateTimeZone( $timezone );
- return $timezone_object->getOffset( new DateTime( 'now' ) );
- } else {
- return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS;
- }
- }
-
- /**
- * @deprecated 2.1.0
- */
- public static function get_local_timezone( $reset = FALSE ) {
- _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
- if ( $reset ) {
- self::$local_timezone = NULL;
- }
- if ( !isset(self::$local_timezone) ) {
- $tzstring = get_option('timezone_string');
-
- if ( empty($tzstring) ) {
- $gmt_offset = get_option('gmt_offset');
- if ( $gmt_offset == 0 ) {
- $tzstring = 'UTC';
- } else {
- $gmt_offset *= HOUR_IN_SECONDS;
- $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 );
-
- // If there's no timezone string, try again with no DST.
- if ( false === $tzstring ) {
- $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 );
- }
-
- // Try mapping to the first abbreviation we can find.
- if ( false === $tzstring ) {
- $is_dst = date( 'I' );
- foreach ( timezone_abbreviations_list() as $abbr ) {
- foreach ( $abbr as $city ) {
- if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) {
- // If there's no valid timezone ID, keep looking.
- if ( null === $city['timezone_id'] ) {
- continue;
- }
-
- $tzstring = $city['timezone_id'];
- break 2;
- }
- }
- }
- }
-
- // If we still have no valid string, then fall back to UTC.
- if ( false === $tzstring ) {
- $tzstring = 'UTC';
- }
- }
- }
-
- self::$local_timezone = new DateTimeZone($tzstring);
- }
- return self::$local_timezone;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php b/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php
deleted file mode 100644
index 6258ba1..0000000
--- a/includes/libraries/action-scheduler/classes/actions/ActionScheduler_Action.php
+++ /dev/null
@@ -1,75 +0,0 @@
-set_hook($hook);
- $this->set_schedule($schedule);
- $this->set_args($args);
- $this->set_group($group);
- }
-
- public function execute() {
- return do_action_ref_array($this->get_hook(), $this->get_args());
- }
-
- /**
- * @param string $hook
- */
- protected function set_hook( $hook ) {
- $this->hook = $hook;
- }
-
- public function get_hook() {
- return $this->hook;
- }
-
- protected function set_schedule( ActionScheduler_Schedule $schedule ) {
- $this->schedule = $schedule;
- }
-
- /**
- * @return ActionScheduler_Schedule
- */
- public function get_schedule() {
- return $this->schedule;
- }
-
- protected function set_args( array $args ) {
- $this->args = $args;
- }
-
- public function get_args() {
- return $this->args;
- }
-
- /**
- * @param string $group
- */
- protected function set_group( $group ) {
- $this->group = $group;
- }
-
- /**
- * @return string
- */
- public function get_group() {
- return $this->group;
- }
-
- /**
- * @return bool If the action has been finished
- */
- public function is_finished() {
- return FALSE;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php b/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php
deleted file mode 100644
index 8bbc5d1..0000000
--- a/includes/libraries/action-scheduler/classes/actions/ActionScheduler_CanceledAction.php
+++ /dev/null
@@ -1,23 +0,0 @@
-set_schedule( new ActionScheduler_NullSchedule() );
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php b/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php
deleted file mode 100644
index b23a56c..0000000
--- a/includes/libraries/action-scheduler/classes/actions/ActionScheduler_FinishedAction.php
+++ /dev/null
@@ -1,16 +0,0 @@
-set_schedule( new ActionScheduler_NullSchedule() );
- }
-
- public function execute() {
- // don't execute
- }
-}
-
\ No newline at end of file
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php
deleted file mode 100644
index d21e869..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBLogger.php
+++ /dev/null
@@ -1,146 +0,0 @@
-format( 'Y-m-d H:i:s' );
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
- $date_local = $date->format( 'Y-m-d H:i:s' );
-
- /** @var \wpdb $wpdb */
- global $wpdb;
- $wpdb->insert( $wpdb->actionscheduler_logs, [
- 'action_id' => $action_id,
- 'message' => $message,
- 'log_date_gmt' => $date_gmt,
- 'log_date_local' => $date_local,
- ], [ '%d', '%s', '%s', '%s' ] );
-
- return $wpdb->insert_id;
- }
-
- /**
- * Retrieve an action log entry.
- *
- * @param int $entry_id Log entry ID.
- *
- * @return ActionScheduler_LogEntry
- */
- public function get_entry( $entry_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $entry = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE log_id=%d", $entry_id ) );
-
- return $this->create_entry_from_db_record( $entry );
- }
-
- /**
- * Create an action log entry from a database record.
- *
- * @param object $record Log entry database record object.
- *
- * @return ActionScheduler_LogEntry
- */
- private function create_entry_from_db_record( $record ) {
- if ( empty( $record ) ) {
- return new ActionScheduler_NullLogEntry();
- }
-
- $date = as_get_datetime_object( $record->log_date_gmt );
-
- return new ActionScheduler_LogEntry( $record->action_id, $record->message, $date );
- }
-
- /**
- * Retrieve the an action's log entries from the database.
- *
- * @param int $action_id Action ID.
- *
- * @return ActionScheduler_LogEntry[]
- */
- public function get_logs( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- $records = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_logs} WHERE action_id=%d", $action_id ) );
-
- return array_map( [ $this, 'create_entry_from_db_record' ], $records );
- }
-
- /**
- * Initialize the data store.
- *
- * @codeCoverageIgnore
- */
- public function init() {
-
- $table_maker = new ActionScheduler_LoggerSchema();
- $table_maker->register_tables();
-
- parent::init();
-
- add_action( 'action_scheduler_deleted_action', [ $this, 'clear_deleted_action_logs' ], 10, 1 );
- }
-
- /**
- * Delete the action logs for an action.
- *
- * @param int $action_id Action ID.
- */
- public function clear_deleted_action_logs( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $wpdb->delete( $wpdb->actionscheduler_logs, [ 'action_id' => $action_id, ], [ '%d' ] );
- }
-
- /**
- * Bulk add cancel action log entries.
- *
- * @param array $action_ids List of action ID.
- */
- public function bulk_log_cancel_actions( $action_ids ) {
- if ( empty( $action_ids ) ) {
- return;
- }
-
- /** @var \wpdb $wpdb */
- global $wpdb;
- $date = as_get_datetime_object();
- $date_gmt = $date->format( 'Y-m-d H:i:s' );
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
- $date_local = $date->format( 'Y-m-d H:i:s' );
- $message = __( 'action canceled', 'action-scheduler' );
- $format = '(%d, ' . $wpdb->prepare( '%s, %s, %s', $message, $date_gmt, $date_local ) . ')';
- $sql_query = "INSERT {$wpdb->actionscheduler_logs} (action_id, message, log_date_gmt, log_date_local) VALUES ";
- $value_rows = [];
-
- foreach ( $action_ids as $action_id ) {
- $value_rows[] = $wpdb->prepare( $format, $action_id );
- }
- $sql_query .= implode( ',', $value_rows );
-
- $wpdb->query( $sql_query );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php
deleted file mode 100644
index 2fd1ae7..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_DBStore.php
+++ /dev/null
@@ -1,803 +0,0 @@
-register_tables();
- }
-
- /**
- * Save an action.
- *
- * @param ActionScheduler_Action $action Action object.
- * @param DateTime $date Optional schedule date. Default null.
- *
- * @return int Action ID.
- */
- public function save_action( ActionScheduler_Action $action, \DateTime $date = null ) {
- try {
-
- $this->validate_action( $action );
-
- /** @var \wpdb $wpdb */
- global $wpdb;
- $data = [
- 'hook' => $action->get_hook(),
- 'status' => ( $action->is_finished() ? self::STATUS_COMPLETE : self::STATUS_PENDING ),
- 'scheduled_date_gmt' => $this->get_scheduled_date_string( $action, $date ),
- 'scheduled_date_local' => $this->get_scheduled_date_string_local( $action, $date ),
- 'args' => json_encode( $action->get_args() ),
- 'schedule' => serialize( $action->get_schedule() ),
- 'group_id' => $this->get_group_id( $action->get_group() ),
- ];
- $wpdb->insert( $wpdb->actionscheduler_actions, $data );
- $action_id = $wpdb->insert_id;
-
- if ( is_wp_error( $action_id ) ) {
- throw new RuntimeException( $action_id->get_error_message() );
- }
- elseif ( empty( $action_id ) ) {
- throw new RuntimeException( $wpdb->last_error ? $wpdb->last_error : __( 'Database error.', 'action-scheduler' ) );
- }
-
- do_action( 'action_scheduler_stored_action', $action_id );
-
- return $action_id;
- } catch ( \Exception $e ) {
- /* translators: %s: error message */
- throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
- }
- }
-
- /**
- * Get a group's ID based on its name/slug.
- *
- * @param string $slug The string name of a group.
- * @param bool $create_if_not_exists Whether to create the group if it does not already exist. Default, true - create the group.
- *
- * @return int The group's ID, if it exists or is created, or 0 if it does not exist and is not created.
- */
- protected function get_group_id( $slug, $create_if_not_exists = true ) {
- if ( empty( $slug ) ) {
- return 0;
- }
- /** @var \wpdb $wpdb */
- global $wpdb;
- $group_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT group_id FROM {$wpdb->actionscheduler_groups} WHERE slug=%s", $slug ) );
- if ( empty( $group_id ) && $create_if_not_exists ) {
- $group_id = $this->create_group( $slug );
- }
-
- return $group_id;
- }
-
- /**
- * Create an action group.
- *
- * @param string $slug Group slug.
- *
- * @return int Group ID.
- */
- protected function create_group( $slug ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $wpdb->insert( $wpdb->actionscheduler_groups, [ 'slug' => $slug ] );
-
- return (int) $wpdb->insert_id;
- }
-
- /**
- * Retrieve an action.
- *
- * @param int $action_id Action ID.
- *
- * @return ActionScheduler_Action
- */
- public function fetch_action( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $data = $wpdb->get_row( $wpdb->prepare(
- "SELECT a.*, g.slug AS `group` FROM {$wpdb->actionscheduler_actions} a LEFT JOIN {$wpdb->actionscheduler_groups} g ON a.group_id=g.group_id WHERE a.action_id=%d",
- $action_id
- ) );
-
- if ( empty( $data ) ) {
- return $this->get_null_action();
- }
-
- try {
- $action = $this->make_action_from_db_record( $data );
- } catch ( ActionScheduler_InvalidActionException $exception ) {
- do_action( 'action_scheduler_failed_fetch_action', $action_id, $exception );
- return $this->get_null_action();
- }
-
- return $action;
- }
-
- /**
- * Create a null action.
- *
- * @return ActionScheduler_NullAction
- */
- protected function get_null_action() {
- return new ActionScheduler_NullAction();
- }
-
- /**
- * Create an action from a database record.
- *
- * @param object $data Action database record.
- *
- * @return ActionScheduler_Action|ActionScheduler_CanceledAction|ActionScheduler_FinishedAction
- */
- protected function make_action_from_db_record( $data ) {
-
- $hook = $data->hook;
- $args = json_decode( $data->args, true );
- $schedule = unserialize( $data->schedule );
-
- $this->validate_args( $args, $data->action_id );
- $this->validate_schedule( $schedule, $data->action_id );
-
- if ( empty( $schedule ) ) {
- $schedule = new ActionScheduler_NullSchedule();
- }
- $group = $data->group ? $data->group : '';
-
- return ActionScheduler::factory()->get_stored_action( $data->status, $data->hook, $args, $schedule, $group );
- }
-
- /**
- * Find an action.
- *
- * @param string $hook Action hook.
- * @param array $params Parameters of the action to find.
- *
- * @return string|null ID of the next action matching the criteria or NULL if not found.
- */
- public function find_action( $hook, $params = [] ) {
- $params = wp_parse_args( $params, [
- 'args' => null,
- 'status' => self::STATUS_PENDING,
- 'group' => '',
- ] );
-
- /** @var wpdb $wpdb */
- global $wpdb;
- $query = "SELECT a.action_id FROM {$wpdb->actionscheduler_actions} a";
- $args = [];
- if ( ! empty( $params[ 'group' ] ) ) {
- $query .= " INNER JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id AND g.slug=%s";
- $args[] = $params[ 'group' ];
- }
- $query .= " WHERE a.hook=%s";
- $args[] = $hook;
- if ( ! is_null( $params[ 'args' ] ) ) {
- $query .= " AND a.args=%s";
- $args[] = json_encode( $params[ 'args' ] );
- }
-
- $order = 'ASC';
- if ( ! empty( $params[ 'status' ] ) ) {
- $query .= " AND a.status=%s";
- $args[] = $params[ 'status' ];
-
- if ( self::STATUS_PENDING == $params[ 'status' ] ) {
- $order = 'ASC'; // Find the next action that matches.
- } else {
- $order = 'DESC'; // Find the most recent action that matches.
- }
- }
-
- $query .= " ORDER BY scheduled_date_gmt $order LIMIT 1";
-
- $query = $wpdb->prepare( $query, $args );
-
- $id = $wpdb->get_var( $query );
-
- return $id;
- }
-
- /**
- * 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.
- *
- * @return string SQL statement already properly escaped.
- */
- 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 value for select or count parameter. Cannot query actions.', 'action-scheduler' ) );
- }
-
- $query = wp_parse_args( $query, [
- 'hook' => '',
- 'args' => null,
- 'date' => null,
- 'date_compare' => '<=',
- 'modified' => null,
- 'modified_compare' => '<=',
- 'group' => '',
- 'status' => '',
- 'claimed' => null,
- 'per_page' => 5,
- 'offset' => 0,
- 'orderby' => 'date',
- 'order' => 'ASC',
- ] );
-
- /** @var \wpdb $wpdb */
- global $wpdb;
- $sql = ( 'count' === $select_or_count ) ? 'SELECT count(a.action_id)' : 'SELECT a.action_id';
- $sql .= " FROM {$wpdb->actionscheduler_actions} a";
- $sql_params = [];
-
- if ( ! empty( $query[ 'group' ] ) || 'group' === $query[ 'orderby' ] ) {
- $sql .= " LEFT JOIN {$wpdb->actionscheduler_groups} g ON g.group_id=a.group_id";
- }
-
- $sql .= " WHERE 1=1";
-
- if ( ! empty( $query[ 'group' ] ) ) {
- $sql .= " AND g.slug=%s";
- $sql_params[] = $query[ 'group' ];
- }
-
- if ( $query[ 'hook' ] ) {
- $sql .= " AND a.hook=%s";
- $sql_params[] = $query[ 'hook' ];
- }
- if ( ! is_null( $query[ 'args' ] ) ) {
- $sql .= " AND a.args=%s";
- $sql_params[] = json_encode( $query[ 'args' ] );
- }
-
- if ( $query[ 'status' ] ) {
- $sql .= " AND a.status=%s";
- $sql_params[] = $query[ 'status' ];
- }
-
- if ( $query[ 'date' ] instanceof \DateTime ) {
- $date = clone $query[ 'date' ];
- $date->setTimezone( new \DateTimeZone( 'UTC' ) );
- $date_string = $date->format( 'Y-m-d H:i:s' );
- $comparator = $this->validate_sql_comparator( $query[ 'date_compare' ] );
- $sql .= " AND a.scheduled_date_gmt $comparator %s";
- $sql_params[] = $date_string;
- }
-
- if ( $query[ 'modified' ] instanceof \DateTime ) {
- $modified = clone $query[ 'modified' ];
- $modified->setTimezone( new \DateTimeZone( 'UTC' ) );
- $date_string = $modified->format( 'Y-m-d H:i:s' );
- $comparator = $this->validate_sql_comparator( $query[ 'modified_compare' ] );
- $sql .= " AND a.last_attempt_gmt $comparator %s";
- $sql_params[] = $date_string;
- }
-
- if ( $query[ 'claimed' ] === true ) {
- $sql .= " AND a.claim_id != 0";
- } elseif ( $query[ 'claimed' ] === false ) {
- $sql .= " AND a.claim_id = 0";
- } elseif ( ! is_null( $query[ 'claimed' ] ) ) {
- $sql .= " AND a.claim_id = %d";
- $sql_params[] = $query[ 'claimed' ];
- }
-
- if ( ! empty( $query['search'] ) ) {
- $sql .= " AND (a.hook LIKE %s OR a.args LIKE %s";
- for( $i = 0; $i < 2; $i++ ) {
- $sql_params[] = sprintf( '%%%s%%', $query['search'] );
- }
-
- $search_claim_id = (int) $query['search'];
- if ( $search_claim_id ) {
- $sql .= ' OR a.claim_id = %d';
- $sql_params[] = $search_claim_id;
- }
-
- $sql .= ')';
- }
-
- if ( 'select' === $select_or_count ) {
- switch ( $query['orderby'] ) {
- case 'hook':
- $orderby = 'a.hook';
- break;
- case 'group':
- $orderby = 'g.slug';
- break;
- case 'modified':
- $orderby = 'a.last_attempt_gmt';
- break;
- case 'date':
- default:
- $orderby = 'a.scheduled_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( $sql_params ) ) {
- $sql = $wpdb->prepare( $sql, $sql_params );
- }
-
- return $sql;
- }
-
- /**
- * Query for action count of list of action IDs.
- *
- * @param array $query Query parameters.
- * @param string $query_type Whether to select or count the results. Default, select.
- *
- * @return null|string|array The IDs of actions matching the query
- */
- public function query_actions( $query = [], $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 Set of 'status' => int $count pairs for statuses with 1 or more actions of that status.
- */
- public function action_counts() {
- global $wpdb;
-
- $sql = "SELECT a.status, count(a.status) as 'count'";
- $sql .= " FROM {$wpdb->actionscheduler_actions} a";
- $sql .= " GROUP BY a.status";
-
- $actions_count_by_status = array();
- $action_stati_and_labels = $this->get_status_labels();
-
- foreach ( $wpdb->get_results( $sql ) as $action_data ) {
- // Ignore any actions with invalid status
- if ( array_key_exists( $action_data->status, $action_stati_and_labels ) ) {
- $actions_count_by_status[ $action_data->status ] = $action_data->count;
- }
- }
-
- return $actions_count_by_status;
- }
-
- /**
- * Cancel an action.
- *
- * @param int $action_id Action ID.
- *
- * @return void
- */
- public function cancel_action( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- $updated = $wpdb->update(
- $wpdb->actionscheduler_actions,
- [ 'status' => self::STATUS_CANCELED ],
- [ 'action_id' => $action_id ],
- [ '%s' ],
- [ '%d' ]
- );
- if ( empty( $updated ) ) {
- /* translators: %s: action ID */
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
- }
- do_action( 'action_scheduler_canceled_action', $action_id );
- }
-
- /**
- * Cancel pending actions by hook.
- *
- * @since 3.0.0
- *
- * @param string $hook Hook name.
- *
- * @return void
- */
- public function cancel_actions_by_hook( $hook ) {
- $this->bulk_cancel_actions( [ 'hook' => $hook ] );
- }
-
- /**
- * Cancel pending actions by group.
- *
- * @param string $group Group slug.
- *
- * @return void
- */
- public function cancel_actions_by_group( $group ) {
- $this->bulk_cancel_actions( [ 'group' => $group ] );
- }
-
- /**
- * Bulk cancel actions.
- *
- * @since 3.0.0
- *
- * @param array $query_args Query parameters.
- */
- protected function bulk_cancel_actions( $query_args ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- if ( ! is_array( $query_args ) ) {
- return;
- }
-
- // Don't cancel actions that are already canceled.
- if ( isset( $query_args['status'] ) && $query_args['status'] == self::STATUS_CANCELED ) {
- return;
- }
-
- $action_ids = true;
- $query_args = wp_parse_args(
- $query_args,
- [
- 'per_page' => 1000,
- 'status' => self::STATUS_PENDING,
- ]
- );
-
- while ( $action_ids ) {
- $action_ids = $this->query_actions( $query_args );
- if ( empty( $action_ids ) ) {
- break;
- }
-
- $format = array_fill( 0, count( $action_ids ), '%d' );
- $query_in = '(' . implode( ',', $format ) . ')';
- $parameters = $action_ids;
- array_unshift( $parameters, self::STATUS_CANCELED );
-
- $wpdb->query(
- $wpdb->prepare( // wpcs: PreparedSQLPlaceholders replacement count ok.
- "UPDATE {$wpdb->actionscheduler_actions} SET status = %s WHERE action_id IN {$query_in}",
- $parameters
- )
- );
-
- do_action( 'action_scheduler_bulk_cancel_actions', $action_ids );
- }
- }
-
- /**
- * Delete an action.
- *
- * @param int $action_id Action ID.
- */
- public function delete_action( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $deleted = $wpdb->delete( $wpdb->actionscheduler_actions, [ 'action_id' => $action_id ], [ '%d' ] );
- if ( empty( $deleted ) ) {
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
- }
- do_action( 'action_scheduler_deleted_action', $action_id );
- }
-
- /**
- * Get the schedule date for an action.
- *
- * @param string $action_id Action ID.
- *
- * @throws \InvalidArgumentException
- * @return \DateTime The local date the action is scheduled to run, or the date that it ran.
- */
- public function get_date( $action_id ) {
- $date = $this->get_date_gmt( $action_id );
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
- return $date;
- }
-
- /**
- * Get the GMT schedule date for an action.
- *
- * @param int $action_id Action ID.
- *
- * @throws \InvalidArgumentException
- * @return \DateTime The GMT date the action is scheduled to run, or the date that it ran.
- */
- protected function get_date_gmt( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $record = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d", $action_id ) );
- if ( empty( $record ) ) {
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
- }
- if ( $record->status == self::STATUS_PENDING ) {
- return as_get_datetime_object( $record->scheduled_date_gmt );
- } else {
- return as_get_datetime_object( $record->last_attempt_gmt );
- }
- }
-
- /**
- * Stake a claim on actions.
- *
- * @param int $max_actions Maximum number of action to include in claim.
- * @param \DateTime $before_date Jobs must be schedule before this date. Defaults to now.
- *
- * @return ActionScheduler_ActionClaim
- */
- 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, $hooks, $group );
- $action_ids = $this->find_actions_by_claim_id( $claim_id );
-
- return new ActionScheduler_ActionClaim( $claim_id, $action_ids );
- }
-
- /**
- * Generate a new action claim.
- *
- * @return int Claim ID.
- */
- protected function generate_claim_id() {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $now = as_get_datetime_object();
- $wpdb->insert( $wpdb->actionscheduler_claims, [ 'date_created_gmt' => $now->format( 'Y-m-d H:i:s' ) ] );
-
- return $wpdb->insert_id;
- }
-
- /**
- * Mark actions claimed.
- *
- * @param string $claim_id Claim Id.
- * @param int $limit Number of action to include in claim.
- * @param \DateTime $before_date Should use UTC timezone.
- *
- * @return int The number of actions that were claimed.
- * @throws \RuntimeException
- */
- protected function claim_actions( $claim_id, $limit, \DateTime $before_date = null, $hooks = array(), $group = '' ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- $now = as_get_datetime_object();
- $date = is_null( $before_date ) ? $now : clone $before_date;
-
- // can't use $wpdb->update() because of the <= condition
- $update = "UPDATE {$wpdb->actionscheduler_actions} SET claim_id=%d, last_attempt_gmt=%s, last_attempt_local=%s";
- $params = array(
- $claim_id,
- $now->format( 'Y-m-d H:i:s' ),
- current_time( 'mysql' ),
- );
-
- $where = "WHERE claim_id = 0 AND scheduled_date_gmt <= %s AND status=%s";
- $params[] = $date->format( 'Y-m-d H:i:s' );
- $params[] = self::STATUS_PENDING;
-
- if ( ! empty( $hooks ) ) {
- $placeholders = array_fill( 0, count( $hooks ), '%s' );
- $where .= ' AND hook IN (' . join( ', ', $placeholders ) . ')';
- $params = array_merge( $params, array_values( $hooks ) );
- }
-
- if ( ! empty( $group ) ) {
-
- $group_id = $this->get_group_id( $group, false );
-
- // throw exception if no matching group found, this matches ActionScheduler_wpPostStore's behaviour
- if ( empty( $group_id ) ) {
- /* translators: %s: group name */
- throw new InvalidArgumentException( sprintf( __( 'The group "%s" does not exist.', 'action-scheduler' ), $group ) );
- }
-
- $where .= ' AND group_id = %d';
- $params[] = $group_id;
- }
-
- $order = "ORDER BY attempts ASC, scheduled_date_gmt ASC, action_id ASC LIMIT %d";
- $params[] = $limit;
-
- $sql = $wpdb->prepare( "{$update} {$where} {$order}", $params );
-
- $rows_affected = $wpdb->query( $sql );
- if ( $rows_affected === false ) {
- throw new \RuntimeException( __( 'Unable to claim actions. Database error.', 'action-scheduler' ) );
- }
-
- return (int) $rows_affected;
- }
-
- /**
- * Get the number of active claims.
- *
- * @return int
- */
- public function get_claim_count() {
- global $wpdb;
-
- $sql = "SELECT COUNT(DISTINCT claim_id) FROM {$wpdb->actionscheduler_actions} WHERE claim_id != 0 AND status IN ( %s, %s)";
- $sql = $wpdb->prepare( $sql, [ self::STATUS_PENDING, self::STATUS_RUNNING ] );
-
- return (int) $wpdb->get_var( $sql );
- }
-
- /**
- * Return an action's claim ID, as stored in the claim_id column.
- *
- * @param string $action_id Action ID.
- * @return mixed
- */
- public function get_claim_id( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- $sql = "SELECT claim_id FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d";
- $sql = $wpdb->prepare( $sql, $action_id );
-
- return (int) $wpdb->get_var( $sql );
- }
-
- /**
- * Retrieve the action IDs of action in a claim.
- *
- * @param string $claim_id Claim ID.
- *
- * @return int[]
- */
- public function find_actions_by_claim_id( $claim_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- $sql = "SELECT action_id FROM {$wpdb->actionscheduler_actions} WHERE claim_id=%d";
- $sql = $wpdb->prepare( $sql, $claim_id );
-
- $action_ids = $wpdb->get_col( $sql );
-
- return array_map( 'intval', $action_ids );
- }
-
- /**
- * Release actions from a claim and delete the claim.
- *
- * @param ActionScheduler_ActionClaim $claim Claim object.
- */
- public function release_claim( ActionScheduler_ActionClaim $claim ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $wpdb->update( $wpdb->actionscheduler_actions, [ 'claim_id' => 0 ], [ 'claim_id' => $claim->get_id() ], [ '%d' ], [ '%d' ] );
- $wpdb->delete( $wpdb->actionscheduler_claims, [ 'claim_id' => $claim->get_id() ], [ '%d' ] );
- }
-
- /**
- * Remove the claim from an action.
- *
- * @param int $action_id Action ID.
- *
- * @return void
- */
- public function unclaim_action( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $wpdb->update(
- $wpdb->actionscheduler_actions,
- [ 'claim_id' => 0 ],
- [ 'action_id' => $action_id ],
- [ '%s' ],
- [ '%d' ]
- );
- }
-
- /**
- * Mark an action as failed.
- *
- * @param int $action_id Action ID.
- */
- public function mark_failure( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $updated = $wpdb->update(
- $wpdb->actionscheduler_actions,
- [ 'status' => self::STATUS_FAILED ],
- [ 'action_id' => $action_id ],
- [ '%s' ],
- [ '%d' ]
- );
- if ( empty( $updated ) ) {
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
- }
- }
-
- /**
- * Add execution message to action log.
- *
- * @param int $action_id Action ID.
- *
- * @return void
- */
- public function log_execution( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
-
- $sql = "UPDATE {$wpdb->actionscheduler_actions} SET attempts = attempts+1, status=%s, last_attempt_gmt = %s, last_attempt_local = %s WHERE action_id = %d";
- $sql = $wpdb->prepare( $sql, self::STATUS_RUNNING, current_time( 'mysql', true ), current_time( 'mysql' ), $action_id );
- $wpdb->query( $sql );
- }
-
- /**
- * Mark an action as complete.
- *
- * @param int $action_id Action ID.
- *
- * @return void
- */
- public function mark_complete( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $updated = $wpdb->update(
- $wpdb->actionscheduler_actions,
- [
- 'status' => self::STATUS_COMPLETE,
- 'last_attempt_gmt' => current_time( 'mysql', true ),
- 'last_attempt_local' => current_time( 'mysql' ),
- ],
- [ 'action_id' => $action_id ],
- [ '%s' ],
- [ '%d' ]
- );
- if ( empty( $updated ) ) {
- throw new \InvalidArgumentException( sprintf( __( 'Unidentified action %s', 'action-scheduler' ), $action_id ) );
- }
- }
-
- /**
- * Get an action's status.
- *
- * @param int $action_id Action ID.
- *
- * @return string
- */
- public function get_status( $action_id ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $sql = "SELECT status FROM {$wpdb->actionscheduler_actions} WHERE action_id=%d";
- $sql = $wpdb->prepare( $sql, $action_id );
- $status = $wpdb->get_var( $sql );
-
- if ( $status === null ) {
- throw new \InvalidArgumentException( __( 'Invalid action ID. No status found.', 'action-scheduler' ) );
- } elseif ( empty( $status ) ) {
- throw new \RuntimeException( __( 'Unknown status found for action.', 'action-scheduler' ) );
- } else {
- return $status;
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php
deleted file mode 100644
index bf68af3..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_HybridStore.php
+++ /dev/null
@@ -1,380 +0,0 @@
-demarkation_id = (int) get_option( self::DEMARKATION_OPTION, 0 );
- if ( empty( $config ) ) {
- $config = Controller::instance()->get_migration_config_object();
- }
- $this->primary_store = $config->get_destination_store();
- $this->secondary_store = $config->get_source_store();
- $this->migration_runner = new Runner( $config );
- }
-
- /**
- * Initialize the table data store tables.
- *
- * @codeCoverageIgnore
- */
- public function init() {
- add_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10, 2 );
- $this->primary_store->init();
- $this->secondary_store->init();
- remove_action( 'action_scheduler/created_table', [ $this, 'set_autoincrement' ], 10 );
- }
-
- /**
- * When the actions table is created, set its autoincrement
- * value to be one higher than the posts table to ensure that
- * there are no ID collisions.
- *
- * @param string $table_name
- * @param string $table_suffix
- *
- * @return void
- * @codeCoverageIgnore
- */
- public function set_autoincrement( $table_name, $table_suffix ) {
- if ( ActionScheduler_StoreSchema::ACTIONS_TABLE === $table_suffix ) {
- if ( empty( $this->demarkation_id ) ) {
- $this->demarkation_id = $this->set_demarkation_id();
- }
- /** @var \wpdb $wpdb */
- global $wpdb;
- $wpdb->insert(
- $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
- [
- 'action_id' => $this->demarkation_id,
- 'hook' => '',
- 'status' => '',
- ]
- );
- $wpdb->delete(
- $wpdb->{ActionScheduler_StoreSchema::ACTIONS_TABLE},
- [ 'action_id' => $this->demarkation_id ]
- );
- }
- }
-
- /**
- * Store the demarkation id in WP options.
- *
- * @param int $id The ID to set as the demarkation point between the two stores
- * Leave null to use the next ID from the WP posts table.
- *
- * @return int The new ID.
- *
- * @codeCoverageIgnore
- */
- private function set_demarkation_id( $id = null ) {
- if ( empty( $id ) ) {
- /** @var \wpdb $wpdb */
- global $wpdb;
- $id = (int) $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" );
- $id ++;
- }
- update_option( self::DEMARKATION_OPTION, $id );
-
- return $id;
- }
-
- /**
- * Find the first matching action from the secondary store.
- * If it exists, migrate it to the primary store immediately.
- * After it migrates, the secondary store will logically contain
- * the next matching action, so return the result thence.
- *
- * @param string $hook
- * @param array $params
- *
- * @return string
- */
- public function find_action( $hook, $params = [] ) {
- $found_unmigrated_action = $this->secondary_store->find_action( $hook, $params );
- if ( ! empty( $found_unmigrated_action ) ) {
- $this->migrate( [ $found_unmigrated_action ] );
- }
-
- return $this->primary_store->find_action( $hook, $params );
- }
-
- /**
- * Find actions matching the query in the secondary source first.
- * If any are found, migrate them immediately. Then the secondary
- * store will contain the canonical results.
- *
- * @param array $query
- * @param string $query_type Whether to select or count the results. Default, select.
- *
- * @return int[]
- */
- public function query_actions( $query = [], $query_type = 'select' ) {
- $found_unmigrated_actions = $this->secondary_store->query_actions( $query, 'select' );
- if ( ! empty( $found_unmigrated_actions ) ) {
- $this->migrate( $found_unmigrated_actions );
- }
-
- return $this->primary_store->query_actions( $query, $query_type );
- }
-
- /**
- * Get a count of all actions in the store, grouped by status
- *
- * @return array Set of 'status' => int $count pairs for statuses with 1 or more actions of that status.
- */
- public function action_counts() {
- $unmigrated_actions_count = $this->secondary_store->action_counts();
- $migrated_actions_count = $this->primary_store->action_counts();
- $actions_count_by_status = array();
-
- foreach ( $this->get_status_labels() as $status_key => $status_label ) {
-
- $count = 0;
-
- if ( isset( $unmigrated_actions_count[ $status_key ] ) ) {
- $count += $unmigrated_actions_count[ $status_key ];
- }
-
- if ( isset( $migrated_actions_count[ $status_key ] ) ) {
- $count += $migrated_actions_count[ $status_key ];
- }
-
- $actions_count_by_status[ $status_key ] = $count;
- }
-
- $actions_count_by_status = array_filter( $actions_count_by_status );
-
- return $actions_count_by_status;
- }
-
- /**
- * If any actions would have been claimed by the secondary store,
- * migrate them immediately, then ask the primary store for the
- * canonical claim.
- *
- * @param int $max_actions
- * @param DateTime|null $before_date
- *
- * @return ActionScheduler_ActionClaim
- */
- public function stake_claim( $max_actions = 10, DateTime $before_date = null, $hooks = array(), $group = '' ) {
- $claim = $this->secondary_store->stake_claim( $max_actions, $before_date, $hooks, $group );
-
- $claimed_actions = $claim->get_actions();
- if ( ! empty( $claimed_actions ) ) {
- $this->migrate( $claimed_actions );
- }
-
- $this->secondary_store->release_claim( $claim );
-
- return $this->primary_store->stake_claim( $max_actions, $before_date, $hooks, $group );
- }
-
- /**
- * Migrate a list of actions to the table data store.
- *
- * @param array $action_ids List of action IDs.
- */
- private function migrate( $action_ids ) {
- $this->migration_runner->migrate_actions( $action_ids );
- }
-
- /**
- * Save an action to the primary store.
- *
- * @param ActionScheduler_Action $action Action object to be saved.
- * @param DateTime $date Optional. Schedule date. Default null.
- */
- public function save_action( ActionScheduler_Action $action, DateTime $date = null ) {
- return $this->primary_store->save_action( $action, $date );
- }
-
- /**
- * Retrieve an existing action whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function fetch_action( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- return $this->secondary_store->fetch_action( $action_id );
- } else {
- return $this->primary_store->fetch_action( $action_id );
- }
- }
-
- /**
- * Cancel an existing action whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function cancel_action( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- $this->secondary_store->cancel_action( $action_id );
- } else {
- $this->primary_store->cancel_action( $action_id );
- }
- }
-
- /**
- * Delete an existing action whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function delete_action( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- $this->secondary_store->delete_action( $action_id );
- } else {
- $this->primary_store->delete_action( $action_id );
- }
- }
-
- /**
- * Get the schedule date an existing action whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function get_date( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- return $this->secondary_store->get_date( $action_id );
- } else {
- return $this->primary_store->get_date( $action_id );
- }
- }
-
- /**
- * Mark an existing action as failed whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function mark_failure( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- $this->secondary_store->mark_failure( $action_id );
- } else {
- $this->primary_store->mark_failure( $action_id );
- }
- }
-
- /**
- * Log the execution of an existing action whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function log_execution( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- $this->secondary_store->log_execution( $action_id );
- } else {
- $this->primary_store->log_execution( $action_id );
- }
- }
-
- /**
- * Mark an existing action complete whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function mark_complete( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- $this->secondary_store->mark_complete( $action_id );
- } else {
- $this->primary_store->mark_complete( $action_id );
- }
- }
-
- /**
- * Get an existing action status whether migrated or not.
- *
- * @param int $action_id Action ID.
- */
- public function get_status( $action_id ) {
- if ( $action_id < $this->demarkation_id ) {
- return $this->secondary_store->get_status( $action_id );
- } else {
- return $this->primary_store->get_status( $action_id );
- }
- }
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * *
- * All claim-related functions should operate solely
- * on the primary store.
- * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- /**
- * Get the claim count from the table data store.
- */
- public function get_claim_count() {
- return $this->primary_store->get_claim_count();
- }
-
- /**
- * Retrieve the claim ID for an action from the table data store.
- *
- * @param int $action_id Action ID.
- */
- public function get_claim_id( $action_id ) {
- return $this->primary_store->get_claim_id( $action_id );
- }
-
- /**
- * Release a claim in the table data store.
- *
- * @param ActionScheduler_ActionClaim $claim Claim object.
- */
- public function release_claim( ActionScheduler_ActionClaim $claim ) {
- $this->primary_store->release_claim( $claim );
- }
-
- /**
- * Release claims on an action in the table data store.
- *
- * @param int $action_id Action ID.
- */
- public function unclaim_action( $action_id ) {
- $this->primary_store->unclaim_action( $action_id );
- }
-
- /**
- * Retrieve a list of action IDs by claim.
- *
- * @param int $claim_id Claim ID.
- */
- public function find_actions_by_claim_id( $claim_id ) {
- return $this->primary_store->find_actions_by_claim_id( $claim_id );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php
deleted file mode 100644
index 7215ddd..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php
+++ /dev/null
@@ -1,240 +0,0 @@
-create_wp_comment( $action_id, $message, $date );
- return $comment_id;
- }
-
- protected function create_wp_comment( $action_id, $message, DateTime $date ) {
-
- $comment_date_gmt = $date->format('Y-m-d H:i:s');
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
- $comment_data = array(
- 'comment_post_ID' => $action_id,
- 'comment_date' => $date->format('Y-m-d H:i:s'),
- 'comment_date_gmt' => $comment_date_gmt,
- 'comment_author' => self::AGENT,
- 'comment_content' => $message,
- 'comment_agent' => self::AGENT,
- 'comment_type' => self::TYPE,
- );
- return wp_insert_comment($comment_data);
- }
-
- /**
- * @param string $entry_id
- *
- * @return ActionScheduler_LogEntry
- */
- public function get_entry( $entry_id ) {
- $comment = $this->get_comment( $entry_id );
- if ( empty($comment) || $comment->comment_type != self::TYPE ) {
- return new ActionScheduler_NullLogEntry();
- }
-
- $date = as_get_datetime_object( $comment->comment_date_gmt );
- ActionScheduler_TimezoneHelper::set_local_timezone( $date );
- return new ActionScheduler_LogEntry( $comment->comment_post_ID, $comment->comment_content, $date );
- }
-
- /**
- * @param string $action_id
- *
- * @return ActionScheduler_LogEntry[]
- */
- public function get_logs( $action_id ) {
- $status = 'all';
- if ( get_post_status($action_id) == 'trash' ) {
- $status = 'post-trashed';
- }
- $comments = get_comments(array(
- 'post_id' => $action_id,
- 'orderby' => 'comment_date_gmt',
- 'order' => 'ASC',
- 'type' => self::TYPE,
- 'status' => $status,
- ));
- $logs = array();
- foreach ( $comments as $c ) {
- $entry = $this->get_entry( $c );
- if ( !empty($entry) ) {
- $logs[] = $entry;
- }
- }
- return $logs;
- }
-
- protected function get_comment( $comment_id ) {
- return get_comment( $comment_id );
- }
-
-
-
- /**
- * @param WP_Comment_Query $query
- */
- 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 ) {
- if ( !empty($query->query_vars[$key]) ) {
- return; // don't slow down queries that wouldn't include action_log comments anyway
- }
- }
- $query->query_vars['action_log_filter'] = TRUE;
- add_filter( 'comments_clauses', array( $this, 'filter_comment_query_clauses' ), 10, 2 );
- }
-
- /**
- * @param array $clauses
- * @param WP_Comment_Query $query
- *
- * @return array
- */
- public function filter_comment_query_clauses( $clauses, $query ) {
- if ( !empty($query->query_vars['action_log_filter']) ) {
- $clauses['where'] .= $this->get_where_clause();
- }
- return $clauses;
- }
-
- /**
- * Make sure Action Scheduler logs are excluded from comment feeds, which use WP_Query, not
- * the WP_Comment_Query class handled by @see self::filter_comment_queries().
- *
- * @param string $where
- * @param WP_Query $query
- *
- * @return string
- */
- public function filter_comment_feed( $where, $query ) {
- if ( is_comment_feed() ) {
- $where .= $this->get_where_clause();
- }
- return $where;
- }
-
- /**
- * Return a SQL clause to exclude Action Scheduler comments.
- *
- * @return string
- */
- protected function get_where_clause() {
- global $wpdb;
- return sprintf( " AND {$wpdb->comments}.comment_type != '%s'", self::TYPE );
- }
-
- /**
- * Remove action log entries from wp_count_comments()
- *
- * @param array $stats
- * @param int $post_id
- *
- * @return object
- */
- public function filter_comment_count( $stats, $post_id ) {
- global $wpdb;
-
- if ( 0 === $post_id ) {
- $stats = $this->get_comment_count();
- }
-
- return $stats;
- }
-
- /**
- * Retrieve the comment counts from our cache, or the database if the cached version isn't set.
- *
- * @return object
- */
- protected function get_comment_count() {
- global $wpdb;
-
- $stats = get_transient( 'as_comment_count' );
-
- if ( ! $stats ) {
- $stats = array();
-
- $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );
-
- $total = 0;
- $stats = array();
- $approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
-
- foreach ( (array) $count as $row ) {
- // Don't count post-trashed toward totals
- if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
- $total += $row['num_comments'];
- }
- if ( isset( $approved[ $row['comment_approved'] ] ) ) {
- $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
- }
- }
-
- $stats['total_comments'] = $total;
- $stats['all'] = $total;
-
- foreach ( $approved as $key ) {
- if ( empty( $stats[ $key ] ) ) {
- $stats[ $key ] = 0;
- }
- }
-
- $stats = (object) $stats;
- set_transient( 'as_comment_count', $stats );
- }
-
- return $stats;
- }
-
- /**
- * 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.
- */
- public function delete_comment_count_cache() {
- delete_transient( 'as_comment_count' );
- }
-
- /**
- * @codeCoverageIgnore
- */
- public function init() {
- add_action( 'action_scheduler_before_process_queue', array( $this, 'disable_comment_counting' ), 10, 0 );
- add_action( 'action_scheduler_after_process_queue', array( $this, 'enable_comment_counting' ), 10, 0 );
-
- parent::init();
-
- add_action( 'pre_get_comments', array( $this, 'filter_comment_queries' ), 10, 1 );
- add_action( 'wp_count_comments', array( $this, 'filter_comment_count' ), 20, 2 ); // run after WC_Comments::wp_count_comments() to make sure we exclude order notes and action logs
- add_action( 'comment_feed_where', array( $this, 'filter_comment_feed' ), 10, 2 );
-
- // Delete comments count cache whenever there is a new comment or a comment status changes
- add_action( 'wp_insert_comment', array( $this, 'delete_comment_count_cache' ) );
- add_action( 'wp_set_comment_status', array( $this, 'delete_comment_count_cache' ) );
- }
-
- public function disable_comment_counting() {
- wp_defer_comment_counting(true);
- }
- public function enable_comment_counting() {
- wp_defer_comment_counting(false);
- }
-
-}
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php
deleted file mode 100644
index 807ec10..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore.php
+++ /dev/null
@@ -1,858 +0,0 @@
-validate_action( $action );
- $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() );
- do_action( 'action_scheduler_stored_action', $post_id );
- return $post_id;
- } catch ( Exception $e ) {
- throw new RuntimeException( sprintf( __('Error saving action: %s', 'action-scheduler'), $e->getMessage() ), 0 );
- }
- }
-
- 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_scheduled_date_string( $action, $scheduled_date ),
- 'post_date' => $this->get_scheduled_date_string_local( $action, $scheduled_date ),
- );
- return $post;
- }
-
- protected function save_post_array( $post_array ) {
- add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 );
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
-
- $has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' );
-
- if ( $has_kses ) {
- // Prevent KSES from corrupting JSON in post_content.
- kses_remove_filters();
- }
-
- $post_id = wp_insert_post($post_array);
-
- if ( $has_kses ) {
- kses_init_filters();
- }
-
- remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 );
- remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
-
- if ( is_wp_error($post_id) || empty($post_id) ) {
- throw new RuntimeException(__('Unable to save action.', 'action-scheduler'));
- }
- return $post_id;
- }
-
- public function filter_insert_post_data( $postdata ) {
- if ( $postdata['post_type'] == self::POST_TYPE ) {
- $postdata['post_author'] = 0;
- if ( $postdata['post_status'] == 'future' ) {
- $postdata['post_status'] = 'publish';
- }
- }
- return $postdata;
- }
-
- /**
- * Create a (probably unique) post name for scheduled actions in a more performant manner than wp_unique_post_slug().
- *
- * When an action's post status is transitioned to something other than 'draft', 'pending' or 'auto-draft, like 'publish'
- * or 'failed' or 'trash', WordPress will find a unique slug (stored in post_name column) using the wp_unique_post_slug()
- * function. This is done to ensure URL uniqueness. The approach taken by wp_unique_post_slug() is to iterate over existing
- * post_name values that match, and append a number 1 greater than the largest. This makes sense when manually creating a
- * post from the Edit Post screen. It becomes a bottleneck when automatically processing thousands of actions, with a
- * database containing thousands of related post_name values.
- *
- * WordPress 5.1 introduces the 'pre_wp_unique_post_slug' filter for plugins to address this issue.
- *
- * We can short-circuit WordPress's wp_unique_post_slug() approach using the 'pre_wp_unique_post_slug' filter. This
- * method is available to be used as a callback on that filter. It provides a more scalable approach to generating a
- * post_name/slug that is probably unique. Because Action Scheduler never actually uses the post_name field, or an
- * action's slug, being probably unique is good enough.
- *
- * For more backstory on this issue, see:
- * - https://github.com/woocommerce/action-scheduler/issues/44 and
- * - https://core.trac.wordpress.org/ticket/21112
- *
- * @param string $override_slug Short-circuit return value.
- * @param string $slug The desired slug (post_name).
- * @param int $post_ID Post ID.
- * @param string $post_status The post status.
- * @param string $post_type Post type.
- * @return string
- */
- public function set_unique_post_slug( $override_slug, $slug, $post_ID, $post_status, $post_type ) {
- if ( self::POST_TYPE == $post_type ) {
- $override_slug = uniqid( self::POST_TYPE . '-', true ) . '-' . wp_generate_password( 32, false );
- }
- return $override_slug;
- }
-
- protected function save_post_schedule( $post_id, $schedule ) {
- update_post_meta( $post_id, self::SCHEDULE_META_KEY, $schedule );
- }
-
- protected function save_action_group( $post_id, $group ) {
- if ( empty($group) ) {
- wp_set_object_terms( $post_id, array(), self::GROUP_TAXONOMY, FALSE );
- } else {
- wp_set_object_terms( $post_id, array($group), self::GROUP_TAXONOMY, FALSE );
- }
- }
-
- public function fetch_action( $action_id ) {
- $post = $this->get_post( $action_id );
- if ( empty($post) || $post->post_type != self::POST_TYPE ) {
- return $this->get_null_action();
- }
-
- try {
- $action = $this->make_action_from_post( $post );
- } catch ( ActionScheduler_InvalidActionException $exception ) {
- do_action( 'action_scheduler_failed_fetch_action', $post->ID, $exception );
- return $this->get_null_action();
- }
-
- return $action;
- }
-
- protected function get_post( $action_id ) {
- if ( empty($action_id) ) {
- return NULL;
- }
- return get_post($action_id);
- }
-
- protected function get_null_action() {
- return new ActionScheduler_NullAction();
- }
-
- protected function make_action_from_post( $post ) {
- $hook = $post->post_title;
-
- $args = json_decode( $post->post_content, true );
- $this->validate_args( $args, $post->ID );
-
- $schedule = get_post_meta( $post->ID, self::SCHEDULE_META_KEY, true );
- $this->validate_schedule( $schedule, $post->ID );
-
- $group = wp_get_object_terms( $post->ID, self::GROUP_TAXONOMY, array('fields' => 'names') );
- $group = empty( $group ) ? '' : reset($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_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;
- }
-
- /**
- * @param string $hook
- * @param array $params
- *
- * @return string ID of the next action matching the criteria or NULL if not found
- */
- public function find_action( $hook, $params = array() ) {
- $params = wp_parse_args( $params, array(
- 'args' => NULL,
- 'status' => ActionScheduler_Store::STATUS_PENDING,
- 'group' => '',
- ));
- /** @var wpdb $wpdb */
- global $wpdb;
- $query = "SELECT p.ID FROM {$wpdb->posts} p";
- $args = array();
- if ( !empty($params['group']) ) {
- $query .= " INNER JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
- $query .= " INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
- $query .= " INNER JOIN {$wpdb->terms} t ON tt.term_id=t.term_id AND t.slug=%s";
- $args[] = $params['group'];
- }
- $query .= " WHERE p.post_title=%s";
- $args[] = $hook;
- $query .= " AND p.post_type=%s";
- $args[] = self::POST_TYPE;
- if ( !is_null($params['args']) ) {
- $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:
- case self::STATUS_RUNNING:
- case self::STATUS_FAILED:
- $order = 'DESC'; // Find the most recent action that matches
- break;
- case self::STATUS_PENDING:
- default:
- $order = 'ASC'; // Find the next action that matches
- break;
- }
- $query .= " ORDER BY post_date_gmt $order LIMIT 1";
-
- $query = $wpdb->prepare( $query, $args );
-
- $id = $wpdb->get_var($query);
- return $id;
- }
-
- /**
- * 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.
- */
- 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,
- 'date' => NULL,
- 'date_compare' => '<=',
- 'modified' => NULL,
- 'modified_compare' => '<=',
- 'group' => '',
- 'status' => '',
- 'claimed' => NULL,
- 'per_page' => 5,
- 'offset' => 0,
- 'orderby' => 'date',
- 'order' => 'ASC',
- 'search' => '',
- ) );
-
- /** @var wpdb $wpdb */
- global $wpdb;
- $sql = ( 'count' === $select_or_count ) ? 'SELECT count(p.ID)' : 'SELECT p.ID ';
- $sql .= "FROM {$wpdb->posts} p";
- $sql_params = array();
- if ( empty( $query['group'] ) && 'group' === $query['orderby'] ) {
- $sql .= " LEFT JOIN {$wpdb->term_relationships} tr ON tr.object_id=p.ID";
- $sql .= " LEFT JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id=tt.term_taxonomy_id";
- $sql .= " LEFT JOIN {$wpdb->terms} t ON tt.term_id=t.term_id";
- } elseif ( ! empty( $query['group'] ) ) {
- $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";
- $sql .= " AND t.slug=%s";
- $sql_params[] = $query['group'];
- }
- $sql .= " WHERE post_type=%s";
- $sql_params[] = self::POST_TYPE;
- if ( $query['hook'] ) {
- $sql .= " AND p.post_title=%s";
- $sql_params[] = $query['hook'];
- }
- if ( !is_null($query['args']) ) {
- $sql .= " AND p.post_content=%s";
- $sql_params[] = json_encode($query['args']);
- }
-
- 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 ) {
- $date = clone $query['date'];
- $date->setTimezone( new DateTimeZone('UTC') );
- $date_string = $date->format('Y-m-d H:i:s');
- $comparator = $this->validate_sql_comparator($query['date_compare']);
- $sql .= " AND p.post_date_gmt $comparator %s";
- $sql_params[] = $date_string;
- }
-
- if ( $query['modified'] instanceof DateTime ) {
- $modified = clone $query['modified'];
- $modified->setTimezone( new DateTimeZone('UTC') );
- $date_string = $modified->format('Y-m-d H:i:s');
- $comparator = $this->validate_sql_comparator($query['modified_compare']);
- $sql .= " AND p.post_modified_gmt $comparator %s";
- $sql_params[] = $date_string;
- }
-
- if ( $query['claimed'] === TRUE ) {
- $sql .= " AND p.post_password != ''";
- } elseif ( $query['claimed'] === FALSE ) {
- $sql .= " AND p.post_password = ''";
- } elseif ( !is_null($query['claimed']) ) {
- $sql .= " AND p.post_password = %s";
- $sql_params[] = $query['claimed'];
- }
-
- 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'] );
- }
- }
-
- 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'];
- }
- }
-
- return $wpdb->prepare( $sql, $sql_params );
- }
-
- /**
- * @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 $action_counts_by_status;
- }
-
- /**
- * @param string $action_id
- *
- * @throws InvalidArgumentException
- */
- public function cancel_action( $action_id ) {
- $post = get_post($action_id);
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
- }
- do_action( 'action_scheduler_canceled_action', $action_id );
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
- wp_trash_post($action_id);
- remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
- }
-
- public function delete_action( $action_id ) {
- $post = get_post($action_id);
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
- }
- do_action( 'action_scheduler_deleted_action', $action_id );
-
- wp_delete_post( $action_id, TRUE );
- }
-
- /**
- * @param string $action_id
- *
- * @throws InvalidArgumentException
- * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran.
- */
- public function get_date( $action_id ) {
- $next = $this->get_date_gmt( $action_id );
- return ActionScheduler_TimezoneHelper::set_local_timezone( $next );
- }
-
- /**
- * @param string $action_id
- *
- * @throws InvalidArgumentException
- * @return ActionScheduler_DateTime The date the action is schedule to run, or the date that it ran.
- */
- public function get_date_gmt( $action_id ) {
- $post = get_post($action_id);
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
- }
- if ( $post->post_status == 'publish' ) {
- return as_get_datetime_object($post->post_modified_gmt);
- } else {
- return as_get_datetime_object($post->post_date_gmt);
- }
- }
-
- /**
- * @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, $hooks = array(), $group = '' ) {
- $claim_id = $this->generate_claim_id();
- $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 );
- }
-
- /**
- * @return int
- */
- public function get_claim_count(){
- global $wpdb;
-
- $sql = "SELECT COUNT(DISTINCT post_password) FROM {$wpdb->posts} WHERE post_password != '' AND post_type = %s AND post_status IN ('in-progress','pending')";
- $sql = $wpdb->prepare( $sql, array( self::POST_TYPE ) );
-
- return $wpdb->get_var( $sql );
- }
-
- protected function generate_claim_id() {
- $claim_id = md5(microtime(true) . rand(0,1000));
- return substr($claim_id, 0, 20); // to fit in db field with 20 char 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 When there is a database error.
- * @throws InvalidArgumentException When the group is invalid.
- */
- 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;
-
- /*
- * 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 ) );
- }
-
- /*
- * 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_gmt',
- 'before' => $date->format( 'Y-m-d H:i' ),
- 'inclusive' => true,
- ),
- 'tax_query' => array(
- array(
- 'taxonomy' => self::GROUP_TAXONOMY,
- 'field' => 'slug',
- 'terms' => $group,
- 'include_children' => false,
- ),
- ),
- );
-
- return $query->query( $query_args );
- }
-
- /**
- * @param string $claim_id
- * @return array
- */
- public function find_actions_by_claim_id( $claim_id ) {
- /** @var wpdb $wpdb */
- global $wpdb;
- $sql = "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_password = %s";
- $sql = $wpdb->prepare( $sql, array( self::POST_TYPE, $claim_id ) );
- $action_ids = $wpdb->get_col( $sql );
- return $action_ids;
- }
-
- public function release_claim( ActionScheduler_ActionClaim $claim ) {
- $action_ids = $this->find_actions_by_claim_id( $claim->get_id() );
- if ( empty($action_ids) ) {
- return; // nothing to do
- }
- $action_id_string = implode(',', array_map('intval', $action_ids));
- /** @var wpdb $wpdb */
- global $wpdb;
- $sql = "UPDATE {$wpdb->posts} SET post_password = '' WHERE ID IN ($action_id_string) AND post_password = %s";
- $sql = $wpdb->prepare( $sql, array( $claim->get_id() ) );
- $result = $wpdb->query($sql);
- if ( $result === false ) {
- /* translators: %s: claim ID */
- throw new RuntimeException( sprintf( __('Unable to unlock claim %s. Database error.', 'action-scheduler'), $claim->get_id() ) );
- }
- }
-
- /**
- * @param string $action_id
- */
- public function unclaim_action( $action_id ) {
- /** @var wpdb $wpdb */
- global $wpdb;
- $sql = "UPDATE {$wpdb->posts} SET post_password = '' WHERE ID = %d AND post_type = %s";
- $sql = $wpdb->prepare( $sql, $action_id, self::POST_TYPE );
- $result = $wpdb->query($sql);
- if ( $result === false ) {
- /* translators: %s: action ID */
- throw new RuntimeException( sprintf( __('Unable to unlock claim on action %s. Database error.', 'action-scheduler'), $action_id ) );
- }
- }
-
- public function mark_failure( $action_id ) {
- /** @var wpdb $wpdb */
- global $wpdb;
- $sql = "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d AND post_type = %s";
- $sql = $wpdb->prepare( $sql, self::STATUS_FAILED, $action_id, self::POST_TYPE );
- $result = $wpdb->query($sql);
- if ( $result === false ) {
- /* translators: %s: action ID */
- throw new RuntimeException( sprintf( __('Unable to mark failure on action %s. Database error.', 'action-scheduler'), $action_id ) );
- }
- }
-
- /**
- * Return an action's claim ID, as stored in the post password column
- *
- * @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 */
- global $wpdb;
-
- $sql = "UPDATE {$wpdb->posts} SET menu_order = menu_order+1, post_status=%s, post_modified_gmt = %s, post_modified = %s WHERE ID = %d AND post_type = %s";
- $sql = $wpdb->prepare( $sql, self::STATUS_RUNNING, current_time('mysql', true), current_time('mysql'), $action_id, self::POST_TYPE );
- $wpdb->query($sql);
- }
-
- /**
- * Record that an action was completed.
- *
- * @param int $action_id ID of the completed action.
- * @throws InvalidArgumentException|RuntimeException
- */
- public function mark_complete( $action_id ) {
- $post = get_post($action_id);
- if ( empty($post) || ($post->post_type != self::POST_TYPE) ) {
- throw new InvalidArgumentException(sprintf(__('Unidentified action %s', 'action-scheduler'), $action_id));
- }
- add_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10, 1 );
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10, 5 );
- $result = wp_update_post(array(
- 'ID' => $action_id,
- 'post_status' => 'publish',
- ), TRUE);
- remove_filter( 'wp_insert_post_data', array( $this, 'filter_insert_post_data' ), 10 );
- remove_filter( 'pre_wp_unique_post_slug', array( $this, 'set_unique_post_slug' ), 10 );
- if ( is_wp_error($result) ) {
- throw new RuntimeException($result->get_error_message());
- }
- }
-
- /**
- * Mark action as migrated when there is an error deleting the action.
- *
- * @param int $action_id Action ID.
- */
- public function mark_migrated( $action_id ) {
- wp_update_post(
- array(
- 'ID' => $action_id,
- 'post_status' => 'migrated'
- )
- );
- }
-
- /**
- * Determine whether the post store can be migrated.
- *
- * @return bool
- */
- public function migration_dependencies_met( $setting ) {
- global $wpdb;
-
- $dependencies_met = get_transient( self::DEPENDENCIES_MET );
- if ( empty( $dependencies_met ) ) {
- $found_action = $wpdb->get_var(
- $wpdb->prepare(
- "SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND CHAR_LENGTH(post_content) > 191 LIMIT 1",
- self::POST_TYPE
- )
- );
- $dependencies_met = $found_action ? 'no' : 'yes';
- set_transient( self::DEPENDENCIES_MET, $dependencies_met, DAY_IN_SECONDS );
- }
-
- return 'yes' == $dependencies_met ? $setting : false;
- }
-
- /**
- * InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.
- *
- * Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However,
- * as we prepare to move to custom tables, and can use an indexed VARCHAR column instead, we want to warn
- * developers of this impending requirement.
- *
- * @param ActionScheduler_Action $action
- */
- protected function validate_action( ActionScheduler_Action $action ) {
- try {
- parent::validate_action( $action );
- } catch ( Exception $e ) {
- $message = sprintf( __( '%s Support for strings longer than this will be removed in a future version.', 'action-scheduler' ), $e->getMessage() );
- _doing_it_wrong( 'ActionScheduler_Action::$args', $message, '2.1.0' );
- }
- }
-
- /**
- * @codeCoverageIgnore
- */
- public function init() {
- add_filter( 'action_scheduler_migration_dependencies_met', array( $this, 'migration_dependencies_met' ) );
-
- $post_type_registrar = new ActionScheduler_wpPostStore_PostTypeRegistrar();
- $post_type_registrar->register();
-
- $post_status_registrar = new ActionScheduler_wpPostStore_PostStatusRegistrar();
- $post_status_registrar->register();
-
- $taxonomy_registrar = new ActionScheduler_wpPostStore_TaxonomyRegistrar();
- $taxonomy_registrar->register();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php
deleted file mode 100644
index 246bc34..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php
+++ /dev/null
@@ -1,58 +0,0 @@
-post_status_args(), $this->post_status_running_labels() ) );
- register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) );
- }
-
- /**
- * Build the args array for the post type definition
- *
- * @return array
- */
- protected function post_status_args() {
- $args = array(
- 'public' => false,
- 'exclude_from_search' => false,
- 'show_in_admin_all_list' => true,
- 'show_in_admin_status_list' => true,
- );
-
- return apply_filters( 'action_scheduler_post_status_args', $args );
- }
-
- /**
- * Build the args array for the post type definition
- *
- * @return array
- */
- protected function post_status_failed_labels() {
- $labels = array(
- 'label' => _x( 'Failed', 'post', 'action-scheduler' ),
- /* translators: %s: count */
- 'label_count' => _n_noop( 'Failed (%s) ', 'Failed (%s) ', 'action-scheduler' ),
- );
-
- return apply_filters( 'action_scheduler_post_status_failed_labels', $labels );
- }
-
- /**
- * Build the args array for the post type definition
- *
- * @return array
- */
- protected function post_status_running_labels() {
- $labels = array(
- 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ),
- /* translators: %s: count */
- 'label_count' => _n_noop( 'In-Progress (%s) ', 'In-Progress (%s) ', 'action-scheduler' ),
- );
-
- return apply_filters( 'action_scheduler_post_status_running_labels', $labels );
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php
deleted file mode 100644
index 8c63bd0..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_PostTypeRegistrar.php
+++ /dev/null
@@ -1,50 +0,0 @@
-post_type_args() );
- }
-
- /**
- * Build the args array for the post type definition
- *
- * @return array
- */
- protected function post_type_args() {
- $args = array(
- 'label' => __( 'Scheduled Actions', 'action-scheduler' ),
- 'description' => __( 'Scheduled actions are hooks triggered on a cetain date and time.', 'action-scheduler' ),
- 'public' => false,
- 'map_meta_cap' => true,
- 'hierarchical' => false,
- 'supports' => array('title', 'editor','comments'),
- 'rewrite' => false,
- 'query_var' => false,
- 'can_export' => true,
- 'ep_mask' => EP_NONE,
- 'labels' => array(
- 'name' => __( 'Scheduled Actions', 'action-scheduler' ),
- 'singular_name' => __( 'Scheduled Action', 'action-scheduler' ),
- 'menu_name' => _x( 'Scheduled Actions', 'Admin menu name', 'action-scheduler' ),
- 'add_new' => __( 'Add', 'action-scheduler' ),
- 'add_new_item' => __( 'Add New Scheduled Action', 'action-scheduler' ),
- 'edit' => __( 'Edit', 'action-scheduler' ),
- 'edit_item' => __( 'Edit Scheduled Action', 'action-scheduler' ),
- 'new_item' => __( 'New Scheduled Action', 'action-scheduler' ),
- 'view' => __( 'View Action', 'action-scheduler' ),
- 'view_item' => __( 'View Action', 'action-scheduler' ),
- 'search_items' => __( 'Search Scheduled Actions', 'action-scheduler' ),
- 'not_found' => __( 'No actions found', 'action-scheduler' ),
- 'not_found_in_trash' => __( 'No actions found in trash', 'action-scheduler' ),
- ),
- );
-
- $args = apply_filters('action_scheduler_post_type_args', $args);
- return $args;
- }
-}
-
\ No newline at end of file
diff --git a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php b/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php
deleted file mode 100644
index 026d625..0000000
--- a/includes/libraries/action-scheduler/classes/data-stores/ActionScheduler_wpPostStore_TaxonomyRegistrar.php
+++ /dev/null
@@ -1,26 +0,0 @@
-taxonomy_args() );
- }
-
- protected function taxonomy_args() {
- $args = array(
- 'label' => __('Action Group', 'action-scheduler'),
- 'public' => false,
- 'hierarchical' => false,
- 'show_admin_column' => true,
- 'query_var' => false,
- 'rewrite' => false,
- );
-
- $args = apply_filters('action_scheduler_taxonomy_args', $args);
- return $args;
- }
-}
-
\ No newline at end of file
diff --git a/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php b/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php
deleted file mode 100644
index c77d083..0000000
--- a/includes/libraries/action-scheduler/classes/migration/ActionMigrator.php
+++ /dev/null
@@ -1,109 +0,0 @@
-source = $source_store;
- $this->destination = $destination_store;
- $this->log_migrator = $log_migrator;
- }
-
- /**
- * Migrate an action.
- *
- * @param int $source_action_id Action ID.
- *
- * @return int 0|new action ID
- */
- public function migrate( $source_action_id ) {
- try {
- $action = $this->source->fetch_action( $source_action_id );
- $status = $this->source->get_status( $source_action_id );
- } catch ( \Exception $e ) {
- $action = null;
- $status = '';
- }
-
- if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
- // null action or empty status means the fetch operation failed or the action didn't exist
- // null schedule means it's missing vital data
- // delete it and move on
- try {
- $this->source->delete_action( $source_action_id );
- } catch ( \Exception $e ) {
- // nothing to do, it didn't exist in the first place
- }
- do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
-
- return 0;
- }
-
- try {
-
- // Make sure the last attempt date is set correctly for completed and failed actions
- $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null;
-
- $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date );
- } catch ( \Exception $e ) {
- do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination );
-
- return 0; // could not save the action in the new store
- }
-
- try {
- switch ( $status ) {
- case \ActionScheduler_Store::STATUS_FAILED :
- $this->destination->mark_failure( $destination_action_id );
- break;
- case \ActionScheduler_Store::STATUS_CANCELED :
- $this->destination->cancel_action( $destination_action_id );
- break;
- }
-
- $this->log_migrator->migrate( $source_action_id, $destination_action_id );
- $this->source->delete_action( $source_action_id );
-
- $test_action = $this->source->fetch_action( $source_action_id );
- if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
- throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) );
- }
- do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
-
- return $destination_action_id;
- } catch ( \Exception $e ) {
- // could not delete from the old store
- $this->source->mark_migrated( $source_action_id );
- do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination );
- do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
-
- return $destination_action_id;
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php b/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php
deleted file mode 100644
index 41c21da..0000000
--- a/includes/libraries/action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php
+++ /dev/null
@@ -1,47 +0,0 @@
- $this->get_scheduled_date_string( $action, $last_attempt_date ),
- 'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ),
- ];
-
- $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
- }
-
- return $action_id;
- } catch ( \Exception $e ) {
- throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php b/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php
deleted file mode 100644
index 4872801..0000000
--- a/includes/libraries/action-scheduler/classes/migration/BatchFetcher.php
+++ /dev/null
@@ -1,86 +0,0 @@
-store = $source_store;
- }
-
- /**
- * Retrieve a list of actions.
- *
- * @param int $count The number of actions to retrieve
- *
- * @return int[] A list of action IDs
- */
- public function fetch( $count = 10 ) {
- foreach ( $this->get_query_strategies( $count ) as $query ) {
- $action_ids = $this->store->query_actions( $query );
- if ( ! empty( $action_ids ) ) {
- return $action_ids;
- }
- }
-
- return [];
- }
-
- /**
- * Generate a list of prioritized of action search parameters.
- *
- * @param int $count Number of actions to find.
- *
- * @return array
- */
- private function get_query_strategies( $count ) {
- $now = as_get_datetime_object();
- $args = [
- 'date' => $now,
- 'per_page' => $count,
- 'offset' => 0,
- 'orderby' => 'date',
- 'order' => 'ASC',
- ];
-
- $priorities = [
- Store::STATUS_PENDING,
- Store::STATUS_FAILED,
- Store::STATUS_CANCELED,
- Store::STATUS_COMPLETE,
- Store::STATUS_RUNNING,
- '', // any other unanticipated status
- ];
-
- foreach ( $priorities as $status ) {
- yield wp_parse_args( [
- 'status' => $status,
- 'date_compare' => '<=',
- ], $args );
- yield wp_parse_args( [
- 'status' => $status,
- 'date_compare' => '>=',
- ], $args );
- }
- }
-}
\ No newline at end of file
diff --git a/includes/libraries/action-scheduler/classes/migration/Config.php b/includes/libraries/action-scheduler/classes/migration/Config.php
deleted file mode 100644
index 50f41ff..0000000
--- a/includes/libraries/action-scheduler/classes/migration/Config.php
+++ /dev/null
@@ -1,168 +0,0 @@
-source_store ) ) {
- throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
- }
-
- return $this->source_store;
- }
-
- /**
- * Set the configured source store.
- *
- * @param ActionScheduler_Store $store Source store object.
- */
- public function set_source_store( Store $store ) {
- $this->source_store = $store;
- }
-
- /**
- * Get the configured source loger.
- *
- * @return ActionScheduler_Logger
- */
- public function get_source_logger() {
- if ( empty( $this->source_logger ) ) {
- throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
- }
-
- return $this->source_logger;
- }
-
- /**
- * Set the configured source logger.
- *
- * @param ActionScheduler_Logger $logger
- */
- public function set_source_logger( Logger $logger ) {
- $this->source_logger = $logger;
- }
-
- /**
- * Get the configured destination store.
- *
- * @return ActionScheduler_Store
- */
- public function get_destination_store() {
- if ( empty( $this->destination_store ) ) {
- throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
- }
-
- return $this->destination_store;
- }
-
- /**
- * Set the configured destination store.
- *
- * @param ActionScheduler_Store $store
- */
- public function set_destination_store( Store $store ) {
- $this->destination_store = $store;
- }
-
- /**
- * Get the configured destination logger.
- *
- * @return ActionScheduler_Logger
- */
- public function get_destination_logger() {
- if ( empty( $this->destination_logger ) ) {
- throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
- }
-
- return $this->destination_logger;
- }
-
- /**
- * Set the configured destination logger.
- *
- * @param ActionScheduler_Logger $logger
- */
- public function set_destination_logger( Logger $logger ) {
- $this->destination_logger = $logger;
- }
-
- /**
- * Get flag indicating whether it's a dry run.
- *
- * @return bool
- */
- public function get_dry_run() {
- return $this->dry_run;
- }
-
- /**
- * Set flag indicating whether it's a dry run.
- *
- * @param bool $dry_run
- */
- public function set_dry_run( $dry_run ) {
- $this->dry_run = (bool) $dry_run;
- }
-
- /**
- * Get progress bar object.
- *
- * @return ActionScheduler\WPCLI\ProgressBar
- */
- public function get_progress_bar() {
- return $this->progress_bar;
- }
-
- /**
- * Set progress bar object.
- *
- * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
- */
- public function set_progress_bar( ProgressBar $progress_bar ) {
- $this->progress_bar = $progress_bar;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/migration/Controller.php b/includes/libraries/action-scheduler/classes/migration/Controller.php
deleted file mode 100644
index 39b5a4a..0000000
--- a/includes/libraries/action-scheduler/classes/migration/Controller.php
+++ /dev/null
@@ -1,206 +0,0 @@
-migration_scheduler = $migration_scheduler;
- $this->store_classname = '';
- }
-
- /**
- * Set the action store class name.
- *
- * @param string $class Classname of the store class.
- *
- * @return string
- */
- public function get_store_class( $class ) {
- if ( \ActionScheduler_DataController::is_migration_complete() ) {
- return \ActionScheduler_DataController::DATASTORE_CLASS;
- } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
- $this->store_classname = $class;
- return $class;
- } else {
- return 'ActionScheduler_HybridStore';
- }
- }
-
- /**
- * Set the action logger class name.
- *
- * @param string $class Classname of the logger class.
- *
- * @return string
- */
- public function get_logger_class( $class ) {
- \ActionScheduler_Store::instance();
-
- if ( $this->has_custom_datastore() ) {
- $this->logger_classname = $class;
- return $class;
- } else {
- return \ActionScheduler_DataController::LOGGER_CLASS;
- }
- }
-
- /**
- * Get flag indicating whether a custom datastore is in use.
- *
- * @return bool
- */
- public function has_custom_datastore() {
- return (bool) $this->store_classname;
- }
-
- /**
- * Set up the background migration process
- *
- * @return void
- */
- public function schedule_migration() {
- if ( \ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled() ) {
- return;
- }
-
- $this->migration_scheduler->schedule_migration();
- }
-
- /**
- * Get the default migration config object
- *
- * @return ActionScheduler\Migration\Config
- */
- public function get_migration_config_object() {
- static $config = null;
-
- if ( ! $config ) {
- $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
- $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
-
- $config = new Config();
- $config->set_source_store( $source_store );
- $config->set_source_logger( $source_logger );
- $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
- $config->set_destination_logger( new \ActionScheduler_DBLogger() );
-
- if ( defined( 'WP_CLI' ) && WP_CLI ) {
- $config->set_progress_bar( new ProgressBar( '', 0 ) );
- }
- }
-
- return apply_filters( 'action_scheduler/migration_config', $config );
- }
-
- /**
- * Hook dashboard migration notice.
- */
- public function hook_admin_notices() {
- if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
- return;
- }
- add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
- }
-
- /**
- * Show a dashboard notice that migration is in progress.
- */
- public function display_migration_notice() {
- printf( '', __( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
- }
-
- /**
- * Add store classes. Hook migration.
- */
- private function hook() {
- add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
- add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
- add_action( 'init', array( $this, 'maybe_hook_migration' ) );
- add_action( 'shutdown', array( $this, 'schedule_migration' ), 0, 0 );
-
- // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
- add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
- add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
- }
-
- /**
- * Possibly hook the migration scheduler action.
- *
- * @author Jeremy Pry
- */
- public function maybe_hook_migration() {
- if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
- return;
- }
-
- $this->migration_scheduler->hook();
- }
-
- /**
- * Allow datastores to enable migration to AS tables.
- */
- public function allow_migration() {
- if ( ! \ActionScheduler_DataController::dependencies_met() ) {
- return false;
- }
-
- if ( null === $this->migrate_custom_store ) {
- $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
- }
-
- return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
- }
-
- /**
- * Proceed with the migration if the dependencies have been met.
- */
- public static function init() {
- if ( \ActionScheduler_DataController::dependencies_met() ) {
- self::instance()->hook();
- }
- }
-
- /**
- * Singleton factory.
- */
- public static function instance() {
- if ( ! isset( self::$instance ) ) {
- self::$instance = new static( new Scheduler() );
- }
-
- return self::$instance;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php b/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php
deleted file mode 100644
index ffc21c2..0000000
--- a/includes/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php
+++ /dev/null
@@ -1,28 +0,0 @@
-source = $source_logger;
- $this->destination = $destination_Logger;
- }
-
- /**
- * Migrate an action log.
- *
- * @param int $source_action_id Source logger object.
- * @param int $destination_action_id Destination logger object.
- */
- public function migrate( $source_action_id, $destination_action_id ) {
- $logs = $this->source->get_logs( $source_action_id );
- foreach ( $logs as $log ) {
- if ( $log->get_action_id() == $source_action_id ) {
- $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() );
- }
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/migration/Runner.php b/includes/libraries/action-scheduler/classes/migration/Runner.php
deleted file mode 100644
index 867c5de..0000000
--- a/includes/libraries/action-scheduler/classes/migration/Runner.php
+++ /dev/null
@@ -1,136 +0,0 @@
-source_store = $config->get_source_store();
- $this->destination_store = $config->get_destination_store();
- $this->source_logger = $config->get_source_logger();
- $this->destination_logger = $config->get_destination_logger();
-
- $this->batch_fetcher = new BatchFetcher( $this->source_store );
- if ( $config->get_dry_run() ) {
- $this->log_migrator = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger );
- $this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
- } else {
- $this->log_migrator = new LogMigrator( $this->source_logger, $this->destination_logger );
- $this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
- }
-
- if ( defined( 'WP_CLI' ) && WP_CLI ) {
- $this->progress_bar = $config->get_progress_bar();
- }
- }
-
- /**
- * Run migration batch.
- *
- * @param int $batch_size Optional batch size. Default 10.
- *
- * @return int Size of batch processed.
- */
- public function run( $batch_size = 10 ) {
- $batch = $this->batch_fetcher->fetch( $batch_size );
- $batch_size = count( $batch );
-
- if ( ! $batch_size ) {
- return 0;
- }
-
- if ( $this->progress_bar ) {
- /* translators: %d: amount of actions */
- $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), number_format_i18n( $batch_size ) ) );
- $this->progress_bar->set_count( $batch_size );
- }
-
- $this->migrate_actions( $batch );
-
- return $batch_size;
- }
-
- /**
- * Migration a batch of actions.
- *
- * @param array $action_ids List of action IDs to migrate.
- */
- public function migrate_actions( array $action_ids ) {
- do_action( 'action_scheduler/migration_batch_starting', $action_ids );
-
- \ActionScheduler::logger()->unhook_stored_action();
- $this->destination_logger->unhook_stored_action();
-
- foreach ( $action_ids as $source_action_id ) {
- $destination_action_id = $this->action_migrator->migrate( $source_action_id );
- if ( $destination_action_id ) {
- $this->destination_logger->log( $destination_action_id, sprintf(
- /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
- __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ),
- $source_action_id,
- get_class( $this->source_store ),
- $destination_action_id,
- get_class( $this->destination_store )
- ) );
- }
-
- if ( $this->progress_bar ) {
- $this->progress_bar->tick();
- }
- }
-
- if ( $this->progress_bar ) {
- $this->progress_bar->finish();
- }
-
- \ActionScheduler::logger()->hook_stored_action();
-
- do_action( 'action_scheduler/migration_batch_complete', $action_ids );
- }
-
- /**
- * Initialize destination store and logger.
- */
- public function init_destination() {
- $this->destination_store->init();
- $this->destination_logger->init();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/migration/Scheduler.php b/includes/libraries/action-scheduler/classes/migration/Scheduler.php
deleted file mode 100644
index da3e5b8..0000000
--- a/includes/libraries/action-scheduler/classes/migration/Scheduler.php
+++ /dev/null
@@ -1,128 +0,0 @@
-get_migration_runner();
- $count = $migration_runner->run( $this->get_batch_size() );
-
- if ( $count === 0 ) {
- $this->mark_complete();
- } else {
- $this->schedule_migration( time() + $this->get_schedule_interval() );
- }
- }
-
- /**
- * Mark the migration complete.
- */
- public function mark_complete() {
- $this->unschedule_migration();
-
- \ActionScheduler_DataController::mark_migration_complete();
- do_action( 'action_scheduler/migration_complete' );
- }
-
- /**
- * Get a flag indicating whether the migration is scheduled.
- *
- * @return bool Whether there is a pending action in the store to handle the migration
- */
- public function is_migration_scheduled() {
- $next = as_next_scheduled_action( self::HOOK );
-
- return ! empty( $next );
- }
-
- /**
- * Schedule the migration.
- *
- * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
- *
- * @return string The action ID
- */
- public function schedule_migration( $when = 0 ) {
- $next = as_next_scheduled_action( self::HOOK );
-
- if ( ! empty( $next ) ) {
- return $next;
- }
-
- if ( empty( $when ) ) {
- $when = time();
- }
-
- return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
- }
-
- /**
- * Remove the scheduled migration action.
- */
- public function unschedule_migration() {
- as_unschedule_action( self::HOOK, null, self::GROUP );
- }
-
- /**
- * Get migration batch schedule interval.
- *
- * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
- */
- private function get_schedule_interval() {
- return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
- }
-
- /**
- * Get migration batch size.
- *
- * @return int Number of actions to migrate in each batch. Defaults to 250.
- */
- private function get_batch_size() {
- return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
- }
-
- /**
- * Get migration runner object.
- *
- * @return Runner
- */
- private function get_migration_runner() {
- $config = Controller::instance()->get_migration_config_object();
-
- return new Runner( $config );
- }
-
-}
diff --git a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php b/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php
deleted file mode 100644
index 840e482..0000000
--- a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CanceledSchedule.php
+++ /dev/null
@@ -1,57 +0,0 @@
-__wakeup() for details.
- **/
- private $timestamp = NULL;
-
- /**
- * @param DateTime $after
- *
- * @return DateTime|null
- */
- public function calculate_next( DateTime $after ) {
- return null;
- }
-
- /**
- * Cancelled actions should never have a next schedule, even if get_next()
- * is called with $after < $this->scheduled_date.
- *
- * @param DateTime $after
- * @return DateTime|null
- */
- public function get_next( DateTime $after ) {
- return null;
- }
-
- /**
- * @return bool
- */
- public function is_recurring() {
- return false;
- }
-
- /**
- * Unserialize recurring schedules serialized/stored prior to AS 3.0.0
- *
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
- * aligned properties and property names for better inheritance. To maintain backward
- * compatibility with schedules serialized and stored prior to 3.0, we need to correctly
- * map the old property names with matching visibility.
- */
- public function __wakeup() {
- if ( ! is_null( $this->timestamp ) ) {
- $this->scheduled_timestamp = $this->timestamp;
- unset( $this->timestamp );
- }
- parent::__wakeup();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php b/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php
deleted file mode 100644
index 7859307..0000000
--- a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_CronSchedule.php
+++ /dev/null
@@ -1,102 +0,0 @@
-__wakeup() for details.
- **/
- private $start_timestamp = NULL;
-
- /**
- * Deprecated property @see $this->__wakeup() for details.
- **/
- private $cron = NULL;
-
- /**
- * Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this
- * objects $recurrence property.
- *
- * @param DateTime $start The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used.
- * @param CronExpression|string $recurrence The CronExpression used to calculate the schedule's next instance.
- * @param DateTime|null $first (Optional) The date & time the first instance of this interval schedule ran. Default null, meaning this is the first instance.
- */
- public function __construct( DateTime $start, $recurrence, DateTime $first = null ) {
- if ( ! is_a( $recurrence, 'CronExpression' ) ) {
- $recurrence = CronExpression::factory( $recurrence );
- }
-
- // For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method.
- $date = $recurrence->getNextRunDate( $start, 0, true );
-
- // parent::__construct() will set this to $date by default, but that may be different to $start now.
- $first = empty( $first ) ? $start : $first;
-
- parent::__construct( $date, $recurrence, $first );
- }
-
- /**
- * Calculate when an instance of this schedule would start based on a given
- * date & time using its the CronExpression.
- *
- * @param DateTime $after
- * @return DateTime
- */
- protected function calculate_next( DateTime $after ) {
- return $this->recurrence->getNextRunDate( $after, 0, false );
- }
-
- /**
- * @return string
- */
- public function get_recurrence() {
- return strval( $this->recurrence );
- }
-
- /**
- * Serialize cron schedules with data required prior to AS 3.0.0
- *
- * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to
- * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
- * aligned properties and property names for better inheritance. To guard against the
- * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
- * also store the data with the old property names so if it's unserialized in AS < 3.0,
- * the schedule doesn't end up with a null recurrence.
- *
- * @return array
- */
- public function __sleep() {
-
- $sleep_params = parent::__sleep();
-
- $this->start_timestamp = $this->scheduled_timestamp;
- $this->cron = $this->recurrence;
-
- return array_merge( $sleep_params, array(
- 'start_timestamp',
- 'cron'
- ) );
- }
-
- /**
- * Unserialize cron schedules serialized/stored prior to AS 3.0.0
- *
- * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
- */
- public function __wakeup() {
- if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
- $this->scheduled_timestamp = $this->start_timestamp;
- unset( $this->start_timestamp );
- }
-
- if ( is_null( $this->recurrence ) && ! is_null( $this->cron ) ) {
- $this->recurrence = $this->cron;
- unset( $this->cron );
- }
- parent::__wakeup();
- }
-}
-
diff --git a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php b/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php
deleted file mode 100644
index 11a591e..0000000
--- a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php
+++ /dev/null
@@ -1,81 +0,0 @@
-__wakeup() for details.
- **/
- private $start_timestamp = NULL;
-
- /**
- * Deprecated property @see $this->__wakeup() for details.
- **/
- private $interval_in_seconds = NULL;
-
- /**
- * Calculate when this schedule should start after a given date & time using
- * the number of seconds between recurrences.
- *
- * @param DateTime $after
- * @return DateTime
- */
- protected function calculate_next( DateTime $after ) {
- $after->modify( '+' . (int) $this->get_recurrence() . ' seconds' );
- return $after;
- }
-
- /**
- * @return int
- */
- public function interval_in_seconds() {
- _deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' );
- return (int) $this->get_recurrence();
- }
-
- /**
- * Serialize interval schedules with data required prior to AS 3.0.0
- *
- * Prior to Action Scheduler 3.0.0, reccuring schedules used different property names to
- * refer to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
- * aligned properties and property names for better inheritance. To guard against the
- * possibility of infinite loops if downgrading to Action Scheduler < 3.0.0, we need to
- * also store the data with the old property names so if it's unserialized in AS < 3.0,
- * the schedule doesn't end up with a null/false/0 recurrence.
- *
- * @return array
- */
- public function __sleep() {
-
- $sleep_params = parent::__sleep();
-
- $this->start_timestamp = $this->scheduled_timestamp;
- $this->interval_in_seconds = $this->recurrence;
-
- return array_merge( $sleep_params, array(
- 'start_timestamp',
- 'interval_in_seconds'
- ) );
- }
-
- /**
- * Unserialize interval schedules serialized/stored prior to AS 3.0.0
- *
- * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
- */
- public function __wakeup() {
- if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
- $this->scheduled_timestamp = $this->start_timestamp;
- unset( $this->start_timestamp );
- }
-
- if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) {
- $this->recurrence = $this->interval_in_seconds;
- unset( $this->interval_in_seconds );
- }
- parent::__wakeup();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php b/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php
deleted file mode 100644
index 0ca9f7c..0000000
--- a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php
+++ /dev/null
@@ -1,28 +0,0 @@
-scheduled_date = null;
- }
-
- /**
- * This schedule has no scheduled DateTime, so we need to override the parent __sleep()
- * @return array
- */
- public function __sleep() {
- return array();
- }
-
- public function __wakeup() {
- $this->scheduled_date = null;
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php b/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php
deleted file mode 100644
index d61a9f7..0000000
--- a/includes/libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php
+++ /dev/null
@@ -1,18 +0,0 @@
-__wakeup() for details.
- **/
- private $timestamp = NULL;
-
- /**
- * @param DateTime $after
- *
- * @return DateTime|null
- */
- public function calculate_next( DateTime $after ) {
- return null;
- }
-
- /**
- * @return bool
- */
- public function is_recurring() {
- return false;
- }
-
- /**
- * Serialize schedule with data required prior to AS 3.0.0
- *
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
- * aligned properties and property names for better inheritance. To guard against the
- * scheduled date for single actions always being seen as "now" if downgrading to
- * Action Scheduler < 3.0.0, we need to also store the data with the old property names
- * so if it's unserialized in AS < 3.0, the schedule doesn't end up with a null recurrence.
- *
- * @return array
- */
- public function __sleep() {
-
- $sleep_params = parent::__sleep();
-
- $this->timestamp = $this->scheduled_timestamp;
-
- return array_merge( $sleep_params, array(
- 'timestamp',
- ) );
- }
-
- /**
- * Unserialize recurring schedules serialized/stored prior to AS 3.0.0
- *
- * Prior to Action Scheduler 3.0.0, schedules used different property names to refer
- * to equivalent data. For example, ActionScheduler_IntervalSchedule::start_timestamp
- * was the same as ActionScheduler_SimpleSchedule::timestamp. Action Scheduler 3.0.0
- * aligned properties and property names for better inheritance. To maintain backward
- * compatibility with schedules serialized and stored prior to 3.0, we need to correctly
- * map the old property names with matching visibility.
- */
- public function __wakeup() {
-
- if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) {
- $this->scheduled_timestamp = $this->timestamp;
- unset( $this->timestamp );
- }
- parent::__wakeup();
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php b/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php
deleted file mode 100644
index d19ae3f..0000000
--- a/includes/libraries/action-scheduler/classes/schema/ActionScheduler_LoggerSchema.php
+++ /dev/null
@@ -1,48 +0,0 @@
-tables = [
- self::LOG_TABLE,
- ];
- }
-
- protected function get_table_definition( $table ) {
- global $wpdb;
- $table_name = $wpdb->$table;
- $charset_collate = $wpdb->get_charset_collate();
- $max_index_length = 191; // @see wp_get_db_schema()
- switch ( $table ) {
-
- case self::LOG_TABLE:
-
- return "CREATE TABLE {$table_name} (
- log_id bigint(20) unsigned NOT NULL auto_increment,
- action_id bigint(20) unsigned NOT NULL,
- message text NOT NULL,
- log_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
- log_date_local datetime NOT NULL default '0000-00-00 00:00:00',
- PRIMARY KEY (log_id),
- KEY action_id (action_id),
- KEY log_date_gmt (log_date_gmt)
- ) $charset_collate";
-
- default:
- return '';
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php b/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php
deleted file mode 100644
index b4a47f7..0000000
--- a/includes/libraries/action-scheduler/classes/schema/ActionScheduler_StoreSchema.php
+++ /dev/null
@@ -1,82 +0,0 @@
-tables = [
- self::ACTIONS_TABLE,
- self::CLAIMS_TABLE,
- self::GROUPS_TABLE,
- ];
- }
-
- protected function get_table_definition( $table ) {
- global $wpdb;
- $table_name = $wpdb->$table;
- $charset_collate = $wpdb->get_charset_collate();
- $max_index_length = 191; // @see wp_get_db_schema()
- switch ( $table ) {
-
- case self::ACTIONS_TABLE:
-
- return "CREATE TABLE {$table_name} (
- action_id bigint(20) unsigned NOT NULL auto_increment,
- hook varchar(191) NOT NULL,
- status varchar(20) NOT NULL,
- scheduled_date_gmt datetime NOT NULL default '0000-00-00 00:00:00',
- scheduled_date_local datetime NOT NULL default '0000-00-00 00:00:00',
- args varchar($max_index_length),
- schedule longtext,
- group_id bigint(20) unsigned NOT NULL default '0',
- attempts int(11) NOT NULL default '0',
- last_attempt_gmt datetime NOT NULL default '0000-00-00 00:00:00',
- last_attempt_local datetime NOT NULL default '0000-00-00 00:00:00',
- claim_id bigint(20) unsigned NOT NULL default '0',
- PRIMARY KEY (action_id),
- KEY hook (hook($max_index_length)),
- KEY status (status),
- KEY scheduled_date_gmt (scheduled_date_gmt),
- KEY args (args($max_index_length)),
- KEY group_id (group_id),
- KEY last_attempt_gmt (last_attempt_gmt),
- KEY claim_id (claim_id)
- ) $charset_collate";
-
- case self::CLAIMS_TABLE:
-
- return "CREATE TABLE {$table_name} (
- claim_id bigint(20) unsigned NOT NULL auto_increment,
- date_created_gmt datetime NOT NULL default '0000-00-00 00:00:00',
- PRIMARY KEY (claim_id),
- KEY date_created_gmt (date_created_gmt)
- ) $charset_collate";
-
- case self::GROUPS_TABLE:
-
- return "CREATE TABLE {$table_name} (
- group_id bigint(20) unsigned NOT NULL auto_increment,
- slug varchar(255) NOT NULL,
- PRIMARY KEY (group_id),
- KEY slug (slug($max_index_length))
- ) $charset_collate";
-
- default:
- return '';
- }
- }
-}
diff --git a/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php b/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php
deleted file mode 100644
index dac17aa..0000000
--- a/includes/libraries/action-scheduler/deprecated/ActionScheduler_Abstract_QueueRunner_Deprecated.php
+++ /dev/null
@@ -1,27 +0,0 @@
-get_date();
- $replacement_method = 'get_date()';
- } else {
- $return_value = $this->get_next( $after );
- $replacement_method = 'get_next( $after )';
- }
-
- _deprecated_function( __METHOD__, '3.0.0', __CLASS__ . '::' . $replacement_method );
-
- return $return_value;
- }
-}
diff --git a/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php b/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php
deleted file mode 100644
index 002dc75..0000000
--- a/includes/libraries/action-scheduler/deprecated/ActionScheduler_Store_Deprecated.php
+++ /dev/null
@@ -1,49 +0,0 @@
-mark_failure( $action_id );
- }
-
- /**
- * Add base hooks
- *
- * @since 2.2.6
- */
- protected static function hook() {
- _deprecated_function( __METHOD__, '3.0.0' );
- }
-
- /**
- * Remove base hooks
- *
- * @since 2.2.6
- */
- protected static function unhook() {
- _deprecated_function( __METHOD__, '3.0.0' );
- }
-
- /**
- * Get the site's local time.
- *
- * @deprecated 2.1.0
- * @return DateTimeZone
- */
- protected function get_local_timezone() {
- _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
- return ActionScheduler_TimezoneHelper::get_local_timezone();
- }
-}
diff --git a/includes/libraries/action-scheduler/deprecated/functions.php b/includes/libraries/action-scheduler/deprecated/functions.php
deleted file mode 100644
index f782c4b..0000000
--- a/includes/libraries/action-scheduler/deprecated/functions.php
+++ /dev/null
@@ -1,126 +0,0 @@
- '' - the name of the action that will be triggered
- * 'args' => NULL - the args array that will be passed with the action
- * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
- * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
- * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
- * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
- * 'group' => '' - the group the action belongs to
- * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
- * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
- * 'per_page' => 5 - Number of results to return
- * 'offset' => 0
- * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
- * 'order' => 'ASC'
- * @param string $return_format OBJECT, ARRAY_A, or ids
- *
- * @deprecated 2.1.0
- *
- * @return array
- */
-function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
- _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' );
- return as_get_scheduled_actions( $args, $return_format );
-}
diff --git a/includes/libraries/action-scheduler/functions.php b/includes/libraries/action-scheduler/functions.php
deleted file mode 100644
index 19bfdb9..0000000
--- a/includes/libraries/action-scheduler/functions.php
+++ /dev/null
@@ -1,251 +0,0 @@
-async( $hook, $args, $group );
-}
-
-/**
- * Schedule an action to run one time
- *
- * @param int $timestamp When the job will run
- * @param string $hook The hook to trigger
- * @param array $args Arguments to pass when the hook triggers
- * @param string $group The group to assign this job to
- *
- * @return string The job ID
- */
-function as_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) {
- return ActionScheduler::factory()->single( $hook, $args, $timestamp, $group );
-}
-
-/**
- * Schedule a recurring action
- *
- * @param int $timestamp When the first instance of the job will run
- * @param int $interval_in_seconds How long to wait between runs
- * @param string $hook The hook to trigger
- * @param array $args Arguments to pass when the hook triggers
- * @param string $group The group to assign this job to
- *
- * @return string The job ID
- */
-function as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) {
- return ActionScheduler::factory()->recurring( $hook, $args, $timestamp, $interval_in_seconds, $group );
-}
-
-/**
- * Schedule an action that recurs on a cron-like schedule.
- *
- * @param int $base_timestamp The first instance of the action will be scheduled
- * to run at a time calculated after this timestamp matching the cron
- * expression. This can be used to delay the first instance of the action.
- * @param string $schedule A cron-link schedule string
- * @see http://en.wikipedia.org/wiki/Cron
- * * * * * * *
- * ┬ ┬ ┬ ┬ ┬ ┬
- * | | | | | |
- * | | | | | + year [optional]
- * | | | | +----- day of week (0 - 7) (Sunday=0 or 7)
- * | | | +---------- month (1 - 12)
- * | | +--------------- day of month (1 - 31)
- * | +-------------------- hour (0 - 23)
- * +------------------------- min (0 - 59)
- * @param string $hook The hook to trigger
- * @param array $args Arguments to pass when the hook triggers
- * @param string $group The group to assign this job to
- *
- * @return string The job ID
- */
-function as_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) {
- return ActionScheduler::factory()->cron( $hook, $args, $timestamp, $schedule, $group );
-}
-
-/**
- * Cancel the next occurrence of a scheduled action.
- *
- * While only the next instance of a recurring or cron action is unscheduled by this method, that will also prevent
- * all future instances of that recurring or cron action from being run. Recurring and cron actions are scheduled in
- * a sequence instead of all being scheduled at once. Each successive occurrence of a recurring action is scheduled
- * only after the former action is run. If the next instance is never run, because it's unscheduled by this function,
- * then the following instance will never be scheduled (or exist), which is effectively the same as being unscheduled
- * by this method also.
- *
- * @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 string The scheduled action ID if a scheduled action was found, or empty string if no matching action found.
- */
-function as_unschedule_action( $hook, $args = array(), $group = '' ) {
- $params = array();
- if ( is_array($args) ) {
- $params['args'] = $args;
- }
- if ( !empty($group) ) {
- $params['group'] = $group;
- }
- $job_id = ActionScheduler::store()->find_action( $hook, $params );
-
- if ( ! empty( $job_id ) ) {
- ActionScheduler::store()->cancel_action( $job_id );
- }
-
- return $job_id;
-}
-
-/**
- * Cancel all occurrences of a scheduled action.
- *
- * @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
- */
-function as_unschedule_all_actions( $hook, $args = array(), $group = '' ) {
- if ( empty( $args ) ) {
- if ( ! empty( $hook ) && empty( $group ) ) {
- ActionScheduler_Store::instance()->cancel_actions_by_hook( $hook );
- return;
- }
- if ( ! empty( $group ) && empty( $hook ) ) {
- ActionScheduler_Store::instance()->cancel_actions_by_group( $group );
- return;
- }
- }
- do {
- $unscheduled_action = as_unschedule_action( $hook, $args, $group );
- } while ( ! empty( $unscheduled_action ) );
-}
-
-/**
- * Check if there is an existing action in the queue with a given hook, args and group combination.
- *
- * An action in the queue could be pending, in-progress or aysnc. If the is pending for a time in
- * future, its scheduled date will be returned as a timestamp. If it is currently being run, or an
- * async action sitting in the queue waiting to be processed, in which case boolean true will be
- * returned. Or there may be no async, in-progress or pending action for this hook, in which case,
- * boolean false will be the return value.
- *
- * @param string $hook
- * @param array $args
- * @param string $group
- *
- * @return int|bool The timestamp for the next occurrence of a pending scheduled action, true for an async or in-progress action or false if there is no matching action.
- */
-function as_next_scheduled_action( $hook, $args = NULL, $group = '' ) {
- $params = array();
- if ( is_array($args) ) {
- $params['args'] = $args;
- }
- if ( !empty($group) ) {
- $params['group'] = $group;
- }
-
- $params['status'] = ActionScheduler_Store::STATUS_RUNNING;
- $job_id = ActionScheduler::store()->find_action( $hook, $params );
- if ( ! empty( $job_id ) ) {
- return true;
- }
-
- $params['status'] = ActionScheduler_Store::STATUS_PENDING;
- $job_id = ActionScheduler::store()->find_action( $hook, $params );
- if ( empty($job_id) ) {
- return false;
- }
- $job = ActionScheduler::store()->fetch_action( $job_id );
- $scheduled_date = $job->get_schedule()->get_date();
- if ( $scheduled_date ) {
- return (int) $scheduled_date->format( 'U' );
- } elseif ( NULL === $scheduled_date ) { // pending async action with NullSchedule
- return true;
- }
- return false;
-}
-
-/**
- * Find scheduled actions
- *
- * @param array $args Possible arguments, with their default values:
- * 'hook' => '' - the name of the action that will be triggered
- * 'args' => NULL - the args array that will be passed with the action
- * 'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
- * 'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
- * 'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime(). Used in UTC timezone.
- * 'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
- * 'group' => '' - the group the action belongs to
- * 'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
- * 'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
- * 'per_page' => 5 - Number of results to return
- * 'offset' => 0
- * 'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
- * 'order' => 'ASC'
- *
- * @param string $return_format OBJECT, ARRAY_A, or ids
- *
- * @return array
- */
-function as_get_scheduled_actions( $args = array(), $return_format = OBJECT ) {
- $store = ActionScheduler::store();
- foreach ( array('date', 'modified') as $key ) {
- if ( isset($args[$key]) ) {
- $args[$key] = as_get_datetime_object($args[$key]);
- }
- }
- $ids = $store->query_actions( $args );
-
- if ( $return_format == 'ids' || $return_format == 'int' ) {
- return $ids;
- }
-
- $actions = array();
- foreach ( $ids as $action_id ) {
- $actions[$action_id] = $store->fetch_action( $action_id );
- }
-
- if ( $return_format == ARRAY_A ) {
- foreach ( $actions as $action_id => $action_object ) {
- $actions[$action_id] = get_object_vars($action_object);
- }
- }
-
- return $actions;
-}
-
-/**
- * Helper function to create an instance of DateTime based on a given
- * string and timezone. By default, will return the current date/time
- * in the UTC timezone.
- *
- * Needed because new DateTime() called without an explicit timezone
- * will create a date/time in PHP's timezone, but we need to have
- * assurance that a date/time uses the right timezone (which we almost
- * always want to be UTC), which means we need to always include the
- * timezone when instantiating datetimes rather than leaving it up to
- * the PHP default.
- *
- * @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 ActionScheduler_DateTime
- */
-function as_get_datetime_object( $date_string = null, $timezone = 'UTC' ) {
- 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 ActionScheduler_DateTime( '@' . $date_string, new DateTimeZone( $timezone ) );
- } else {
- $date = new ActionScheduler_DateTime( $date_string, new DateTimeZone( $timezone ) );
- }
- return $date;
-}
diff --git a/includes/libraries/action-scheduler/lib/WP_Async_Request.php b/includes/libraries/action-scheduler/lib/WP_Async_Request.php
deleted file mode 100644
index d7dea1c..0000000
--- a/includes/libraries/action-scheduler/lib/WP_Async_Request.php
+++ /dev/null
@@ -1,170 +0,0 @@
-identifier = $this->prefix . '_' . $this->action;
-
- add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
- add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
- }
-
- /**
- * Set data used during the request
- *
- * @param array $data Data.
- *
- * @return $this
- */
- public function data( $data ) {
- $this->data = $data;
-
- return $this;
- }
-
- /**
- * Dispatch the async request
- *
- * @return array|WP_Error
- */
- public function dispatch() {
- $url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
- $args = $this->get_post_args();
-
- return wp_remote_post( esc_url_raw( $url ), $args );
- }
-
- /**
- * Get query args
- *
- * @return array
- */
- protected function get_query_args() {
- if ( property_exists( $this, 'query_args' ) ) {
- return $this->query_args;
- }
-
- return array(
- 'action' => $this->identifier,
- 'nonce' => wp_create_nonce( $this->identifier ),
- );
- }
-
- /**
- * Get query URL
- *
- * @return string
- */
- protected function get_query_url() {
- if ( property_exists( $this, 'query_url' ) ) {
- return $this->query_url;
- }
-
- return admin_url( 'admin-ajax.php' );
- }
-
- /**
- * Get post args
- *
- * @return array
- */
- protected function get_post_args() {
- if ( property_exists( $this, 'post_args' ) ) {
- return $this->post_args;
- }
-
- return array(
- 'timeout' => 0.01,
- 'blocking' => false,
- 'body' => $this->data,
- 'cookies' => $_COOKIE,
- 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
- );
- }
-
- /**
- * Maybe handle
- *
- * Check for correct nonce and pass to handler.
- */
- public function maybe_handle() {
- // Don't lock up other requests while processing
- session_write_close();
-
- check_ajax_referer( $this->identifier, 'nonce' );
-
- $this->handle();
-
- wp_die();
- }
-
- /**
- * Handle
- *
- * Override this method to perform any actions required
- * during the async request.
- */
- abstract protected function handle();
-
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php
deleted file mode 100755
index 7f33c37..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression.php
+++ /dev/null
@@ -1,318 +0,0 @@
-
- * @link http://en.wikipedia.org/wiki/Cron
- */
-class CronExpression
-{
- const MINUTE = 0;
- const HOUR = 1;
- const DAY = 2;
- const MONTH = 3;
- const WEEKDAY = 4;
- const YEAR = 5;
-
- /**
- * @var array CRON expression parts
- */
- private $cronParts;
-
- /**
- * @var CronExpression_FieldFactory CRON field factory
- */
- private $fieldFactory;
-
- /**
- * @var array Order in which to test of cron parts
- */
- private static $order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE);
-
- /**
- * Factory method to create a new CronExpression.
- *
- * @param string $expression The CRON expression to create. There are
- * several special predefined values which can be used to substitute the
- * CRON expression:
- *
- * @yearly, @annually) - Run once a year, midnight, Jan. 1 - 0 0 1 1 *
- * @monthly - Run once a month, midnight, first of month - 0 0 1 * *
- * @weekly - Run once a week, midnight on Sun - 0 0 * * 0
- * @daily - Run once a day, midnight - 0 0 * * *
- * @hourly - Run once an hour, first minute - 0 * * * *
- *
-*@param CronExpression_FieldFactory $fieldFactory (optional) Field factory to use
- *
- * @return CronExpression
- */
- public static function factory($expression, CronExpression_FieldFactory $fieldFactory = null)
- {
- $mappings = array(
- '@yearly' => '0 0 1 1 *',
- '@annually' => '0 0 1 1 *',
- '@monthly' => '0 0 1 * *',
- '@weekly' => '0 0 * * 0',
- '@daily' => '0 0 * * *',
- '@hourly' => '0 * * * *'
- );
-
- if (isset($mappings[$expression])) {
- $expression = $mappings[$expression];
- }
-
- return new self($expression, $fieldFactory ? $fieldFactory : new CronExpression_FieldFactory());
- }
-
- /**
- * Parse a CRON expression
- *
- * @param string $expression CRON expression (e.g. '8 * * * *')
- * @param CronExpression_FieldFactory $fieldFactory Factory to create cron fields
- */
- public function __construct($expression, CronExpression_FieldFactory $fieldFactory)
- {
- $this->fieldFactory = $fieldFactory;
- $this->setExpression($expression);
- }
-
- /**
- * Set or change the CRON expression
- *
- * @param string $value CRON expression (e.g. 8 * * * *)
- *
- * @return CronExpression
- * @throws InvalidArgumentException if not a valid CRON expression
- */
- public function setExpression($value)
- {
- $this->cronParts = preg_split('/\s/', $value, -1, PREG_SPLIT_NO_EMPTY);
- if (count($this->cronParts) < 5) {
- throw new InvalidArgumentException(
- $value . ' is not a valid CRON expression'
- );
- }
-
- foreach ($this->cronParts as $position => $part) {
- $this->setPart($position, $part);
- }
-
- return $this;
- }
-
- /**
- * Set part of the CRON expression
- *
- * @param int $position The position of the CRON expression to set
- * @param string $value The value to set
- *
- * @return CronExpression
- * @throws InvalidArgumentException if the value is not valid for the part
- */
- public function setPart($position, $value)
- {
- if (!$this->fieldFactory->getField($position)->validate($value)) {
- throw new InvalidArgumentException(
- 'Invalid CRON field value ' . $value . ' as position ' . $position
- );
- }
-
- $this->cronParts[$position] = $value;
-
- return $this;
- }
-
- /**
- * Get a next run date relative to the current date or a specific date
- *
- * @param string|DateTime $currentTime (optional) Relative calculation date
- * @param int $nth (optional) Number of matches to skip before returning a
- * matching next run date. 0, the default, will return the current
- * date and time if the next run date falls on the current date and
- * time. Setting this value to 1 will skip the first match and go to
- * the second match. Setting this value to 2 will skip the first 2
- * matches and so on.
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
- * current date if it matches the cron expression
- *
- * @return DateTime
- * @throws RuntimeException on too many iterations
- */
- public function getNextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
- {
- return $this->getRunDate($currentTime, $nth, false, $allowCurrentDate);
- }
-
- /**
- * Get a previous run date relative to the current date or a specific date
- *
- * @param string|DateTime $currentTime (optional) Relative calculation date
- * @param int $nth (optional) Number of matches to skip before returning
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
- * current date if it matches the cron expression
- *
- * @return DateTime
- * @throws RuntimeException on too many iterations
- * @see CronExpression::getNextRunDate
- */
- public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate = false)
- {
- return $this->getRunDate($currentTime, $nth, true, $allowCurrentDate);
- }
-
- /**
- * Get multiple run dates starting at the current date or a specific date
- *
- * @param int $total Set the total number of dates to calculate
- * @param string|DateTime $currentTime (optional) Relative calculation date
- * @param bool $invert (optional) Set to TRUE to retrieve previous dates
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
- * current date if it matches the cron expression
- *
- * @return array Returns an array of run dates
- */
- public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false)
- {
- $matches = array();
- for ($i = 0; $i < max(0, $total); $i++) {
- $matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate);
- }
-
- return $matches;
- }
-
- /**
- * Get all or part of the CRON expression
- *
- * @param string $part (optional) Specify the part to retrieve or NULL to
- * get the full cron schedule string.
- *
- * @return string|null Returns the CRON expression, a part of the
- * CRON expression, or NULL if the part was specified but not found
- */
- public function getExpression($part = null)
- {
- if (null === $part) {
- return implode(' ', $this->cronParts);
- } elseif (array_key_exists($part, $this->cronParts)) {
- return $this->cronParts[$part];
- }
-
- return null;
- }
-
- /**
- * Helper method to output the full expression.
- *
- * @return string Full CRON expression
- */
- public function __toString()
- {
- return $this->getExpression();
- }
-
- /**
- * Determine if the cron is due to run based on the current date or a
- * specific date. This method assumes that the current number of
- * seconds are irrelevant, and should be called once per minute.
- *
- * @param string|DateTime $currentTime (optional) Relative calculation date
- *
- * @return bool Returns TRUE if the cron is due to run or FALSE if not
- */
- public function isDue($currentTime = 'now')
- {
- if ('now' === $currentTime) {
- $currentDate = date('Y-m-d H:i');
- $currentTime = strtotime($currentDate);
- } elseif ($currentTime instanceof DateTime) {
- $currentDate = $currentTime->format('Y-m-d H:i');
- $currentTime = strtotime($currentDate);
- } else {
- $currentTime = new DateTime($currentTime);
- $currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0);
- $currentDate = $currentTime->format('Y-m-d H:i');
- $currentTime = (int)($currentTime->getTimestamp());
- }
-
- return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime;
- }
-
- /**
- * Get the next or previous run date of the expression relative to a date
- *
- * @param string|DateTime $currentTime (optional) Relative calculation date
- * @param int $nth (optional) Number of matches to skip before returning
- * @param bool $invert (optional) Set to TRUE to go backwards in time
- * @param bool $allowCurrentDate (optional) Set to TRUE to return the
- * current date if it matches the cron expression
- *
- * @return DateTime
- * @throws RuntimeException on too many iterations
- */
- protected function getRunDate($currentTime = null, $nth = 0, $invert = false, $allowCurrentDate = false)
- {
- if ($currentTime instanceof DateTime) {
- $currentDate = $currentTime;
- } else {
- $currentDate = new DateTime($currentTime ? $currentTime : 'now');
- $currentDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
- }
-
- $currentDate->setTime($currentDate->format('H'), $currentDate->format('i'), 0);
- $nextRun = clone $currentDate;
- $nth = (int) $nth;
-
- // Set a hard limit to bail on an impossible date
- for ($i = 0; $i < 1000; $i++) {
-
- foreach (self::$order as $position) {
- $part = $this->getExpression($position);
- if (null === $part) {
- continue;
- }
-
- $satisfied = false;
- // Get the field object used to validate this part
- $field = $this->fieldFactory->getField($position);
- // Check if this is singular or a list
- if (strpos($part, ',') === false) {
- $satisfied = $field->isSatisfiedBy($nextRun, $part);
- } else {
- foreach (array_map('trim', explode(',', $part)) as $listPart) {
- if ($field->isSatisfiedBy($nextRun, $listPart)) {
- $satisfied = true;
- break;
- }
- }
- }
-
- // If the field is not satisfied, then start over
- if (!$satisfied) {
- $field->increment($nextRun, $invert);
- continue 2;
- }
- }
-
- // Skip this match if needed
- if ((!$allowCurrentDate && $nextRun == $currentDate) || --$nth > -1) {
- $this->fieldFactory->getField(0)->increment($nextRun, $invert);
- continue;
- }
-
- return $nextRun;
- }
-
- // @codeCoverageIgnoreStart
- throw new RuntimeException('Impossible CRON expression');
- // @codeCoverageIgnoreEnd
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php
deleted file mode 100755
index f8d5c00..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_AbstractField.php
+++ /dev/null
@@ -1,100 +0,0 @@
-
- */
-abstract class CronExpression_AbstractField implements CronExpression_FieldInterface
-{
- /**
- * Check to see if a field is satisfied by a value
- *
- * @param string $dateValue Date value to check
- * @param string $value Value to test
- *
- * @return bool
- */
- public function isSatisfied($dateValue, $value)
- {
- if ($this->isIncrementsOfRanges($value)) {
- return $this->isInIncrementsOfRanges($dateValue, $value);
- } elseif ($this->isRange($value)) {
- return $this->isInRange($dateValue, $value);
- }
-
- return $value == '*' || $dateValue == $value;
- }
-
- /**
- * Check if a value is a range
- *
- * @param string $value Value to test
- *
- * @return bool
- */
- public function isRange($value)
- {
- return strpos($value, '-') !== false;
- }
-
- /**
- * Check if a value is an increments of ranges
- *
- * @param string $value Value to test
- *
- * @return bool
- */
- public function isIncrementsOfRanges($value)
- {
- return strpos($value, '/') !== false;
- }
-
- /**
- * Test if a value is within a range
- *
- * @param string $dateValue Set date value
- * @param string $value Value to test
- *
- * @return bool
- */
- public function isInRange($dateValue, $value)
- {
- $parts = array_map('trim', explode('-', $value, 2));
-
- return $dateValue >= $parts[0] && $dateValue <= $parts[1];
- }
-
- /**
- * Test if a value is within an increments of ranges (offset[-to]/step size)
- *
- * @param string $dateValue Set date value
- * @param string $value Value to test
- *
- * @return bool
- */
- public function isInIncrementsOfRanges($dateValue, $value)
- {
- $parts = array_map('trim', explode('/', $value, 2));
- $stepSize = isset($parts[1]) ? $parts[1] : 0;
- if ($parts[0] == '*' || $parts[0] === '0') {
- return (int) $dateValue % $stepSize == 0;
- }
-
- $range = explode('-', $parts[0], 2);
- $offset = $range[0];
- $to = isset($range[1]) ? $range[1] : $dateValue;
- // Ensure that the date value is within the range
- if ($dateValue < $offset || $dateValue > $to) {
- return false;
- }
-
- for ($i = $offset; $i <= $to; $i+= $stepSize) {
- if ($i == $dateValue) {
- return true;
- }
- }
-
- return false;
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php
deleted file mode 100755
index 40c1d6c..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfMonthField.php
+++ /dev/null
@@ -1,110 +0,0 @@
-
- */
-class CronExpression_DayOfMonthField extends CronExpression_AbstractField
-{
- /**
- * Get the nearest day of the week for a given day in a month
- *
- * @param int $currentYear Current year
- * @param int $currentMonth Current month
- * @param int $targetDay Target day of the month
- *
- * @return DateTime Returns the nearest date
- */
- private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
- {
- $tday = str_pad($targetDay, 2, '0', STR_PAD_LEFT);
- $target = new DateTime("$currentYear-$currentMonth-$tday");
- $currentWeekday = (int) $target->format('N');
-
- if ($currentWeekday < 6) {
- return $target;
- }
-
- $lastDayOfMonth = $target->format('t');
-
- foreach (array(-1, 1, -2, 2) as $i) {
- $adjusted = $targetDay + $i;
- if ($adjusted > 0 && $adjusted <= $lastDayOfMonth) {
- $target->setDate($currentYear, $currentMonth, $adjusted);
- if ($target->format('N') < 6 && $target->format('m') == $currentMonth) {
- return $target;
- }
- }
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function isSatisfiedBy(DateTime $date, $value)
- {
- // ? states that the field value is to be skipped
- if ($value == '?') {
- return true;
- }
-
- $fieldValue = $date->format('d');
-
- // Check to see if this is the last day of the month
- if ($value == 'L') {
- return $fieldValue == $date->format('t');
- }
-
- // Check to see if this is the nearest weekday to a particular value
- if (strpos($value, 'W')) {
- // Parse the target day
- $targetDay = substr($value, 0, strpos($value, 'W'));
- // Find out if the current day is the nearest day of the week
- return $date->format('j') == self::getNearestWeekday(
- $date->format('Y'),
- $date->format('m'),
- $targetDay
- )->format('j');
- }
-
- return $this->isSatisfied($date->format('d'), $value);
- }
-
- /**
- * {@inheritdoc}
- */
- public function increment(DateTime $date, $invert = false)
- {
- if ($invert) {
- $date->modify('previous day');
- $date->setTime(23, 59);
- } else {
- $date->modify('next day');
- $date->setTime(0, 0);
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validate($value)
- {
- return (bool) preg_match('/[\*,\/\-\?LW0-9A-Za-z]+/', $value);
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php
deleted file mode 100755
index e9f68a7..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_DayOfWeekField.php
+++ /dev/null
@@ -1,124 +0,0 @@
-
- */
-class CronExpression_DayOfWeekField extends CronExpression_AbstractField
-{
- /**
- * {@inheritdoc}
- */
- public function isSatisfiedBy(DateTime $date, $value)
- {
- if ($value == '?') {
- return true;
- }
-
- // Convert text day of the week values to integers
- $value = str_ireplace(
- array('SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'),
- range(0, 6),
- $value
- );
-
- $currentYear = $date->format('Y');
- $currentMonth = $date->format('m');
- $lastDayOfMonth = $date->format('t');
-
- // Find out if this is the last specific weekday of the month
- if (strpos($value, 'L')) {
- $weekday = str_replace('7', '0', substr($value, 0, strpos($value, 'L')));
- $tdate = clone $date;
- $tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
- while ($tdate->format('w') != $weekday) {
- $tdate->setDate($currentYear, $currentMonth, --$lastDayOfMonth);
- }
-
- return $date->format('j') == $lastDayOfMonth;
- }
-
- // Handle # hash tokens
- if (strpos($value, '#')) {
- list($weekday, $nth) = explode('#', $value);
- // Validate the hash fields
- if ($weekday < 1 || $weekday > 5) {
- throw new InvalidArgumentException("Weekday must be a value between 1 and 5. {$weekday} given");
- }
- if ($nth > 5) {
- throw new InvalidArgumentException('There are never more than 5 of a given weekday in a month');
- }
- // The current weekday must match the targeted weekday to proceed
- if ($date->format('N') != $weekday) {
- return false;
- }
-
- $tdate = clone $date;
- $tdate->setDate($currentYear, $currentMonth, 1);
- $dayCount = 0;
- $currentDay = 1;
- while ($currentDay < $lastDayOfMonth + 1) {
- if ($tdate->format('N') == $weekday) {
- if (++$dayCount >= $nth) {
- break;
- }
- }
- $tdate->setDate($currentYear, $currentMonth, ++$currentDay);
- }
-
- return $date->format('j') == $currentDay;
- }
-
- // Handle day of the week values
- if (strpos($value, '-')) {
- $parts = explode('-', $value);
- if ($parts[0] == '7') {
- $parts[0] = '0';
- } elseif ($parts[1] == '0') {
- $parts[1] = '7';
- }
- $value = implode('-', $parts);
- }
-
- // Test to see which Sunday to use -- 0 == 7 == Sunday
- $format = in_array(7, str_split($value)) ? 'N' : 'w';
- $fieldValue = $date->format($format);
-
- return $this->isSatisfied($fieldValue, $value);
- }
-
- /**
- * {@inheritdoc}
- */
- public function increment(DateTime $date, $invert = false)
- {
- if ($invert) {
- $date->modify('-1 day');
- $date->setTime(23, 59, 0);
- } else {
- $date->modify('+1 day');
- $date->setTime(0, 0, 0);
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validate($value)
- {
- return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value);
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php
deleted file mode 100755
index 556ba1a..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldFactory.php
+++ /dev/null
@@ -1,55 +0,0 @@
-
- * @link http://en.wikipedia.org/wiki/Cron
- */
-class CronExpression_FieldFactory
-{
- /**
- * @var array Cache of instantiated fields
- */
- private $fields = array();
-
- /**
- * Get an instance of a field object for a cron expression position
- *
- * @param int $position CRON expression position value to retrieve
- *
- * @return CronExpression_FieldInterface
- * @throws InvalidArgumentException if a position is not valid
- */
- public function getField($position)
- {
- if (!isset($this->fields[$position])) {
- switch ($position) {
- case 0:
- $this->fields[$position] = new CronExpression_MinutesField();
- break;
- case 1:
- $this->fields[$position] = new CronExpression_HoursField();
- break;
- case 2:
- $this->fields[$position] = new CronExpression_DayOfMonthField();
- break;
- case 3:
- $this->fields[$position] = new CronExpression_MonthField();
- break;
- case 4:
- $this->fields[$position] = new CronExpression_DayOfWeekField();
- break;
- case 5:
- $this->fields[$position] = new CronExpression_YearField();
- break;
- default:
- throw new InvalidArgumentException(
- $position . ' is not a valid position'
- );
- }
- }
-
- return $this->fields[$position];
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php
deleted file mode 100755
index 5d5109b..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_FieldInterface.php
+++ /dev/null
@@ -1,39 +0,0 @@
-
- */
-interface CronExpression_FieldInterface
-{
- /**
- * Check if the respective value of a DateTime field satisfies a CRON exp
- *
- * @param DateTime $date DateTime object to check
- * @param string $value CRON expression to test against
- *
- * @return bool Returns TRUE if satisfied, FALSE otherwise
- */
- public function isSatisfiedBy(DateTime $date, $value);
-
- /**
- * When a CRON expression is not satisfied, this method is used to increment
- * or decrement a DateTime object by the unit of the cron field
- *
- * @param DateTime $date DateTime object to change
- * @param bool $invert (optional) Set to TRUE to decrement
- *
- * @return CronExpression_FieldInterface
- */
- public function increment(DateTime $date, $invert = false);
-
- /**
- * Validates a CRON expression for a given field
- *
- * @param string $value CRON expression value to validate
- *
- * @return bool Returns TRUE if valid, FALSE otherwise
- */
- public function validate($value);
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php
deleted file mode 100755
index 088ca73..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_HoursField.php
+++ /dev/null
@@ -1,47 +0,0 @@
-
- */
-class CronExpression_HoursField extends CronExpression_AbstractField
-{
- /**
- * {@inheritdoc}
- */
- public function isSatisfiedBy(DateTime $date, $value)
- {
- return $this->isSatisfied($date->format('H'), $value);
- }
-
- /**
- * {@inheritdoc}
- */
- public function increment(DateTime $date, $invert = false)
- {
- // Change timezone to UTC temporarily. This will
- // allow us to go back or forwards and hour even
- // if DST will be changed between the hours.
- $timezone = $date->getTimezone();
- $date->setTimezone(new DateTimeZone('UTC'));
- if ($invert) {
- $date->modify('-1 hour');
- $date->setTime($date->format('H'), 59);
- } else {
- $date->modify('+1 hour');
- $date->setTime($date->format('H'), 0);
- }
- $date->setTimezone($timezone);
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validate($value)
- {
- return (bool) preg_match('/[\*,\/\-0-9]+/', $value);
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php
deleted file mode 100755
index 436acf2..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MinutesField.php
+++ /dev/null
@@ -1,39 +0,0 @@
-
- */
-class CronExpression_MinutesField extends CronExpression_AbstractField
-{
- /**
- * {@inheritdoc}
- */
- public function isSatisfiedBy(DateTime $date, $value)
- {
- return $this->isSatisfied($date->format('i'), $value);
- }
-
- /**
- * {@inheritdoc}
- */
- public function increment(DateTime $date, $invert = false)
- {
- if ($invert) {
- $date->modify('-1 minute');
- } else {
- $date->modify('+1 minute');
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validate($value)
- {
- return (bool) preg_match('/[\*,\/\-0-9]+/', $value);
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php
deleted file mode 100755
index d3deb12..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_MonthField.php
+++ /dev/null
@@ -1,55 +0,0 @@
-
- */
-class CronExpression_MonthField extends CronExpression_AbstractField
-{
- /**
- * {@inheritdoc}
- */
- public function isSatisfiedBy(DateTime $date, $value)
- {
- // Convert text month values to integers
- $value = str_ireplace(
- array(
- 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN',
- 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'
- ),
- range(1, 12),
- $value
- );
-
- return $this->isSatisfied($date->format('m'), $value);
- }
-
- /**
- * {@inheritdoc}
- */
- public function increment(DateTime $date, $invert = false)
- {
- if ($invert) {
- // $date->modify('last day of previous month'); // remove for php 5.2 compat
- $date->modify('previous month');
- $date->modify($date->format('Y-m-t'));
- $date->setTime(23, 59);
- } else {
- //$date->modify('first day of next month'); // remove for php 5.2 compat
- $date->modify('next month');
- $date->modify($date->format('Y-m-01'));
- $date->setTime(0, 0);
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validate($value)
- {
- return (bool) preg_match('/[\*,\/\-0-9A-Z]+/', $value);
- }
-}
diff --git a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php b/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php
deleted file mode 100755
index f11562e..0000000
--- a/includes/libraries/action-scheduler/lib/cron-expression/CronExpression_YearField.php
+++ /dev/null
@@ -1,43 +0,0 @@
-
- */
-class CronExpression_YearField extends CronExpression_AbstractField
-{
- /**
- * {@inheritdoc}
- */
- public function isSatisfiedBy(DateTime $date, $value)
- {
- return $this->isSatisfied($date->format('Y'), $value);
- }
-
- /**
- * {@inheritdoc}
- */
- public function increment(DateTime $date, $invert = false)
- {
- if ($invert) {
- $date->modify('-1 year');
- $date->setDate($date->format('Y'), 12, 31);
- $date->setTime(23, 59, 0);
- } else {
- $date->modify('+1 year');
- $date->setDate($date->format('Y'), 1, 1);
- $date->setTime(0, 0, 0);
- }
-
- return $this;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validate($value)
- {
- return (bool) preg_match('/[\*,\/\-0-9]+/', $value);
- }
-}
diff --git a/includes/libraries/class-wc-datetime.php b/includes/libraries/class-wc-datetime.php
deleted file mode 100644
index f36c14e..0000000
--- a/includes/libraries/class-wc-datetime.php
+++ /dev/null
@@ -1,73 +0,0 @@
-format( DATE_ATOM );
- }
-
- /**
- * Missing in PHP 5.2.
- *
- * @since 3.0.0
- * @return int
- */
- public function getTimestamp() {
- return method_exists( 'DateTime', 'getTimestamp' ) ? parent::getTimestamp() : $this->format( 'U' );
- }
-
- /**
- * Get the timestamp with the WordPress timezone offset added or subtracted.
- *
- * @since 3.0.0
- * @return int
- */
- public function getOffsetTimestamp() {
- return $this->getTimestamp() + $this->getOffset();
- }
-
- /**
- * Format a date based on the offset timestamp.
- *
- * @since 3.0.0
- * @param string $format
- * @return string
- */
- public function date( $format ) {
- return gmdate( $format, $this->getOffsetTimestamp() );
- }
-
- /**
- * Return a localised date based on offset timestamp. Wrapper for date_i18n function.
- *
- * @since 3.0.0
- * @param string $format
- * @return string
- */
- public function date_i18n( $format = 'Y-m-d' ) {
- return date_i18n( $format, $this->getOffsetTimestamp() );
- }
-}
diff --git a/includes/admin/meta-boxes/class-wcs-meta-box-payment-retries.php b/includes/payment-retry/admin/class-wcs-meta-box-payment-retries.php
similarity index 90%
rename from includes/admin/meta-boxes/class-wcs-meta-box-payment-retries.php
rename to includes/payment-retry/admin/class-wcs-meta-box-payment-retries.php
index 25e0ca1..f90e183 100644
--- a/includes/admin/meta-boxes/class-wcs-meta-box-payment-retries.php
+++ b/includes/payment-retry/admin/class-wcs-meta-box-payment-retries.php
@@ -28,7 +28,7 @@ class WCS_Meta_Box_Payment_Retries {
$retries = WCS_Retry_Manager::store()->get_retries_for_order( $post->ID );
- include_once( dirname( __FILE__ ) . '/views/html-retries-table.php' );
+ include_once( dirname( __FILE__ ) . '/html-retries-table.php' );
do_action( 'woocommerce_subscriptions_retries_meta_box', $post->ID, $retries );
}
diff --git a/includes/payment-retry/class-wcs-retry-admin.php b/includes/payment-retry/admin/class-wcs-retry-admin.php
similarity index 100%
rename from includes/payment-retry/class-wcs-retry-admin.php
rename to includes/payment-retry/admin/class-wcs-retry-admin.php
diff --git a/includes/admin/meta-boxes/views/html-retries-table.php b/includes/payment-retry/admin/html-retries-table.php
similarity index 100%
rename from includes/admin/meta-boxes/views/html-retries-table.php
rename to includes/payment-retry/admin/html-retries-table.php
diff --git a/includes/class-wcs-retry-manager.php b/includes/payment-retry/class-wcs-retry-manager.php
similarity index 98%
rename from includes/class-wcs-retry-manager.php
rename to includes/payment-retry/class-wcs-retry-manager.php
index 20bbc4d..4801305 100644
--- a/includes/class-wcs-retry-manager.php
+++ b/includes/payment-retry/class-wcs-retry-manager.php
@@ -274,14 +274,11 @@ class WCS_Retry_Manager {
* When a retry hook is triggered, check if the rules for that retry are still valid
* and if so, retry the payment.
*
- * @param WC_Order|int The order on which the payment failed
- * @since 2.1
+ * @since 2.1.0
+ * @param WC_Order|int The order on which the payment failed.
*/
- public static function maybe_retry_payment( $last_order ) {
-
- if ( ! is_object( $last_order ) ) {
- $last_order = wc_get_order( $last_order );
- }
+ public static function maybe_retry_payment( $order_id ) {
+ $last_order = ! is_object( $order_id ) ? wc_get_order( $order_id ) : $order_id;
if ( false === $last_order ) {
return;
diff --git a/includes/abstracts/abstract-wcs-retry-store.php b/includes/payment-retry/data-stores/abstract-wcs-retry-store.php
similarity index 100%
rename from includes/abstracts/abstract-wcs-retry-store.php
rename to includes/payment-retry/data-stores/abstract-wcs-retry-store.php
diff --git a/includes/payment-retry/class-wcs-retry-database-store.php b/includes/payment-retry/data-stores/class-wcs-retry-database-store.php
similarity index 100%
rename from includes/payment-retry/class-wcs-retry-database-store.php
rename to includes/payment-retry/data-stores/class-wcs-retry-database-store.php
diff --git a/includes/payment-retry/class-wcs-retry-hybrid-store.php b/includes/payment-retry/data-stores/class-wcs-retry-hybrid-store.php
similarity index 100%
rename from includes/payment-retry/class-wcs-retry-hybrid-store.php
rename to includes/payment-retry/data-stores/class-wcs-retry-hybrid-store.php
diff --git a/includes/payment-retry/class-wcs-retry-post-store.php b/includes/payment-retry/data-stores/class-wcs-retry-post-store.php
similarity index 100%
rename from includes/payment-retry/class-wcs-retry-post-store.php
rename to includes/payment-retry/data-stores/class-wcs-retry-post-store.php
diff --git a/includes/payment-retry/class-wcs-retry-stores.php b/includes/payment-retry/data-stores/class-wcs-retry-stores.php
similarity index 100%
rename from includes/payment-retry/class-wcs-retry-stores.php
rename to includes/payment-retry/data-stores/class-wcs-retry-stores.php
diff --git a/includes/emails/class-wcs-email-customer-payment-retry.php b/includes/payment-retry/emails/class-wcs-email-customer-payment-retry.php
similarity index 97%
rename from includes/emails/class-wcs-email-customer-payment-retry.php
rename to includes/payment-retry/emails/class-wcs-email-customer-payment-retry.php
index 2db1b9a..22b6a48 100644
--- a/includes/emails/class-wcs-email-customer-payment-retry.php
+++ b/includes/payment-retry/emails/class-wcs-email-customer-payment-retry.php
@@ -27,7 +27,7 @@ class WCS_Email_Customer_Payment_Retry extends WCS_Email_Customer_Renewal_Invoic
$this->template_html = 'emails/customer-payment-retry.php';
$this->template_plain = 'emails/plain/customer-payment-retry.php';
- $this->template_base = plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/';
+ $this->template_base = WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/' );
$this->subject = __( 'Automatic payment failed for {order_number}, we will retry {retry_time}', 'woocommerce-subscriptions' );
$this->heading = __( 'Automatic payment failed for order {order_number}', 'woocommerce-subscriptions' );
diff --git a/includes/emails/class-wcs-email-payment-retry.php b/includes/payment-retry/emails/class-wcs-email-payment-retry.php
similarity index 97%
rename from includes/emails/class-wcs-email-payment-retry.php
rename to includes/payment-retry/emails/class-wcs-email-payment-retry.php
index 44ccc08..71722f4 100644
--- a/includes/emails/class-wcs-email-payment-retry.php
+++ b/includes/payment-retry/emails/class-wcs-email-payment-retry.php
@@ -31,7 +31,7 @@ class WCS_Email_Payment_Retry extends WC_Email_Failed_Order {
$this->template_html = 'emails/admin-payment-retry.php';
$this->template_plain = 'emails/plain/admin-payment-retry.php';
- $this->template_base = plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'templates/';
+ $this->template_base = WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'templates/' );
// We want all the parent's methods, with none of its properties, so call its parent's constructor, rather than my parent constructor
WC_Email::__construct();
diff --git a/includes/payment-retry/class-wcs-retry-email.php b/includes/payment-retry/emails/class-wcs-retry-email.php
similarity index 100%
rename from includes/payment-retry/class-wcs-retry-email.php
rename to includes/payment-retry/emails/class-wcs-retry-email.php
diff --git a/includes/class-wc-order-item-pending-switch.php b/includes/switching/class-wc-order-item-pending-switch.php
similarity index 100%
rename from includes/class-wc-order-item-pending-switch.php
rename to includes/switching/class-wc-order-item-pending-switch.php
diff --git a/includes/class-wc-subscriptions-switcher.php b/includes/switching/class-wc-subscriptions-switcher.php
similarity index 94%
rename from includes/class-wc-subscriptions-switcher.php
rename to includes/switching/class-wc-subscriptions-switcher.php
index 2a588f0..bc30b45 100644
--- a/includes/class-wc-subscriptions-switcher.php
+++ b/includes/switching/class-wc-subscriptions-switcher.php
@@ -36,7 +36,7 @@ class WC_Subscriptions_Switcher {
add_filter( 'post_type_link', array( __CLASS__, 'add_switch_query_arg_post_link' ), 12, 2 );
// Add the settings to control whether Switching is enabled and how it will behave
- add_filter( 'woocommerce_subscription_settings', array( __CLASS__, 'add_settings' ) );
+ add_filter( 'woocommerce_subscription_settings', array( __CLASS__, 'add_settings' ), 15 );
// Render "wcs_switching_options" field
add_action( 'woocommerce_admin_field_wcs_switching_options', __CLASS__ . '::switching_options_field_html' );
@@ -47,11 +47,22 @@ class WC_Subscriptions_Switcher {
// We need to create subscriptions on checkout and want to do it after almost all other extensions have added their products/items/fees
add_action( 'woocommerce_checkout_order_processed', array( __CLASS__, 'process_checkout' ), 50, 2 );
+ // Same as above for WooCommerce Blocks.
+ add_action( 'woocommerce_store_api_checkout_order_processed', array( __CLASS__, 'process_checkout' ), 50, 1 );
+
// When creating an order, add meta if it's for switching a subscription
add_action( 'woocommerce_checkout_update_order_meta', array( __CLASS__, 'add_order_meta' ), 10, 2 );
- // Add a renewal orders section to the Related Orders meta box
- add_action( 'woocommerce_subscriptions_related_orders_meta_box_rows', array( __CLASS__, 'switch_order_meta_box_rows' ), 10 );
+ // Same as above for WooCommerce Blocks.
+ if ( class_exists( 'Automattic\WooCommerce\Blocks\Package' ) ) {
+ if ( version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '7.2.0', '>=' ) ) {
+ add_action( 'woocommerce_store_api_checkout_update_order_meta', array( __CLASS__, 'add_order_meta' ), 10, 1 );
+ } elseif ( version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '6.3.0', '>=' ) ) {
+ add_action( 'woocommerce_blocks_checkout_update_order_meta', array( __CLASS__, 'add_order_meta' ), 10, 1 );
+ } else {
+ add_action( '__experimental_woocommerce_blocks_checkout_update_order_meta', array( __CLASS__, 'add_order_meta' ), 10, 1 );
+ }
+ }
// Don't allow switching to the same product
add_filter( 'woocommerce_add_to_cart_validation', array( __CLASS__, 'validate_switch_request' ), 10, 4 );
@@ -138,6 +149,10 @@ class WC_Subscriptions_Switcher {
add_action( 'woocommerce_grant_product_download_permissions', array( __CLASS__, 'delay_granting_download_permissions' ), 9, 1 );
add_action( 'woocommerce_subscriptions_switch_completed', array( __CLASS__, 'grant_download_permissions' ), 9, 1 );
add_action( 'woocommerce_subscription_checkout_switch_order_processed', array( __CLASS__, 'log_switches' ) );
+ add_filter( 'woocommerce_subscriptions_admin_related_orders_to_display', array( __CLASS__, 'display_switches_in_related_order_metabox' ), 10, 3 );
+
+ // Override the add to cart text when switch args are present.
+ add_filter( 'woocommerce_product_single_add_to_cart_text', array( __CLASS__, 'display_switch_add_to_cart_text' ), 10, 1 );
}
/**
@@ -147,7 +162,7 @@ class WC_Subscriptions_Switcher {
*/
public static function attach_dependant_hooks() {
- if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( wcs_is_woocommerce_pre( '3.0' ) ) {
// For order items created as part of a switch, keep a record of the prorated amounts
add_action( 'woocommerce_add_order_item_meta', array( __CLASS__, 'add_order_item_meta' ), 10, 3 );
@@ -370,8 +385,7 @@ class WC_Subscriptions_Switcher {
*/
public static function add_settings( $settings ) {
- array_splice( $settings, 12, 0, array(
-
+ $switching_settings = array(
array(
'name' => __( 'Switching', 'woocommerce-subscriptions' ),
'type' => 'title',
@@ -379,12 +393,10 @@ class WC_Subscriptions_Switcher {
'desc' => sprintf( __( 'Allow subscribers to switch (upgrade or downgrade) between different subscriptions. %1$sLearn more%2$s.', 'woocommerce-subscriptions' ), '', ' ' ),
'id' => WC_Subscriptions_Admin::$option_prefix . '_switch_settings',
),
-
array(
'type' => 'wcs_switching_options',
'id' => WC_Subscriptions_Admin::$option_prefix . '_allow_switching',
),
-
array(
'name' => __( 'Prorate Recurring Payment', 'woocommerce-subscriptions' ),
'desc' => __( '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?', 'woocommerce-subscriptions' ),
@@ -402,7 +414,6 @@ class WC_Subscriptions_Switcher {
),
'desc_tip' => true,
),
-
array(
'name' => __( 'Prorate Sign up Fee', 'woocommerce-subscriptions' ),
'desc' => __( '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).', 'woocommerce-subscriptions' ),
@@ -418,7 +429,6 @@ class WC_Subscriptions_Switcher {
),
'desc_tip' => true,
),
-
array(
'name' => __( 'Prorate Subscription Length', 'woocommerce-subscriptions' ),
'desc' => __( '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.', 'woocommerce-subscriptions' ),
@@ -434,7 +444,6 @@ class WC_Subscriptions_Switcher {
),
'desc_tip' => true,
),
-
array(
'name' => __( 'Switch Button Text', 'woocommerce-subscriptions' ),
'desc' => __( '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".', 'woocommerce-subscriptions' ),
@@ -445,12 +454,16 @@ class WC_Subscriptions_Switcher {
'type' => 'text',
'desc_tip' => true,
),
-
array(
'type' => 'sectionend',
'id' => WC_Subscriptions_Admin::$option_prefix . '_switch_settings',
),
- ) );
+ );
+
+ // Insert the switch settings in after the synchronisation section otherwise add them to the end.
+ if ( ! WC_Subscriptions_Admin::insert_setting_after( $settings, WC_Subscriptions_Synchroniser::$setting_id . '_title', $switching_settings, 'multiple-settings', 'sectionend' ) ) {
+ $settings = array_merge( $settings, $switching_settings );
+ }
return $settings;
}
@@ -538,9 +551,11 @@ class WC_Subscriptions_Switcher {
return;
}
- $switch_url = esc_url( self::get_switch_url( $item_id, $item, $subscription ) );
- $switch_text = get_option( WC_Subscriptions_Admin::$option_prefix . '_switch_button_text', __( 'Upgrade or Downgrade', 'woocommerce-subscriptions' ) );
- $switch_link = sprintf( '%s ', $switch_url, $switch_text );
+ $switch_url = esc_url( self::get_switch_url( $item_id, $item, $subscription ) );
+ $switch_text = apply_filters( 'woocommerce_subscriptions_switch_link_text', get_option( WC_Subscriptions_Admin::$option_prefix . '_switch_button_text', __( 'Upgrade or Downgrade', 'woocommerce-subscriptions' ) ), $item_id, $item, $subscription );
+ $switch_classes = apply_filters( 'woocommerce_subscriptions_switch_link_classes', array( 'wcs-switch-link', 'button' ), $item_id, $item, $subscription );
+
+ $switch_link = sprintf( '%s ', $switch_url, implode( ' ', (array) $switch_classes ), $switch_text );
echo wp_kses( apply_filters( 'woocommerce_subscriptions_switch_link', $switch_link, $item_id, $item, $subscription ), array( 'a' => array( 'href' => array(), 'title' => array(), 'class' => array() ) ) ); // phpcs:ignore WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound
}
@@ -558,7 +573,7 @@ class WC_Subscriptions_Switcher {
$subscription = wcs_get_subscription( $subscription );
}
- $product = wc_get_product( $item['product_id'] );
+ $product = wc_get_product( $item['product_id'] );
$parent_products = WC_Subscriptions_Product::get_visible_grouped_parent_product_ids( $product );
$additional_query_args = array();
@@ -569,7 +584,13 @@ class WC_Subscriptions_Switcher {
$switch_url = get_permalink( $product->get_id() );
if ( ! empty( $_GET ) && is_product() ) {
- $product_variations = $product->get_variation_attributes();
+ $product_variations = array();
+
+ // Attributes in GET args are prefixed with attribute_ so to make sure we compare them correctly, apply the same prefix.
+ foreach ( $product->get_variation_attributes() as $attribute => $value ) {
+ $product_variations[ wcs_maybe_prefix_key( strtolower( $attribute ), 'attribute_' ) ] = $value;
+ }
+
$additional_query_args = array_intersect_key( $_GET, $product_variations );
}
}
@@ -757,11 +778,11 @@ class WC_Subscriptions_Switcher {
* If the order being generated is for switching a subscription, keep a record of some of the switch
* routines meta against the order.
*
- * @param int $order_id The ID of a WC_Order object
- * @param array $posted The data posted on checkout
+ * @param int|\WC_Order $order_id The ID of a WC_Order object
+ * @param array $posted The data posted on checkout
* @since 1.4
*/
- public static function add_order_meta( $order_id, $posted ) {
+ public static function add_order_meta( $order_id, $posted = array() ) {
$order = wc_get_order( $order_id );
@@ -789,7 +810,7 @@ class WC_Subscriptions_Switcher {
*/
public static function add_order_item_meta( $order_item_id, $cart_item, $cart_item_key ) {
- if ( false === WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( false === wcs_is_woocommerce_pre( '3.0' ) ) {
_deprecated_function( __METHOD__, '2.2.0 and WooCommerce 3.0.0', __CLASS__ . '::add_order_line_item_meta( $order_item, $cart_item_key, $cart_item )' );
}
@@ -840,7 +861,7 @@ class WC_Subscriptions_Switcher {
if ( wcs_is_subscription( $order ) ) {
if ( ! empty( $switch_details['item_id'] ) ) {
- $order_item->add_meta_data( '_switched_subscription_item_id', $switch_details['item_id'] );
+ $order_item->update_meta_data( '_switched_subscription_item_id', $switch_details['item_id'] );
}
} else {
$sign_up_fee_prorated = WC()->cart->cart_contents[ $cart_item_key ]['data']->get_meta( '_subscription_sign_up_fee_prorated', true );
@@ -863,7 +884,7 @@ class WC_Subscriptions_Switcher {
*/
public static function set_subscription_item_meta( $item_id, $cart_item, $cart_item_key ) {
- if ( ! WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( ! wcs_is_woocommerce_pre( '3.0' ) ) {
_deprecated_function( __METHOD__, '2.2.0', __CLASS__ . '::add_subscription_line_item_meta( $order_item, $cart_item_key, $cart_item )' );
}
@@ -887,11 +908,12 @@ class WC_Subscriptions_Switcher {
* If the item is on a new billing schedule and there are other items on the existing subscription, the old item will
* be removed and the new item will be added to a new subscription by @see WC_Subscriptions_Checkout::process_checkout()
*
- * @param int $order_id The post_id of a shop_order post/WC_Order object
- * @param array $posted_data The data posted on checkout
+ * @param int|\WC_Order $order_id The post_id of a shop_order post/WC_Order
+ * object
+ * @param array $posted_data The data posted on checkout
* @since 2.0
*/
- public static function process_checkout( $order_id, $posted_data ) {
+ public static function process_checkout( $order_id, $posted_data = array() ) {
global $wpdb;
if ( ! WC_Subscriptions_Cart::cart_contains_subscription() ) {
@@ -937,7 +959,7 @@ class WC_Subscriptions_Switcher {
if ( $is_single_item_subscription || ( false === $is_different_billing_schedule && false === $is_different_payment_date && false === $is_different_length ) ) {
// Add the new item
- if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( wcs_is_woocommerce_pre( '3.0' ) ) {
$item_id = WC_Subscriptions_Checkout::add_cart_item( $subscription, $cart_item, $cart_item_key );
wcs_update_order_item_type( $item_id, 'line_item_pending_switch', $subscription->get_id() );
} else {
@@ -1084,7 +1106,7 @@ class WC_Subscriptions_Switcher {
WC_Subscriptions_Checkout::add_shipping( $subscription, $recurring_cart );
- if ( ! WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( ! wcs_is_woocommerce_pre( '3.0' ) ) {
// We must save the subscription, we need the Shipping method saved
// otherwise the ID is bogus (new:1) and we need it.
$subscription->save();
@@ -1099,7 +1121,7 @@ class WC_Subscriptions_Switcher {
}
}
- if ( WC_Subscriptions::is_woocommerce_pre( '3.0' ) ) {
+ if ( wcs_is_woocommerce_pre( '3.0' ) ) {
$subscription->set_total( $subscription_shipping_total, 'shipping' );
} else {
$subscription->set_shipping_total( $subscription_shipping_total );
@@ -1159,84 +1181,20 @@ class WC_Subscriptions_Switcher {
/**
* Updates address on the subscription if one of them is changed.
*
- * @param WC_Order $order The new order
- * @param WC_Subscription $subscription The original subscription
+ * @param WC_Order $order The new order
+ * @param WC_Subscription $subscription The original subscription
*/
public static function maybe_update_subscription_address( $order, $subscription ) {
-
- if ( method_exists( $subscription, 'get_address' ) ) {
-
- $order_billing = $order->get_address( 'billing' );
- $order_shipping = $order->get_address();
- $subscription_billing = $subscription->get_address( 'billing' );
- $subscription_shipping = $subscription->get_address();
-
- } else {
-
- $order_billing = wcs_get_order_address( $order, 'billing' );
- $order_shipping = wcs_get_order_address( $order );
- $subscription_billing = wcs_get_order_address( $subscription, 'billing' );
- $subscription_shipping = wcs_get_order_address( $subscription );
-
- }
-
- $subscription->set_address( array_diff_assoc( $order_billing, $subscription_billing ), 'billing' );
- $subscription->set_address( array_diff_assoc( $order_shipping, $subscription_shipping ), 'shipping' );
-
- }
-
- /**
- * If the subscription purchased in an order has since been switched, include a link to the order placed to switch the subscription
- * in the "Related Orders" meta box (displayed on the Edit Order screen).
- *
- * @param WC_Order $order The current order.
- * @since 1.4
- */
- public static function switch_order_meta_box_rows( $post ) {
-
- $subscriptions = array();
- $switched_subscriptions = array();
- $orders = array();
-
- // On the subscription page, just show related orders
- if ( wcs_is_subscription( $post->ID ) ) {
-
- // Select the orders which switched item/s from this subscription
- $orders = wcs_get_switch_orders_for_subscription( $post->ID );
-
- foreach ( $orders as $order_id => $order ) {
- wcs_set_objects_property( $order, 'relationship', __( 'Switch Order', 'woocommerce-subscriptions' ), 'set_prop_only' );
- }
-
- // Select the subscriptions which had item/s switched to this subscription by its parent order
- if ( ! empty( $post->post_parent ) ) {
- $switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->post_parent );
- }
-
- // On the Edit Order screen, show any subscriptions with items switched by this order
- } else {
- $switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->ID );
- }
-
- if ( is_array( $switched_subscriptions ) ) {
- foreach ( $switched_subscriptions as $subscription_id => $subscription ) {
- wcs_set_objects_property( $subscription, 'relationship', __( 'Switched Subscription', 'woocommerce-subscriptions' ), 'set_prop_only' );
- $orders[ $subscription_id ] = $subscription;
- }
- }
-
- foreach ( $orders as $order ) {
- include( plugin_dir_path( WC_Subscriptions::$plugin_file ) . 'includes/admin/meta-boxes/views/html-related-orders-row.php' );
- }
-
+ $subscription->set_address( array_diff_assoc( $order->get_address( 'billing' ), $subscription->get_address( 'billing' ) ), 'billing' );
+ $subscription->set_address( array_diff_assoc( $order->get_address( 'shipping' ), $subscription->get_address( 'shipping' ) ), 'shipping' );
}
/**
* Check if the cart includes any items which are to switch an existing subscription's contents.
*
- * @return bool|array Returns cart items that modify subscription contents, or false if no such items exist.
* @since 2.0
* @param string $item_action Types of items to include ("any", "switch", or "add").
+ * @return bool|array Returns cart items that modify subscription contents, or false if no such items exist.
*/
public static function cart_contains_switches( $item_action = 'switch' ) {
$subscription_switches = false;
@@ -1753,8 +1711,6 @@ class WC_Subscriptions_Switcher {
* @since 2.1
*/
public static function process_subscription_switches( $order_id, $order_old_status, $order_new_status ) {
- global $wpdb;
-
$order = wc_get_order( $order_id );
$switch_processed = wcs_get_objects_property( $order, 'completed_subscription_switch' );
@@ -1767,16 +1723,17 @@ class WC_Subscriptions_Switcher {
if ( $order_completed ) {
try {
// Start transaction if available
- $wpdb->query( 'START TRANSACTION' );
+ $transaction = new WCS_SQL_Transaction();
+ $transaction->start();
self::complete_subscription_switches( $order );
wcs_set_objects_property( $order, 'completed_subscription_switch', 'true' );
- $wpdb->query( 'COMMIT' );
+ $transaction->commit();
} catch ( Exception $e ) {
- $wpdb->query( 'ROLLBACK' );
+ $transaction->rollback();
throw $e;
}
@@ -1883,6 +1840,16 @@ class WC_Subscriptions_Switcher {
return $product_subtotal;
}
+ /**
+ * Gets the switch direction of a cart item.
+ *
+ * @param array $cart_item Cart item object.
+ * @return string|null Cart item subscription switch direction or null.
+ */
+ public static function get_cart_item_switch_type( $cart_item ) {
+ return isset( $cart_item['subscription_switch'], $cart_item['subscription_switch']['upgraded_or_downgraded'] ) ? $cart_item['subscription_switch']['upgraded_or_downgraded'] : null;
+ }
+
/**
* Creates a 2.0 updated version of the "subscriptions_switched" callback for developers to hook onto.
*
@@ -2101,7 +2068,7 @@ class WC_Subscriptions_Switcher {
*/
public static function set_force_payment_flag_in_cart( $total ) {
- if ( $total > 0 || 'yes' == get_option( WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no' ) || false === self::cart_contains_switches( 'any' ) ) {
+ if ( $total > 0 || wcs_is_manual_renewal_required() || false === self::cart_contains_switches( 'any' ) ) {
return $total;
}
@@ -2178,7 +2145,7 @@ class WC_Subscriptions_Switcher {
public static function maybe_set_payment_method_after_switch( $order ) {
// Only set manual subscriptions to automatic if automatic payments are enabled
- if ( 'yes' == get_option( WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no' ) ) {
+ if ( wcs_is_manual_renewal_required() ) {
return;
}
@@ -2239,13 +2206,14 @@ class WC_Subscriptions_Switcher {
* @param WC_Subscription $subscription The Subscription.
* @param WC_Order_Item $subscription_item The current line item on the subscription to map back through the related orders.
* @param string $include_sign_up_fees Optional. Whether to include the sign-up fees paid. Can be 'include_sign_up_fees' or 'exclude_sign_up_fees'. Default 'include_sign_up_fees'.
+ * @param WC_Order[] $orders_to_include Optional. The orders to include in the total.
*
* @return float The total amount paid for an existing subscription line item.
*/
- public static function calculate_total_paid_since_last_order( $subscription, $subscription_item, $include_sign_up_fees = 'include_sign_up_fees' ) {
+ public static function calculate_total_paid_since_last_order( $subscription, $subscription_item, $include_sign_up_fees = 'include_sign_up_fees', $orders_to_include = array() ) {
$found_item = false;
$item_total_paid = 0;
- $orders = $subscription->get_related_orders( 'all', array( 'parent', 'renewal', 'switch' ) );
+ $orders = empty( $orders_to_include ) ? $subscription->get_related_orders( 'all', array( 'parent', 'renewal', 'switch' ) ) : $orders_to_include;
// We need the orders sorted by the date they were paid, with the newest first.
wcs_sort_objects( $orders, 'date_paid', 'descending' );
@@ -2334,6 +2302,46 @@ class WC_Subscriptions_Switcher {
}
}
+ /**
+ * Adds switch orders or switched subscriptions to the related order meta box.
+ *
+ * @since 3.1.0
+ *
+ * @param WC_Abstract_Order[] $orders_to_display The list of related orders to display.
+ * @param WC_Subscription[] $subscriptions The list of related subscriptions.
+ * @param WP_Post $post The order or subscription post being viewed.
+ *
+ * @return $orders_to_display The orders/subscriptions to display in the meta box.
+ */
+ public static function display_switches_in_related_order_metabox( $orders_to_display, $subscriptions, $post ) {
+ $switched_subscriptions = array();
+
+ // On the subscription page, just show related orders.
+ if ( wcs_is_subscription( $post->ID ) ) {
+
+ foreach ( wcs_get_switch_orders_for_subscription( $post->ID ) as $order ) {
+ $order->update_meta_data( '_relationship', __( 'Switch Order', 'woocommerce-subscriptions' ) );
+ $orders_to_display[] = $order;
+ }
+
+ // Display the subscriptions which had item/s switched to this subscription by its parent order.
+ if ( ! empty( $post->post_parent ) ) {
+ $switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->post_parent );
+ }
+
+ // On the Edit Order screen, show any subscriptions with items switched by this order.
+ } else {
+ $switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->ID );
+ }
+
+ foreach ( $switched_subscriptions as $subscription ) {
+ $subscription->update_meta_data( '_relationship', __( 'Switched Subscription', 'woocommerce-subscriptions' ) );
+ $orders_to_display[] = $subscription;
+ }
+
+ return $orders_to_display;
+ }
+
/** Deprecated Methods **/
/**
@@ -2535,6 +2543,22 @@ class WC_Subscriptions_Switcher {
return $cart_contains_subscription_creating_switch;
}
+ /**
+ * Filters the add to cart text for products during a switch request.
+ *
+ * @since 3.1.0
+ *
+ * @param string $add_to_cart_text The product's default add to cart text.
+ * @return string 'Switch subscription' during a switch, or the default add to cart text if switch args aren't present.
+ */
+ public static function display_switch_add_to_cart_text( $add_to_cart_text ) {
+ if ( isset( $_GET['switch-subscription'], $_GET['item'] ) ) {
+ $add_to_cart_text = _x( 'Switch subscription', 'add to cart button text while switching a subscription', 'woocommerce-subscriptions' );
+ }
+
+ return $add_to_cart_text;
+ }
+
/**
* Don't allow switched subscriptions to be cancelled.
*
@@ -2827,4 +2851,51 @@ class WC_Subscriptions_Switcher {
return $related_orders;
}
+
+ /**
+ * If the subscription purchased in an order has since been switched, include a link to the order placed to switch the subscription
+ * in the "Related Orders" meta box (displayed on the Edit Order screen).
+ *
+ * @param WC_Order $order The current order.
+ * @since 1.4
+ * @deprecated 3.1.0
+ */
+ public static function switch_order_meta_box_rows( $post ) {
+ wcs_deprecated_function( __METHOD__, '3.1.0' );
+ $subscriptions = array();
+ $switched_subscriptions = array();
+ $orders = array();
+
+ // On the subscription page, just show related orders
+ if ( wcs_is_subscription( $post->ID ) ) {
+
+ // Select the orders which switched item/s from this subscription
+ $orders = wcs_get_switch_orders_for_subscription( $post->ID );
+
+ foreach ( $orders as $order_id => $order ) {
+ wcs_set_objects_property( $order, 'relationship', __( 'Switch Order', 'woocommerce-subscriptions' ), 'set_prop_only' );
+ }
+
+ // Select the subscriptions which had item/s switched to this subscription by its parent order
+ if ( ! empty( $post->post_parent ) ) {
+ $switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->post_parent );
+ }
+
+ // On the Edit Order screen, show any subscriptions with items switched by this order
+ } else {
+ $switched_subscriptions = wcs_get_subscriptions_for_switch_order( $post->ID );
+ }
+
+ if ( is_array( $switched_subscriptions ) ) {
+ foreach ( $switched_subscriptions as $subscription_id => $subscription ) {
+ wcs_set_objects_property( $subscription, 'relationship', __( 'Switched Subscription', 'woocommerce-subscriptions' ), 'set_prop_only' );
+ $orders[ $subscription_id ] = $subscription;
+ }
+ }
+
+ foreach ( $orders as $order ) {
+ include( WC_Subscriptions_Core_Plugin::instance()->get_subscriptions_core_directory( 'includes/admin/meta-boxes/views/html-related-orders-row.php' ) );
+ }
+
+ }
}
diff --git a/includes/class-wcs-add-cart-item.php b/includes/switching/class-wcs-add-cart-item.php
similarity index 84%
rename from includes/class-wcs-add-cart-item.php
rename to includes/switching/class-wcs-add-cart-item.php
index cb6685f..38ac8c0 100644
--- a/includes/class-wcs-add-cart-item.php
+++ b/includes/switching/class-wcs-add-cart-item.php
@@ -57,6 +57,17 @@ class WCS_Add_Cart_Item extends WCS_Switch_Cart_Item {
return 0;
}
+ /**
+ * Determines if the last order was a switch and the outcome of that was a fully reduced pre-paid term.
+ * Since the last order didn't contain this item, we can safely return false here.
+ *
+ * @since 3.0.7
+ * @return bool Whether the last order was a switch and it fully reduced the prepaid term.
+ */
+ protected function is_switch_after_fully_reduced_prepaid_term() {
+ return false;
+ }
+
/** Helper functions */
/**
diff --git a/includes/class-wcs-cart-switch.php b/includes/switching/class-wcs-cart-switch.php
similarity index 82%
rename from includes/class-wcs-cart-switch.php
rename to includes/switching/class-wcs-cart-switch.php
index 2c01292..07ddebc 100644
--- a/includes/class-wcs-cart-switch.php
+++ b/includes/switching/class-wcs-cart-switch.php
@@ -25,6 +25,9 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
// Check if a user is requesting to pay for a switch order, needs to happen after $wp->query_vars are set
add_action( 'template_redirect', array( &$this, 'maybe_setup_cart' ), 99 );
+
+ // Filters the Place order button text
+ add_filter( 'woocommerce_order_button_text', array( $this, 'order_button_text' ), 15 );
}
/**
@@ -38,6 +41,7 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
// Remove version dependent callbacks which don't apply to switch carts
remove_filter( 'woocommerce_checkout_update_customer_data', array( &$this, 'maybe_update_subscription_customer_data' ), 10 );
remove_filter( 'woocommerce_checkout_update_user_meta', array( &$this, 'maybe_update_subscription_address_data' ), 10 );
+ remove_filter( 'woocommerce_store_api_checkout_update_customer_from_request', array( &$this, 'maybe_update_subscription_address_data_from_store_api' ), 10, 2 );
}
/**
@@ -101,7 +105,7 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
// Backwards compatibility (2.1 -> 2.1.2)
$subscription_item_id_key = ( isset( $switch_data['switches'][ $item_id ]['subscription_item_id'] ) ) ? 'subscription_item_id' : 'remove_line_item';
- $_GET['item'] = $switch_data['switches'][ $item_id ][ $subscription_item_id_key ];
+ $_GET['item'] = $switch_data['switches'][ $item_id ][ $subscription_item_id_key ];
break;
}
}
@@ -121,7 +125,7 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
$meta_value = is_array( $meta_value ) ? $meta_value[0] : $meta_value; // In WC 3.0 the meta values are no longer arrays
if ( taxonomy_is_product_attribute( $meta_key ) || meta_is_product_attribute( $meta_key, $meta_value, $product_id ) ) {
- $variations[ $meta_key ] = $meta_value;
+ $variations[ $meta_key ] = $meta_value;
$_POST[ 'attribute_' . $meta_key ] = $meta_value;
}
}
@@ -134,9 +138,7 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
}
}
- WC()->session->set( 'order_awaiting_payment', $order_id );
- $this->set_cart_hash( $order_id );
-
+ $this->set_order_awaiting_payment( $order_id );
wp_safe_redirect( wc_get_checkout_url() );
exit;
}
@@ -162,4 +164,22 @@ class WCS_Cart_Switch extends WCS_Cart_Renewal {
}
}
}
+
+ /**
+ * Overrides the place order button text on the checkout when the cart contains only switch requests.
+ *
+ * @since 3.1.0
+ *
+ * @param string $place_order_text The place order button text.
+ * @return string The place order button text. 'Switch subscription' if the cart contains only switches, otherwise the default.
+ */
+ public function order_button_text( $place_order_text ) {
+ $cart_switches = WC_Subscriptions_Switcher::cart_contains_switches();
+
+ if ( isset( WC()->cart ) && $cart_switches && count( $cart_switches ) === count( WC()->cart->get_cart() ) ) {
+ $place_order_text = _x( 'Switch subscription', 'The place order button text while switching a subscription', 'woocommerce-subscriptions' );
+ }
+
+ return $place_order_text;
+ }
}
diff --git a/includes/class-wcs-switch-cart-item.php b/includes/switching/class-wcs-switch-cart-item.php
similarity index 75%
rename from includes/class-wcs-switch-cart-item.php
rename to includes/switching/class-wcs-switch-cart-item.php
index 599687f..471a1ce 100644
--- a/includes/class-wcs-switch-cart-item.php
+++ b/includes/switching/class-wcs-switch-cart-item.php
@@ -255,8 +255,14 @@ class WCS_Switch_Cart_Item {
* @return float
*/
public function get_total_paid_for_current_period() {
+
if ( ! isset( $this->total_paid_for_current_period ) ) {
- $this->total_paid_for_current_period = WC_Subscriptions_Switcher::calculate_total_paid_since_last_order( $this->subscription, $this->existing_item, 'exclude_sign_up_fees' );
+ // If the last order was a switch with a fully reduced pre-paid term, the amount the cutomer has paid is just the total in that order.
+ if ( $this->is_switch_after_fully_reduced_prepaid_term() ) {
+ $this->total_paid_for_current_period = WC_Subscriptions_Switcher::calculate_total_paid_since_last_order( $this->subscription, $this->existing_item, 'exclude_sign_up_fees', array( $this->get_last_switch_order() ) );
+ } else {
+ $this->total_paid_for_current_period = WC_Subscriptions_Switcher::calculate_total_paid_since_last_order( $this->subscription, $this->existing_item, 'exclude_sign_up_fees' );
+ }
}
return $this->total_paid_for_current_period;
@@ -334,9 +340,16 @@ class WCS_Switch_Cart_Item {
$method_to_use = 'days_in_billing_cycle';
}
+ // If the last order was a switch order with a fully reduced pre-paid term.
+ if ( $this->is_switch_after_fully_reduced_prepaid_term() ) {
+ $method_to_use = 'days_between_switch_and_next_payment';
+ }
+
// Find the number of days between the last payment and the next
if ( 'days_between_payments' === $method_to_use ) {
$days_in_old_cycle = round( ( $this->next_payment_timestamp - $this->get_last_order_paid_time() ) / DAY_IN_SECONDS );
+ } elseif ( 'days_between_switch_and_next_payment' === $method_to_use ) {
+ $days_in_old_cycle = round( ( $this->next_payment_timestamp - $this->get_last_switch_order()->get_date_paid()->getTimestamp() ) / DAY_IN_SECONDS );
} else {
$days_in_old_cycle = wcs_get_days_in_cycle( $this->subscription->get_billing_period(), $this->subscription->get_billing_interval() );
}
@@ -351,7 +364,12 @@ class WCS_Switch_Cart_Item {
* @return int
*/
public function calculate_days_in_new_cycle() {
- $last_order_time = $this->get_last_order_paid_time();
+ if ( $this->is_switch_after_fully_reduced_prepaid_term() ) {
+ $last_order_time = $this->get_last_switch_order()->get_date_paid()->getTimestamp();
+ } else {
+ $last_order_time = $this->get_last_order_paid_time();
+ }
+
$new_billing_period = WC_Subscriptions_Product::get_period( $this->product );
$new_billing_interval = WC_Subscriptions_Product::get_interval( $this->product );
@@ -411,4 +429,79 @@ class WCS_Switch_Cart_Item {
public function is_switch_during_trial() {
return $this->subscription->get_time( 'trial_end' ) > gmdate( 'U' );
}
+
+ /**
+ * Retrieves the subscription's last switch order.
+ *
+ * @since 3.0.7
+ * @return WC_Order|Null The last switch order or null if one doesn't exist.
+ */
+ protected function get_last_switch_order() {
+ static $switch_order = null;
+
+ if ( ! $switch_order ) {
+ $switch_order = $this->subscription->get_last_order( 'all', 'switch' );
+ }
+
+ return $switch_order;
+ }
+
+ /**
+ * Determines if the last order was a switch and the outcome of that was a fully reduced pre-paid term.
+ *
+ * A fully reduced pre-paid term occurs when the amount the customer has paid (in total including switches) doesn't cover the amount of time that has elapsed already at the new price per day.
+ *
+ * For example:
+ * - Original purchase of a $70 / week subscription.
+ * - 5 days into the subscription the customer switches to a $120 / 3 days. The lower freqency triggers the pre-paid term to be reduced.
+ * - The $70 paid at $40 a day only entitles the customer to 1.75 days.
+ * - Because they are already 5 days into the subscription, that $70 is fully absorbed at the new price and no time is 'owed'.
+ * - The subscription starts today and the customer pays full price.
+ *
+ * @see https://docs.woocommerce.com/document/subscriptions/switching-guide/#section-11
+ * @see WCS_Switch_Totals_Calculator::reduce_prepaid_term()
+ *
+ * @since 3.0.7
+ * @return bool Whether the last order was a switch and it fully reduced the prepaid term.
+ */
+ protected function is_switch_after_fully_reduced_prepaid_term() {
+
+ if ( ! isset( $this->is_switch_after_fully_reduced_prepaid_term ) ) {
+ $last_switch_order = $this->get_last_switch_order();
+
+ if ( empty( $last_switch_order ) || ! $last_switch_order->get_date_paid() ) {
+ $this->is_switch_after_fully_reduced_prepaid_term = false;
+ return false;
+ }
+
+ $switch_paid_date = $last_switch_order->get_date_paid();
+
+ // If the last switch order occured after the last payment order (parent or renewal)
+ if ( $switch_paid_date->getTimestamp() < $this->get_last_order_paid_time() ) {
+ $this->is_switch_after_fully_reduced_prepaid_term = false;
+ return false;
+ }
+
+ /**
+ * If the last switch resulted in the customer being charged the pull cost upfront, the customer must have been entitled to fewer days than had already elapsed - see reduce_prepaid_term().
+ * This means the subscription billing term would have started from that switch order's date, not the last order (parent/renewal) date.
+ */
+ $first_payment_after_switch = WC_Subscriptions_Product::get_first_renewal_payment_time( $this->existing_item->get_product(), gmdate( 'Y-m-d H:i:s', $switch_paid_date->format( 'U' ) ) );
+
+ // If the first payment date after the last switch is roughly equal (+- 1 hour) to the next payment date, then it was a fully reduced pre-paid term switch.
+ $this->is_switch_after_fully_reduced_prepaid_term = ( $this->next_payment_timestamp - HOUR_IN_SECONDS <= $first_payment_after_switch ) && ( $first_payment_after_switch <= $this->next_payment_timestamp + HOUR_IN_SECONDS );
+ }
+
+ return $this->is_switch_after_fully_reduced_prepaid_term;
+ }
+
+ /**
+ * Determines whether the customer is switching to a subscription with a length of 1 - one off payment.
+ *
+ * @since 3.0.12
+ * @return bool
+ */
+ public function is_switch_to_one_payment_subscription() {
+ return 1 === absint( WC_Subscriptions_Product::get_length( $this->product ) );
+ }
}
diff --git a/includes/class-wcs-switch-totals-calculator.php b/includes/switching/class-wcs-switch-totals-calculator.php
old mode 100644
new mode 100755
similarity index 88%
rename from includes/class-wcs-switch-totals-calculator.php
rename to includes/switching/class-wcs-switch-totals-calculator.php
index 36eee1b..dd948b7
--- a/includes/class-wcs-switch-totals-calculator.php
+++ b/includes/switching/class-wcs-switch-totals-calculator.php
@@ -97,7 +97,9 @@ class WCS_Switch_Totals_Calculator {
$this->set_switch_type_in_cart( $cart_item_key, $switch_type );
if ( $this->should_prorate_recurring_price( $switch_item ) ) {
- if ( 'upgrade' === $switch_type ) {
+
+ // Switching to a product with only 1 payment means no next payment can be collected and so we calculate a gap payment in that scenario.
+ if ( 'upgrade' === $switch_type || $switch_item->is_switch_to_one_payment_subscription() ) {
if ( $this->should_reduce_prepaid_term( $switch_item ) ) {
$this->reduce_prepaid_term( $cart_item_key, $switch_item );
} else {
@@ -107,7 +109,9 @@ class WCS_Switch_Totals_Calculator {
$upgrade_cost = $this->calculate_upgrade_cost( $switch_item );
$this->set_upgrade_cost( $switch_item, $upgrade_cost );
}
- } elseif ( 'downgrade' === $switch_type && $this->should_extend_prepaid_term() ) {
+ }
+
+ if ( apply_filters( 'wcs_switch_should_extend_prepaid_term', 'downgrade' === $switch_type && $this->should_extend_prepaid_term(), $switch_item ) ) {
$this->extend_prepaid_term( $cart_item_key, $switch_item );
}
@@ -121,6 +125,8 @@ class WCS_Switch_Totals_Calculator {
$this->apportion_length( $switch_item );
}
+ do_action( 'wcs_switch_calculations_completed', $switch_item, $cart_item_key );
+
if ( defined( 'WCS_DEBUG' ) && WCS_DEBUG && ! wcs_doing_ajax() ) {
$this->log_switch( $switch_item );
}
@@ -210,7 +216,7 @@ class WCS_Switch_Totals_Calculator {
$prorate_all = in_array( $this->apportion_recurring_price, array( 'yes', 'yes-upgrade' ) );
$prorate_virtual = in_array( $this->apportion_recurring_price, array( 'virtual', 'virtual-upgrade' ) );
- return $prorate_all || ( $prorate_virtual && $switch_item->is_virtual_product() );
+ return apply_filters( 'wcs_switch_should_prorate_recurring_price', $prorate_all || ( $prorate_virtual && $switch_item->is_virtual_product() ), $switch_item );
}
/**
@@ -265,7 +271,8 @@ class WCS_Switch_Totals_Calculator {
* @return bool
*/
protected function should_apportion_length( $switch_item ) {
- return 'yes' == $this->apportion_length || ( 'virtual' == $this->apportion_length && $switch_item->is_virtual_product() );
+
+ return apply_filters( 'wcs_switch_should_prorate_length', 'yes' == $this->apportion_length || ( 'virtual' == $this->apportion_length && $switch_item->is_virtual_product() ), $switch_item );
}
/** Total Calculators */
@@ -279,9 +286,9 @@ class WCS_Switch_Totals_Calculator {
* @param WCS_Switch_Cart_Item $switch_item
*/
protected function apportion_sign_up_fees( $switch_item ) {
- if ( 'no' === $this->apportion_sign_up_fee ) {
- $switch_item->product->update_meta_data( '_subscription_sign_up_fee', 0 );
- } elseif ( $switch_item->existing_item && 'yes' === $this->apportion_sign_up_fee ) {
+ $should_apportion_sign_up_fee = apply_filters( 'wcs_switch_should_prorate_sign_up_fee', 'yes' === $this->apportion_sign_up_fee, $switch_item );
+
+ if ( $should_apportion_sign_up_fee && $switch_item->existing_item ) {
$product = wc_get_product( $switch_item->canonical_product_id );
// Make sure we get a fresh copy of the product's meta to avoid prorating an already prorated sign-up fee
@@ -296,8 +303,16 @@ class WCS_Switch_Totals_Calculator {
$sign_up_fee_paid = ( $sign_up_fee_paid * $switch_item->existing_item['qty'] ) / $switch_item->cart_item['quantity'];
}
- $switch_item->product->update_meta_data( '_subscription_sign_up_fee', max( $sign_up_fee_due - $sign_up_fee_paid, 0 ) );
+ // Allowing third parties to customize the applied sign-up fee
+ $subscription_sign_up_fee = apply_filters( 'wcs_switch_sign_up_fee', max( $sign_up_fee_due - $sign_up_fee_paid, 0 ), $switch_item );
+
+ $switch_item->product->update_meta_data( '_subscription_sign_up_fee', $subscription_sign_up_fee );
$switch_item->product->update_meta_data( '_subscription_sign_up_fee_prorated', WC_Subscriptions_Product::get_sign_up_fee( $switch_item->product ) );
+ } elseif ( 'no' === $this->apportion_sign_up_fee ) {
+ // Allowing third parties to force the application of a sign-up fee
+ $subscription_sign_up_fee = apply_filters( 'wcs_switch_sign_up_fee', 0, $switch_item );
+
+ $switch_item->product->update_meta_data( '_subscription_sign_up_fee', $subscription_sign_up_fee );
}
}
@@ -379,7 +394,12 @@ class WCS_Switch_Totals_Calculator {
// Find how many more days at the new lower price it takes to exceed the amount owed
$days_to_add = $this->calculate_pre_paid_days( $amount_still_owing, $switch_item->get_new_price_per_day() );
- $days_to_add -= $switch_item->get_days_until_next_payment();
+ // Subtract days until next payments only if days to add is not zero
+ if ( 0 !== $days_to_add ) {
+ $days_to_add -= $switch_item->get_days_until_next_payment();
+ }
+
+ $days_to_add = apply_filters( 'wcs_switch_days_to_extend_prepaid_term', $days_to_add, $cart_item_key, $switch_item );
$this->cart->cart_contents[ $cart_item_key ]['subscription_switch']['first_payment_timestamp'] = $switch_item->next_payment_timestamp + ( $days_to_add * DAY_IN_SECONDS );
}
@@ -391,7 +411,17 @@ class WCS_Switch_Totals_Calculator {
* @param WCS_Switch_Cart_Item $switch_item
*/
protected function apportion_length( $switch_item ) {
- $base_length = WC_Subscriptions_Product::get_length( $switch_item->canonical_product_id );
+ $base_length = wcs_get_objects_property( $switch_item->product, 'subscription_base_length_prorated' );
+
+ // Already modified the subscription length of this instance previously?
+ if ( is_null( $base_length ) ) {
+ // Get the length from the unmodified product instance, and save it for later.
+ // A "lazier" way to do the same would have been to call 'WC_Subscriptions_Product::get_length( $switch_item->canonical_product_id )', but this breaks APFS, and is more expensive performance-wise.
+ // See https://github.com/woocommerce/woocommerce-subscriptions/issues/3928
+ $base_length = WC_Subscriptions_Product::get_length( $switch_item->product );
+ wcs_set_objects_property( $switch_item->product, 'subscription_base_length_prorated', $base_length, 'set_prop_only' );
+ }
+
$completed_payments = $switch_item->subscription->get_payment_count();
$length_remaining = $base_length - $completed_payments;
@@ -400,6 +430,8 @@ class WCS_Switch_Totals_Calculator {
$length_remaining = $base_length;
}
+ $length_remaining = apply_filters( 'wcs_switch_length_remaining', $length_remaining, $switch_item );
+
$switch_item->product->update_meta_data( '_subscription_length', $length_remaining );
}
diff --git a/languages/woocommerce-subscriptions-fr.mo b/languages/woocommerce-subscriptions-fr.mo
new file mode 100644
index 0000000000000000000000000000000000000000..d7c119a05c33e1b823764ba92722047fa03e5be9
GIT binary patch
literal 190575
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 T+qUd109o$^$gWLebO(#
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
z
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