No Description

Settings.php 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Implements a batch processor for updating settings after new version.
  10. *
  11. * @since 1.7.0
  12. *
  13. * @see PUM_Abstract_Upgrade
  14. */
  15. abstract class PUM_Abstract_Upgrade_Settings extends PUM_Abstract_Upgrade {
  16. /**
  17. * Batch process ID.
  18. *
  19. * @var string
  20. */
  21. public $batch_id = '';
  22. /**
  23. * Executes a single step in the batch process.
  24. *
  25. * @return int|string|WP_Error Next step number, 'done', or a WP_Error object.
  26. */
  27. public function process_step() {
  28. // Allows sending a start & success message separately.
  29. if ( $this->step > 1 ) {
  30. return 'done';
  31. }
  32. $settings = pum_get_options();
  33. $this->process_settings( $settings );
  34. return ++ $this->step;
  35. }
  36. /**
  37. * Retrieves a message for the given code.
  38. *
  39. * @param string $code Message code.
  40. *
  41. * @return string Message.
  42. */
  43. public function get_message( $code ) {
  44. switch ( $code ) {
  45. case 'start':
  46. $message = sprintf( __( 'Updating settings for v%s compatibility.', 'popup-maker' ), '1.7' );
  47. break;
  48. case 'done':
  49. $message = __( 'Settings updated successfully.', 'popup-maker' );
  50. break;
  51. default:
  52. $message = '';
  53. break;
  54. }
  55. return $message;
  56. }
  57. /**
  58. * Process needed upgrades on Popup Maker settings
  59. *
  60. * You need to handle saving!!!
  61. *
  62. * @param array $settings
  63. */
  64. abstract public function process_settings( $settings = array() );
  65. }