WPSEO_Option::retain_variable_keys()protectedYoast 1.0

Make sure that any set option values relating to post_types and/or taxonomies are retained, even when that post_type or taxonomy may not yet have been registered.

{@internal The wpseo_titles concrete class overrules this method. Make sure that any changes applied here, also get ported to that version.}}

Метод класса: WPSEO_Option{}

Хуков нет.

Возвращает

Массив.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->retain_variable_keys( $dirty, $clean );
$dirty(массив) (обязательный)
Original option as retrieved from the database.
$clean(массив) (обязательный)
Filtered option where any options which shouldn't be in our option have already been removed and any options which weren't set have been set to their defaults.

Код WPSEO_Option::retain_variable_keys() Yoast 24.9

protected function retain_variable_keys( $dirty, $clean ) {
	if ( ( is_array( $this->variable_array_key_patterns ) && $this->variable_array_key_patterns !== [] ) && ( is_array( $dirty ) && $dirty !== [] ) ) {
		foreach ( $dirty as $key => $value ) {

			// Do nothing if already in filtered options.
			if ( isset( $clean[ $key ] ) ) {
				continue;
			}

			foreach ( $this->variable_array_key_patterns as $pattern ) {

				if ( strpos( $key, $pattern ) === 0 ) {
					$clean[ $key ] = $value;
					break;
				}
			}
		}
	}

	return $clean;
}