Load documents in BuddyBoss profiles based on conditions.

huangapple go评论66阅读模式
英文:

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(&#39;,&#39;, $output);

echo &quot;&lt;script&gt;console.log(&#39;Debug Objects: &quot; . $output . &quot;&#39; );&lt;/script&gt;&quot;;
}

function document_screen_restrict($arg) {
    $admin=is_admin();
    debug($admin);
	if ( bp_is_my_profile() ) {
		debug(&quot;My documents, SEE&quot;);
		return $arg;
	}elseif ( $admin ){
		debug(&quot;I am Admin, SEE&quot;);
		return $arg;
	}else{
		debug(&quot;not my documents, SHOULD NOT SEE&quot;);
		return;
	}
}

add_filter(&#39;bp_document_get&#39;,&#39;document_screen_restrict&#39;);

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( &#39;bb_media_user_can_access&#39;, &#39;remove_document_download_globally_bb&#39;, 10, 4 );

function remove_document_download_globally_bb( $data, $id, $type, $media_group_id ){

  if( &#39;document&#39; == $type || &#39;folder&#39; == $type ){

    if ( bp_is_my_profile() ) {
        $data[&#39;can_download&#39;] = true;
    }elseif ( current_user_can(&#39;manage_options&#39;) ){
        $data[&#39;can_download&#39;] = true;
    }else{
        $data[&#39;can_download&#39;] = false;
    }
  }

  return $data;

}

huangapple
  • 本文由 发表于 2023年4月11日 08:21:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981609.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定