Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_wp_preview_post_thumbnail_filter() WordPress Function

The _wp_preview_post_thumbnail_filter() function allows you to override the default thumbnail image for a post when it is displayed in the "Preview" mode. This can be useful if you want to use a different image for the post when it is displayed in the "Preview" mode.

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

Filters post thumbnail lookup to set the post thumbnail.


Parameters

$value

(null|array|string)(Required)The value to return

  • a single metadata value, or an array of values.

$post_id

(int)(Required)Post ID.

$meta_key

(string)(Required)Meta key.


Top ↑

Return

(null|array) The default return value or the post thumbnail meta array.


Top ↑

Source

File: wp-includes/revision.php

function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) {
	$post = get_post();
	if ( ! $post ) {
		return $value;
	}

	if ( empty( $_REQUEST['_thumbnail_id'] ) ||
		empty( $_REQUEST['preview_id'] ) ||
		$post->ID != $post_id ||
		'_thumbnail_id' !== $meta_key ||
		'revision' === $post->post_type ||
		$post_id != $_REQUEST['preview_id'] ) {

		return $value;
	}

	$thumbnail_id = (int) $_REQUEST['_thumbnail_id'];
	if ( $thumbnail_id <= 0 ) {
		return '';
	}

	return (string) $thumbnail_id;
}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.