| 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 |
|
| 37 |
Hooks::addAction('admin_menu', DonationFormsAdminPage::class, 'register', 0); |
| 38 |
|
| 39 |
if (empty($showLegacy)) { |
| 40 |
if (DonationFormsAdminPage::isShowing()) { |
| 41 |
Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadScripts'); |
| 42 |
} |
| 43 |
} elseif (DonationFormsAdminPage::isShowingLegacyPage()) { |
| 44 |
Hooks::addAction('admin_head', DonationFormsAdminPage::class, 'renderReactSwitch'); |
| 45 |
} |
| 46 |
|
| 47 |
// Onboarding |
| 48 |
Hooks::addAction('submitpost_box', DonationFormsAdminPage::class, 'renderMigrationGuideBox'); |
| 49 |
Hooks::addAction('admin_enqueue_scripts', DonationFormsAdminPage::class, 'loadMigrationScripts'); |
| 50 |
|
| 51 |
// Dismiss notices |
| 52 |
$noticeActions = [ |
| 53 |
'givewp_show_onboarding_banner' => 'show-onboarding-banner', |
| 54 |
'givewp_show_upgraded_tooltip' => 'show-upgraded-tooltip', |
| 55 |
'givewp_show_default_form_tooltip' => 'show-default-form-tooltip', |
| 56 |
]; |
| 57 |
|
| 58 |
foreach ($noticeActions as $action => $metaKey) { |
| 59 |
add_action("wp_ajax_{$action}", static function () use ($metaKey) { |
| 60 |
add_user_meta(get_current_user_id(), "givewp-{$metaKey}", time(), true); |
| 61 |
}); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|