LegacyServiceProvider.php
5 years ago
Onboarding.php
4 years ago
PaymentGateways.php
4 years ago
RestAPI.php
5 years ago
Routes.php
5 years ago
ServiceProvider.php
5 years ago
Onboarding.php
104 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\ServiceProviders; |
| 4 | |
| 5 | use Give\Framework\Migrations\MigrationsRegister; |
| 6 | use Give\Helpers\Hooks; |
| 7 | use Give\Onboarding\Migrations\SetFormDonationLevelsToStrings; |
| 8 | use Give\Onboarding\SettingsRepository; |
| 9 | use Give\Onboarding\FormRepository; |
| 10 | use Give\Onboarding\DefaultFormFactory; |
| 11 | use Give\Onboarding\LocaleCollection; |
| 12 | use Give\Onboarding\SettingsRepositoryFactory; |
| 13 | use Give\Onboarding\Setup\Page as SetupPage; |
| 14 | use Give\Onboarding\Setup\PageView as SetupPageView; |
| 15 | use Give\Onboarding\Wizard\Page as WizardPage; |
| 16 | use Give\Onboarding\Wizard\FormPreview; |
| 17 | use Give\Onboarding\Routes\SettingsRoute; |
| 18 | use Give\Onboarding\Routes\LocationRoute; |
| 19 | use Give\Onboarding\Routes\CurrencyRoute; |
| 20 | use Give\Onboarding\Routes\AddonsRoute; |
| 21 | use Give\Onboarding\Routes\FeaturesRoute; |
| 22 | use Give\Onboarding\Routes\FormRoute; |
| 23 | use Give\Onboarding\Setup\Handlers\AdminNoticeHandler; |
| 24 | use Give\Onboarding\Setup\Handlers\TopLevelMenuRedirect; |
| 25 | |
| 26 | class Onboarding implements ServiceProvider { |
| 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( DonationsRedirect::class ); |
| 42 | give()->bind( SettingsRoute::class ); |
| 43 | give()->bind( CurrencyRoute::class ); |
| 44 | give()->bind( AddonsRoute::class ); |
| 45 | give()->bind( FeaturesRoute::class ); |
| 46 | give()->bind( FormRoute::class ); |
| 47 | give()->bind( FormRepository::class ); |
| 48 | give()->bind( DefaultFormFactory::class ); |
| 49 | give()->bind( SettingsRepositoryFactory::class ); |
| 50 | give()->bind( LocaleCollection::class ); |
| 51 | give()->singleton( SetupPageView::class ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @inheritDoc |
| 56 | */ |
| 57 | public function boot() { |
| 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( 'rest_api_init', AddonsRoute::class, 'registerRoute', 10 ); // Static route, onboarding/settings/addons |
| 78 | Hooks::addAction( 'rest_api_init', CurrencyRoute::class, 'registerRoute', 10 ); // Static route, onboarding/settings/currency |
| 79 | Hooks::addAction( 'rest_api_init', FeaturesRoute::class, 'registerRoute', 10 ); // Static route, onboarding/settings/features |
| 80 | Hooks::addAction( 'rest_api_init', SettingsRoute::class, 'registerRoute', 11 ); // Dynamic route, onboarding/settings/{setting} |
| 81 | |
| 82 | // Maybe load Setup Page |
| 83 | if ( give_is_setting_enabled( SetupPage::getSetupPageEnabledOrDisabled() ) ) { |
| 84 | Hooks::addAction( 'admin_init', AdminNoticeHandler::class, 'maybeHandle' ); |
| 85 | Hooks::addAction( 'admin_init', TopLevelMenuRedirect::class, 'maybeHandle' ); |
| 86 | Hooks::addAction( 'admin_menu', SetupPage::class, 'add_page' ); |
| 87 | Hooks::addAction( 'admin_enqueue_scripts', SetupPage::class, 'enqueue_scripts' ); |
| 88 | Hooks::addAction( 'admin_post_dismiss_setup_page', SetupPage::class, 'dismissSetupPage' ); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Registers migrations |
| 94 | * |
| 95 | * @since 2.13.3 |
| 96 | */ |
| 97 | private function registerMigrations() |
| 98 | { |
| 99 | give(MigrationsRegister::class)->addMigrations([ |
| 100 | SetFormDonationLevelsToStrings::class |
| 101 | ]); |
| 102 | } |
| 103 | } |
| 104 |