PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.19.4
GiveWP – Donation Plugin and Fundraising Platform v3.19.4
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 / includes / gateways / offline-donations.php
give / includes / gateways Last commit date
paypal 4 years ago stripe 1 year ago actions.php 4 years ago functions.php 2 years ago offline-donations.php 2 years ago
offline-donations.php
274 lines
1 <?php
2 /**
3 * Offline Donations Gateway
4 *
5 * @package Give
6 * @subpackage Gateways
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 /**
13 * Register gateway settings.
14 *
15 * @param $settings
16 *
17 * @return array
18 */
19 function give_offline_add_settings( $settings ) {
20
21 // Bailout: Do not show offline gateways setting in to metabox if its disabled globally.
22 if ( in_array( 'offline', (array) give_get_option( 'gateways' ) ) ) {
23 return $settings;
24 }
25
26 // Vars
27 $prefix = '_give_';
28
29 $is_gateway_active = give_is_gateway_active( 'offline' );
30
31 // this gateway isn't active
32 if ( ! $is_gateway_active ) {
33 // return settings and bounce
34 return $settings;
35 }
36
37 // Fields
38 $check_settings = [
39
40 [
41 'name' => __( 'Offline Donations', 'give' ),
42 'desc' => __( 'Do you want to customize the donation instructions for this form?', 'give' ),
43 'id' => $prefix . 'customize_offline_donations',
44 'type' => 'radio_inline',
45 'default' => 'global',
46 'options' => apply_filters(
47 'give_forms_content_options_select',
48 [
49 'global' => __( 'Global Option', 'give' ),
50 'enabled' => __( 'Customize', 'give' ),
51 'disabled' => __( 'Disable', 'give' ),
52 ]
53 ),
54 ],
55 [
56 'name' => __( 'Billing Fields', 'give' ),
57 'desc' => __( 'This option will enable the billing details section for this form\'s offline donation payment gateway. The fieldset will appear above the offline donation instructions.', 'give' ),
58 'id' => $prefix . 'offline_donation_enable_billing_fields_single',
59 'row_classes' => 'give-subfield give-hidden',
60 'type' => 'radio_inline',
61 'default' => 'disabled',
62 'options' => [
63 'enabled' => __( 'Enabled', 'give' ),
64 'disabled' => __( 'Disabled', 'give' ),
65 ],
66 ],
67 [
68 'id' => $prefix . 'offline_checkout_notes',
69 'name' => __( 'Donation Instructions', 'give' ),
70 'desc' => __( 'Enter the instructions you want to display to the donor during the donation process. Most likely this would include important information like mailing address and who to make the check out to.', 'give' ),
71 'default' => give_get_default_offline_donation_content(),
72 'type' => 'wysiwyg',
73 'row_classes' => 'give-subfield give-hidden',
74 'options' => [
75 'textarea_rows' => 6,
76 ],
77 ],
78 [
79 'name' => 'offline_docs',
80 'type' => 'docs_link',
81 'url' => 'http://docs.givewp.com/settings-gateway-offline-donations',
82 'title' => __( 'Offline Donations', 'give' ),
83 ],
84 ];
85
86 return array_merge( $settings, $check_settings );
87 }
88
89 add_filter( 'give_forms_offline_donations_metabox_fields', 'give_offline_add_settings' );
90
91
92 /**
93 * Offline Donation Content
94 *
95 * Get default offline donation text
96 *
97 * @return string
98 */
99 function give_get_default_offline_donation_content() {
100 $default_text = '<p>' . __( 'To make an offline donation toward this cause, follow these steps:', 'give' ) . ' </p>';
101 $default_text .= '<ol>';
102 $default_text .= '<li>';
103 $default_text .= sprintf(
104 /* translators: %s: site name */
105 __( 'Write a check payable to "{sitename}"', 'give' )
106 );
107 $default_text .= '</li>';
108 $default_text .= '<li>';
109 $default_text .= sprintf(
110 /* translators: %s: site name */
111 __( 'On the memo line of the check, indicate that the donation is for "{sitename}"', 'give' )
112 );
113 $default_text .= '</li>';
114 $default_text .= '<li>' . __( 'Mail your check to:', 'give' ) . '</li>';
115 $default_text .= '</ol>';
116 $default_text .= '{offline_mailing_address}<br>';
117 $default_text .= '<p>' . __( 'Your tax-deductible donation is greatly appreciated!', 'give' ) . '</p>';
118
119 return apply_filters( 'give_default_offline_donation_content', $default_text );
120
121 }
122
123 /**
124 * Offline Donation Email Content
125 *
126 * Gets the default offline donation email content
127 *
128 * @since 2.14.0 Remove unnecessary sprintf
129 *
130 * @return string
131 */
132 function give_get_default_offline_donation_email_content() {
133 $default_text = '<p>' . __( 'Hi {name},', 'give' ) . '</p>';
134 $default_text .= '<p>' . __( 'Thank you for letting us know that you\'re mailing a check! Your generosity is greatly appreciated. Here are those steps again:', 'give' ) . '</p>';
135 $default_text .= '<ol>';
136 $default_text .= '<li>';
137 $default_text .= esc_html__( 'Write a check payable to "{sitename}"', 'give' );
138 $default_text .= '</li>';
139 $default_text .= '<li>';
140 $default_text .= esc_html__( 'On the memo line of the check, indicate that the donation is for "{form_title}"', 'give' );
141 $default_text .= '</li>';
142 $default_text .= '<li>' . __( 'Mail your check to:', 'give' ) . '</li>';
143 $default_text .= '</ol>';
144 $default_text .= '{offline_mailing_address}<br>';
145 $default_text .= '<p>' . esc_html__( 'Once we receive the check, we will mark it as complete in our system, which will generate an email receipt for your records. Please contact us with any questions you may have!', 'give' ) . '</p>';
146 $default_text .= '<p>' . esc_html__( 'Thanks in advance!', 'give' ) . '</p>';
147 $default_text .= '<p>{sitename}</p>';
148
149 return apply_filters( 'give_default_offline_donation_content', $default_text );
150 }
151
152 /**
153 * Get formatted offline instructions
154 *
155 * @since 2.15.0
156 *
157 * @param string $instructions
158 * @param int $form_id
159 * @param bool $wpautop
160 *
161 * @return string
162 */
163 function get_formatted_offline_instructions( $instructions, $form_id, $wpautop = false ) {
164 $settings_url = admin_url( 'post.php?post=' . $form_id . '&action=edit&message=1' );
165
166 /* translators: %s: form settings url */
167 $offline_instructions = ! empty( $instructions ) ? $instructions : sprintf(
168 __( 'Please enter offline donation instructions in <a href="%s">this form\'s settings</a>.', 'give' ),
169 $settings_url
170 );
171
172 $offline_instructions = give_do_email_tags($offline_instructions, ['form_id' => $form_id]);
173
174 return $wpautop ? wpautop( do_shortcode( $offline_instructions ) ) : $offline_instructions;
175 }
176
177 /**
178 * Get offline payment instructions.
179 *
180 * @since 2.15.0 - conditionally display instructions based on form settings
181 * @since 1.7
182 *
183 * @param int $form_id
184 * @param bool $wpautop
185 *
186 * @return string
187 */
188 function give_get_offline_payment_instruction( $form_id, $wpautop = false ) {
189 // Bailout.
190 if ( ! $form_id ) {
191 return '';
192 }
193
194 $post_offline_customization_option = give_get_meta( $form_id, '_give_customize_offline_donations', true );
195 $post_offline_customization_option_enabled = give_is_setting_enabled( $post_offline_customization_option );
196
197 if ( $post_offline_customization_option === 'disabled' ) {
198 return '';
199 }
200
201 $post_offline_instructions = give_get_meta( $form_id, '_give_offline_checkout_notes', true );
202 $global_offline_instructions = give_get_option( 'global_offline_donation_content' );
203 $offline_instructions_content = $post_offline_customization_option_enabled ? $post_offline_instructions : $global_offline_instructions;
204
205 $formatted_offline_instructions = get_formatted_offline_instructions(
206 $offline_instructions_content,
207 $form_id,
208 $wpautop
209 );
210
211 /**
212 * Filter the offline instruction content
213 *
214 * @since 2.2.0
215 */
216 return apply_filters(
217 'give_the_offline_instructions_content',
218 $formatted_offline_instructions,
219 $offline_instructions_content,
220 $form_id,
221 $wpautop
222 );
223 }
224
225
226 /**
227 * Remove offline gateway from gateway list of offline disable for form.
228 *
229 * @since 1.8
230 *
231 * @param array $gateway_list
232 * @param $form_id
233 *
234 * @return array
235 */
236 function give_filter_offline_gateway( $gateway_list, $form_id ) {
237 if (
238 // Show offline payment gateway if enable for new donation form.
239 ( false === strpos( $_SERVER['REQUEST_URI'], '/wp-admin/post-new.php?post_type=give_forms' ) )
240 && $form_id
241 && ! give_is_setting_enabled( give_get_meta( $form_id, '_give_customize_offline_donations', true, 'global' ), [ 'enabled', 'global' ] )
242 ) {
243 unset( $gateway_list['offline'] );
244 }
245
246 // Output.
247 return $gateway_list;
248 }
249
250 add_filter( 'give_enabled_payment_gateways', 'give_filter_offline_gateway', 10, 2 );
251
252 /**
253 * Set default gateway to global default payment gateway
254 * if current default gateways selected offline and offline payment gateway is disabled.
255 *
256 * @since 1.8
257 *
258 * @param string $meta_key Meta key.
259 * @param string $meta_value Meta value.
260 * @param int $postid Form ID.
261 *
262 * @return void
263 */
264 function _give_customize_offline_donations_on_save_callback( $meta_key, $meta_value, $postid ) {
265 if (
266 ! give_is_setting_enabled( $meta_value, [ 'global', 'enabled' ] )
267 && ( 'offline' === give_get_meta( $postid, '_give_default_gateway', true ) )
268 ) {
269 give_update_meta( $postid, '_give_default_gateway', 'global' );
270 }
271 }
272
273 add_filter( 'give_save__give_customize_offline_donations', '_give_customize_offline_donations_on_save_callback', 10, 3 );
274