WPSEO_Replace_Vars::set_up_replacements()privateYoast 1.0

Retrieve the replacements for the variables found.

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

Хуков нет.

Возвращает

Массив. Retrieved replacements - this might be a smaller array as some variables may not yield a replacement in certain contexts.

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

// private - только в коде основоного (родительского) класса
$result = $this->set_up_replacements( $matches, $omit );
$matches(массив) (обязательный)
Variables found in the original string - regex result.
$omit(массив) (обязательный)
Variables that should not be replaced by this function.

Код WPSEO_Replace_Vars::set_up_replacements() Yoast 22.4

private function set_up_replacements( $matches, $omit ) {

	$replacements = [];

	// @todo Figure out a way to deal with external functions starting with cf_/ct_.
	foreach ( $matches[1] as $k => $var ) {

		// Don't set up replacements which should be omitted.
		if ( in_array( $var, $omit, true ) ) {
			continue;
		}

		// Deal with variable variable names first.
		if ( strpos( $var, 'cf_' ) === 0 ) {
			$replacement = $this->retrieve_cf_custom_field_name( $var );
		}
		elseif ( strpos( $var, 'ct_desc_' ) === 0 ) {
			$replacement = $this->retrieve_ct_desc_custom_tax_name( $var );
		}
		elseif ( strpos( $var, 'ct_' ) === 0 ) {
			$single      = ( isset( $matches[2][ $k ] ) && $matches[2][ $k ] !== '' );
			$replacement = $this->retrieve_ct_custom_tax_name( $var, $single );
		}
		// Deal with non-variable variable names.
		elseif ( method_exists( $this, 'retrieve_' . $var ) ) {
			$method_name = 'retrieve_' . $var;
			$replacement = $this->$method_name();
		}
		// Deal with externally defined variable names.
		elseif ( isset( self::$external_replacements[ $var ] ) && ! is_null( self::$external_replacements[ $var ] ) ) {
			$replacement = call_user_func( self::$external_replacements[ $var ], $var, $this->args );
		}

		// Replacement retrievals can return null if no replacement can be determined, root those outs.
		if ( isset( $replacement ) ) {
			$var                  = self::add_var_delimiter( $var );
			$replacements[ $var ] = $replacement;
		}
		unset( $replacement, $single, $method_name );
	}

	return $replacements;
}