PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.16.6.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.6.1
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 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / PaymentGateways / PayPalCommerce / Banners / PayPalStandardToDonationsMigrationGlobalBanner.php
give / src / PaymentGateways / PayPalCommerce / Banners Last commit date
GatewaySettingPageBanner.php 2 years ago PayPalDonationsSettingPageBanner.php 2 years ago PayPalStandardToDonationsMigrationGlobalBanner.php 2 years ago
PayPalStandardToDonationsMigrationGlobalBanner.php
172 lines
1 <?php
2
3 namespace Give\PaymentGateways\PayPalCommerce\Banners;
4
5 use Give\PaymentGateways\Gateways\PayPalStandard\PayPalStandard;
6
7 /**
8 * Class PayPalStandardToDonationsMigrationGlobalBanner
9 *
10 * Note: This class uses notice api to disable the banner for the user.
11 *
12 * @since 2.33.0
13 */
14 class PayPalStandardToDonationsMigrationGlobalBanner
15 {
16 /**
17 * @since 2.33.0
18 * @var string
19 */
20 private $bannerId = 'PayPalStandardToDonationsMigrationGlobalBanner';
21
22 /**
23 * @since 2.33.0
24 * @return void
25 */
26 public function setHook()
27 {
28 // Bailout if user is not can not edit GiveWP settings.
29 if (! current_user_can('manage_give_settings')) {
30 return;
31 }
32
33 add_action('admin_enqueue_scripts', function () {
34 $isGivePage = ( isset($_GET['page']) && 'give-forms' === $_GET['page'] )
35 || ( isset($_GET['post_type']) && 'give_forms' === $_GET['post_type'] );
36
37 if ($isGivePage && give_is_gateway_active(PayPalStandard::id())) {
38 add_action('admin_footer', function () {
39 wp_print_inline_script_tag($this->getModalScript());
40 });
41 }
42 });
43 }
44
45 /**
46 * Render the banner.
47 *
48 * @since 2.33.0
49 */
50 public function getModalScript(): string
51 {
52 if ($this->isBannerDisabledForUser()) {
53 return '';
54 }
55
56 $nonce = wp_create_nonce("give_edit_{$this->bannerId}_notice");
57
58 $modalTitle = esc_html__(
59 'PayPal Standard Deprecation',
60 'give'
61 );
62
63 $modalTitle = $this->getIcon() . "&nbsp;&nbsp;$modalTitle";
64
65 $modalSubHeading = esc_html__(
66 'PayPal Standard is no longer supported by PayPal',
67 'give'
68 );
69
70 $modalDescription = esc_html__(
71 'Migrate to PayPal Donations, which fully supports PayPal\'s latest API updates. As PayPal Standard is being deprecated, it will soon be removed from our platform. PayPal Standard will continue to work a while longer, but we strongly recommend migrating to PayPal Donations as soon as you can.',
72 'give'
73 );
74
75 $modalCancelButtonTitle = esc_html__(
76 'Read Documentation',
77 'give'
78 );
79
80 $modalConfirmButtonTitle = esc_html__(
81 'Connect PayPal Donations',
82 'give'
83 );
84
85 $linkToPayPalDonationsSettingPage = esc_url_raw(
86 admin_url(
87 'edit.php?post_type=give_forms&page=give-settings&tab=gateways&section=paypal'
88 )
89 );
90
91 return <<<EOT
92 const givePayPalStandardToDonationsMigrationGlobalBanner = () => {
93 const dismissModalAjaxRequest = async () => {
94 const formData = new FormData();
95 formData.append('give-action', 'dismiss_notices');
96 formData.append('notice_id', '$this->bannerId');
97 formData.append('dismissible_type', 'user');
98 formData.append('dismiss_interval', 'permanent');
99 formData.append('_wpnonce', '$nonce');
100
101 await fetch(ajaxurl, {
102 method: 'POST',
103 body: formData,
104 })
105 };
106
107 new Give.modal.GiveConfirmModal( {
108 classes: {
109 modalWrapper: 'give-paypal-standard-to-donations-migration-banner',
110 cancelBtn: 'give-button--secondary js-has-event-handler',
111 },
112 modalContent: {
113 body: `
114 <h2 class="give-modal__title">$modalTitle</h2>
115 <div class="give-modal__description">
116 <strong>$modalSubHeading</strong>
117 <p>$modalDescription</p>
118 </div>
119 `.trim(),
120 cancelBtnTitle: '$modalCancelButtonTitle',
121 confirmBtnTitle: '$modalConfirmButtonTitle'
122 },
123 closeOnBgClick: true,
124 showCloseBtn: true,
125 callbacks: {
126 open: () => {
127 const modal = document.querySelector('.give-modal');
128
129 modal.querySelector('.give-popup-close-button').addEventListener('click', () => {
130 window.open('https://docs.givewp.com/paypal-migration-doc', '_blank')
131 });
132
133 modal.querySelector('.give-popup-confirm-button').addEventListener('click', async () => {
134 await dismissModalAjaxRequest();
135 window.location.assign('$linkToPayPalDonationsSettingPage');
136 });
137 },
138 close: () => {
139 dismissModalAjaxRequest();
140 }
141 }
142 } ).render();
143 };
144
145 givePayPalStandardToDonationsMigrationGlobalBanner();
146 EOT;
147 }
148
149 /**
150 * @since 2.33.0
151 * @return string
152 */
153 private function getIcon(): string
154 {
155 return '<svg width="16" height="15" viewBox="0 0 16 15" fill="none" xmlns="http://www.w3.org/2000/svg">
156 <path fill-rule="evenodd" clip-rule="evenodd" d="M8.54163 1.11224C8.19676 0.958893 7.80304 0.958893 7.45817 1.11224C7.19182 1.23068 7.01879 1.43929 6.89839 1.60927C6.78002 1.7764 6.65328 1.99535 6.5139 2.23615L1.00246 11.7559C0.862519 11.9976 0.73535 12.2172 0.649123 12.4036C0.561489 12.593 0.46642 12.8476 0.496719 13.1382C0.535926 13.5143 0.732954 13.856 1.03876 14.0784C1.27509 14.2502 1.54309 14.2955 1.75093 14.3146C1.95543 14.3334 2.2092 14.3333 2.48846 14.3333H13.5113C13.7906 14.3333 14.0444 14.3334 14.2489 14.3146C14.4567 14.2955 14.7247 14.2502 14.961 14.0784C15.2668 13.856 15.4639 13.5143 15.5031 13.1382C15.5334 12.8476 15.4383 12.593 15.3507 12.4036C15.2645 12.2172 15.1373 11.9976 14.9974 11.756L9.48589 2.23612C9.34652 1.99534 9.21978 1.77639 9.10141 1.60927C8.98101 1.43929 8.80798 1.23068 8.54163 1.11224ZM8.66659 6C8.66659 5.63181 8.36811 5.33333 7.99992 5.33333C7.63173 5.33333 7.33325 5.63181 7.33325 6V8.66666C7.33325 9.03485 7.63173 9.33333 7.99992 9.33333C8.36811 9.33333 8.66659 9.03485 8.66659 8.66666V6ZM7.99992 10.6667C7.63173 10.6667 7.33325 10.9651 7.33325 11.3333C7.33325 11.7015 7.63173 12 7.99992 12H8.00659C8.37478 12 8.67325 11.7015 8.67325 11.3333C8.67325 10.9651 8.37478 10.6667 8.00659 10.6667H7.99992Z" fill="#F29718"/>
157 </svg>';
158 }
159
160 /**
161 * @since 2.33.0
162 * @return bool
163 */
164 private function isBannerDisabledForUser(): bool
165 {
166 $optionKey = give()->notices->get_notice_key($this->bannerId, 'permanent', get_current_user_id());
167 $optionData = \Give_Cache::get($optionKey, true);
168
169 return ! empty($optionData) && ! is_wp_error($optionData);
170 }
171 }
172