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

查看:87
本文介绍了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.

我在做什么错了?

推荐答案

尝试替换为以下代码:

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天全站免登陆