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
← All changes | includes/gateways/functions.php +68 -34 2.30.04.16.9 View file →
@@ -16,13 +16,15 @@
16 16
17 17 /**
18 18 * Returns a list of all available gateways.
19 19 *
20 + * @since 3.0.0 add $version param
20 21 * @since 2.30.0 add filter give_payment_gateways_admin_label
21 22 * @since 1.0
23 + * @param int|null $version
22 24 * @return array $gateways All the available gateways
23 25 */
24 -function give_get_payment_gateways()
26 +function give_get_payment_gateways($version = null)
25 27 {
26 28 // Default, built-in gateways
27 29 $gateways = apply_filters(
28 30 'give_payment_gateways',
@@ -38,10 +40,17 @@
38 40 );
39 41 }
40 42 });
41 43
42 - $gatewayLabels = give_get_option('gateways_label', []);
44 + $gatewayLabels = [];
45 + if (!$version || $version === 2) {
46 + $gatewayLabels = array_merge($gatewayLabels, (array)give_get_option('gateways_label', []));
47 + }
43 48
49 + if (!$version || $version === 3) {
50 + $gatewayLabels = array_merge($gatewayLabels, (array)give_get_option('gateways_label_v3', []));
51 + }
52 +
44 53 // Replace payment gateway checkout label with admin defined checkout label.
45 54 if ($gatewayLabels) {
46 55 foreach ($gatewayLabels as $gatewayId => $checkoutLabel) {
47 56 if ($checkoutLabel && array_key_exists($gatewayId, $gateways)) {
@@ -55,19 +64,27 @@
55 64
56 65 /**
57 66 * Returns a list of all enabled gateways.
58 67 *
68 + * @since 3.0.0 add $version param
59 69 * @since 1.0
60 70 *
61 - * @param int $form_id Form ID
62 - *
71 + * @param int|null $form_id Form ID
72 + * @param int|null $version
63 73 * @return array $gateway_list All the available gateways
64 74 */
65 -function give_get_enabled_payment_gateways( $form_id = 0 ) {
75 +function give_get_enabled_payment_gateways($form_id = 0, $version = null)
76 +{
77 + $gateways = give_get_payment_gateways($version);
66 78
67 - $gateways = give_get_payment_gateways();
79 + $enabled = [];
80 + if (!$version || $version === 2) {
81 + $enabled = array_merge($enabled, (array)give_get_option('gateways', []));
82 + }
68 83
69 - $enabled = isset( $_POST['gateways'] ) ? $_POST['gateways'] : give_get_option( 'gateways' );
84 + if (!$version || $version === 3) {
85 + $enabled = array_merge($enabled, (array)give_get_option('gateways_v3', []));
86 + }
70 87
71 88 $gateway_list = [];
72 89
73 90 foreach ( $gateways as $key => $gateway ) {
@@ -76,44 +93,51 @@
76 93 }
77 94 }
78 95
79 96 // Set order of payment gateway in list.
80 - $gateway_list = give_get_ordered_payment_gateways( $gateway_list );
97 + $gateway_list = give_get_ordered_payment_gateways($gateway_list, $version);
81 98
82 - return apply_filters( 'give_enabled_payment_gateways', $gateway_list, $form_id );
99 + return apply_filters('give_enabled_payment_gateways', $gateway_list, $form_id, $version);
83 100 }
84 101
85 102 /**
86 103 * Checks whether a specified gateway is activated.
87 104 *
105 + * @since 3.0.2 add $version param
88 106 * @since 1.0
89 107 *
90 108 * @param string $gateway Name of the gateway to check for
91 - *
92 - * @return boolean true if enabled, false otherwise
109 + * @param int|null $version
110 + * @return bool true if enabled, false otherwise
93 111 */
94 -function give_is_gateway_active( $gateway ) {
95 - $gateways = give_get_enabled_payment_gateways();
112 +function give_is_gateway_active($gateway, $version = 2)
113 +{
114 + $gateways = give_get_enabled_payment_gateways(null, $version);
96 115
97 116 $ret = array_key_exists( $gateway, $gateways );
98 117
99 - return apply_filters( 'give_is_gateway_active', $ret, $gateway, $gateways );
118 + return apply_filters('give_is_gateway_active', $ret, $gateway, $gateways, $version);
100 119 }
101 120
102 121 /**
103 122 * Gets the default payment gateway selected from the Give Settings
104 123 *
124 + * @since 3.0.2 add $version param
105 125 * @since 1.0
106 126 *
107 - * @param $form_id int ID of the Give Form
108 - *
127 + * @param int|null $form_id int ID of the Give Form
128 + * @param int|null $version
109 129 * @return string Gateway ID
110 130 */
111 -function give_get_default_gateway( $form_id ) {
112 -
113 - $enabled_gateways = array_keys( give_get_enabled_payment_gateways() );
114 - $default_gateway = give_get_option( 'default_gateway' );
115 - $default = ! empty( $default_gateway ) && give_is_gateway_active( $default_gateway ) ? $default_gateway : $enabled_gateways[0];
131 +function give_get_default_gateway($form_id, $version = 2)
132 +{
133 + $suffix = $version === 3 ? '_v3' : '';
134 + $enabled_gateways = array_keys(give_get_enabled_payment_gateways($form_id, $version));
135 + $default_gateway = give_get_option('default_gateway' . $suffix);
136 + $default = !empty($default_gateway) && give_is_gateway_active(
137 + $default_gateway,
138 + $version
139 + ) ? $default_gateway : $enabled_gateways[0];
116 140 $form_default = give_get_meta( $form_id, '_give_default_gateway', true );
117 141
118 142 // Single Form settings varies compared to the Global default settings.
119 143 if (
@@ -120,14 +144,14 @@
120 144 ! empty( $form_default ) &&
121 145 $form_id !== null &&
122 146 $default !== $form_default &&
123 147 'global' !== $form_default &&
124 - give_is_gateway_active( $form_default )
148 + give_is_gateway_active($form_default, $version)
125 149 ) {
126 150 $default = $form_default;
127 151 }
128 152
129 - return apply_filters( 'give_default_gateway', $default );
153 + return apply_filters('give_default_gateway', $default, $version);
130 154 }
131 155
132 156 /**
133 157 * Returns the admin label for the specified gateway
@@ -149,20 +173,22 @@
149 173
150 174 /**
151 175 * Returns the checkout label for the specified gateway
152 176 *
177 + * @since 3.0.0 add $version param
153 178 * @since 1.0
154 179 * @since 2.15.0 Code removed. Here no need to forcefully change manual payment gateway checkout label to "Test Donation".
155 180 *
156 181 * @param string $gateway Name of the gateway to retrieve a label for
157 - *
182 + * @param int|null $version
158 183 * @return string Checkout label for the gateway
159 184 */
160 -function give_get_gateway_checkout_label( $gateway ) {
161 - $gateways = give_get_payment_gateways();
185 +function give_get_gateway_checkout_label($gateway, $version = 2)
186 +{
187 + $gateways = give_get_payment_gateways($version);
162 188 $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
163 189
164 - return apply_filters( 'give_gateway_checkout_label', $label, $gateway );
190 + return apply_filters('give_gateway_checkout_label', $label, $gateway, $version);
165 191 }
166 192
167 193 /**
168 194 * Returns the options a gateway supports
@@ -329,18 +355,26 @@
329 355
330 356 /**
331 357 * Returns a ordered list of all available gateways.
332 358 *
359 + * @since 3.0.2 add $version param
333 360 * @since 1.4.5
334 361 *
335 362 * @param array $gateways List of payment gateways
336 - *
363 + * @param int|null $version
337 364 * @return array $gateways All the available gateways
338 365 */
339 -function give_get_ordered_payment_gateways( $gateways ) {
366 +function give_get_ordered_payment_gateways($gateways, $version = null)
367 +{
368 + // Get gateways setting.
369 + $gateways_setting = [];
370 + if (!$version || $version === 2) {
371 + $gateways_setting = array_merge($gateways_setting, (array)give_get_option('gateways', []));
372 + }
340 373
341 - // Get gateways setting.
342 - $gateways_setting = isset( $_POST['gateways'] ) ? $_POST['gateways'] : give_get_option( 'gateways' );
374 + if (!$version || $version === 3) {
375 + $gateways_setting = array_merge($gateways_setting, (array)give_get_option('gateways_v3', []));
376 + }
343 377
344 378 // Return from here if we do not have gateways setting.
345 379 if ( empty( $gateways_setting ) ) {
346 380 return $gateways;
@@ -350,10 +384,9 @@
350 384 $gateways_setting = array_reverse( $gateways_setting );
351 385
352 386 // Reorder gateways array
353 387 foreach ( $gateways_setting as $gateway_key => $value ) {
354 -
355 - $new_gateway_value = isset( $gateways[ $gateway_key ] ) ? $gateways[ $gateway_key ] : '';
388 + $new_gateway_value = $gateways[$gateway_key] ?? '';
356 389 unset( $gateways[ $gateway_key ] );
357 390
358 391 if ( ! empty( $new_gateway_value ) ) {
359 392 $gateways = array_merge( [ $gateway_key => $new_gateway_value ], $gateways );
@@ -362,10 +395,11 @@
362 395
363 396 /**
364 397 * Filter payment gateways order.
365 398 *
399 + * @since 3.0.2 add $version param
366 400 * @since 1.7
367 401 *
368 402 * @param array $gateways All the available gateways
369 403 */
370 - return apply_filters( 'give_payment_gateways_order', $gateways );
404 + return apply_filters('give_payment_gateways_order', $gateways, $version);
371 405 }