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