WordPress功能类型参数

时间:2012-07-26 作者:Gerald

我不知道如何找出我的代码出了什么问题,为什么自定义帖子类型“Book”没有显示在我的仪表板上,我以管理员身份登录,我使用的是最新安装的WordPress 3.4.1

这里有我的代码

function codex_custom_init() {

  $labels = array(
    \'name\' => _x(\'Books\', \'post type general name\'),
    \'singular_name\' => _x(\'Book\', \'post type singular name\'),
    \'add_new\' => _x(\'Add New\', \'book\'),
    \'add_new_item\' => __(\'Add New Book\'),
    \'edit_item\' => __(\'Edit Book\'),
    \'new_item\' => __(\'New Book\'),
    \'all_items\' => __(\'All Books\'),
    \'view_item\' => __(\'View Book\'),
    \'search_items\' => __(\'Search Books\'),
    \'not_found\' =>  __(\'No books found\'),
    \'not_found_in_trash\' => __(\'No books found in Trash\'), 
    \'parent_item_colon\' => \'\',
    \'menu_name\' => __(\'Books\')

  );

    $capabilities = array(
    \'publish_posts\' => \'publish_books\',
    \'edit_posts\' => \'edit_books\',
    \'edit_others_posts\' => \'edit_others_books\',
    \'delete_posts\' => \'delete_books\',
    \'delete_others_posts\' => \'delete_others_books\',
    \'read_private_posts\' => \'read_private_books\',
    \'edit_post\' => \'edit_book\',
    \'delete_post\' => \'delete_book\',
    \'read_post\' => \'read_book\'
    );


  $args = array(
    \'labels\' => $labels,
    \'public\' => true,
    \'publicly_queryable\' => true,
    \'show_ui\' => true, 
    \'show_in_menu\' => true, 
    \'query_var\' => true,
    \'rewrite\' => true,
    \'capability_type\' => \'book\',
    \'capabilities\' => $capabilities,
    \'has_archive\' => true, 
    \'hierarchical\' => false,
    \'menu_position\' => null,
    \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
  ); 

  register_post_type(\'book\',$args);

}

add_action( \'init\', \'codex_custom_init\' );
我的代码是添加具有自定义功能的新自定义帖子,以使用members plugin.

1 个回复
SO网友:trans1t

看起来具有自定义capability\\u类型的CPT在默认情况下不会显示为超级管理员。即使手动添加所需用户角色的权限(在我的情况下是授权管理员)也无法实现这一点-我还必须手动添加管理员的功能,然后一切就绪。

将此代码插入我的插件激活挂钩,很好。

$roles = array( get_role(\'licensing-admin\'), get_role(\'administrator\') );

foreach($roles as $role) {
  if($role) {
    $role->add_cap(\'edit_license\');
    $role->add_cap(\'read_license\');
    $role->add_cap(\'delete_license\');
    $role->add_cap(\'edit_licenses\');
    $role->add_cap(\'edit_others_licenses\');
    $role->add_cap(\'publish_licenses\');
    $role->add_cap(\'read_private_licenses\');
    $role->add_cap(\'delete_licenses\');
    $role->add_cap(\'delete_private_licenses\');
    $role->add_cap(\'delete_published_licenses\');
    $role->add_cap(\'delete_others_licenses\');
    $role->add_cap(\'edit_private_licenses\');
    $role->add_cap(\'edit_published_licenses\');
  }
}

结束

相关推荐

PHP致命错误:无法为wp-includes/capabilities.php中的非对象调用重载函数

我在apache日志中遇到了太多以下错误。PHP Fatal error: Cannot call overloaded function for non-object in wp-includes/capabilities.php on line 1187这是函数current\\u user\\u can($capability)的内部,第1187行如下所示:$current_user = wp_get_current_user(); 我不知道问题出在哪里?