52 */ |
53 */ |
53 public function __construct() { |
54 public function __construct() { |
54 $this->settings = array( |
55 $this->settings = array( |
55 'term' => array( |
56 'term' => array( |
56 'filter' => 'get_term_metadata', |
57 'filter' => 'get_term_metadata', |
57 'callback' => array( $this, 'lazyload_term_meta' ), |
58 'callback' => array( $this, 'lazyload_meta_callback' ), |
58 ), |
59 ), |
59 'comment' => array( |
60 'comment' => array( |
60 'filter' => 'get_comment_metadata', |
61 'filter' => 'get_comment_metadata', |
61 'callback' => array( $this, 'lazyload_comment_meta' ), |
62 'callback' => array( $this, 'lazyload_meta_callback' ), |
|
63 ), |
|
64 'blog' => array( |
|
65 'filter' => 'get_blog_metadata', |
|
66 'callback' => array( $this, 'lazyload_meta_callback' ), |
62 ), |
67 ), |
63 ); |
68 ); |
64 } |
69 } |
65 |
70 |
66 /** |
71 /** |
128 * |
133 * |
129 * This method is public so that it can be used as a filter callback. As a rule, there |
134 * This method is public so that it can be used as a filter callback. As a rule, there |
130 * is no need to invoke it directly. |
135 * is no need to invoke it directly. |
131 * |
136 * |
132 * @since 4.5.0 |
137 * @since 4.5.0 |
|
138 * @deprecated 6.3.0 Use WP_Metadata_Lazyloader::lazyload_meta_callback() instead. |
133 * |
139 * |
134 * @param mixed $check The `$check` param passed from the 'get_term_metadata' hook. |
140 * @param mixed $check The `$check` param passed from the 'get_term_metadata' hook. |
135 * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be |
141 * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be |
136 * another value if filtered by a plugin. |
142 * another value if filtered by a plugin. |
137 */ |
143 */ |
138 public function lazyload_term_meta( $check ) { |
144 public function lazyload_term_meta( $check ) { |
139 if ( ! empty( $this->pending_objects['term'] ) ) { |
145 _deprecated_function( __METHOD__, '6.3.0', 'WP_Metadata_Lazyloader::lazyload_meta_callback' ); |
140 update_termmeta_cache( array_keys( $this->pending_objects['term'] ) ); |
146 return $this->lazyload_meta_callback( $check, 0, '', false, 'term' ); |
141 |
|
142 // No need to run again for this set of terms. |
|
143 $this->reset_queue( 'term' ); |
|
144 } |
|
145 |
|
146 return $check; |
|
147 } |
147 } |
148 |
148 |
149 /** |
149 /** |
150 * Lazy-loads comment meta for queued comments. |
150 * Lazy-loads comment meta for queued comments. |
151 * |
151 * |
152 * This method is public so that it can be used as a filter callback. As a rule, there is no need to invoke it |
152 * This method is public so that it can be used as a filter callback. As a rule, there is no need to invoke it |
153 * directly, from either inside or outside the `WP_Query` object. |
153 * directly, from either inside or outside the `WP_Query` object. |
154 * |
154 * |
155 * @since 4.5.0 |
155 * @since 4.5.0 |
|
156 * @deprecated 6.3.0 Use WP_Metadata_Lazyloader::lazyload_meta_callback() instead. |
156 * |
157 * |
157 * @param mixed $check The `$check` param passed from the {@see 'get_comment_metadata'} hook. |
158 * @param mixed $check The `$check` param passed from the {@see 'get_comment_metadata'} hook. |
158 * @return mixed The original value of `$check`, so as not to short-circuit `get_comment_metadata()`. |
159 * @return mixed The original value of `$check`, so as not to short-circuit `get_comment_metadata()`. |
159 */ |
160 */ |
160 public function lazyload_comment_meta( $check ) { |
161 public function lazyload_comment_meta( $check ) { |
161 if ( ! empty( $this->pending_objects['comment'] ) ) { |
162 _deprecated_function( __METHOD__, '6.3.0', 'WP_Metadata_Lazyloader::lazyload_meta_callback' ); |
162 update_meta_cache( 'comment', array_keys( $this->pending_objects['comment'] ) ); |
163 return $this->lazyload_meta_callback( $check, 0, '', false, 'comment' ); |
163 |
164 } |
164 // No need to run again for this set of comments. |
165 |
165 $this->reset_queue( 'comment' ); |
166 /** |
166 } |
167 * Lazy-loads meta for queued objects. |
|
168 * |
|
169 * This method is public so that it can be used as a filter callback. As a rule, there |
|
170 * is no need to invoke it directly. |
|
171 * |
|
172 * @since 6.3.0 |
|
173 * |
|
174 * @param mixed $check The `$check` param passed from the 'get_*_metadata' hook. |
|
175 * @param int $object_id ID of the object metadata is for. |
|
176 * @param string $meta_key Unused. |
|
177 * @param bool $single Unused. |
|
178 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', |
|
179 * or any other object type with an associated meta table. |
|
180 * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be |
|
181 * another value if filtered by a plugin. |
|
182 */ |
|
183 public function lazyload_meta_callback( $check, $object_id, $meta_key, $single, $meta_type ) { |
|
184 if ( empty( $this->pending_objects[ $meta_type ] ) ) { |
|
185 return $check; |
|
186 } |
|
187 |
|
188 $object_ids = array_keys( $this->pending_objects[ $meta_type ] ); |
|
189 if ( $object_id && ! in_array( $object_id, $object_ids, true ) ) { |
|
190 $object_ids[] = $object_id; |
|
191 } |
|
192 |
|
193 update_meta_cache( $meta_type, $object_ids ); |
|
194 |
|
195 // No need to run again for this set of objects. |
|
196 $this->reset_queue( $meta_type ); |
167 |
197 |
168 return $check; |
198 return $check; |
169 } |
199 } |
170 } |
200 } |