WPSEO_Replace_Vars::retrieve_excerpt()privateYoast 1.0

Retrieve the post/page/cpt excerpt for use as replacement string. The excerpt will be auto-generated if it does not exist.

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

Хуков нет.

Возвращает

Строку|null.

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

// private - только в коде основоного (родительского) класса
$result = $this->retrieve_excerpt();

Код WPSEO_Replace_Vars::retrieve_excerpt() Yoast 22.4

private function retrieve_excerpt() {
	$replacement = null;
	$locale      = get_locale();

	// Japanese doesn't have a jp_JP variant in WP.
	$limit = ( $locale === 'ja' ) ? 80 : 156;

	// The check `post_password_required` is because excerpt must be hidden for a post with a password.
	if ( ! empty( $this->args->ID ) && ! post_password_required( $this->args->ID ) ) {
		if ( $this->args->post_excerpt !== '' ) {
			$replacement = wp_strip_all_tags( $this->args->post_excerpt );
		}
		elseif ( $this->args->post_content !== '' ) {
			$content = strip_shortcodes( $this->args->post_content );
			$content = wp_strip_all_tags( $content );

			if ( mb_strlen( $content ) <= $limit ) {
				return $content;
			}

			$replacement = wp_html_excerpt( $content, $limit );

			// Check if the description has space and trim the auto-generated string to a word boundary.
			if ( strrpos( $replacement, ' ' ) ) {
				$replacement = substr( $replacement, 0, strrpos( $replacement, ' ' ) );
			}
		}
	}

	return $replacement;
}