如何解决在WordPress插件中创建自定义帖子类型,添加自定义元字段,以防止将来此类帖子的所有可编辑性
我是插件开发的新手,遇到了一些减速。
所以这是我的标准,我很难解决其中的任何一条:
我只需要三个字段,其中两个是自定义元字段(标题,website_url和website_source_code)-我相信正在创建额外的字段!
我需要一个管理菜单标签,该标签将链接到网站列表-使用下面的扩展代码时不会显示。
我要求删除所有形式的编辑,但是,仍然可以单击每个条目并查看其内容(无法编辑或更新)-我认为这是Meta_cap功能的来源,请不要仍然不知道如何应用。
// Create Custom Post Type
protected function create_post_type() {
add_action('init',array($this,'custom_post_type'));
add_action('admin_init','custom_post_type_caps'));
}
// Register Websites Custom Post Type
function custom_post_type() {
$labels = array(
'name' => __( 'Websites','website-textdomain' ),'singular_name' => __( 'Website','add_new' => __( 'Add New','add_new_item' => __( 'Add New Website','edit_item' => __( 'Edit Website','new_item' => __( 'New Website','view_item' => __( 'View Website','search_items' => __( 'Search Websites','not_found' => __( 'No websites found','not_found_in_trash' => __( 'No websites found in Trash','parent_item_colon' => __( 'Parent Website:','menu_name' => __( 'Websites','website-textdomain' )
);
$capabilities = array(
'publish_posts' => 'publish_websites','edit_posts' => 'edit_websites','edit_others_posts' => 'edit_others_websites','delete_posts' => 'delete_websites','delete_others_posts' => 'delete_others_websites','read_private_posts' => 'read_private_websites','edit_post' => 'edit_website','delete_post' => 'delete_website','read_post' => 'read_website'
);
$args = array(
'labels' => $labels,'public' => true,'publicly_queryable' => true,'show_ui' => true,'show_in_menu' => true,'query_var' => true,'rewrite' => true,'capability_type' => 'website','capabilities' => $capabilities,'hierarchical' => false,'menu_position' => null,'supports' => array('title','custom-fields')
);
register_post_type('website',$args);
//register_post_type('website',['public' => true,'label' => 'Websites']);
}
function custom_post_type_caps() {
// gets the administrator role
$admins = get_role('administrator');
$admins->add_cap('edit_website');
$admins->add_cap('delete_website');
$admins->add_cap('read_website');
}
很多事情都被注释掉了,因为我知道它可以工作,帖子被创建并且可以在wp_query循环中访问。我只是无法剔除上面列表中的任何其他要求,因此尝试将代码愚蠢一些,以期使我过于复杂。
如果我使用此行:
register_post_type('website','label' => 'Websites']);
帖子类型已创建,并且菜单标签出现在管理员左侧菜单中。但是,我无法从上面的列表中添加任何其他条件。
我已经阅读并赞赏有很多其他类似的文章,但是没有一个是类似的文章,要求的组合是唯一的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。