【问题标题】:Show specific media for particular wordpress role显示特定 wordpress 角色的特定媒体
【发布时间】:2012-08-03 18:30:54
【问题描述】:

我正在寻找有关如何仅向特定用户显示特定媒体的想法。

我已为该角色创建了一个新角色和功能,我希望将特定媒体文件附加到该角色。这样新角色的人只能查看分配给它的媒体。

最后,我创建的是人们将登录以下载文档的页面。我希望能够动态地提取这些文档,但如果我无法弄清楚我在上面要求做什么,我只会将文档硬编码到页面中。

【问题讨论】:

    标签: wordpress roles capability


    【解决方案1】:

    嗯...就仅向某些用户显示某些媒体而言...

    我们可以检查他们在哪里查看他们的媒体,如果您只是在 WP-Admin 界面中谈论默认媒体库,那么我们可以检查 URL 以查看他们是否在媒体库页面上.

    我们将(很可能)将此代码放置在我们主题的 functions.php 文件中,或根据您的设计放置在我们的插件中。

    //we need access to the $wp_query;
    global $wp_query;
    
    //now we build our function, we need to pass $wp_query into it
    function manage_user_media($wp_query){
    
      //we check the location of the window
      if(strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false ||
          strops($_SERVER['REQUEST_URI'], '/wp-admin/media-upload.php') !== false):
    
          //check if the logged in user has a capability of say...a level 5 user
          if(!current_user_can('level_5')):
    
              //this user does not have the capabilities of a level 5 user.
              //hijack the 'author' query var, so we can set it to the ID of our user
              $wp_query->set('author', get_current_user_id());
    
          endif;    
    
      endif;
    
    }
    

    如果Wordpress User Levels are confusing to you, have a look at the Codex for comparison.

    这意味着,任何 5 级以上用户都可以看到 [ALL] 个媒体元素,而 5 级以下用户只能查看仅 [HIS OR HER] 媒体元素。

    【讨论】:

    • 不,我指的是在前端查看媒体。我认为他们已经决定不使用登录,所以我不再需要它了。我真的很感谢你的帮助!我不能赞成你的帖子,否则我会的。只知道我在脑海中投了赞成票:)。
    猜你喜欢
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 1970-01-01
    相关资源
    最近更新 更多