我不是PHP程序员,只是一个简单的WordPress用户。
我如何允许作者角色允许发布贡献者的帖子
我不是PHP程序员,只是一个简单的WordPress用户。
我如何允许作者角色允许发布贡献者的帖子
我认为最好的方法是添加edit_other_posts
能够在插件/主题激活中“编写”角色,并在插件/主题停用时删除该功能。使用此方法,您只需运行一次任务,无需进一步编码。
使用插件激活/停用:
register_activation_hook( __FILE__, \'cyb_activation_function\' );
function cyb_activation_function() {
$author = get_role( \'author\' );
$author->add_cap( \'edit_others_posts\' );
}
register_deactivation_hook( __FILE__, \'cyb_deactivation_function\');
function cyb_deactivation_function() {
$author = get_role( \'author\' );
$author->remove_cap( \'edit_others_posts\' );
}
使用主题激活/停用:add_action(\'after_switch_theme\', \'cyb_activation_function\');
function cyb_activation_function() {
$author = get_role( \'author\' );
$author->add_cap( \'edit_others_posts\' );
}
add_action(\'switch_theme\', \'cyb_deactivation_function\');
function cyb_deactivation_function() {
$author = get_role( \'author\' );
$author->remove_cap( \'edit_others_posts\' );
}
显然,可以通过编程方式更改角色的功能,但前提是
不是PHP程序员,只是一个简单的WordPress用户
您必须使用允许修改用户角色的插件<有很多,但我个人的建议是Members JustinTadlock的插件。
这个的技术名称是什么?
每一个role 有一堆capabilities 分配给他们<这就是你要找的条件。
如何允许作者角色允许发布贡献者帖子?
您需要的功能是edit_others_posts
.
您要查找的术语是编辑器。如果您指的是一个可以编辑/发布您的贡献者帖子的用户。
您想通过its了解角色和功能codex entry. 为了让您的用户Author
用户角色要能够编辑和发布挂起的帖子,您需要分配该功能edit_others_posts
此角色。
将以下内容添加到functions.php
文件(使用add_cap, 代码基于kaiser\'s answer):
function add_edit_others_posts_to_author_role()
{
if ( ! current_user_can( \'author\' ) )
return;
// here you should check if the role already has_cap already and if so, abort/return;
if ( current_user_can( \'author\' ) )
{
$GLOBALS[\'wp_roles\']->add_cap( \'author\',\'edit_others_posts\' );
}
}
add_action( \'admin_init\', \'add_edit_others_posts_to_author_role\', 10, 0 );
或者,您可以使用以下插件User Role Editor. 您还可以考虑,这将允许您的作者级用户编辑已发布的帖子。发布了一个很好的解决方案allow Editors to edit pending posts but not draft ones.我正在尝试将query\\u posts放在WP\\u查询中。我的query\\u帖子之后的任何内容都无法正常工作。这是我的密码。我做错了什么?<?php $args = array( \'post_type\' => \'product\', \'posts_per_page\' => 1, \'product_cat\' => \'featured\' ); $loop = new WP_Query( $args ); while