WPSEO_Replace_Vars::retrieve_ct_desc_custom_tax_name()privateYoast 1.0

Retrieve a post/page/cpt's custom taxonomies description for use as replacement string.

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

Хуков нет.

Возвращает

Строку|null.

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

// private - только в коде основоного (родительского) класса
$result = $this->retrieve_ct_desc_custom_tax_name( $var_to_replace );
$var_to_replace(строка) (обязательный)
The complete variable to replace which includes the name of the custom taxonomy which description is to be retrieved.

Код WPSEO_Replace_Vars::retrieve_ct_desc_custom_tax_name() Yoast 22.4

private function retrieve_ct_desc_custom_tax_name( $var_to_replace ) {
	$replacement = null;

	if ( is_string( $var_to_replace ) && $var_to_replace !== '' ) {
		$tax = substr( $var_to_replace, 8 );
		if ( ! empty( $this->args->ID ) ) {
			$terms = get_the_terms( $this->args->ID, $tax );
			if ( is_array( $terms ) && $terms !== [] ) {
				$term      = current( $terms );
				$term_desc = get_term_field( 'description', $term->term_id, $tax );
				if ( $term_desc !== '' ) {
					$replacement = wp_strip_all_tags( $term_desc );
				}
			}
		}
	}

	return $replacement;
}