| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | +use Give\Framework\Permissions\Facades\UserPermissions; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * Class Give_Updates |
| 5 | 7 | * |
| 6 | 8 | * @since 1.8.12 |
| @@ -13,9 +15,9 @@ | ||
| 13 | 15 | * @since |
| 14 | 16 | * @access static |
| 15 | 17 | * @var |
| 16 | 18 | */ |
| 17 | - static private $instance; | |
| 19 | + private static $instance; | |
| 18 | 20 | |
| 19 | 21 | /** |
| 20 | 22 | * Instance. |
| 21 | 23 | * |
| @@ -22,9 +24,9 @@ | ||
| 22 | 24 | * @since |
| 23 | 25 | * @access public |
| 24 | 26 | * @var Give_Background_Updater |
| 25 | 27 | */ |
| 26 | - static public $background_updater; | |
| 28 | + public static $background_updater; | |
| 27 | 29 | |
| 28 | 30 | /** |
| 29 | 31 | * Updates |
| 30 | 32 | * |
| @@ -31,9 +33,9 @@ | ||
| 31 | 33 | * @since 1.8.12 |
| 32 | 34 | * @access private |
| 33 | 35 | * @var array |
| 34 | 36 | */ |
| 35 | - private $updates = array(); | |
| 37 | + private $updates = []; | |
| 36 | 38 | |
| 37 | 39 | /** |
| 38 | 40 | * Current update percentage number |
| 39 | 41 | * |
| @@ -80,13 +82,13 @@ | ||
| 80 | 82 | * |
| 81 | 83 | * @param array $args |
| 82 | 84 | */ |
| 83 | 85 | public function register( $args ) { |
| 84 | - $args_default = array( | |
| 86 | + $args_default = [ | |
| 85 | 87 | 'id' => '', |
| 86 | 88 | 'version' => '', |
| 87 | 89 | 'callback' => '', |
| 88 | - ); | |
| 90 | + ]; | |
| 89 | 91 | |
| 90 | 92 | $args = wp_parse_args( $args, $args_default ); |
| 91 | 93 | |
| 92 | 94 | // You can only register database upgrade. |
| @@ -103,9 +105,9 @@ | ||
| 103 | 105 | } |
| 104 | 106 | |
| 105 | 107 | // Change depend param to array. |
| 106 | 108 | if ( isset( $args['depend'] ) && is_string( $args['depend'] ) ) { |
| 107 | - $args['depend'] = array( $args['depend'] ); | |
| 109 | + $args['depend'] = [ $args['depend'] ]; | |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | $this->updates[ $args['type'] ][] = $args; |
| 111 | 113 | } |
| @@ -143,21 +145,21 @@ | ||
| 143 | 145 | |
| 144 | 146 | /** |
| 145 | 147 | * Setup hooks. |
| 146 | 148 | */ |
| 147 | - add_action( 'init', array( $this, '__register_upgrade' ), 9999 ); | |
| 148 | - add_action( 'give_set_upgrade_completed', array( $this, '__flush_resume_updates' ), 9999 ); | |
| 149 | - add_action( 'wp_ajax_give_db_updates_info', array( $this, '__give_db_updates_info' ) ); | |
| 150 | - add_action( 'wp_ajax_give_run_db_updates', array( $this, '__give_start_updating' ) ); | |
| 151 | - add_action( 'admin_init', array( $this, '__redirect_admin' ) ); | |
| 152 | - add_action( 'admin_init', array( $this, '__pause_db_update' ), - 1 ); | |
| 153 | - add_action( 'admin_init', array( $this, '__restart_db_update' ), - 1 ); | |
| 154 | - add_action( 'admin_notices', array( $this, '__show_notice' ) ); | |
| 155 | - add_action( 'give_restart_db_upgrade', array( $this, '__health_background_update' ) ); | |
| 149 | + add_action( 'init', [ $this, '__register_upgrade' ], 9999 ); | |
| 150 | + add_action( 'give_set_upgrade_completed', [$this, 'flush_resume_updates'], 9999 ); | |
| 151 | + add_action( 'wp_ajax_give_db_updates_info', [$this, 'give_db_updates_info'] ); | |
| 152 | + add_action( 'wp_ajax_give_run_db_updates', [$this, 'give_start_updating'] ); | |
| 153 | + add_action( 'admin_init', [$this, 'redirect_admin'] ); | |
| 154 | + add_action( 'admin_init', [$this, 'pause_db_update'], - 1 ); | |
| 155 | + add_action( 'admin_init', [$this, 'restart_db_update'], - 1 ); | |
| 156 | + add_action( 'admin_notices', [$this, 'show_notice'] ); | |
| 157 | + add_action( 'give_restart_db_upgrade', [$this, 'health_background_update'] ); | |
| 156 | 158 | |
| 157 | 159 | if ( is_admin() ) { |
| 158 | - add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 ); | |
| 159 | - add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 ); | |
| 160 | + add_action( 'admin_init', [$this, 'change_donations_label'], 9999 ); | |
| 161 | + add_action( 'admin_menu', [$this, 'register_menu'], 55 ); | |
| 160 | 162 | } |
| 161 | 163 | } |
| 162 | 164 | |
| 163 | 165 | /** |
| @@ -162,17 +164,18 @@ | ||
| 162 | 164 | |
| 163 | 165 | /** |
| 164 | 166 | * Register plugin add-on updates. |
| 165 | 167 | * |
| 168 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 166 | 169 | * @since 1.8.12 |
| 167 | 170 | * @access public |
| 168 | 171 | */ |
| 169 | - public function __register_plugin_addon_updates() { | |
| 170 | - $addons = give_get_plugins(); | |
| 172 | + public function register_plugin_addon_updates() { | |
| 173 | + $addons = give_get_plugins( [ 'only_premium_add_ons' => true ] ); | |
| 171 | 174 | $plugin_updates = get_plugin_updates(); |
| 172 | 175 | |
| 173 | 176 | foreach ( $addons as $key => $info ) { |
| 174 | - if ( 'active' != $info['Status'] || 'add-on' != $info['Type'] || empty( $plugin_updates[ $key ] ) ) { | |
| 177 | + if ( empty( $plugin_updates[ $key ] ) ) { | |
| 175 | 178 | continue; |
| 176 | 179 | } |
| 177 | 180 | |
| 178 | 181 | $this->updates['plugin'][] = array_merge( $info, (array) $plugin_updates[ $key ] ); |
| @@ -201,12 +204,13 @@ | ||
| 201 | 204 | |
| 202 | 205 | /** |
| 203 | 206 | * Rename `Donations` menu title if updates exists |
| 204 | 207 | * |
| 208 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 205 | 209 | * @since 1.8.12 |
| 206 | 210 | * @access public |
| 207 | 211 | */ |
| 208 | - function __change_donations_label() { | |
| 212 | + function change_donations_label() { | |
| 209 | 213 | global $menu; |
| 210 | 214 | |
| 211 | 215 | // Bailout. |
| 212 | 216 | if ( empty( $menu ) || ! $this->get_total_update_count() ) { |
| @@ -221,9 +225,9 @@ | ||
| 221 | 225 | } |
| 222 | 226 | |
| 223 | 227 | $menu[ $index ][0] = sprintf( |
| 224 | 228 | '%1$s <span class="update-plugins"><span class="plugin-count give-update-progress-count">%2$s%3$s</span></span>', |
| 225 | - __( 'Donations', 'give' ), | |
| 229 | + __( 'GiveWP', 'give' ), | |
| 226 | 230 | $is_update ? |
| 227 | 231 | $this->get_db_update_processing_percentage() : |
| 228 | 232 | $this->get_total_update_count(), |
| 229 | 233 | $is_update ? '%' : '' |
| @@ -235,14 +239,16 @@ | ||
| 235 | 239 | |
| 236 | 240 | /** |
| 237 | 241 | * Register updates menu |
| 238 | 242 | * |
| 243 | + * @since 4.14.0 update permission capability to use facade | |
| 244 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 239 | 245 | * @since 1.8.12 |
| 240 | 246 | * @access public |
| 241 | 247 | */ |
| 242 | - public function __register_menu() { | |
| 248 | + public function register_menu() { | |
| 243 | 249 | // Load plugin updates. |
| 244 | - $this->__register_plugin_addon_updates(); | |
| 250 | + $this->register_plugin_addon_updates(); | |
| 245 | 251 | |
| 246 | 252 | // Bailout. |
| 247 | 253 | if ( ! $this->get_total_update_count() ) { |
| 248 | 254 | // Show complete update message if still on update setting page. |
| @@ -249,13 +255,13 @@ | ||
| 249 | 255 | if ( isset( $_GET['page'] ) && 'give-updates' === $_GET['page'] ) { |
| 250 | 256 | // Upgrades |
| 251 | 257 | add_submenu_page( |
| 252 | 258 | 'edit.php?post_type=give_forms', |
| 253 | - esc_html__( 'Give Updates Complete', 'give' ), | |
| 259 | + esc_html__( 'GiveWP Updates Complete', 'give' ), | |
| 254 | 260 | __( 'Updates', 'give' ), |
| 255 | 261 | 'manage_give_settings', |
| 256 | 262 | 'give-updates', |
| 257 | - array( $this, 'render_complete_page' ) | |
| 263 | + [ $this, 'render_complete_page' ] | |
| 258 | 264 | ); |
| 259 | 265 | } |
| 260 | 266 | |
| 261 | 267 | return; |
| @@ -265,9 +271,9 @@ | ||
| 265 | 271 | |
| 266 | 272 | // Upgrades |
| 267 | 273 | add_submenu_page( |
| 268 | 274 | 'edit.php?post_type=give_forms', |
| 269 | - esc_html__( 'Give Updates', 'give' ), | |
| 275 | + esc_html__( 'GiveWP Updates', 'give' ), | |
| 270 | 276 | sprintf( |
| 271 | 277 | '%1$s <span class="update-plugins"%2$s><span class="plugin-count give-update-progress-count">%3$s%4$s</span></span>', |
| 272 | 278 | __( 'Updates', 'give' ), |
| 273 | 279 | isset( $_GET['give-pause-db-upgrades'] ) ? ' style="display:none;"' : '', |
| @@ -275,11 +281,11 @@ | ||
| 275 | 281 | $this->get_db_update_processing_percentage() : |
| 276 | 282 | $this->get_total_update_count(), |
| 277 | 283 | $is_update ? '%' : '' |
| 278 | 284 | ), |
| 279 | - 'manage_give_settings', | |
| 285 | + UserPermissions::settings()->manageCap(), | |
| 280 | 286 | 'give-updates', |
| 281 | - array( $this, 'render_page' ) | |
| 287 | + [ $this, 'render_page' ] | |
| 282 | 288 | ); |
| 283 | 289 | } |
| 284 | 290 | |
| 285 | 291 | |
| @@ -285,12 +291,13 @@ | ||
| 285 | 291 | |
| 286 | 292 | /** |
| 287 | 293 | * Show update related notices |
| 288 | 294 | * |
| 295 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 289 | 296 | * @since 2.0 |
| 290 | 297 | * @access public |
| 291 | 298 | */ |
| 292 | - public function __redirect_admin() { | |
| 299 | + public function redirect_admin() { | |
| 293 | 300 | // Show db upgrade completed notice. |
| 294 | 301 | if ( |
| 295 | 302 | ! wp_doing_ajax() && |
| 296 | 303 | current_user_can( 'manage_give_settings' ) && |
| @@ -307,8 +314,9 @@ | ||
| 307 | 314 | |
| 308 | 315 | /** |
| 309 | 316 | * Pause db upgrade |
| 310 | 317 | * |
| 318 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 311 | 319 | * @since 2.0.1 |
| 312 | 320 | * @access public |
| 313 | 321 | * |
| 314 | 322 | * @param bool $force |
| @@ -314,9 +322,9 @@ | ||
| 314 | 322 | * @param bool $force |
| 315 | 323 | * |
| 316 | 324 | * @return bool |
| 317 | 325 | */ |
| 318 | - public function __pause_db_update( $force = false ) { | |
| 326 | + public function pause_db_update( $force = false ) { | |
| 319 | 327 | // Bailout. |
| 320 | 328 | if ( |
| 321 | 329 | ! $force && |
| 322 | 330 | ( |
| @@ -332,9 +340,9 @@ | ||
| 332 | 340 | } |
| 333 | 341 | |
| 334 | 342 | delete_option( 'give_upgrade_error' ); |
| 335 | 343 | |
| 336 | - $this->__health_background_update( $this ); | |
| 344 | + $this->health_background_update( $this ); | |
| 337 | 345 | $batch = self::$background_updater->get_all_batch(); |
| 338 | 346 | |
| 339 | 347 | // Bailout: if batch is empty |
| 340 | 348 | if ( empty( $batch->data ) ) { |
| @@ -371,14 +379,15 @@ | ||
| 371 | 379 | |
| 372 | 380 | /** |
| 373 | 381 | * Restart db upgrade |
| 374 | 382 | * |
| 383 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 375 | 384 | * @since 2.0.1 |
| 376 | 385 | * @access public |
| 377 | 386 | * |
| 378 | 387 | * @return bool |
| 379 | 388 | */ |
| 380 | - public function __restart_db_update() { | |
| 389 | + public function restart_db_update() { | |
| 381 | 390 | // Bailout. |
| 382 | 391 | if ( |
| 383 | 392 | wp_doing_ajax() || |
| 384 | 393 | ! isset( $_GET['page'] ) || |
| @@ -399,9 +408,8 @@ | ||
| 399 | 408 | delete_option( 'give_paused_batches' ); |
| 400 | 409 | |
| 401 | 410 | Give()->logs->add( 'Update Restart', print_r( $batch, true ), 0, 'update' ); |
| 402 | 411 | |
| 403 | - | |
| 404 | 412 | /** Fire action when restart db updates |
| 405 | 413 | * |
| 406 | 414 | * @since 2.0.1 |
| 407 | 415 | */ |
| @@ -415,14 +423,15 @@ | ||
| 415 | 423 | |
| 416 | 424 | /** |
| 417 | 425 | * Health check for updates. |
| 418 | 426 | * |
| 427 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 419 | 428 | * @since 2.0 |
| 420 | 429 | * @access public |
| 421 | 430 | * |
| 422 | 431 | * @param Give_Updates $give_updates |
| 423 | 432 | */ |
| 424 | - public function __health_background_update( $give_updates ) { | |
| 433 | + public function health_background_update( $give_updates ) { | |
| 425 | 434 | if ( ! $this->is_doing_updates() ) { |
| 426 | 435 | return; |
| 427 | 436 | } |
| 428 | 437 | |
| @@ -428,13 +437,13 @@ | ||
| 428 | 437 | |
| 429 | 438 | Give_Background_Updater::flush_cache(); |
| 430 | 439 | |
| 431 | 440 | /* @var stdClass $batch */ |
| 432 | - $batch = Give_Updates::$background_updater->get_all_batch(); | |
| 433 | - $old_batch_update_ids = is_array( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); | |
| 441 | + $batch = self::$background_updater->get_all_batch(); | |
| 442 | + $old_batch_update_ids = is_array( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : []; | |
| 434 | 443 | $all_updates = $give_updates->get_updates( 'database', 'all' ); |
| 435 | 444 | $all_update_ids = wp_list_pluck( $all_updates, 'id' ); |
| 436 | - $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); | |
| 445 | + $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : []; | |
| 437 | 446 | $log_data = ''; |
| 438 | 447 | $doing_upgrade_args = get_option( 'give_doing_upgrade' ); |
| 439 | 448 | |
| 440 | 449 | if ( ! empty( $doing_upgrade_args ) ) { |
| @@ -478,9 +487,9 @@ | ||
| 478 | 487 | /** |
| 479 | 488 | * Add new upgrade to batch |
| 480 | 489 | */ |
| 481 | 490 | if ( $new_updates = $this->get_updates( 'database', 'new' ) ) { |
| 482 | - $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : array(); | |
| 491 | + $all_batch_update_ids = ! empty( $batch->data ) ? wp_list_pluck( $batch->data, 'id' ) : []; | |
| 483 | 492 | |
| 484 | 493 | foreach ( $new_updates as $index => $new_update ) { |
| 485 | 494 | if ( give_has_upgrade_completed( $new_update['id'] ) || in_array( $new_update['id'], $all_batch_update_ids ) ) { |
| 486 | 495 | unset( $new_updates[ $index ] ); |
| @@ -503,9 +512,9 @@ | ||
| 503 | 512 | // Complete batch if do not have any data to process. |
| 504 | 513 | self::$background_updater->delete( $batch->key ); |
| 505 | 514 | |
| 506 | 515 | if ( self::$background_updater->has_queue() ) { |
| 507 | - $this->__health_background_update( $this ); | |
| 516 | + $this->health_background_update( $this ); | |
| 508 | 517 | } else { |
| 509 | 518 | delete_site_transient( self::$background_updater->get_identifier() . '_process_lock' ); |
| 510 | 519 | wp_clear_scheduled_hook( self::$background_updater->get_cron_identifier() ); |
| 511 | 520 | |
| @@ -510,9 +519,8 @@ | ||
| 510 | 519 | wp_clear_scheduled_hook( self::$background_updater->get_cron_identifier() ); |
| 511 | 520 | |
| 512 | 521 | self::$background_updater->complete(); |
| 513 | 522 | } |
| 514 | - | |
| 515 | 523 | } elseif ( array_diff( wp_list_pluck( $batch->data, 'id' ), $old_batch_update_ids ) ) { |
| 516 | 524 | |
| 517 | 525 | $log_data .= 'Updating batch' . "\n"; |
| 518 | 526 | $log_data .= print_r( $batch, true ); |
| @@ -522,20 +530,19 @@ | ||
| 522 | 530 | update_option( $batch->key, $batch->data, false ); |
| 523 | 531 | } else { |
| 524 | 532 | |
| 525 | 533 | foreach ( $batch->data as $data ) { |
| 526 | - Give_Updates::$background_updater->push_to_queue( $data ); | |
| 534 | + self::$background_updater->push_to_queue( $data ); | |
| 527 | 535 | } |
| 528 | 536 | |
| 529 | - Give_Updates::$background_updater->save(); | |
| 537 | + self::$background_updater->save(); | |
| 530 | 538 | } |
| 531 | 539 | } |
| 532 | 540 | |
| 533 | - | |
| 534 | 541 | /** |
| 535 | 542 | * Fix give_doing_upgrade option |
| 536 | 543 | */ |
| 537 | - if( $fresh_new_db_count = $this->get_total_new_db_update_count( true ) ) { | |
| 544 | + if ( $fresh_new_db_count = $this->get_total_new_db_update_count( true ) ) { | |
| 538 | 545 | update_option( 'give_db_update_count', $fresh_new_db_count, false ); |
| 539 | 546 | } |
| 540 | 547 | |
| 541 | 548 | $doing_upgrade_args['update'] = 1; |
| @@ -566,9 +573,9 @@ | ||
| 566 | 573 | break; |
| 567 | 574 | } |
| 568 | 575 | } |
| 569 | 576 | |
| 570 | - if( ! empty( $doing_upgrade_args['update_info'] ) ) { | |
| 577 | + if ( ! empty( $doing_upgrade_args['update_info'] ) ) { | |
| 571 | 578 | update_option( 'give_doing_upgrade', $doing_upgrade_args, false ); |
| 572 | 579 | |
| 573 | 580 | $log_data .= 'Updated doing update:' . "\n"; |
| 574 | 581 | $log_data .= print_r( $doing_upgrade_args, true ) . "\n"; |
| @@ -580,13 +587,19 @@ | ||
| 580 | 587 | |
| 581 | 588 | /** |
| 582 | 589 | * Show update related notices |
| 583 | 590 | * |
| 591 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 584 | 592 | * @since 2.0 |
| 585 | 593 | * @access public |
| 586 | 594 | */ |
| 587 | - public function __show_notice() { | |
| 595 | + public function show_notice() { | |
| 588 | 596 | $current_screen = get_current_screen(); |
| 597 | + $hide_on_pages = [ | |
| 598 | + 'give_forms_page_give-updates', | |
| 599 | + 'update-core', | |
| 600 | + 'give_forms_page_give-addons', | |
| 601 | + ]; | |
| 589 | 602 | |
| 590 | 603 | // Bailout. |
| 591 | 604 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
| 592 | 605 | return; |
| @@ -596,11 +609,10 @@ | ||
| 596 | 609 | if ( ! empty( $_GET['give-run-db-update'] ) ) { |
| 597 | 610 | $this->run_db_update(); |
| 598 | 611 | } |
| 599 | 612 | |
| 600 | - | |
| 601 | 613 | // Bailout. |
| 602 | - if ( in_array( $current_screen->base, array( 'give_forms_page_give-updates', 'update-core' ) ) ) { | |
| 614 | + if ( in_array( $current_screen->base, $hide_on_pages ) ) { | |
| 603 | 615 | return; |
| 604 | 616 | } |
| 605 | 617 | |
| 606 | 618 | // Show notice if upgrade paused. |
| @@ -612,25 +624,27 @@ | ||
| 612 | 624 | <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
| 613 | 625 | – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a backup before proceeding.', 'give' ); ?> |
| 614 | 626 | <br> |
| 615 | 627 | <br> |
| 616 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-restart-db-upgrades' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-restart-updater-btn"> | |
| 628 | + <a href="<?php echo esc_url( add_query_arg( [ 'give-restart-db-upgrades' => 1 ], admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-restart-updater-btn"> | |
| 617 | 629 | <?php _e( 'Restart the updater', 'give' ); ?> |
| 618 | 630 | </a> |
| 619 | - <?php else: ?> | |
| 631 | + <?php else : ?> | |
| 620 | 632 | <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
| 621 | 633 | – <?php _e( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); ?> |
| 622 | - <a href="<?php echo esc_url('http://docs.givewp.com/troubleshooting-db-updates')?>" target="_blank"><?php _e( 'Read More', 'give' ); ?> »</a> | |
| 623 | - <?php | |
| 634 | + <a href="<?php echo esc_url( 'http://docs.givewp.com/troubleshooting-db-updates' ); ?>" target="_blank"><?php _e( 'Read More', 'give' ); ?> »</a> | |
| 635 | + <?php | |
| 624 | 636 | endif; |
| 625 | 637 | $desc_html = ob_get_clean(); |
| 626 | 638 | |
| 627 | - Give()->notices->register_notice( array( | |
| 628 | - 'id' => 'give_upgrade_db', | |
| 629 | - 'type' => 'error', | |
| 630 | - 'dismissible' => false, | |
| 631 | - 'description' => $desc_html, | |
| 632 | - ) ); | |
| 639 | + Give()->notices->register_notice( | |
| 640 | + [ | |
| 641 | + 'id' => 'give_upgrade_db', | |
| 642 | + 'type' => 'error', | |
| 643 | + 'dismissible' => false, | |
| 644 | + 'description' => $desc_html, | |
| 645 | + ] | |
| 646 | + ); | |
| 633 | 647 | } |
| 634 | 648 | |
| 635 | 649 | // Bailout if doing upgrades. |
| 636 | 650 | if ( $this->is_doing_updates() ) { |
| @@ -638,14 +652,16 @@ | ||
| 638 | 652 | } |
| 639 | 653 | |
| 640 | 654 | // Show db upgrade completed notice. |
| 641 | 655 | if ( ! empty( $_GET['give-db-update-completed'] ) ) { |
| 642 | - Give()->notices->register_notice( array( | |
| 643 | - 'id' => 'give_db_upgrade_completed', | |
| 644 | - 'type' => 'updated', | |
| 645 | - 'description' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), | |
| 646 | - 'show' => true, | |
| 647 | - ) ); | |
| 656 | + Give()->notices->register_notice( | |
| 657 | + [ | |
| 658 | + 'id' => 'give_db_upgrade_completed', | |
| 659 | + 'type' => 'updated', | |
| 660 | + 'description' => __( 'GiveWP database updates completed successfully. Thank you for updating to the latest version!', 'give' ), | |
| 661 | + 'show' => true, | |
| 662 | + ] | |
| 663 | + ); | |
| 648 | 664 | |
| 649 | 665 | // Start update. |
| 650 | 666 | } elseif ( ! empty( $_GET['give-run-db-update'] ) ) { |
| 651 | 667 | $this->run_db_update(); |
| @@ -658,9 +674,9 @@ | ||
| 658 | 674 | <strong><?php _e( 'Database Update', 'give' ); ?></strong> |
| 659 | 675 | – <?php _e( 'GiveWP needs to update your database to the latest version. The following process will make updates to your site\'s database. Please create a complete backup before proceeding.', 'give' ); ?> |
| 660 | 676 | </p> |
| 661 | 677 | <p class="submit"> |
| 662 | - <a href="<?php echo esc_url( add_query_arg( array( 'give-run-db-update' => 1 ), admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-run-update-now"> | |
| 678 | + <a href="<?php echo esc_url( add_query_arg( [ 'give-run-db-update' => 1 ], admin_url( 'edit.php?post_type=give_forms&page=give-updates' ) ) ); ?>" class="button button-primary give-run-update-now"> | |
| 663 | 679 | <?php _e( 'Run the updater', 'give' ); ?> |
| 664 | 680 | </a> |
| 665 | 681 | </p> |
| 666 | 682 | <?php |
| @@ -665,14 +681,16 @@ | ||
| 665 | 681 | </p> |
| 666 | 682 | <?php |
| 667 | 683 | $desc_html = ob_get_clean(); |
| 668 | 684 | |
| 669 | - Give()->notices->register_notice( array( | |
| 670 | - 'id' => 'give_upgrade_db', | |
| 671 | - 'type' => 'updated', | |
| 672 | - 'dismissible' => false, | |
| 673 | - 'description' => $desc_html, | |
| 674 | - ) ); | |
| 685 | + Give()->notices->register_notice( | |
| 686 | + [ | |
| 687 | + 'id' => 'give_upgrade_db', | |
| 688 | + 'type' => 'updated', | |
| 689 | + 'dismissible' => false, | |
| 690 | + 'description' => $desc_html, | |
| 691 | + ] | |
| 692 | + ); | |
| 675 | 693 | } |
| 676 | 694 | } |
| 677 | 695 | |
| 678 | 696 | /** |
| @@ -714,16 +732,21 @@ | ||
| 714 | 732 | } |
| 715 | 733 | |
| 716 | 734 | add_option( 'give_db_update_count', count( $updates ), '', false ); |
| 717 | 735 | |
| 718 | - add_option( 'give_doing_upgrade', array( | |
| 719 | - 'update_info' => $updates[0], | |
| 720 | - 'step' => 1, | |
| 721 | - 'update' => 1, | |
| 722 | - 'heading' => sprintf( 'Update %s of %s', 1, count( $updates ) ), | |
| 723 | - 'percentage' => 0, | |
| 724 | - 'total_percentage' => 0, | |
| 725 | - ), '', false ); | |
| 736 | + add_option( | |
| 737 | + 'give_doing_upgrade', | |
| 738 | + [ | |
| 739 | + 'update_info' => $updates[0], | |
| 740 | + 'step' => 1, | |
| 741 | + 'update' => 1, | |
| 742 | + 'heading' => sprintf( 'Update %s of %s', 1, count( $updates ) ), | |
| 743 | + 'percentage' => 0, | |
| 744 | + 'total_percentage' => 0, | |
| 745 | + ], | |
| 746 | + '', | |
| 747 | + false | |
| 748 | + ); | |
| 726 | 749 | |
| 727 | 750 | self::$background_updater->save()->dispatch(); |
| 728 | 751 | } |
| 729 | 752 | |
| @@ -730,16 +753,13 @@ | ||
| 730 | 753 | |
| 731 | 754 | /** |
| 732 | 755 | * Delete resume updates |
| 733 | 756 | * |
| 757 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 734 | 758 | * @since 1.8.12 |
| 735 | 759 | * @access public |
| 736 | 760 | */ |
| 737 | - public function __flush_resume_updates() { | |
| 738 | - //delete_option( 'give_doing_upgrade' ); | |
| 739 | - update_option( 'give_version', preg_replace( '/[^0-9.].*/', '', GIVE_VERSION ), false ); | |
| 740 | - | |
| 741 | - // Reset counter. | |
| 761 | + public function flush_resume_updates() { | |
| 742 | 762 | $this->step = $this->percentage = 0; |
| 743 | 763 | |
| 744 | 764 | $this->update = ( $this->get_total_db_update_count() > $this->update ) ? |
| 745 | 765 | ( $this->update + 1 ) : |
| @@ -749,14 +769,15 @@ | ||
| 749 | 769 | |
| 750 | 770 | /** |
| 751 | 771 | * Initialize updates |
| 752 | 772 | * |
| 773 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 753 | 774 | * @since 2.0 |
| 754 | 775 | * @access public |
| 755 | 776 | * |
| 756 | 777 | * @return void |
| 757 | 778 | */ |
| 758 | - public function __give_start_updating() { | |
| 779 | + public function give_start_updating() { | |
| 759 | 780 | // Check permission. |
| 760 | 781 | if ( |
| 761 | 782 | ! current_user_can( 'manage_give_settings' ) || |
| 762 | 783 | $this->is_doing_updates() |
| @@ -781,14 +802,15 @@ | ||
| 781 | 802 | |
| 782 | 803 | /** |
| 783 | 804 | * This function handle ajax query for dn update status. |
| 784 | 805 | * |
| 806 | + * @since 4.9.0 rename function - PHP 8 compatibility | |
| 785 | 807 | * @since 2.0 |
| 786 | 808 | * @access public |
| 787 | 809 | * |
| 788 | 810 | * @return string |
| 789 | 811 | */ |
| 790 | - public function __give_db_updates_info() { | |
| 812 | + public function give_db_updates_info() { | |
| 791 | 813 | // Check permission. |
| 792 | 814 | if ( ! current_user_can( 'manage_give_settings' ) ) { |
| 793 | 815 | give_die(); |
| 794 | 816 | } |
| @@ -796,13 +818,13 @@ | ||
| 796 | 818 | $update_info = get_option( 'give_doing_upgrade' ); |
| 797 | 819 | $response_type = ''; |
| 798 | 820 | |
| 799 | 821 | if ( self::$background_updater->is_paused_process() ) { |
| 800 | - $update_info = array( | |
| 822 | + $update_info = [ | |
| 801 | 823 | 'message' => __( 'The updates have been paused.', 'give' ), |
| 802 | 824 | 'heading' => '', |
| 803 | 825 | 'percentage' => 0, |
| 804 | - ); | |
| 826 | + ]; | |
| 805 | 827 | |
| 806 | 828 | if ( get_option( 'give_upgrade_error' ) ) { |
| 807 | 829 | $update_info['message'] = __( 'An unexpected issue occurred during the database update which caused it to stop automatically. Please contact support for assistance.', 'give' ); |
| 808 | 830 | } |
| @@ -809,13 +831,13 @@ | ||
| 809 | 831 | |
| 810 | 832 | $response_type = 'error'; |
| 811 | 833 | |
| 812 | 834 | } elseif ( empty( $update_info ) || ! $this->get_total_new_db_update_count( true ) ) { |
| 813 | - $update_info = array( | |
| 814 | - 'message' => __( 'Give database updates completed successfully. Thank you for updating to the latest version!', 'give' ), | |
| 835 | + $update_info = [ | |
| 836 | + 'message' => __( 'GiveWP database updates completed successfully. Thank you for updating to the latest version!', 'give' ), | |
| 815 | 837 | 'heading' => __( 'Updates Completed.', 'give' ), |
| 816 | 838 | 'percentage' => 0, |
| 817 | - ); | |
| 839 | + ]; | |
| 818 | 840 | $response_type = 'success'; |
| 819 | 841 | |
| 820 | 842 | delete_option( 'give_show_db_upgrade_complete_notice' ); |
| 821 | 843 | } |
| @@ -832,15 +854,15 @@ | ||
| 832 | 854 | * @param $data |
| 833 | 855 | * @param string $type |
| 834 | 856 | */ |
| 835 | 857 | public function send_ajax_response( $data, $type = '' ) { |
| 836 | - $default = array( | |
| 858 | + $default = [ | |
| 837 | 859 | 'message' => '', |
| 838 | 860 | 'heading' => '', |
| 839 | 861 | 'percentage' => 0, |
| 840 | 862 | 'step' => 0, |
| 841 | 863 | 'update' => 0, |
| 842 | - ); | |
| 864 | + ]; | |
| 843 | 865 | |
| 844 | 866 | // Set data. |
| 845 | 867 | $data = wp_parse_args( $data, $default ); |
| 846 | 868 | |
| @@ -856,11 +878,13 @@ | ||
| 856 | 878 | wp_send_json_error( $data ); |
| 857 | 879 | break; |
| 858 | 880 | |
| 859 | 881 | default: |
| 860 | - wp_send_json( array( | |
| 861 | - 'data' => $data, | |
| 862 | - ) ); | |
| 882 | + wp_send_json( | |
| 883 | + [ | |
| 884 | + 'data' => $data, | |
| 885 | + ] | |
| 886 | + ); | |
| 863 | 887 | break; |
| 864 | 888 | } |
| 865 | 889 | } |
| 866 | 890 | |
| @@ -922,9 +946,9 @@ | ||
| 922 | 946 | * @access public |
| 923 | 947 | * @return bool |
| 924 | 948 | */ |
| 925 | 949 | public function is_doing_updates() { |
| 926 | - return (bool) get_option( 'give_doing_upgrade' ); | |
| 950 | + return (bool) Give_Cache_Setting::get_option( 'give_doing_upgrade' ); | |
| 927 | 951 | } |
| 928 | 952 | |
| 929 | 953 | |
| 930 | 954 | /** |
| @@ -941,14 +965,14 @@ | ||
| 941 | 965 | $is_valid_dependency = true; |
| 942 | 966 | // $update_ids = wp_list_pluck( $this->get_updates( 'database', 'all' ), 'id' ); |
| 943 | 967 | // |
| 944 | 968 | // foreach ( $update['depend'] as $depend ) { |
| 945 | - // // Check if dependency is valid or not. | |
| 946 | - // if ( ! in_array( $depend, $update_ids ) ) { | |
| 947 | - // $is_valid_dependency = false; | |
| 948 | - // break; | |
| 949 | - // } | |
| 969 | + // Check if dependency is valid or not. | |
| 970 | + // if ( ! in_array( $depend, $update_ids ) ) { | |
| 971 | + // $is_valid_dependency = false; | |
| 972 | + // break; | |
| 950 | 973 | // } |
| 974 | + // } | |
| 951 | 975 | |
| 952 | 976 | return $is_valid_dependency; |
| 953 | 977 | } |
| 954 | 978 | |
| @@ -969,9 +993,9 @@ | ||
| 969 | 993 | return $this->updates; |
| 970 | 994 | } |
| 971 | 995 | |
| 972 | 996 | // Get specific update. |
| 973 | - $updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : array(); | |
| 997 | + $updates = ! empty( $this->updates[ $update_type ] ) ? $this->updates[ $update_type ] : []; | |
| 974 | 998 | |
| 975 | 999 | // Bailout. |
| 976 | 1000 | if ( empty( $updates ) ) { |
| 977 | 1001 | return $updates; |