PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.1
GiveWP – Donation Plugin and Fundraising Platform v4.1.1
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
give / src / Subscriptions / ServiceProvider.php

ServiceProvider.php in GiveWP – Donation Plugin and Fundraising Platform 4.1.1, at src/Subscriptions/ServiceProvider.php

75 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Subscriptions;
4
5 use Give\Framework\Migrations\MigrationsRegister;
6 use Give\Helpers\Hooks;
7 use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
8 use Give\Subscriptions\LegacyListeners\DispatchGiveSubscriptionPostCreate;
9 use Give\Subscriptions\LegacyListeners\DispatchGiveSubscriptionPreCreate;
10 use Give\Subscriptions\ListTable\SubscriptionsListTable;
11 use Give\Subscriptions\Migrations\AddPaymentModeToSubscriptionTable;
12 use Give\Subscriptions\Migrations\CreateSubscriptionTables;
13 use Give\Subscriptions\Repositories\SubscriptionRepository;
14
15 class ServiceProvider implements ServiceProviderInterface
16 {
17 /**
18 * @inheritDoc
19 */
20 public function register()
21 {
22 give()->singleton('subscriptions', SubscriptionRepository::class);
23 give()->singleton(SubscriptionsListTable::class, function() {
24 $listTable = new SubscriptionsListTable();
25 Hooks::doAction('givewp_subscriptions_list_table', $listTable);
26
27 return $listTable;
28 });
29 }
30
31 /**
32 * @inheritDoc
33 */
34 public function boot()
35 {
36 $this->bootLegacyListeners();
37 $this->registerMigrations();
38
39 $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 }
47 }
48
49 /**
50 * Legacy Listeners
51 *
52 * @since 2.19.6
53 */
54 private function bootLegacyListeners()
55 {
56 Hooks::addAction('givewp_subscription_creating', DispatchGiveSubscriptionPreCreate::class);
57 Hooks::addAction('givewp_subscription_created', DispatchGiveSubscriptionPostCreate::class);
58 }
59
60 /**
61 * Registers database migrations with the MigrationsRunner
62 *
63 * @since 2.24.0
64 */
65 private function registerMigrations()
66 {
67 /** @var MigrationsRegister $register */
68 $register = give(MigrationsRegister::class);
69 $register->addMigrations([
70 CreateSubscriptionTables::class,
71 AddPaymentModeToSubscriptionTable::class,
72 ]);
73 }
74 }
75