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 +119 -66 2.3.04.16.9 View file →
@@ -3,9 +3,9 @@
3 3 * Gateway Functions
4 4 *
5 5 * @package Give
6 6 * @subpackage Gateways
7 - * @copyright Copyright (c) 2016, WordImpress
7 + * @copyright Copyright (c) 2016, GiveWP
8 8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 9 * @since 1.0
10 10 */
11 11
@@ -16,44 +16,77 @@
16 16
17 17 /**
18 18 * Returns a list of all available gateways.
19 19 *
20 + * @since 3.0.0 add $version param
21 + * @since 2.30.0 add filter give_payment_gateways_admin_label
20 22 * @since 1.0
23 + * @param int|null $version
21 24 * @return array $gateways All the available gateways
22 25 */
23 -function give_get_payment_gateways() {
24 - // Default, built-in gateways
25 - $gateways = array(
26 - 'paypal' => array(
27 - 'admin_label' => __( 'PayPal Standard', 'give' ),
28 - 'checkout_label' => __( 'PayPal', 'give' ),
29 - ),
30 - 'manual' => array(
31 - 'admin_label' => __( 'Test Donation', 'give' ),
32 - 'checkout_label' => __( 'Test Donation', 'give' )
33 - ),
34 - );
26 +function give_get_payment_gateways($version = null)
27 +{
28 + // Default, built-in gateways
29 + $gateways = apply_filters(
30 + 'give_payment_gateways',
31 + Give_Cache_Setting::get_option('gateways', [])
32 + );
35 33
36 - return apply_filters( 'give_payment_gateways', $gateways );
34 + array_walk($gateways, static function (&$gateway, $gatewayId) {
35 + if (isset($gateway['admin_label'])) {
36 + $gateway['admin_label'] = apply_filters(
37 + 'give_payment_gateways_admin_label',
38 + $gateway['admin_label'],
39 + $gatewayId
40 + );
41 + }
42 + });
37 43
44 + $gatewayLabels = [];
45 + if (!$version || $version === 2) {
46 + $gatewayLabels = array_merge($gatewayLabels, (array)give_get_option('gateways_label', []));
47 + }
48 +
49 + if (!$version || $version === 3) {
50 + $gatewayLabels = array_merge($gatewayLabels, (array)give_get_option('gateways_label_v3', []));
51 + }
52 +
53 + // Replace payment gateway checkout label with admin defined checkout label.
54 + if ($gatewayLabels) {
55 + foreach ($gatewayLabels as $gatewayId => $checkoutLabel) {
56 + if ($checkoutLabel && array_key_exists($gatewayId, $gateways)) {
57 + $gateways[$gatewayId]['checkout_label'] = $checkoutLabel;
58 + }
59 + }
60 + }
61 +
62 + return $gateways;
38 63 }
39 64
40 65 /**
41 66 * Returns a list of all enabled gateways.
42 67 *
68 + * @since 3.0.0 add $version param
43 69 * @since 1.0
44 70 *
45 - * @param int $form_id Form ID
46 - *
71 + * @param int|null $form_id Form ID
72 + * @param int|null $version
47 73 * @return array $gateway_list All the available gateways
48 74 */
49 -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);
50 78
51 - $gateways = give_get_payment_gateways();
79 + $enabled = [];
80 + if (!$version || $version === 2) {
81 + $enabled = array_merge($enabled, (array)give_get_option('gateways', []));
82 + }
52 83
53 - $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 + }
54 87
55 - $gateway_list = array();
88 + $gateway_list = [];
56 89
57 90 foreach ( $gateways as $key => $gateway ) {
58 91 if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
59 92 $gateway_list[ $key ] = $gateway;
@@ -60,44 +93,51 @@
60 93 }
61 94 }
62 95
63 96 // Set order of payment gateway in list.
64 - $gateway_list = give_get_ordered_payment_gateways( $gateway_list );
97 + $gateway_list = give_get_ordered_payment_gateways($gateway_list, $version);
65 98
66 - return apply_filters( 'give_enabled_payment_gateways', $gateway_list, $form_id );
99 + return apply_filters('give_enabled_payment_gateways', $gateway_list, $form_id, $version);
67 100 }
68 101
69 102 /**
70 103 * Checks whether a specified gateway is activated.
71 104 *
105 + * @since 3.0.2 add $version param
72 106 * @since 1.0
73 107 *
74 108 * @param string $gateway Name of the gateway to check for
75 - *
76 - * @return boolean true if enabled, false otherwise
109 + * @param int|null $version
110 + * @return bool true if enabled, false otherwise
77 111 */
78 -function give_is_gateway_active( $gateway ) {
79 - $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);
80 115
81 116 $ret = array_key_exists( $gateway, $gateways );
82 117
83 - return apply_filters( 'give_is_gateway_active', $ret, $gateway, $gateways );
118 + return apply_filters('give_is_gateway_active', $ret, $gateway, $gateways, $version);
84 119 }
85 120
86 121 /**
87 122 * Gets the default payment gateway selected from the Give Settings
88 123 *
124 + * @since 3.0.2 add $version param
89 125 * @since 1.0
90 126 *
91 - * @param $form_id int ID of the Give Form
92 - *
127 + * @param int|null $form_id int ID of the Give Form
128 + * @param int|null $version
93 129 * @return string Gateway ID
94 130 */
95 -function give_get_default_gateway( $form_id ) {
96 -
97 - $enabled_gateways = array_keys( give_get_enabled_payment_gateways() );
98 - $default_gateway = give_get_option('default_gateway');
99 - $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];
100 140 $form_default = give_get_meta( $form_id, '_give_default_gateway', true );
101 141
102 142 // Single Form settings varies compared to the Global default settings.
103 143 if (
@@ -104,54 +144,51 @@
104 144 ! empty( $form_default ) &&
105 145 $form_id !== null &&
106 146 $default !== $form_default &&
107 147 'global' !== $form_default &&
108 - give_is_gateway_active( $form_default )
148 + give_is_gateway_active($form_default, $version)
109 149 ) {
110 150 $default = $form_default;
111 151 }
112 152
113 - return apply_filters( 'give_default_gateway', $default );
153 + return apply_filters('give_default_gateway', $default, $version);
114 154 }
115 155
116 156 /**
117 157 * Returns the admin label for the specified gateway
118 158 *
159 + * @since 2.21.0 remove hard coded admin_labels
119 160 * @since 1.0
120 161 *
121 - * @param string $gateway Name of the gateway to retrieve a label for
162 + * @param string $gateway Name of the gateway to retrieve a label for
122 163 *
123 164 * @return string Gateway admin label
124 165 */
125 -function give_get_gateway_admin_label( $gateway ) {
126 - $gateways = give_get_payment_gateways();
127 - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
166 +function give_get_gateway_admin_label($gateway)
167 +{
168 + $gateways = give_get_payment_gateways();
169 + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
128 170
129 - if ( $gateway == 'manual' ) {
130 - $label = __( 'Test Donation', 'give' );
131 - }
132 -
133 - return apply_filters( 'give_gateway_admin_label', $label, $gateway );
171 + return apply_filters('give_gateway_admin_label', $label, $gateway);
134 172 }
135 173
136 174 /**
137 175 * Returns the checkout label for the specified gateway
138 176 *
177 + * @since 3.0.0 add $version param
139 178 * @since 1.0
179 + * @since 2.15.0 Code removed. Here no need to forcefully change manual payment gateway checkout label to "Test Donation".
140 180 *
141 181 * @param string $gateway Name of the gateway to retrieve a label for
142 - *
182 + * @param int|null $version
143 183 * @return string Checkout label for the gateway
144 184 */
145 -function give_get_gateway_checkout_label( $gateway ) {
146 - $gateways = give_get_payment_gateways();
185 +function give_get_gateway_checkout_label($gateway, $version = 2)
186 +{
187 + $gateways = give_get_payment_gateways($version);
147 188 $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
148 189
149 - if ( $gateway == 'manual' ) {
150 - $label = __( 'Test Donation', 'give' );
151 - }
152 -
153 - return apply_filters( 'give_gateway_checkout_label', $label, $gateway );
190 + return apply_filters('give_gateway_checkout_label', $label, $gateway, $version);
154 191 }
155 192
156 193 /**
157 194 * Returns the options a gateway supports
@@ -163,9 +200,9 @@
163 200 * @return array Options the gateway supports
164 201 */
165 202 function give_get_gateway_supports( $gateway ) {
166 203 $gateways = give_get_enabled_payment_gateways();
167 - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
204 + $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : [];
168 205
169 206 return apply_filters( 'give_gateway_supports', $supports, $gateway );
170 207 }
171 208
@@ -241,8 +278,12 @@
241 278 * Record a log entry
242 279 *
243 280 * A wrapper function for the Give_Logging class add() method.
244 281 *
282 + * @deprecated 2.10.0
283 + * @use Log::LOG_TYPE( $message );
284 + * @see Log
285 + *
245 286 * @since 1.0
246 287 * @since 2.0 Use global logs object
247 288 *
248 289 * @param string $title Log title. Default is empty.
@@ -260,8 +301,12 @@
260 301 * Record a gateway error.
261 302 *
262 303 * A simple wrapper function for give_record_log().
263 304 *
305 + * @deprecated 2.10.0
306 + * @use Log::LOG_TYPE( $message );
307 + * @see Log
308 + *
264 309 * @access public
265 310 * @since 1.0
266 311 *
267 312 * @param string $title Title of the log entry (default: empty)
@@ -280,9 +325,9 @@
280 325 * Counts the number of donations made with a gateway.
281 326 *
282 327 * @since 1.0
283 328 *
284 - * @param string $gateway_id
329 + * @param string $gateway_id
285 330 * @param array|string $status
286 331 *
287 332 * @return int
288 333 */
@@ -288,9 +333,9 @@
288 333 */
289 334 function give_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
290 335
291 336 $ret = 0;
292 - $args = array(
337 + $args = [
293 338 'meta_key' => '_give_payment_gateway',
294 339 'meta_value' => $gateway_id,
295 340 'nopaging' => true,
296 341 'post_type' => 'give_payment',
@@ -295,9 +340,9 @@
295 340 'nopaging' => true,
296 341 'post_type' => 'give_payment',
297 342 'post_status' => $status,
298 343 'fields' => 'ids',
299 - );
344 + ];
300 345
301 346 $payments = new WP_Query( $args );
302 347
303 348 if ( $payments ) {
@@ -310,18 +355,26 @@
310 355
311 356 /**
312 357 * Returns a ordered list of all available gateways.
313 358 *
359 + * @since 3.0.2 add $version param
314 360 * @since 1.4.5
315 361 *
316 362 * @param array $gateways List of payment gateways
317 - *
363 + * @param int|null $version
318 364 * @return array $gateways All the available gateways
319 365 */
320 -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 + }
321 373
322 - // Get gateways setting.
323 - $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 + }
324 377
325 378 // Return from here if we do not have gateways setting.
326 379 if ( empty( $gateways_setting ) ) {
327 380 return $gateways;
@@ -331,14 +384,13 @@
331 384 $gateways_setting = array_reverse( $gateways_setting );
332 385
333 386 // Reorder gateways array
334 387 foreach ( $gateways_setting as $gateway_key => $value ) {
335 -
336 - $new_gateway_value = isset( $gateways[ $gateway_key ] ) ? $gateways[ $gateway_key ] : '';
388 + $new_gateway_value = $gateways[$gateway_key] ?? '';
337 389 unset( $gateways[ $gateway_key ] );
338 390
339 391 if ( ! empty( $new_gateway_value ) ) {
340 - $gateways = array_merge( array( $gateway_key => $new_gateway_value ), $gateways );
392 + $gateways = array_merge( [ $gateway_key => $new_gateway_value ], $gateways );
341 393 }
342 394 }
343 395
344 396 /**
@@ -343,10 +395,11 @@
343 395
344 396 /**
345 397 * Filter payment gateways order.
346 398 *
399 + * @since 3.0.2 add $version param
347 400 * @since 1.7
348 401 *
349 402 * @param array $gateways All the available gateways
350 403 */
351 - return apply_filters( 'give_payment_gateways_order', $gateways );
352 -}
404 + return apply_filters('give_payment_gateways_order', $gateways, $version);
405 +}