0

我正在将 bbpress 与 Wordpress 一起使用,并且正在尝试更改user-profile.php内部的wp-content/plugins/bbpress/includes/users/显示方式。

如果用户有旁观者角色,我想回显一条“您没有参与论坛的权限”的文字,但我无法完成。这就是我现在所拥有的:

 <p class="bbp-user-forum-role"><?php  printf( __( 'Forum Role: %s',      'bbpress' ), bbp_get_user_display_role()    ); ?></p>
    // My php code comes here:
 if( bbp_get_spectator_role() ) {
    echo "<p>You do not have permission to participate in the forum.</p>";
    }

以上不起作用。但是,有一个名为“bbp_is_user_keymaster()”的函数。如果有类似的,那就太好了bbp_is_user_spectator(),但我似乎找不到。

任何想法如何做到这一点?

4

1 回答 1

0

通过一些编辑,您应该能够使用此代码:http ://simplysmartmedia.com/2013/03/role-based-profile-fields-in-wordpress/

编辑后的代码可能类似于;

    <?php
function check_user_role( $role, $user_id = null ) {
  if (isset($_REQUEST['user_id']))
    $user_id = $_REQUEST['user_id'];
// Checks if the value is a number
  if ( is_numeric( $user_id ) )
    $user = get_userdata( $user_id );
    else
    $user = wp_get_current_user();
  if ( empty( $user ) )
    return false;
  return in_array( $role, (array) $user->roles );
}

function one_random_test() {
if ( check_user_role ('spectator') ) {
    echo 'You are not allowed to edit anything.';
}
}
  add_action('bbp_template_before_user_profile', 'one_random_test');
?>

文本“您无权编辑任何内容”。然后出现在用户个人资料页面的顶部。使用任何你喜欢的钩子让它出现在其他地方。

于 2014-10-17T09:56:27.610 回答