private function parse_galleries($content, $post_id = 0)
{
$attachments = array();
$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 = array();
if (!empty($gallery['include'])) {
$_attachments = get_posts(array('include' => $gallery['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image'));
foreach ($_attachments as $key => $val) {
$gallery_attachments[$val->ID] = $_attachments[$key];
}
} elseif (!empty($gallery['exclude']) && !empty($id)) {
$gallery_attachments = get_children(array('post_parent' => $id, 'exclude' => $gallery['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image'));
} elseif (!empty($id)) {
$gallery_attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image'));
}
$attachments = array_merge($attachments, $gallery_attachments);
}
return array_unique($attachments, SORT_REGULAR);
}