Wordpress中特定用户的特定职位 [英] Specific Part of Post for Specific User in Wordpress
问题描述
我正在wordpress中开发一个基于成员资格的网站,我在其中安装了S2Member插件,并向用户显示了一个包含一些快速链接的欢迎页面.我现在停留在要显示特定用户名的特定链接的位置.我安装了名为peter的登录重定向的插件,该插件向用户显示特定的登录页面,但对我不起作用,因为我已经在使用S2 Member插件.
I am developing a membership based website in wordpress where I installed S2Member plugin and I show a user a welcome page with some quick links. I am now stuck at the point where I want to show specific links for specific usernames. I installed a plugin named peter's login redirect that shows a specific login page to the user but it didn;t work for me as I am already using a S2 Member plugin.
还有其他方法可以为特定用户显示特定链接/按钮/后置部分吗?
Is there any other way to show a specific link/button/post-part for the specific user?
推荐答案
我认为最简单的方法是使用 Shortcode ,则可以检测到用户名,用户角色或WP_User对象中包含的其他内容:
I think the easiest way is using a Shortcode, you can detect the user name, user role or something else contained in the WP_User object:
<?php
/**
* Plugin Name: (SO) Welcome Shortcode
*/
add_shortcode( 'welcome', 'welcome_so_23702194' );
function welcome_so_23702194( $atts, $content = null )
{
$user = get_userdata( get_current_user_id() );
if( !$user ) // Normal visitor, nor logged in
return '';
# Use the following to inspect the object, and do at the end --> return $debug;
// $debug = '<pre>' . print_r( $user, true ) . '</pre>';
if( 'brasofilo' == $user->data->user_login )
$output = "Hello, brasofilo!";
elseif( in_array( 'administrator', $user->roles ) )
$output = "Hello, admininstrator user";
else
$output = '';
return $output;
}
然后,在欢迎页面中,在内容[welcome]
的中间添加简码.
Then, in your Welcome page add the shortcode in the middle of the content [welcome]
.
这篇关于Wordpress中特定用户的特定职位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!