现在是下午4点,我的大脑一个小时前就停止了工作,就我的一生而言,我就是搞不明白为什么事情没有按预期进行。
我试图在媒体库中仅显示用户上载的媒体。我的过滤器工作并只返回用户上传的媒体,直到我添加if语句以确保它只影响媒体库。
/**
* Hide others media from Contributors
*/
function ggstyle_hide_media_by_other($query)
{
// When I add this if statement the filter no longer works.
$screen = get_current_screen();
if ($screen->id != \'upload\') {
return $query;
}
if (current_user_can(\'contributor\')) {
$query->set(\'author\', get_current_user_id());
}
return $query;
}
add_filter(\'pre_get_posts\', \'ggstyle_hide_media_by_other\');
// Debuggin function
function ggstyle_debug()
{
// Debug shows that this screen IS \'upload\'....
echo "<pre>".print_r(get_current_screen(), true)."</pre>";
}
add_filter(\'admin_head\', \'ggstyle_debug\');