{"action":"created","issue":{"url":"https://api.github.com/repos/boonebgorges/buddypress-docs/issues/448","labels_url":"https://api.github.com/repos/boonebgorges/buddypress-docs/issues/448/labels{/name}","comments_url":"https://api.github.com/repos/boonebgorges/buddypress-docs/issues/448/comments","events_url":"https://api.github.com/repos/boonebgorges/buddypress-docs/issues/448/events","html_url":"https://github.com/boonebgorges/buddypress-docs/issues/448","id":61131617,"number":448,"title":"`bp_docs_general_access_protection()` not reporting correctly","user":{"login":"christianwach","id":726936,"avatar_url":"https://avatars.githubusercontent.com/u/726936?v=3","gravatar_id":"","url":"https://api.github.com/users/christianwach","html_url":"https://github.com/christianwach","followers_url":"https://api.github.com/users/christianwach/followers","following_url":"https://api.github.com/users/christianwach/following{/other_user}","gists_url":"https://api.github.com/users/christianwach/gists{/gist_id}","starred_url":"https://api.github.com/users/christianwach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianwach/subscriptions","organizations_url":"https://api.github.com/users/christianwach/orgs","repos_url":"https://api.github.com/users/christianwach/repos","events_url":"https://api.github.com/users/christianwach/events{/privacy}","received_events_url":"https://api.github.com/users/christianwach/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-13T16:46:52Z","updated_at":"2015-03-13T22:02:53Z","closed_at":null,"body":"Hi @boonebgorges, it seems as though `bp_docs_general_access_protection()` is not reporting correctly when used on a WP Multisite instance that still uses the 'ms-files.php' filter - i.e. a WP Multisite that was started prior to WP 3.5 - and when BuddyPress is not installed on the root blog. \r\n\r\n(BTW, I ran into this on a \"vintage\" multi-network instance - one that had been upgraded since the mists of time - with BP Multi Network installed and CBOX enabled on a secondary network.)\r\n\r\nIn these cases, the .htaccess file in each subdirectory of 'bp-attachments' has no effect because the RewriteRule in the root .htaccess overrides it and the files are never served directly.\r\n\r\nIn this instance, I've found it necessary to ignore the result of `bp_docs_general_access_protection()` and use the following filter to reinstate the URLs that would be used if it were reporting correctly:\r\n\r\n```php\r\n/**\r\n * Change the base URL for BP Docs, because we are serving files via ms-files\r\n */\r\nadd_filter( 'bp_docs_attachment_url_base', 'my_bp_docs_attachment_url_base', 100, 2 );\r\nfunction my_bp_docs_attachment_url_base( $att_url, $attachment ) {\r\n\t$new_att_base = basename( get_attached_file( $attachment->ID ) );\r\n\t$new_doc_url = bp_docs_get_doc_link( $attachment->post_parent );\r\n\t$new_att_url = add_query_arg( 'bp-attachment', $new_att_base, $new_doc_url );\r\n\treturn $new_att_url;\r\n}\r\n```\r\n\r\nI suppose another way to implement this would be to check the status of `get_site_option( 'ms_files_rewriting' )` in `BP_Docs_Attachments->check_is_protected()` and tease out the unfiltered URL to the 'test.html' file for the `wp_remote_get()` call. But that seemed like a lot of work when the filter above seems to work :grinning: \r\n\r\nHope this helps someone."},"comment":{"url":"https://api.github.com/repos/boonebgorges/buddypress-docs/issues/comments/79461018","html_url":"https://github.com/boonebgorges/buddypress-docs/issues/448#issuecomment-79461018","issue_url":"https://api.github.com/repos/boonebgorges/buddypress-docs/issues/448","id":79461018,"user":{"login":"boonebgorges","id":246627,"avatar_url":"https://avatars.githubusercontent.com/u/246627?v=3","gravatar_id":"","url":"https://api.github.com/users/boonebgorges","html_url":"https://github.com/boonebgorges","followers_url":"https://api.github.com/users/boonebgorges/followers","following_url":"https://api.github.com/users/boonebgorges/following{/other_user}","gists_url":"https://api.github.com/users/boonebgorges/gists{/gist_id}","starred_url":"https://api.github.com/users/boonebgorges/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boonebgorges/subscriptions","organizations_url":"https://api.github.com/users/boonebgorges/orgs","repos_url":"https://api.github.com/users/boonebgorges/repos","events_url":"https://api.github.com/users/boonebgorges/events{/privacy}","received_events_url":"https://api.github.com/users/boonebgorges/received_events","type":"User","site_admin":false},"created_at":"2015-03-13T22:02:53Z","updated_at":"2015-03-13T22:02:53Z","body":"Thanks for the tip, @christianwach. I will look into a general solution \nfor this.\n\nOn 03/13/2015 12:46 PM, Christian Wach wrote:\n> Hi @boonebgorges <https://github.com/boonebgorges>, it seems as though\n> |bp_docs_general_access_protection()| is not reporting correctly when\n> used on a WP Multisite instance that still uses the 'ms-files.php'\n> filter - i.e. a WP Multisite that was started prior to WP 3.5 - and when\n> BuddyPress is not installed on the root blog.\n>\n> (BTW, I ran into this on a \"vintage\" multi-network instance - one that\n> had been upgraded since the mists of time - with BP Multi Network\n> installed and CBOX enabled on a secondary network.)\n>\n> In these cases, the .htaccess file in each subdirectory of\n> 'bp-attachments' has no effect because the RewriteRule in the root\n> .htaccess overrides it and the files are never served directly.\n>\n> In this instance, I've found it necessary to ignore the result of\n> |bp_docs_general_access_protection()| and use the following filter to\n> reinstate the URLs that would be used if it were reporting correctly:\n>\n> /**\n>   * Change the base URL for BP Docs, because we are serving files via ms-files\n>   */\n> add_filter('bp_docs_attachment_url_base','my_bp_docs_attachment_url_base',100,2  );\n> function  my_bp_docs_attachment_url_base($att_url,$attachment  ) {\n>      $new_att_base  =  basename( get_attached_file($attachment->ID  ) );\n>      $new_doc_url  =  bp_docs_get_doc_link($attachment->post_parent  );\n>      $new_att_url  =  add_query_arg('bp-attachment',$new_att_base,$new_doc_url  );\n>      return  $new_att_url;\n> }\n>\n> I suppose another way to implement this would be to check the status of\n> |get_site_option( 'ms_files_rewriting' )| in\n> |BP_Docs_Attachments->check_is_protected()| and tease out the unfiltered\n> URL to the 'test.html' file for the |wp_remote_get()| call. But that\n> seemed like a lot of work when the filter above seems to work :grinning:\n>\n> Hope this helps someone.\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/boonebgorges/buddypress-docs/issues/448>.\n>\n"}}