Wordpress:get_delete_post_link 不适用于自定义角色 [英] Wordpress: get_delete_post_link not working for custom role

查看:18
本文介绍了Wordpress:get_delete_post_link 不适用于自定义角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在functions.php中有一个自定义角色:

I have a custom role in functions.php:

add_role('test_pilot', 'Test Pilot', array(
    'read' => true,
    'edit_posts' => true,
    'delete_posts' => true,
));
// Give the custom role a new level
$test_pilot = get_role('test_pilot');
$test_pilot->add_cap('level_3');

...在前端我试图回显删除帖子链接:

...and on the front-end I'm trying to echo the delete post link:

<?php echo get_delete_post_link( get_the_ID() ); ?>

问题是,当以具有试飞员角色的用户身份登录时,该链接实际上并未显示.

The problem is the link isn't actually being displayed when logged in as a user with the test pilot role.

如果我以管理员身份登录,则会显示链接.

If I am logged in as an administrator the link does display.

我做错了什么?

推荐答案

尝试用下面的代码替换:

Try to replacing with below code:

function init_roles() {
global $wp_roles;

if (class_exists('WP_Roles'))   
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles(); 

if (is_object($wp_roles)) :
    $wp_roles->add_cap( 'editor');      
endif;

$wp_roles->add_role( 'test_pilot', 'Test Pilot', array(
    'read' => true,
    'edit_posts' => true,
    'delete_posts' => true
)); 
}
add_action('init', 'init_roles');

这篇关于Wordpress:get_delete_post_link 不适用于自定义角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