我使用WordPress和Church Theme Content插件,这个插件注册了各种自定义帖子类型和其他分类,特别编写的主题可以利用。
为了帮助管理网站,我想修改其中一个分类和帖子类型的功能,并允许某些用户对它们的权限有限。在这里和其他网站上挖掘之后,我做了一个简单的插件,修改了功能并使用了Members插件来修改用户的权限,但是自4.6更新后它就不再工作了,他们不再使用#39 ; t出现在Members插件和用户角色编辑器....的自定义功能列表中。
我不知道从哪里开始寻找解决方案,我已经来回尝试不同的事情,并试图找到关于它如何运作的体面文档,但我已陷入困境,任何帮助都将不胜感激。
当前代码正在运行,现在没有:
<?php
/*
Plugin Name: Church Theme Content - Custom Sermon Caps
Description: Allows fine grained control over Sermon Posts
Version: 1
Author: Tom Wild
Text Domain: ctcCustom-toolset
*/
// Prevent direct access to this file.
if (!defined( 'ABSPATH' )){
header( 'HTTP/1.0 403 Forbidden' );
echo 'This file should not be accessed directly!';
exit; // Exit if accessed directly
}
function ctc__modify_caps() {
// get the arguments of the already-registered taxonomy
$speaker_category_args = get_taxonomy('ctc_sermon_speaker'); // returns an object
// make changes to the args
$speaker_category_args->capabilities = array(
'manage_terms' => 'add_speakers',
'edit_terms' => 'edit_speakers',
'delete_terms' => 'delete_speakes',
'assign_terms' => 'assign_speakers'
);
$sermon_post_type = get_post_type_object('ctc_sermon');
$sermon_post_type->capability_type = 'sermon';
$sermon_post_type->map_meta_cap = true;
$sermon_post_type->capabilities = array(
// meta caps (don't assign these to roles)
'edit_post' => 'edit_sermon',
'read_post' => 'read_sermon',
'delete_post' => 'delete_sermon',
// primitive/meta caps
'create_posts' => 'create_sermons',
// primitive caps used outside of map_meta_cap()
'edit_posts' => 'edit_sermons',
'edit_others_posts' => 'edit_others_sermons',
'publish_posts' => 'publish_sermons',
'read_private_posts' => 'read',
// primitive caps used inside of map_meta_cap()
'read' => 'read',
'delete_posts' => 'delete_sermons',
'delete_private_posts' => 'delete_private_sermons',
'delete_published_posts' => 'delete_published_sermons',
'delete_others_posts' => 'delete_others_sermons',
'edit_private_posts' => 'edit_private_sermons',
'edit_published_posts' => 'edit_published_sermons'
);
// re-register the taxonomy
register_taxonomy('ctc_sermon_speaker', 'ctc_sermon', (array) $speaker_category_args );
register_post_type('ctc_sermon',(array) $sermon_post_type);
}
add_action('init', 'ctc__modify_caps', 11);
?>
答案 0 :(得分:0)
不确定为什么它停止工作,但我找到了解决方案。
在深入了解教会主题内容的代码后,我发现它允许过滤器注册帖子类型和分类,所以我重新编写了我的代码:
<?php
//Other Stuff
function ctc__do_sermon_tag_filter($args) {
$args['capabilities'] = array(
'manage_terms' => 'add_sermon_tags',
'edit_terms' => 'edit_sermon_tags',
'delete_terms' => 'delete_sermon_tags',
'assign_terms' => 'assign_sermon_tags'
);
}
function ctc__do_sermon_post_type_filter($args){
$args['capability_type'] = 'sermon';
$args['capabilities'] = array(
// meta caps (don't assign these to roles)
'edit_post' => 'edit_sermon',
'read_post' => 'read_sermon',
'delete_post' => 'delete_sermon',
// primitive/meta caps
'create_posts' => 'create_sermons',
// primitive caps used outside of map_meta_cap()
'edit_posts' => 'edit_sermons',
'edit_others_posts' => 'edit_others_sermons',
'publish_posts' => 'publish_sermons',
'read_private_posts' => 'read_private_sermons',
// primitive caps used inside of map_meta_cap()
'read' => 'read',
'delete_posts' => 'delete_sermons',
'delete_private_posts' => 'delete_private_sermons',
'delete_published_posts' => 'delete_published_sermons',
'delete_others_posts' => 'delete_others_sermons',
'edit_private_posts' => 'edit_private_sermons',
'edit_published_posts' => 'edit_published_sermons'
);
return $args;
}
function ctc__add_filters(){
add_filter('ctc_post_type_sermon_args','ctc__do_sermon_post_type_filter',11);
add_filter('ctc_taxonomy_sermon_topic_args','ctc__do_sermon_topic_filter',11);
add_filter('ctc_taxonomy_sermon_book_args','ctc__do_sermon_book_filter',11);
add_filter('ctc_taxonomy_sermon_series_args','ctc__do_sermon_series_filter',11);
add_filter('ctc_taxonomy_sermon_speaker_args','ctc__do_sermon_speaker_filter',11);
add_filter('ctc_taxonomy_sermon_tag_args','ctc__do_sermon_tag_filter',11);
}
add_action('init', 'ctc__add_filters',9);
?>