如何在wordpress中设置特定用户的默认内容设置



我在WordPress中寻找默认内容设置,然后我找到了这个代码,它工作正常,但我想为不同用户在WordPress的新帖子设置不同的默认内容,我该怎么做,示例user1:新的发布默认内容将是";FB是最大的社交网络";user2:新发布的默认内容将是";YT是最大的视频网站";user3:新发布的默认内容将是";TW正被全球官员使用";

我如何使用不同的用户和为不同的作者、贡献者、编辑等设置的不同默认内容?

此代码在所有用户上运行相同管理员、编辑、作者、贡献者

add_filter( 'default_content', 'add_default_content_to_wp_editor' );
function add_default_content_to_wp_editor($content) {
$content = "<h2>You are not allowed to</h2><br>
<p>
<h3>comment unless you are logged in.</h3><br>
<p>
<b>No spammers! The Big Kahuna is watching</b><br>
<p>";
return $content;
}
add_filter('default_content', 'my_editor_content', 10, 2);
function my_editor_content($content, $post)
{
global $current_user;
$user_roles = isset($current_user->roles[0]) ? $current_user->roles[0] : '';
switch ($user_roles) {
case 'administrator':
$content = 'FB is a largest social network';
break;
case 'author':
$content = 'YT is largest videos web';
break;
case 'editor':
$content = 'TW is being used by officials globally';
break;
}
return $content;
}

这可能有助于您根据用户角色设置默认内容。。。如果有其他事情请告诉我。谢谢

最新更新