PHP 8.2.29
Preview: class-wp-metadata-lazyloader.php Size: 6.67 KB
/home/medyaist/ulviyegida.com.tr/wp-includes/class-wp-metadata-lazyloader.php
<?php
/**
 * Meta API: WP_Metadata_Lazyloader class
 *
 * @package WordPress
 * @subpackage Meta
 * @since 4.5.0
 */

/**
 * Core class used for lazy-loading object metadata.
 *
 * When loading many objects of a given type, such as posts in a WP_Query loop, it often makes
 * sense to prime various metadata caches at the beginning of the loop. This means fetching all
 * relevant metadata with a single database query, a technique that has the potential to improve
 * performance dramatically in some cases.
 *
 * In cases where the given metadata may not even be used in the loop, we can improve performance
 * even more by only priming the metadata cache for affected items the first time a piece of metadata
 * is requested - ie, by lazy-loading it. So, for example, comment meta may not be loaded into the
 * cache in the comments section of a post until the first time get_comment_meta() is called in the
 * context of the comment loop.
 *
 * WP uses the WP_Metadata_Lazyloader class to queue objects for metadata cache priming. The class
 * then detects the relevant get_*_meta() function call, and queries the metadata of all queued objects.
 *
 * Do not access this class directly. Use the wp_metadata_lazyloader() function.
 *
 * @since 4.5.0
 */
#[AllowDynamicProperties]
class WP_Metadata_Lazyloader {
	/**
	 * Pending objects queue.
	 *
	 * @since 4.5.0
	 * @var array
	 */
	protected $pending_objects;

	/**
	 * Settings for supported object types.
	 *
	 * @since 4.5.0
	 * @var array
	 */
	protected $settings = array();

	/**
	 * Constructor.
	 *
	 * @since 4.5.0
	 */
	public function __construct() {
		$this->settings = array(
			'term'    => array(
				'filter'   => 'get_term_metadata',
				'callback' => array( $this, 'lazyload_meta_callback' ),
			),
			'comment' => array(
				'filter'   => 'get_comment_metadata',
				'callback' => array( $this, 'lazyload_meta_callback' ),
			),
			'blog'    => array(
				'filter'   => 'get_blog_metadata',
				'callback' => array( $this, 'lazyload_meta_callback' ),
			),
		);
	}

	/**
	 * Adds objects to the metadata lazy-load queue.
	 *
	 * @since 4.5.0
	 *
	 * @param string $object_type Type of object whose meta is to be lazy-loaded. Accepts 'term' or 'comment'.
	 * @param array  $object_ids  Array of object IDs.
	 * @return void|WP_Error WP_Error on failure.
	 */
	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'], 10, 5 );

		/**
		 * 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 );
	}

	/**
	 * Resets lazy-load queue for a given object type.
	 *
	 * @since 4.5.0
	 *
	 * @param string $object_type Object type. Accepts 'comment' or 'term'.
	 * @return void|WP_Error WP_Error on failure.
	 */
	public function reset_queue( $object_type ) {
		if ( ! isset( $this->settings[ $object_type ] ) ) {
			return new WP_Error( 'invalid_object_type', __( 'Invalid object type.' ) );
		}

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

		$this->pending_objects[ $object_type ] = array();
		remove_filter( $type_settings['filter'], $type_settings['callback'] );
	}

	/**
	 * Lazy-loads term meta for queued terms.
	 *
	 * This method is public so that it can be used as a filter callback. As a rule, there
	 * is no need to invoke it directly.
	 *
	 * @since 4.5.0
	 * @deprecated 6.3.0 Use WP_Metadata_Lazyloader::lazyload_meta_callback() instead.
	 *
	 * @param mixed $check The `$check` param passed from the 'get_term_metadata' hook.
	 * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be
	 *               another value if filtered by a plugin.
	 */
	public function lazyload_term_meta( $check ) {
		_deprecated_function( __METHOD__, '6.3.0', 'WP_Metadata_Lazyloader::lazyload_meta_callback' );
		return $this->lazyload_meta_callback( $check, 0, '', false, 'term' );
	}

