Actions
1 year ago
BlockModels
2 years ago
BlockTypes
1 year ago
Controllers
1 year ago
DataTransferObjects
2 years ago
EmailPreview
2 years ago
Routes
1 year ago
ValueObjects
2 years ago
ViewModels
1 year ago
resources
1 year ago
FormBuilderRouteBuilder.php
1 year ago
ServiceProvider.php
1 year ago
ServiceProvider.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormBuilder; |
| 4 | |
| 5 | use Give\DonationForms\Models\DonationForm; |
| 6 | use Give\FormBuilder\Actions\ConvertGlobalDefaultOptionsToDefaultBlocks; |
| 7 | use Give\FormBuilder\Actions\DequeueAdminScriptsInFormBuilder; |
| 8 | use Give\FormBuilder\Actions\DequeueAdminStylesInFormBuilder; |
| 9 | use Give\FormBuilder\Actions\UpdateDonorCommentsMeta; |
| 10 | use Give\FormBuilder\Actions\UpdateEmailSettingsMeta; |
| 11 | use Give\FormBuilder\Actions\UpdateEmailTemplateMeta; |
| 12 | use Give\FormBuilder\Actions\UpdateFormExcerpt; |
| 13 | use Give\FormBuilder\Actions\UpdateFormGridMeta; |
| 14 | use Give\FormBuilder\EmailPreview\Routes\RegisterEmailPreviewRoutes; |
| 15 | use Give\FormBuilder\Routes\CreateFormRoute; |
| 16 | use Give\FormBuilder\Routes\EditFormRoute; |
| 17 | use Give\FormBuilder\Routes\RegisterFormBuilderPageRoute; |
| 18 | use Give\FormBuilder\Routes\RegisterFormBuilderRestRoutes; |
| 19 | use Give\FormBuilder\ValueObjects\EditorMode; |
| 20 | use Give\Helpers\Hooks; |
| 21 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 22 | |
| 23 | /** |
| 24 | * @since 3.0.0 |
| 25 | */ |
| 26 | class ServiceProvider implements ServiceProviderInterface |
| 27 | { |
| 28 | /** |
| 29 | * @inheritDoc |
| 30 | */ |
| 31 | public function register() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @inheritDoc |
| 37 | */ |
| 38 | public function boot() |
| 39 | { |
| 40 | Hooks::addAction('rest_api_init', RegisterFormBuilderRestRoutes::class); |
| 41 | |
| 42 | Hooks::addAction('rest_api_init', RegisterEmailPreviewRoutes::class); |
| 43 | |
| 44 | Hooks::addAction('admin_init', CreateFormRoute::class); |
| 45 | |
| 46 | Hooks::addAction('admin_init', EditFormRoute::class); |
| 47 | |
| 48 | Hooks::addAction('admin_menu', RegisterFormBuilderPageRoute::class); |
| 49 | |
| 50 | Hooks::addAction('admin_print_scripts', DequeueAdminScriptsInFormBuilder::class); |
| 51 | |
| 52 | Hooks::addAction('admin_print_styles', DequeueAdminStylesInFormBuilder::class); |
| 53 | |
| 54 | /** Integrates the "Add v3 Form" button with the Donation Forms table. */ |
| 55 | add_action('admin_enqueue_scripts', static function () { |
| 56 | wp_localize_script('give-admin-donation-forms', 'GiveNextGen', [ |
| 57 | 'newFormUrl' => FormBuilderRouteBuilder::makeCreateFormRoute()->getUrl(), |
| 58 | ]); |
| 59 | }); |
| 60 | |
| 61 | add_action('givewp_form_builder_updated', static function (DonationForm $form) { |
| 62 | give(UpdateFormGridMeta::class)->__invoke($form); |
| 63 | give(UpdateEmailSettingsMeta::class)->__invoke($form); |
| 64 | give(UpdateEmailTemplateMeta::class)->__invoke($form); |
| 65 | give(UpdateDonorCommentsMeta::class)->__invoke($form); |
| 66 | }); |
| 67 | |
| 68 | Hooks::addAction('givewp_form_builder_new_form', ConvertGlobalDefaultOptionsToDefaultBlocks::class); |
| 69 | |
| 70 | $this->setupOnboardingTour(); |
| 71 | } |
| 72 | |
| 73 | protected function setupOnboardingTour() |
| 74 | { |
| 75 | add_action('wp_ajax_givewp_tour_completed', static function () { |
| 76 | $mode = new EditorMode($_POST['mode']); |
| 77 | add_user_meta(get_current_user_id(), "givewp-form-builder-$mode-tour-completed", time(), true); |
| 78 | }); |
| 79 | |
| 80 | add_action('wp_ajax_givewp_migration_hide_notice', static function () { |
| 81 | give_update_meta((int)$_GET['formId'], 'givewp-form-builder-migration-hide-notice', time(), true); |
| 82 | }); |
| 83 | |
| 84 | add_action('wp_ajax_givewp_transfer_hide_notice', static function () { |
| 85 | give_update_meta((int)$_GET['formId'], 'givewp-form-builder-transfer-hide-notice', time(), true); |
| 86 | }); |
| 87 | |
| 88 | add_action('wp_ajax_givewp_goal_hide_notice', static function () { |
| 89 | add_user_meta(get_current_user_id(), 'givewp-goal-notice-dismissed', time(), true); |
| 90 | }); |
| 91 | |
| 92 | /** |
| 93 | * @since 3.16.2 |
| 94 | */ |
| 95 | add_action('wp_ajax_givewp_additional_payment_gateways_hide_notice', static function () { |
| 96 | add_user_meta(get_current_user_id(), 'givewp-additional-payment-gateways-notice-dismissed', time(), true); |
| 97 | }); |
| 98 | } |
| 99 | } |
| 100 |