PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.14.0
GiveWP – Donation Plugin and Fundraising Platform v4.14.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
← All changes | src/Subscriptions/ServiceProvider.php +68 -7 2.31.04.14.0 View file →
@@ -4,13 +4,19 @@
4 4
5 5 use Give\Framework\Migrations\MigrationsRegister;
6 6 use Give\Helpers\Hooks;
7 7 use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
8 +use Give\Subscriptions\Actions\LoadSubscriptionAdminOptions;
8 9 use Give\Subscriptions\LegacyListeners\DispatchGiveSubscriptionPostCreate;
9 10 use Give\Subscriptions\LegacyListeners\DispatchGiveSubscriptionPreCreate;
10 11 use Give\Subscriptions\ListTable\SubscriptionsListTable;
12 +use Give\Subscriptions\Migrations\AddCampaignId;
13 +use Give\Subscriptions\Migrations\AddCampaignIdColumn;
11 14 use Give\Subscriptions\Migrations\AddPaymentModeToSubscriptionTable;
15 +use Give\Subscriptions\Migrations\BackfillMissingCampaignIdForDonations;
12 16 use Give\Subscriptions\Migrations\CreateSubscriptionTables;
17 +use Give\Subscriptions\Migrations\UpdateProductID;
18 +use Give\Subscriptions\Repositories\SubscriptionNotesRepository;
13 19 use Give\Subscriptions\Repositories\SubscriptionRepository;
14 20
15 21 class ServiceProvider implements ServiceProviderInterface
16 22 {
@@ -15,12 +21,15 @@
15 21 class ServiceProvider implements ServiceProviderInterface
16 22 {
17 23 /**
18 24 * @inheritDoc
25 + *
26 + * @since 4.8.0 Register Subscription Repository to container
19 27 */
20 28 public function register()
21 29 {
22 30 give()->singleton('subscriptions', SubscriptionRepository::class);
31 + give()->singleton('subscriptionNotes', SubscriptionNotesRepository::class);
23 32 give()->singleton(SubscriptionsListTable::class, function() {
24 33 $listTable = new SubscriptionsListTable();
25 34 Hooks::doAction('givewp_subscriptions_list_table', $listTable);
26 35
@@ -29,22 +38,57 @@
29 38 }
30 39
31 40 /**
32 41 * @inheritDoc
42 + *
43 + * @since 4.14.0 move subscription page registration to method to defer conditionals and DB queries to appropriate hooks.
33 44 */
34 45 public function boot()
35 46 {
36 47 $this->bootLegacyListeners();
37 48 $this->registerMigrations();
49 + $this->registerSubscriptionAdminOptions();
50 + $this->registerSubscriptionsAdminPage();
51 + }
38 52
53 + /**
54 + * Register the subscriptions admin page, deferring conditionals and DB queries to appropriate hooks.
55 + *
56 + * @since 4.14.0
57 + */
58 + private function registerSubscriptionsAdminPage()
59 + {
60 + // Register new admin page if user hasn't chosen to use the legacy one
61 + add_action('give_forms_page_give-subscriptions', function () {
62 + if ($this->shouldShowLegacySubscriptionsPage()) {
63 + return;
64 + }
65 +
66 + give(SubscriptionsAdminPage::class)->render();
67 + }, 1);
68 +
69 + // Render the "Switch to New View" button on the legacy subscriptions page
70 + add_action('admin_head', function () {
71 + if (!SubscriptionsAdminPage::isShowing()) {
72 + return;
73 + }
74 +
75 + if (!$this->shouldShowLegacySubscriptionsPage()) {
76 + return;
77 + }
78 +
79 + give(SubscriptionsAdminPage::class)->renderReactSwitch();
80 + });
81 + }
82 +
83 + /**
84 + * @since 4.14.0
85 + */
86 + private function shouldShowLegacySubscriptionsPage(): bool
87 + {
39 88 $userId = get_current_user_id();
40 - $showLegacy = get_user_meta($userId, '_give_subscriptions_archive_show_legacy', true);
41 - // only register new admin page if user hasn't chosen to use the old one
42 - if (empty($showLegacy) && SubscriptionsAdminPage::isShowing()) {
43 - Hooks::addAction('admin_enqueue_scripts', SubscriptionsAdminPage::class, 'loadScripts');
44 - } elseif (SubscriptionsAdminPage::isShowing()) {
45 - Hooks::addAction('admin_head', SubscriptionsAdminPage::class, 'renderReactSwitch');
46 - }
89 +
90 + return (bool) get_user_meta($userId, '_give_subscriptions_archive_show_legacy', true);
47 91 }
48 92
49 93 /**
50 94 * Legacy Listeners
@@ -59,8 +103,9 @@
59 103
60 104 /**
61 105 * Registers database migrations with the MigrationsRunner
62 106 *
107 + * @since 4.11.0 add AddCampaignIdColumn and AddCampaignId migrations
63 108 * @since 2.24.0
64 109 */
65 110 private function registerMigrations()
66 111 {
@@ -68,7 +113,23 @@
68 113 $register = give(MigrationsRegister::class);
69 114 $register->addMigrations([
70 115 CreateSubscriptionTables::class,
71 116 AddPaymentModeToSubscriptionTable::class,
117 + BackfillMissingCampaignIdForDonations::class,
118 + AddCampaignIdColumn::class,
119 + AddCampaignId::class,
120 + UpdateProductID::class
72 121 ]);
122 + }
123 +
124 + /**
125 + * @since 4.8.0
126 + */
127 + private function registerSubscriptionAdminOptions()
128 + {
129 + add_action('admin_enqueue_scripts', function() {
130 + if (SubscriptionsAdminPage::isShowing()) {
131 + give(LoadSubscriptionAdminOptions::class)();
132 + }
133 + });
73 134 }
74 135 }