	/**
	 * Lazy-loads comment meta for queued comments.
	 *
	 * This method is public so that it can be used as a filter callback. As a rule, there is no need to invoke it
	 * directly, from either inside or outside the `WP_Query` object.
	 *
	 * @since 4.5.0
	 * @deprecated 6.3.0 Use WP_Metadata_Lazyloader::lazyload_meta_callback() instead.
	 *
	 * @param mixed $check The `$check` param passed from the {@see 'get_comment_metadata'} hook.
	 * @return mixed The original value of `$check`, so as not to short-circuit `get_comment_metadata()`.
	 */
	public function lazyload_comment_meta( $check ) {
		_deprecated_function( __METHOD__, '6.3.0', 'WP_Metadata_Lazyloader::lazyload_meta_callback' );
		return $this->lazyload_meta_callback( $check, 0, '', false, 'comment' );
	}

	/**
	 * Lazy-loads meta for queued objects.
	 *
	 * This method is public so that it can be used as a filter callback. As a rule, there
	 * is no need to invoke it directly.
	 *
	 * @since 6.3.0
	 *
	 * @param mixed  $check     The `$check` param passed from the 'get_*_metadata' hook.
	 * @param int    $object_id ID of the object metadata is for.
	 * @param string $meta_key  Unused.
	 * @param bool   $single    Unused.
	 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user',
	 *                          or any other object type with an associated meta table.
	 * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be
	 *               another value if filtered by a plugin.
	 */
	public function lazyload_meta_callback( $check, $object_id, $meta_key, $single, $meta_type ) {
		if ( empty( $this->pending_objects[ $meta_type ] ) ) {
			return $check;
		}

		$object_ids = array_keys( $this->pending_objects[ $meta_type ] );
		if ( $object_id && ! in_array( $object_id, $object_ids, true ) ) {
			$object_ids[] = $object_id;
		}

		update_meta_cache( $meta_type, $object_ids );

		// No need to run again for this set of objects.
		$this->reset_queue( $meta_type );

		return $check;
	}
}

Directory Contents

