WPSEO_Sitemap_Image_Parser::parse_galleries()protectedYoast 1.0

Parse gallery shortcodes in a given content.

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

Хуков нет.

Возвращает

Массив. Set of attachment objects.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->parse_galleries( $content, $post_id );
$content(строка) (обязательный)
Content string.
$post_id(int)
ID of post being parsed.

Код WPSEO_Sitemap_Image_Parser::parse_galleries() Yoast 22.4

protected function parse_galleries( $content, $post_id = 0 ) {

	$attachments = [];
	$galleries   = $this->get_content_galleries( $content );

	foreach ( $galleries as $gallery ) {

		$id = $post_id;

		if ( ! empty( $gallery['id'] ) ) {
			$id = intval( $gallery['id'] );
		}

		// Forked from core gallery_shortcode() to have exact same logic. R.
		if ( ! empty( $gallery['ids'] ) ) {
			$gallery['include'] = $gallery['ids'];
		}

		$gallery_attachments = $this->get_gallery_attachments( $id, $gallery );

		$attachments = array_merge( $attachments, $gallery_attachments );
	}

	return array_unique( $attachments, SORT_REGULAR );
}