以“订户”身份登录时,GET_DELETE_POST_LINK($POST->ID)为空

时间:2017-03-21 作者:frshjb373

尝试在前端创建删除链接,但作为订阅者登录时get_delete_post_link( $post->ID ) 变量为空。以管理员身份登录时,链接正常。

我错过什么了吗?

1 个回复
SO网友:Sam

您的问题可能是订阅者无法删除帖子。请尝试以下内容以了解情况。

if ( !current_user_can( \'delete_post\', $post->ID ) )
{
   echo \'I do not have the privilege to delete posts\';
}
else{
     get_delete_post_link( $post->ID );
}
以上内容可能会让任何用户删除任何其他用户的帖子,从而给您带来麻烦,因此以下内容旨在仅允许具有订阅者级别的帖子所有者删除其帖子或具有正确权限的人。

          if ( get_the_author_meta(\'ID\') == get_current_user_id() && current_user_can(\'subscriber\') )
          {
            // owner of post and subscriber
            get_delete_post_link( $post->ID );
          }
          if ( get_the_author_meta(\'ID\') != get_current_user_id()  && current_user_can(\'subscriber\')  )
          {
            // not the owner of post and subscriber
            echo \'Not your post\';
          }
          else
          {
           // should be ok as not a subscriber and has delete privilages
           get_delete_post_link( $post->ID );
          }

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register