我正在努力prevent moderation of forum posts 适用于具有“中等”能力或积极的“高级”会员计划(WC会员资格)的用户。
我希望这些作者的回复不受我们的限制(链接数量、封锁词等)。
我尝试过使用以下过滤器,但没有成功:
add_filter( \'bbp_bypass_check_for_moderation\', \'bbp_bypass_if_user_can_moderate\', 10, 4 );
function bbp_bypass_if_user_can_moderate( $anonymous_data, $author_id, $title, $content ){
if( user_can( $author_id, \'moderate\' ) || wc_memberships_is_user_active_member( $author_id, \'premium\' ) ){
return true;
} else {
return false;
}
}
add_filter( \'bp_bypass_check_for_moderation\', \'bp_bypass_if_user_can_moderate\', 10, 3 );
function bp_bypass_if_user_can_moderate( $user_id, $title, $content ){
if( user_can( $user_id, \'moderate\' ) || wc_memberships_is_user_active_member( $user_id, \'premium\' ) ){
return true;
} else {
return false;
}
}
看起来上面的代码应该可以工作。我是否忽视了什么?
参考文献:
- https://www.buddyboss.com/resources/reference/functions/bbp_check_for_moderation/
- https://www.buddyboss.com/resources/reference/hooks/bp_bypass_check_for_moderation/
- https://developer.wordpress.org/reference/functions/user_can/
- https://docs.woocommerce.com/document/woocommerce-memberships-function-reference/#wc_memberships_is_user_active_member
最合适的回答,由SO网友:MarkPraschan 整理而成
经过多次尝试和错误,我终于找到了答案。
的文档bbp_bypass_check_for_moderation
是否缺少第一个参数($value
). 以下是所有参数的工作代码:
/* Bypass moderation (bbPress) */
add_filter( \'bbp_bypass_check_for_moderation\', \'bbp_bypass_if_user_can_moderate\', 5, 5 );
function bbp_bypass_if_user_can_moderate( $value, $anonymous_data, $author_id, $title, $content ){
if( user_can( $author_id, \'moderate\' ) || wc_memberships_is_user_active_member( $author_id, \'premium\' ) ){
return true;
}
return false;
}
/* Bypass moderation (BuddyPress) */
add_filter( \'bp_bypass_check_for_moderation\', \'bp_bypass_if_user_can_moderate\', 5, 4 );
function bp_bypass_if_user_can_moderate( $value, $user_id, $title, $content ){
if( user_can( $author_id, \'moderate\' ) || wc_memberships_is_user_active_member( $author_id, \'premium\' ) ){
return true;
}
return false;
}
SO网友:Rup
bp\\u bypass\\u if\\u user\\u can\\u mediate参数错误。从…起the documentation you linked to 它应该是bool$value、int$user\\u id、string$title、string$content,对于过滤器来说,如果不打算更改它,则应该像往常一样传递$value。e、 g.以下是您的过滤器的固定版本:
add_filter( \'bp_bypass_check_for_moderation\',
\'bbp_bypass_if_user_can_moderate\', 10, 4 );
function bbp_bypass_if_user_can_moderate( $value, $user_id, $title, $content ) {
if ( ( !$value ) && ( user_can( $user_id, \'moderate\' ) ||
wc_memberships_is_user_active_member( $user_id, \'premium\' ) ) ) {
return true;
}
return $value;
}
但我不能肯定这会奏效。