英文:
Conditionally load documents in BuddyBoss profiles
问题
I am trying to make the current user's documents only accessible to the current user and admins.
我正在尝试让当前用户的文档只能被当前用户和管理员访问。
I am currently trying to add a filter when you are not on your own profile, you will not see the documents. The documents are still showing however...
我目前正在尝试添加一个过滤器,当您不在自己的个人资料页面时,您将看不到文档。然而,文档仍然显示...
英文:
I am trying to make the current user's documents only accessible to the current user and admins.
I am currently trying to add a filter when you are not on your own profile, you will not see the documents. The documents are still showing however...
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);
答案1
得分: 0
以下是您提供的代码的中文翻译:
看起来这是在工作的
function debug($data) {
$output = $data;
if (is_array($output))
$output = implode(',', $output);
echo "<script>console.log('调试对象: " . $output . "');</script>";
}
function document_screen_restrict($arg) {
$admin=is_admin();
debug($admin);
if ( bp_is_my_profile() ) {
debug("我的文档,查看");
return $arg;
}elseif ( $admin ){
debug("我是管理员,查看");
return $arg;
}else{
debug("不是我的文档,不应查看");
return;
}
}
add_filter('bp_document_get','document_screen_restrict');
然而,如果你有URL,即使没有登录,你仍然可以下载它。这是如何有条件地阻止下载,如果你没有登录。当你在URL中输入文档链接时,现在会重定向你到登录的主页,如果你已经登录,它将像往常一样下载。
```php
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;
}
英文:
It looks like this is working
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');
However if you have the url you can still download it if you're not logged in. This is how to stop the download conditionally if your not logged in. When you enter the document link in the url it is now redirecting you to the main page to log in, if you already are then it will just download per usual.
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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论