当我们发布空匿名回复时,会出现以下错误:
负责处理此问题的部分是bbp_new_reply_handler()
函数,在文件中/bbpress/includes/replies/functions.php
. 其中包含我们感兴趣的几行内容:
// User is anonymous
if ( bbp_is_anonymous() ) {
// Filter anonymous data
$anonymous_data = bbp_filter_anonymous_post_data();
在哪里
bbp_filter_anonymous_post_data()
在文件中定义
/bbpress/includes/replies/functions.php
.
这里有一个演示插件
允许您发布带有空姓名和电子邮件的回复仍然保留每个IP号码的洪水检查不要写cookies,这样会预先填写姓名和电子邮件文本框给你匿名回复者的名字其中:
/**
* Plugin Name: Empty Anonymous Replies in BBPress
* Plugin URI: http://wordpress.stackexchange.com/a/133420/26350
*/
add_action( \'init\', array( \'WPSE_Empty_Anonymous_Replies\', \'init\' ) );
class WPSE_Empty_Anonymous_Replies
{
static protected $name = \'nobody\';
static protected $email = \'nobody@example.com\';
static public function init()
{
add_filter( \'bbp_filter_anonymous_post_data\',
array( __CLASS__, \'bbp_filter_anonymous_post_data\' ),
11, 2 );
add_filter( \'bbp_pre_anonymous_post_author_name\',
array( __CLASS__, \'bbp_pre_anonymous_post_author_name\' ) );
add_filter( \'bbp_pre_anonymous_post_author_email\',
array( __CLASS__, \'bbp_pre_anonymous_post_author_email\' ) );
}
static public function bbp_filter_anonymous_post_data( $retval, $r )
{
if( self::$name === $r[\'bbp_anonymous_name\']
&& self::$email === $r[\'bbp_anonymous_email\'] )
{
// reset the input to skip writing cookies
$retval = array();
// trick to activate the IP flood check
$retval[\'bbp_anonymous_flood_check\'] = \'1\';
}
return $retval;
}
static public function bbp_pre_anonymous_post_author_name( $name )
{
remove_filter( current_filter(), array( __CLASS__, __FUNCTION__ ) );
if( empty( $name ) )
$name = self::$name;
return $name;
}
static public function bbp_pre_anonymous_post_author_email( $email )
{
remove_filter( current_filter(), array( __CLASS__, __FUNCTION__ ) );
if( empty( $email ) )
$email = self::$email;
return $email;
}
}
我希望这能为你指明正确的方向。