_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: 這是一個私有函式,用於在管理區預覽一個文章時過濾該文章的特色圖片。它用於確保在預覽文章時顯示正確的圖片,即使在上次儲存文章後特色圖片已經改變。

過濾文章縮圖的查詢,以設定文章的縮圖。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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;
}
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; }
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
檢視更多 >