_wp_preview_post_thumbnail_filter

函数
_wp_preview_post_thumbnail_filter ( $value, $post_id, $meta_key )
Access
Private
参数
  • (null|array|string) $value The value to return - a single metadata value, or an array of values.
    Required:
  • (int) $post_id Post ID.
    Required:
  • (string) $meta_key Meta key.
    Required:
返回值
  • (null|array) The default return value or the post thumbnail meta array.
定义位置
相关方法
_wp_preview_terms_filter_wp_post_thumbnail_htmlset_post_thumbnail_sizepreview_theme_ob_filterget_post_thumbnail_id
引入
4.6.0
弃用
-

_wp_preview_post_thumbnail_filter: 这是一个私有函数,用于在管理区预览一个文章时过滤该文章的特色图片。它用于确保在预览文章时显示正确的图片,即使在上次保存文章后特色图片已经改变。

过滤文章缩略图的查找,以设置文章的缩略图。

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;
}

常见问题

FAQs
查看更多 >