WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Получай пассивный доход от сайта с помощью браузерных PUSH уведомлений
функция не описана

WPSEO_Replace_Vars::replace() public Yoast 1.0

Replace %%variable_placeholders%% with their real value based on the current requested page/post/cpt/etc.

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

Хуки из метода
Возвращает

Строку. Ничего.

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

$WPSEO_Replace_Vars = new WPSEO_Replace_Vars();
$WPSEO_Replace_Vars->replace( $string, $args, $omit );
$string(строка) (обязательный)
The string to replace the variables in.
$args(массив) (обязательный)
The object some of the replacement values might come from, could be a post, taxonomy or term.
$omit(массив)
Variables that should not be replaced by this function.

Код WPSEO_Replace_Vars::replace() Yoast 16.2

<?php
public function replace( $string, $args, $omit = [] ) {

	$string = wp_strip_all_tags( $string );

	// Let's see if we can bail super early.
	if ( strpos( $string, '%%' ) === false ) {
		return YoastSEO()->helpers->string->standardize_whitespace( $string );
	}

	$args = (array) $args;
	if ( isset( $args['post_content'] ) && ! empty( $args['post_content'] ) ) {
		$args['post_content'] = YoastSEO()->helpers->string->strip_shortcode( $args['post_content'] );
	}
	if ( isset( $args['post_excerpt'] ) && ! empty( $args['post_excerpt'] ) ) {
		$args['post_excerpt'] = YoastSEO()->helpers->string->strip_shortcode( $args['post_excerpt'] );
	}
	$this->args = (object) wp_parse_args( $args, $this->defaults );

	// Clean $omit array.
	if ( is_array( $omit ) && $omit !== [] ) {
		$omit = array_map( [ __CLASS__, 'remove_var_delimiter' ], $omit );
	}

	$replacements = [];
	if ( preg_match_all( '`%%([^%]+(%%single)?)%%?`iu', $string, $matches ) ) {
		$replacements = $this->set_up_replacements( $matches, $omit );
	}

	/**
	 * Filter: 'wpseo_replacements' - Allow customization of the replacements before they are applied.
	 *
	 * @api     array   $replacements The replacements.
	 *
	 * @param array $args The object some of the replacement values might come from,
	 *                    could be a post, taxonomy or term.
	 */
	$replacements = apply_filters( 'wpseo_replacements', $replacements, $this->args );

	// Do the actual replacements.
	if ( is_array( $replacements ) && $replacements !== [] ) {
		$string = str_replace(
			array_keys( $replacements ),
			// Make sure to exclude replacement values that are arrays e.g. coming from a custom field serialized value.
			array_filter( array_values( $replacements ), 'is_scalar' ),
			$string
		);
	}

	/**
	 * Filter: 'wpseo_replacements_final' - Allow overruling of whether or not to remove placeholders
	 * which didn't yield a replacement.
	 *
	 * @example <code>add_filter( 'wpseo_replacements_final', '__return_false' );</code>
	 *
	 * @api     bool $final
	 */
	if ( apply_filters( 'wpseo_replacements_final', true ) === true && ( isset( $matches[1] ) && is_array( $matches[1] ) ) ) {
		// Remove non-replaced variables.
		$remove = array_diff( $matches[1], $omit ); // Make sure the $omit variables do not get removed.
		$remove = array_map( [ __CLASS__, 'add_var_delimiter' ], $remove );
		$string = str_replace( $remove, '', $string );
	}

	// Undouble separators which have nothing between them, i.e. where a non-replaced variable was removed.
	if ( isset( $replacements['%%sep%%'] ) && ( is_string( $replacements['%%sep%%'] ) && $replacements['%%sep%%'] !== '' ) ) {
		$q_sep  = preg_quote( $replacements['%%sep%%'], '`' );
		$string = preg_replace( '`' . $q_sep . '(?:\s*' . $q_sep . ')*`u', $replacements['%%sep%%'], $string );
	}

	// Remove superfluous whitespace.
	$string = YoastSEO()->helpers->string->standardize_whitespace( $string );

	return $string;
}