Dirs: 29 × Files: 77
Name Size Perms Modified Actions
- drwxr-xr-x 2026-01-08 03:40:22
Edit Download
assets DIR
- drwxr-xr-x 2026-01-08 03:47:47
Edit Download
- drwxr-xr-x 2026-01-06 04:41:31
Edit Download
- drwxr-xr-x 2026-01-13 06:06:16
Edit Download
- drwxr-xr-x 2026-01-13 06:06:57
Edit Download
blocks DIR
- drwxr-xr-x 2026-01-13 06:07:03
Edit Download
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
css DIR
- drwxr-xr-x 2026-01-08 03:47:19
Edit Download
customize DIR
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
fonts DIR
- drwxr-xr-x 2026-01-08 04:06:46
Edit Download
html-api DIR
- drwxr-xr-x 2026-01-06 04:42:28
Edit Download
ID3 DIR
- drwxr-xr-x 2026-01-13 10:11:27
Edit Download
images DIR
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
IXR DIR
- drwxr-xr-x 2026-01-06 04:42:26
Edit Download
js DIR
- drwxr-xr-x 2026-01-13 08:29:20
Edit Download
l10n DIR
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
PHPMailer DIR
- drwxr-xr-x 2026-01-13 06:07:31
Edit Download
pomo DIR
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
Requests DIR
- drwxr-xr-x 2025-10-22 09:56:02
Edit Download
rest-api DIR
- drwxr-xr-x 2025-10-22 09:56:03
Edit Download
SimplePie DIR
- drwxr-xr-x 2025-10-22 09:56:03
Edit Download
sitemaps DIR
- drwxr-xr-x 2025-10-22 09:56:03
Edit Download
- drwxr-xr-x 2026-01-08 04:07:35
Edit Download
- drwxr-xr-x 2026-01-08 03:41:06
Edit Download
Text DIR
- drwxr-xr-x 2025-10-22 09:56:03
Edit Download
- drwxr-xr-x 2026-01-08 03:41:05
Edit Download
widgets DIR
- drwxr-xr-x 2025-10-22 09:56:03
Edit Download
18.94 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
7.35 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
12.90 KB lrw-r--r-- 2024-11-29 19:46:22
Edit Download
61.02 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
42.63 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
6.61 KB lrw-r--r-- 2024-09-17 18:08:16
Edit Download
2.18 KB lrw-r--r-- 2023-04-05 10:12:26
Edit Download
16.70 KB lrw-r--r-- 2025-04-03 11:38:28
Edit Download
8.28 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
2.92 KB lrw-r--r-- 2024-09-03 13:33:16
Edit Download
1.32 KB lrw-r--r-- 2022-09-12 12:47:14
Edit Download
4.60 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
11.62 KB lrw-r--r-- 2025-03-05 19:17:24
Edit Download
5.32 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
10.60 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
67.84 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
6.34 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
1.99 KB lrw-r--r-- 2024-09-19 23:07:12
Edit Download
7.02 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
4.91 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
16.86 KB lrw-r--r-- 2024-05-01 21:01:10
Edit Download
3.97 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
47.66 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
9.22 KB lrw-r--r-- 2025-02-11 10:40:30
Edit Download
25.51 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
198.38 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
10.46 KB lrw-r--r-- 2025-01-22 16:48:26
Edit Download
29.26 KB lrw-r--r-- 2025-01-22 16:48:26
Edit Download
15.02 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
2.57 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
15.56 KB lrw-r--r-- 2025-04-14 11:31:24
Edit Download
7.33 KB lrw-r--r-- 2023-02-21 13:39:20
Edit Download
253 B lrw-r--r-- 2024-09-27 16:28:14
Edit Download
7.96 KB lrw-r--r-- 2024-10-22 07:16:16
Edit Download
3.23 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
969 B lrw-r--r-- 2024-09-30 19:50:20
Edit Download
4.30 KB lrw-r--r-- 2023-10-11 04:05:26
Edit Download
20.22 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
17.01 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
7.27 KB lrw-r--r-- 2024-02-27 19:38:16
Edit Download
6.62 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
1.79 KB lrw-r--r-- 2024-02-05 22:25:14
Edit Download
6.67 KB lrw-r--r-- 2023-05-11 08:15:24
Edit Download
8.98 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
6.74 KB lrw-r--r-- 2024-03-06 02:05:12
Edit Download
4.99 KB lrw-r--r-- 2024-09-03 15:19:14
Edit Download
4.25 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
24.72 KB lrw-r--r-- 2025-03-17 19:40:26
Edit Download
4.77 KB lrw-r--r-- 2025-02-17 08:24:22
Edit Download
18.12 KB lrw-r--r-- 2025-03-26 19:07:28
Edit Download
979 B lrw-r--r-- 2024-02-14 16:27:10
Edit Download
18.44 KB lrw-r--r-- 2025-01-22 16:48:26
Edit Download
10.24 KB lrw-r--r-- 2024-11-19 23:50:24
Edit Download
4.69 KB lrw-r--r-- 2025-02-18 19:32:22
Edit Download
2.94 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
3.27 KB lrw-r--r-- 2022-09-12 12:47:14
Edit Download
11.10 KB lrw-r--r-- 2024-09-30 20:58:16
Edit Download
37.02 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
2.24 KB lrw-r--r-- 2025-01-22 16:48:26
Edit Download
4.02 KB lrw-r--r-- 2023-05-02 12:45:22
Edit Download
5.38 KB lrw-r--r-- 2024-03-04 09:41:10
Edit Download
1.16 KB lrw-r--r-- 2020-01-28 21:45:18
Edit Download
4.04 KB lrw-r--r-- 2024-03-04 09:41:10
Edit Download
20.71 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
89.69 KB lrw-r--r-- 2025-12-03 18:14:00
Edit Download
4.11 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
200 B lrw-r--r-- 2020-11-12 08:17:08
Edit Download
255 B lrw-r--r-- 2020-11-16 19:52:06
Edit Download
22.66 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
9.68 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
23.49 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
544 B lrw-r--r-- 2023-09-30 21:22:28
Edit Download
6.09 KB lrw-r--r-- 2025-02-17 14:49:20
Edit Download
6.41 KB lrw-r--r-- 2025-01-22 16:48:26
Edit Download
69.46 KB lrw-r--r-- 2025-12-03 18:13:59
Edit Download
445 B lrw-r--r-- 2022-07-21 19:45:12
Edit Download
799 B lrw-r--r-- 2025-01-22 16:48:26
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).