WordPress.org

Making WordPress.org

Changeset 3320


Ignore:
Timestamp:
06/08/2016 06:51:52 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Attempt to attach our custom post_meta fields to the result of get_post_meta( $post_id, false) to aid with ElastcSearch indexing and other plugin interactions.

WordPress lacks a post-get_post_meta() filter so the way to attach custom meta is ajuggling act of $post_meta.

See #1584

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3319 r3320  
    555555                return array( $ratings );
    556556                break;
     557            case false:
     558                // In the event $meta_key is false, the caller wants all meta fields, so we'll append our custom ones here too.
     559                remove_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ) );
     560
     561                // Fetch the existing ones from the database
     562                $value = get_metadata( 'post', $object_id, $meta_key );
     563
     564                // Re-attach ourselves for next time!
     565                add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );
     566
     567                $custom_meta_fields = array( 'downloads', 'rating', 'ratings' );
     568                $custom_meta_fields = apply_filters( 'wporg_plugins_custom_meta_fields', $custom_meta_fields, $object_id );
     569
     570                foreach ( $custom_meta_fields as $key ) {
     571                    // When WordPress calls `get_post_meta( $post_id, false )` it expects an array of maybe_serialize()'d data
     572                    $shimed_data = $this->filter_shim_postmeta( false, $object_id, $key );
     573                    if ( $shimed_data ) {
     574                        $value[ $key ][0] = (string) maybe_serialize( $shimed_data[0] );
     575                    }
     576                }
     577
     578                break;
    557579        }
    558580        return $value;
Note: See TracChangeset for help on using the changeset viewer.