PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Donations / Actions / LoadDonationsListTableAssets.php

LoadDonationsListTableAssets.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Donations/Actions/LoadDonationsListTableAssets.php

126 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Donations\Actions;
4
5 use Give\Donations\ListTable\DonationsListTable;
6 use Give\Donations\ValueObjects\DonationStatus;
7 use Give\Framework\Database\DB;
8 use Give\Framework\Support\Facades\Scripts\ScriptAsset;
9 use Give\Helpers\Language;
10 use Give\Helpers\Utils;
11
12 /**
13 * @since 4.6.0
14 */
15 class LoadDonationsListTableAssets
16 {
17 /**
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-donations';
24 $asset = ScriptAsset::get(GIVE_PLUGIN_DIR . 'build/assets/dist/js/give-admin-donations.asset.php');
25
26 wp_register_script(
27 $handleName,
28 GIVE_PLUGIN_URL . 'build/assets/dist/js/give-admin-donations.js',
29 $asset['dependencies'],
30 $asset['version'],
31 true
32 );
33
34 wp_localize_script($handleName, 'GiveDonations', [
35 'apiRoot' => esc_url_raw(rest_url('give-api/v2/admin/donations')),
36 'apiNonce' => wp_create_nonce('wp_rest'),
37 'campaigns' => $this->getCampaigns(),
38 'table' => give(DonationsListTable::class)->toArray(),
39 'adminUrl' => admin_url(),
40 'pluginUrl' => GIVE_PLUGIN_URL,
41 'dismissedRecommendations' => $this->getDismissedRecommendations(),
42 'addonsBulkActions' => [],
43 'paymentMode' => give_is_test_mode(),
44 'manualDonations' => Utils::isPluginActive('give-manual-donations/give-manual-donations.php'),
45 'recurringDonationsEnabled' => Utils::isPluginActive('give-recurring/give-recurring.php'),
46 'donationStatuses' => DonationStatus::labels(),
47 ]);
48
49 wp_enqueue_script($handleName);
50
51 Language::setScriptTranslations($handleName);
52
53 wp_enqueue_style(
54 'give-admin-ui-font',
55 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400..700&display=swap',
56 [],
57 null
58 );
59
60 wp_enqueue_style('givewp-design-system-foundation');
61
62 wp_enqueue_style(
63 $handleName,
64 GIVE_PLUGIN_URL . 'build/assets/dist/js/give-admin-donations.css',
65 [],
66 $asset['version']
67 );
68 }
69
70 /**
71 * Retrieve a list of donation forms to populate the form filter dropdown
72 *
73 * @since 4.0.0 replace formselect with campaigns.
74 * @since 2.20.0
75 * @return array
76 */
77 private function getCampaigns()
78 {
79 $options = DB::table('give_campaigns')
80 ->select(
81 ['id', 'value'],
82 ['campaign_title', 'text']
83 )
84 ->getAll(ARRAY_A);
85
86 return array_merge(
87 [
88 [
89 'value' => '0',
90 'text' => __('Any', 'give'),
91 ]
92 ],
93 $options
94 );
95 }
96
97 /**
98 * Retrieve a list of dismissed recommendations.
99 *
100 * @since 2.27.1
101 */
102 private function getDismissedRecommendations(): array
103 {
104 $dismissedRecommendations = [];
105
106 $recurringAddonIsActive = Utils::isPluginActive('give-recurring/give-recurring.php');
107 $feeRecoveryAddonIsActive = Utils::isPluginActive('give-fee-recovery/give-fee-recovery.php');
108 $designatedFundsAddonIsActive = Utils::isPluginActive('give-funds/give-funds.php');
109
110 $optionNames = [
111 'givewp_donations_recurring_recommendation_dismissed' => $recurringAddonIsActive,
112 'givewp_donations_fee_recovery_recommendation_dismissed' => $feeRecoveryAddonIsActive,
113 'givewp_donations_designated_funds_recommendation_dismissed' => $designatedFundsAddonIsActive,
114 ];
115
116 foreach ($optionNames as $optionName => $isActive) {
117 $dismissed = get_option($optionName, false);
118 if ($dismissed || $isActive) {
119 $dismissedRecommendations[] = $optionName;
120 }
121 }
122
123 return $dismissedRecommendations;
124 }
125 }
126