| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Give\Donations; |
| 4 | 4 | |
| 5 | +use Give\Donations\Actions\LoadDonationAdminOptions; | |
| 6 | +use Give\Donations\CustomFields\Controllers\DonationDetailsController; | |
| 5 | 7 | use Give\Donations\LegacyListeners\ClearDonationPostCache; |
| 6 | 8 | use Give\Donations\LegacyListeners\DispatchDonationNoteEmailNotification; |
| 7 | 9 | use Give\Donations\LegacyListeners\DispatchGiveInsertPayment; |
| 8 | 10 | use Give\Donations\LegacyListeners\DispatchGivePreInsertPayment; |
| @@ -10,12 +12,18 @@ | ||
| 10 | 12 | use Give\Donations\LegacyListeners\DispatchGiveUpdatePaymentStatus; |
| 11 | 13 | use Give\Donations\LegacyListeners\InsertSequentialId; |
| 12 | 14 | use Give\Donations\LegacyListeners\RemoveSequentialId; |
| 13 | 15 | use Give\Donations\LegacyListeners\UpdateDonorPaymentIds; |
| 16 | +use Give\Donations\LegacyListeners\UpdateDonationMetaWithLegacyFormCurrencySettings; | |
| 17 | +use Give\Donations\Listeners\DonationCreated\UpdateDonationMetaWithCurrencySettings; | |
| 18 | +use Give\Donations\Listeners\DonationCreated\UpdateDonorMetaWithLastDonatedCurrency; | |
| 14 | 19 | use Give\Donations\ListTable\DonationsListTable; |
| 15 | 20 | use Give\Donations\Migrations\AddMissingDonorIdToDonationComments; |
| 16 | 21 | use Give\Donations\Migrations\MoveDonationCommentToDonationMetaTable; |
| 22 | +use Give\Donations\Migrations\RecalculateExchangeRate; | |
| 23 | +use Give\Donations\Migrations\SanitizeSerializedObjectPayloads; | |
| 17 | 24 | use Give\Donations\Migrations\SetAutomaticFormattingOption; |
| 25 | +use Give\Donations\Migrations\UnserializeTitlePrefix; | |
| 18 | 26 | use Give\Donations\Models\Donation; |
| 19 | 27 | use Give\Donations\Repositories\DonationNotesRepository; |
| 20 | 28 | use Give\Donations\Repositories\DonationRepository; |
| 21 | 29 | use Give\Framework\Migrations\MigrationsRegister; |
| @@ -43,15 +51,21 @@ | ||
| 43 | 51 | * @inheritDoc |
| 44 | 52 | */ |
| 45 | 53 | public function boot() |
| 46 | 54 | { |
| 55 | + $this->bootListeners(); | |
| 47 | 56 | $this->bootLegacyListeners(); |
| 48 | 57 | $this->registerDonationsAdminPage(); |
| 58 | + $this->addCustomFieldsToDonationDetails(); | |
| 59 | + $this->loadDonationAdminOptions(); | |
| 49 | 60 | |
| 50 | 61 | give(MigrationsRegister::class)->addMigrations([ |
| 51 | 62 | AddMissingDonorIdToDonationComments::class, |
| 52 | 63 | SetAutomaticFormattingOption::class, |
| 53 | 64 | MoveDonationCommentToDonationMetaTable::class, |
| 65 | + UnserializeTitlePrefix::class, | |
| 66 | + RecalculateExchangeRate::class, | |
| 67 | + SanitizeSerializedObjectPayloads::class, | |
| 54 | 68 | ]); |
| 55 | 69 | } |
| 56 | 70 | |
| 57 | 71 | /** |
| @@ -64,8 +78,9 @@ | ||
| 64 | 78 | { |
| 65 | 79 | Hooks::addAction('givewp_donation_creating', DispatchGivePreInsertPayment::class); |
| 66 | 80 | |
| 67 | 81 | add_action('givewp_donation_created', static function (Donation $donation) { |
| 82 | + (new UpdateDonationMetaWithLegacyFormCurrencySettings())($donation); | |
| 68 | 83 | (new InsertSequentialId())($donation); |
| 69 | 84 | (new DispatchGiveInsertPayment())($donation); |
| 70 | 85 | (new UpdateDonorPaymentIds())($donation); |
| 71 | 86 | |
| @@ -99,20 +114,55 @@ | ||
| 99 | 114 | |
| 100 | 115 | /** |
| 101 | 116 | * Donations Admin page |
| 102 | 117 | * |
| 118 | + * @since 4.14.0 defer conditionals and DB queries to admin_menu hook. | |
| 103 | 119 | * @since 2.20.0 |
| 104 | 120 | */ |
| 105 | 121 | private function registerDonationsAdminPage() |
| 106 | 122 | { |
| 107 | - $userId = get_current_user_id(); | |
| 108 | - $showLegacy = get_user_meta($userId, '_give_donations_archive_show_legacy', true); | |
| 109 | - // only register new admin page if user hasn't chosen to use the old one | |
| 110 | - if (empty($showLegacy)) { | |
| 111 | - Hooks::addAction('admin_menu', DonationsAdminPage::class, 'registerMenuItem', 20); | |
| 123 | + add_action('admin_menu', function () { | |
| 124 | + $userId = get_current_user_id(); | |
| 125 | + $showLegacy = get_user_meta($userId, '_give_donations_archive_show_legacy', true); | |
| 112 | 126 | |
| 113 | - if (DonationsAdminPage::isShowing()) { | |
| 114 | - Hooks::addAction('admin_enqueue_scripts', DonationsAdminPage::class, 'loadScripts'); | |
| 127 | + // only register new admin page if user hasn't chosen to use the old one | |
| 128 | + if (empty($showLegacy)) { | |
| 129 | + give(DonationsAdminPage::class)->registerMenuItem(); | |
| 115 | 130 | } |
| 116 | - } | |
| 131 | + }, 20); | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * @since 3.0.0 | |
| 136 | + */ | |
| 137 | + private function addCustomFieldsToDonationDetails() | |
| 138 | + { | |
| 139 | + add_action('give_view_donation_details_billing_after', static function ($donationId) { | |
| 140 | + echo (new DonationDetailsController())->show($donationId); | |
| 141 | + }); | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * @since 4.2.0 | |
| 146 | + */ | |
| 147 | + private function bootListeners() | |
| 148 | + { | |
| 149 | + add_action('givewp_donation_created', static function (Donation $donation) { | |
| 150 | + (new UpdateDonationMetaWithCurrencySettings())($donation); | |
| 151 | + | |
| 152 | + (new UpdateDonorMetaWithLastDonatedCurrency())($donation); | |
| 153 | + }); | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 157 | + * @since 4.6.1 Move to admin_enqueue_scripts hook | |
| 158 | + * @since 4.6.0 | |
| 159 | + */ | |
| 160 | + private function loadDonationAdminOptions() | |
| 161 | + { | |
| 162 | + add_action('admin_enqueue_scripts', function () { | |
| 163 | + if (DonationsAdminPage::isShowingDetailsPage()) { | |
| 164 | + give(LoadDonationAdminOptions::class)(); | |
| 165 | + } | |
| 166 | + }); | |
| 117 | 167 | } |
| 118 | 168 | } |