WP_Metadata_Lazyloader::queue_objects() WordPress Method

The WP_Metadata_Lazyloader::queue_objects() method is responsible for loading the required metadata for a given set of objects. This is done by first querying the database for the relevant metadata, then loading it into the object cache.

WP_Metadata_Lazyloader::queue_objects( string $object_type, array $object_ids ) #

Adds objects to the metadata lazy-load queue.


Parameters

$object_type

(string)(Required)Type of object whose meta is to be lazy-loaded. Accepts 'term' or 'comment'.

$object_ids

(array)(Required)Array of object IDs.


Top ↑

Return

(void|WP_Error) WP_Error on failure.


Top ↑

Source

File: wp-includes/class-wp-metadata-lazyloader.php

	public function queue_objects( $object_type, $object_ids ) {
		if ( ! isset( $this->settings[ $object_type ] ) ) {
			return new WP_Error( 'invalid_object_type', __( 'Invalid object type.' ) );
		}

		$type_settings = $this->settings[ $object_type ];

		if ( ! isset( $this->pending_objects[ $object_type ] ) ) {
			$this->pending_objects[ $object_type ] = array();
		}

		foreach ( $object_ids as $object_id ) {
			// Keyed by ID for faster lookup.
			if ( ! isset( $this->pending_objects[ $object_type ][ $object_id ] ) ) {
				$this->pending_objects[ $object_type ][ $object_id ] = 1;
			}
		}

		add_filter( $type_settings['filter'], $type_settings['callback'] );

		/**
		 * Fires after objects are added to the metadata lazy-load queue.
		 *
		 * @since 4.5.0
		 *
		 * @param array                  $object_ids  Array of object IDs.
		 * @param string                 $object_type Type of object being queued.
		 * @param WP_Metadata_Lazyloader $lazyloader  The lazy-loader object.
		 */
		do_action( 'metadata_lazyloader_queued_objects', $object_ids, $object_type, $this );
	}


Top ↑

Changelog

Changelog
VersionDescription
4.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.