function add_images_to_sitemap($images, $post_id) { //check the content for $post_id contains a foogallery shortcode $post = get_post($post_id); //get all the foogallery shortcodes in the post $gallery_shortcodes = foogallery_extract_gallery_shortcodes($post->post_content); foreach ($gallery_shortcodes as $gallery_id => $shortcode) { //load each gallery $gallery = FooGallery::get_by_id($gallery_id); //add each image to the sitemap image array foreach ($gallery->attachments() as $attachment) { $image = array('src' => $attachment->url, 'title' => $attachment->caption, 'alt' => $attachment->alt); $images[] = $image; } } return $images; }
public function attach_gallery_to_post($post_id, $post) { // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } //only do this check for a page or post if ('post' == $post->post_type || 'page' == $post->post_type) { //first, clear any foogallery usages that the post might have delete_post_meta($post_id, FOOGALLERY_META_POST_USAGE); //if the content contains the foogallery shortcode then add a custom field $gallery_shortcodes = foogallery_extract_gallery_shortcodes($post->post_content); foreach ($gallery_shortcodes as $id => $shortcode) { add_post_meta($post_id, FOOGALLERY_META_POST_USAGE, $id, false); } } }
public function attach_gallery_to_post($post_id, $post) { // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } //only do this check for a page or post if ('post' == $post->post_type || 'page' == $post->post_type) { do_action('foogallery_start_attach_gallery_to_post', $post_id); //Clear any foogallery usages that the post might have delete_post_meta($post_id, FOOGALLERY_META_POST_USAGE); //get all foogallery shortcodes that are on the page/post $gallery_shortcodes = foogallery_extract_gallery_shortcodes($post->post_content); if (is_array($gallery_shortcodes) && count($gallery_shortcodes) > 0) { foreach ($gallery_shortcodes as $id => $shortcode) { //if the content contains the foogallery shortcode then add a custom field add_post_meta($post_id, FOOGALLERY_META_POST_USAGE, $id, false); do_action('foogallery_attach_gallery_to_post', $post_id, $id); } } } }