class-acf-ajax-upgrade.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. if ( ! class_exists( 'ACF_Ajax_Upgrade' ) ) :
  6. class ACF_Ajax_Upgrade extends ACF_Ajax {
  7. /** @var string The AJAX action name */
  8. var $action = 'acf/ajax/upgrade';
  9. /**
  10. * get_response
  11. *
  12. * Returns the response data to sent back.
  13. *
  14. * @date 31/7/18
  15. * @since 5.7.2
  16. *
  17. * @param array $request The request args.
  18. * @return mixed The response data or WP_Error.
  19. */
  20. function get_response( $request ) {
  21. // Switch blog.
  22. if ( isset( $request['blog_id'] ) ) {
  23. switch_to_blog( $request['blog_id'] );
  24. }
  25. // Bail early if no upgrade avaiable.
  26. if ( ! acf_has_upgrade() ) {
  27. return new WP_Error( 'upgrade_error', __( 'No updates available.', 'acf' ) );
  28. }
  29. // Listen for output.
  30. ob_start();
  31. // Run upgrades.
  32. acf_upgrade_all();
  33. // Store output.
  34. $error = ob_get_clean();
  35. // Return error or success.
  36. if ( $error ) {
  37. return new WP_Error( 'upgrade_error', $error );
  38. }
  39. return true;
  40. }
  41. }
  42. acf_new_instance( 'ACF_Ajax_Upgrade' );
  43. endif; // class_exists check