Exceptions
1 week ago
GlobalStyles.php
3 years ago
LegacyServiceProvider.php
1 week ago
Onboarding.php
3 years ago
PaymentGateways.php
1 year ago
RequestType.php
3 years ago
RestAPI.php
8 months ago
Routes.php
4 years ago
ServiceProvider.php
4 years ago
Onboarding.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\ServiceProviders; |
| 4 | |
| 5 | use Give\Framework\Migrations\MigrationsRegister; |
| 6 | use Give\Helpers\Hooks; |
| 7 | use Give\Onboarding\DefaultFormFactory; |
| 8 | use Give\Onboarding\FormRepository; |
| 9 | use Give\Onboarding\LocaleCollection; |
| 10 | use Give\Onboarding\Migrations\SetFormDonationLevelsToStrings; |
| 11 | use Give\Onboarding\Routes\AddonsRoute; |
| 12 | use Give\Onboarding\Routes\CurrencyRoute; |
| 13 | use Give\Onboarding\Routes\FeaturesRoute; |
| 14 | use Give\Onboarding\Routes\FormRoute; |
| 15 | use Give\Onboarding\Routes\LocationRoute; |
| 16 | use Give\Onboarding\Routes\SettingsRoute; |
| 17 | use Give\Onboarding\SettingsRepositoryFactory; |
| 18 | use Give\Onboarding\Setup\Handlers\AdminNoticeHandler; |
| 19 | use Give\Onboarding\Setup\Handlers\TopLevelMenuRedirect; |
| 20 | use Give\Onboarding\Setup\Page as SetupPage; |
| 21 | use Give\Onboarding\Setup\PageView as SetupPageView; |
| 22 | use Give\Onboarding\Wizard\FormPreview; |
| 23 | use Give\Onboarding\Wizard\Page as WizardPage; |
| 24 | |
| 25 | class Onboarding implements ServiceProvider |
| 26 | { |
| 27 | |
| 28 | /** |
| 29 | * @inheritDoc |
| 30 | */ |
| 31 | public function register() |
| 32 | { |
| 33 | // Onboarding Wizard and Setup page require WP v5.0.x or greater |
| 34 | if (version_compare(get_bloginfo('version'), '5.0', '<=')) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | give()->singleton(SetupPage::class); |
| 39 | give()->singleton(WizardPage::class); |
| 40 | give()->singleton(FormPreview::class); |
| 41 | give()->bind(SettingsRoute::class); |
| 42 | give()->bind(CurrencyRoute::class); |
| 43 | give()->bind(AddonsRoute::class); |
| 44 | give()->bind(FeaturesRoute::class); |
| 45 | give()->bind(FormRoute::class); |
| 46 | give()->bind(FormRepository::class); |
| 47 | give()->bind(DefaultFormFactory::class); |
| 48 | give()->bind(SettingsRepositoryFactory::class); |
| 49 | give()->bind(LocaleCollection::class); |
| 50 | give()->singleton(SetupPageView::class); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * @inheritDoc |
| 55 | */ |
| 56 | public function boot() |
| 57 | { |
| 58 | $this->registerMigrations(); |
| 59 | |
| 60 | // Onboarding Wizard and Setup page require WP v5.0.x or greater |
| 61 | if (version_compare(get_bloginfo('version'), '5.0', '<=')) { |
| 62 | return; |
| 63 | } |
| 64 | |
| 65 | // Load Wizard Page |
| 66 | Hooks::addAction('admin_menu', WizardPage::class, 'add_page'); |
| 67 | Hooks::addAction('admin_init', WizardPage::class, 'redirect'); |
| 68 | Hooks::addAction('admin_init', WizardPage::class, 'setup_wizard'); |
| 69 | Hooks::addAction('admin_enqueue_scripts', WizardPage::class, 'enqueue_scripts'); |
| 70 | |
| 71 | // Load Form Preview |
| 72 | Hooks::addAction('admin_menu', FormPreview::class, 'add_page'); |
| 73 | Hooks::addAction('admin_init', FormPreview::class, 'setup_form_preview'); |
| 74 | |
| 75 | Hooks::addAction('rest_api_init', FormRoute::class, 'registerRoute'); |
| 76 | Hooks::addAction('rest_api_init', LocationRoute::class, 'registerRoute'); |
| 77 | Hooks::addAction( |
| 78 | 'rest_api_init', |
| 79 | AddonsRoute::class, |
| 80 | 'registerRoute', |
| 81 | 10 |
| 82 | ); // Static route, onboarding/settings/addons |
| 83 | Hooks::addAction( |
| 84 | 'rest_api_init', |
| 85 | CurrencyRoute::class, |
| 86 | 'registerRoute', |
| 87 | 10 |
| 88 | ); // Static route, onboarding/settings/currency |
| 89 | Hooks::addAction( |
| 90 | 'rest_api_init', |
| 91 | FeaturesRoute::class, |
| 92 | 'registerRoute', |
| 93 | 10 |
| 94 | ); // Static route, onboarding/settings/features |
| 95 | Hooks::addAction( |
| 96 | 'rest_api_init', |
| 97 | SettingsRoute::class, |
| 98 | 'registerRoute', |
| 99 | 11 |
| 100 | ); // Dynamic route, onboarding/settings/{setting} |
| 101 | |
| 102 | // Maybe load Setup Page |
| 103 | if (give_is_setting_enabled(SetupPage::getSetupPageEnabledOrDisabled())) { |
| 104 | Hooks::addAction('admin_init', AdminNoticeHandler::class, 'maybeHandle'); |
| 105 | Hooks::addAction('admin_init', TopLevelMenuRedirect::class, 'maybeHandle'); |
| 106 | Hooks::addAction('admin_menu', SetupPage::class, 'add_page', 80); |
| 107 | Hooks::addAction('admin_enqueue_scripts', SetupPage::class, 'enqueue_scripts'); |
| 108 | Hooks::addAction('admin_post_dismiss_setup_page', SetupPage::class, 'dismissSetupPage'); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Registers migrations |
| 114 | * |
| 115 | * @since 2.13.3 |
| 116 | */ |
| 117 | private function registerMigrations() |
| 118 | { |
| 119 | give(MigrationsRegister::class)->addMigrations([ |
| 120 | SetFormDonationLevelsToStrings::class, |
| 121 | ]); |
| 122 | } |
| 123 | } |
| 124 |