CreateUserFromDonor.php
2 years ago
LoadDonorAdminOptions.php
11 months ago
LoadDonorDetailsAssets.php
1 year ago
LoadDonorsListTableAssets.php
8 months ago
SendDonorUserRegistrationNotification.php
2 years ago
UpdateAdminDonorDetails.php
2 years ago
LoadDonorsListTableAssets.php
112 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Donors\Actions; |
| 4 | |
| 5 | use Give\Donors\ListTable\DonorsListTable; |
| 6 | use Give\Framework\Database\DB; |
| 7 | use Give\Framework\Support\Facades\Scripts\ScriptAsset; |
| 8 | use Give\Helpers\Language; |
| 9 | use Give\Helpers\Utils; |
| 10 | |
| 11 | /** |
| 12 | * @since 4.4.0 |
| 13 | */ |
| 14 | class LoadDonorsListTableAssets |
| 15 | { |
| 16 | /** |
| 17 | * @since 4.11.0 add recurringDonations check to the localize script |
| 18 | * @since 2.27.1 Pass dismissed recommendations to the localize script |
| 19 | * @since 2.20.0 |
| 20 | */ |
| 21 | public function __invoke() |
| 22 | { |
| 23 | $handleName = 'give-admin-donors'; |
| 24 | $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/assets/dist/js/give-admin-donors.asset.php'); |
| 25 | |
| 26 | wp_register_script( |
| 27 | $handleName, |
| 28 | GIVE_PLUGIN_URL . 'build/assets/dist/js/give-admin-donors.js', |
| 29 | $asset['dependencies'], |
| 30 | $asset['version'], |
| 31 | true |
| 32 | ); |
| 33 | |
| 34 | wp_localize_script($handleName, 'GiveDonors', [ |
| 35 | 'apiRoot' => esc_url_raw(rest_url('give-api/v2/admin/donors')), |
| 36 | 'apiNonce' => wp_create_nonce('wp_rest'), |
| 37 | 'forms' => $this->getForms(), |
| 38 | 'table' => give(DonorsListTable::class)->toArray(), |
| 39 | 'adminUrl' => admin_url(), |
| 40 | 'pluginUrl' => GIVE_PLUGIN_URL, |
| 41 | 'dismissedRecommendations' => $this->getDismissedRecommendations(), |
| 42 | 'recurringDonationsEnabled' => Utils::isPluginActive('give-recurring/give-recurring.php'), |
| 43 | ]); |
| 44 | |
| 45 | wp_enqueue_script($handleName); |
| 46 | |
| 47 | Language::setScriptTranslations($handleName); |
| 48 | |
| 49 | wp_enqueue_style( |
| 50 | 'give-admin-ui-font', |
| 51 | 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400..700&display=swap', |
| 52 | [], |
| 53 | null |
| 54 | ); |
| 55 | |
| 56 | wp_enqueue_style('givewp-design-system-foundation'); |
| 57 | |
| 58 | wp_enqueue_style( |
| 59 | $handleName, |
| 60 | GIVE_PLUGIN_URL . 'build/assets/dist/js/give-admin-donors.css', |
| 61 | [], |
| 62 | $asset['version'] |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Preload initial table data |
| 68 | * |
| 69 | * @since 2.20.0 |
| 70 | */ |
| 71 | private function getForms(): array |
| 72 | { |
| 73 | $options = DB::table('posts') |
| 74 | ->select( |
| 75 | ['ID', 'value'], |
| 76 | ['post_title', 'text'] |
| 77 | ) |
| 78 | ->where('post_type', 'give_forms') |
| 79 | ->whereIn('post_status', ['publish', 'draft', 'pending', 'private']) |
| 80 | ->getAll(ARRAY_A); |
| 81 | |
| 82 | return array_merge([ |
| 83 | [ |
| 84 | 'value' => '0', |
| 85 | 'text' => __('Any', 'give'), |
| 86 | ], |
| 87 | ], $options); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Retrieve a list of dismissed recommendations. |
| 92 | * |
| 93 | * @since 2.27.1 |
| 94 | */ |
| 95 | private function getDismissedRecommendations(): array |
| 96 | { |
| 97 | $dismissedRecommendations = []; |
| 98 | |
| 99 | $feeRecoveryAddonIsActive = Utils::isPluginActive('give-fee-recovery/give-fee-recovery.php'); |
| 100 | |
| 101 | $optionName = 'givewp_donors_fee_recovery_recommendation_dismissed'; |
| 102 | |
| 103 | $dismissed = get_option($optionName, false); |
| 104 | |
| 105 | if ($dismissed || $feeRecoveryAddonIsActive) { |
| 106 | $dismissedRecommendations[] = $optionName; |
| 107 | } |
| 108 | |
| 109 | return $dismissedRecommendations; |
| 110 | } |
| 111 | } |
| 112 |