Wordpress: get_delete_post_link not working for custom role

吃可爱长大的小学妹 提交于 2019-12-13 06:05:32

问题


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.

What am I doing wrong?


回答1:


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');


来源:https://stackoverflow.com/questions/20277937/wordpress-get-delete-post-link-not-working-for-custom-role

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!