class-admin-bar.php
2 days ago
class-aioseo-sitemaps.php
2 days ago
class-css-load-optimizer.php
2 days ago
class-foogallery-template-loader.php
2 days ago
class-public.php
2 days ago
class-rank-math-seo-sitemaps.php
2 days ago
class-shortcodes.php
2 days ago
class-yoast-seo-sitemaps.php
2 days ago
index.php
2 days ago
class-aioseo-sitemaps.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Adds support for All In One SEO Sitemaps |
| 9 | * |
| 10 | * Date: 02/08/2020 |
| 11 | */ |
| 12 | if ( ! class_exists( 'FooGallery_All_In_One_Seo_Sitemap_Support' ) ) { |
| 13 | |
| 14 | class FooGallery_All_In_One_Seo_Sitemap_Support { |
| 15 | |
| 16 | function __construct() { |
| 17 | //version 4+ |
| 18 | add_filter( 'aioseo_sitemap_posts', array( $this, 'add_images_to_sitemap' ), 10, 2 ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Add sitemap entries for AIOSEO v4+ |
| 23 | * |
| 24 | * @param $entries |
| 25 | * @param $post_type |
| 26 | * |
| 27 | * @return mixed |
| 28 | */ |
| 29 | function add_images_to_sitemap( $entries, $post_type ) { |
| 30 | if ( is_array( $entries ) ) { |
| 31 | foreach ( $entries as &$entry ) { |
| 32 | $post_permalink = $entry['loc']; |
| 33 | $post_id = url_to_postid( $post_permalink ); |
| 34 | $images = isset( $entry['images'] ) ? $entry['images'] : array(); |
| 35 | if ( $post_id > 0 ) { |
| 36 | $galleries = get_post_meta( $post_id, FOOGALLERY_META_POST_USAGE ); |
| 37 | if ( is_array( $galleries ) ) { |
| 38 | foreach ( $galleries as $gallery_id ) { |
| 39 | |
| 40 | //load each gallery |
| 41 | $gallery = FooGallery::get_by_id( $gallery_id ); |
| 42 | |
| 43 | if ( false === $gallery ) { |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | //add each image to the sitemap image array |
| 48 | foreach ( $gallery->attachments() as $attachment ) { |
| 49 | $images[] = (object) array( |
| 50 | 'image:loc' => $attachment->url, |
| 51 | 'image:caption' => $attachment->alt, |
| 52 | 'image:title' => $attachment->caption, |
| 53 | ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | $entry['images'] = $images; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return $entries; |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 |