-
-
Save wpsmithtwc/a77b6f2c18d0296bdf77dde713519d75 to your computer and use it in GitHub Desktop.
Revisions
-
westonruter revised this gist
Jun 18, 2013 . 3 changed files with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ <?php // Copied from core for reference /** * Retrieve metadata for the specified object. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ <?php // Copied from core for reference /** * Retrieve Post Thumbnail ID. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ <?php // Copied from core for reference /** * Retrieve post meta field for a post. -
westonruter revised this gist
Jun 18, 2013 . 1 changed file with 13 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,19 +4,18 @@ */ add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) { // We want to pass the actual _thumbnail_id into the filter, so requires recursion static $is_recursing = false; // Only filter if we're not recursing and if it is a post thumbnail ID if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) { $is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called $value = get_post_thumbnail_id( $post_id ); $is_recursing = false; $value = apply_filters( 'post_thumbnail_id', $value, $post_id ); // yay! if ( ! $single ) { $value = array( $value ); } } return $value; }, 10, 4); -
westonruter revised this gist
Jun 18, 2013 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,6 @@ * @return int */ function get_post_thumbnail_id( $post_id = null ) { $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; return get_post_meta( $post_id, '_thumbnail_id', true ); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,5 +14,5 @@ * is true. */ function get_post_meta($post_id, $key = '', $single = false) { return get_metadata('post', $post_id, $key, $single); } -
westonruter revised this gist
Jun 18, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ * How to filter the value that would be returned by get_post_thumbnail_id() */ add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) { // We want to pass the actual _thumbnail_id into the filter, so requires recursion static $is_recursing = false; -
westonruter revised this gist
Jun 18, 2013 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,15 +4,18 @@ */ add_filter( 'get_post_metadata', function ($value, $post_id, $meta_key, $single) { // We want to pass the actual _thumbnail_id into the filter, so requires recursion static $is_recursing = false; // Only filter if we're not recursing and if it is a post thumbnail ID if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) { $is_recursing = true; // prevent this conditional when get_post_thumbnail_id() is called $value = get_post_thumbnail_id( $post_id ); $is_recursing = false; $value = apply_filters( 'post_thumbnail_id', $value, $post_id ); // yay! if ( ! $single ) { $value = array( $value ); } } return $value; }, 10, 4); -
westonruter revised this gist
Jun 18, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) { $is_recursing = true; $value = get_post_thumbnail_id( $post_id ); $value = apply_filters( 'post_thumbnail_id', $value, $post_id ); if ( ! $single ) { $value = array( $value ); } -
westonruter revised this gist
Jun 18, 2013 . 4 changed files with 19 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ <?php /** * How to filter the value that would be returned by get_post_thumbnail_id() */ add_filter( 'get_post_metadata', function ($value, $post_id, $meta_key, $single) { static $is_recursing = false; if ( ! $is_recursing && $meta_key === '_thumbnail_id' ) { $is_recursing = true; $value = get_post_thumbnail_id( $post_id ); $value = apply_filters( 'the_post_thumbnail_id', $value, $post_id ); if ( ! $single ) { $value = array( $value ); } $is_recursing = false; } return $value; }, 10, 4); File renamed without changes.File renamed without changes.File renamed without changes. -
westonruter created this gist
Jun 18, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ <?php /** * Retrieve metadata for the specified object. * * @since 2.9.0 * * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) * @param int $object_id ID of the object metadata is for * @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for * the specified object. * @param bool $single Optional, default is false. If true, return only the first value of the * specified meta_key. This parameter has no effect if meta_key is not specified. * @return string|array Single metadata value, or array of values */ function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) { if ( !$meta_type ) return false; if ( !$object_id = absint($object_id) ) return false; $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, $single ); if ( null !== $check ) { if ( $single && is_array( $check ) ) return $check[0]; else return $check; } $meta_cache = wp_cache_get($object_id, $meta_type . '_meta'); if ( !$meta_cache ) { $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); $meta_cache = $meta_cache[$object_id]; } if ( !$meta_key ) return $meta_cache; if ( isset($meta_cache[$meta_key]) ) { if ( $single ) return maybe_unserialize( $meta_cache[$meta_key][0] ); else return array_map('maybe_unserialize', $meta_cache[$meta_key]); } if ($single) return ''; else return array(); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ <?php /** * Retrieve Post Thumbnail ID. * * @since 2.9.0 * * @param int $post_id Optional. Post ID. * @return int */ function get_post_thumbnail_id( $post_id = null ) { $post_id = ( null === $post_id ) ? get_the_ID() : $post_id; return get_post_meta( $post_id, '_thumbnail_id', true ); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <?php /** * Retrieve post meta field for a post. * * @since 1.5.0 * @uses $wpdb * @link http://codex.wordpress.org/Function_Reference/get_post_meta * * @param int $post_id Post ID. * @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. * @param bool $single Whether to return a single value. * @return mixed Will be an array if $single is false. Will be value of meta data field if $single * is true. */ function get_post_meta($post_id, $key = '', $single = false) { return get_metadata('post', $post_id, $key, $single); }