[英]php unless wordpress user role = “subscriber” display this html code
我需要向Wordpress中除“订户”以外的所有用户角色显示HTML代码。
这是我无法正常工作的代码。
<?php
$current_user = wp_get_current_user();
?>
<?php if ( $current_user->role == 'subscriber' ) : ?>
<span>here is my html</span>
<?php endif; ?>
附注:正如您所知,我对php不太满意。
解决了! 我使用了以下代码,可提供所需的功能:
<?php if ( $this->current_user_can_edit_posts ) : ?>
<span>my html</span>
<?php endif; ?>
对于其他人,您可能需要更改“ $ this”部分。 因此,您可以检索current_user。 也许有人仍然可以为他们发布答案。
经过验证的代码有效。 让我知道它是否也适用于您! :)
<?php
$current_user = wp_get_current_user();
if ( ! in_array( 'subscriber', (array) $current_user->roles ) ) {
?>
<span>here is my html</span>
<?php
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.