show_passwords_fields
实际上是一个过滤器!您可以使用匿名函数如上所述钩住它:
add_filter( \'show_password_fields\', function(){return true} );
您还可以编写函数,并将其用作回调:
function wpse_79994_show_password_fields() {
return true;
}
add_filter( \'show_password_fields\', \'wpse_79994_show_password_fields\' );
但是,由于只返回布尔值(true或false),您可以这样做:
add_filter( \'show_password_fields\', \'__return_true\' );
现在,我明白所有关于过滤器的讨论实际上并不能解决你的问题。上面使用的代码应该有效,除非返回
true
. 正如您从
apply_filters()
函数在问题的第一段代码中,
true
实际上是默认值:
you aren\'t actually changing anything!
如果你想知道apply_filters(\'show_password_fields\', true )
如果为false,可以使用以下代码:
add_filter( \'show_password_fields\', \'__return_false\' );
<小时>
Edit: 原因是,即使使用过滤器,
apply_filters(\'show_password_fields\', true )
是
still 返回false肯定是因为应用过滤器后,某个插件中的过滤器将其更改为false。您可以通过提高过滤器的优先级来覆盖此选项:
add_filter( \'show_password_fields\', \'__return_true\', 999 );