CustomFields
2 years ago
DataTransferObjects
3 years ago
Endpoints
2 years ago
Exceptions
4 years ago
Factories
3 years ago
ListTable
3 years ago
Models
2 years ago
Repositories
3 years ago
ValueObjects
3 years ago
resources
3 years ago
DonorsAdminPage.php
3 years ago
ServiceProvider.php
2 years ago
ServiceProvider.php
69 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Donors; |
| 4 | |
| 5 | use Give\Donors\CustomFields\Controllers\DonorDetailsController; |
| 6 | use Give\Donors\ListTable\DonorsListTable; |
| 7 | use Give\Donors\Models\Donor; |
| 8 | use Give\Donors\Repositories\DonorRepositoryProxy; |
| 9 | use Give\Helpers\Hooks; |
| 10 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 11 | use Give_Donor as LegacyDonor; |
| 12 | |
| 13 | /** |
| 14 | * @since 2.19.6 |
| 15 | */ |
| 16 | class ServiceProvider implements ServiceProviderInterface |
| 17 | { |
| 18 | |
| 19 | /** |
| 20 | * @inheritDoc |
| 21 | */ |
| 22 | public function register() |
| 23 | { |
| 24 | give()->singleton('donors', DonorRepositoryProxy::class); |
| 25 | give()->singleton(DonorsListTable::class, function() { |
| 26 | $listTable = new DonorsListTable(); |
| 27 | Hooks::doAction('givewp_donors_list_table', $listTable); |
| 28 | |
| 29 | return $listTable; |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @inheritDoc |
| 35 | */ |
| 36 | public function boot() |
| 37 | { |
| 38 | $userId = get_current_user_id(); |
| 39 | $showLegacy = get_user_meta($userId, '_give_donors_archive_show_legacy', true); |
| 40 | // only register new admin page if user hasn't chosen to use the old one |
| 41 | if(empty($showLegacy)) { |
| 42 | Hooks::addAction('admin_menu', DonorsAdminPage::class, 'registerMenuItem', 30); |
| 43 | |
| 44 | if (DonorsAdminPage::isShowing()) { |
| 45 | Hooks::addAction('admin_enqueue_scripts', DonorsAdminPage::class, 'loadScripts'); |
| 46 | } |
| 47 | } |
| 48 | elseif(DonorsAdminPage::isShowing()) |
| 49 | { |
| 50 | Hooks::addAction( 'admin_head', DonorsAdminPage::class, 'renderReactSwitch'); |
| 51 | } |
| 52 | |
| 53 | $this->addCustomFieldsToDonorDetails(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @since 3.0.0 |
| 58 | */ |
| 59 | private function addCustomFieldsToDonorDetails() |
| 60 | { |
| 61 | add_action('give_donor_after_tables', static function (LegacyDonor $legacyDonor) { |
| 62 | /** @var Donor $donor */ |
| 63 | $donor = Donor::find($legacyDonor->id); |
| 64 | |
| 65 | echo (new DonorDetailsController())->show($donor); |
| 66 | }); |
| 67 | } |
| 68 | } |
| 69 |