我有一个CPT来代替我的“post”post类型,但我仍然需要能够使用附件。问题是,附件具有post功能。
我不想给我的角色赋予post功能,因此,我试图找到一种方法来避免它。
我在wordpress的跟踪中发现了一个黑客:http://core.trac.wordpress.org/ticket/19834
function crunchhack() {
global $wp_post_types;
$wp_post_types[\'attachment\']->cap->edit_post = \'upload_files\';
}
add_action( \'init\', \'crunchhack\' );
我已将其添加到
functions.php
. 它不起作用,因此,我尝试用
upload_files
:
function fix_media_permissions() {
global $wp_post_types;
$wp_post_types[\'attachment\']->cap->edit_post = \'upload_files\';
$wp_post_types[\'attachment\']->cap->read_post = \'upload_files\';
$wp_post_types[\'attachment\']->cap->delete_post = \'upload_files\';
$wp_post_types[\'attachment\']->cap->edit_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->edit_others_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->edit_published_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->publish_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->delete_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->delete_others_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->delete_published_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->delete_private_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->edit_private_posts = \'upload_files\';
$wp_post_types[\'attachment\']->cap->read_private_posts = \'upload_files\';
}
add_action( \'init\', \'fix_media_permissions\');
遗憾的是,这也行不通。我可以看到上传的图片,但仅此而已。有什么想法吗?
最合适的回答,由SO网友:Afterlame 整理而成
我解决了它。问题是,我在另一个函数(稍后调用)中调用了该函数。问题中的代码片段工作正常。
我曾想过删除这个问题,但我认为对于正在搜索类似方法的其他用户来说,这个片段会很有趣。