The `sitetree_is_building_sitemap` Action Hook

sitetree_is_building_sitemap is an action triggered whenever the Google Sitemap is rebuilt, after all the posts, pages and custom posts elements are generated but before the taxonomy elements are created.

Adding <url> Elements to the Google Sitemap

The code below adds a <url> element with <image> child elements to the Google Sitemap.

function add_url_element_to_sitemap( $sitemapBuilder ) {
    // Array of SiteTreeImageElement objects.
    $images = array(
        SiteTreeImageElement::make( 'https://sitetreeplugin.com/image-1.jpg', 'Image Title', 'Image caption.' ),
        SiteTreeImageElement::make( 'https://sitetreeplugin.com/image-2.jpg', 'Image Title', 'Image caption.' ),
        SiteTreeImageElement::make( 'https://sitetreeplugin.com/image-3.jpg', 'Image Title', 'Image caption.' )
    );

    $sitemapBuilder->buildURLElement( 'https://sitetreeplugin.com/', 'daily', '0.8', '2019-11-11', $images );
}

add_action( 'sitetree_is_building_sitemap', 'add_url_element_to_sitemap' );

The $sitemapBuilder parameter is a reference to the object of class SiteTreeSitemapBuilder to which is assigned the task of building the Google Sitemap. Its class' interface, declared in core/builders-interfaces.php, is the following:

interface SiteTreeSitemapBuilderInterface {
    /**
     * Limit set according to the XML schema defined for 
     * the Image Sitemap extension.
     *
     * @since 2.0
     */
    const IMAGES_PER_URL_ELEMENT = 1000;

    /**
     * @since 2.0
     *
     * @param string $url        Absolute URL of a publicly accessible web page.
     * @param string $changefreq Optional. How frequently the page is updated.
     *                           Accepted values: hourly, daily, weekly, monthly, yearly, always, never.
     * @param string $priority   Optional. Crawling priority of the page.
     *                           Must be a decimal number with one decimal digit and
     *                           included in the range [0.0, 1.0].
     * @param string $lastmod    Optional. The date on which the page was last modified.
     *                           Valid date formats at {@link https://www.php.net/manual/en/datetime.formats.php}.
     * @param array  $images     Optional. Array of SiteTreeImageElement objects, {@see SiteTreeImageElementInterface}.
     *                           Its size must not exceed {@see self::IMAGES_PER_URL_ELEMENT}.       
     */
    public function buildURLElement( $url, $changefreq = '', $priority = '', $lastmod = '', &$images = array() );
}

The interface of the class SiteTreeImageElement is declared in core/image-element.class.php as follows:

interface SiteTreeImageElementInterface {
    /**
     * Returns a SiteTreeImageElement object.
     *
     * @since 2.0
     *
     * @param string $url     Absolute URL of the image file.
     * @param string $title   Optional.
     * @param string $caption Optional.
     * @return object
     */
    public static function make( $url, $title = '', $caption = '' );
}