_wp_preview_post_thumbnail_filter

Filters post thumbnail lookup to set the post thumbnail.

Description

(null|array) _wp_preview_post_thumbnail_filter( (null|array|string) $value, (int) $post_id, (string) $meta_key ); 

Returns (null|array)

The default return value or the post thumbnail meta array.

Parameters (3)

0. $value (null|array|string)
The value to return - a single metadata value, or an array of values.
1. $post_id (int)
The post id.
2. $meta_key (string)
The meta key.

Usage

  1. if ( !function_exists( '_wp_preview_post_thumbnail_filter' ) ) { 
  2. require_once ABSPATH . WPINC . '/revision.php'; 
  3.  
  4. // The value to return - a single metadata value, or an array of values. 
  5. $value = null; 
  6.  
  7. // The post id. 
  8. $post_id = -1; 
  9.  
  10. // The meta key. 
  11. $meta_key = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _wp_preview_post_thumbnail_filter($value, $post_id, $meta_key); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/revision.php  
  1. function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) { 
  2. if ( ! $post = get_post() ) { 
  3. return $value; 
  4.  
  5. if ( empty( $_REQUEST['_thumbnail_id'] ) || 
  6. empty( $_REQUEST['preview_id'] ) || 
  7. $post->ID != $post_id || 
  8. '_thumbnail_id' != $meta_key || 
  9. 'revision' == $post->post_type || 
  10. $post_id != $_REQUEST['preview_id'] 
  11. ) { 
  12. return $value; 
  13.  
  14. $thumbnail_id = intval( $_REQUEST['_thumbnail_id'] ); 
  15. if ( $thumbnail_id <= 0 ) { 
  16. return ''; 
  17.  
  18. return strval( $thumbnail_id );