【问题标题】:bbpress if spectator role - echo out textbbpress 如果观众角色 - 回显文本
【发布时间】:2014-12-07 04:07:03
【问题描述】:

我正在将 bbpress 与 Wordpress 一起使用,我正在尝试更改 user-profile.phpwp-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() 代替,那就太好了,但我似乎找不到。

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

【问题讨论】:

    标签: wordpress bbpress


    【解决方案1】:

    稍作修改,您应该可以使用以下代码: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');
    ?>
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 2018-08-30
      • 1970-01-01
      • 2010-12-14
      • 2020-04-22
      相关资源
      最近更新 更多