有条件地加载BuddyBoss配置文件中的文档



我试图使当前用户的文档只能被当前用户和管理员访问。

我目前正试图添加一个过滤器,当你不是在你自己的个人资料,你将看不到文件。然而,文件仍然显示…

function debug($data) {
$output = $data;
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log('Debug Objects: " . $output . "' );</script>";
}
function document_screen_restrict() {
if ( bp_is_my_profile() != 1 ) {
debug("not my documents, SHOULD NOT SEE");
add_filter("document_screen",'__return_false');
debug(did_action( 'document_screen' ));
return;
}else{
debug("My documents, SEE");
remove_filter("document_screen",'__return_false');
debug(did_action( 'document_screen' ));
}
}
add_action('wp','document_screen_restrict',10);

看起来运行正常

function debug($data) {
$output = $data;
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log('Debug Objects: " . $output . "' );</script>";
}
function document_screen_restrict($arg) {
$admin=is_admin();
debug($admin);
if ( bp_is_my_profile() ) {
debug("My documents, SEE");
return $arg;
}elseif ( $admin ){
debug("I am Admin, SEE");
return $arg;
}else{
debug("not my documents, SHOULD NOT SEE");
return;
}
}
add_filter('bp_document_get','document_screen_restrict');

然而,如果你有url,你仍然可以下载它,如果你没有登录。这是如何有条件地停止下载,如果你没有登录。当你在url中输入文档链接时,它现在会将你重定向到主页登录,如果你已经登录了,那么它会照常下载。

add_filter( 'bb_media_user_can_access', 'remove_document_download_globally_bb', 10, 4 );
function remove_document_download_globally_bb( $data, $id, $type, $media_group_id ){
if( 'document' == $type || 'folder' == $type ){
if ( bp_is_my_profile() ) {
$data['can_download'] = true;
}elseif ( current_user_can('manage_options') ){
$data['can_download'] = true;
}else{
$data['can_download'] = false;
}
}
return $data;
}

最新更新