Нет описания

class-pum-admin-upgrade-routine.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Upgrade Routine Class
  4. *
  5. * @package PUM
  6. * @subpackage Admin/Upgrades
  7. * @copyright Copyright (c) 2019, Code Atlantic LLC
  8. * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
  9. * @since 1.4
  10. */
  11. // Exit if accessed directly
  12. if ( ! defined( 'ABSPATH' ) ) {
  13. exit;
  14. }
  15. /**
  16. * Class PUM_Admin_Upgrade_Routine
  17. */
  18. class PUM_Admin_Upgrade_Routine {
  19. /**
  20. * Describe the upgrade routine.
  21. *
  22. * @return string
  23. */
  24. public static function description() {
  25. return '';
  26. }
  27. /**
  28. * Run the upgrade routine.
  29. *
  30. * @return void
  31. */
  32. public static function run() {
  33. }
  34. /**
  35. * Properly redirects or returns redirect url if DOING_AJAX.
  36. *
  37. * @param string $redirect
  38. */
  39. public static function redirect( $redirect = '' ) {
  40. wp_redirect( $redirect );
  41. exit;
  42. }
  43. /**
  44. * Generate the next step ajax response or redirect.
  45. */
  46. public static function next_step() {
  47. $upgrades = PUM_Admin_Upgrades::instance();
  48. $upgrades->step_up();
  49. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  50. echo wp_json_encode( array(
  51. 'status' => sprintf( __( 'Step %d of approximately %d running', 'popup-maker' ), $upgrades->get_arg( 'step' ), $upgrades->get_arg( 'steps' ) ),
  52. 'next' => $upgrades->get_args(),
  53. ) );
  54. exit;
  55. } else {
  56. $redirect = add_query_arg( $upgrades->get_args(), admin_url() );
  57. PUM_Admin_Upgrade_Routine::redirect( $redirect );
  58. }
  59. }
  60. public static function done() {
  61. $upgrades = PUM_Admin_Upgrades::instance();
  62. delete_option( 'pum_doing_upgrade' );
  63. $upgrades->set_upgrade_complete( $upgrades->current_routine() );
  64. $upgrades->set_pum_db_ver( $upgrades->get_arg( 'pum-upgrade' ) );
  65. $next_routine = $upgrades->next_routine();
  66. if ( $upgrades->has_upgrades() && $next_routine && $upgrades->get_upgrade( $next_routine ) ) {
  67. if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  68. $upgrades->set_arg( 'step', 1 );
  69. $upgrades->set_arg( 'completed', 0 );
  70. $upgrades->set_arg( 'pum-upgrade', $next_routine );
  71. echo wp_json_encode( array(
  72. 'status' => sprintf( '<strong>%s</strong>', $upgrades->get_upgrade( $next_routine ) ),
  73. 'next' => $upgrades->get_args(),
  74. ) );
  75. exit;
  76. }
  77. }
  78. }
  79. }