Changeset 55608
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-metadata-lazyloader.php
r54133 r55608 56 56 'term' => array( 57 57 'filter' => 'get_term_metadata', 58 'callback' => array( $this, 'lazyload_ term_meta' ),58 'callback' => array( $this, 'lazyload_meta_callback' ), 59 59 ), 60 60 'comment' => array( 61 61 'filter' => 'get_comment_metadata', 62 'callback' => array( $this, 'lazyload_ comment_meta' ),62 'callback' => array( $this, 'lazyload_meta_callback' ), 63 63 ), 64 64 ); … … 92 92 } 93 93 94 add_filter( $type_settings['filter'], $type_settings['callback'] );94 add_filter( $type_settings['filter'], $type_settings['callback'], 10, 5 ); 95 95 96 96 /** … … 132 132 * 133 133 * @since 4.5.0 134 * @deprecated 6.3.0 Use WP_Metadata_Lazyloader::lazyload_meta_callback() instead. 134 135 * 135 136 * @param mixed $check The `$check` param passed from the 'get_term_metadata' hook. … … 138 139 */ 139 140 public function lazyload_term_meta( $check ) { 140 if ( ! empty( $this->pending_objects['term'] ) ) { 141 update_termmeta_cache( array_keys( $this->pending_objects['term'] ) ); 142 143 // No need to run again for this set of terms. 144 $this->reset_queue( 'term' ); 145 } 146 147 return $check; 141 _deprecated_function( __METHOD__, '6.3.0', 'WP_Metadata_Lazyloader::lazyload_meta_callback' ); 142 return $this->lazyload_meta_callback( $check, 0, '', false, 'term' ); 148 143 } 149 144 … … 155 150 * 156 151 * @since 4.5.0 152 * @deprecated 6.3.0 Use WP_Metadata_Lazyloader::lazyload_meta_callback() instead. 157 153 * 158 154 * @param mixed $check The `$check` param passed from the {@see 'get_comment_metadata'} hook. … … 160 156 */ 161 157 public function lazyload_comment_meta( $check ) { 162 if ( ! empty( $this->pending_objects['comment'] ) ) { 163 update_meta_cache( 'comment', array_keys( $this->pending_objects['comment'] ) ); 158 _deprecated_function( __METHOD__, '6.3.0', 'WP_Metadata_Lazyloader::lazyload_meta_callback' ); 159 return $this->lazyload_meta_callback( $check, 0, '', false, 'comment' ); 160 } 164 161 165 // No need to run again for this set of comments. 166 $this->reset_queue( 'comment' ); 162 /** 163 * Lazy-loads meta for queued objects. 164 * 165 * This method is public so that it can be used as a filter callback. As a rule, there 166 * is no need to invoke it directly. 167 * 168 * @since 6.3.0 169 * 170 * @param mixed $check The `$check` param passed from the 'get_*_metadata' hook. 171 * @param int $object_id ID of the object metadata is for. 172 * @param string $meta_key Unused. 173 * @param bool $single Unused. 174 * @param string $meta_type Type of object metadata is for. Accepts 'post', 'comment', 'term', 'user', 175 * or any other object type with an associated meta table. 176 * @return mixed In order not to short-circuit `get_metadata()`. Generally, this is `null`, but it could be 177 * another value if filtered by a plugin. 178 */ 179 public function lazyload_meta_callback( $check, $object_id, $meta_key, $single, $meta_type ) { 180 if ( empty( $this->pending_objects[ $meta_type ] ) ) { 181 return $check; 167 182 } 183 184 $object_ids = array_keys( $this->pending_objects[ $meta_type ] ); 185 if ( $object_id && ! in_array( $object_id, $object_ids, true ) ) { 186 $object_ids[] = $object_id; 187 } 188 189 update_meta_cache( $meta_type, $object_ids ); 190 191 // No need to run again for this set of objects. 192 $this->reset_queue( $meta_type ); 168 193 169 194 return $check; -
trunk/tests/phpunit/tests/query/lazyLoadTermMeta.php
r55252 r55608 109 109 } 110 110 111 112 /** 113 * @ticket 57901 114 * 115 * @covers ::wp_queue_posts_for_term_meta_lazyload 116 */ 117 public function test_wp_queue_posts_for_term_meta_lazyload_insert_term() { 118 $filter = new MockAction(); 119 add_filter( 'update_term_metadata_cache', array( $filter, 'filter' ), 10, 2 ); 120 121 register_taxonomy( 'wptests_tax', 'post' ); 122 123 $t1 = wp_insert_term( 'Foo', 'wptests_tax' ); 124 $term_id = $t1['term_id']; 125 126 new WP_Query( 127 array( 128 'post__in' => self::$post_ids, 129 'lazy_load_term_meta' => true, 130 ) 131 ); 132 133 get_term_meta( $term_id ); 134 135 $args = $filter->get_args(); 136 $first = reset( $args ); 137 $term_ids = end( $first ); 138 $this->assertContains( $term_id, $term_ids ); 139 } 140 111 141 /** 112 142 * @ticket 57150 … … 134 164 $first = reset( $args ); 135 165 $term_ids = end( $first ); 136 $this->assert NotContains( $remove_term_id, $term_ids );166 $this->assertContains( $remove_term_id, $term_ids ); 137 167 } 138 168 }
Note: See TracChangeset
for help on using the changeset viewer.