DataTransferObjects
3 years ago
Endpoints
1 year ago
ListTable
1 year ago
Models
3 years ago
Properties
3 years ago
Repositories
3 years ago
ValueObjects
2 years ago
resources
1 year ago
DonationFormsAdminPage.php
1 year ago
ServiceProvider.php
2 years ago
ServiceProvider.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationForms\V2; |
| 4 | |
| 5 | use Give\DonationForms\V2\ListTable\DonationFormsListTable; |
| 6 | use Give\DonationForms\V2\Repositories\DonationFormsRepository; |
| 7 | use Give\Helpers\Hooks; |
| 8 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 9 | |
| 10 | /** |
| 11 | * @since 2.19.0 |
| 12 | */ |
| 13 | class ServiceProvider implements ServiceProviderInterface |
| 14 | { |
| 15 | /** |
| 16 | * @inheritDoc |
| 17 | */ |
| 18 | public function register() |
| 19 | { |
| 20 | give()->singleton('donationForms', DonationFormsRepository::class); |
| 21 | give()->singleton(DonationFormsListTable::class, function () { |
| 22 | $listTable = new DonationFormsListTable(); |
| 23 | Hooks::doAction('givewp_donation_forms_list_table', $listTable); |
| 24 | |
| 25 | return $listTable; |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @inheritDoc |
| 31 | */ |
| 32 | public function boot() |
| 33 | { |
| 34 | $userId = get_current_user_id(); |
| 35 | $showLegacy = get_user_meta($userId, '_give_donation_forms_archive_show_legacy', true); |
| 36 | // only register new admin page if user hasn't chosen to use the old one |
| 37 | if (empty($showLegacy)) { |
| 38 | Hooks::addAction('admin_menu', DonationFormsAdminPage::class, 'register', 0); |
| 39 | Hooks::addAction('admin_menu', DonationFormsAdminPage::class, 'highlightAllFormsMenuItem'); |
| 40 | |
| 41 | if (DonationFormsAdminPage::isShowing()) { |
| 42 | Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadScripts'); |
| 43 | } |
| 44 | } elseif (DonationFormsAdminPage::isShowingLegacyPage()) { |
| 45 | Hooks::addAction('admin_head', DonationFormsAdminPage::class, 'renderReactSwitch'); |
| 46 | } |
| 47 | |
| 48 | // Onboarding |
| 49 | Hooks::addAction('submitpost_box', DonationFormsAdminPage::class, 'renderMigrationGuideBox'); |
| 50 | Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadMigrationScripts'); |
| 51 | |
| 52 | add_action('wp_ajax_givewp_show_onboarding_banner', static function () { |
| 53 | add_user_meta(get_current_user_id(), 'givewp-show-onboarding-banner', time(), true); |
| 54 | }); |
| 55 | |
| 56 | add_action('wp_ajax_givewp_show_upgraded_tooltip', static function () { |
| 57 | add_user_meta(get_current_user_id(), 'givewp-show-upgraded-tooltip', time(), true); |
| 58 | }); |
| 59 | } |
| 60 | } |
| 61 |