product type slug. * * @var array */ public const array LEGACY_OPTIONS = array( 'simple_button_text_single' => 'simple', 'grouped_button_text_single' => 'grouped', ); /** * Constructor. * * @param Settings $settings Settings repository. */ public function __construct( private Settings $settings ) {} /** * Runs the migration once per plugin version. * * @return void */ public function maybe_run(): void { if ( VERSION === get_option( self::DB_VERSION_OPTION ) ) { return; } $settings = $this->settings->all(); $changed = false; foreach ( self::LEGACY_OPTIONS as $option => $type ) { $legacy = get_option( $option, null ); if ( null === $legacy ) { continue; } $legacy = is_scalar( $legacy ) ? (string) $legacy : ''; $single = Context::Single->value; // Version 1.x only changed the text on single product pages; never overwrite new settings. if ( '' !== $legacy && '' === ( $settings['texts'][ $type ][ $single ] ?? '' ) ) { $settings['texts'][ $type ][ $single ] = $legacy; $changed = true; } delete_option( $option ); } if ( $changed || false === get_option( Settings::OPTION, false ) ) { $this->settings->save( $settings ); } update_option( self::DB_VERSION_OPTION, VERSION ); } }