【问题标题】:Adding new user roll in WordPress that can only add custom posts在 WordPress 中添加只能添加自定义帖子的新用户角色
【发布时间】:2013-09-04 11:54:01
【问题描述】:

我已经购买了这个主题 http://pixelgeeklab.com/wp-realestast/#all 并想在 wordpress 中添加新的用户名,以便访问者可以注册到网站并添加自己的资产。

我尝试手动编写此代码,但意识到工作量很大,我尝试使用 Justin Tadlock (http://wordpress.org/plugins/members/) 的成员插件

我的问题是我只能允许查看和编辑所有帖子,但无法编辑,因此访问者只能访问名为 ESTATES 的自定义帖子类型。

在下面找到functions.php的代码(我尝试了很多,所以如果有人能看到这个并清除代码,我将非常感激):

 add_action('init', 'wptuts_getrole');  

function wptuts_getrole() {  
    $role = get_role('seller');  
    echo '<pre>';
    var_dump($role);  
    echo '</pre>';
}  

add_action( 'init', 'ct_add_role' ); 
function ct_add_role() {

 $role = get_role( 'seller' );
 $role->remove_cap('edit_posts');
     $role->add_cap('read');
     $role->add_cap('manage_options');
     $role->add_cap('publish_posts');
     $role->add_cap('add_estates');
     $role->add_cap('edit_estate');

/*add_role('seller', 'Seller', array(
    'read' => true,
    'add_posts'=> false,
    'publish_posts' => false,
    'edit_posts' => false,
    'delete_posts' => false,
    'add_estate'=> false,
    'manage_options'=>false,
));*/
//}

还有来自 Estates.php 的代码:

 /**
 * #####################################
 * Actions
 * #####################################
 */
static function register() {
    $args = array(
        'labels'       => array(
            'name'          => 'Estates',
            'singular_name' => 'Estate',
        ),
        'description'  => __( 'This post type is used in RealEstast theme', PGL ),
        'public'       => TRUE,
        'show_ui'      => TRUE,
        'hierarchical' => FALSE,
       /* 'capability_type' => 'post',
        'capability' => array(
            'add_posts' => 'add_estates',
            'publish_posts' => 'publish_estates',
            'edit_posts' => 'edit_estates',
            'edit_others_posts' => 'edit_others_estates',
            'delete_posts' => 'delete_estates',
            'delete_others_posts' => 'delete_others_estates',
            'read_private_posts' => 'read_private_estates',
            'edit_post' => 'edit_estate',
            'delete_post' => 'delete_estate',
            'read_post' => 'read_estate',
        ),*/
        'supports'     => array(
            'title',
            'editor',
            'thumbnail',
        ),
        'has_archive'  => TRUE,
        'rewrite'      => array(
            'slug'       => 'estate',
            'with_front' => TRUE
        ),
    );
    register_post_type( 'estate', $args );

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    你可以试试这个插件,它应该能满足你的一切需求http://wordpress.org/plugins/advanced-access-manager/

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-07
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      相关资源
      最近更新 更多