Yoast\WP\SEO\Abilities\Infrastructure\Global_Setting_Targets

Post_Type_Archive_Target::ensure_available │ public │ Yoast 1.0

Ensures the content type has an archive with global settings.

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

Хуков нет.

Возвращает

void. Ничего (null).

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

$Post_Type_Archive_Target = new Post_Type_Archive_Target();
$Post_Type_Archive_Target->ensure_available(): void;

Код Post_Type_Archive_Target::ensure_available() Yoast 28.9

public function ensure_available(): void {
	if ( $this->post_type === '' ) {
		$message = \sprintf(
			/* translators: %s expands to the name of a parameter. */
			\__( 'Provide the %s of the content type whose archive to update.', 'wordpress-seo' ),
			'post_type',
		);

		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- This is an exception message, not output.
		throw new Unavailable_Global_Setting_Target_Exception( 'yoast_seo_missing_post_type', $message );
	}

	// Targets built from the list of archives skip the lookup, so listing them does not rebuild that list per archive.
	if ( ! $this->is_known_archive && ! \array_key_exists( $this->post_type, $this->post_type_helper->get_indexable_post_archives() ) ) {
		$message = \sprintf(
			/* translators: 1: the name of a parameter, 2: the name of an ability. */
			\__( 'No content type archive with SEO data exists for the given %1$s. The %2$s ability lists the ones that do.', 'wordpress-seo' ),
			'post_type',
			'yoast-seo/get-archive-and-special-page-seo-settings',
		);

		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- This is an exception message, not output.
		throw new Unavailable_Global_Setting_Target_Exception( 'yoast_seo_invalid_post_type', $message );
	}

	// Checked after the archive, so the Shop page is only pointed to when the product archive has SEO data.
	if ( $this->post_type === 'product' && $this->woocommerce_helper->is_active() ) {
		throw $this->get_woocommerce_shop_exception();
	}
}