PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.12.2
GiveWP – Donation Plugin and Fundraising Platform v2.12.2
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 / install.php
give / includes Last commit date
admin 4 years ago api 5 years ago database 5 years ago deprecated 5 years ago donors 5 years ago emails 6 years ago forms 4 years ago frontend 6 years ago gateways 5 years ago libraries 6 years ago payments 4 years ago actions.php 5 years ago ajax-functions.php 5 years ago class-give-async-process.php 6 years ago class-give-background-updater.php 6 years ago class-give-cache-setting.php 5 years ago class-give-cache.php 6 years ago class-give-cli-commands.php 6 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 6 years ago class-give-donor.php 5 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 5 years ago class-give-logging.php 5 years ago class-give-readme-parser.php 6 years ago class-give-roles.php 6 years ago class-give-scripts.php 5 years ago class-give-session.php 5 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 6 years ago class-notices.php 5 years ago country-functions.php 5 years ago currencies-list.php 6 years ago currency-functions.php 5 years ago error-tracking.php 6 years ago filters.php 5 years ago formatting.php 6 years ago install.php 5 years ago login-register.php 6 years ago misc-functions.php 4 years ago plugin-compatibility.php 6 years ago post-types.php 5 years ago price-functions.php 6 years ago process-donation.php 5 years ago setting-functions.php 6 years ago shortcodes.php 6 years ago template-functions.php 5 years ago user-functions.php 5 years ago
install.php
554 lines
1 <?php
2
3 use Give\Log\Migrations\MigrateExistingLogs;
4 use Give\Revenue\Migrations\AddPastDonationsToRevenueTable;
5
6 /**
7 * Install Function
8 *
9 * @package Give
10 * @subpackage Functions/Install
11 * @copyright Copyright (c) 2016, GiveWP
12 * @license https://opensource.org/licenses/gpl-license GNU Public License
13 * @since 1.0
14 */
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * Install
23 *
24 * Runs on plugin install by setting up the post types, custom taxonomies, flushing rewrite rules to initiate the new
25 * 'donations' slug and also creates the plugin and populates the settings fields for those plugin pages. After
26 * successful install, the user is redirected to the Give Onboarding Wizard.
27 *
28 * @since 1.0
29 *
30 * @param bool $network_wide
31 *
32 * @global $wpdb
33 * @return void
34 */
35 function give_install( $network_wide = false ) {
36
37 global $wpdb;
38
39 if ( is_multisite() && $network_wide ) {
40
41 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs LIMIT 100" ) as $blog_id ) {
42
43 switch_to_blog( $blog_id );
44 give_run_install();
45 restore_current_blog();
46
47 }
48 } else {
49
50 give_run_install();
51
52 }
53
54 }
55
56 /**
57 * Run the Give Install process.
58 *
59 * @since 1.5
60 * @return void
61 */
62 function give_run_install() {
63 $give_options = give_get_settings();
64
65 // Setup the Give Custom Post Types.
66 give_setup_post_types();
67
68 // Add Upgraded From Option.
69 $current_version = get_option( 'give_version' );
70 if ( $current_version ) {
71 update_option( 'give_version_upgraded_from', $current_version, false );
72 }
73
74 // Setup some default options.
75 $options = [];
76
77 // Fresh Install? Setup Test Mode, Base Country (US), Test Gateway, Currency.
78 if ( empty( $current_version ) ) {
79 $options = array_merge( $options, give_get_default_settings() );
80 } else {
81 // Otherwise, disable the Onboarding experience
82 $options = [
83 'setup_page_enabled' => 'disabled',
84 ];
85 }
86
87 // Populate the default values.
88 update_option( 'give_settings', array_merge( $give_options, $options ), false );
89
90 // Create Give roles.
91 $roles = new Give_Roles();
92 $roles->add_roles();
93 $roles->add_caps();
94
95 // Set api version, end point and refresh permalink.
96 $api = new Give_API();
97 $api->add_endpoint();
98 update_option( 'give_default_api_version', 'v' . $api->get_version(), false );
99
100 // Create databases.
101 __give_register_tables();
102
103 // Add a temporary option to note that Give pages have been created.
104 Give_Cache::set( '_give_installed', $options, 30, true );
105
106 /**
107 * Run plugin upgrades.
108 *
109 * @since 1.8
110 */
111 do_action( 'give_upgrades' );
112
113 if ( GIVE_VERSION !== get_option( 'give_version' ) ) {
114 update_option( 'give_version', GIVE_VERSION, false );
115 }
116
117 if ( ! $current_version ) {
118
119 require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
120
121 // When new upgrade routines are added, mark them as complete on fresh install.
122 $upgrade_routines = [
123 'upgrade_give_user_caps_cleanup',
124 'upgrade_give_payment_customer_id',
125 'upgrade_give_offline_status',
126 'v18_upgrades_core_setting',
127 'v18_upgrades_form_metadata',
128 'v189_upgrades_levels_post_meta',
129 'v1812_update_amount_values',
130 'v1812_update_donor_purchase_values',
131 'v1813_update_user_roles',
132 'v1813_update_donor_user_roles',
133 'v1817_update_donation_iranian_currency_code',
134 'v1817_cleanup_user_roles',
135 'v1818_assign_custom_amount_set_donation',
136 'v1818_give_worker_role_cleanup',
137 'v20_upgrades_form_metadata',
138 'v20_logs_upgrades',
139 'v20_move_metadata_into_new_table',
140 'v20_rename_donor_tables',
141 'v20_upgrades_donor_name',
142 'v20_upgrades_user_address',
143 'v20_upgrades_payment_metadata',
144 'v201_upgrades_payment_metadata',
145 'v201_add_missing_donors',
146 'v201_move_metadata_into_new_table',
147 'v201_logs_upgrades',
148 'v210_verify_form_status_upgrades',
149 'v213_delete_donation_meta',
150 'v215_update_donor_user_roles',
151 'v220_rename_donation_meta_type',
152 'v224_update_donor_meta',
153 'v224_update_donor_meta_forms_id',
154 'v230_move_donor_note',
155 'v230_move_donation_note',
156 'v230_delete_donor_wall_related_donor_data',
157 'v230_delete_donor_wall_related_comment_data',
158 'v240_update_form_goal_progress',
159 'v241_remove_sale_logs',
160 'v270_store_stripe_account_for_donation',
161 AddPastDonationsToRevenueTable::id(),
162 MigrateExistingLogs::id(),
163 ];
164
165 foreach ( $upgrade_routines as $upgrade ) {
166 give_set_upgrade_complete( $upgrade );
167 }
168 }
169
170 // Bail if activating from network, or bulk.
171 if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
172 return;
173 }
174
175 // Setup embed form route on fresh install or plugin activation.
176 Give()->routeForm->setBasePrefix();
177 Give()->routeForm->addRule();
178
179 // Flush rewrite rules.
180 flush_rewrite_rules();
181
182 // Add the transient to redirect.
183 Give_Cache::set( '_give_activation_redirect', true, 30, true );
184 }
185
186 /**
187 * Network Activated New Site Setup.
188 *
189 * When a new site is created when Give is network activated this function runs the appropriate install function to set
190 * up the site for Give.
191 *
192 * @since 1.3.5
193 *
194 * @param int $blog_id The Blog ID created.
195 * @param int $user_id The User ID set as the admin.
196 * @param string $domain The URL.
197 * @param string $path Site Path.
198 * @param int $site_id The Site ID.
199 * @param array $meta Blog Meta.
200 */
201 function give_on_create_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
202
203 if ( is_plugin_active_for_network( GIVE_PLUGIN_BASENAME ) ) {
204
205 switch_to_blog( $blog_id );
206 give_install();
207 restore_current_blog();
208
209 }
210
211 }
212
213 add_action( 'wpmu_new_blog', 'give_on_create_blog', 10, 6 );
214
215
216 /**
217 * Drop Give's custom tables when a mu site is deleted.
218 *
219 * @since 1.4.3
220 *
221 * @param array $tables The tables to drop.
222 * @param int $blog_id The Blog ID being deleted.
223 *
224 * @return array The tables to drop.
225 */
226 function give_wpmu_drop_tables( $tables, $blog_id ) {
227
228 switch_to_blog( $blog_id );
229 $custom_tables = __give_get_tables();
230
231 /* @var Give_DB $table */
232 foreach ( $custom_tables as $table ) {
233 if ( $table->installed() ) {
234 $tables[] = $table->table_name;
235 }
236 }
237
238 restore_current_blog();
239
240 return $tables;
241
242 }
243
244 add_filter( 'wpmu_drop_tables', 'give_wpmu_drop_tables', 10, 2 );
245
246 /**
247 * Post-installation
248 *
249 * Runs just after plugin installation and exposes the give_after_install hook.
250 *
251 * @since 1.0
252 * @return void
253 */
254 function give_after_install() {
255
256 if ( ! is_admin() ) {
257 return;
258 }
259
260 $give_options = Give_Cache::get( '_give_installed', true );
261 $give_table_check = get_option( '_give_table_check', false );
262
263 if ( false === $give_table_check || current_time( 'timestamp' ) > $give_table_check ) {
264
265 if ( ! @Give()->donor_meta->installed() ) {
266
267 // Create the donor meta database.
268 // (this ensures it creates it on multisite instances where it is network activated).
269 @Give()->donor_meta->create_table();
270
271 }
272
273 if ( ! @Give()->donors->installed() ) {
274 // Create the donor database.
275 // (this ensures it creates it on multisite instances where it is network activated).
276 @Give()->donors->create_table();
277 }
278
279 /**
280 * Fires after plugin installation.
281 *
282 * @since 1.0
283 *
284 * @param array $give_options Give plugin options.
285 */
286 do_action( 'give_after_install', $give_options );
287
288 update_option( '_give_table_check', ( current_time( 'timestamp' ) + WEEK_IN_SECONDS ), false );
289 }
290
291 // Delete the transient
292 if ( false !== $give_options ) {
293 Give_Cache::delete( Give_Cache::get_key( '_give_installed' ) );
294 }
295
296 }
297
298 add_action( 'admin_init', 'give_after_install' );
299
300
301 /**
302 * Install user roles on sub-sites of a network
303 *
304 * Roles do not get created when Give is network activation so we need to create them during admin_init
305 *
306 * @since 1.0
307 * @return void
308 */
309 function give_install_roles_on_network() {
310
311 global $wp_roles;
312
313 if ( ! is_object( $wp_roles ) ) {
314 return;
315 }
316
317 if ( ! array_key_exists( 'give_manager', $wp_roles->roles ) ) {
318
319 // Create Give plugin roles
320 $roles = new Give_Roles();
321 $roles->add_roles();
322 $roles->add_caps();
323
324 }
325
326 }
327
328 add_action( 'admin_init', 'give_install_roles_on_network' );
329
330 /**
331 * Default core setting values.
332 *
333 * @since 1.8
334 * @return array
335 */
336 function give_get_default_settings() {
337
338 $options = [
339 // General.
340 'base_country' => 'US',
341 'test_mode' => 'enabled',
342 'currency' => 'USD',
343 'currency_position' => 'before',
344 'session_lifetime' => '604800',
345 'email_access' => 'enabled',
346 'thousands_separator' => ',',
347 'decimal_separator' => '.',
348 'number_decimals' => 2,
349 'sequential-ordering_status' => 'enabled',
350
351 // Display options.
352 'css' => 'enabled',
353 'floatlabels' => 'disabled',
354 'company_field' => 'disabled',
355 'name_title_prefix' => 'disabled',
356 'forms_singular' => 'enabled',
357 'forms_archives' => 'enabled',
358 'forms_excerpt' => 'enabled',
359 'form_featured_img' => 'enabled',
360 'form_sidebar' => 'enabled',
361 'categories' => 'disabled',
362 'tags' => 'disabled',
363 'terms' => 'disabled',
364 'admin_notices' => 'enabled',
365 'cache' => 'enabled',
366 'uninstall_on_delete' => 'disabled',
367 'the_content_filter' => 'enabled',
368 'scripts_footer' => 'disabled',
369 'agree_to_terms_label' => __( 'Agree to Terms?', 'give' ),
370 'agreement_text' => give_get_default_agreement_text(),
371 'babel_polyfill_script' => 'enabled',
372
373 // Paypal IPN verification.
374 'paypal_verification' => 'enabled',
375
376 // Default is manual gateway.
377 'gateways' => [
378 'manual' => 1,
379 'offline' => 1,
380 ],
381 'default_gateway' => 'manual',
382
383 // Offline gateway setup.
384 'global_offline_donation_content' => give_get_default_offline_donation_content(),
385 'global_offline_donation_email' => give_get_default_offline_donation_content(),
386
387 // Billing address.
388 'give_offline_donation_enable_billing_fields' => 'disabled',
389
390 // Default donation notification email.
391 'donation_notification' => give_get_default_donation_notification_email(),
392
393 // Default email receipt message.
394 'donation_receipt' => give_get_default_donation_receipt_email(),
395
396 'donor_default_user_role' => 'give_donor',
397 Give()->routeForm->getOptionName() => 'give',
398
399 // Stripe accounts.
400 '_give_stripe_get_all_accounts' => [],
401
402 // Onboarding
403 'setup_page_enabled' => 'enabled',
404
405 // Advanced settings
406 'usage_tracking' => 'disabled',
407 ];
408
409 return $options;
410 }
411
412 /**
413 * Default terms and conditions.
414 */
415 function give_get_default_agreement_text() {
416
417 $org_name = get_bloginfo( 'name' );
418
419 $agreement = sprintf(
420 '<p>Acceptance of any contribution, gift or grant is at the discretion of the %1$s. The %1$s will not accept any gift unless it can be used or expended consistently with the purpose and mission of the %1$s.</p>
421 <p>No irrevocable gift, whether outright or life-income in character, will be accepted if under any reasonable set of circumstances the gift would jeopardize the donor’s financial security.</p>
422 <p>The %1$s will refrain from providing advice about the tax or other treatment of gifts and will encourage donors to seek guidance from their own professional advisers to assist them in the process of making their donation.</p>
423 <p>The %1$s will accept donations of cash or publicly traded securities. Gifts of in-kind services will be accepted at the discretion of the %1$s.</p>
424 <p>Certain other gifts, real property, personal property, in-kind gifts, non-liquid securities, and contributions whose sources are not transparent or whose use is restricted in some manner, must be reviewed prior to acceptance due to the special obligations raised or liabilities they may pose for %1$s.</p>
425 <p>The %1$s will provide acknowledgments to donors meeting tax requirements for property received by the charity as a gift. However, except for gifts of cash and publicly traded securities, no value shall be ascribed to any receipt or other form of substantiation of a gift received by %1$s.</p>
426 <p>The %1$s will respect the intent of the donor relating to gifts for restricted purposes and those relating to the desire to remain anonymous. With respect to anonymous gifts, the %1$s will restrict information about the donor to only those staff members with a need to know.</p>
427 <p>The %1$s will not compensate, whether through commissions, finders\' fees, or other means, any third party for directing a gift or a donor to the %1$s.</p>',
428 $org_name
429 );
430
431 return apply_filters( 'give_get_default_agreement_text', $agreement, $org_name );
432 }
433
434
435 /**
436 * This function will install give related page which is not created already.
437 *
438 * @since 1.8.11
439 *
440 * @return void
441 */
442 function give_create_pages() {
443
444 // Bailout if pages already created.
445 if ( Give_Cache_Setting::get_option( 'give_install_pages_created' ) ) {
446 return;
447 }
448
449 $options = [];
450
451 // Checks if the Success Page option exists AND that the page exists.
452 if ( ! get_post( give_get_option( 'success_page' ) ) ) {
453
454 // Donation Confirmation (Success) Page
455 $success = wp_insert_post(
456 [
457 'post_title' => esc_html__( 'Donation Confirmation', 'give' ),
458 'post_content' => '[give_receipt]',
459 'post_status' => 'publish',
460 'post_author' => 1,
461 'post_type' => 'page',
462 'comment_status' => 'closed',
463 ]
464 );
465
466 // Store our page IDs
467 $options['success_page'] = $success;
468 }
469
470 // Checks if the Failure Page option exists AND that the page exists.
471 if ( ! get_post( give_get_option( 'failure_page' ) ) ) {
472
473 // Failed Donation Page
474 $failed = wp_insert_post(
475 [
476 'post_title' => esc_html__( 'Donation Failed', 'give' ),
477 'post_content' => esc_html__( 'We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give' ),
478 'post_status' => 'publish',
479 'post_author' => 1,
480 'post_type' => 'page',
481 'comment_status' => 'closed',
482 ]
483 );
484
485 $options['failure_page'] = $failed;
486 }
487
488 if ( ! empty( $options ) ) {
489 update_option( 'give_settings', array_merge( give_get_settings(), $options ), false );
490 }
491
492 add_option( 'give_install_pages_created', 1, '', false );
493 }
494
495 // @TODO we can add this hook only when plugin activate instead of every admin page load.
496 // @see known issue https://github.com/impress-org/give/issues/1848
497 add_action( 'admin_init', 'give_create_pages', - 1 );
498
499
500 /**
501 * Install tables on plugin update if missing
502 * Note: only for internal use
503 *
504 * @since 2.4.1
505 *
506 * @param string $old_version
507 */
508 function give_install_tables_on_plugin_update( $old_version ) {
509 update_option( 'give_version_upgraded_from', $old_version, false );
510 __give_register_tables();
511 }
512
513 add_action( 'update_option_give_version', 'give_install_tables_on_plugin_update', 0, 2 );
514
515
516 /**
517 * Get array of table class objects
518 *
519 * Note: only for internal purpose use
520 *
521 * @sice 2.3.1
522 */
523 function __give_get_tables() {
524 $tables = [
525 'donors_db' => new Give_DB_Donors(),
526 'donor_meta_db' => new Give_DB_Donor_Meta(),
527 'comment_db' => new Give_DB_Comments(),
528 'comment_db_meta' => new Give_DB_Comment_Meta(),
529 'give_session' => new Give_DB_Sessions(),
530 'formmeta_db' => new Give_DB_Form_Meta(),
531 'sequential_db' => new Give_DB_Sequential_Ordering(),
532 'donation_meta' => new Give_DB_Payment_Meta(),
533 ];
534
535 return $tables;
536 }
537
538 /**
539 * Register classes
540 * Note: only for internal purpose use
541 *
542 * @sice 2.3.1
543 */
544 function __give_register_tables() {
545 $tables = __give_get_tables();
546
547 /* @var Give_DB $table */
548 foreach ( $tables as $table ) {
549 if ( ! $table->installed() ) {
550 $table->register_table();
551 }
552 }
553 }
554