WPSEO_Sitemaps_Cache::get_sitemap_data()publicYoast 1.0

Get the sitemap that is cached.

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

Хуков нет.

Возвращает

WPSEO_Sitemap_Cache_Data|null. Null on no cache found otherwise object containing sitemap and meta data.

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

$WPSEO_Sitemaps_Cache = new WPSEO_Sitemaps_Cache();
$WPSEO_Sitemaps_Cache->get_sitemap_data( $type, $page );
$type(строка) (обязательный)
Sitemap type.
$page(int) (обязательный)
Page number to retrieve.

Код WPSEO_Sitemaps_Cache::get_sitemap_data() Yoast 19.7.1

public function get_sitemap_data( $type, $page ) {

	$sitemap = $this->get_sitemap( $type, $page );

	if ( empty( $sitemap ) ) {
		return null;
	}

	/*
	 * Unserialize Cache Data object as is_serialized() doesn't recognize classes in C format.
	 * This work-around should no longer be needed once the minimum PHP version has gone up to PHP 7.4,
	 * as the `WPSEO_Sitemap_Cache_Data` class uses O format serialization in PHP 7.4 and higher.
	 *
	 * @link https://wiki.php.net/rfc/custom_object_serialization
	 */
	if ( is_string( $sitemap ) && strpos( $sitemap, 'C:24:"WPSEO_Sitemap_Cache_Data"' ) === 0 ) {
		// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Can't be avoided due to how WP stores options.
		$sitemap = unserialize( $sitemap );
	}

	// What we expect it to be if it is set.
	if ( $sitemap instanceof WPSEO_Sitemap_Cache_Data_Interface ) {
		return $sitemap;
	}

	return null;
}