唯一可以改变的是gettext
:
add_action( \'loop_start\', \'wpse_77028_switch_filter\' );
add_action( \'loop_end\', \'wpse_77028_switch_filter\' );
/**
* Turn comment text filter on or off depending on global $post object.
*
* @wp-hook loop_start
* @wp-hook loop_end
* @return void
*/
function wpse_77028_switch_filter()
{
$func = \'loop_start\' === current_filter() ? \'add_filter\' : \'remove_filter\';
$func( \'gettext\', \'wpse_77028_comment_num_text\', 10, 3 );
}
/**
* Change default text for comments_popup_link()
*
* @wp-hook gettext
* @param string $translated
* @param string $original
* @param string $domain
* @return string
*/
function wpse_77028_comment_num_text( $translated, $original, $domain )
{
if ( \'Enter your password to view comments.\' === $original
and \'default\' === $domain
)
return \' \';
return $translated;
}
不幸的是,这相当昂贵:
gettext
多次调用,每次都会运行筛选器。您无法在第一次匹配后停用它,因为每页可能需要多次。我添加了一个包装器函数,以确保它仅在存在全局
$post
对象