请注意,还有其他输入参数可用于admin_post_thumbnail_html
过滤器回调,即$post->ID
和$thumbnail_id
:
/**
* Filters the admin post thumbnail HTML markup to return.
*
* @since 2.9.0
* @since 3.5.0 Added the `$post_id` parameter.
* @since 4.6.0 Added the `$thumbnail_id` parameter.
*
* @param string $content Admin post thumbnail HTML markup.
* @param int $post_id Post ID.
* @param int $thumbnail_id Thumbnail ID.
*/
return apply_filters( \'admin_post_thumbnail_html\', $content, $post->ID, $thumbnail_id );
适用于
_wp_post_thumbnail_html()
作用
下面是一个示例,通过使用$post->ID
改为输入参数:
function wpse250432_add_featured_description( $content, $post_id, $thumbnail_id ) {
$small_description = get_post_meta( $post_id, \'thumbnail_description\', true );
// Target only the \'post\' post type
if ( \'post\' === get_post_type( $post_id ) )
$content .= \'<div id="thumb_desc_container">...</div>\'; // Edit
return $content;
}
add_filter( \'admin_post_thumbnail_html\', \'wpse250432_add_featured_description\', 10, 3 );
如果确实需要将此筛选限制为
post.php
和
post-new.php
屏幕和
get-post-thumbnail-html
ajax调用,然后可以添加如下检查:
if(
! did_action( \'load-post.php\' )
&& ! did_action( \'load-post-new.php\' )
&& ! did_action( \'wp_ajax_get-post-thumbnail-html\' )
)
return $content;
但我假设你打电话给“私人”
_wp_post_thumbnail_html()
其他核心功能?但这些(下划线)
private functions are not intended for use by plugin and theme developers, but only by other core functions.