我正在使用WordPress的bbpress,我正在尝试更改wp-content/plugins/bbpress/includes/users/ user-profile.php 。
如果用户有观众角色,我想回复一条文字说“你没有参与论坛的许可”,但我无法完成。 这就是我现在拥有的:
<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()话会很棒,但我似乎找不到一个。
任何想法如何做到这一点?
I'm using bbpress with Wordpress and I'm trying to change how user-profile.php inside wp-content/plugins/bbpress/includes/users/ appear.
I want to echo out a text saying "You do not have permission to participate in the forum" if the user has the spectator role, but I can't accomplish it. This is what I have now:
<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>"; }The above doesn't work. However, there is a function called "bbp_is_user_keymaster()". It would be great if there was a similar but bbp_is_user_spectator() instead, but I can't seem to find one.
Any ideas how to do this?
最满意答案
通过一些编辑,您应该能够使用此代码: 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'); ?>文字“你不能编辑任何东西。” 然后出现在用户个人资料页面的顶部。 使用你喜欢的任何钩子让它出现在其他地方。
With a bit of editing you should be able to use this code: http://simplysmartmedia.com/2013/03/role-based-profile-fields-in-wordpress/
The edited code could look something like;
<?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'); ?>The text "You are not allowed to edit anything." then appears at the top of the users profile page. Use whatever hook you like to have it appear somewhere else.
更多推荐
发布评论