WordPress为了整个系统的安全性,默认订阅者是不能上传图片的,而我们在制作一些主题的时候需要用到用户投稿功能,这个时候我们可以通过下面的代码让订阅者也可以上传图片。
function dahuzi_add_user_rights() {
$role = 'subscriber';
$role = get_role($role);
$role->add_cap('upload_files');
}
add_action( 'admin_init', 'dahuzi_add_user_rights');
将下面的代码放至当前使用WordPress主题的functions.php中。
/增加订阅者权限,使其可以在投稿的时候上传图片,删除图片
function dahuzi_add_user_rights() {
$role = 'subscriber';
$role = get_role($role);
$role->add_cap('upload_files');
$role->add_cap('edit_others_posts');
$role->add_cap('edit_published_posts');
$role->add_cap('delete_posts');
}
add_action( 'admin_init', 'dahuzi_add_user_rights');
需要注意的是,这些权限是直接写进数据库的,开启这些权限后,如需重新禁用这些权限时,直接删除这段代码是不行的。