upgrade-functions.php
2730 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Upgrade Functions |
| 4 | * |
| 5 | * @package Give |
| 6 | * @subpackage Admin/Upgrades |
| 7 | * @copyright Copyright (c) 2016, WordImpress |
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 | * @since 1.0 |
| 10 | * |
| 11 | * NOTICE: When adding new upgrade notices, please be sure to put the action into the upgrades array during install: |
| 12 | * /includes/install.php @ Appox Line 156 |
| 13 | */ |
| 14 | |
| 15 | // Exit if accessed directly. |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Perform automatic database upgrades when necessary. |
| 22 | * |
| 23 | * @since 1.6 |
| 24 | * @return void |
| 25 | */ |
| 26 | function give_do_automatic_upgrades() { |
| 27 | $did_upgrade = false; |
| 28 | $give_version = preg_replace( '/[^0-9.].*/', '', get_option( 'give_version' ) ); |
| 29 | |
| 30 | if ( ! $give_version ) { |
| 31 | // 1.0 is the first version to use this option so we must add it. |
| 32 | $give_version = '1.0'; |
| 33 | } |
| 34 | |
| 35 | switch ( true ) { |
| 36 | |
| 37 | case version_compare( $give_version, '1.6', '<' ) : |
| 38 | give_v16_upgrades(); |
| 39 | $did_upgrade = true; |
| 40 | |
| 41 | case version_compare( $give_version, '1.7', '<' ) : |
| 42 | give_v17_upgrades(); |
| 43 | $did_upgrade = true; |
| 44 | |
| 45 | case version_compare( $give_version, '1.8', '<' ) : |
| 46 | give_v18_upgrades(); |
| 47 | $did_upgrade = true; |
| 48 | |
| 49 | case version_compare( $give_version, '1.8.7', '<' ) : |
| 50 | give_v187_upgrades(); |
| 51 | $did_upgrade = true; |
| 52 | |
| 53 | case version_compare( $give_version, '1.8.8', '<' ) : |
| 54 | give_v188_upgrades(); |
| 55 | $did_upgrade = true; |
| 56 | |
| 57 | case version_compare( $give_version, '1.8.9', '<' ) : |
| 58 | give_v189_upgrades(); |
| 59 | $did_upgrade = true; |
| 60 | |
| 61 | case version_compare( $give_version, '1.8.12', '<' ) : |
| 62 | give_v1812_upgrades(); |
| 63 | $did_upgrade = true; |
| 64 | |
| 65 | case version_compare( $give_version, '1.8.13', '<' ) : |
| 66 | give_v1813_upgrades(); |
| 67 | $did_upgrade = true; |
| 68 | |
| 69 | case version_compare( $give_version, '1.8.17', '<' ) : |
| 70 | give_v1817_upgrades(); |
| 71 | $did_upgrade = true; |
| 72 | |
| 73 | case version_compare( $give_version, '1.8.18', '<' ) : |
| 74 | give_v1818_upgrades(); |
| 75 | $did_upgrade = true; |
| 76 | |
| 77 | case version_compare( $give_version, '2.0', '<' ) : |
| 78 | give_v20_upgrades(); |
| 79 | $did_upgrade = true; |
| 80 | |
| 81 | case version_compare( $give_version, '2.0.1', '<' ) : |
| 82 | // Do nothing on fresh install. |
| 83 | if ( ! doing_action( 'give_upgrades' ) ) { |
| 84 | give_v201_create_tables(); |
| 85 | Give_Updates::get_instance()->__health_background_update( Give_Updates::get_instance() ); |
| 86 | Give_Updates::$background_updater->dispatch(); |
| 87 | } |
| 88 | |
| 89 | $did_upgrade = true; |
| 90 | |
| 91 | case version_compare( $give_version, '2.0.2', '<' ) : |
| 92 | // Remove 2.0.1 update to rerun on 2.0.2 |
| 93 | $completed_upgrades = give_get_completed_upgrades(); |
| 94 | $v201_updates = array( |
| 95 | 'v201_upgrades_payment_metadata', |
| 96 | 'v201_add_missing_donors', |
| 97 | 'v201_move_metadata_into_new_table', |
| 98 | 'v201_logs_upgrades', |
| 99 | ); |
| 100 | |
| 101 | foreach ( $v201_updates as $v201_update ) { |
| 102 | if ( in_array( $v201_update, $completed_upgrades ) ) { |
| 103 | unset( $completed_upgrades[ array_search( $v201_update, $completed_upgrades ) ] ); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | update_option( 'give_completed_upgrades', $completed_upgrades ); |
| 108 | |
| 109 | // Do nothing on fresh install. |
| 110 | if ( ! doing_action( 'give_upgrades' ) ) { |
| 111 | give_v201_create_tables(); |
| 112 | Give_Updates::get_instance()->__health_background_update( Give_Updates::get_instance() ); |
| 113 | Give_Updates::$background_updater->dispatch(); |
| 114 | } |
| 115 | |
| 116 | $did_upgrade = true; |
| 117 | |
| 118 | case version_compare( $give_version, '2.0.3', '<' ) : |
| 119 | give_v203_upgrades(); |
| 120 | $did_upgrade = true; |
| 121 | } |
| 122 | |
| 123 | if ( $did_upgrade ) { |
| 124 | update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | add_action( 'admin_init', 'give_do_automatic_upgrades' ); |
| 129 | add_action( 'give_upgrades', 'give_do_automatic_upgrades' ); |
| 130 | |
| 131 | /** |
| 132 | * Display Upgrade Notices. |
| 133 | * |
| 134 | * IMPORTANT: ALSO UPDATE INSTALL.PHP WITH THE ID OF THE UPGRADE ROUTINE SO IT DOES NOT AFFECT NEW INSTALLS. |
| 135 | * |
| 136 | * @since 1.0 |
| 137 | * @since 1.8.12 Update new update process code. |
| 138 | * |
| 139 | * @param Give_Updates $give_updates |
| 140 | * |
| 141 | * @return void |
| 142 | */ |
| 143 | function give_show_upgrade_notices( $give_updates ) { |
| 144 | // v1.3.2 Upgrades |
| 145 | $give_updates->register( |
| 146 | array( |
| 147 | 'id' => 'upgrade_give_payment_customer_id', |
| 148 | 'version' => '1.3.2', |
| 149 | 'callback' => 'give_v132_upgrade_give_payment_customer_id', |
| 150 | ) |
| 151 | ); |
| 152 | |
| 153 | // v1.3.4 Upgrades ensure the user has gone through 1.3.4. |
| 154 | $give_updates->register( |
| 155 | array( |
| 156 | 'id' => 'upgrade_give_offline_status', |
| 157 | 'depend' => 'upgrade_give_payment_customer_id', |
| 158 | 'version' => '1.3.4', |
| 159 | 'callback' => 'give_v134_upgrade_give_offline_status', |
| 160 | ) |
| 161 | ); |
| 162 | |
| 163 | // v1.8 form metadata upgrades. |
| 164 | $give_updates->register( |
| 165 | array( |
| 166 | 'id' => 'v18_upgrades_form_metadata', |
| 167 | 'version' => '1.8', |
| 168 | 'callback' => 'give_v18_upgrades_form_metadata', |
| 169 | ) |
| 170 | ); |
| 171 | |
| 172 | // v1.8.9 Upgrades |
| 173 | $give_updates->register( |
| 174 | array( |
| 175 | 'id' => 'v189_upgrades_levels_post_meta', |
| 176 | 'version' => '1.8.9', |
| 177 | 'callback' => 'give_v189_upgrades_levels_post_meta_callback', |
| 178 | ) |
| 179 | ); |
| 180 | |
| 181 | // v1.8.12 Upgrades |
| 182 | $give_updates->register( |
| 183 | array( |
| 184 | 'id' => 'v1812_update_amount_values', |
| 185 | 'version' => '1.8.12', |
| 186 | 'callback' => 'give_v1812_update_amount_values_callback', |
| 187 | ) |
| 188 | ); |
| 189 | |
| 190 | // v1.8.12 Upgrades |
| 191 | $give_updates->register( |
| 192 | array( |
| 193 | 'id' => 'v1812_update_donor_purchase_values', |
| 194 | 'version' => '1.8.12', |
| 195 | 'callback' => 'give_v1812_update_donor_purchase_value_callback', |
| 196 | ) |
| 197 | ); |
| 198 | |
| 199 | // v1.8.13 Upgrades for donor |
| 200 | $give_updates->register( |
| 201 | array( |
| 202 | 'id' => 'v1813_update_donor_user_roles', |
| 203 | 'version' => '1.8.13', |
| 204 | 'callback' => 'give_v1813_update_donor_user_roles_callback', |
| 205 | ) |
| 206 | ); |
| 207 | |
| 208 | // v1.8.17 Upgrades for donations. |
| 209 | $give_updates->register( array( |
| 210 | 'id' => 'v1817_update_donation_iranian_currency_code', |
| 211 | 'version' => '1.8.17', |
| 212 | 'callback' => 'give_v1817_update_donation_iranian_currency_code', |
| 213 | ) ); |
| 214 | |
| 215 | // v1.8.17 Upgrades for cleanup of user roles. |
| 216 | $give_updates->register( array( |
| 217 | 'id' => 'v1817_cleanup_user_roles', |
| 218 | 'version' => '1.8.17', |
| 219 | 'callback' => 'give_v1817_cleanup_user_roles', |
| 220 | ) ); |
| 221 | |
| 222 | // v1.8.18 Upgrades for assigning custom amount to existing set donations. |
| 223 | $give_updates->register( array( |
| 224 | 'id' => 'v1818_assign_custom_amount_set_donation', |
| 225 | 'version' => '1.8.18', |
| 226 | 'callback' => 'give_v1818_assign_custom_amount_set_donation', |
| 227 | ) ); |
| 228 | |
| 229 | // v1.8.18 Cleanup the Give Worker Role Caps. |
| 230 | $give_updates->register( array( |
| 231 | 'id' => 'v1818_give_worker_role_cleanup', |
| 232 | 'version' => '1.8.18', |
| 233 | 'callback' => 'give_v1818_give_worker_role_cleanup', |
| 234 | ) ); |
| 235 | |
| 236 | // v2.0.0 Upgrades |
| 237 | $give_updates->register( |
| 238 | array( |
| 239 | 'id' => 'v20_upgrades_form_metadata', |
| 240 | 'version' => '2.0.0', |
| 241 | 'callback' => 'give_v20_upgrades_form_metadata_callback', |
| 242 | ) |
| 243 | ); |
| 244 | |
| 245 | // v2.0.0 User Address Upgrades |
| 246 | $give_updates->register( |
| 247 | array( |
| 248 | 'id' => 'v20_upgrades_user_address', |
| 249 | 'version' => '2.0.0', |
| 250 | 'callback' => 'give_v20_upgrades_user_address', |
| 251 | ) |
| 252 | ); |
| 253 | |
| 254 | // v2.0.0 Upgrades |
| 255 | $give_updates->register( |
| 256 | array( |
| 257 | 'id' => 'v20_upgrades_payment_metadata', |
| 258 | 'version' => '2.0.0', |
| 259 | 'callback' => 'give_v20_upgrades_payment_metadata_callback', |
| 260 | ) |
| 261 | ); |
| 262 | |
| 263 | // v2.0.0 Upgrades |
| 264 | $give_updates->register( |
| 265 | array( |
| 266 | 'id' => 'v20_logs_upgrades', |
| 267 | 'version' => '2.0.0', |
| 268 | 'callback' => 'give_v20_logs_upgrades_callback', |
| 269 | |
| 270 | ) |
| 271 | ); |
| 272 | |
| 273 | // v2.0.0 Donor Name Upgrades |
| 274 | $give_updates->register( |
| 275 | array( |
| 276 | 'id' => 'v20_upgrades_donor_name', |
| 277 | 'version' => '2.0.0', |
| 278 | 'callback' => 'give_v20_upgrades_donor_name', |
| 279 | ) |
| 280 | ); |
| 281 | |
| 282 | // v2.0.0 Upgrades |
| 283 | $give_updates->register( |
| 284 | array( |
| 285 | 'id' => 'v20_move_metadata_into_new_table', |
| 286 | 'version' => '2.0.0', |
| 287 | 'callback' => 'give_v20_move_metadata_into_new_table_callback', |
| 288 | 'depend' => array( 'v20_upgrades_payment_metadata', 'v20_upgrades_form_metadata' ), |
| 289 | ) |
| 290 | ); |
| 291 | |
| 292 | // v2.0.0 Upgrades |
| 293 | $give_updates->register( |
| 294 | array( |
| 295 | 'id' => 'v20_rename_donor_tables', |
| 296 | 'version' => '2.0.0', |
| 297 | 'callback' => 'give_v20_rename_donor_tables_callback', |
| 298 | 'depend' => array( |
| 299 | 'v20_move_metadata_into_new_table', |
| 300 | 'v20_logs_upgrades', |
| 301 | 'v20_upgrades_form_metadata', |
| 302 | 'v20_upgrades_payment_metadata', |
| 303 | 'v20_upgrades_user_address', |
| 304 | 'v20_upgrades_donor_name', |
| 305 | ), |
| 306 | ) |
| 307 | ); |
| 308 | |
| 309 | |
| 310 | // v2.0.1 Upgrades |
| 311 | $give_updates->register( |
| 312 | array( |
| 313 | 'id' => 'v201_upgrades_payment_metadata', |
| 314 | 'version' => '2.0.1', |
| 315 | 'callback' => 'give_v201_upgrades_payment_metadata_callback', |
| 316 | ) |
| 317 | ); |
| 318 | |
| 319 | // v2.0.1 Upgrades |
| 320 | $give_updates->register( |
| 321 | array( |
| 322 | 'id' => 'v201_add_missing_donors', |
| 323 | 'version' => '2.0.1', |
| 324 | 'callback' => 'give_v201_add_missing_donors_callback', |
| 325 | ) |
| 326 | ); |
| 327 | |
| 328 | // Run v2.0.0 Upgrades again in 2.0.1 |
| 329 | $give_updates->register( |
| 330 | array( |
| 331 | 'id' => 'v201_move_metadata_into_new_table', |
| 332 | 'version' => '2.0.1', |
| 333 | 'callback' => 'give_v201_move_metadata_into_new_table_callback', |
| 334 | 'depend' => array( 'v201_upgrades_payment_metadata', 'v201_add_missing_donors' ), |
| 335 | ) |
| 336 | ); |
| 337 | |
| 338 | // Run v2.0.0 Upgrades again in 2.0.1 |
| 339 | $give_updates->register( |
| 340 | array( |
| 341 | 'id' => 'v201_logs_upgrades', |
| 342 | 'version' => '2.0.1', |
| 343 | 'callback' => 'give_v201_logs_upgrades_callback', |
| 344 | ) |
| 345 | ); |
| 346 | |
| 347 | // v2.1 Verify Form Status Upgrade. |
| 348 | $give_updates->register( |
| 349 | array( |
| 350 | 'id' => 'v210_verify_form_status_upgrades', |
| 351 | 'version' => '2.1.0', |
| 352 | 'callback' => 'give_v210_verify_form_status_upgrades_callback', |
| 353 | ) |
| 354 | ); |
| 355 | |
| 356 | // v2.1.3 Delete non attached donation meta. |
| 357 | $give_updates->register( |
| 358 | array( |
| 359 | 'id' => 'v213_delete_donation_meta', |
| 360 | 'version' => '2.1.3', |
| 361 | 'callback' => 'give_v213_delete_donation_meta_callback', |
| 362 | 'depends' => array( 'v201_move_metadata_into_new_table' ) |
| 363 | ) |
| 364 | ); |
| 365 | |
| 366 | // v2.1.5 Add additional capability to the give_manager role. |
| 367 | $give_updates->register( |
| 368 | array( |
| 369 | 'id' => 'v215_update_donor_user_roles', |
| 370 | 'version' => '2.1.5', |
| 371 | 'callback' => 'give_v215_update_donor_user_roles_callback', |
| 372 | ) |
| 373 | ); |
| 374 | |
| 375 | } |
| 376 | |
| 377 | add_action( 'give_register_updates', 'give_show_upgrade_notices' ); |
| 378 | |
| 379 | /** |
| 380 | * Triggers all upgrade functions |
| 381 | * |
| 382 | * This function is usually triggered via AJAX |
| 383 | * |
| 384 | * @since 1.0 |
| 385 | * @return void |
| 386 | */ |
| 387 | function give_trigger_upgrades() { |
| 388 | |
| 389 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
| 390 | wp_die( esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( |
| 391 | 'response' => 403, |
| 392 | ) ); |
| 393 | } |
| 394 | |
| 395 | $give_version = get_option( 'give_version' ); |
| 396 | |
| 397 | if ( ! $give_version ) { |
| 398 | // 1.0 is the first version to use this option so we must add it. |
| 399 | $give_version = '1.0'; |
| 400 | add_option( 'give_version', $give_version ); |
| 401 | } |
| 402 | |
| 403 | update_option( 'give_version', GIVE_VERSION ); |
| 404 | delete_option( 'give_doing_upgrade' ); |
| 405 | |
| 406 | if ( DOING_AJAX ) { |
| 407 | die( 'complete' ); |
| 408 | } // End if(). |
| 409 | } |
| 410 | |
| 411 | add_action( 'wp_ajax_give_trigger_upgrades', 'give_trigger_upgrades' ); |
| 412 | |
| 413 | |
| 414 | /** |
| 415 | * Upgrades the |
| 416 | * |
| 417 | * Standardizes the discrepancies between two metakeys `_give_payment_customer_id` and `_give_payment_donor_id` |
| 418 | * |
| 419 | * @since 1.3.2 |
| 420 | */ |
| 421 | function give_v132_upgrade_give_payment_customer_id() { |
| 422 | global $wpdb; |
| 423 | |
| 424 | /* @var Give_Updates $give_updates */ |
| 425 | $give_updates = Give_Updates::get_instance(); |
| 426 | |
| 427 | // UPDATE DB METAKEYS. |
| 428 | $sql = "UPDATE $wpdb->postmeta SET meta_key = '_give_payment_customer_id' WHERE meta_key = '_give_payment_donor_id'"; |
| 429 | $query = $wpdb->query( $sql ); |
| 430 | |
| 431 | $give_updates->percentage = 100; |
| 432 | give_set_upgrade_complete( 'upgrade_give_payment_customer_id' ); |
| 433 | } |
| 434 | |
| 435 | |
| 436 | /** |
| 437 | * Upgrades the Offline Status |
| 438 | * |
| 439 | * Reverses the issue where offline donations in "pending" status where inappropriately marked as abandoned |
| 440 | * |
| 441 | * @since 1.3.4 |
| 442 | */ |
| 443 | function give_v134_upgrade_give_offline_status() { |
| 444 | global $wpdb; |
| 445 | |
| 446 | /* @var Give_Updates $give_updates */ |
| 447 | $give_updates = Give_Updates::get_instance(); |
| 448 | |
| 449 | // Get abandoned offline payments. |
| 450 | $select = "SELECT ID FROM $wpdb->posts p "; |
| 451 | $join = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id "; |
| 452 | $where = "WHERE p.post_type = 'give_payment' "; |
| 453 | $where .= "AND ( p.post_status = 'abandoned' )"; |
| 454 | $where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )"; |
| 455 | |
| 456 | $sql = $select . $join . $where; |
| 457 | $found_payments = $wpdb->get_col( $sql ); |
| 458 | |
| 459 | foreach ( $found_payments as $payment ) { |
| 460 | |
| 461 | // Only change ones marked abandoned since our release last week because the admin may have marked some abandoned themselves. |
| 462 | $modified_time = get_post_modified_time( 'U', false, $payment ); |
| 463 | |
| 464 | // 1450124863 = 12/10/2015 20:42:25. |
| 465 | if ( $modified_time >= 1450124863 ) { |
| 466 | |
| 467 | give_update_payment_status( $payment, 'pending' ); |
| 468 | |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | $give_updates->percentage = 100; |
| 473 | give_set_upgrade_complete( 'upgrade_give_offline_status' ); |
| 474 | } |
| 475 | |
| 476 | |
| 477 | /** |
| 478 | * Cleanup User Roles |
| 479 | * |
| 480 | * This upgrade routine removes unused roles and roles with typos |
| 481 | * |
| 482 | * @since 1.5.2 |
| 483 | */ |
| 484 | function give_v152_cleanup_users() { |
| 485 | |
| 486 | $give_version = get_option( 'give_version' ); |
| 487 | |
| 488 | if ( ! $give_version ) { |
| 489 | // 1.0 is the first version to use this option so we must add it. |
| 490 | $give_version = '1.0'; |
| 491 | } |
| 492 | |
| 493 | $give_version = preg_replace( '/[^0-9.].*/', '', $give_version ); |
| 494 | |
| 495 | // v1.5.2 Upgrades |
| 496 | if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) { |
| 497 | |
| 498 | // Delete all caps with "ss". |
| 499 | // Also delete all unused "campaign" roles. |
| 500 | $delete_caps = array( |
| 501 | 'delete_give_formss', |
| 502 | 'delete_others_give_formss', |
| 503 | 'delete_private_give_formss', |
| 504 | 'delete_published_give_formss', |
| 505 | 'read_private_forms', |
| 506 | 'edit_give_formss', |
| 507 | 'edit_others_give_formss', |
| 508 | 'edit_private_give_formss', |
| 509 | 'edit_published_give_formss', |
| 510 | 'publish_give_formss', |
| 511 | 'read_private_give_formss', |
| 512 | 'assign_give_campaigns_terms', |
| 513 | 'delete_give_campaigns', |
| 514 | 'delete_give_campaigns_terms', |
| 515 | 'delete_give_campaignss', |
| 516 | 'delete_others_give_campaignss', |
| 517 | 'delete_private_give_campaignss', |
| 518 | 'delete_published_give_campaignss', |
| 519 | 'edit_give_campaigns', |
| 520 | 'edit_give_campaigns_terms', |
| 521 | 'edit_give_campaignss', |
| 522 | 'edit_others_give_campaignss', |
| 523 | 'edit_private_give_campaignss', |
| 524 | 'edit_published_give_campaignss', |
| 525 | 'manage_give_campaigns_terms', |
| 526 | 'publish_give_campaignss', |
| 527 | 'read_give_campaigns', |
| 528 | 'read_private_give_campaignss', |
| 529 | 'view_give_campaigns_stats', |
| 530 | 'delete_give_paymentss', |
| 531 | 'delete_others_give_paymentss', |
| 532 | 'delete_private_give_paymentss', |
| 533 | 'delete_published_give_paymentss', |
| 534 | 'edit_give_paymentss', |
| 535 | 'edit_others_give_paymentss', |
| 536 | 'edit_private_give_paymentss', |
| 537 | 'edit_published_give_paymentss', |
| 538 | 'publish_give_paymentss', |
| 539 | 'read_private_give_paymentss', |
| 540 | ); |
| 541 | |
| 542 | global $wp_roles; |
| 543 | foreach ( $delete_caps as $cap ) { |
| 544 | foreach ( array_keys( $wp_roles->roles ) as $role ) { |
| 545 | $wp_roles->remove_cap( $role, $cap ); |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | // Create Give plugin roles. |
| 550 | $roles = new Give_Roles(); |
| 551 | $roles->add_roles(); |
| 552 | $roles->add_caps(); |
| 553 | |
| 554 | // The Update Ran. |
| 555 | update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ) ); |
| 556 | give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' ); |
| 557 | delete_option( 'give_doing_upgrade' ); |
| 558 | |
| 559 | }// End if(). |
| 560 | |
| 561 | } |
| 562 | |
| 563 | add_action( 'admin_init', 'give_v152_cleanup_users' ); |
| 564 | |
| 565 | /** |
| 566 | * 1.6 Upgrade routine to create the customer meta table. |
| 567 | * |
| 568 | * @since 1.6 |
| 569 | * @return void |
| 570 | */ |
| 571 | function give_v16_upgrades() { |
| 572 | // Create the donor databases. |
| 573 | $donors_db = new Give_DB_Donors(); |
| 574 | $donors_db->create_table(); |
| 575 | $donor_meta = new Give_DB_Donor_Meta(); |
| 576 | $donor_meta->create_table(); |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * 1.7 Upgrades. |
| 581 | * |
| 582 | * a. Update license api data for plugin addons. |
| 583 | * b. Cleanup user roles. |
| 584 | * |
| 585 | * @since 1.7 |
| 586 | * @return void |
| 587 | */ |
| 588 | function give_v17_upgrades() { |
| 589 | // Upgrade license data. |
| 590 | give_v17_upgrade_addon_license_data(); |
| 591 | give_v17_cleanup_roles(); |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * Upgrade license data |
| 596 | * |
| 597 | * @since 1.7 |
| 598 | */ |
| 599 | function give_v17_upgrade_addon_license_data() { |
| 600 | $give_options = give_get_settings(); |
| 601 | |
| 602 | $api_url = 'https://givewp.com/give-sl-api/'; |
| 603 | |
| 604 | // Get addons license key. |
| 605 | $addons = array(); |
| 606 | foreach ( $give_options as $key => $value ) { |
| 607 | if ( false !== strpos( $key, '_license_key' ) ) { |
| 608 | $addons[ $key ] = $value; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // Bailout: We do not have any addon license data to upgrade. |
| 613 | if ( empty( $addons ) ) { |
| 614 | return false; |
| 615 | } |
| 616 | |
| 617 | foreach ( $addons as $key => $addon_license ) { |
| 618 | |
| 619 | // Get addon shortname. |
| 620 | $shortname = str_replace( '_license_key', '', $key ); |
| 621 | |
| 622 | // Addon license option name. |
| 623 | $addon_license_option_name = $shortname . '_license_active'; |
| 624 | |
| 625 | // bailout if license is empty. |
| 626 | if ( empty( $addon_license ) ) { |
| 627 | delete_option( $addon_license_option_name ); |
| 628 | continue; |
| 629 | } |
| 630 | |
| 631 | // Get addon name. |
| 632 | $addon_name = array(); |
| 633 | $addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) ); |
| 634 | foreach ( $addon_name_parts as $name_part ) { |
| 635 | |
| 636 | // Fix addon name |
| 637 | switch ( $name_part ) { |
| 638 | case 'authorizenet' : |
| 639 | $name_part = 'authorize.net'; |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | $addon_name[] = ucfirst( $name_part ); |
| 644 | } |
| 645 | |
| 646 | $addon_name = implode( ' ', $addon_name ); |
| 647 | |
| 648 | // Data to send to the API. |
| 649 | $api_params = array( |
| 650 | 'edd_action' => 'activate_license', // never change from "edd_" to "give_"! |
| 651 | 'license' => $addon_license, |
| 652 | 'item_name' => urlencode( $addon_name ), |
| 653 | 'url' => home_url(), |
| 654 | ); |
| 655 | |
| 656 | // Call the API. |
| 657 | $response = wp_remote_post( |
| 658 | $api_url, |
| 659 | array( |
| 660 | 'timeout' => 15, |
| 661 | 'sslverify' => false, |
| 662 | 'body' => $api_params, |
| 663 | ) |
| 664 | ); |
| 665 | |
| 666 | // Make sure there are no errors. |
| 667 | if ( is_wp_error( $response ) ) { |
| 668 | delete_option( $addon_license_option_name ); |
| 669 | continue; |
| 670 | } |
| 671 | |
| 672 | // Tell WordPress to look for updates. |
| 673 | set_site_transient( 'update_plugins', null ); |
| 674 | |
| 675 | // Decode license data. |
| 676 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 677 | update_option( $addon_license_option_name, $license_data ); |
| 678 | }// End foreach(). |
| 679 | } |
| 680 | |
| 681 | |
| 682 | /** |
| 683 | * Cleanup User Roles. |
| 684 | * |
| 685 | * This upgrade routine removes unused roles and roles with typos. |
| 686 | * |
| 687 | * @since 1.7 |
| 688 | */ |
| 689 | function give_v17_cleanup_roles() { |
| 690 | |
| 691 | // Delete all caps with "_give_forms_" and "_give_payments_". |
| 692 | // These roles have no usage; the proper is singular. |
| 693 | $delete_caps = array( |
| 694 | 'view_give_forms_stats', |
| 695 | 'delete_give_forms_terms', |
| 696 | 'assign_give_forms_terms', |
| 697 | 'edit_give_forms_terms', |
| 698 | 'manage_give_forms_terms', |
| 699 | 'view_give_payments_stats', |
| 700 | 'manage_give_payments_terms', |
| 701 | 'edit_give_payments_terms', |
| 702 | 'assign_give_payments_terms', |
| 703 | 'delete_give_payments_terms', |
| 704 | ); |
| 705 | |
| 706 | global $wp_roles; |
| 707 | foreach ( $delete_caps as $cap ) { |
| 708 | foreach ( array_keys( $wp_roles->roles ) as $role ) { |
| 709 | $wp_roles->remove_cap( $role, $cap ); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // Set roles again. |
| 714 | $roles = new Give_Roles(); |
| 715 | $roles->add_roles(); |
| 716 | $roles->add_caps(); |
| 717 | |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * 1.8 Upgrades. |
| 722 | * |
| 723 | * a. Upgrade checkbox settings to radio button settings. |
| 724 | * a. Update form meta for new metabox settings. |
| 725 | * |
| 726 | * @since 1.8 |
| 727 | * @return void |
| 728 | */ |
| 729 | function give_v18_upgrades() { |
| 730 | // Upgrade checkbox settings to radio button settings. |
| 731 | give_v18_upgrades_core_setting(); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * Upgrade core settings. |
| 736 | * |
| 737 | * @since 1.8 |
| 738 | * @return void |
| 739 | */ |
| 740 | function give_v18_upgrades_core_setting() { |
| 741 | // Core settings which changes from checkbox to radio. |
| 742 | $core_setting_names = array_merge( |
| 743 | array_keys( give_v18_renamed_core_settings() ), |
| 744 | array( |
| 745 | 'uninstall_on_delete', |
| 746 | 'scripts_footer', |
| 747 | 'test_mode', |
| 748 | 'email_access', |
| 749 | 'terms', |
| 750 | 'give_offline_donation_enable_billing_fields', |
| 751 | ) |
| 752 | ); |
| 753 | |
| 754 | // Bailout: If not any setting define. |
| 755 | if ( $give_settings = get_option( 'give_settings' ) ) { |
| 756 | |
| 757 | $setting_changed = false; |
| 758 | |
| 759 | // Loop: check each setting field. |
| 760 | foreach ( $core_setting_names as $setting_name ) { |
| 761 | // New setting name. |
| 762 | $new_setting_name = preg_replace( '/^(enable_|disable_)/', '', $setting_name ); |
| 763 | |
| 764 | // Continue: If setting already set. |
| 765 | if ( |
| 766 | array_key_exists( $new_setting_name, $give_settings ) |
| 767 | && in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) ) |
| 768 | ) { |
| 769 | continue; |
| 770 | } |
| 771 | |
| 772 | // Set checkbox value to radio value. |
| 773 | $give_settings[ $setting_name ] = ( ! empty( $give_settings[ $setting_name ] ) && 'on' === $give_settings[ $setting_name ] ? 'enabled' : 'disabled' ); |
| 774 | |
| 775 | // @see https://github.com/WordImpress/Give/issues/1063. |
| 776 | if ( false !== strpos( $setting_name, 'disable_' ) ) { |
| 777 | |
| 778 | $give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'disabled' : 'enabled' ); |
| 779 | } elseif ( false !== strpos( $setting_name, 'enable_' ) ) { |
| 780 | |
| 781 | $give_settings[ $new_setting_name ] = ( give_is_setting_enabled( $give_settings[ $setting_name ] ) ? 'enabled' : 'disabled' ); |
| 782 | } |
| 783 | |
| 784 | // Tell bot to update core setting to db. |
| 785 | if ( ! $setting_changed ) { |
| 786 | $setting_changed = true; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | // Update setting only if they changed. |
| 791 | if ( $setting_changed ) { |
| 792 | update_option( 'give_settings', $give_settings ); |
| 793 | } |
| 794 | }// End if(). |
| 795 | |
| 796 | give_set_upgrade_complete( 'v18_upgrades_core_setting' ); |
| 797 | } |
| 798 | |
| 799 | /** |
| 800 | * Upgrade form metadata for new metabox settings. |
| 801 | * |
| 802 | * @since 1.8 |
| 803 | * @return void |
| 804 | */ |
| 805 | function give_v18_upgrades_form_metadata() { |
| 806 | /* @var Give_Updates $give_updates */ |
| 807 | $give_updates = Give_Updates::get_instance(); |
| 808 | |
| 809 | // form query |
| 810 | $forms = new WP_Query( array( |
| 811 | 'paged' => $give_updates->step, |
| 812 | 'status' => 'any', |
| 813 | 'order' => 'ASC', |
| 814 | 'post_type' => 'give_forms', |
| 815 | 'posts_per_page' => 20, |
| 816 | ) |
| 817 | ); |
| 818 | |
| 819 | if ( $forms->have_posts() ) { |
| 820 | $give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) ); |
| 821 | |
| 822 | while ( $forms->have_posts() ) { |
| 823 | $forms->the_post(); |
| 824 | |
| 825 | // Form content. |
| 826 | // Note in version 1.8 display content setting split into display content and content placement setting. |
| 827 | // You can delete _give_content_option in future. |
| 828 | $show_content = give_get_meta( get_the_ID(), '_give_content_option', true ); |
| 829 | if ( $show_content && ! give_get_meta( get_the_ID(), '_give_display_content', true ) ) { |
| 830 | $field_value = ( 'none' !== $show_content ? 'enabled' : 'disabled' ); |
| 831 | give_update_meta( get_the_ID(), '_give_display_content', $field_value ); |
| 832 | |
| 833 | $field_value = ( 'none' !== $show_content ? $show_content : 'give_pre_form' ); |
| 834 | give_update_meta( get_the_ID(), '_give_content_placement', $field_value ); |
| 835 | } |
| 836 | |
| 837 | // "Disable" Guest Donation. Checkbox. |
| 838 | // See: https://github.com/WordImpress/Give/issues/1470. |
| 839 | $guest_donation = give_get_meta( get_the_ID(), '_give_logged_in_only', true ); |
| 840 | $guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' ); |
| 841 | give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval ); |
| 842 | |
| 843 | // Offline Donations. |
| 844 | // See: https://github.com/WordImpress/Give/issues/1579. |
| 845 | $offline_donation = give_get_meta( get_the_ID(), '_give_customize_offline_donations', true ); |
| 846 | if ( 'no' === $offline_donation ) { |
| 847 | $offline_donation_newval = 'global'; |
| 848 | } elseif ( 'yes' === $offline_donation ) { |
| 849 | $offline_donation_newval = 'enabled'; |
| 850 | } else { |
| 851 | $offline_donation_newval = 'disabled'; |
| 852 | } |
| 853 | give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval ); |
| 854 | |
| 855 | // Convert yes/no setting field to enabled/disabled. |
| 856 | $form_radio_settings = array( |
| 857 | // Custom Amount. |
| 858 | '_give_custom_amount', |
| 859 | |
| 860 | // Donation Gaol. |
| 861 | '_give_goal_option', |
| 862 | |
| 863 | // Close Form. |
| 864 | '_give_close_form_when_goal_achieved', |
| 865 | |
| 866 | // Term & conditions. |
| 867 | '_give_terms_option', |
| 868 | |
| 869 | // Billing fields. |
| 870 | '_give_offline_donation_enable_billing_fields_single', |
| 871 | ); |
| 872 | |
| 873 | foreach ( $form_radio_settings as $meta_key ) { |
| 874 | // Get value. |
| 875 | $field_value = give_get_meta( get_the_ID(), $meta_key, true ); |
| 876 | |
| 877 | // Convert meta value only if it is in yes/no/none. |
| 878 | if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) { |
| 879 | |
| 880 | $field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' ); |
| 881 | give_update_meta( get_the_ID(), $meta_key, $field_value ); |
| 882 | } |
| 883 | } |
| 884 | }// End while(). |
| 885 | |
| 886 | wp_reset_postdata(); |
| 887 | |
| 888 | } else { |
| 889 | // No more forms found, finish up. |
| 890 | give_set_upgrade_complete( 'v18_upgrades_form_metadata' ); |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | |
| 895 | /** |
| 896 | * Get list of core setting renamed in version 1.8. |
| 897 | * |
| 898 | * @since 1.8 |
| 899 | * @return array |
| 900 | */ |
| 901 | function give_v18_renamed_core_settings() { |
| 902 | return array( |
| 903 | 'disable_paypal_verification' => 'paypal_verification', |
| 904 | 'disable_css' => 'css', |
| 905 | 'disable_welcome' => 'welcome', |
| 906 | 'disable_forms_singular' => 'forms_singular', |
| 907 | 'disable_forms_archives' => 'forms_archives', |
| 908 | 'disable_forms_excerpt' => 'forms_excerpt', |
| 909 | 'disable_form_featured_img' => 'form_featured_img', |
| 910 | 'disable_form_sidebar' => 'form_sidebar', |
| 911 | 'disable_admin_notices' => 'admin_notices', |
| 912 | 'disable_the_content_filter' => 'the_content_filter', |
| 913 | 'enable_floatlabels' => 'floatlabels', |
| 914 | 'enable_categories' => 'categories', |
| 915 | 'enable_tags' => 'tags', |
| 916 | ); |
| 917 | } |
| 918 | |
| 919 | |
| 920 | /** |
| 921 | * Upgrade core settings. |
| 922 | * |
| 923 | * @since 1.8.7 |
| 924 | * @return void |
| 925 | */ |
| 926 | function give_v187_upgrades() { |
| 927 | global $wpdb; |
| 928 | |
| 929 | /** |
| 930 | * Upgrade 1: Remove stat and cache transients. |
| 931 | */ |
| 932 | $cached_options = $wpdb->get_col( |
| 933 | $wpdb->prepare( |
| 934 | " |
| 935 | SELECT * |
| 936 | FROM {$wpdb->options} |
| 937 | WHERE ( |
| 938 | option_name LIKE %s |
| 939 | OR option_name LIKE %s |
| 940 | OR option_name LIKE %s |
| 941 | OR option_name LIKE %s |
| 942 | OR option_name LIKE %s |
| 943 | OR option_name LIKE %s |
| 944 | OR option_name LIKE %s |
| 945 | OR option_name LIKE %s |
| 946 | OR option_name LIKE %s |
| 947 | OR option_name LIKE %s |
| 948 | OR option_name LIKE %s |
| 949 | OR option_name LIKE %s |
| 950 | OR option_name LIKE %s |
| 951 | ) |
| 952 | ", |
| 953 | array( |
| 954 | '%_transient_give_stats_%', |
| 955 | 'give_cache%', |
| 956 | '%_transient_give_add_ons_feed%', |
| 957 | '%_transient__give_ajax_works' . |
| 958 | '%_transient_give_total_api_keys%', |
| 959 | '%_transient_give_i18n_give_promo_hide%', |
| 960 | '%_transient_give_contributors%', |
| 961 | '%_transient_give_estimated_monthly_stats%', |
| 962 | '%_transient_give_earnings_total%', |
| 963 | '%_transient_give_i18n_give_%', |
| 964 | '%_transient__give_installed%', |
| 965 | '%_transient__give_activation_redirect%', |
| 966 | '%_transient__give_hide_license_notices_shortly_%', |
| 967 | '%give_income_total%', |
| 968 | ) |
| 969 | ), |
| 970 | 1 |
| 971 | ); |
| 972 | |
| 973 | // User related transients. |
| 974 | $user_apikey_options = $wpdb->get_results( |
| 975 | $wpdb->prepare( |
| 976 | "SELECT user_id, meta_key |
| 977 | FROM $wpdb->usermeta |
| 978 | WHERE meta_value=%s", |
| 979 | 'give_user_public_key' |
| 980 | ), |
| 981 | ARRAY_A |
| 982 | ); |
| 983 | |
| 984 | if ( ! empty( $user_apikey_options ) ) { |
| 985 | foreach ( $user_apikey_options as $user ) { |
| 986 | $cached_options[] = '_transient_' . md5( 'give_api_user_' . $user['meta_key'] ); |
| 987 | $cached_options[] = '_transient_' . md5( 'give_api_user_public_key' . $user['user_id'] ); |
| 988 | $cached_options[] = '_transient_' . md5( 'give_api_user_secret_key' . $user['user_id'] ); |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | if ( ! empty( $cached_options ) ) { |
| 993 | foreach ( $cached_options as $option ) { |
| 994 | switch ( true ) { |
| 995 | case ( false !== strpos( $option, 'transient' ) ): |
| 996 | $option = str_replace( '_transient_', '', $option ); |
| 997 | delete_transient( $option ); |
| 998 | break; |
| 999 | |
| 1000 | default: |
| 1001 | delete_option( $option ); |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * Update Capabilities for Give_Worker User Role. |
| 1009 | * |
| 1010 | * This upgrade routine will update access rights for Give_Worker User Role. |
| 1011 | * |
| 1012 | * @since 1.8.8 |
| 1013 | */ |
| 1014 | function give_v188_upgrades() { |
| 1015 | |
| 1016 | global $wp_roles; |
| 1017 | |
| 1018 | // Get the role object. |
| 1019 | $give_worker = get_role( 'give_worker' ); |
| 1020 | |
| 1021 | // A list of capabilities to add for give workers. |
| 1022 | $caps_to_add = array( |
| 1023 | 'edit_posts', |
| 1024 | 'edit_pages', |
| 1025 | ); |
| 1026 | |
| 1027 | foreach ( $caps_to_add as $cap ) { |
| 1028 | // Add the capability. |
| 1029 | $give_worker->add_cap( $cap ); |
| 1030 | } |
| 1031 | |
| 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * Update Post meta for minimum and maximum amount for multi level donation forms |
| 1036 | * |
| 1037 | * This upgrade routine adds post meta for give_forms CPT for multi level donation form. |
| 1038 | * |
| 1039 | * @since 1.8.9 |
| 1040 | */ |
| 1041 | function give_v189_upgrades_levels_post_meta_callback() { |
| 1042 | /* @var Give_Updates $give_updates */ |
| 1043 | $give_updates = Give_Updates::get_instance(); |
| 1044 | |
| 1045 | // form query. |
| 1046 | $donation_forms = new WP_Query( array( |
| 1047 | 'paged' => $give_updates->step, |
| 1048 | 'status' => 'any', |
| 1049 | 'order' => 'ASC', |
| 1050 | 'post_type' => 'give_forms', |
| 1051 | 'posts_per_page' => 20, |
| 1052 | ) |
| 1053 | ); |
| 1054 | |
| 1055 | if ( $donation_forms->have_posts() ) { |
| 1056 | $give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
| 1057 | |
| 1058 | while ( $donation_forms->have_posts() ) { |
| 1059 | $donation_forms->the_post(); |
| 1060 | $form_id = get_the_ID(); |
| 1061 | |
| 1062 | // Remove formatting from _give_set_price. |
| 1063 | update_post_meta( |
| 1064 | $form_id, |
| 1065 | '_give_set_price', |
| 1066 | give_sanitize_amount( get_post_meta( $form_id, '_give_set_price', true ) ) |
| 1067 | ); |
| 1068 | |
| 1069 | // Remove formatting from _give_custom_amount_minimum. |
| 1070 | update_post_meta( |
| 1071 | $form_id, |
| 1072 | '_give_custom_amount_minimum', |
| 1073 | give_sanitize_amount( get_post_meta( $form_id, '_give_custom_amount_minimum', true ) ) |
| 1074 | ); |
| 1075 | |
| 1076 | // Bailout. |
| 1077 | if ( 'set' === get_post_meta( $form_id, '_give_price_option', true ) ) { |
| 1078 | continue; |
| 1079 | } |
| 1080 | |
| 1081 | $donation_levels = get_post_meta( $form_id, '_give_donation_levels', true ); |
| 1082 | |
| 1083 | if ( ! empty( $donation_levels ) ) { |
| 1084 | |
| 1085 | foreach ( $donation_levels as $index => $donation_level ) { |
| 1086 | if ( isset( $donation_level['_give_amount'] ) ) { |
| 1087 | $donation_levels[ $index ]['_give_amount'] = give_sanitize_amount( $donation_level['_give_amount'] ); |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | update_post_meta( $form_id, '_give_donation_levels', $donation_levels ); |
| 1092 | |
| 1093 | $donation_levels_amounts = wp_list_pluck( $donation_levels, '_give_amount' ); |
| 1094 | |
| 1095 | $min_amount = min( $donation_levels_amounts ); |
| 1096 | $max_amount = max( $donation_levels_amounts ); |
| 1097 | |
| 1098 | // Set Minimum and Maximum amount for Multi Level Donation Forms |
| 1099 | give_update_meta( $form_id, '_give_levels_minimum_amount', $min_amount ? give_sanitize_amount( $min_amount ) : 0 ); |
| 1100 | give_update_meta( $form_id, '_give_levels_maximum_amount', $max_amount ? give_sanitize_amount( $max_amount ) : 0 ); |
| 1101 | } |
| 1102 | |
| 1103 | } |
| 1104 | |
| 1105 | /* Restore original Post Data */ |
| 1106 | wp_reset_postdata(); |
| 1107 | } else { |
| 1108 | // The Update Ran. |
| 1109 | give_set_upgrade_complete( 'v189_upgrades_levels_post_meta' ); |
| 1110 | } |
| 1111 | |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | /** |
| 1116 | * Give version 1.8.9 upgrades |
| 1117 | * |
| 1118 | * @since 1.8.9 |
| 1119 | */ |
| 1120 | function give_v189_upgrades() { |
| 1121 | /** |
| 1122 | * 1. Remove user license related notice show blocked ( Give_Notice will handle ) |
| 1123 | */ |
| 1124 | global $wpdb; |
| 1125 | |
| 1126 | // Delete permanent notice blocker. |
| 1127 | $wpdb->query( |
| 1128 | $wpdb->prepare( |
| 1129 | " |
| 1130 | DELETE FROM $wpdb->usermeta |
| 1131 | WHERE meta_key |
| 1132 | LIKE '%%%s%%' |
| 1133 | ", |
| 1134 | '_give_hide_license_notices_permanently' |
| 1135 | ) |
| 1136 | ); |
| 1137 | |
| 1138 | // Delete short notice blocker. |
| 1139 | $wpdb->query( |
| 1140 | $wpdb->prepare( |
| 1141 | " |
| 1142 | DELETE FROM $wpdb->options |
| 1143 | WHERE option_name |
| 1144 | LIKE '%%%s%%' |
| 1145 | ", |
| 1146 | '__give_hide_license_notices_shortly_' |
| 1147 | ) |
| 1148 | ); |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * 2.0 Upgrades. |
| 1153 | * |
| 1154 | * @since 2.0 |
| 1155 | * @return void |
| 1156 | */ |
| 1157 | function give_v20_upgrades() { |
| 1158 | // Update cache setting. |
| 1159 | give_update_option( 'cache', 'enabled' ); |
| 1160 | |
| 1161 | // Upgrade email settings. |
| 1162 | give_v20_upgrades_email_setting(); |
| 1163 | } |
| 1164 | |
| 1165 | /** |
| 1166 | * Move old email api settings to new email setting api for following emails: |
| 1167 | * 1. new offline donation [This was hard coded] |
| 1168 | * 2. offline donation instruction |
| 1169 | * 3. new donation |
| 1170 | * 4. donation receipt |
| 1171 | * |
| 1172 | * @since 2.0 |
| 1173 | */ |
| 1174 | function give_v20_upgrades_email_setting() { |
| 1175 | $all_setting = give_get_settings(); |
| 1176 | |
| 1177 | // Bailout on fresh install. |
| 1178 | if ( empty( $all_setting ) ) { |
| 1179 | return; |
| 1180 | } |
| 1181 | |
| 1182 | $settings = array( |
| 1183 | 'offline_donation_subject' => 'offline-donation-instruction_email_subject', |
| 1184 | 'global_offline_donation_email' => 'offline-donation-instruction_email_message', |
| 1185 | 'donation_subject' => 'donation-receipt_email_subject', |
| 1186 | 'donation_receipt' => 'donation-receipt_email_message', |
| 1187 | 'donation_notification_subject' => 'new-donation_email_subject', |
| 1188 | 'donation_notification' => 'new-donation_email_message', |
| 1189 | 'admin_notice_emails' => array( |
| 1190 | 'new-donation_recipient', |
| 1191 | 'new-offline-donation_recipient', |
| 1192 | 'new-donor-register_recipient', |
| 1193 | ), |
| 1194 | 'admin_notices' => 'new-donation_notification', |
| 1195 | ); |
| 1196 | |
| 1197 | foreach ( $settings as $old_setting => $new_setting ) { |
| 1198 | // Do not update already modified |
| 1199 | if ( ! is_array( $new_setting ) ) { |
| 1200 | if ( array_key_exists( $new_setting, $all_setting ) || ! array_key_exists( $old_setting, $all_setting ) ) { |
| 1201 | continue; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | switch ( $old_setting ) { |
| 1206 | case 'admin_notices': |
| 1207 | $notification_status = give_get_option( $old_setting, 'enabled' ); |
| 1208 | |
| 1209 | give_update_option( $new_setting, $notification_status ); |
| 1210 | |
| 1211 | // @todo: Delete this option later ( version > 2.0 ), We need this for per form email addon. |
| 1212 | // give_delete_option( $old_setting ); |
| 1213 | |
| 1214 | break; |
| 1215 | |
| 1216 | // @todo: Delete this option later ( version > 2.0 ) because we need this for backward compatibility give_get_admin_notice_emails. |
| 1217 | case 'admin_notice_emails': |
| 1218 | $recipients = give_get_admin_notice_emails(); |
| 1219 | |
| 1220 | foreach ( $new_setting as $setting ) { |
| 1221 | // bailout if setting already exist. |
| 1222 | if ( array_key_exists( $setting, $all_setting ) ) { |
| 1223 | continue; |
| 1224 | } |
| 1225 | |
| 1226 | give_update_option( $setting, $recipients ); |
| 1227 | } |
| 1228 | break; |
| 1229 | |
| 1230 | default: |
| 1231 | give_update_option( $new_setting, give_get_option( $old_setting ) ); |
| 1232 | give_delete_option( $old_setting ); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * Give version 1.8.9 upgrades |
| 1239 | * |
| 1240 | * @since 1.8.9 |
| 1241 | */ |
| 1242 | function give_v1812_upgrades() { |
| 1243 | /** |
| 1244 | * Validate number format settings. |
| 1245 | */ |
| 1246 | $give_settings = give_get_settings(); |
| 1247 | $give_setting_updated = false; |
| 1248 | |
| 1249 | if ( $give_settings['thousands_separator'] === $give_settings['decimal_separator'] ) { |
| 1250 | $give_settings['number_decimals'] = 0; |
| 1251 | $give_settings['decimal_separator'] = ''; |
| 1252 | $give_setting_updated = true; |
| 1253 | |
| 1254 | } elseif ( empty( $give_settings['decimal_separator'] ) ) { |
| 1255 | $give_settings['number_decimals'] = 0; |
| 1256 | $give_setting_updated = true; |
| 1257 | |
| 1258 | } elseif ( 6 < absint( $give_settings['number_decimals'] ) ) { |
| 1259 | $give_settings['number_decimals'] = 5; |
| 1260 | $give_setting_updated = true; |
| 1261 | } |
| 1262 | |
| 1263 | if ( $give_setting_updated ) { |
| 1264 | update_option( 'give_settings', $give_settings ); |
| 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | /** |
| 1270 | * Give version 1.8.12 update |
| 1271 | * |
| 1272 | * Standardized amount values to six decimal |
| 1273 | * |
| 1274 | * @see https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602 |
| 1275 | * |
| 1276 | * @since 1.8.12 |
| 1277 | */ |
| 1278 | function give_v1812_update_amount_values_callback() { |
| 1279 | /* @var Give_Updates $give_updates */ |
| 1280 | $give_updates = Give_Updates::get_instance(); |
| 1281 | |
| 1282 | // form query. |
| 1283 | $donation_forms = new WP_Query( array( |
| 1284 | 'paged' => $give_updates->step, |
| 1285 | 'status' => 'any', |
| 1286 | 'order' => 'ASC', |
| 1287 | 'post_type' => array( 'give_forms', 'give_payment' ), |
| 1288 | 'posts_per_page' => 20, |
| 1289 | ) |
| 1290 | ); |
| 1291 | if ( $donation_forms->have_posts() ) { |
| 1292 | $give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
| 1293 | |
| 1294 | while ( $donation_forms->have_posts() ) { |
| 1295 | $donation_forms->the_post(); |
| 1296 | global $post; |
| 1297 | |
| 1298 | $meta = get_post_meta( $post->ID ); |
| 1299 | |
| 1300 | switch ( $post->post_type ) { |
| 1301 | case 'give_forms': |
| 1302 | // _give_set_price. |
| 1303 | if ( ! empty( $meta['_give_set_price'][0] ) ) { |
| 1304 | update_post_meta( $post->ID, '_give_set_price', give_sanitize_amount_for_db( $meta['_give_set_price'][0] ) ); |
| 1305 | } |
| 1306 | |
| 1307 | // _give_custom_amount_minimum. |
| 1308 | if ( ! empty( $meta['_give_custom_amount_minimum'][0] ) ) { |
| 1309 | update_post_meta( $post->ID, '_give_custom_amount_minimum', give_sanitize_amount_for_db( $meta['_give_custom_amount_minimum'][0] ) ); |
| 1310 | } |
| 1311 | |
| 1312 | // _give_levels_minimum_amount. |
| 1313 | if ( ! empty( $meta['_give_levels_minimum_amount'][0] ) ) { |
| 1314 | update_post_meta( $post->ID, '_give_levels_minimum_amount', give_sanitize_amount_for_db( $meta['_give_levels_minimum_amount'][0] ) ); |
| 1315 | } |
| 1316 | |
| 1317 | // _give_levels_maximum_amount. |
| 1318 | if ( ! empty( $meta['_give_levels_maximum_amount'][0] ) ) { |
| 1319 | update_post_meta( $post->ID, '_give_levels_maximum_amount', give_sanitize_amount_for_db( $meta['_give_levels_maximum_amount'][0] ) ); |
| 1320 | } |
| 1321 | |
| 1322 | // _give_set_goal. |
| 1323 | if ( ! empty( $meta['_give_set_goal'][0] ) ) { |
| 1324 | update_post_meta( $post->ID, '_give_set_goal', give_sanitize_amount_for_db( $meta['_give_set_goal'][0] ) ); |
| 1325 | } |
| 1326 | |
| 1327 | // _give_form_earnings. |
| 1328 | if ( ! empty( $meta['_give_form_earnings'][0] ) ) { |
| 1329 | update_post_meta( $post->ID, '_give_form_earnings', give_sanitize_amount_for_db( $meta['_give_form_earnings'][0] ) ); |
| 1330 | } |
| 1331 | |
| 1332 | // _give_custom_amount_minimum. |
| 1333 | if ( ! empty( $meta['_give_donation_levels'][0] ) ) { |
| 1334 | $donation_levels = unserialize( $meta['_give_donation_levels'][0] ); |
| 1335 | |
| 1336 | foreach ( $donation_levels as $index => $level ) { |
| 1337 | if ( empty( $level['_give_amount'] ) ) { |
| 1338 | continue; |
| 1339 | } |
| 1340 | |
| 1341 | $donation_levels[ $index ]['_give_amount'] = give_sanitize_amount_for_db( $level['_give_amount'] ); |
| 1342 | } |
| 1343 | |
| 1344 | $meta['_give_donation_levels'] = $donation_levels; |
| 1345 | update_post_meta( $post->ID, '_give_donation_levels', $meta['_give_donation_levels'] ); |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | break; |
| 1350 | |
| 1351 | case 'give_payment': |
| 1352 | // _give_payment_total. |
| 1353 | if ( ! empty( $meta['_give_payment_total'][0] ) ) { |
| 1354 | update_post_meta( $post->ID, '_give_payment_total', give_sanitize_amount_for_db( $meta['_give_payment_total'][0] ) ); |
| 1355 | } |
| 1356 | |
| 1357 | break; |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | /* Restore original Post Data */ |
| 1362 | wp_reset_postdata(); |
| 1363 | } else { |
| 1364 | // The Update Ran. |
| 1365 | give_set_upgrade_complete( 'v1812_update_amount_values' ); |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | /** |
| 1371 | * Give version 1.8.12 update |
| 1372 | * |
| 1373 | * Standardized amount values to six decimal for donor |
| 1374 | * |
| 1375 | * @see https://github.com/WordImpress/Give/issues/1849#issuecomment-315128602 |
| 1376 | * |
| 1377 | * @since 1.8.12 |
| 1378 | */ |
| 1379 | function give_v1812_update_donor_purchase_value_callback() { |
| 1380 | /* @var Give_Updates $give_updates */ |
| 1381 | $give_updates = Give_Updates::get_instance(); |
| 1382 | |
| 1383 | // form query. |
| 1384 | $donors = Give()->donors->get_donors( array( |
| 1385 | 'number' => 20, |
| 1386 | 'offset' => $give_updates->get_offset( 20 ), |
| 1387 | ) |
| 1388 | ); |
| 1389 | |
| 1390 | if ( ! empty( $donors ) ) { |
| 1391 | $give_updates->set_percentage( Give()->donors->count(), $give_updates->get_offset( 20 ) ); |
| 1392 | |
| 1393 | /* @var Object $donor */ |
| 1394 | foreach ( $donors as $donor ) { |
| 1395 | Give()->donors->update( $donor->id, array( 'purchase_value' => give_sanitize_amount_for_db( $donor->purchase_value ) ) ); |
| 1396 | } |
| 1397 | } else { |
| 1398 | // The Update Ran. |
| 1399 | give_set_upgrade_complete( 'v1812_update_donor_purchase_values' ); |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * Upgrade routine for updating user roles for existing donors. |
| 1405 | * |
| 1406 | * @since 1.8.13 |
| 1407 | */ |
| 1408 | function give_v1813_update_donor_user_roles_callback() { |
| 1409 | /* @var Give_Updates $give_updates */ |
| 1410 | $give_updates = Give_Updates::get_instance(); |
| 1411 | |
| 1412 | // Fetch all the existing donors. |
| 1413 | $donors = Give()->donors->get_donors( array( |
| 1414 | 'number' => 20, |
| 1415 | 'offset' => $give_updates->get_offset( 20 ), |
| 1416 | ) |
| 1417 | ); |
| 1418 | |
| 1419 | if ( ! empty( $donors ) ) { |
| 1420 | $give_updates->set_percentage( Give()->donors->count(), $give_updates->get_offset( 20 ) ); |
| 1421 | |
| 1422 | /* @var Object $donor */ |
| 1423 | foreach ( $donors as $donor ) { |
| 1424 | $user_id = $donor->user_id; |
| 1425 | |
| 1426 | // Proceed, if donor is attached with user. |
| 1427 | if ( $user_id ) { |
| 1428 | $user = get_userdata( $user_id ); |
| 1429 | |
| 1430 | // Update user role, if user has subscriber role. |
| 1431 | if ( is_array( $user->roles ) && in_array( 'subscriber', $user->roles ) ) { |
| 1432 | wp_update_user( |
| 1433 | array( |
| 1434 | 'ID' => $user_id, |
| 1435 | 'role' => 'give_donor', |
| 1436 | ) |
| 1437 | ); |
| 1438 | } |
| 1439 | } |
| 1440 | } |
| 1441 | } else { |
| 1442 | // The Update Ran. |
| 1443 | give_set_upgrade_complete( 'v1813_update_donor_user_roles' ); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | /** |
| 1449 | * Version 1.8.13 automatic updates |
| 1450 | * |
| 1451 | * @since 1.8.13 |
| 1452 | */ |
| 1453 | function give_v1813_upgrades() { |
| 1454 | // Update admin setting. |
| 1455 | give_update_option( 'donor_default_user_role', 'give_donor' ); |
| 1456 | |
| 1457 | // Update Give roles. |
| 1458 | $roles = new Give_Roles(); |
| 1459 | $roles->add_roles(); |
| 1460 | $roles->add_caps(); |
| 1461 | } |
| 1462 | |
| 1463 | /** |
| 1464 | * Correct currency code for "Iranian Currency" for all of the payments. |
| 1465 | * |
| 1466 | * @since 1.8.17 |
| 1467 | */ |
| 1468 | function give_v1817_update_donation_iranian_currency_code() { |
| 1469 | /* @var Give_Updates $give_updates */ |
| 1470 | $give_updates = Give_Updates::get_instance(); |
| 1471 | |
| 1472 | // form query. |
| 1473 | $payments = new WP_Query( array( |
| 1474 | 'paged' => $give_updates->step, |
| 1475 | 'status' => 'any', |
| 1476 | 'order' => 'ASC', |
| 1477 | 'post_type' => array( 'give_payment' ), |
| 1478 | 'posts_per_page' => 100, |
| 1479 | ) |
| 1480 | ); |
| 1481 | |
| 1482 | if ( $payments->have_posts() ) { |
| 1483 | $give_updates->set_percentage( $payments->found_posts, ( $give_updates->step * 100 ) ); |
| 1484 | |
| 1485 | while ( $payments->have_posts() ) { |
| 1486 | $payments->the_post(); |
| 1487 | |
| 1488 | $payment_meta = give_get_payment_meta( get_the_ID() ); |
| 1489 | |
| 1490 | if ( 'RIAL' === $payment_meta['currency'] ) { |
| 1491 | $payment_meta['currency'] = 'IRR'; |
| 1492 | give_update_meta( get_the_ID(), '_give_payment_meta', $payment_meta ); |
| 1493 | } |
| 1494 | |
| 1495 | } |
| 1496 | |
| 1497 | } else { |
| 1498 | // The Update Ran. |
| 1499 | give_set_upgrade_complete( 'v1817_update_donation_iranian_currency_code' ); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | /** |
| 1504 | * Correct currency code for "Iranian Currency" in Give setting. |
| 1505 | * Version 1.8.17 automatic updates |
| 1506 | * |
| 1507 | * @since 1.8.17 |
| 1508 | */ |
| 1509 | function give_v1817_upgrades() { |
| 1510 | $give_settings = give_get_settings(); |
| 1511 | |
| 1512 | if ( 'RIAL' === $give_settings['currency'] ) { |
| 1513 | $give_settings['currency'] = 'IRR'; |
| 1514 | update_option( 'give_settings', $give_settings ); |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | /** |
| 1519 | * Process Clean up of User Roles for more flexibility. |
| 1520 | * |
| 1521 | * @since 1.8.17 |
| 1522 | */ |
| 1523 | function give_v1817_process_cleanup_user_roles() { |
| 1524 | |
| 1525 | global $wp_roles; |
| 1526 | |
| 1527 | if ( ! ( $wp_roles instanceof WP_Roles ) ) { |
| 1528 | return; |
| 1529 | } |
| 1530 | |
| 1531 | // Add Capabilities to user roles as required. |
| 1532 | $add_caps = array( |
| 1533 | 'administrator' => array( |
| 1534 | 'view_give_payments', |
| 1535 | ), |
| 1536 | ); |
| 1537 | |
| 1538 | // Remove Capabilities to user roles as required. |
| 1539 | $remove_caps = array( |
| 1540 | 'give_manager' => array( |
| 1541 | 'edit_others_pages', |
| 1542 | 'edit_others_posts', |
| 1543 | 'delete_others_pages', |
| 1544 | 'delete_others_posts', |
| 1545 | 'manage_categories', |
| 1546 | 'import', |
| 1547 | 'export', |
| 1548 | ), |
| 1549 | ); |
| 1550 | |
| 1551 | foreach ( $add_caps as $role => $caps ) { |
| 1552 | foreach ( $caps as $cap ) { |
| 1553 | $wp_roles->add_cap( $role, $cap ); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | foreach ( $remove_caps as $role => $caps ) { |
| 1558 | foreach ( $caps as $cap ) { |
| 1559 | $wp_roles->remove_cap( $role, $cap ); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | } |
| 1564 | |
| 1565 | /** |
| 1566 | * Upgrade Routine - Clean up of User Roles for more flexibility. |
| 1567 | * |
| 1568 | * @since 1.8.17 |
| 1569 | */ |
| 1570 | function give_v1817_cleanup_user_roles() { |
| 1571 | /* @var Give_Updates $give_updates */ |
| 1572 | $give_updates = Give_Updates::get_instance(); |
| 1573 | |
| 1574 | give_v1817_process_cleanup_user_roles(); |
| 1575 | |
| 1576 | $give_updates->percentage = 100; |
| 1577 | |
| 1578 | // Create Give plugin roles. |
| 1579 | $roles = new Give_Roles(); |
| 1580 | $roles->add_roles(); |
| 1581 | $roles->add_caps(); |
| 1582 | |
| 1583 | give_set_upgrade_complete( 'v1817_cleanup_user_roles' ); |
| 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * Automatic Upgrade for release 1.8.18. |
| 1588 | * |
| 1589 | * @since 1.8.18 |
| 1590 | */ |
| 1591 | function give_v1818_upgrades() { |
| 1592 | |
| 1593 | // Remove email_access_installed from give_settings. |
| 1594 | give_delete_option( 'email_access_installed' ); |
| 1595 | } |
| 1596 | |
| 1597 | /** |
| 1598 | * Upgrade Routine - Assigns Custom Amount to existing donation of type set donation. |
| 1599 | * |
| 1600 | * @since 1.8.18 |
| 1601 | */ |
| 1602 | function give_v1818_assign_custom_amount_set_donation() { |
| 1603 | |
| 1604 | /* @var Give_Updates $give_updates */ |
| 1605 | $give_updates = Give_Updates::get_instance(); |
| 1606 | |
| 1607 | $donations = new WP_Query( array( |
| 1608 | 'paged' => $give_updates->step, |
| 1609 | 'status' => 'any', |
| 1610 | 'order' => 'ASC', |
| 1611 | 'post_type' => array( 'give_payment' ), |
| 1612 | 'posts_per_page' => 100, |
| 1613 | ) |
| 1614 | ); |
| 1615 | |
| 1616 | if ( $donations->have_posts() ) { |
| 1617 | $give_updates->set_percentage( $donations->found_posts, $give_updates->step * 100 ); |
| 1618 | |
| 1619 | while ( $donations->have_posts() ) { |
| 1620 | $donations->the_post(); |
| 1621 | |
| 1622 | $form = new Give_Donate_Form( give_get_meta( get_the_ID(), '_give_payment_form_id', true ) ); |
| 1623 | $donation_meta = give_get_payment_meta( get_the_ID() ); |
| 1624 | |
| 1625 | // Update Donation meta with price_id set as custom, only if it is: |
| 1626 | // 1. Donation Type = Set Donation. |
| 1627 | // 2. Donation Price Id is not set to custom. |
| 1628 | // 3. Form has not enabled custom price and donation amount assures that it is custom amount. |
| 1629 | if ( |
| 1630 | $form->ID && |
| 1631 | $form->is_set_type_donation_form() && |
| 1632 | ( 'custom' !== $donation_meta['price_id'] ) && |
| 1633 | $form->is_custom_price( give_get_meta( get_the_ID(), '_give_payment_total', true ) ) |
| 1634 | ) { |
| 1635 | $donation_meta['price_id'] = 'custom'; |
| 1636 | give_update_meta( get_the_ID(), '_give_payment_meta', $donation_meta ); |
| 1637 | give_update_meta( get_the_ID(), '_give_payment_price_id', 'custom' ); |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | wp_reset_postdata(); |
| 1642 | } else { |
| 1643 | // Update Ran Successfully. |
| 1644 | give_set_upgrade_complete( 'v1818_assign_custom_amount_set_donation' ); |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | /** |
| 1649 | * Upgrade Routine - Removed Give Worker caps. |
| 1650 | * |
| 1651 | * See: https://github.com/WordImpress/Give/issues/2476 |
| 1652 | * |
| 1653 | * @since 1.8.18 |
| 1654 | */ |
| 1655 | function give_v1818_give_worker_role_cleanup() { |
| 1656 | |
| 1657 | /* @var Give_Updates $give_updates */ |
| 1658 | $give_updates = Give_Updates::get_instance(); |
| 1659 | |
| 1660 | global $wp_roles; |
| 1661 | |
| 1662 | if ( ! ( $wp_roles instanceof WP_Roles ) ) { |
| 1663 | return; |
| 1664 | } |
| 1665 | |
| 1666 | // Remove Capabilities to user roles as required. |
| 1667 | $remove_caps = array( |
| 1668 | 'give_worker' => array( |
| 1669 | 'delete_give_payments', |
| 1670 | 'delete_others_give_payments', |
| 1671 | 'delete_private_give_payments', |
| 1672 | 'delete_published_give_payments', |
| 1673 | 'edit_others_give_payments', |
| 1674 | 'edit_private_give_payments', |
| 1675 | 'edit_published_give_payments', |
| 1676 | 'read_private_give_payments', |
| 1677 | ), |
| 1678 | ); |
| 1679 | |
| 1680 | foreach ( $remove_caps as $role => $caps ) { |
| 1681 | foreach ( $caps as $cap ) { |
| 1682 | $wp_roles->remove_cap( $role, $cap ); |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | $give_updates->percentage = 100; |
| 1687 | |
| 1688 | // Create Give plugin roles. |
| 1689 | $roles = new Give_Roles(); |
| 1690 | $roles->add_roles(); |
| 1691 | $roles->add_caps(); |
| 1692 | |
| 1693 | give_set_upgrade_complete( 'v1818_give_worker_role_cleanup' ); |
| 1694 | } |
| 1695 | |
| 1696 | /** |
| 1697 | * |
| 1698 | * Upgrade form metadata for new metabox settings. |
| 1699 | * |
| 1700 | * @since 2.0 |
| 1701 | * @return void |
| 1702 | */ |
| 1703 | function give_v20_upgrades_form_metadata_callback() { |
| 1704 | $give_updates = Give_Updates::get_instance(); |
| 1705 | |
| 1706 | // form query |
| 1707 | $forms = new WP_Query( array( |
| 1708 | 'paged' => $give_updates->step, |
| 1709 | 'status' => 'any', |
| 1710 | 'order' => 'ASC', |
| 1711 | 'post_type' => 'give_forms', |
| 1712 | 'posts_per_page' => 100, |
| 1713 | ) |
| 1714 | ); |
| 1715 | |
| 1716 | if ( $forms->have_posts() ) { |
| 1717 | $give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
| 1718 | |
| 1719 | while ( $forms->have_posts() ) { |
| 1720 | $forms->the_post(); |
| 1721 | global $post; |
| 1722 | |
| 1723 | // Update offline instruction email notification status. |
| 1724 | $offline_instruction_notification_status = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true ); |
| 1725 | $offline_instruction_notification_status = give_is_setting_enabled( $offline_instruction_notification_status, array( |
| 1726 | 'enabled', |
| 1727 | 'global', |
| 1728 | ) ) |
| 1729 | ? $offline_instruction_notification_status |
| 1730 | : 'global'; |
| 1731 | update_post_meta( get_the_ID(), '_give_offline-donation-instruction_notification', $offline_instruction_notification_status ); |
| 1732 | |
| 1733 | // Update offline instruction email message. |
| 1734 | update_post_meta( |
| 1735 | get_the_ID(), |
| 1736 | '_give_offline-donation-instruction_email_message', |
| 1737 | get_post_meta( |
| 1738 | get_the_ID(), |
| 1739 | // @todo: Delete this option later ( version > 2.0 ). |
| 1740 | '_give_offline_donation_email', |
| 1741 | true |
| 1742 | ) |
| 1743 | ); |
| 1744 | |
| 1745 | // Update offline instruction email subject. |
| 1746 | update_post_meta( |
| 1747 | get_the_ID(), |
| 1748 | '_give_offline-donation-instruction_email_subject', |
| 1749 | get_post_meta( |
| 1750 | get_the_ID(), |
| 1751 | // @todo: Delete this option later ( version > 2.0 ). |
| 1752 | '_give_offline_donation_subject', |
| 1753 | true |
| 1754 | ) |
| 1755 | ); |
| 1756 | |
| 1757 | |
| 1758 | }// End while(). |
| 1759 | |
| 1760 | wp_reset_postdata(); |
| 1761 | } else { |
| 1762 | // No more forms found, finish up. |
| 1763 | give_set_upgrade_complete( 'v20_upgrades_form_metadata' ); |
| 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | /** |
| 1769 | * Upgrade payment metadata for new metabox settings. |
| 1770 | * |
| 1771 | * @since 2.0 |
| 1772 | * @global wpdb $wpdb |
| 1773 | * @return void |
| 1774 | */ |
| 1775 | function give_v20_upgrades_payment_metadata_callback() { |
| 1776 | global $wpdb; |
| 1777 | $give_updates = Give_Updates::get_instance(); |
| 1778 | |
| 1779 | // form query |
| 1780 | $forms = new WP_Query( array( |
| 1781 | 'paged' => $give_updates->step, |
| 1782 | 'status' => 'any', |
| 1783 | 'order' => 'ASC', |
| 1784 | 'post_type' => 'give_payment', |
| 1785 | 'posts_per_page' => 100, |
| 1786 | ) |
| 1787 | ); |
| 1788 | |
| 1789 | if ( $forms->have_posts() ) { |
| 1790 | $give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
| 1791 | |
| 1792 | while ( $forms->have_posts() ) { |
| 1793 | $forms->the_post(); |
| 1794 | global $post; |
| 1795 | |
| 1796 | // Split _give_payment_meta meta. |
| 1797 | // @todo Remove _give_payment_meta after releases 2.0 |
| 1798 | $payment_meta = give_get_meta( $post->ID, '_give_payment_meta', true ); |
| 1799 | |
| 1800 | if ( ! empty( $payment_meta ) ) { |
| 1801 | _give_20_bc_split_and_save_give_payment_meta( $post->ID, $payment_meta ); |
| 1802 | } |
| 1803 | |
| 1804 | $deprecated_meta_keys = array( |
| 1805 | '_give_payment_customer_id' => '_give_payment_donor_id', |
| 1806 | '_give_payment_user_email' => '_give_payment_donor_email', |
| 1807 | '_give_payment_user_ip' => '_give_payment_donor_ip', |
| 1808 | ); |
| 1809 | |
| 1810 | foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) { |
| 1811 | // Do not add new meta key if already exist. |
| 1812 | if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key=%s", $post->ID, $new_meta_key ) ) ) { |
| 1813 | continue; |
| 1814 | } |
| 1815 | |
| 1816 | $wpdb->insert( |
| 1817 | $wpdb->postmeta, |
| 1818 | array( |
| 1819 | 'post_id' => $post->ID, |
| 1820 | 'meta_key' => $new_meta_key, |
| 1821 | 'meta_value' => give_get_meta( $post->ID, $old_meta_key, true ), |
| 1822 | ) |
| 1823 | ); |
| 1824 | } |
| 1825 | |
| 1826 | // Bailout |
| 1827 | if ( $donor_id = give_get_meta( $post->ID, '_give_payment_donor_id', true ) ) { |
| 1828 | /* @var Give_Donor $donor */ |
| 1829 | $donor = new Give_Donor( $donor_id ); |
| 1830 | |
| 1831 | $address['line1'] = give_get_meta( $post->ID, '_give_donor_billing_address1', true, '' ); |
| 1832 | $address['line2'] = give_get_meta( $post->ID, '_give_donor_billing_address2', true, '' ); |
| 1833 | $address['city'] = give_get_meta( $post->ID, '_give_donor_billing_city', true, '' ); |
| 1834 | $address['state'] = give_get_meta( $post->ID, '_give_donor_billing_state', true, '' ); |
| 1835 | $address['zip'] = give_get_meta( $post->ID, '_give_donor_billing_zip', true, '' ); |
| 1836 | $address['country'] = give_get_meta( $post->ID, '_give_donor_billing_country', true, '' ); |
| 1837 | |
| 1838 | // Save address. |
| 1839 | $donor->add_address( 'billing[]', $address ); |
| 1840 | } |
| 1841 | |
| 1842 | }// End while(). |
| 1843 | |
| 1844 | wp_reset_postdata(); |
| 1845 | } else { |
| 1846 | // @todo Delete user id meta after releases 2.0 |
| 1847 | // $wpdb->get_var( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key=%s", '_give_payment_user_id' ) ); |
| 1848 | |
| 1849 | // No more forms found, finish up. |
| 1850 | give_set_upgrade_complete( 'v20_upgrades_payment_metadata' ); |
| 1851 | } |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | /** |
| 1856 | * Upgrade logs data. |
| 1857 | * |
| 1858 | * @since 2.0 |
| 1859 | * @return void |
| 1860 | */ |
| 1861 | function give_v20_logs_upgrades_callback() { |
| 1862 | global $wpdb; |
| 1863 | $give_updates = Give_Updates::get_instance(); |
| 1864 | |
| 1865 | // form query |
| 1866 | $forms = new WP_Query( array( |
| 1867 | 'paged' => $give_updates->step, |
| 1868 | 'order' => 'DESC', |
| 1869 | 'post_type' => 'give_log', |
| 1870 | 'post_status' => 'any', |
| 1871 | 'posts_per_page' => 100, |
| 1872 | ) |
| 1873 | ); |
| 1874 | |
| 1875 | if ( $forms->have_posts() ) { |
| 1876 | $give_updates->set_percentage( $forms->found_posts, $give_updates->step * 100 ); |
| 1877 | |
| 1878 | while ( $forms->have_posts() ) { |
| 1879 | $forms->the_post(); |
| 1880 | global $post; |
| 1881 | |
| 1882 | if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_logs WHERE ID=%d", $post->ID ) ) ) { |
| 1883 | continue; |
| 1884 | } |
| 1885 | |
| 1886 | $term = get_the_terms( $post->ID, 'give_log_type' ); |
| 1887 | $term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array(); |
| 1888 | $term_name = ! empty( $term ) ? $term->slug : ''; |
| 1889 | |
| 1890 | $log_data = array( |
| 1891 | 'ID' => $post->ID, |
| 1892 | 'log_title' => $post->post_title, |
| 1893 | 'log_content' => $post->post_content, |
| 1894 | 'log_parent' => 0, |
| 1895 | 'log_type' => $term_name, |
| 1896 | 'log_date' => $post->post_date, |
| 1897 | 'log_date_gmt' => $post->post_date_gmt, |
| 1898 | ); |
| 1899 | $log_meta = array(); |
| 1900 | |
| 1901 | if ( $old_log_meta = get_post_meta( $post->ID ) ) { |
| 1902 | foreach ( $old_log_meta as $meta_key => $meta_value ) { |
| 1903 | switch ( $meta_key ) { |
| 1904 | case '_give_log_payment_id': |
| 1905 | $log_data['log_parent'] = current( $meta_value ); |
| 1906 | $log_meta['_give_log_form_id'] = $post->post_parent; |
| 1907 | break; |
| 1908 | |
| 1909 | default: |
| 1910 | $log_meta[ $meta_key ] = current( $meta_value ); |
| 1911 | } |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | if ( 'api_request' === $term_name ) { |
| 1916 | $log_meta['_give_log_api_query'] = $post->post_excerpt; |
| 1917 | } |
| 1918 | |
| 1919 | $wpdb->insert( "{$wpdb->prefix}give_logs", $log_data ); |
| 1920 | |
| 1921 | if ( ! empty( $log_meta ) ) { |
| 1922 | foreach ( $log_meta as $meta_key => $meta_value ) { |
| 1923 | Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value ); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | $logIDs[] = $post->ID; |
| 1928 | }// End while(). |
| 1929 | |
| 1930 | wp_reset_postdata(); |
| 1931 | } else { |
| 1932 | // @todo: Delete terms and taxonomy after releases 2.0. |
| 1933 | /*$terms = get_terms( 'give_log_type', array( 'fields' => 'ids', 'hide_empty' => false ) ); |
| 1934 | if ( ! empty( $terms ) ) { |
| 1935 | foreach ( $terms as $term ) { |
| 1936 | wp_delete_term( $term, 'give_log_type' ); |
| 1937 | } |
| 1938 | }*/ |
| 1939 | |
| 1940 | // @todo: Delete logs after releases 2.0. |
| 1941 | /*$logIDs = get_posts( array( |
| 1942 | 'order' => 'DESC', |
| 1943 | 'post_type' => 'give_log', |
| 1944 | 'post_status' => 'any', |
| 1945 | 'posts_per_page' => - 1, |
| 1946 | 'fields' => 'ids', |
| 1947 | ) |
| 1948 | );*/ |
| 1949 | |
| 1950 | /*if ( ! empty( $logIDs ) ) { |
| 1951 | foreach ( $logIDs as $log ) { |
| 1952 | // Delete term relationship and posts. |
| 1953 | wp_delete_object_term_relationships( $log, 'give_log_type' ); |
| 1954 | wp_delete_post( $log, true ); |
| 1955 | } |
| 1956 | }*/ |
| 1957 | |
| 1958 | // @todo: Unregister taxonomy after releases 2.0. |
| 1959 | /*unregister_taxonomy( 'give_log_type' );*/ |
| 1960 | |
| 1961 | // Delete log cache. |
| 1962 | Give()->logs->delete_cache(); |
| 1963 | |
| 1964 | // No more forms found, finish up. |
| 1965 | give_set_upgrade_complete( 'v20_logs_upgrades' ); |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | /** |
| 1971 | * Move payment and form metadata to new table |
| 1972 | * |
| 1973 | * @since 2.0 |
| 1974 | * @return void |
| 1975 | */ |
| 1976 | function give_v20_move_metadata_into_new_table_callback() { |
| 1977 | global $wpdb; |
| 1978 | $give_updates = Give_Updates::get_instance(); |
| 1979 | |
| 1980 | // form query |
| 1981 | $payments = new WP_Query( array( |
| 1982 | 'paged' => $give_updates->step, |
| 1983 | 'status' => 'any', |
| 1984 | 'order' => 'ASC', |
| 1985 | 'post_type' => array( 'give_forms', 'give_payment' ), |
| 1986 | 'posts_per_page' => 100, |
| 1987 | ) |
| 1988 | ); |
| 1989 | |
| 1990 | if ( $payments->have_posts() ) { |
| 1991 | $give_updates->set_percentage( $payments->found_posts, $give_updates->step * 100 ); |
| 1992 | |
| 1993 | while ( $payments->have_posts() ) { |
| 1994 | $payments->the_post(); |
| 1995 | global $post; |
| 1996 | |
| 1997 | $meta_data = $wpdb->get_results( |
| 1998 | $wpdb->prepare( |
| 1999 | "SELECT * FROM $wpdb->postmeta where post_id=%d", |
| 2000 | get_the_ID() |
| 2001 | ), |
| 2002 | ARRAY_A |
| 2003 | ); |
| 2004 | |
| 2005 | if ( ! empty( $meta_data ) ) { |
| 2006 | foreach ( $meta_data as $index => $data ) { |
| 2007 | // Check for duplicate meta values. |
| 2008 | if ( $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . ( 'give_forms' === $post->post_type ? $wpdb->formmeta : $wpdb->paymentmeta ) . " WHERE meta_id=%d", $data['meta_id'] ), ARRAY_A ) ) { |
| 2009 | continue; |
| 2010 | } |
| 2011 | |
| 2012 | switch ( $post->post_type ) { |
| 2013 | case 'give_forms': |
| 2014 | $data['form_id'] = $data['post_id']; |
| 2015 | unset( $data['post_id'] ); |
| 2016 | |
| 2017 | Give()->form_meta->insert( $data ); |
| 2018 | // @todo: delete form meta from post meta table after releases 2.0. |
| 2019 | /*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
| 2020 | |
| 2021 | break; |
| 2022 | |
| 2023 | case 'give_payment': |
| 2024 | $data['payment_id'] = $data['post_id']; |
| 2025 | unset( $data['post_id'] ); |
| 2026 | |
| 2027 | Give()->payment_meta->insert( $data ); |
| 2028 | |
| 2029 | // @todo: delete donation meta from post meta table after releases 2.0. |
| 2030 | /*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
| 2031 | |
| 2032 | break; |
| 2033 | } |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | }// End while(). |
| 2038 | |
| 2039 | wp_reset_postdata(); |
| 2040 | } else { |
| 2041 | // No more forms found, finish up. |
| 2042 | give_set_upgrade_complete( 'v20_move_metadata_into_new_table' ); |
| 2043 | } |
| 2044 | |
| 2045 | } |
| 2046 | |
| 2047 | /** |
| 2048 | * Upgrade routine for splitting donor name into first name and last name. |
| 2049 | * |
| 2050 | * @since 2.0 |
| 2051 | * |
| 2052 | * @return void |
| 2053 | */ |
| 2054 | function give_v20_upgrades_donor_name() { |
| 2055 | /* @var Give_Updates $give_updates */ |
| 2056 | $give_updates = Give_Updates::get_instance(); |
| 2057 | |
| 2058 | $donors = Give()->donors->get_donors( array( |
| 2059 | 'paged' => $give_updates->step, |
| 2060 | 'number' => 100, |
| 2061 | ) ); |
| 2062 | |
| 2063 | if ( $donors ) { |
| 2064 | $give_updates->set_percentage( count( $donors ), $give_updates->step * 100 ); |
| 2065 | // Loop through Donors |
| 2066 | foreach ( $donors as $donor ) { |
| 2067 | |
| 2068 | $donor_name = explode( ' ', $donor->name, 2 ); |
| 2069 | $donor_first_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_first_name' ); |
| 2070 | $donor_last_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_last_name' ); |
| 2071 | |
| 2072 | // If first name meta of donor is not created, then create it. |
| 2073 | if ( ! $donor_first_name && isset( $donor_name[0] ) ) { |
| 2074 | Give()->donor_meta->add_meta( $donor->id, '_give_donor_first_name', $donor_name[0] ); |
| 2075 | } |
| 2076 | |
| 2077 | // If last name meta of donor is not created, then create it. |
| 2078 | if ( ! $donor_last_name && isset( $donor_name[1] ) ) { |
| 2079 | Give()->donor_meta->add_meta( $donor->id, '_give_donor_last_name', $donor_name[1] ); |
| 2080 | } |
| 2081 | |
| 2082 | // If Donor is connected with WP User then update user meta. |
| 2083 | if ( $donor->user_id ) { |
| 2084 | if ( isset( $donor_name[0] ) ) { |
| 2085 | update_user_meta( $donor->user_id, 'first_name', $donor_name[0] ); |
| 2086 | } |
| 2087 | if ( isset( $donor_name[1] ) ) { |
| 2088 | update_user_meta( $donor->user_id, 'last_name', $donor_name[1] ); |
| 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | } else { |
| 2094 | // The Update Ran. |
| 2095 | give_set_upgrade_complete( 'v20_upgrades_donor_name' ); |
| 2096 | } |
| 2097 | |
| 2098 | } |
| 2099 | |
| 2100 | /** |
| 2101 | * Upgrade routine for user addresses. |
| 2102 | * |
| 2103 | * @since 2.0 |
| 2104 | * @global wpdb $wpdb |
| 2105 | * |
| 2106 | * @return void |
| 2107 | */ |
| 2108 | function give_v20_upgrades_user_address() { |
| 2109 | global $wpdb; |
| 2110 | |
| 2111 | /* @var Give_Updates $give_updates */ |
| 2112 | $give_updates = Give_Updates::get_instance(); |
| 2113 | |
| 2114 | /* @var WP_User_Query $user_query */ |
| 2115 | $user_query = new WP_User_Query( |
| 2116 | array( |
| 2117 | 'number' => 100, |
| 2118 | 'paged' => $give_updates->step, |
| 2119 | ) |
| 2120 | ); |
| 2121 | |
| 2122 | $users = $user_query->get_results(); |
| 2123 | |
| 2124 | if ( $users ) { |
| 2125 | $give_updates->set_percentage( $user_query->get_total(), $give_updates->step * 100 ); |
| 2126 | |
| 2127 | // Loop through Donors |
| 2128 | foreach ( $users as $user ) { |
| 2129 | /* @var Give_Donor $donor */ |
| 2130 | $donor = new Give_Donor( $user->ID, true ); |
| 2131 | |
| 2132 | if ( ! $donor->id ) { |
| 2133 | continue; |
| 2134 | } |
| 2135 | |
| 2136 | $address = $wpdb->get_var( |
| 2137 | $wpdb->prepare( |
| 2138 | " |
| 2139 | SELECT meta_value FROM {$wpdb->usermeta} |
| 2140 | WHERE user_id=%s |
| 2141 | AND meta_key=%s |
| 2142 | ", |
| 2143 | $user->ID, |
| 2144 | '_give_user_address' |
| 2145 | ) |
| 2146 | ); |
| 2147 | |
| 2148 | if ( ! empty( $address ) ) { |
| 2149 | $address = maybe_unserialize( $address ); |
| 2150 | $donor->add_address( 'personal', $address ); |
| 2151 | $donor->add_address( 'billing[]', $address ); |
| 2152 | |
| 2153 | |
| 2154 | // @todo: delete _give_user_address from user meta after releases 2.0. |
| 2155 | /*delete_user_meta( $user->ID, '_give_user_address' );*/ |
| 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | } else { |
| 2160 | // The Update Ran. |
| 2161 | give_set_upgrade_complete( 'v20_upgrades_user_address' ); |
| 2162 | } |
| 2163 | |
| 2164 | } |
| 2165 | |
| 2166 | /** |
| 2167 | * Upgrade logs data. |
| 2168 | * |
| 2169 | * @since 2.0 |
| 2170 | * @global wpdb $wpdb |
| 2171 | * @return void |
| 2172 | */ |
| 2173 | function give_v20_rename_donor_tables_callback() { |
| 2174 | global $wpdb; |
| 2175 | |
| 2176 | /* @var Give_Updates $give_updates */ |
| 2177 | $give_updates = Give_Updates::get_instance(); |
| 2178 | |
| 2179 | $tables = array( |
| 2180 | "{$wpdb->prefix}give_customers" => "{$wpdb->prefix}give_donors", |
| 2181 | "{$wpdb->prefix}give_customermeta" => "{$wpdb->prefix}give_donormeta", |
| 2182 | ); |
| 2183 | |
| 2184 | // Alter customer table |
| 2185 | foreach ( $tables as $old_table => $new_table ) { |
| 2186 | if ( |
| 2187 | $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $old_table ) ) && |
| 2188 | ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", $new_table ) ) |
| 2189 | ) { |
| 2190 | $wpdb->query( "ALTER TABLE {$old_table} RENAME TO {$new_table}" ); |
| 2191 | |
| 2192 | if ( "{$wpdb->prefix}give_donormeta" === $new_table ) { |
| 2193 | $wpdb->query( "ALTER TABLE {$new_table} CHANGE COLUMN customer_id donor_id bigint(20)" ); |
| 2194 | } |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | $give_updates->percentage = 100; |
| 2199 | |
| 2200 | // No more forms found, finish up. |
| 2201 | give_set_upgrade_complete( 'v20_rename_donor_tables' ); |
| 2202 | |
| 2203 | // Re initiate donor classes. |
| 2204 | Give()->donors = new Give_DB_Donors(); |
| 2205 | Give()->donor_meta = new Give_DB_Donor_Meta(); |
| 2206 | } |
| 2207 | |
| 2208 | |
| 2209 | /** |
| 2210 | * Create missing meta tables. |
| 2211 | * |
| 2212 | * @since 2.0.1 |
| 2213 | * @global wpdb $wpdb |
| 2214 | * @return void |
| 2215 | */ |
| 2216 | function give_v201_create_tables() { |
| 2217 | global $wpdb; |
| 2218 | |
| 2219 | if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_paymentmeta" ) ) ) { |
| 2220 | Give()->payment_meta->create_table(); |
| 2221 | } |
| 2222 | |
| 2223 | if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_formmeta" ) ) ) { |
| 2224 | Give()->form_meta->create_table(); |
| 2225 | } |
| 2226 | |
| 2227 | if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_logs" ) ) ) { |
| 2228 | Give()->logs->log_db->create_table(); |
| 2229 | } |
| 2230 | |
| 2231 | if ( ! $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_logmeta" ) ) ) { |
| 2232 | Give()->logs->logmeta_db->create_table(); |
| 2233 | } |
| 2234 | } |
| 2235 | |
| 2236 | /** |
| 2237 | * Upgrade payment metadata for new metabox settings. |
| 2238 | * |
| 2239 | * @since 2.0.1 |
| 2240 | * @global wpdb $wpdb |
| 2241 | * @return void |
| 2242 | */ |
| 2243 | function give_v201_upgrades_payment_metadata_callback() { |
| 2244 | global $wpdb, $post; |
| 2245 | $give_updates = Give_Updates::get_instance(); |
| 2246 | give_v201_create_tables(); |
| 2247 | |
| 2248 | $payments = $wpdb->get_col( |
| 2249 | " |
| 2250 | SELECT ID FROM $wpdb->posts |
| 2251 | WHERE 1=1 |
| 2252 | AND ( |
| 2253 | $wpdb->posts.post_date >= '2018-01-08 00:00:00' |
| 2254 | ) |
| 2255 | AND $wpdb->posts.post_type = 'give_payment' |
| 2256 | AND {$wpdb->posts}.post_status IN ('" . implode( "','", array_keys( give_get_payment_statuses() ) ) . "') |
| 2257 | ORDER BY $wpdb->posts.post_date ASC |
| 2258 | LIMIT 100 |
| 2259 | OFFSET " . $give_updates->get_offset( 100 ) |
| 2260 | ); |
| 2261 | |
| 2262 | if ( ! empty( $payments ) ) { |
| 2263 | $give_updates->set_percentage( give_get_total_post_type_count( 'give_payment' ), ( $give_updates->step * 100 ) ); |
| 2264 | |
| 2265 | foreach ( $payments as $payment_id ) { |
| 2266 | $post = get_post( $payment_id ); |
| 2267 | setup_postdata( $post ); |
| 2268 | |
| 2269 | // Do not add new meta keys if already refactored. |
| 2270 | if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key=%s", $post->ID, '_give_payment_donor_id' ) ) ) { |
| 2271 | continue; |
| 2272 | } |
| 2273 | |
| 2274 | |
| 2275 | // Split _give_payment_meta meta. |
| 2276 | // @todo Remove _give_payment_meta after releases 2.0 |
| 2277 | $payment_meta = give_get_meta( $post->ID, '_give_payment_meta', true ); |
| 2278 | |
| 2279 | if ( ! empty( $payment_meta ) ) { |
| 2280 | _give_20_bc_split_and_save_give_payment_meta( $post->ID, $payment_meta ); |
| 2281 | } |
| 2282 | |
| 2283 | $deprecated_meta_keys = array( |
| 2284 | '_give_payment_customer_id' => '_give_payment_donor_id', |
| 2285 | '_give_payment_user_email' => '_give_payment_donor_email', |
| 2286 | '_give_payment_user_ip' => '_give_payment_donor_ip', |
| 2287 | ); |
| 2288 | |
| 2289 | foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) { |
| 2290 | // Do not add new meta key if already exist. |
| 2291 | if ( $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id=%d AND meta_key=%s", $post->ID, $new_meta_key ) ) ) { |
| 2292 | continue; |
| 2293 | } |
| 2294 | |
| 2295 | $wpdb->insert( |
| 2296 | $wpdb->postmeta, |
| 2297 | array( |
| 2298 | 'post_id' => $post->ID, |
| 2299 | 'meta_key' => $new_meta_key, |
| 2300 | 'meta_value' => give_get_meta( $post->ID, $old_meta_key, true ), |
| 2301 | ) |
| 2302 | ); |
| 2303 | } |
| 2304 | |
| 2305 | // Bailout |
| 2306 | if ( $donor_id = give_get_meta( $post->ID, '_give_payment_donor_id', true ) ) { |
| 2307 | /* @var Give_Donor $donor */ |
| 2308 | $donor = new Give_Donor( $donor_id ); |
| 2309 | |
| 2310 | $address['line1'] = give_get_meta( $post->ID, '_give_donor_billing_address1', true, '' ); |
| 2311 | $address['line2'] = give_get_meta( $post->ID, '_give_donor_billing_address2', true, '' ); |
| 2312 | $address['city'] = give_get_meta( $post->ID, '_give_donor_billing_city', true, '' ); |
| 2313 | $address['state'] = give_get_meta( $post->ID, '_give_donor_billing_state', true, '' ); |
| 2314 | $address['zip'] = give_get_meta( $post->ID, '_give_donor_billing_zip', true, '' ); |
| 2315 | $address['country'] = give_get_meta( $post->ID, '_give_donor_billing_country', true, '' ); |
| 2316 | |
| 2317 | // Save address. |
| 2318 | $donor->add_address( 'billing[]', $address ); |
| 2319 | } |
| 2320 | |
| 2321 | }// End while(). |
| 2322 | |
| 2323 | wp_reset_postdata(); |
| 2324 | } else { |
| 2325 | // @todo Delete user id meta after releases 2.0 |
| 2326 | // $wpdb->get_var( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key=%s", '_give_payment_user_id' ) ); |
| 2327 | |
| 2328 | // No more forms found, finish up. |
| 2329 | give_set_upgrade_complete( 'v201_upgrades_payment_metadata' ); |
| 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * Move payment and form metadata to new table |
| 2335 | * |
| 2336 | * @since 2.0.1 |
| 2337 | * @return void |
| 2338 | */ |
| 2339 | function give_v201_move_metadata_into_new_table_callback() { |
| 2340 | global $wpdb, $post; |
| 2341 | $give_updates = Give_Updates::get_instance(); |
| 2342 | give_v201_create_tables(); |
| 2343 | |
| 2344 | $payments = $wpdb->get_col( |
| 2345 | " |
| 2346 | SELECT ID FROM $wpdb->posts |
| 2347 | WHERE 1=1 |
| 2348 | AND ( $wpdb->posts.post_type = 'give_payment' OR $wpdb->posts.post_type = 'give_forms' ) |
| 2349 | AND {$wpdb->posts}.post_status IN ('" . implode( "','", array_keys( give_get_payment_statuses() ) ) . "') |
| 2350 | ORDER BY $wpdb->posts.post_date ASC |
| 2351 | LIMIT 100 |
| 2352 | OFFSET " . $give_updates->get_offset( 100 ) |
| 2353 | ); |
| 2354 | |
| 2355 | if ( ! empty( $payments ) ) { |
| 2356 | $give_updates->set_percentage( give_get_total_post_type_count( array( |
| 2357 | 'give_forms', |
| 2358 | 'give_payment', |
| 2359 | ) ), $give_updates->step * 100 ); |
| 2360 | |
| 2361 | foreach ( $payments as $payment_id ) { |
| 2362 | $post = get_post( $payment_id ); |
| 2363 | setup_postdata( $post ); |
| 2364 | |
| 2365 | $meta_data = $wpdb->get_results( |
| 2366 | $wpdb->prepare( |
| 2367 | "SELECT * FROM $wpdb->postmeta where post_id=%d", |
| 2368 | get_the_ID() |
| 2369 | ), |
| 2370 | ARRAY_A |
| 2371 | ); |
| 2372 | |
| 2373 | if ( ! empty( $meta_data ) ) { |
| 2374 | foreach ( $meta_data as $index => $data ) { |
| 2375 | // Check for duplicate meta values. |
| 2376 | if ( $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . ( 'give_forms' === $post->post_type ? $wpdb->formmeta : $wpdb->paymentmeta ) . " WHERE meta_id=%d", $data['meta_id'] ), ARRAY_A ) ) { |
| 2377 | continue; |
| 2378 | } |
| 2379 | |
| 2380 | switch ( $post->post_type ) { |
| 2381 | case 'give_forms': |
| 2382 | $data['form_id'] = $data['post_id']; |
| 2383 | unset( $data['post_id'] ); |
| 2384 | |
| 2385 | Give()->form_meta->insert( $data ); |
| 2386 | // @todo: delete form meta from post meta table after releases 2.0. |
| 2387 | /*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
| 2388 | |
| 2389 | break; |
| 2390 | |
| 2391 | case 'give_payment': |
| 2392 | $data['payment_id'] = $data['post_id']; |
| 2393 | unset( $data['post_id'] ); |
| 2394 | |
| 2395 | Give()->payment_meta->insert( $data ); |
| 2396 | |
| 2397 | // @todo: delete donation meta from post meta table after releases 2.0. |
| 2398 | /*delete_post_meta( get_the_ID(), $data['meta_key'] );*/ |
| 2399 | |
| 2400 | break; |
| 2401 | } |
| 2402 | } |
| 2403 | } |
| 2404 | |
| 2405 | }// End while(). |
| 2406 | |
| 2407 | wp_reset_postdata(); |
| 2408 | } else { |
| 2409 | // No more forms found, finish up. |
| 2410 | give_set_upgrade_complete( 'v201_move_metadata_into_new_table' ); |
| 2411 | } |
| 2412 | |
| 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * Move data to new log table. |
| 2417 | * |
| 2418 | * @since 2.0.1 |
| 2419 | * @return void |
| 2420 | */ |
| 2421 | function give_v201_logs_upgrades_callback() { |
| 2422 | global $wpdb, $post; |
| 2423 | $give_updates = Give_Updates::get_instance(); |
| 2424 | give_v201_create_tables(); |
| 2425 | |
| 2426 | $logs = $wpdb->get_col( |
| 2427 | " |
| 2428 | SELECT ID FROM $wpdb->posts |
| 2429 | WHERE 1=1 |
| 2430 | AND $wpdb->posts.post_type = 'give_log' |
| 2431 | AND {$wpdb->posts}.post_status IN ('" . implode( "','", array_keys( give_get_payment_statuses() ) ) . "') |
| 2432 | ORDER BY $wpdb->posts.post_date ASC |
| 2433 | LIMIT 100 |
| 2434 | OFFSET " . $give_updates->get_offset( 100 ) |
| 2435 | ); |
| 2436 | |
| 2437 | if ( ! empty( $logs ) ) { |
| 2438 | $give_updates->set_percentage( give_get_total_post_type_count( 'give_log' ), $give_updates->step * 100 ); |
| 2439 | |
| 2440 | foreach ( $logs as $log_id ) { |
| 2441 | $post = get_post( $log_id ); |
| 2442 | setup_postdata( $post ); |
| 2443 | |
| 2444 | if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_logs WHERE ID=%d", $post->ID ) ) ) { |
| 2445 | continue; |
| 2446 | } |
| 2447 | |
| 2448 | $term = get_the_terms( $post->ID, 'give_log_type' ); |
| 2449 | $term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array(); |
| 2450 | $term_name = ! empty( $term ) ? $term->slug : ''; |
| 2451 | |
| 2452 | $log_data = array( |
| 2453 | 'ID' => $post->ID, |
| 2454 | 'log_title' => $post->post_title, |
| 2455 | 'log_content' => $post->post_content, |
| 2456 | 'log_parent' => 0, |
| 2457 | 'log_type' => $term_name, |
| 2458 | 'log_date' => $post->post_date, |
| 2459 | 'log_date_gmt' => $post->post_date_gmt, |
| 2460 | ); |
| 2461 | $log_meta = array(); |
| 2462 | |
| 2463 | if ( $old_log_meta = get_post_meta( $post->ID ) ) { |
| 2464 | foreach ( $old_log_meta as $meta_key => $meta_value ) { |
| 2465 | switch ( $meta_key ) { |
| 2466 | case '_give_log_payment_id': |
| 2467 | $log_data['log_parent'] = current( $meta_value ); |
| 2468 | $log_meta['_give_log_form_id'] = $post->post_parent; |
| 2469 | break; |
| 2470 | |
| 2471 | default: |
| 2472 | $log_meta[ $meta_key ] = current( $meta_value ); |
| 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | |
| 2477 | if ( 'api_request' === $term_name ) { |
| 2478 | $log_meta['_give_log_api_query'] = $post->post_excerpt; |
| 2479 | } |
| 2480 | |
| 2481 | $wpdb->insert( "{$wpdb->prefix}give_logs", $log_data ); |
| 2482 | |
| 2483 | if ( ! empty( $log_meta ) ) { |
| 2484 | foreach ( $log_meta as $meta_key => $meta_value ) { |
| 2485 | Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value ); |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | $logIDs[] = $post->ID; |
| 2490 | }// End while(). |
| 2491 | |
| 2492 | wp_reset_postdata(); |
| 2493 | } else { |
| 2494 | // Delete log cache. |
| 2495 | Give()->logs->delete_cache(); |
| 2496 | |
| 2497 | // No more forms found, finish up. |
| 2498 | give_set_upgrade_complete( 'v201_logs_upgrades' ); |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | |
| 2503 | /** |
| 2504 | * Add missing donor. |
| 2505 | * |
| 2506 | * @since 2.0.1 |
| 2507 | * @return void |
| 2508 | */ |
| 2509 | function give_v201_add_missing_donors_callback() { |
| 2510 | global $wpdb; |
| 2511 | give_v201_create_tables(); |
| 2512 | |
| 2513 | if ( $wpdb->query( $wpdb->prepare( "SHOW TABLES LIKE %s", "{$wpdb->prefix}give_customers" ) ) ) { |
| 2514 | $customers = wp_list_pluck( $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}give_customers" ), 'id' ); |
| 2515 | $donors = wp_list_pluck( $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}give_donors" ), 'id' ); |
| 2516 | $donor_data = array(); |
| 2517 | |
| 2518 | if ( $missing_donors = array_diff( $customers, $donors ) ) { |
| 2519 | foreach ( $missing_donors as $donor_id ) { |
| 2520 | $donor_data[] = array( |
| 2521 | 'info' => $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_customers WHERE id=%d", $donor_id ) ), |
| 2522 | 'meta' => $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_customermeta WHERE customer_id=%d", $donor_id ) ), |
| 2523 | |
| 2524 | ); |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | if ( ! empty( $donor_data ) ) { |
| 2529 | $donor_table_name = Give()->donors->table_name; |
| 2530 | $donor_meta_table_name = Give()->donor_meta->table_name; |
| 2531 | |
| 2532 | Give()->donors->table_name = "{$wpdb->prefix}give_donors"; |
| 2533 | Give()->donor_meta->table_name = "{$wpdb->prefix}give_donormeta"; |
| 2534 | |
| 2535 | foreach ( $donor_data as $donor ) { |
| 2536 | $donor['info'][0] = (array) $donor['info'][0]; |
| 2537 | |
| 2538 | // Prevent duplicate meta id issue. |
| 2539 | if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_donors WHERE id=%d", $donor['info'][0]['id'] ) ) ) { |
| 2540 | continue; |
| 2541 | } |
| 2542 | |
| 2543 | $donor_id = Give()->donors->add( $donor['info'][0] ); |
| 2544 | |
| 2545 | if ( ! empty( $donor['meta'] ) ) { |
| 2546 | foreach ( $donor['meta'] as $donor_meta ) { |
| 2547 | $donor_meta = (array) $donor_meta; |
| 2548 | |
| 2549 | // Prevent duplicate meta id issue. |
| 2550 | if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_donormeta WHERE meta_id=%d", $donor_meta['meta_id'] ) ) ) { |
| 2551 | unset( $donor_meta['meta_id'] ); |
| 2552 | } |
| 2553 | |
| 2554 | $donor_meta['donor_id'] = $donor_meta['customer_id']; |
| 2555 | unset( $donor_meta['customer_id'] ); |
| 2556 | |
| 2557 | Give()->donor_meta->insert( $donor_meta ); |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | /** |
| 2562 | * Fix donor name and address |
| 2563 | */ |
| 2564 | $address = $wpdb->get_var( |
| 2565 | $wpdb->prepare( |
| 2566 | " |
| 2567 | SELECT meta_value FROM {$wpdb->usermeta} |
| 2568 | WHERE user_id=%s |
| 2569 | AND meta_key=%s |
| 2570 | ", |
| 2571 | $donor['info'][0]['user_id'], |
| 2572 | '_give_user_address' |
| 2573 | ) |
| 2574 | ); |
| 2575 | |
| 2576 | $donor = new Give_Donor( $donor_id ); |
| 2577 | |
| 2578 | if ( ! empty( $address ) ) { |
| 2579 | $address = maybe_unserialize( $address ); |
| 2580 | $donor->add_address( 'personal', $address ); |
| 2581 | $donor->add_address( 'billing[]', $address ); |
| 2582 | } |
| 2583 | |
| 2584 | $donor_name = explode( ' ', $donor->name, 2 ); |
| 2585 | $donor_first_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_first_name' ); |
| 2586 | $donor_last_name = Give()->donor_meta->get_meta( $donor->id, '_give_donor_last_name' ); |
| 2587 | |
| 2588 | // If first name meta of donor is not created, then create it. |
| 2589 | if ( ! $donor_first_name && isset( $donor_name[0] ) ) { |
| 2590 | Give()->donor_meta->add_meta( $donor->id, '_give_donor_first_name', $donor_name[0] ); |
| 2591 | } |
| 2592 | |
| 2593 | // If last name meta of donor is not created, then create it. |
| 2594 | if ( ! $donor_last_name && isset( $donor_name[1] ) ) { |
| 2595 | Give()->donor_meta->add_meta( $donor->id, '_give_donor_last_name', $donor_name[1] ); |
| 2596 | } |
| 2597 | |
| 2598 | // If Donor is connected with WP User then update user meta. |
| 2599 | if ( $donor->user_id ) { |
| 2600 | if ( isset( $donor_name[0] ) ) { |
| 2601 | update_user_meta( $donor->user_id, 'first_name', $donor_name[0] ); |
| 2602 | } |
| 2603 | if ( isset( $donor_name[1] ) ) { |
| 2604 | update_user_meta( $donor->user_id, 'last_name', $donor_name[1] ); |
| 2605 | } |
| 2606 | } |
| 2607 | } |
| 2608 | |
| 2609 | Give()->donors->table_name = $donor_table_name; |
| 2610 | Give()->donor_meta->table_name = $donor_meta_table_name; |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | Give_Updates::get_instance()->percentage = 100; |
| 2615 | give_set_upgrade_complete( 'v201_add_missing_donors' ); |
| 2616 | } |
| 2617 | |
| 2618 | |
| 2619 | /** |
| 2620 | * Version 2.0.3 automatic updates |
| 2621 | * |
| 2622 | * @since 2.0.3 |
| 2623 | */ |
| 2624 | function give_v203_upgrades() { |
| 2625 | global $wpdb; |
| 2626 | |
| 2627 | // Do not auto load option. |
| 2628 | $wpdb->update( $wpdb->options, array( 'autoload' => 'no' ), array( 'option_name' => 'give_completed_upgrades' ) ); |
| 2629 | |
| 2630 | // Remove from cache. |
| 2631 | $all_options = wp_load_alloptions(); |
| 2632 | |
| 2633 | if ( isset( $all_options['give_completed_upgrades'] ) ) { |
| 2634 | unset( $all_options['give_completed_upgrades'] ); |
| 2635 | wp_cache_set( 'alloptions', $all_options, 'options' ); |
| 2636 | } |
| 2637 | |
| 2638 | } |
| 2639 | |
| 2640 | /** |
| 2641 | * Upgrade routine for 2.1 to set form closed status for all the donation forms. |
| 2642 | * |
| 2643 | * @since 2.1 |
| 2644 | */ |
| 2645 | function give_v210_verify_form_status_upgrades_callback() { |
| 2646 | |
| 2647 | $give_updates = Give_Updates::get_instance(); |
| 2648 | |
| 2649 | // form query. |
| 2650 | $donation_forms = new WP_Query( array( |
| 2651 | 'paged' => $give_updates->step, |
| 2652 | 'status' => 'any', |
| 2653 | 'order' => 'ASC', |
| 2654 | 'post_type' => 'give_forms', |
| 2655 | 'posts_per_page' => 20, |
| 2656 | ) |
| 2657 | ); |
| 2658 | |
| 2659 | if ( $donation_forms->have_posts() ) { |
| 2660 | $give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
| 2661 | |
| 2662 | while ( $donation_forms->have_posts() ) { |
| 2663 | $donation_forms->the_post(); |
| 2664 | $form_id = get_the_ID(); |
| 2665 | |
| 2666 | $form_closed_status = give_get_meta( $form_id, '_give_form_status', true ); |
| 2667 | if ( empty( $form_closed_status ) ) { |
| 2668 | give_set_form_closed_status( $form_id ); |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | /* Restore original Post Data */ |
| 2673 | wp_reset_postdata(); |
| 2674 | |
| 2675 | } else { |
| 2676 | |
| 2677 | // The Update Ran. |
| 2678 | give_set_upgrade_complete( 'v210_verify_form_status_upgrades' ); |
| 2679 | } |
| 2680 | |
| 2681 | } |
| 2682 | |
| 2683 | /** |
| 2684 | * Upgrade routine for 2.1.3 to delete meta which is not attach to any donation. |
| 2685 | * |
| 2686 | * @since 2.1 |
| 2687 | */ |
| 2688 | function give_v213_delete_donation_meta_callback() { |
| 2689 | global $wpdb; |
| 2690 | $give_updates = Give_Updates::get_instance(); |
| 2691 | $donation_meta_table = Give()->payment_meta->table_name; |
| 2692 | |
| 2693 | $donations = $wpdb->get_col( |
| 2694 | " |
| 2695 | SELECT DISTINCT payment_id |
| 2696 | FROM {$donation_meta_table} |
| 2697 | LIMIT 20 |
| 2698 | OFFSET {$give_updates->get_offset( 20 )} |
| 2699 | " |
| 2700 | ); |
| 2701 | |
| 2702 | if ( ! empty( $donations ) ) { |
| 2703 | foreach ( $donations as $donation ) { |
| 2704 | $donation_obj = get_post( $donation ); |
| 2705 | |
| 2706 | if ( ! $donation_obj instanceof WP_Post ) { |
| 2707 | Give()->payment_meta->delete_all_meta( $donation ); |
| 2708 | } |
| 2709 | } |
| 2710 | } else { |
| 2711 | |
| 2712 | // The Update Ran. |
| 2713 | give_set_upgrade_complete( 'v213_delete_donation_meta' ); |
| 2714 | } |
| 2715 | |
| 2716 | } |
| 2717 | |
| 2718 | /** |
| 2719 | * Adds 'view_give_payments' capability to 'give_manager' user role. |
| 2720 | * |
| 2721 | * @since 2.1.5 |
| 2722 | */ |
| 2723 | function give_v215_update_donor_user_roles_callback() { |
| 2724 | |
| 2725 | $role = get_role( 'give_manager' ); |
| 2726 | $role->add_cap( 'view_give_payments' ); |
| 2727 | |
| 2728 | give_set_upgrade_complete( 'v215_update_donor_user_roles' ); |
| 2729 | } |
| 2730 |