| @@ -2,18 +2,20 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Upgrade Functions |
| 4 | 4 | * |
| 5 | 5 | * @package Give |
| 6 | - * @subpackage Admin/Upgrades | |
| 7 | - * @copyright Copyright (c) 2016, GiveWP | |
| 8 | - * @license https://opensource.org/licenses/gpl-license GNU Public License | |
| 9 | 6 | * @since 1.0 |
| 10 | 7 | * |
| 11 | 8 | * NOTICE: When adding new upgrade notices, please be sure to put the action into the upgrades array during install: |
| 12 | 9 | * /includes/install.php @ Appox Line 156 |
| 10 | + * @copyright Copyright (c) 2016, GiveWP | |
| 11 | + * @license https://opensource.org/licenses/gpl-license GNU Public License | |
| 12 | + * @subpackage Admin/Upgrades | |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | // Exit if accessed directly. |
| 16 | +use Give\Helpers\Gateways\Stripe; | |
| 17 | + | |
| 16 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | 19 | exit; |
| 18 | 20 | } |
| 19 | 21 | |
| @@ -24,9 +26,9 @@ | ||
| 24 | 26 | * @return void |
| 25 | 27 | */ |
| 26 | 28 | function give_do_automatic_upgrades() { |
| 27 | 29 | $did_upgrade = false; |
| 28 | - $give_version = preg_replace( '/[^0-9.].*/', '', get_option( 'give_version' ) ); | |
| 30 | + $give_version = preg_replace( '/[^0-9.].*/', '', Give_Cache_Setting::get_option( 'give_version' ) ); | |
| 29 | 31 | |
| 30 | 32 | if ( ! $give_version ) { |
| 31 | 33 | // 1.0 is the first version to use this option so we must add it. |
| 32 | 34 | $give_version = '1.0'; |
| @@ -81,9 +83,9 @@ | ||
| 81 | 83 | case version_compare( $give_version, '2.0.1', '<' ): |
| 82 | 84 | // Do nothing on fresh install. |
| 83 | 85 | if ( ! doing_action( 'give_upgrades' ) ) { |
| 84 | 86 | give_v201_create_tables(); |
| 85 | - Give_Updates::get_instance()->__health_background_update( Give_Updates::get_instance() ); | |
| 87 | + Give_Updates::get_instance()->health_background_update( Give_Updates::get_instance() ); | |
| 86 | 88 | Give_Updates::$background_updater->dispatch(); |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | 91 | $did_upgrade = true; |
| @@ -90,14 +92,14 @@ | ||
| 90 | 92 | |
| 91 | 93 | case version_compare( $give_version, '2.0.2', '<' ): |
| 92 | 94 | // Remove 2.0.1 update to rerun on 2.0.2 |
| 93 | 95 | $completed_upgrades = give_get_completed_upgrades(); |
| 94 | - $v201_updates = array( | |
| 96 | + $v201_updates = [ | |
| 95 | 97 | 'v201_upgrades_payment_metadata', |
| 96 | 98 | 'v201_add_missing_donors', |
| 97 | 99 | 'v201_move_metadata_into_new_table', |
| 98 | 100 | 'v201_logs_upgrades', |
| 99 | - ); | |
| 101 | + ]; | |
| 100 | 102 | |
| 101 | 103 | foreach ( $v201_updates as $v201_update ) { |
| 102 | 104 | if ( in_array( $v201_update, $completed_upgrades ) ) { |
| 103 | 105 | unset( $completed_upgrades[ array_search( $v201_update, $completed_upgrades ) ] ); |
| @@ -108,9 +110,9 @@ | ||
| 108 | 110 | |
| 109 | 111 | // Do nothing on fresh install. |
| 110 | 112 | if ( ! doing_action( 'give_upgrades' ) ) { |
| 111 | 113 | give_v201_create_tables(); |
| 112 | - Give_Updates::get_instance()->__health_background_update( Give_Updates::get_instance() ); | |
| 114 | + Give_Updates::get_instance()->health_background_update( Give_Updates::get_instance() ); | |
| 113 | 115 | Give_Updates::$background_updater->dispatch(); |
| 114 | 116 | } |
| 115 | 117 | |
| 116 | 118 | $did_upgrade = true; |
| @@ -129,17 +131,45 @@ | ||
| 129 | 131 | |
| 130 | 132 | case version_compare( $give_version, '2.3.0', '<' ): |
| 131 | 133 | give_v230_upgrades(); |
| 132 | 134 | $did_upgrade = true; |
| 135 | + | |
| 136 | + case version_compare( $give_version, '2.5.0', '<' ): | |
| 137 | + give_v250_upgrades(); | |
| 138 | + $did_upgrade = true; | |
| 139 | + | |
| 140 | + case version_compare( $give_version, '2.5.8', '<' ): | |
| 141 | + give_v258_upgrades(); | |
| 142 | + $did_upgrade = true; | |
| 143 | + | |
| 144 | + case version_compare( $give_version, '2.5.11', '<' ): | |
| 145 | + give_v2511_upgrades(); | |
| 146 | + $did_upgrade = true; | |
| 147 | + | |
| 148 | + case version_compare( $give_version, '2.6.3', '<' ): | |
| 149 | + give_v263_upgrades(); | |
| 150 | + $did_upgrade = true; | |
| 151 | + | |
| 152 | + case version_compare( $give_version, '2.7.0', '<' ): | |
| 153 | + // Flush rewrite rules. It will help to store register route for embed form. | |
| 154 | + flush_rewrite_rules(); | |
| 155 | + | |
| 156 | + give_v270_upgrades(); | |
| 157 | + | |
| 158 | + $did_upgrade = true; | |
| 159 | + | |
| 160 | + case version_compare( $give_version, '2.9.0', '<' ): | |
| 161 | + give_v290_remove_old_export_files(); | |
| 162 | + $did_upgrade = true; | |
| 133 | 163 | } |
| 134 | 164 | |
| 135 | - if ( $did_upgrade ) { | |
| 136 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ), false ); | |
| 165 | + if ( $did_upgrade || version_compare( $give_version, GIVE_VERSION, '<' ) ) { | |
| 166 | + update_option( 'give_version', GIVE_VERSION, false ); | |
| 137 | 167 | } |
| 138 | 168 | } |
| 139 | 169 | |
| 140 | -add_action( 'admin_init', 'give_do_automatic_upgrades' ); | |
| 141 | -add_action( 'give_upgrades', 'give_do_automatic_upgrades' ); | |
| 170 | +add_action( 'admin_init', 'give_do_automatic_upgrades', 0 ); | |
| 171 | +add_action( 'give_upgrades', 'give_do_automatic_upgrades', 0 ); | |
| 142 | 172 | |
| 143 | 173 | /** |
| 144 | 174 | * Display Upgrade Notices. |
| 145 | 175 | * |
| @@ -154,308 +184,305 @@ | ||
| 154 | 184 | */ |
| 155 | 185 | function give_show_upgrade_notices( $give_updates ) { |
| 156 | 186 | // v1.3.2 Upgrades |
| 157 | 187 | $give_updates->register( |
| 158 | - array( | |
| 188 | + [ | |
| 159 | 189 | 'id' => 'upgrade_give_payment_customer_id', |
| 160 | 190 | 'version' => '1.3.2', |
| 161 | 191 | 'callback' => 'give_v132_upgrade_give_payment_customer_id', |
| 162 | - ) | |
| 192 | + ] | |
| 163 | 193 | ); |
| 164 | 194 | |
| 165 | 195 | // v1.3.4 Upgrades ensure the user has gone through 1.3.4. |
| 166 | 196 | $give_updates->register( |
| 167 | - array( | |
| 197 | + [ | |
| 168 | 198 | 'id' => 'upgrade_give_offline_status', |
| 169 | 199 | 'depend' => 'upgrade_give_payment_customer_id', |
| 170 | 200 | 'version' => '1.3.4', |
| 171 | 201 | 'callback' => 'give_v134_upgrade_give_offline_status', |
| 172 | - ) | |
| 202 | + ] | |
| 173 | 203 | ); |
| 174 | 204 | |
| 175 | 205 | // v1.8 form metadata upgrades. |
| 176 | 206 | $give_updates->register( |
| 177 | - array( | |
| 207 | + [ | |
| 178 | 208 | 'id' => 'v18_upgrades_form_metadata', |
| 179 | 209 | 'version' => '1.8', |
| 180 | 210 | 'callback' => 'give_v18_upgrades_form_metadata', |
| 181 | - ) | |
| 211 | + ] | |
| 182 | 212 | ); |
| 183 | 213 | |
| 184 | 214 | // v1.8.9 Upgrades |
| 185 | 215 | $give_updates->register( |
| 186 | - array( | |
| 216 | + [ | |
| 187 | 217 | 'id' => 'v189_upgrades_levels_post_meta', |
| 188 | 218 | 'version' => '1.8.9', |
| 189 | 219 | 'callback' => 'give_v189_upgrades_levels_post_meta_callback', |
| 190 | - ) | |
| 220 | + ] | |
| 191 | 221 | ); |
| 192 | 222 | |
| 193 | 223 | // v1.8.12 Upgrades |
| 194 | 224 | $give_updates->register( |
| 195 | - array( | |
| 225 | + [ | |
| 196 | 226 | 'id' => 'v1812_update_amount_values', |
| 197 | 227 | 'version' => '1.8.12', |
| 198 | 228 | 'callback' => 'give_v1812_update_amount_values_callback', |
| 199 | - ) | |
| 229 | + ] | |
| 200 | 230 | ); |
| 201 | 231 | |
| 202 | 232 | // v1.8.12 Upgrades |
| 203 | 233 | $give_updates->register( |
| 204 | - array( | |
| 234 | + [ | |
| 205 | 235 | 'id' => 'v1812_update_donor_purchase_values', |
| 206 | 236 | 'version' => '1.8.12', |
| 207 | 237 | 'callback' => 'give_v1812_update_donor_purchase_value_callback', |
| 208 | - ) | |
| 238 | + ] | |
| 209 | 239 | ); |
| 210 | 240 | |
| 211 | 241 | // v1.8.13 Upgrades for donor |
| 212 | 242 | $give_updates->register( |
| 213 | - array( | |
| 243 | + [ | |
| 214 | 244 | 'id' => 'v1813_update_donor_user_roles', |
| 215 | 245 | 'version' => '1.8.13', |
| 216 | 246 | 'callback' => 'give_v1813_update_donor_user_roles_callback', |
| 217 | - ) | |
| 247 | + ] | |
| 218 | 248 | ); |
| 219 | 249 | |
| 220 | 250 | // v1.8.17 Upgrades for donations. |
| 221 | 251 | $give_updates->register( |
| 222 | - array( | |
| 252 | + [ | |
| 223 | 253 | 'id' => 'v1817_update_donation_iranian_currency_code', |
| 224 | 254 | 'version' => '1.8.17', |
| 225 | 255 | 'callback' => 'give_v1817_update_donation_iranian_currency_code', |
| 226 | - ) | |
| 256 | + ] | |
| 227 | 257 | ); |
| 228 | 258 | |
| 229 | 259 | // v1.8.17 Upgrades for cleanup of user roles. |
| 230 | 260 | $give_updates->register( |
| 231 | - array( | |
| 261 | + [ | |
| 232 | 262 | 'id' => 'v1817_cleanup_user_roles', |
| 233 | 263 | 'version' => '1.8.17', |
| 234 | 264 | 'callback' => 'give_v1817_cleanup_user_roles', |
| 235 | - ) | |
| 265 | + ] | |
| 236 | 266 | ); |
| 237 | 267 | |
| 238 | 268 | // v1.8.18 Upgrades for assigning custom amount to existing set donations. |
| 239 | 269 | $give_updates->register( |
| 240 | - array( | |
| 270 | + [ | |
| 241 | 271 | 'id' => 'v1818_assign_custom_amount_set_donation', |
| 242 | 272 | 'version' => '1.8.18', |
| 243 | 273 | 'callback' => 'give_v1818_assign_custom_amount_set_donation', |
| 244 | - ) | |
| 274 | + ] | |
| 245 | 275 | ); |
| 246 | 276 | |
| 247 | 277 | // v1.8.18 Cleanup the Give Worker Role Caps. |
| 248 | 278 | $give_updates->register( |
| 249 | - array( | |
| 279 | + [ | |
| 250 | 280 | 'id' => 'v1818_give_worker_role_cleanup', |
| 251 | 281 | 'version' => '1.8.18', |
| 252 | 282 | 'callback' => 'give_v1818_give_worker_role_cleanup', |
| 253 | - ) | |
| 283 | + ] | |
| 254 | 284 | ); |
| 255 | 285 | |
| 256 | 286 | // v2.0.0 Upgrades |
| 257 | 287 | $give_updates->register( |
| 258 | - array( | |
| 288 | + [ | |
| 259 | 289 | 'id' => 'v20_upgrades_form_metadata', |
| 260 | 290 | 'version' => '2.0.0', |
| 261 | 291 | 'callback' => 'give_v20_upgrades_form_metadata_callback', |
| 262 | - ) | |
| 292 | + ] | |
| 263 | 293 | ); |
| 264 | 294 | |
| 265 | 295 | // v2.0.0 User Address Upgrades |
| 266 | 296 | $give_updates->register( |
| 267 | - array( | |
| 297 | + [ | |
| 268 | 298 | 'id' => 'v20_upgrades_user_address', |
| 269 | 299 | 'version' => '2.0.0', |
| 270 | 300 | 'callback' => 'give_v20_upgrades_user_address', |
| 271 | - ) | |
| 301 | + ] | |
| 272 | 302 | ); |
| 273 | 303 | |
| 274 | 304 | // v2.0.0 Upgrades |
| 275 | 305 | $give_updates->register( |
| 276 | - array( | |
| 306 | + [ | |
| 277 | 307 | 'id' => 'v20_upgrades_payment_metadata', |
| 278 | 308 | 'version' => '2.0.0', |
| 279 | 309 | 'callback' => 'give_v20_upgrades_payment_metadata_callback', |
| 280 | - ) | |
| 310 | + ] | |
| 281 | 311 | ); |
| 282 | 312 | |
| 283 | - // v2.0.0 Upgrades | |
| 284 | - $give_updates->register( | |
| 285 | - array( | |
| 286 | - 'id' => 'v20_logs_upgrades', | |
| 287 | - 'version' => '2.0.0', | |
| 288 | - 'callback' => 'give_v20_logs_upgrades_callback', | |
| 289 | - | |
| 290 | - ) | |
| 291 | - ); | |
| 292 | - | |
| 293 | 313 | // v2.0.0 Donor Name Upgrades |
| 294 | 314 | $give_updates->register( |
| 295 | - array( | |
| 315 | + [ | |
| 296 | 316 | 'id' => 'v20_upgrades_donor_name', |
| 297 | 317 | 'version' => '2.0.0', |
| 298 | 318 | 'callback' => 'give_v20_upgrades_donor_name', |
| 299 | - ) | |
| 319 | + ] | |
| 300 | 320 | ); |
| 301 | 321 | |
| 302 | 322 | // v2.0.0 Upgrades |
| 303 | 323 | $give_updates->register( |
| 304 | - array( | |
| 324 | + [ | |
| 305 | 325 | 'id' => 'v20_move_metadata_into_new_table', |
| 306 | 326 | 'version' => '2.0.0', |
| 307 | 327 | 'callback' => 'give_v20_move_metadata_into_new_table_callback', |
| 308 | - 'depend' => array( 'v20_upgrades_payment_metadata', 'v20_upgrades_form_metadata' ), | |
| 309 | - ) | |
| 328 | + 'depend' => [ 'v20_upgrades_payment_metadata', 'v20_upgrades_form_metadata' ], | |
| 329 | + ] | |
| 310 | 330 | ); |
| 311 | 331 | |
| 312 | 332 | // v2.0.0 Upgrades |
| 313 | 333 | $give_updates->register( |
| 314 | - array( | |
| 334 | + [ | |
| 315 | 335 | 'id' => 'v20_rename_donor_tables', |
| 316 | 336 | 'version' => '2.0.0', |
| 317 | 337 | 'callback' => 'give_v20_rename_donor_tables_callback', |
| 318 | - 'depend' => array( | |
| 338 | + 'depend' => [ | |
| 319 | 339 | 'v20_move_metadata_into_new_table', |
| 320 | - 'v20_logs_upgrades', | |
| 321 | 340 | 'v20_upgrades_form_metadata', |
| 322 | 341 | 'v20_upgrades_payment_metadata', |
| 323 | 342 | 'v20_upgrades_user_address', |
| 324 | 343 | 'v20_upgrades_donor_name', |
| 325 | - ), | |
| 326 | - ) | |
| 344 | + ], | |
| 345 | + ] | |
| 327 | 346 | ); |
| 328 | 347 | |
| 329 | 348 | // v2.0.1 Upgrades |
| 330 | 349 | $give_updates->register( |
| 331 | - array( | |
| 350 | + [ | |
| 332 | 351 | 'id' => 'v201_upgrades_payment_metadata', |
| 333 | 352 | 'version' => '2.0.1', |
| 334 | 353 | 'callback' => 'give_v201_upgrades_payment_metadata_callback', |
| 335 | - ) | |
| 354 | + ] | |
| 336 | 355 | ); |
| 337 | 356 | |
| 338 | 357 | // v2.0.1 Upgrades |
| 339 | 358 | $give_updates->register( |
| 340 | - array( | |
| 359 | + [ | |
| 341 | 360 | 'id' => 'v201_add_missing_donors', |
| 342 | 361 | 'version' => '2.0.1', |
| 343 | 362 | 'callback' => 'give_v201_add_missing_donors_callback', |
| 344 | - ) | |
| 363 | + ] | |
| 345 | 364 | ); |
| 346 | 365 | |
| 347 | 366 | // Run v2.0.0 Upgrades again in 2.0.1 |
| 348 | 367 | $give_updates->register( |
| 349 | - array( | |
| 368 | + [ | |
| 350 | 369 | 'id' => 'v201_move_metadata_into_new_table', |
| 351 | 370 | 'version' => '2.0.1', |
| 352 | 371 | 'callback' => 'give_v201_move_metadata_into_new_table_callback', |
| 353 | - 'depend' => array( 'v201_upgrades_payment_metadata', 'v201_add_missing_donors' ), | |
| 354 | - ) | |
| 372 | + 'depend' => [ 'v201_upgrades_payment_metadata', 'v201_add_missing_donors' ], | |
| 373 | + ] | |
| 355 | 374 | ); |
| 356 | 375 | |
| 357 | - // Run v2.0.0 Upgrades again in 2.0.1 | |
| 358 | - $give_updates->register( | |
| 359 | - array( | |
| 360 | - 'id' => 'v201_logs_upgrades', | |
| 361 | - 'version' => '2.0.1', | |
| 362 | - 'callback' => 'give_v201_logs_upgrades_callback', | |
| 363 | - ) | |
| 364 | - ); | |
| 365 | - | |
| 366 | 376 | // v2.1 Verify Form Status Upgrade. |
| 367 | 377 | $give_updates->register( |
| 368 | - array( | |
| 378 | + [ | |
| 369 | 379 | 'id' => 'v210_verify_form_status_upgrades', |
| 370 | 380 | 'version' => '2.1.0', |
| 371 | 381 | 'callback' => 'give_v210_verify_form_status_upgrades_callback', |
| 372 | - ) | |
| 382 | + ] | |
| 373 | 383 | ); |
| 374 | 384 | |
| 375 | 385 | // v2.1.3 Delete non attached donation meta. |
| 376 | 386 | $give_updates->register( |
| 377 | - array( | |
| 387 | + [ | |
| 378 | 388 | 'id' => 'v213_delete_donation_meta', |
| 379 | 389 | 'version' => '2.1.3', |
| 380 | 390 | 'callback' => 'give_v213_delete_donation_meta_callback', |
| 381 | - 'depends' => array( 'v201_move_metadata_into_new_table' ), | |
| 382 | - ) | |
| 391 | + 'depends' => [ 'v201_move_metadata_into_new_table' ], | |
| 392 | + ] | |
| 383 | 393 | ); |
| 384 | 394 | |
| 385 | 395 | // v2.1.5 Add additional capability to the give_manager role. |
| 386 | 396 | $give_updates->register( |
| 387 | - array( | |
| 397 | + [ | |
| 388 | 398 | 'id' => 'v215_update_donor_user_roles', |
| 389 | 399 | 'version' => '2.1.5', |
| 390 | 400 | 'callback' => 'give_v215_update_donor_user_roles_callback', |
| 391 | - ) | |
| 401 | + ] | |
| 392 | 402 | ); |
| 393 | 403 | |
| 394 | 404 | // v2.2.4 set each donor to anonymous by default. |
| 395 | 405 | $give_updates->register( |
| 396 | - array( | |
| 406 | + [ | |
| 397 | 407 | 'id' => 'v224_update_donor_meta', |
| 398 | 408 | 'version' => '2.2.4', |
| 399 | 409 | 'callback' => 'give_v224_update_donor_meta_callback', |
| 400 | - ) | |
| 410 | + ] | |
| 401 | 411 | ); |
| 402 | 412 | |
| 403 | 413 | // v2.2.4 Associate form IDs with donor meta of anonymous donations. |
| 404 | 414 | $give_updates->register( |
| 405 | - array( | |
| 415 | + [ | |
| 406 | 416 | 'id' => 'v224_update_donor_meta_forms_id', |
| 407 | 417 | 'version' => '2.2.4', |
| 408 | 418 | 'callback' => 'give_v224_update_donor_meta_forms_id_callback', |
| 409 | 419 | 'depend' => 'v224_update_donor_meta', |
| 410 | - ) | |
| 420 | + ] | |
| 411 | 421 | ); |
| 412 | 422 | |
| 413 | 423 | // v2.3.0 Move donor notes to custom comment table. |
| 414 | 424 | $give_updates->register( |
| 415 | - array( | |
| 425 | + [ | |
| 416 | 426 | 'id' => 'v230_move_donor_note', |
| 417 | 427 | 'version' => '2.3.0', |
| 418 | 428 | 'callback' => 'give_v230_move_donor_note_callback', |
| 419 | - ) | |
| 429 | + ] | |
| 420 | 430 | ); |
| 421 | 431 | |
| 422 | 432 | // v2.3.0 Move donation notes to custom comment table. |
| 423 | 433 | $give_updates->register( |
| 424 | - array( | |
| 434 | + [ | |
| 425 | 435 | 'id' => 'v230_move_donation_note', |
| 426 | 436 | 'version' => '2.3.0', |
| 427 | 437 | 'callback' => 'give_v230_move_donation_note_callback', |
| 428 | - ) | |
| 438 | + ] | |
| 429 | 439 | ); |
| 430 | 440 | |
| 431 | 441 | // v2.3.0 remove donor wall related donor meta data. |
| 432 | 442 | $give_updates->register( |
| 433 | - array( | |
| 443 | + [ | |
| 434 | 444 | 'id' => 'v230_delete_donor_wall_related_donor_data', |
| 435 | 445 | 'version' => '2.3.0', |
| 436 | - 'depend' => array( | |
| 446 | + 'depend' => [ | |
| 437 | 447 | 'v224_update_donor_meta', |
| 438 | 448 | 'v224_update_donor_meta_forms_id', |
| 439 | 449 | 'v230_move_donor_note', |
| 440 | - 'v230_move_donation_note' | |
| 441 | - ), | |
| 450 | + 'v230_move_donation_note', | |
| 451 | + ], | |
| 442 | 452 | 'callback' => 'give_v230_delete_dw_related_donor_data_callback', |
| 443 | - ) | |
| 453 | + ] | |
| 444 | 454 | ); |
| 445 | 455 | |
| 446 | 456 | // v2.3.0 remove donor wall related comment meta data. |
| 447 | 457 | $give_updates->register( |
| 448 | - array( | |
| 458 | + [ | |
| 449 | 459 | 'id' => 'v230_delete_donor_wall_related_comment_data', |
| 450 | 460 | 'version' => '2.3.0', |
| 451 | 461 | 'callback' => 'give_v230_delete_dw_related_comment_data_callback', |
| 452 | - 'depend' => array( | |
| 462 | + 'depend' => [ | |
| 453 | 463 | 'v230_move_donor_note', |
| 454 | - 'v230_move_donation_note' | |
| 455 | - ), | |
| 456 | - ) | |
| 464 | + 'v230_move_donation_note', | |
| 465 | + ], | |
| 466 | + ] | |
| 457 | 467 | ); |
| 468 | + | |
| 469 | + // v2.4.0 Update donation form goal progress data. | |
| 470 | + $give_updates->register( | |
| 471 | + [ | |
| 472 | + 'id' => 'v240_update_form_goal_progress', | |
| 473 | + 'version' => '2.4.0', | |
| 474 | + 'callback' => 'give_v240_update_form_goal_progress_callback', | |
| 475 | + ] | |
| 476 | + ); | |
| 477 | + | |
| 478 | + $give_updates->register( | |
| 479 | + [ | |
| 480 | + 'id' => 'v270_store_stripe_account_for_donation', | |
| 481 | + 'version' => '2.7.0', | |
| 482 | + 'callback' => 'give_v270_store_stripe_account_for_donation_callback', | |
| 483 | + ] | |
| 484 | + ); | |
| 458 | 485 | } |
| 459 | 486 | |
| 460 | 487 | add_action( 'give_register_updates', 'give_show_upgrade_notices' ); |
| 461 | 488 | |
| @@ -470,11 +497,13 @@ | ||
| 470 | 497 | function give_trigger_upgrades() { |
| 471 | 498 | |
| 472 | 499 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
| 473 | 500 | wp_die( |
| 474 | - esc_html__( 'You do not have permission to do Give upgrades.', 'give' ), esc_html__( 'Error', 'give' ), array( | |
| 501 | + esc_html__( 'You do not have permission to do GiveWP upgrades.', 'give' ), | |
| 502 | + esc_html__( 'Error', 'give' ), | |
| 503 | + [ | |
| 475 | 504 | 'response' => 403, |
| 476 | - ) | |
| 505 | + ] | |
| 477 | 506 | ); |
| 478 | 507 | } |
| 479 | 508 | |
| 480 | 509 | $give_version = get_option( 'give_version' ); |
| @@ -534,10 +563,10 @@ | ||
| 534 | 563 | // Get abandoned offline payments. |
| 535 | 564 | $select = "SELECT ID FROM $wpdb->posts p "; |
| 536 | 565 | $join = "LEFT JOIN $wpdb->postmeta m ON p.ID = m.post_id "; |
| 537 | 566 | $where = "WHERE p.post_type = 'give_payment' "; |
| 538 | - $where .= "AND ( p.post_status = 'abandoned' )"; | |
| 539 | - $where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )"; | |
| 567 | + $where .= "AND ( p.post_status = 'abandoned' )"; | |
| 568 | + $where .= "AND ( m.meta_key = '_give_payment_gateway' AND m.meta_value = 'offline' )"; | |
| 540 | 569 | |
| 541 | 570 | $sql = $select . $join . $where; |
| 542 | 571 | $found_payments = $wpdb->get_col( $sql ); |
| 543 | 572 | |
| @@ -581,9 +610,9 @@ | ||
| 581 | 610 | if ( version_compare( $give_version, '1.5.2', '<' ) || ! give_has_upgrade_completed( 'upgrade_give_user_caps_cleanup' ) ) { |
| 582 | 611 | |
| 583 | 612 | // Delete all caps with "ss". |
| 584 | 613 | // Also delete all unused "campaign" roles. |
| 585 | - $delete_caps = array( | |
| 614 | + $delete_caps = [ | |
| 586 | 615 | 'delete_give_formss', |
| 587 | 616 | 'delete_others_give_formss', |
| 588 | 617 | 'delete_private_give_formss', |
| 589 | 618 | 'delete_published_give_formss', |
| @@ -621,9 +650,9 @@ | ||
| 621 | 650 | 'edit_private_give_paymentss', |
| 622 | 651 | 'edit_published_give_paymentss', |
| 623 | 652 | 'publish_give_paymentss', |
| 624 | 653 | 'read_private_give_paymentss', |
| 625 | - ); | |
| 654 | + ]; | |
| 626 | 655 | |
| 627 | 656 | global $wp_roles; |
| 628 | 657 | foreach ( $delete_caps as $cap ) { |
| 629 | 658 | foreach ( array_keys( $wp_roles->roles ) as $role ) { |
| @@ -636,9 +665,9 @@ | ||
| 636 | 665 | $roles->add_roles(); |
| 637 | 666 | $roles->add_caps(); |
| 638 | 667 | |
| 639 | 668 | // The Update Ran. |
| 640 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ), false ); | |
| 669 | + update_option( 'give_version', GIVE_VERSION, false ); | |
| 641 | 670 | give_set_upgrade_complete( 'upgrade_give_user_caps_cleanup' ); |
| 642 | 671 | delete_option( 'give_doing_upgrade' ); |
| 643 | 672 | |
| 644 | 673 | }// End if(). |
| @@ -686,9 +715,9 @@ | ||
| 686 | 715 | |
| 687 | 716 | $api_url = 'https://givewp.com/give-sl-api/'; |
| 688 | 717 | |
| 689 | 718 | // Get addons license key. |
| 690 | - $addons = array(); | |
| 719 | + $addons = []; | |
| 691 | 720 | foreach ( $give_options as $key => $value ) { |
| 692 | 721 | if ( false !== strpos( $key, '_license_key' ) ) { |
| 693 | 722 | $addons[ $key ] = $value; |
| 694 | 723 | } |
| @@ -713,9 +742,9 @@ | ||
| 713 | 742 | continue; |
| 714 | 743 | } |
| 715 | 744 | |
| 716 | 745 | // Get addon name. |
| 717 | - $addon_name = array(); | |
| 746 | + $addon_name = []; | |
| 718 | 747 | $addon_name_parts = explode( '_', str_replace( 'give_', '', $shortname ) ); |
| 719 | 748 | foreach ( $addon_name_parts as $name_part ) { |
| 720 | 749 | |
| 721 | 750 | // Fix addon name |
| @@ -730,23 +759,23 @@ | ||
| 730 | 759 | |
| 731 | 760 | $addon_name = implode( ' ', $addon_name ); |
| 732 | 761 | |
| 733 | 762 | // Data to send to the API. |
| 734 | - $api_params = array( | |
| 763 | + $api_params = [ | |
| 735 | 764 | 'edd_action' => 'activate_license', // never change from "edd_" to "give_"! |
| 736 | 765 | 'license' => $addon_license, |
| 737 | 766 | 'item_name' => urlencode( $addon_name ), |
| 738 | 767 | 'url' => home_url(), |
| 739 | - ); | |
| 768 | + ]; | |
| 740 | 769 | |
| 741 | 770 | // Call the API. |
| 742 | 771 | $response = wp_remote_post( |
| 743 | 772 | $api_url, |
| 744 | - array( | |
| 773 | + [ | |
| 745 | 774 | 'timeout' => 15, |
| 746 | 775 | 'sslverify' => false, |
| 747 | 776 | 'body' => $api_params, |
| 748 | - ) | |
| 777 | + ] | |
| 749 | 778 | ); |
| 750 | 779 | |
| 751 | 780 | // Make sure there are no errors. |
| 752 | 781 | if ( is_wp_error( $response ) ) { |
| @@ -774,9 +803,9 @@ | ||
| 774 | 803 | function give_v17_cleanup_roles() { |
| 775 | 804 | |
| 776 | 805 | // Delete all caps with "_give_forms_" and "_give_payments_". |
| 777 | 806 | // These roles have no usage; the proper is singular. |
| 778 | - $delete_caps = array( | |
| 807 | + $delete_caps = [ | |
| 779 | 808 | 'view_give_forms_stats', |
| 780 | 809 | 'delete_give_forms_terms', |
| 781 | 810 | 'assign_give_forms_terms', |
| 782 | 811 | 'edit_give_forms_terms', |
| @@ -785,9 +814,9 @@ | ||
| 785 | 814 | 'manage_give_payments_terms', |
| 786 | 815 | 'edit_give_payments_terms', |
| 787 | 816 | 'assign_give_payments_terms', |
| 788 | 817 | 'delete_give_payments_terms', |
| 789 | - ); | |
| 818 | + ]; | |
| 790 | 819 | |
| 791 | 820 | global $wp_roles; |
| 792 | 821 | foreach ( $delete_caps as $cap ) { |
| 793 | 822 | foreach ( array_keys( $wp_roles->roles ) as $role ) { |
| @@ -825,9 +854,9 @@ | ||
| 825 | 854 | function give_v18_upgrades_core_setting() { |
| 826 | 855 | // Core settings which changes from checkbox to radio. |
| 827 | 856 | $core_setting_names = array_merge( |
| 828 | 857 | array_keys( give_v18_renamed_core_settings() ), |
| 829 | - array( | |
| 858 | + [ | |
| 830 | 859 | 'uninstall_on_delete', |
| 831 | 860 | 'scripts_footer', |
| 832 | 861 | 'test_mode', |
| 833 | 862 | 'email_access', |
| @@ -832,9 +861,9 @@ | ||
| 832 | 861 | 'test_mode', |
| 833 | 862 | 'email_access', |
| 834 | 863 | 'terms', |
| 835 | 864 | 'give_offline_donation_enable_billing_fields', |
| 836 | - ) | |
| 865 | + ] | |
| 837 | 866 | ); |
| 838 | 867 | |
| 839 | 868 | // Bailout: If not any setting define. |
| 840 | 869 | if ( $give_settings = get_option( 'give_settings' ) ) { |
| @@ -848,9 +877,9 @@ | ||
| 848 | 877 | |
| 849 | 878 | // Continue: If setting already set. |
| 850 | 879 | if ( |
| 851 | 880 | array_key_exists( $new_setting_name, $give_settings ) |
| 852 | - && in_array( $give_settings[ $new_setting_name ], array( 'enabled', 'disabled' ) ) | |
| 881 | + && in_array( $give_settings[ $new_setting_name ], [ 'enabled', 'disabled' ] ) | |
| 853 | 882 | ) { |
| 854 | 883 | continue; |
| 855 | 884 | } |
| 856 | 885 | |
| @@ -892,15 +921,15 @@ | ||
| 892 | 921 | $give_updates = Give_Updates::get_instance(); |
| 893 | 922 | |
| 894 | 923 | // form query |
| 895 | 924 | $forms = new WP_Query( |
| 896 | - array( | |
| 925 | + [ | |
| 897 | 926 | 'paged' => $give_updates->step, |
| 898 | 927 | 'status' => 'any', |
| 899 | 928 | 'order' => 'ASC', |
| 900 | 929 | 'post_type' => 'give_forms', |
| 901 | 930 | 'posts_per_page' => 20, |
| 902 | - ) | |
| 931 | + ] | |
| 903 | 932 | ); |
| 904 | 933 | |
| 905 | 934 | if ( $forms->have_posts() ) { |
| 906 | 935 | $give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 20 ) ); |
| @@ -922,9 +951,9 @@ | ||
| 922 | 951 | |
| 923 | 952 | // "Disable" Guest Donation. Checkbox. |
| 924 | 953 | // See: https://github.com/impress-org/give/issues/1470. |
| 925 | 954 | $guest_donation = give_get_meta( get_the_ID(), '_give_logged_in_only', true ); |
| 926 | - $guest_donation_newval = ( in_array( $guest_donation, array( 'yes', 'on' ) ) ? 'disabled' : 'enabled' ); | |
| 955 | + $guest_donation_newval = ( in_array( $guest_donation, [ 'yes', 'on' ] ) ? 'disabled' : 'enabled' ); | |
| 927 | 956 | give_update_meta( get_the_ID(), '_give_logged_in_only', $guest_donation_newval ); |
| 928 | 957 | |
| 929 | 958 | // Offline Donations. |
| 930 | 959 | // See: https://github.com/impress-org/give/issues/1579. |
| @@ -938,9 +967,9 @@ | ||
| 938 | 967 | } |
| 939 | 968 | give_update_meta( get_the_ID(), '_give_customize_offline_donations', $offline_donation_newval ); |
| 940 | 969 | |
| 941 | 970 | // Convert yes/no setting field to enabled/disabled. |
| 942 | - $form_radio_settings = array( | |
| 971 | + $form_radio_settings = [ | |
| 943 | 972 | // Custom Amount. |
| 944 | 973 | '_give_custom_amount', |
| 945 | 974 | |
| 946 | 975 | // Donation Gaol. |
| @@ -953,9 +982,9 @@ | ||
| 953 | 982 | '_give_terms_option', |
| 954 | 983 | |
| 955 | 984 | // Billing fields. |
| 956 | 985 | '_give_offline_donation_enable_billing_fields_single', |
| 957 | - ); | |
| 986 | + ]; | |
| 958 | 987 | |
| 959 | 988 | foreach ( $form_radio_settings as $meta_key ) { |
| 960 | 989 | // Get value. |
| 961 | 990 | $field_value = give_get_meta( get_the_ID(), $meta_key, true ); |
| @@ -960,11 +989,11 @@ | ||
| 960 | 989 | // Get value. |
| 961 | 990 | $field_value = give_get_meta( get_the_ID(), $meta_key, true ); |
| 962 | 991 | |
| 963 | 992 | // Convert meta value only if it is in yes/no/none. |
| 964 | - if ( in_array( $field_value, array( 'yes', 'on', 'no', 'none' ) ) ) { | |
| 993 | + if ( in_array( $field_value, [ 'yes', 'on', 'no', 'none' ] ) ) { | |
| 965 | 994 | |
| 966 | - $field_value = ( in_array( $field_value, array( 'yes', 'on' ) ) ? 'enabled' : 'disabled' ); | |
| 995 | + $field_value = ( in_array( $field_value, [ 'yes', 'on' ] ) ? 'enabled' : 'disabled' ); | |
| 967 | 996 | give_update_meta( get_the_ID(), $meta_key, $field_value ); |
| 968 | 997 | } |
| 969 | 998 | } |
| 970 | 999 | }// End while(). |
| @@ -984,12 +1013,11 @@ | ||
| 984 | 1013 | * @since 1.8 |
| 985 | 1014 | * @return array |
| 986 | 1015 | */ |
| 987 | 1016 | function give_v18_renamed_core_settings() { |
| 988 | - return array( | |
| 1017 | + return [ | |
| 989 | 1018 | 'disable_paypal_verification' => 'paypal_verification', |
| 990 | 1019 | 'disable_css' => 'css', |
| 991 | - 'disable_welcome' => 'welcome', | |
| 992 | 1020 | 'disable_forms_singular' => 'forms_singular', |
| 993 | 1021 | 'disable_forms_archives' => 'forms_archives', |
| 994 | 1022 | 'disable_forms_excerpt' => 'forms_excerpt', |
| 995 | 1023 | 'disable_form_featured_img' => 'form_featured_img', |
| @@ -998,9 +1026,9 @@ | ||
| 998 | 1026 | 'disable_the_content_filter' => 'the_content_filter', |
| 999 | 1027 | 'enable_floatlabels' => 'floatlabels', |
| 1000 | 1028 | 'enable_categories' => 'categories', |
| 1001 | 1029 | 'enable_tags' => 'tags', |
| 1002 | - ); | |
| 1030 | + ]; | |
| 1003 | 1031 | } |
| 1004 | 1032 | |
| 1005 | 1033 | |
| 1006 | 1034 | /** |
| @@ -1035,9 +1063,9 @@ | ||
| 1035 | 1063 | OR option_name LIKE %s |
| 1036 | 1064 | OR option_name LIKE %s |
| 1037 | 1065 | ) |
| 1038 | 1066 | ", |
| 1039 | - array( | |
| 1067 | + [ | |
| 1040 | 1068 | '%_transient_give_stats_%', |
| 1041 | 1069 | 'give_cache%', |
| 1042 | 1070 | '%_transient_give_add_ons_feed%', |
| 1043 | 1071 | '%_transient__give_ajax_works' . |
| @@ -1050,9 +1078,9 @@ | ||
| 1050 | 1078 | '%_transient__give_installed%', |
| 1051 | 1079 | '%_transient__give_activation_redirect%', |
| 1052 | 1080 | '%_transient__give_hide_license_notices_shortly_%', |
| 1053 | 1081 | '%give_income_total%', |
| 1054 | - ) | |
| 1082 | + ] | |
| 1055 | 1083 | ), |
| 1056 | 1084 | 1 |
| 1057 | 1085 | ); |
| 1058 | 1086 | |
| @@ -1104,12 +1132,12 @@ | ||
| 1104 | 1132 | // Get the role object. |
| 1105 | 1133 | $give_worker = get_role( 'give_worker' ); |
| 1106 | 1134 | |
| 1107 | 1135 | // A list of capabilities to add for give workers. |
| 1108 | - $caps_to_add = array( | |
| 1136 | + $caps_to_add = [ | |
| 1109 | 1137 | 'edit_posts', |
| 1110 | 1138 | 'edit_pages', |
| 1111 | - ); | |
| 1139 | + ]; | |
| 1112 | 1140 | |
| 1113 | 1141 | foreach ( $caps_to_add as $cap ) { |
| 1114 | 1142 | // Add the capability. |
| 1115 | 1143 | $give_worker->add_cap( $cap ); |
| @@ -1129,15 +1157,15 @@ | ||
| 1129 | 1157 | $give_updates = Give_Updates::get_instance(); |
| 1130 | 1158 | |
| 1131 | 1159 | // form query. |
| 1132 | 1160 | $donation_forms = new WP_Query( |
| 1133 | - array( | |
| 1161 | + [ | |
| 1134 | 1162 | 'paged' => $give_updates->step, |
| 1135 | 1163 | 'status' => 'any', |
| 1136 | 1164 | 'order' => 'ASC', |
| 1137 | 1165 | 'post_type' => 'give_forms', |
| 1138 | 1166 | 'posts_per_page' => 20, |
| 1139 | - ) | |
| 1167 | + ] | |
| 1140 | 1168 | ); |
| 1141 | 1169 | |
| 1142 | 1170 | if ( $donation_forms->have_posts() ) { |
| 1143 | 1171 | $give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
| @@ -1214,11 +1242,11 @@ | ||
| 1214 | 1242 | $wpdb->prepare( |
| 1215 | 1243 | " |
| 1216 | 1244 | DELETE FROM $wpdb->usermeta |
| 1217 | 1245 | WHERE meta_key |
| 1218 | - LIKE '%%%s%%' | |
| 1246 | + LIKE '%s' | |
| 1219 | 1247 | ", |
| 1220 | - '_give_hide_license_notices_permanently' | |
| 1248 | + '%_give_hide_license_notices_permanently%' | |
| 1221 | 1249 | ) |
| 1222 | 1250 | ); |
| 1223 | 1251 | |
| 1224 | 1252 | // Delete short notice blocker. |
| @@ -1226,11 +1254,11 @@ | ||
| 1226 | 1254 | $wpdb->prepare( |
| 1227 | 1255 | " |
| 1228 | 1256 | DELETE FROM $wpdb->options |
| 1229 | 1257 | WHERE option_name |
| 1230 | - LIKE '%%%s%%' | |
| 1258 | + LIKE '%s' | |
| 1231 | 1259 | ", |
| 1232 | - '__give_hide_license_notices_shortly_' | |
| 1260 | + '%__give_hide_license_notices_shortly_%' | |
| 1233 | 1261 | ) |
| 1234 | 1262 | ); |
| 1235 | 1263 | } |
| 1236 | 1264 | |
| @@ -1264,9 +1292,9 @@ | ||
| 1264 | 1292 | if ( empty( $all_setting ) ) { |
| 1265 | 1293 | return; |
| 1266 | 1294 | } |
| 1267 | 1295 | |
| 1268 | - $settings = array( | |
| 1296 | + $settings = [ | |
| 1269 | 1297 | 'offline_donation_subject' => 'offline-donation-instruction_email_subject', |
| 1270 | 1298 | 'global_offline_donation_email' => 'offline-donation-instruction_email_message', |
| 1271 | 1299 | 'donation_subject' => 'donation-receipt_email_subject', |
| 1272 | 1300 | 'donation_receipt' => 'donation-receipt_email_message', |
| @@ -1271,15 +1299,15 @@ | ||
| 1271 | 1299 | 'donation_subject' => 'donation-receipt_email_subject', |
| 1272 | 1300 | 'donation_receipt' => 'donation-receipt_email_message', |
| 1273 | 1301 | 'donation_notification_subject' => 'new-donation_email_subject', |
| 1274 | 1302 | 'donation_notification' => 'new-donation_email_message', |
| 1275 | - 'admin_notice_emails' => array( | |
| 1303 | + 'admin_notice_emails' => [ | |
| 1276 | 1304 | 'new-donation_recipient', |
| 1277 | 1305 | 'new-offline-donation_recipient', |
| 1278 | 1306 | 'new-donor-register_recipient', |
| 1279 | - ), | |
| 1307 | + ], | |
| 1280 | 1308 | 'admin_notices' => 'new-donation_notification', |
| 1281 | - ); | |
| 1309 | + ]; | |
| 1282 | 1310 | |
| 1283 | 1311 | foreach ( $settings as $old_setting => $new_setting ) { |
| 1284 | 1312 | // Do not update already modified |
| 1285 | 1313 | if ( ! is_array( $new_setting ) ) { |
| @@ -1365,15 +1393,15 @@ | ||
| 1365 | 1393 | $give_updates = Give_Updates::get_instance(); |
| 1366 | 1394 | |
| 1367 | 1395 | // form query. |
| 1368 | 1396 | $donation_forms = new WP_Query( |
| 1369 | - array( | |
| 1397 | + [ | |
| 1370 | 1398 | 'paged' => $give_updates->step, |
| 1371 | 1399 | 'status' => 'any', |
| 1372 | 1400 | 'order' => 'ASC', |
| 1373 | - 'post_type' => array( 'give_forms', 'give_payment' ), | |
| 1401 | + 'post_type' => [ 'give_forms', 'give_payment' ], | |
| 1374 | 1402 | 'posts_per_page' => 20, |
| 1375 | - ) | |
| 1403 | + ] | |
| 1376 | 1404 | ); |
| 1377 | 1405 | if ( $donation_forms->have_posts() ) { |
| 1378 | 1406 | $give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
| 1379 | 1407 | |
| @@ -1466,12 +1494,12 @@ | ||
| 1466 | 1494 | $give_updates = Give_Updates::get_instance(); |
| 1467 | 1495 | |
| 1468 | 1496 | // form query. |
| 1469 | 1497 | $donors = Give()->donors->get_donors( |
| 1470 | - array( | |
| 1498 | + [ | |
| 1471 | 1499 | 'number' => 20, |
| 1472 | 1500 | 'offset' => $give_updates->get_offset( 20 ), |
| 1473 | - ) | |
| 1501 | + ] | |
| 1474 | 1502 | ); |
| 1475 | 1503 | |
| 1476 | 1504 | if ( ! empty( $donors ) ) { |
| 1477 | 1505 | $give_updates->set_percentage( Give()->donors->count(), $give_updates->get_offset( 20 ) ); |
| @@ -1477,9 +1505,9 @@ | ||
| 1477 | 1505 | $give_updates->set_percentage( Give()->donors->count(), $give_updates->get_offset( 20 ) ); |
| 1478 | 1506 | |
| 1479 | 1507 | /* @var Object $donor */ |
| 1480 | 1508 | foreach ( $donors as $donor ) { |
| 1481 | - Give()->donors->update( $donor->id, array( 'purchase_value' => give_sanitize_amount_for_db( $donor->purchase_value ) ) ); | |
| 1509 | + Give()->donors->update( $donor->id, [ 'purchase_value' => give_sanitize_amount_for_db( $donor->purchase_value ) ] ); | |
| 1482 | 1510 | } |
| 1483 | 1511 | } else { |
| 1484 | 1512 | // The Update Ran. |
| 1485 | 1513 | give_set_upgrade_complete( 'v1812_update_donor_purchase_values' ); |
| @@ -1496,12 +1524,12 @@ | ||
| 1496 | 1524 | $give_updates = Give_Updates::get_instance(); |
| 1497 | 1525 | |
| 1498 | 1526 | // Fetch all the existing donors. |
| 1499 | 1527 | $donors = Give()->donors->get_donors( |
| 1500 | - array( | |
| 1528 | + [ | |
| 1501 | 1529 | 'number' => 20, |
| 1502 | 1530 | 'offset' => $give_updates->get_offset( 20 ), |
| 1503 | - ) | |
| 1531 | + ] | |
| 1504 | 1532 | ); |
| 1505 | 1533 | |
| 1506 | 1534 | if ( ! empty( $donors ) ) { |
| 1507 | 1535 | $give_updates->set_percentage( Give()->donors->count(), $give_updates->get_offset( 20 ) ); |
| @@ -1516,12 +1544,12 @@ | ||
| 1516 | 1544 | |
| 1517 | 1545 | // Update user role, if user has subscriber role. |
| 1518 | 1546 | if ( is_array( $user->roles ) && in_array( 'subscriber', $user->roles ) ) { |
| 1519 | 1547 | wp_update_user( |
| 1520 | - array( | |
| 1548 | + [ | |
| 1521 | 1549 | 'ID' => $user_id, |
| 1522 | 1550 | 'role' => 'give_donor', |
| 1523 | - ) | |
| 1551 | + ] | |
| 1524 | 1552 | ); |
| 1525 | 1553 | } |
| 1526 | 1554 | } |
| 1527 | 1555 | } |
| @@ -1557,15 +1585,15 @@ | ||
| 1557 | 1585 | $give_updates = Give_Updates::get_instance(); |
| 1558 | 1586 | |
| 1559 | 1587 | // form query. |
| 1560 | 1588 | $payments = new WP_Query( |
| 1561 | - array( | |
| 1589 | + [ | |
| 1562 | 1590 | 'paged' => $give_updates->step, |
| 1563 | 1591 | 'status' => 'any', |
| 1564 | 1592 | 'order' => 'ASC', |
| 1565 | - 'post_type' => array( 'give_payment' ), | |
| 1593 | + 'post_type' => [ 'give_payment' ], | |
| 1566 | 1594 | 'posts_per_page' => 100, |
| 1567 | - ) | |
| 1595 | + ] | |
| 1568 | 1596 | ); |
| 1569 | 1597 | |
| 1570 | 1598 | if ( $payments->have_posts() ) { |
| 1571 | 1599 | $give_updates->set_percentage( $payments->found_posts, ( $give_updates->step * 100 ) ); |
| @@ -1614,17 +1642,17 @@ | ||
| 1614 | 1642 | return; |
| 1615 | 1643 | } |
| 1616 | 1644 | |
| 1617 | 1645 | // Add Capabilities to user roles as required. |
| 1618 | - $add_caps = array( | |
| 1619 | - 'administrator' => array( | |
| 1646 | + $add_caps = [ | |
| 1647 | + 'administrator' => [ | |
| 1620 | 1648 | 'view_give_payments', |
| 1621 | - ), | |
| 1622 | - ); | |
| 1649 | + ], | |
| 1650 | + ]; | |
| 1623 | 1651 | |
| 1624 | 1652 | // Remove Capabilities to user roles as required. |
| 1625 | - $remove_caps = array( | |
| 1626 | - 'give_manager' => array( | |
| 1653 | + $remove_caps = [ | |
| 1654 | + 'give_manager' => [ | |
| 1627 | 1655 | 'edit_others_pages', |
| 1628 | 1656 | 'edit_others_posts', |
| 1629 | 1657 | 'delete_others_pages', |
| 1630 | 1658 | 'delete_others_posts', |
| @@ -1630,10 +1658,10 @@ | ||
| 1630 | 1658 | 'delete_others_posts', |
| 1631 | 1659 | 'manage_categories', |
| 1632 | 1660 | 'import', |
| 1633 | 1661 | 'export', |
| 1634 | - ), | |
| 1635 | - ); | |
| 1662 | + ], | |
| 1663 | + ]; | |
| 1636 | 1664 | |
| 1637 | 1665 | foreach ( $add_caps as $role => $caps ) { |
| 1638 | 1666 | foreach ( $caps as $cap ) { |
| 1639 | 1667 | $wp_roles->add_cap( $role, $cap ); |
| @@ -1690,15 +1718,15 @@ | ||
| 1690 | 1718 | /* @var Give_Updates $give_updates */ |
| 1691 | 1719 | $give_updates = Give_Updates::get_instance(); |
| 1692 | 1720 | |
| 1693 | 1721 | $donations = new WP_Query( |
| 1694 | - array( | |
| 1722 | + [ | |
| 1695 | 1723 | 'paged' => $give_updates->step, |
| 1696 | 1724 | 'status' => 'any', |
| 1697 | 1725 | 'order' => 'ASC', |
| 1698 | - 'post_type' => array( 'give_payment' ), | |
| 1726 | + 'post_type' => [ 'give_payment' ], | |
| 1699 | 1727 | 'posts_per_page' => 100, |
| 1700 | - ) | |
| 1728 | + ] | |
| 1701 | 1729 | ); |
| 1702 | 1730 | |
| 1703 | 1731 | if ( $donations->have_posts() ) { |
| 1704 | 1732 | $give_updates->set_percentage( $donations->found_posts, $give_updates->step * 100 ); |
| @@ -1750,10 +1778,10 @@ | ||
| 1750 | 1778 | return; |
| 1751 | 1779 | } |
| 1752 | 1780 | |
| 1753 | 1781 | // Remove Capabilities to user roles as required. |
| 1754 | - $remove_caps = array( | |
| 1755 | - 'give_worker' => array( | |
| 1782 | + $remove_caps = [ | |
| 1783 | + 'give_worker' => [ | |
| 1756 | 1784 | 'delete_give_payments', |
| 1757 | 1785 | 'delete_others_give_payments', |
| 1758 | 1786 | 'delete_private_give_payments', |
| 1759 | 1787 | 'delete_published_give_payments', |
| @@ -1760,10 +1788,10 @@ | ||
| 1760 | 1788 | 'edit_others_give_payments', |
| 1761 | 1789 | 'edit_private_give_payments', |
| 1762 | 1790 | 'edit_published_give_payments', |
| 1763 | 1791 | 'read_private_give_payments', |
| 1764 | - ), | |
| 1765 | - ); | |
| 1792 | + ], | |
| 1793 | + ]; | |
| 1766 | 1794 | |
| 1767 | 1795 | foreach ( $remove_caps as $role => $caps ) { |
| 1768 | 1796 | foreach ( $caps as $cap ) { |
| 1769 | 1797 | $wp_roles->remove_cap( $role, $cap ); |
| @@ -1791,15 +1819,15 @@ | ||
| 1791 | 1819 | $give_updates = Give_Updates::get_instance(); |
| 1792 | 1820 | |
| 1793 | 1821 | // form query |
| 1794 | 1822 | $forms = new WP_Query( |
| 1795 | - array( | |
| 1823 | + [ | |
| 1796 | 1824 | 'paged' => $give_updates->step, |
| 1797 | 1825 | 'status' => 'any', |
| 1798 | 1826 | 'order' => 'ASC', |
| 1799 | 1827 | 'post_type' => 'give_forms', |
| 1800 | 1828 | 'posts_per_page' => 100, |
| 1801 | - ) | |
| 1829 | + ] | |
| 1802 | 1830 | ); |
| 1803 | 1831 | |
| 1804 | 1832 | if ( $forms->have_posts() ) { |
| 1805 | 1833 | $give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
| @@ -1810,12 +1838,13 @@ | ||
| 1810 | 1838 | |
| 1811 | 1839 | // Update offline instruction email notification status. |
| 1812 | 1840 | $offline_instruction_notification_status = get_post_meta( get_the_ID(), '_give_customize_offline_donations', true ); |
| 1813 | 1841 | $offline_instruction_notification_status = give_is_setting_enabled( |
| 1814 | - $offline_instruction_notification_status, array( | |
| 1842 | + $offline_instruction_notification_status, | |
| 1843 | + [ | |
| 1815 | 1844 | 'enabled', |
| 1816 | 1845 | 'global', |
| 1817 | - ) | |
| 1846 | + ] | |
| 1818 | 1847 | ) |
| 1819 | 1848 | ? $offline_instruction_notification_status |
| 1820 | 1849 | : 'global'; |
| 1821 | 1850 | update_post_meta( get_the_ID(), '_give_offline-donation-instruction_notification', $offline_instruction_notification_status ); |
| @@ -1857,10 +1886,10 @@ | ||
| 1857 | 1886 | /** |
| 1858 | 1887 | * Upgrade payment metadata for new metabox settings. |
| 1859 | 1888 | * |
| 1860 | 1889 | * @since 2.0 |
| 1890 | + * @return void | |
| 1861 | 1891 | * @global wpdb $wpdb |
| 1862 | - * @return void | |
| 1863 | 1892 | */ |
| 1864 | 1893 | function give_v20_upgrades_payment_metadata_callback() { |
| 1865 | 1894 | global $wpdb; |
| 1866 | 1895 | $give_updates = Give_Updates::get_instance(); |
| @@ -1866,15 +1895,15 @@ | ||
| 1866 | 1895 | $give_updates = Give_Updates::get_instance(); |
| 1867 | 1896 | |
| 1868 | 1897 | // form query |
| 1869 | 1898 | $forms = new WP_Query( |
| 1870 | - array( | |
| 1899 | + [ | |
| 1871 | 1900 | 'paged' => $give_updates->step, |
| 1872 | 1901 | 'status' => 'any', |
| 1873 | 1902 | 'order' => 'ASC', |
| 1874 | 1903 | 'post_type' => 'give_payment', |
| 1875 | 1904 | 'posts_per_page' => 100, |
| 1876 | - ) | |
| 1905 | + ] | |
| 1877 | 1906 | ); |
| 1878 | 1907 | |
| 1879 | 1908 | if ( $forms->have_posts() ) { |
| 1880 | 1909 | $give_updates->set_percentage( $forms->found_posts, ( $give_updates->step * 100 ) ); |
| @@ -1890,13 +1919,13 @@ | ||
| 1890 | 1919 | if ( ! empty( $payment_meta ) ) { |
| 1891 | 1920 | _give_20_bc_split_and_save_give_payment_meta( $post->ID, $payment_meta ); |
| 1892 | 1921 | } |
| 1893 | 1922 | |
| 1894 | - $deprecated_meta_keys = array( | |
| 1923 | + $deprecated_meta_keys = [ | |
| 1895 | 1924 | '_give_payment_customer_id' => '_give_payment_donor_id', |
| 1896 | 1925 | '_give_payment_user_email' => '_give_payment_donor_email', |
| 1897 | 1926 | '_give_payment_user_ip' => '_give_payment_donor_ip', |
| 1898 | - ); | |
| 1927 | + ]; | |
| 1899 | 1928 | |
| 1900 | 1929 | foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) { |
| 1901 | 1930 | // Do not add new meta key if already exist. |
| 1902 | 1931 | 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 ) ) ) { |
| @@ -1904,13 +1933,13 @@ | ||
| 1904 | 1933 | } |
| 1905 | 1934 | |
| 1906 | 1935 | $wpdb->insert( |
| 1907 | 1936 | $wpdb->postmeta, |
| 1908 | - array( | |
| 1937 | + [ | |
| 1909 | 1938 | 'post_id' => $post->ID, |
| 1910 | 1939 | 'meta_key' => $new_meta_key, |
| 1911 | 1940 | 'meta_value' => give_get_meta( $post->ID, $old_meta_key, true ), |
| 1912 | - ) | |
| 1941 | + ] | |
| 1913 | 1942 | ); |
| 1914 | 1943 | } |
| 1915 | 1944 | |
| 1916 | 1945 | // Bailout |
| @@ -1940,129 +1969,11 @@ | ||
| 1940 | 1969 | } |
| 1941 | 1970 | |
| 1942 | 1971 | |
| 1943 | 1972 | /** |
| 1944 | - * Upgrade logs data. | |
| 1945 | - * | |
| 1946 | - * @since 2.0 | |
| 1947 | - * @return void | |
| 1948 | - */ | |
| 1949 | -function give_v20_logs_upgrades_callback() { | |
| 1950 | - global $wpdb; | |
| 1951 | - $give_updates = Give_Updates::get_instance(); | |
| 1952 | - | |
| 1953 | - // form query | |
| 1954 | - $forms = new WP_Query( | |
| 1955 | - array( | |
| 1956 | - 'paged' => $give_updates->step, | |
| 1957 | - 'order' => 'DESC', | |
| 1958 | - 'post_type' => 'give_log', | |
| 1959 | - 'post_status' => 'any', | |
| 1960 | - 'posts_per_page' => 100, | |
| 1961 | - ) | |
| 1962 | - ); | |
| 1963 | - | |
| 1964 | - if ( $forms->have_posts() ) { | |
| 1965 | - $give_updates->set_percentage( $forms->found_posts, $give_updates->step * 100 ); | |
| 1966 | - | |
| 1967 | - while ( $forms->have_posts() ) { | |
| 1968 | - $forms->the_post(); | |
| 1969 | - global $post; | |
| 1970 | - | |
| 1971 | - if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_logs WHERE ID=%d", $post->ID ) ) ) { | |
| 1972 | - continue; | |
| 1973 | - } | |
| 1974 | - | |
| 1975 | - $term = get_the_terms( $post->ID, 'give_log_type' ); | |
| 1976 | - $term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array(); | |
| 1977 | - $term_name = ! empty( $term ) ? $term->slug : ''; | |
| 1978 | - | |
| 1979 | - $log_data = array( | |
| 1980 | - 'ID' => $post->ID, | |
| 1981 | - 'log_title' => $post->post_title, | |
| 1982 | - 'log_content' => $post->post_content, | |
| 1983 | - 'log_parent' => 0, | |
| 1984 | - 'log_type' => $term_name, | |
| 1985 | - 'log_date' => $post->post_date, | |
| 1986 | - 'log_date_gmt' => $post->post_date_gmt, | |
| 1987 | - ); | |
| 1988 | - $log_meta = array(); | |
| 1989 | - | |
| 1990 | - if ( $old_log_meta = get_post_meta( $post->ID ) ) { | |
| 1991 | - foreach ( $old_log_meta as $meta_key => $meta_value ) { | |
| 1992 | - switch ( $meta_key ) { | |
| 1993 | - case '_give_log_payment_id': | |
| 1994 | - $log_data['log_parent'] = current( $meta_value ); | |
| 1995 | - $log_meta['_give_log_form_id'] = $post->post_parent; | |
| 1996 | - break; | |
| 1997 | - | |
| 1998 | - default: | |
| 1999 | - $log_meta[ $meta_key ] = current( $meta_value ); | |
| 2000 | - } | |
| 2001 | - } | |
| 2002 | - } | |
| 2003 | - | |
| 2004 | - if ( 'api_request' === $term_name ) { | |
| 2005 | - $log_meta['_give_log_api_query'] = $post->post_excerpt; | |
| 2006 | - } | |
| 2007 | - | |
| 2008 | - $wpdb->insert( "{$wpdb->prefix}give_logs", $log_data ); | |
| 2009 | - | |
| 2010 | - if ( ! empty( $log_meta ) ) { | |
| 2011 | - foreach ( $log_meta as $meta_key => $meta_value ) { | |
| 2012 | - Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value ); | |
| 2013 | - } | |
| 2014 | - } | |
| 2015 | - | |
| 2016 | - $logIDs[] = $post->ID; | |
| 2017 | - }// End while(). | |
| 2018 | - | |
| 2019 | - wp_reset_postdata(); | |
| 2020 | - } else { | |
| 2021 | - // @todo: Delete terms and taxonomy after releases 2.0. | |
| 2022 | - /* | |
| 2023 | - $terms = get_terms( 'give_log_type', array( 'fields' => 'ids', 'hide_empty' => false ) ); | |
| 2024 | - if ( ! empty( $terms ) ) { | |
| 2025 | - foreach ( $terms as $term ) { | |
| 2026 | - wp_delete_term( $term, 'give_log_type' ); | |
| 2027 | - } | |
| 2028 | - }*/ | |
| 2029 | - | |
| 2030 | - // @todo: Delete logs after releases 2.0. | |
| 2031 | - /* | |
| 2032 | - $logIDs = get_posts( array( | |
| 2033 | - 'order' => 'DESC', | |
| 2034 | - 'post_type' => 'give_log', | |
| 2035 | - 'post_status' => 'any', | |
| 2036 | - 'posts_per_page' => - 1, | |
| 2037 | - 'fields' => 'ids', | |
| 2038 | - ) | |
| 2039 | - );*/ | |
| 2040 | - | |
| 2041 | - /* | |
| 2042 | - if ( ! empty( $logIDs ) ) { | |
| 2043 | - foreach ( $logIDs as $log ) { | |
| 2044 | - // Delete term relationship and posts. | |
| 2045 | - wp_delete_object_term_relationships( $log, 'give_log_type' ); | |
| 2046 | - wp_delete_post( $log, true ); | |
| 2047 | - } | |
| 2048 | - }*/ | |
| 2049 | - | |
| 2050 | - // @todo: Unregister taxonomy after releases 2.0. | |
| 2051 | - /*unregister_taxonomy( 'give_log_type' );*/ | |
| 2052 | - | |
| 2053 | - // Delete log cache. | |
| 2054 | - Give()->logs->delete_cache(); | |
| 2055 | - | |
| 2056 | - // No more forms found, finish up. | |
| 2057 | - give_set_upgrade_complete( 'v20_logs_upgrades' ); | |
| 2058 | - } | |
| 2059 | -} | |
| 2060 | - | |
| 2061 | - | |
| 2062 | -/** | |
| 2063 | 1973 | * Move payment and form metadata to new table |
| 2064 | 1974 | * |
| 1975 | + * @since 4.14.0 Replace {$wpdb->paymentmeta} with {$wpdb->donationmeta} | |
| 2065 | 1976 | * @since 2.0 |
| 2066 | 1977 | * @return void |
| 2067 | 1978 | */ |
| 2068 | 1979 | function give_v20_move_metadata_into_new_table_callback() { |
| @@ -2070,15 +1981,15 @@ | ||
| 2070 | 1981 | $give_updates = Give_Updates::get_instance(); |
| 2071 | 1982 | |
| 2072 | 1983 | // form query |
| 2073 | 1984 | $payments = new WP_Query( |
| 2074 | - array( | |
| 1985 | + [ | |
| 2075 | 1986 | 'paged' => $give_updates->step, |
| 2076 | 1987 | 'status' => 'any', |
| 2077 | 1988 | 'order' => 'ASC', |
| 2078 | - 'post_type' => array( 'give_forms', 'give_payment' ), | |
| 1989 | + 'post_type' => [ 'give_forms', 'give_payment' ], | |
| 2079 | 1990 | 'posts_per_page' => 100, |
| 2080 | - ) | |
| 1991 | + ] | |
| 2081 | 1992 | ); |
| 2082 | 1993 | |
| 2083 | 1994 | if ( $payments->have_posts() ) { |
| 2084 | 1995 | $give_updates->set_percentage( $payments->found_posts, $give_updates->step * 100 ); |
| @@ -2097,9 +2008,9 @@ | ||
| 2097 | 2008 | |
| 2098 | 2009 | if ( ! empty( $meta_data ) ) { |
| 2099 | 2010 | foreach ( $meta_data as $index => $data ) { |
| 2100 | 2011 | // Check for duplicate meta values. |
| 2101 | - 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 ) ) { | |
| 2012 | + if ( $result = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . ( 'give_forms' === $post->post_type ? $wpdb->formmeta : $wpdb->donationmeta ) . ' WHERE meta_id=%d', $data['meta_id'] ), ARRAY_A ) ) { | |
| 2102 | 2013 | continue; |
| 2103 | 2014 | } |
| 2104 | 2015 | |
| 2105 | 2016 | switch ( $post->post_type ) { |
| @@ -2147,12 +2058,12 @@ | ||
| 2147 | 2058 | /* @var Give_Updates $give_updates */ |
| 2148 | 2059 | $give_updates = Give_Updates::get_instance(); |
| 2149 | 2060 | |
| 2150 | 2061 | $donors = Give()->donors->get_donors( |
| 2151 | - array( | |
| 2062 | + [ | |
| 2152 | 2063 | 'paged' => $give_updates->step, |
| 2153 | 2064 | 'number' => 100, |
| 2154 | - ) | |
| 2065 | + ] | |
| 2155 | 2066 | ); |
| 2156 | 2067 | |
| 2157 | 2068 | if ( $donors ) { |
| 2158 | 2069 | $give_updates->set_percentage( count( $donors ), $give_updates->step * 100 ); |
| @@ -2193,11 +2104,11 @@ | ||
| 2193 | 2104 | /** |
| 2194 | 2105 | * Upgrade routine for user addresses. |
| 2195 | 2106 | * |
| 2196 | 2107 | * @since 2.0 |
| 2108 | + * @return void | |
| 2197 | 2109 | * @global wpdb $wpdb |
| 2198 | 2110 | * |
| 2199 | - * @return void | |
| 2200 | 2111 | */ |
| 2201 | 2112 | function give_v20_upgrades_user_address() { |
| 2202 | 2113 | global $wpdb; |
| 2203 | 2114 | |
| @@ -2205,12 +2116,12 @@ | ||
| 2205 | 2116 | $give_updates = Give_Updates::get_instance(); |
| 2206 | 2117 | |
| 2207 | 2118 | /* @var WP_User_Query $user_query */ |
| 2208 | 2119 | $user_query = new WP_User_Query( |
| 2209 | - array( | |
| 2120 | + [ | |
| 2210 | 2121 | 'number' => 100, |
| 2211 | 2122 | 'paged' => $give_updates->step, |
| 2212 | - ) | |
| 2123 | + ] | |
| 2213 | 2124 | ); |
| 2214 | 2125 | |
| 2215 | 2126 | $users = $user_query->get_results(); |
| 2216 | 2127 | |
| @@ -2257,10 +2168,10 @@ | ||
| 2257 | 2168 | /** |
| 2258 | 2169 | * Upgrade logs data. |
| 2259 | 2170 | * |
| 2260 | 2171 | * @since 2.0 |
| 2172 | + * @return void | |
| 2261 | 2173 | * @global wpdb $wpdb |
| 2262 | - * @return void | |
| 2263 | 2174 | */ |
| 2264 | 2175 | function give_v20_rename_donor_tables_callback() { |
| 2265 | 2176 | global $wpdb; |
| 2266 | 2177 | |
| @@ -2266,12 +2177,12 @@ | ||
| 2266 | 2177 | |
| 2267 | 2178 | /* @var Give_Updates $give_updates */ |
| 2268 | 2179 | $give_updates = Give_Updates::get_instance(); |
| 2269 | 2180 | |
| 2270 | - $tables = array( | |
| 2181 | + $tables = [ | |
| 2271 | 2182 | "{$wpdb->prefix}give_customers" => "{$wpdb->prefix}give_donors", |
| 2272 | 2183 | "{$wpdb->prefix}give_customermeta" => "{$wpdb->prefix}give_donormeta", |
| 2273 | - ); | |
| 2184 | + ]; | |
| 2274 | 2185 | |
| 2275 | 2186 | // Alter customer table |
| 2276 | 2187 | foreach ( $tables as $old_table => $new_table ) { |
| 2277 | 2188 | if ( |
| @@ -2300,10 +2211,10 @@ | ||
| 2300 | 2211 | /** |
| 2301 | 2212 | * Create missing meta tables. |
| 2302 | 2213 | * |
| 2303 | 2214 | * @since 2.0.1 |
| 2215 | + * @return void | |
| 2304 | 2216 | * @global wpdb $wpdb |
| 2305 | - * @return void | |
| 2306 | 2217 | */ |
| 2307 | 2218 | function give_v201_create_tables() { |
| 2308 | 2219 | global $wpdb; |
| 2309 | 2220 | |
| @@ -2313,16 +2224,8 @@ | ||
| 2313 | 2224 | |
| 2314 | 2225 | if ( ! $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->prefix}give_formmeta" ) ) ) { |
| 2315 | 2226 | Give()->form_meta->create_table(); |
| 2316 | 2227 | } |
| 2317 | - | |
| 2318 | - if ( ! $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->prefix}give_logs" ) ) ) { | |
| 2319 | - Give()->logs->log_db->create_table(); | |
| 2320 | - } | |
| 2321 | - | |
| 2322 | - if ( ! $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->prefix}give_logmeta" ) ) ) { | |
| 2323 | - Give()->logs->logmeta_db->create_table(); | |
| 2324 | - } | |
| 2325 | 2228 | } |
| 2326 | 2229 | |
| 2327 | 2230 | /** |
| 2328 | 2231 | * Upgrade payment metadata for new metabox settings. |
| @@ -2327,10 +2230,10 @@ | ||
| 2327 | 2230 | /** |
| 2328 | 2231 | * Upgrade payment metadata for new metabox settings. |
| 2329 | 2232 | * |
| 2330 | 2233 | * @since 2.0.1 |
| 2234 | + * @return void | |
| 2331 | 2235 | * @global wpdb $wpdb |
| 2332 | - * @return void | |
| 2333 | 2236 | */ |
| 2334 | 2237 | function give_v201_upgrades_payment_metadata_callback() { |
| 2335 | 2238 | global $wpdb, $post; |
| 2336 | 2239 | $give_updates = Give_Updates::get_instance(); |
| @@ -2339,14 +2242,14 @@ | ||
| 2339 | 2242 | $payments = $wpdb->get_col( |
| 2340 | 2243 | " |
| 2341 | 2244 | SELECT ID FROM $wpdb->posts |
| 2342 | 2245 | WHERE 1=1 |
| 2343 | - AND ( | |
| 2246 | + AND ( | |
| 2344 | 2247 | $wpdb->posts.post_date >= '2018-01-08 00:00:00' |
| 2345 | 2248 | ) |
| 2346 | 2249 | AND $wpdb->posts.post_type = 'give_payment' |
| 2347 | 2250 | AND {$wpdb->posts}.post_status IN ('" . implode( "','", array_keys( give_get_payment_statuses() ) ) . "') |
| 2348 | - ORDER BY $wpdb->posts.post_date ASC | |
| 2251 | + ORDER BY $wpdb->posts.post_date ASC | |
| 2349 | 2252 | LIMIT 100 |
| 2350 | 2253 | OFFSET " . $give_updates->get_offset( 100 ) |
| 2351 | 2254 | ); |
| 2352 | 2255 | |
| @@ -2369,13 +2272,13 @@ | ||
| 2369 | 2272 | if ( ! empty( $payment_meta ) ) { |
| 2370 | 2273 | _give_20_bc_split_and_save_give_payment_meta( $post->ID, $payment_meta ); |
| 2371 | 2274 | } |
| 2372 | 2275 | |
| 2373 | - $deprecated_meta_keys = array( | |
| 2276 | + $deprecated_meta_keys = [ | |
| 2374 | 2277 | '_give_payment_customer_id' => '_give_payment_donor_id', |
| 2375 | 2278 | '_give_payment_user_email' => '_give_payment_donor_email', |
| 2376 | 2279 | '_give_payment_user_ip' => '_give_payment_donor_ip', |
| 2377 | - ); | |
| 2280 | + ]; | |
| 2378 | 2281 | |
| 2379 | 2282 | foreach ( $deprecated_meta_keys as $old_meta_key => $new_meta_key ) { |
| 2380 | 2283 | // Do not add new meta key if already exist. |
| 2381 | 2284 | 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 ) ) ) { |
| @@ -2383,13 +2286,13 @@ | ||
| 2383 | 2286 | } |
| 2384 | 2287 | |
| 2385 | 2288 | $wpdb->insert( |
| 2386 | 2289 | $wpdb->postmeta, |
| 2387 | - array( | |
| 2290 | + [ | |
| 2388 | 2291 | 'post_id' => $post->ID, |
| 2389 | 2292 | 'meta_key' => $new_meta_key, |
| 2390 | 2293 | 'meta_value' => give_get_meta( $post->ID, $old_meta_key, true ), |
| 2391 | - ) | |
| 2294 | + ] | |
| 2392 | 2295 | ); |
| 2393 | 2296 | } |
| 2394 | 2297 | |
| 2395 | 2298 | // Bailout |
| @@ -2420,8 +2323,9 @@ | ||
| 2420 | 2323 | |
| 2421 | 2324 | /** |
| 2422 | 2325 | * Move payment and form metadata to new table |
| 2423 | 2326 | * |
| 2327 | + * @since 4.14.0 Replace {$wpdb->paymentmeta} with {$wpdb->donationmeta} | |
| 2424 | 2328 | * @since 2.0.1 |
| 2425 | 2329 | * @return void |
| 2426 | 2330 | */ |
| 2427 | 2331 | function give_v201_move_metadata_into_new_table_callback() { |
| @@ -2430,13 +2334,13 @@ | ||
| 2430 | 2334 | give_v201_create_tables(); |
| 2431 | 2335 | |
| 2432 | 2336 | $payments = $wpdb->get_col( |
| 2433 | 2337 | " |
| 2434 | - SELECT ID FROM $wpdb->posts | |
| 2338 | + SELECT ID FROM $wpdb->posts | |
| 2435 | 2339 | WHERE 1=1 |
| 2436 | 2340 | AND ( $wpdb->posts.post_type = 'give_payment' OR $wpdb->posts.post_type = 'give_forms' ) |
| 2437 | 2341 | AND {$wpdb->posts}.post_status IN ('" . implode( "','", array_keys( give_get_payment_statuses() ) ) . "') |
| 2438 | - ORDER BY $wpdb->posts.post_date ASC | |
| 2342 | + ORDER BY $wpdb->posts.post_date ASC | |
| 2439 | 2343 | LIMIT 100 |
| 2440 | 2344 | OFFSET " . $give_updates->get_offset( 100 ) |
| 2441 | 2345 | ); |
| 2442 | 2346 | |
| @@ -2442,13 +2346,14 @@ | ||
| 2442 | 2346 | |
| 2443 | 2347 | if ( ! empty( $payments ) ) { |
| 2444 | 2348 | $give_updates->set_percentage( |
| 2445 | 2349 | give_get_total_post_type_count( |
| 2446 | - array( | |
| 2350 | + [ | |
| 2447 | 2351 | 'give_forms', |
| 2448 | 2352 | 'give_payment', |
| 2449 | - ) | |
| 2450 | - ), $give_updates->step * 100 | |
| 2353 | + ] | |
| 2354 | + ), | |
| 2355 | + $give_updates->step * 100 | |
| 2451 | 2356 | ); |
| 2452 | 2357 | |
| 2453 | 2358 | foreach ( $payments as $payment_id ) { |
| 2454 | 2359 | $post = get_post( $payment_id ); |
| @@ -2464,9 +2369,9 @@ | ||
| 2464 | 2369 | |
| 2465 | 2370 | if ( ! empty( $meta_data ) ) { |
| 2466 | 2371 | foreach ( $meta_data as $index => $data ) { |
| 2467 | 2372 | // Check for duplicate meta values. |
| 2468 | - 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 ) ) { | |
| 2373 | + if ( $result = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . ( 'give_forms' === $post->post_type ? $wpdb->formmeta : $wpdb->donationmeta ) . ' WHERE meta_id=%d', $data['meta_id'] ), ARRAY_A ) ) { | |
| 2469 | 2374 | continue; |
| 2470 | 2375 | } |
| 2471 | 2376 | |
| 2472 | 2377 | switch ( $post->post_type ) { |
| @@ -2502,96 +2407,9 @@ | ||
| 2502 | 2407 | } |
| 2503 | 2408 | |
| 2504 | 2409 | } |
| 2505 | 2410 | |
| 2506 | -/** | |
| 2507 | - * Move data to new log table. | |
| 2508 | - * | |
| 2509 | - * @since 2.0.1 | |
| 2510 | - * @return void | |
| 2511 | - */ | |
| 2512 | -function give_v201_logs_upgrades_callback() { | |
| 2513 | - global $wpdb, $post; | |
| 2514 | - $give_updates = Give_Updates::get_instance(); | |
| 2515 | - give_v201_create_tables(); | |
| 2516 | 2411 | |
| 2517 | - $logs = $wpdb->get_col( | |
| 2518 | - " | |
| 2519 | - SELECT ID FROM $wpdb->posts | |
| 2520 | - WHERE 1=1 | |
| 2521 | - AND $wpdb->posts.post_type = 'give_log' | |
| 2522 | - AND {$wpdb->posts}.post_status IN ('" . implode( "','", array_keys( give_get_payment_statuses() ) ) . "') | |
| 2523 | - ORDER BY $wpdb->posts.post_date ASC | |
| 2524 | - LIMIT 100 | |
| 2525 | - OFFSET " . $give_updates->get_offset( 100 ) | |
| 2526 | - ); | |
| 2527 | - | |
| 2528 | - if ( ! empty( $logs ) ) { | |
| 2529 | - $give_updates->set_percentage( give_get_total_post_type_count( 'give_log' ), $give_updates->step * 100 ); | |
| 2530 | - | |
| 2531 | - foreach ( $logs as $log_id ) { | |
| 2532 | - $post = get_post( $log_id ); | |
| 2533 | - setup_postdata( $post ); | |
| 2534 | - | |
| 2535 | - if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_logs WHERE ID=%d", $post->ID ) ) ) { | |
| 2536 | - continue; | |
| 2537 | - } | |
| 2538 | - | |
| 2539 | - $term = get_the_terms( $post->ID, 'give_log_type' ); | |
| 2540 | - $term = ! is_wp_error( $term ) && ! empty( $term ) ? $term[0] : array(); | |
| 2541 | - $term_name = ! empty( $term ) ? $term->slug : ''; | |
| 2542 | - | |
| 2543 | - $log_data = array( | |
| 2544 | - 'ID' => $post->ID, | |
| 2545 | - 'log_title' => $post->post_title, | |
| 2546 | - 'log_content' => $post->post_content, | |
| 2547 | - 'log_parent' => 0, | |
| 2548 | - 'log_type' => $term_name, | |
| 2549 | - 'log_date' => $post->post_date, | |
| 2550 | - 'log_date_gmt' => $post->post_date_gmt, | |
| 2551 | - ); | |
| 2552 | - $log_meta = array(); | |
| 2553 | - | |
| 2554 | - if ( $old_log_meta = get_post_meta( $post->ID ) ) { | |
| 2555 | - foreach ( $old_log_meta as $meta_key => $meta_value ) { | |
| 2556 | - switch ( $meta_key ) { | |
| 2557 | - case '_give_log_payment_id': | |
| 2558 | - $log_data['log_parent'] = current( $meta_value ); | |
| 2559 | - $log_meta['_give_log_form_id'] = $post->post_parent; | |
| 2560 | - break; | |
| 2561 | - | |
| 2562 | - default: | |
| 2563 | - $log_meta[ $meta_key ] = current( $meta_value ); | |
| 2564 | - } | |
| 2565 | - } | |
| 2566 | - } | |
| 2567 | - | |
| 2568 | - if ( 'api_request' === $term_name ) { | |
| 2569 | - $log_meta['_give_log_api_query'] = $post->post_excerpt; | |
| 2570 | - } | |
| 2571 | - | |
| 2572 | - $wpdb->insert( "{$wpdb->prefix}give_logs", $log_data ); | |
| 2573 | - | |
| 2574 | - if ( ! empty( $log_meta ) ) { | |
| 2575 | - foreach ( $log_meta as $meta_key => $meta_value ) { | |
| 2576 | - Give()->logs->logmeta_db->update_meta( $post->ID, $meta_key, $meta_value ); | |
| 2577 | - } | |
| 2578 | - } | |
| 2579 | - | |
| 2580 | - $logIDs[] = $post->ID; | |
| 2581 | - }// End while(). | |
| 2582 | - | |
| 2583 | - wp_reset_postdata(); | |
| 2584 | - } else { | |
| 2585 | - // Delete log cache. | |
| 2586 | - Give()->logs->delete_cache(); | |
| 2587 | - | |
| 2588 | - // No more forms found, finish up. | |
| 2589 | - give_set_upgrade_complete( 'v201_logs_upgrades' ); | |
| 2590 | - } | |
| 2591 | -} | |
| 2592 | - | |
| 2593 | - | |
| 2594 | 2412 | /** |
| 2595 | 2413 | * Add missing donor. |
| 2596 | 2414 | * |
| 2597 | 2415 | * @since 2.0.1 |
| @@ -2616,17 +2434,17 @@ | ||
| 2616 | 2434 | if ( ! empty( $customers ) ) { |
| 2617 | 2435 | $give_updates->set_percentage( $total_customers, ( $give_updates->step * 20 ) ); |
| 2618 | 2436 | |
| 2619 | 2437 | $missing_donors = array_diff( $customers, $donors ); |
| 2620 | - $donor_data = array(); | |
| 2438 | + $donor_data = []; | |
| 2621 | 2439 | |
| 2622 | 2440 | if ( $missing_donors ) { |
| 2623 | 2441 | foreach ( $missing_donors as $donor_id ) { |
| 2624 | - $donor_data[] = array( | |
| 2442 | + $donor_data[] = [ | |
| 2625 | 2443 | 'info' => $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_customers WHERE id=%d", $donor_id ) ), |
| 2626 | 2444 | 'meta' => $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}give_customermeta WHERE customer_id=%d", $donor_id ) ), |
| 2627 | 2445 | |
| 2628 | - ); | |
| 2446 | + ]; | |
| 2629 | 2447 | } |
| 2630 | 2448 | } |
| 2631 | 2449 | |
| 2632 | 2450 | if ( ! empty( $donor_data ) ) { |
| @@ -2727,9 +2545,9 @@ | ||
| 2727 | 2545 | function give_v203_upgrades() { |
| 2728 | 2546 | global $wpdb; |
| 2729 | 2547 | |
| 2730 | 2548 | // Do not auto load option. |
| 2731 | - $wpdb->update( $wpdb->options, array( 'autoload' => 'no' ), array( 'option_name' => 'give_completed_upgrades' ) ); | |
| 2549 | + $wpdb->update( $wpdb->options, [ 'autoload' => 'no' ], [ 'option_name' => 'give_completed_upgrades' ] ); | |
| 2732 | 2550 | |
| 2733 | 2551 | // Remove from cache. |
| 2734 | 2552 | $all_options = wp_load_alloptions(); |
| 2735 | 2553 | |
| @@ -2768,9 +2586,9 @@ | ||
| 2768 | 2586 | * |
| 2769 | 2587 | * Set autoload to no to reduce result weight from WordPress query |
| 2770 | 2588 | */ |
| 2771 | 2589 | |
| 2772 | - $options = array( | |
| 2590 | + $options = [ | |
| 2773 | 2591 | 'give_settings', |
| 2774 | 2592 | 'give_version', |
| 2775 | 2593 | 'give_version_upgraded_from', |
| 2776 | 2594 | 'give_default_api_version', |
| @@ -2781,9 +2599,9 @@ | ||
| 2781 | 2599 | 'give_last_paypal_ipn_received', |
| 2782 | 2600 | 'give_use_php_sessions', |
| 2783 | 2601 | 'give_subscriptions', |
| 2784 | 2602 | '_give_subscriptions_edit_last', |
| 2785 | - ); | |
| 2603 | + ]; | |
| 2786 | 2604 | |
| 2787 | 2605 | // Add all table version option name |
| 2788 | 2606 | // Add banner option *_active_by_user |
| 2789 | 2607 | $option_like = $wpdb->get_col( |
| @@ -2836,9 +2654,9 @@ | ||
| 2836 | 2654 | * @since 2.3.0 |
| 2837 | 2655 | */ |
| 2838 | 2656 | function give_v230_upgrades() { |
| 2839 | 2657 | |
| 2840 | - $options_key = array( | |
| 2658 | + $options_key = [ | |
| 2841 | 2659 | 'give_temp_delete_form_ids', // delete import donor |
| 2842 | 2660 | 'give_temp_delete_donation_ids', // delete import donor |
| 2843 | 2661 | 'give_temp_delete_step', // delete import donor |
| 2844 | 2662 | 'give_temp_delete_donor_ids', // delete import donor |
| @@ -2857,9 +2675,9 @@ | ||
| 2857 | 2675 | 'give_temp_recount_form_stats', // delete form stats |
| 2858 | 2676 | 'give_temp_recount_earnings', // recount income |
| 2859 | 2677 | 'give_recount_earnings_total', // recount income |
| 2860 | 2678 | 'give_temp_reset_ids', // reset stats |
| 2861 | - ); | |
| 2679 | + ]; | |
| 2862 | 2680 | |
| 2863 | 2681 | $options_key = '\'' . implode( "','", $options_key ) . '\''; |
| 2864 | 2682 | |
| 2865 | 2683 | global $wpdb; |
| @@ -2882,15 +2700,15 @@ | ||
| 2882 | 2700 | $give_updates = Give_Updates::get_instance(); |
| 2883 | 2701 | |
| 2884 | 2702 | // form query. |
| 2885 | 2703 | $donation_forms = new WP_Query( |
| 2886 | - array( | |
| 2704 | + [ | |
| 2887 | 2705 | 'paged' => $give_updates->step, |
| 2888 | 2706 | 'status' => 'any', |
| 2889 | 2707 | 'order' => 'ASC', |
| 2890 | 2708 | 'post_type' => 'give_forms', |
| 2891 | 2709 | 'posts_per_page' => 20, |
| 2892 | - ) | |
| 2710 | + ] | |
| 2893 | 2711 | ); |
| 2894 | 2712 | |
| 2895 | 2713 | if ( $donation_forms->have_posts() ) { |
| 2896 | 2714 | $give_updates->set_percentage( $donation_forms->found_posts, ( $give_updates->step * 20 ) ); |
| @@ -3014,18 +2832,18 @@ | ||
| 3014 | 2832 | /* @var Give_Updates $give_updates */ |
| 3015 | 2833 | $give_updates = Give_Updates::get_instance(); |
| 3016 | 2834 | |
| 3017 | 2835 | $donor_count = Give()->donors->count( |
| 3018 | - array( | |
| 2836 | + [ | |
| 3019 | 2837 | 'number' => - 1, |
| 3020 | - ) | |
| 2838 | + ] | |
| 3021 | 2839 | ); |
| 3022 | 2840 | |
| 3023 | 2841 | $donors = Give()->donors->get_donors( |
| 3024 | - array( | |
| 2842 | + [ | |
| 3025 | 2843 | 'paged' => $give_updates->step, |
| 3026 | 2844 | 'number' => 100, |
| 3027 | - ) | |
| 2845 | + ] | |
| 3028 | 2846 | ); |
| 3029 | 2847 | |
| 3030 | 2848 | if ( $donors ) { |
| 3031 | 2849 | $give_updates->set_percentage( $donor_count, $give_updates->step * 100 ); |
| @@ -3033,9 +2851,9 @@ | ||
| 3033 | 2851 | foreach ( $donors as $donor ) { |
| 3034 | 2852 | $anonymous_metadata = Give()->donor_meta->get_meta( $donor->id, '_give_anonymous_donor', true ); |
| 3035 | 2853 | |
| 3036 | 2854 | // If first name meta of donor is not created, then create it. |
| 3037 | - if ( ! in_array( $anonymous_metadata, array( '0', '1' ) ) ) { | |
| 2855 | + if ( ! in_array( $anonymous_metadata, [ '0', '1' ] ) ) { | |
| 3038 | 2856 | Give()->donor_meta->add_meta( $donor->id, '_give_anonymous_donor', '0' ); |
| 3039 | 2857 | } |
| 3040 | 2858 | } |
| 3041 | 2859 | } else { |
| @@ -3046,21 +2864,21 @@ | ||
| 3046 | 2864 | |
| 3047 | 2865 | /** Update donor meta |
| 3048 | 2866 | * Set "_give_anonymous_donor_forms" meta key if not exist |
| 3049 | 2867 | * |
| 3050 | - * | |
| 3051 | 2868 | * @since 2.2.4 |
| 3052 | 2869 | */ |
| 3053 | 2870 | function give_v224_update_donor_meta_forms_id_callback() { |
| 3054 | 2871 | $give_updates = Give_Updates::get_instance(); |
| 3055 | 2872 | |
| 3056 | - $donations = new WP_Query( array( | |
| 2873 | + $donations = new WP_Query( | |
| 2874 | + [ | |
| 3057 | 2875 | 'paged' => $give_updates->step, |
| 3058 | 2876 | 'status' => 'any', |
| 3059 | 2877 | 'order' => 'ASC', |
| 3060 | - 'post_type' => array( 'give_payment' ), | |
| 2878 | + 'post_type' => [ 'give_payment' ], | |
| 3061 | 2879 | 'posts_per_page' => 20, |
| 3062 | - ) | |
| 2880 | + ] | |
| 3063 | 2881 | ); |
| 3064 | 2882 | |
| 3065 | 2883 | if ( $donations->have_posts() ) { |
| 3066 | 2884 | $give_updates->set_percentage( $donations->found_posts, $give_updates->step * 20 ); |
| @@ -3074,9 +2892,9 @@ | ||
| 3074 | 2892 | $donor_id = give_get_payment_donor_id( $donation_id ); |
| 3075 | 2893 | $is_donated_as_anonymous = give_is_anonymous_donation( $donation_id ); |
| 3076 | 2894 | |
| 3077 | 2895 | $is_anonymous_donor = Give()->donor_meta->get_meta( $donor_id, "_give_anonymous_donor_form_{$form_id}", true ); |
| 3078 | - $is_edit_donor_meta = ! in_array( $is_anonymous_donor, array( '0', '1' ) ) | |
| 2896 | + $is_edit_donor_meta = ! in_array( $is_anonymous_donor, [ '0', '1' ] ) | |
| 3079 | 2897 | ? true |
| 3080 | 2898 | : ( 0 !== absint( $is_anonymous_donor ) ); |
| 3081 | 2899 | |
| 3082 | 2900 | if ( $is_edit_donor_meta ) { |
| @@ -3089,9 +2907,28 @@ | ||
| 3089 | 2907 | give_set_upgrade_complete( 'v224_update_donor_meta_forms_id' ); |
| 3090 | 2908 | } |
| 3091 | 2909 | } |
| 3092 | 2910 | |
| 2911 | +/** | |
| 2912 | + * Add custom comment table | |
| 2913 | + * | |
| 2914 | + * @since 2.4.0 | |
| 2915 | + */ | |
| 2916 | +function give_v230_add_missing_comment_tables() { | |
| 2917 | + $custom_tables = [ | |
| 2918 | + Give()->comment->db, | |
| 2919 | + Give()->comment->db_meta, | |
| 2920 | + ]; | |
| 3093 | 2921 | |
| 2922 | + /* @var Give_DB $table */ | |
| 2923 | + foreach ( $custom_tables as $table ) { | |
| 2924 | + if ( ! $table->installed() ) { | |
| 2925 | + $table->register_table(); | |
| 2926 | + } | |
| 2927 | + } | |
| 2928 | +} | |
| 2929 | + | |
| 2930 | + | |
| 3094 | 2931 | /** |
| 3095 | 2932 | * Move donor notes to comment table |
| 3096 | 2933 | * |
| 3097 | 2934 | * @since 2.3.0 |
| @@ -3096,19 +2933,26 @@ | ||
| 3096 | 2933 | * |
| 3097 | 2934 | * @since 2.3.0 |
| 3098 | 2935 | */ |
| 3099 | 2936 | function give_v230_move_donor_note_callback() { |
| 2937 | + // Add comment table if missing. | |
| 2938 | + give_v230_add_missing_comment_tables(); | |
| 2939 | + | |
| 3100 | 2940 | /* @var Give_Updates $give_updates */ |
| 3101 | 2941 | $give_updates = Give_Updates::get_instance(); |
| 3102 | 2942 | |
| 3103 | - $donor_count = Give()->donors->count( array( | |
| 3104 | - 'number' => - 1, | |
| 3105 | - ) ); | |
| 2943 | + $donor_count = Give()->donors->count( | |
| 2944 | + [ | |
| 2945 | + 'number' => - 1, | |
| 2946 | + ] | |
| 2947 | + ); | |
| 3106 | 2948 | |
| 3107 | - $donors = Give()->donors->get_donors( array( | |
| 3108 | - 'paged' => $give_updates->step, | |
| 3109 | - 'number' => 100, | |
| 3110 | - ) ); | |
| 2949 | + $donors = Give()->donors->get_donors( | |
| 2950 | + [ | |
| 2951 | + 'paged' => $give_updates->step, | |
| 2952 | + 'number' => 100, | |
| 2953 | + ] | |
| 2954 | + ); | |
| 3111 | 2955 | |
| 3112 | 2956 | if ( $donors ) { |
| 3113 | 2957 | $give_updates->set_percentage( $donor_count, $give_updates->step * 100 ); |
| 3114 | 2958 | // Loop through Donors |
| @@ -3123,9 +2967,9 @@ | ||
| 3123 | 2967 | $note = array_map( 'trim', explode( '-', $note ) ); |
| 3124 | 2968 | $timestamp = strtotime( $note[0] ); |
| 3125 | 2969 | |
| 3126 | 2970 | Give()->comment->db->add( |
| 3127 | - array( | |
| 2971 | + [ | |
| 3128 | 2972 | 'comment_content' => $note[1], |
| 3129 | 2973 | 'user_id' => absint( Give()->donors->get_column_by( 'user_id', 'id', $donor->id ) ), |
| 3130 | 2974 | 'comment_date' => date( 'Y-m-d H:i:s', $timestamp ), |
| 3131 | 2975 | 'comment_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $timestamp ) ), |
| @@ -3130,14 +2974,13 @@ | ||
| 3130 | 2974 | 'comment_date' => date( 'Y-m-d H:i:s', $timestamp ), |
| 3131 | 2975 | 'comment_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', $timestamp ) ), |
| 3132 | 2976 | 'comment_parent' => $donor->id, |
| 3133 | 2977 | 'comment_type' => 'donor', |
| 3134 | - ) | |
| 2978 | + ] | |
| 3135 | 2979 | ); |
| 3136 | 2980 | } |
| 3137 | 2981 | } |
| 3138 | 2982 | } |
| 3139 | - | |
| 3140 | 2983 | } else { |
| 3141 | 2984 | // The Update Ran. |
| 3142 | 2985 | give_set_upgrade_complete( 'v230_move_donor_note' ); |
| 3143 | 2986 | } |
| @@ -3150,8 +2993,11 @@ | ||
| 3150 | 2993 | */ |
| 3151 | 2994 | function give_v230_move_donation_note_callback() { |
| 3152 | 2995 | global $wpdb; |
| 3153 | 2996 | |
| 2997 | + // Add comment table if missing. | |
| 2998 | + give_v230_add_missing_Comment_tables(); | |
| 2999 | + | |
| 3154 | 3000 | /* @var Give_Updates $give_updates */ |
| 3155 | 3001 | $give_updates = Give_Updates::get_instance(); |
| 3156 | 3002 | |
| 3157 | 3003 | $donation_note_count = $wpdb->get_var( |
| @@ -3188,9 +3034,9 @@ | ||
| 3188 | 3034 | $donation_id = $comment->comment_post_ID; |
| 3189 | 3035 | $form_id = give_get_payment_form_id( $donation_id ); |
| 3190 | 3036 | |
| 3191 | 3037 | $comment_id = Give()->comment->db->add( |
| 3192 | - array( | |
| 3038 | + [ | |
| 3193 | 3039 | 'comment_content' => $comment->comment_content, |
| 3194 | 3040 | 'user_id' => $comment->user_id, |
| 3195 | 3041 | 'comment_date' => date( 'Y-m-d H:i:s', strtotime( $comment->comment_date ) ), |
| 3196 | 3042 | 'comment_date_gmt' => get_gmt_from_date( date( 'Y-m-d H:i:s', strtotime( $comment->comment_date_gmt ) ) ), |
| @@ -3197,26 +3043,26 @@ | ||
| 3197 | 3043 | 'comment_parent' => $comment->comment_post_ID, |
| 3198 | 3044 | 'comment_type' => is_numeric( get_comment_meta( $comment->comment_ID, '_give_donor_id', true ) ) |
| 3199 | 3045 | ? 'donor_donation' |
| 3200 | 3046 | : 'donation', |
| 3201 | - ) | |
| 3047 | + ] | |
| 3202 | 3048 | ); |
| 3203 | 3049 | |
| 3204 | - if( ! $comment_id ) { | |
| 3050 | + if ( ! $comment_id ) { | |
| 3205 | 3051 | continue; |
| 3206 | 3052 | } |
| 3207 | 3053 | |
| 3208 | 3054 | // @see https://github.com/impress-org/give/issues/3737#issuecomment-428460802 |
| 3209 | - $restricted_meta_keys = array( | |
| 3055 | + $restricted_meta_keys = [ | |
| 3210 | 3056 | 'akismet_result', |
| 3211 | 3057 | 'akismet_as_submitted', |
| 3212 | - 'akismet_history' | |
| 3213 | - ); | |
| 3058 | + 'akismet_history', | |
| 3059 | + ]; | |
| 3214 | 3060 | |
| 3215 | 3061 | if ( $comment_meta = get_comment_meta( $comment->comment_ID ) ) { |
| 3216 | 3062 | foreach ( $comment_meta as $meta_key => $meta_value ) { |
| 3217 | 3063 | // Skip few comment meta keys. |
| 3218 | - if( in_array( $meta_key, $restricted_meta_keys) ) { | |
| 3064 | + if ( in_array( $meta_key, $restricted_meta_keys ) ) { | |
| 3219 | 3065 | continue; |
| 3220 | 3066 | } |
| 3221 | 3067 | |
| 3222 | 3068 | $meta_value = maybe_unserialize( $meta_value ); |
| @@ -3230,13 +3076,12 @@ | ||
| 3230 | 3076 | |
| 3231 | 3077 | // Delete comment. |
| 3232 | 3078 | update_comment_meta( $comment->comment_ID, '_give_comment_moved', 1 ); |
| 3233 | 3079 | } |
| 3234 | - | |
| 3235 | 3080 | } else { |
| 3236 | 3081 | $comment_ids = $wpdb->get_col( |
| 3237 | 3082 | $wpdb->prepare( |
| 3238 | - " | |
| 3083 | + " | |
| 3239 | 3084 | SELECT DISTINCT comment_id |
| 3240 | 3085 | FROM {$wpdb->commentmeta} |
| 3241 | 3086 | WHERE meta_key=%s |
| 3242 | 3087 | AND meta_value=%d |
| @@ -3245,10 +3090,10 @@ | ||
| 3245 | 3090 | 1 |
| 3246 | 3091 | ) |
| 3247 | 3092 | ); |
| 3248 | 3093 | |
| 3249 | - if( ! empty( $comment_ids ) ) { | |
| 3250 | - $comment_ids = "'" . implode( "','", $comment_ids ). "'"; | |
| 3094 | + if ( ! empty( $comment_ids ) ) { | |
| 3095 | + $comment_ids = "'" . implode( "','", $comment_ids ) . "'"; | |
| 3251 | 3096 | |
| 3252 | 3097 | $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_ID IN ({$comment_ids})" ); |
| 3253 | 3098 | $wpdb->query( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id IN ({$comment_ids})" ); |
| 3254 | 3099 | } |
| @@ -3261,17 +3106,18 @@ | ||
| 3261 | 3106 | /** |
| 3262 | 3107 | * Delete donor wall related donor meta data |
| 3263 | 3108 | * |
| 3264 | 3109 | * @since 2.3.0 |
| 3265 | - * | |
| 3266 | 3110 | */ |
| 3267 | -function give_v230_delete_dw_related_donor_data_callback(){ | |
| 3111 | +function give_v230_delete_dw_related_donor_data_callback() { | |
| 3268 | 3112 | global $wpdb; |
| 3269 | 3113 | |
| 3270 | 3114 | $give_updates = Give_Updates::get_instance(); |
| 3271 | 3115 | |
| 3272 | - $wpdb->query( "DELETE FROM {$wpdb->donormeta} WHERE meta_key LIKE '%_give_anonymous_donor%' OR meta_key='_give_has_comment';" ); | |
| 3116 | + $donor_meta_table_name = Give()->donor_meta->table_name; | |
| 3273 | 3117 | |
| 3118 | + $wpdb->query( "DELETE FROM {$donor_meta_table_name} WHERE meta_key LIKE '%_give_anonymous_donor%' OR meta_key='_give_has_comment';" ); | |
| 3119 | + | |
| 3274 | 3120 | $give_updates->percentage = 100; |
| 3275 | 3121 | |
| 3276 | 3122 | // The Update Ran. |
| 3277 | 3123 | give_set_upgrade_complete( 'v230_delete_donor_wall_related_donor_data' ); |
| @@ -3280,11 +3126,10 @@ | ||
| 3280 | 3126 | /** |
| 3281 | 3127 | * Delete donor wall related comment meta data |
| 3282 | 3128 | * |
| 3283 | 3129 | * @since 2.3.0 |
| 3284 | - * | |
| 3285 | 3130 | */ |
| 3286 | -function give_v230_delete_dw_related_comment_data_callback(){ | |
| 3131 | +function give_v230_delete_dw_related_comment_data_callback() { | |
| 3287 | 3132 | global $wpdb; |
| 3288 | 3133 | |
| 3289 | 3134 | $give_updates = Give_Updates::get_instance(); |
| 3290 | 3135 | |
| @@ -3293,5 +3138,429 @@ | ||
| 3293 | 3138 | $give_updates->percentage = 100; |
| 3294 | 3139 | |
| 3295 | 3140 | // The Update Ran. |
| 3296 | 3141 | give_set_upgrade_complete( 'v230_delete_donor_wall_related_comment_data' ); |
| 3142 | +} | |
| 3143 | + | |
| 3144 | +/** | |
| 3145 | + * Update donation form goal progress data. | |
| 3146 | + * | |
| 3147 | + * @since 2.4.0 | |
| 3148 | + */ | |
| 3149 | +function give_v240_update_form_goal_progress_callback() { | |
| 3150 | + | |
| 3151 | + /* @var Give_Updates $give_updates */ | |
| 3152 | + $give_updates = Give_Updates::get_instance(); | |
| 3153 | + | |
| 3154 | + // form query | |
| 3155 | + $forms = new WP_Query( | |
| 3156 | + [ | |
| 3157 | + 'paged' => $give_updates->step, | |
| 3158 | + 'status' => 'any', | |
| 3159 | + 'order' => 'ASC', | |
| 3160 | + 'post_type' => 'give_forms', | |
| 3161 | + 'posts_per_page' => 20, | |
| 3162 | + ] | |
| 3163 | + ); | |
| 3164 | + | |
| 3165 | + if ( $forms->have_posts() ) { | |
| 3166 | + while ( $forms->have_posts() ) { | |
| 3167 | + $forms->the_post(); | |
| 3168 | + | |
| 3169 | + // Update the goal progress for donation form. | |
| 3170 | + give_update_goal_progress( get_the_ID() ); | |
| 3171 | + | |
| 3172 | + }// End while(). | |
| 3173 | + | |
| 3174 | + wp_reset_postdata(); | |
| 3175 | + | |
| 3176 | + } else { | |
| 3177 | + | |
| 3178 | + // No more forms found, finish up. | |
| 3179 | + give_set_upgrade_complete( 'v240_update_form_goal_progress' ); | |
| 3180 | + | |
| 3181 | + } | |
| 3182 | +} | |
| 3183 | + | |
| 3184 | +/** | |
| 3185 | + * DB upgrades for Give 2.5.0 | |
| 3186 | + * | |
| 3187 | + * @since 2.5.0 | |
| 3188 | + */ | |
| 3189 | +function give_v250_upgrades() { | |
| 3190 | + global $wpdb; | |
| 3191 | + | |
| 3192 | + $old_license = []; | |
| 3193 | + $new_license = []; | |
| 3194 | + $give_licenses = get_option( 'give_licenses', [] ); | |
| 3195 | + $give_options = give_get_settings(); | |
| 3196 | + | |
| 3197 | + // Get add-ons license key. | |
| 3198 | + $addons = []; | |
| 3199 | + foreach ( $give_options as $key => $value ) { | |
| 3200 | + if ( false !== strpos( $key, '_license_key' ) ) { | |
| 3201 | + $addons[ $key ] = $value; | |
| 3202 | + } | |
| 3203 | + } | |
| 3204 | + | |
| 3205 | + // Bailout: We do not have any add-on license data to upgrade. | |
| 3206 | + if ( empty( $addons ) ) { | |
| 3207 | + return false; | |
| 3208 | + } | |
| 3209 | + | |
| 3210 | + foreach ( $addons as $key => $license_key ) { | |
| 3211 | + | |
| 3212 | + // Get addon shortname. | |
| 3213 | + $addon_shortname = str_replace( '_license_key', '', $key ); | |
| 3214 | + | |
| 3215 | + // Addon license option name. | |
| 3216 | + $addon_shortname = "{$addon_shortname}_license_active"; | |
| 3217 | + $addon_license_data = get_option( "{$addon_shortname}_license_active", [] ); | |
| 3218 | + | |
| 3219 | + if ( | |
| 3220 | + ! $license_key | |
| 3221 | + || array_key_exists( $license_key, $give_licenses ) | |
| 3222 | + ) { | |
| 3223 | + continue; | |
| 3224 | + } | |
| 3225 | + | |
| 3226 | + $old_license[ $license_key ] = $addon_license_data; | |
| 3227 | + } | |
| 3228 | + | |
| 3229 | + // Bailout. | |
| 3230 | + if ( empty( $old_license ) ) { | |
| 3231 | + return false; | |
| 3232 | + } | |
| 3233 | + | |
| 3234 | + /* @var stdClass $data */ | |
| 3235 | + foreach ( $old_license as $key => $data ) { | |
| 3236 | + $tmp = Give_License::request_license_api( | |
| 3237 | + [ | |
| 3238 | + 'edd_action' => 'check_license', | |
| 3239 | + 'license' => $key, | |
| 3240 | + ], | |
| 3241 | + true | |
| 3242 | + ); | |
| 3243 | + | |
| 3244 | + if ( is_wp_error( $tmp ) || ! $tmp['success'] ) { | |
| 3245 | + continue; | |
| 3246 | + } | |
| 3247 | + | |
| 3248 | + $new_license[ $key ] = $tmp; | |
| 3249 | + } | |
| 3250 | + | |
| 3251 | + // Bailout. | |
| 3252 | + if ( empty( $new_license ) ) { | |
| 3253 | + return false; | |
| 3254 | + } | |
| 3255 | + | |
| 3256 | + $give_licenses = array_merge( $give_licenses, $new_license ); | |
| 3257 | + | |
| 3258 | + update_option( 'give_licenses', $give_licenses ); | |
| 3259 | + | |
| 3260 | + /** | |
| 3261 | + * Delete data. | |
| 3262 | + */ | |
| 3263 | + | |
| 3264 | + // 1. license keys | |
| 3265 | + foreach ( get_option( 'give_settings' ) as $index => $setting ) { | |
| 3266 | + if ( false !== strpos( $index, '_license_key' ) ) { | |
| 3267 | + give_delete_option( $index ); | |
| 3268 | + } | |
| 3269 | + } | |
| 3270 | + | |
| 3271 | + // 2. license api data | |
| 3272 | + $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name like '%_license_active%' AND option_name like 'give_%'" ); | |
| 3273 | + | |
| 3274 | + // 3. subscriptions data | |
| 3275 | + delete_option( '_give_subscriptions_edit_last' ); | |
| 3276 | + delete_option( 'give_subscriptions' ); | |
| 3277 | + | |
| 3278 | + // 4. misc | |
| 3279 | + delete_option( 'give_is_addon_activated' ); | |
| 3280 | + | |
| 3281 | + give_refresh_licenses(); | |
| 3282 | +} | |
| 3283 | + | |
| 3284 | +/** | |
| 3285 | + * DB upgrades for Give 2.5.8 | |
| 3286 | + * | |
| 3287 | + * @since 2.5.8 | |
| 3288 | + */ | |
| 3289 | +function give_v258_upgrades() { | |
| 3290 | + | |
| 3291 | + $is_checkout_enabled = give_is_setting_enabled( give_get_option( 'stripe_checkout_enabled', 'disabled' ) ); | |
| 3292 | + | |
| 3293 | + // Bailout, if stripe checkout is not active as a gateway. | |
| 3294 | + if ( ! $is_checkout_enabled ) { | |
| 3295 | + return; | |
| 3296 | + } | |
| 3297 | + | |
| 3298 | + $enabled_gateways = give_get_option( 'gateways', [] ); | |
| 3299 | + | |
| 3300 | + // Bailout, if Stripe Checkout is already enabled. | |
| 3301 | + if ( ! empty( $enabled_gateways['stripe_checkout'] ) ) { | |
| 3302 | + return; | |
| 3303 | + } | |
| 3304 | + | |
| 3305 | + $gateways_label = give_get_option( 'gateways_label', [] ); | |
| 3306 | + $default_gateway = give_get_option( 'default_gateway' ); | |
| 3307 | + | |
| 3308 | + // Set Stripe Checkout as active gateway. | |
| 3309 | + $enabled_gateways['stripe_checkout'] = 1; | |
| 3310 | + | |
| 3311 | + // Unset Stripe - Credit Card as an active gateway. | |
| 3312 | + unset( $enabled_gateways['stripe'] ); | |
| 3313 | + | |
| 3314 | + // Set Stripe Checkout same as Stripe as they have enabled Stripe Checkout under Stripe using same label. | |
| 3315 | + $gateways_label['stripe_checkout'] = $gateways_label['stripe']; | |
| 3316 | + give_update_option( 'gateways_label', $gateways_label ); | |
| 3317 | + | |
| 3318 | + // If default gateway selected is `stripe` then set `stripe checkout` as default. | |
| 3319 | + if ( 'stripe' === $default_gateway ) { | |
| 3320 | + give_update_option( 'default_gateway', 'stripe_checkout' ); | |
| 3321 | + } | |
| 3322 | + | |
| 3323 | + // Update the enabled gateways in database. | |
| 3324 | + give_update_option( 'gateways', $enabled_gateways ); | |
| 3325 | + | |
| 3326 | + // Delete the old legacy settings. | |
| 3327 | + give_delete_option( 'stripe_checkout_enabled' ); | |
| 3328 | +} | |
| 3329 | + | |
| 3330 | + | |
| 3331 | +/** | |
| 3332 | + * DB upgrades for Give 2.5.11 | |
| 3333 | + * | |
| 3334 | + * @since 2.5.11 | |
| 3335 | + */ | |
| 3336 | +function give_v2511_upgrades() { | |
| 3337 | + global $wp_roles, $wpdb; | |
| 3338 | + $all_roles = get_editable_roles(); | |
| 3339 | + | |
| 3340 | + // Run code only if not a fresh install. | |
| 3341 | + if ( Give_Cache_Setting::get_option( 'give_version' ) ) { | |
| 3342 | + // Remove unused notes column from donor table. | |
| 3343 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}give_donors DROP COLUMN notes;" ); | |
| 3344 | + } | |
| 3345 | + | |
| 3346 | + foreach ( $all_roles as $role => $data ) { | |
| 3347 | + $wp_roles->remove_cap( $role, 'delete_give_form' ); | |
| 3348 | + $wp_roles->remove_cap( $role, 'delete_give_payment' ); | |
| 3349 | + $wp_roles->remove_cap( $role, 'edit_give_form' ); | |
| 3350 | + $wp_roles->remove_cap( $role, 'edit_give_payment' ); | |
| 3351 | + $wp_roles->remove_cap( $role, 'read_give_form' ); | |
| 3352 | + $wp_roles->remove_cap( $role, 'read_give_payment' ); | |
| 3353 | + } | |
| 3354 | +} | |
| 3355 | + | |
| 3356 | +/** | |
| 3357 | + * Upgrade for version 2.6.3 | |
| 3358 | + * | |
| 3359 | + * @since 2.6.3 | |
| 3360 | + */ | |
| 3361 | +function give_v263_upgrades() { | |
| 3362 | + $licenses = get_option( 'give_licenses', [] ); | |
| 3363 | + | |
| 3364 | + if ( $licenses ) { | |
| 3365 | + foreach ( $licenses as $license ) { | |
| 3366 | + if ( ! empty( $license['is_all_access_pass'] ) ) { | |
| 3367 | + // Remove single license which is part of all access pass. | |
| 3368 | + // @see https://github.com/impress-org/givewp/issues/4669 | |
| 3369 | + $addonSlugs = Give_License::getAddonSlugsFromAllAccessPassLicense( $license ); | |
| 3370 | + foreach ( $licenses as $license_key => $data ) { | |
| 3371 | + // Skip bundle plan license key. | |
| 3372 | + if ( ! empty( $data['is_all_access_pass'] ) ) { | |
| 3373 | + continue; | |
| 3374 | + } | |
| 3375 | + | |
| 3376 | + if ( in_array( $data['plugin_slug'], $addonSlugs, true ) ) { | |
| 3377 | + unset( $licenses[ $license_key ] ); | |
| 3378 | + } | |
| 3379 | + } | |
| 3380 | + } | |
| 3381 | + } | |
| 3382 | + | |
| 3383 | + update_option( 'give_licenses', $licenses ); | |
| 3384 | + } | |
| 3385 | +} | |
| 3386 | + | |
| 3387 | + | |
| 3388 | +/** | |
| 3389 | + * Upgrade routine to call for backward compatibility to manage default Stripe account. | |
| 3390 | + * | |
| 3391 | + * @since 2.7.0 | |
| 3392 | + * @return void | |
| 3393 | + * @global wpdb $wpdb | |
| 3394 | + */ | |
| 3395 | +function give_v270_upgrades() { | |
| 3396 | + global $wpdb; | |
| 3397 | + | |
| 3398 | + $settingKey = '_give_stripe_get_all_accounts'; | |
| 3399 | + $giveSettings = give_get_settings(); | |
| 3400 | + $isStripeAccountMigrated = array_key_exists( $settingKey, $giveSettings ); | |
| 3401 | + $stripeAccounts = $isStripeAccountMigrated ? $giveSettings[ $settingKey ] : []; | |
| 3402 | + | |
| 3403 | + // Process, only when there is no Stripe accounts stored. | |
| 3404 | + if ( ! $isStripeAccountMigrated ) { | |
| 3405 | + $liveSecretKey = give_get_option( 'live_secret_key' ); | |
| 3406 | + $testSecretKey = give_get_option( 'test_secret_key' ); | |
| 3407 | + $livePublishableKey = give_get_option( 'live_publishable_key' ); | |
| 3408 | + $testPublishableKey = give_get_option( 'test_publishable_key' ); | |
| 3409 | + $isStripeConfigurationExist = $liveSecretKey || $testSecretKey || $livePublishableKey || $testPublishableKey; | |
| 3410 | + | |
| 3411 | + if ( $isStripeConfigurationExist ) { | |
| 3412 | + // Manual API Keys are enabled. | |
| 3413 | + if ( ! give_get_option( 'give_stripe_user_id' ) ) { | |
| 3414 | + $uniqueSlug = 'account_1'; | |
| 3415 | + $stripeAccounts[ $uniqueSlug ] = [ | |
| 3416 | + 'type' => 'manual', | |
| 3417 | + 'account_name' => give_stripe_convert_slug_to_title( $uniqueSlug ), | |
| 3418 | + 'account_slug' => $uniqueSlug, | |
| 3419 | + 'account_email' => '', | |
| 3420 | + 'account_country' => '', | |
| 3421 | + 'account_id' => '', // This parameter will be empty for manual API Keys Stripe account. | |
| 3422 | + 'live_secret_key' => $liveSecretKey, | |
| 3423 | + 'test_secret_key' => $testSecretKey, | |
| 3424 | + 'live_publishable_key' => $livePublishableKey, | |
| 3425 | + 'test_publishable_key' => $testPublishableKey, | |
| 3426 | + ]; | |
| 3427 | + | |
| 3428 | + // Set first Stripe account as default. | |
| 3429 | + give_update_option( '_give_stripe_default_account', $uniqueSlug ); | |
| 3430 | + } else { | |
| 3431 | + | |
| 3432 | + $secret_key = give_get_option( 'live_secret_key' ); | |
| 3433 | + if ( give_is_test_mode() ) { | |
| 3434 | + $secret_key = give_get_option( 'test_secret_key' ); | |
| 3435 | + } | |
| 3436 | + | |
| 3437 | + \Stripe\Stripe::setApiKey( $secret_key ); | |
| 3438 | + | |
| 3439 | + $accounts_count = is_countable( $stripeAccounts ) ? count( $stripeAccounts ) + 1 : 1; | |
| 3440 | + $all_account_slugs = array_keys( $stripeAccounts ); | |
| 3441 | + $accountSlug = give_stripe_get_unique_account_slug( $all_account_slugs, $accounts_count ); | |
| 3442 | + $accountName = give_stripe_convert_slug_to_title( $accountSlug ); | |
| 3443 | + $accountEmail = ''; | |
| 3444 | + $accountCountry = ''; | |
| 3445 | + $stripeAccountId = give_get_option( 'give_stripe_user_id' ); | |
| 3446 | + $accountDetails = give_stripe_get_account_details( $stripeAccountId ); | |
| 3447 | + | |
| 3448 | + // Setup Account Details for Connected Stripe Accounts. | |
| 3449 | + if ( ! empty( $accountDetails->id ) && 'account' === $accountDetails->object ) { | |
| 3450 | + $accountName = ! empty( $accountDetails->business_profile->name ) ? | |
| 3451 | + $accountDetails->business_profile->name : | |
| 3452 | + $accountDetails->settings->dashboard->display_name; | |
| 3453 | + $accountSlug = $accountDetails->id; | |
| 3454 | + $accountEmail = $accountDetails->email; | |
| 3455 | + $accountCountry = $accountDetails->country; | |
| 3456 | + } | |
| 3457 | + | |
| 3458 | + $stripeAccounts[ $accountSlug ] = [ | |
| 3459 | + 'type' => 'connect', | |
| 3460 | + 'account_name' => $accountName, | |
| 3461 | + 'account_slug' => $accountSlug, | |
| 3462 | + 'account_email' => $accountEmail, | |
| 3463 | + 'account_country' => $accountCountry, | |
| 3464 | + 'account_id' => $stripeAccountId, | |
| 3465 | + 'live_secret_key' => $liveSecretKey, | |
| 3466 | + 'test_secret_key' => $testSecretKey, | |
| 3467 | + 'live_publishable_key' => $livePublishableKey, | |
| 3468 | + 'test_publishable_key' => $testPublishableKey, | |
| 3469 | + ]; | |
| 3470 | + | |
| 3471 | + // Set first Stripe account as default. | |
| 3472 | + give_update_option( '_give_stripe_default_account', $accountSlug ); | |
| 3473 | + } | |
| 3474 | + | |
| 3475 | + give_update_option( $settingKey, $stripeAccounts ); | |
| 3476 | + | |
| 3477 | + // Remove legacy settings. | |
| 3478 | + give_delete_option( 'live_secret_key' ); | |
| 3479 | + give_delete_option( 'test_secret_key' ); | |
| 3480 | + give_delete_option( 'live_publishable_key' ); | |
| 3481 | + give_delete_option( 'test_publishable_key' ); | |
| 3482 | + give_delete_option( 'give_stripe_connected' ); | |
| 3483 | + give_delete_option( 'give_stripe_user_id' ); | |
| 3484 | + } | |
| 3485 | + } | |
| 3486 | + | |
| 3487 | + // Do not need to go beyond this if you are on fresh install and on fresh install donationmeta property is not defined for $wpdb. | |
| 3488 | + // Below code is to check if site have donations which processed with Stripe payment method | |
| 3489 | + // if not then we will auto complete stripe background update. | |
| 3490 | + if ( ! property_exists( $wpdb, 'donationmeta' ) ) { | |
| 3491 | + return; | |
| 3492 | + } | |
| 3493 | + | |
| 3494 | + $canStoreStripeInformationInDonation = (bool) $wpdb->get_var( | |
| 3495 | + $wpdb->prepare( | |
| 3496 | + " | |
| 3497 | + SELECT COUNT(donation_id) | |
| 3498 | + FROM $wpdb->donationmeta | |
| 3499 | + WHERE meta_key=%s | |
| 3500 | + AND meta_value LIKE %s", | |
| 3501 | + '_give_payment_gateway', | |
| 3502 | + '%stripe%' | |
| 3503 | + ) | |
| 3504 | + ); | |
| 3505 | + | |
| 3506 | + if ( ! $canStoreStripeInformationInDonation || ! $stripeAccounts ) { | |
| 3507 | + give_set_upgrade_complete( 'v270_store_stripe_account_for_donation' ); | |
| 3508 | + } | |
| 3509 | +} | |
| 3510 | + | |
| 3511 | +/** | |
| 3512 | + * This manual upgrade routine is used set the default Stripe account for all the existing donations. | |
| 3513 | + * This process will help us to identify which Stripe account is used to process a specific donation. | |
| 3514 | + * | |
| 3515 | + * @since 2.7.0 | |
| 3516 | + * | |
| 3517 | + * @return void | |
| 3518 | + */ | |
| 3519 | +function give_v270_store_stripe_account_for_donation_callback() { | |
| 3520 | + /* @var Give_Updates $give_updates */ | |
| 3521 | + $give_updates = Give_Updates::get_instance(); | |
| 3522 | + | |
| 3523 | + $donations = new WP_Query( | |
| 3524 | + [ | |
| 3525 | + 'paged' => $give_updates->step, | |
| 3526 | + 'status' => 'any', | |
| 3527 | + 'order' => 'ASC', | |
| 3528 | + 'post_type' => [ 'give_payment' ], | |
| 3529 | + 'posts_per_page' => 100, | |
| 3530 | + ] | |
| 3531 | + ); | |
| 3532 | + | |
| 3533 | + if ( $donations->have_posts() ) { | |
| 3534 | + $give_updates->set_percentage( $donations->found_posts, $give_updates->step * 100 ); | |
| 3535 | + | |
| 3536 | + while ( $donations->have_posts() ) { | |
| 3537 | + $donations->the_post(); | |
| 3538 | + $donationId = get_the_ID(); | |
| 3539 | + | |
| 3540 | + // Continue, if the donation is not processed with any of the supported payment method of Stripe. | |
| 3541 | + if ( ! Stripe::isDonationPaymentMethod( give_get_payment_gateway( $donationId ) ) ) { | |
| 3542 | + continue; | |
| 3543 | + } | |
| 3544 | + | |
| 3545 | + Stripe::addAccountDetail( | |
| 3546 | + $donationId, | |
| 3547 | + give_get_payment_form_id( $donationId ) | |
| 3548 | + ); | |
| 3549 | + } | |
| 3550 | + | |
| 3551 | + wp_reset_postdata(); | |
| 3552 | + } else { | |
| 3553 | + // Update Ran Successfully. | |
| 3554 | + give_set_upgrade_complete( 'v270_store_stripe_account_for_donation' ); | |
| 3555 | + } | |
| 3556 | +} | |
| 3557 | + | |
| 3558 | +/** | |
| 3559 | + * Removes any leftover export files that should've been deleted | |
| 3560 | + * | |
| 3561 | + * @since 2.9.0 | |
| 3562 | + */ | |
| 3563 | +function give_v290_remove_old_export_files() { | |
| 3564 | + @unlink( WP_CONTENT_DIR . '/uploads/give-payments.csv' ); | |
| 3565 | + @unlink( WP_CONTENT_DIR . '/uploads/give-donors.csv' ); | |
| 3297 | 3566 | } |