Changeset 3208011
- Timestamp:
- 12/14/2024 05:00:25 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-random-post-thumbnails/trunk/classes/class-wprpt.php
r1866667 r3208011 24 24 if ( ! is_admin() || wp_doing_ajax() ) { 25 25 add_filter( 'post_thumbnail_id', array($this, 'set_post_thumbnail_id') ); 26 add_filter( 'get_post_metadata', array($this, 'filter_get_post_metadata') , 10, 4);27 26 add_filter( 'wprpt_all_images', array($this, 'add_global_images') ); 28 27 add_filter( 'wprpt_all_images', array($this, 'add_images_based_on_post_type') ); … … 96 95 97 96 return !empty($image_id) ? $image_id : $thumbnail_id; 98 99 }100 101 102 /**103 * Add a filter to modify get_post_metadata() so we can add a filter on the104 * post thumbnail ID. So, now there's a new filter 'post_thumbnail_id'.105 *106 * @see https://gist.github.com/westonruter/5808015107 *108 * @since 1.0.0109 *110 * @param $value (null|array|string)111 * @param $object_id (int|array|string)112 * @param $meta_key (string|array|string)113 * @param $single (string|array|string)114 * @return string115 */116 function filter_get_post_metadata( $value, $post_id, $meta_key, $single ) {117 118 // We want to pass the actual _thumbnail_id into the filter, so requires recursion119 static $is_recursing = false;120 121 // Only filter if we're not recursing and if it is a post thumbnail ID122 if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) {123 $is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called124 $value = get_post_thumbnail_id( $post_id );125 $is_recursing = false;126 $value = apply_filters( 'post_thumbnail_id', $value, $post_id ); // yay!127 if ( ! $single ) {128 $value = array( $value );129 }130 }131 132 return $value;133 97 134 98 }
Note: See TracChangeset
for help on using the changeset viewer.