• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Jetpack_Sitemap_Builder::build_one_image_sitemap() – Build and store a single image sitemap. Returns false if no sitemap is built.

You appear to be a bot. Output may be restricted

Description

Build and store a single image sitemap. Returns false if no sitemap is built.

Side effect: Create/update an image sitemap row.

Usage

$bool|array = Jetpack_Sitemap_Builder::build_one_image_sitemap( $number, $from_id );

Parameters

$number
( int ) required – The number of the current sitemap.
$from_id
( int ) required – The greatest lower bound of the IDs of the posts to be included.
$last_id
( int ) required – The ID of the last item to be successfully added to the buffer.
$any_left
( bool ) required – 'true' if there are items which haven't been saved to a sitemap, 'false' otherwise.
$last_modified
( string ) required – The most recent timestamp to appear on the sitemap. }

Returns

bool|array @args {

Source

File name: jetpack/modules/sitemaps/sitemap-builder.php
Lines:

1 to 61 of 61
  public function build_one_image_sitemap( $number, $from_id ) {
    $last_post_id   = $from_id;
    $any_posts_left = true;

    if ( $this->logger ) {
      $debug_name = jp_sitemap_filename( JP_IMAGE_SITEMAP_TYPE, $number );
      $this->logger->report( "-- Building $debug_name" );
    }

    $buffer = new Jetpack_Sitemap_Buffer_Image(
      JP_SITEMAP_MAX_ITEMS,
      JP_SITEMAP_MAX_BYTES
    );

    // Add as many items to the buffer as possible.
    while ( false === $buffer->is_full() ) {
      $posts = $this->librarian->query_images_after_id(
        $last_post_id,
        JP_SITEMAP_BATCH_SIZE
      );

      if ( null == $posts ) { // WPCS: loose comparison ok.
        $any_posts_left = false;
        break;
      }

      foreach ( $posts as $post ) {
        $current_item = $this->image_post_to_sitemap_item( $post );

        if ( true === $buffer->append( $current_item['xml'] ) ) {
          $last_post_id = $post->ID;
          $buffer->view_time( $current_item['last_modified'] );
        } else {
          break;
        }
      }
    }

    // If no items were added, return false.
    if ( true === $buffer->is_empty() ) {
      return false;
    }

    // Store the buffer as the content of a jp_sitemap post.
    $this->librarian->store_sitemap_data(
      $number,
      JP_IMAGE_SITEMAP_TYPE,
      $buffer->contents(),
      $buffer->last_modified()
    );

    /*
		 * Now report back with the ID of the last post to be
		 * successfully added and whether there are any posts left.
		 */
    return array(
      'last_id'       => $last_post_id,
      'any_left'      => $any_posts_left,
      'last_modified' => $buffer->last_modified(),
    );
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 27 November 2019

Primary Sidebar

Information

Function name: Jetpack_Sitemap_Builder::build_one_image_sitemap
Class ref: Jetpack_Sitemap_Builder
Plugin ref: Jetpack
Version: 9.2
Sourcefile: modules/sitemaps/sitemap-builder.php
File ref: modules/sitemaps/sitemap-builder.php
Deprecated?: No
API Letters: B,J,O,S

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites