WPSEO_Option::get_switch_key()protectedYoast 1.0

Check whether a given array key conforms to one of the variable array key patterns for this option.

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

Хуков нет.

Возвращает

Строку. Pattern if it conforms, original array key if it doesn't or if the option does not have variable array keys.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_switch_key( $key );
$key(строка) (обязательный)
Array key to check.

Код WPSEO_Option::get_switch_key() Yoast 22.3

protected function get_switch_key( $key ) {
	if ( ! isset( $this->variable_array_key_patterns ) || ( ! is_array( $this->variable_array_key_patterns ) || $this->variable_array_key_patterns === [] ) ) {
		return $key;
	}

	foreach ( $this->variable_array_key_patterns as $pattern ) {
		if ( strpos( $key, $pattern ) === 0 ) {
			return $pattern;
		}
	}

	return $key;
}