abilities
2 days ago
admin
2 days ago
compatibility
2 days ago
extensions
2 days ago
foopluginbase
2 days ago
public
2 days ago
thumbs
2 days ago
asset-manifest.php
2 days ago
class-attachment-filters.php
2 days ago
class-command-palette.php
2 days ago
class-foogallery-animated-gif-support.php
2 days ago
class-foogallery-attachment-custom-class.php
2 days ago
class-foogallery-attachment-filename.php
2 days ago
class-foogallery-attachment-type.php
2 days ago
class-foogallery-attachment.php
2 days ago
class-foogallery-cache.php
2 days ago
class-foogallery-common-fields.php
2 days ago
class-foogallery-crop-position.php
2 days ago
class-foogallery-datasource-media_library.php
2 days ago
class-foogallery-debug.php
2 days ago
class-foogallery-delayed-runtime-loader.php
2 days ago
class-foogallery-extensions-compatibility.php
2 days ago
class-foogallery-force-https.php
2 days ago
class-foogallery-lazyload.php
2 days ago
class-foogallery-license-constant-handler.php
2 days ago
class-foogallery-lightbox.php
2 days ago
class-foogallery-no-javascript-fallback.php
2 days ago
class-foogallery-paging.php
2 days ago
class-foogallery-password-protect.php
2 days ago
class-foogallery-sitemaps.php
2 days ago
class-foogallery-widget.php
2 days ago
class-foogallery.php
2 days ago
class-gallery-advanced-settings.php
2 days ago
class-il8n.php
2 days ago
class-override-thumbnail.php
2 days ago
class-posttypes.php
2 days ago
class-previews.php
2 days ago
class-retina.php
2 days ago
class-thumbnail-dimensions.php
2 days ago
class-thumbnails.php
2 days ago
class-version-check.php
2 days ago
constants.php
2 days ago
functions.php
2 days ago
gallery-management-functions.php
2 days ago
includes.php
2 days ago
index.php
2 days ago
render-functions.php
2 days ago
class-foogallery-sitemaps.php
107 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * Class for managing sitemaps within FooGallery |
| 9 | */ |
| 10 | |
| 11 | if ( ! class_exists( 'FooGallery_Sitemaps' ) ) { |
| 12 | class FooGallery_Sitemaps { |
| 13 | public function __construct() { |
| 14 | //add_action('init', array( $this, 'register_sitemaps' ) ); |
| 15 | //add_filter( 'wp_sitemaps_posts_entry', array( $this, 'add_images_to_sitemap_entry'), 10, 3 ); |
| 16 | } |
| 17 | |
| 18 | public function register_sitemaps() { |
| 19 | //check if WordPress sitemaps are supported |
| 20 | if ( function_exists( 'wp_register_sitemap_provider' ) && class_exists( 'WP_Sitemaps_Provider' ) ) { |
| 21 | $provider = new FooGallery_Sitemaps_Provider(); |
| 22 | // phpcs:ignore -- Compatibility is guarded by function_exists() and class_exists(). |
| 23 | wp_register_sitemap_provider( 'foogallery', $provider ); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public function add_images_to_sitemap_entry( $sitemap_entry, $post, $post_type ) { |
| 28 | $galleries = get_post_meta( $post->ID, FOOGALLERY_META_POST_USAGE ); |
| 29 | foreach ( $galleries as $gallery_id ) { |
| 30 | |
| 31 | //load each gallery |
| 32 | $gallery = FooGallery::get_by_id( $gallery_id ); |
| 33 | |
| 34 | if ( false === $gallery ) continue; |
| 35 | |
| 36 | //add each image to the sitemap image array |
| 37 | foreach ( $gallery->attachments() as $attachment ) { |
| 38 | $sitemap_entry['image:image'][] = array( |
| 39 | 'image:loc' => $attachment->url, |
| 40 | 'image:title' => $attachment->caption, |
| 41 | 'image:caption' => $attachment->alt |
| 42 | ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return $sitemap_entry; |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | if ( ! class_exists( 'FooGallery_Sitemaps_Provider' ) ) { |
| 52 | class FooGallery_Sitemaps_Provider extends WP_Sitemaps_Provider { |
| 53 | |
| 54 | /** |
| 55 | * WP_Sitemaps_My_Plugin constructor. |
| 56 | * |
| 57 | * @since 5.5.0 (use your plugin version) |
| 58 | */ |
| 59 | public function __construct() { |
| 60 | $this->name = 'foogallery'; |
| 61 | $this->object_type = 'image'; |
| 62 | } |
| 63 | |
| 64 | public function get_url_list( $page_num, $object_subtype = '' ) { |
| 65 | $url_list = array(); |
| 66 | |
| 67 | //get all galleries |
| 68 | $galleries = foogallery_get_all_galleries(); |
| 69 | |
| 70 | //find all pages or posts that have galleries |
| 71 | foreach ( $galleries as $gallery ) { |
| 72 | $gallery_usages = $gallery->find_usages(); |
| 73 | |
| 74 | foreach ( $gallery_usages as $post ) { |
| 75 | $sitemap_entry = array( |
| 76 | 'loc' => get_permalink( $post ), |
| 77 | ); |
| 78 | |
| 79 | $url_list[] = $sitemap_entry; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return $url_list; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Gets the max number of pages available for the object type. |
| 88 | * |
| 89 | * @since 5.5.0 (use your plugin version) |
| 90 | * |
| 91 | * @see WP_Sitemaps_Provider::max_num_pages |
| 92 | * |
| 93 | * @param string $object_subtype Optional. Default empty. |
| 94 | * |
| 95 | * @return int Total page count. |
| 96 | */ |
| 97 | public function get_max_num_pages( $object_subtype = '' ) { |
| 98 | // again, use a function from your own plugin to fetch this data. |
| 99 | //$pages = plugin_prefix_get_my_pagination(); |
| 100 | |
| 101 | //return count( $pages ); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 |