register_legacy_keys_migration( array( 'AMPExperimentJson' => 'ampExperimentJSON', 'ampExperimentJson' => 'ampExperimentJSON', 'optimize_id' => 'optimizeID', 'optimizeId' => 'optimizeID', ) ); $this->register_owned_keys(); add_filter( 'option_' . self::OPTION, function ( $option ) { // Migrate legacy values where this was saved as decoded JSON object. if ( is_array( $option ) && array_key_exists( 'ampExperimentJSON', $option ) && ! is_string( $option['ampExperimentJSON'] ) ) { if ( empty( $option['ampExperimentJSON'] ) ) { $option['ampExperimentJSON'] = ''; } else { $option['ampExperimentJSON'] = wp_json_encode( $option['ampExperimentJSON'] ); } } return $option; } ); } /** * Returns keys for owned settings. * * @since 1.16.0 * * @return array An array of keys for owned settings. */ public function get_owned_keys() { return array( 'optimizeID', ); } /** * Gets the default value. * * @since 1.2.0 * * @return array */ protected function get_default() { return array( 'ownerID' => 0, 'ampExperimentJSON' => '', 'optimizeID' => '', 'placeAntiFlickerSnippet' => false, ); } /** * Gets the callback for sanitizing the setting's value before saving. * * @since 1.39.0 * * @return callable|null */ protected function get_sanitize_callback() { return function( $option ) { if ( is_array( $option ) ) { if ( isset( $option['placeAntiFlickerSnippet'] ) ) { $option['placeAntiFlickerSnippet'] = (bool) $option['placeAntiFlickerSnippet']; } } return $option; }; } }