Plugin Directory

Changeset 3208011


Ignore:
Timestamp:
12/14/2024 05:00:25 PM (16 months ago)
Author:
bdeleasa
Message:

Removing the filter_get_post_metadata function which was only needed to add in the post_thumbnail_id filter. That filter is now in Wordpress Core so my custom one is no longer needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-random-post-thumbnails/trunk/classes/class-wprpt.php

    r1866667 r3208011  
    2424        if ( ! is_admin() || wp_doing_ajax() ) {
    2525            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);
    2726            add_filter( 'wprpt_all_images', array($this, 'add_global_images') );
    2827            add_filter( 'wprpt_all_images', array($this, 'add_images_based_on_post_type') );
     
    9695
    9796        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 the
    104      * post thumbnail ID. So, now there's a new filter 'post_thumbnail_id'.
    105      *
    106      * @see https://gist.github.com/westonruter/5808015
    107      *
    108      * @since 1.0.0
    109      *
    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 string
    115      */
    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 recursion
    119         static $is_recursing = false;
    120 
    121         // Only filter if we're not recursing and if it is a post thumbnail ID
    122         if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) {
    123             $is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called
    124             $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;
    13397
    13498    }
Note: See TracChangeset for help on using the changeset viewer.