context = $context; $this->options = $options ?: new Options( $context ); $this->sign_in_with_google_settings = new Sign_In_With_Google_Settings( $this->options ); } /** * Registers hooks. * * @since 1.163.0 */ public function register() { add_action( 'admin_init', array( $this, 'migrate' ) ); } /** * Migrates the DB. * * @since 1.163.0 */ public function migrate() { $db_version = $this->options->get( self::DB_VERSION_OPTION ); if ( ! $db_version || version_compare( $db_version, self::DB_VERSION, '<' ) ) { $this->migrate_one_tap_enabled_setting(); $this->options->set( self::DB_VERSION_OPTION, self::DB_VERSION ); } } /** * Migrates the One Tap Setting to the most conservative value based * on previous user settings. * * Given the new setting is equivalent to the old setting of * "One Tap on all pages", we only set One Tap to be enabled if * the no-longer-used "One Tap on all pages" setting was set to true. * * @since 1.163.0 */ protected function migrate_one_tap_enabled_setting() { if ( ! $this->sign_in_with_google_settings->has() ) { return; } $sign_in_with_google_settings = $this->sign_in_with_google_settings->get(); if ( ! is_array( $sign_in_with_google_settings ) || empty( $sign_in_with_google_settings ) ) { return; } if ( array_key_exists( 'oneTapOnAllPages', $sign_in_with_google_settings ) && true === $sign_in_with_google_settings['oneTapOnAllPages'] ) { $sign_in_with_google_settings['oneTapEnabled'] = true; } else { $sign_in_with_google_settings['oneTapEnabled'] = false; } unset( $sign_in_with_google_settings['oneTapOnAllPages'] ); // Save the updated settings. $this->sign_in_with_google_settings->set( $sign_in_with_google_settings ); } }