Parent for Doc Drop-down Showing all Docs
-
I’m working on an internal website for a client and I’m running into an issue with the parent for doc drop-down when creating a new doc. The problem is that the parent for doc drop-down is showing all saved documents even if they are from private or hidden groups. How do I limit the results in the drop-down to only show documents that the user has access to?
-
hi Hortons-art-
If you’re logged in as a site admin, you’ll see every doc in that dropdown. If you log in as a subscriber level user, then doc protection kicks in to filter that list.
Something must be up with my setup than. I’m logged in as a subscriber and it’s showing all Docs that have been created sitewide in the dropdown.
I just created a new test user and created that users first doc. The parent for doc dropdown lists all docs that have been created sitewide. After that first doc is created though, I can create a new document and then it only shows my docs. If I delete all of my docs and try to create a new one the dropdown shows all docs again for parent of.
Thanks for your response and for describing the steps to reproduce the issue. I’ve followed them, but my new user’s parent doc dropdown only shows docs that the new user should be able to see.
So, if you make a new doc (using an existing user) that has all of its access parameters set to “creator”, will your new user be able to see it in the parent dropdown?
When the new user visits the docs directory, are they seeing the correct set of docs, or are they seeing private/restricted docs there, too?
My guess is that another plugin is also filtering
WP_Queryat thepre_get_postshook (that’s how BP Docs removes private docs fromWP_Query), so if you can deactivate your other plugins to find out which one conflicts with BP Docs, that’d be very helpful.Thanks!
Hi David,
Thanks for getting back to me on this. If I make a new doc (using an existing user) that has all of its access parameters set to “creator”, the new user is still able to see it in the parent dropdown.
When the new user visits the docs directory, they are seeing the correct set of docs and are not seeing private/restricted docs.
I’ve deactivated all plugins except for BuddyPress and BuddyPress Docs and switched to the Twenty Fifteen theme, but the results are still the same. The new user’s list of options for the parent dropdown are still showing all docs until that user creates a new doc and saves it.
Hi horntons-art-
Thanks for taking the time to troubleshoot. Can you add this function to your theme’s
functions.phpfile and let me know what is output in the ‘parent’ meta box when it’s broken (and what it looks like when it’s working as expected)?The output for the ‘parent’ meta box when it’s broken is:
array(58) { ["post_type"] => string(6) "bp_doc" ["tax_query"] => array(1) { [0] => array(4) { ["terms"] => array(3) { [0] => string(21) "bp_docs_access_anyone" [1] => string(23) "bp_docs_access_loggedin" [2] => string(21) "bp_docs_access_user_1" } ["taxonomy"] => string(14) "bp_docs_access" ["field"] => string(4) "slug" ["operator"] => string(2) "IN" } } ["meta_query"] => array(0) { } ["orderby"] => string(8) "modified" ["order"] => string(3) "ASC" ["paged"] => int(1) ["posts_per_page"] => int(-1) ["error"] => string(0) "" ["m"] => string(0) "" ["p"] => int(0) ["post_parent"] => string(0) "" ["subpost"] => string(0) "" ["subpost_id"] => string(0) "" ["attachment"] => string(0) "" ["attachment_id"] => int(0) ["name"] => string(0) "" ["static"] => string(0) "" ["pagename"] => string(0) "" ["page_id"] => int(0) ["second"] => string(0) "" ["minute"] => string(0) "" ["hour"] => string(0) "" ["day"] => int(0) ["monthnum"] => int(0) ["year"] => int(0) ["w"] => int(0) ["category_name"] => string(0) "" ["tag"] => string(0) "" ["cat"] => string(0) "" ["tag_id"] => string(0) "" ["author"] => string(0) "" ["author_name"] => string(0) "" ["feed"] => string(0) "" ["tb"] => string(0) "" ["comments_popup"] => string(0) "" ["meta_key"] => string(0) "" ["meta_value"] => string(0) "" ["preview"] => string(0) "" ["s"] => string(0) "" ["sentence"] => string(0) "" ["title"] => string(0) "" ["fields"] => string(0) "" ["menu_order"] => string(0) "" ["category__in"] => array(0) { } ["category__not_in"] => array(0) { } ["category__and"] => array(0) { } ["post__in"] => array(0) { } ["post__not_in"] => array(0) { } ["post_name__in"] => array(0) { } ["tag__in"] => array(0) { } ["tag__not_in"] => array(0) { } ["tag__and"] => array(0) { } ["tag_slug__in"] => array(0) { } ["tag_slug__and"] => array(0) { } ["post_parent__in"] => array(0) { } ["post_parent__not_in"] => array(0) { } ["author__in"] => array(0) { } ["author__not_in"] => array(0) { } }It’s the exact same output when it’s working as expected.
Hi Hortons-art-
Shoot, it looks like the query arguments are correct. If you have access to your WP database, can you see if all three of those terms exist? They’ll be in
wp_terms; see if terms with those slugs are being created. (I’m wondering if maybe thebp_docs_access_user_1term isn’t being created before that user–with ID of 1–creates a doc, and that’s causing problems with your query on your setup. )(To clarify, that term shouldn’t exist unless the user has created a doc with the read access level set to “Doc author only”, but the query looks fine, so I’m not sure what’s interacting with it.)
I’m still wondering if the query is getting modified later on. Can you try another troubleshooting filter to see if anything else is hooked to
pre_get_posts?bp_docs_access_anyoneis the only term that is showing up in the wp_terms tablebp_access_loggedinandbp_docs_access_user_1aren’t listed in the tablebp_docs_access_user_2which is my admin user is showing up.The output of the filter you provided is:
array(2) { [10]=> array(2) { ["00000000485616f50000000045405f77filter_gallery_posts"] => array(2) { ["function"] => array(2) { [0] => object(BP_Docs_Attachments)#192 (4) { ["doc_id":protected] => NULL ["override_doc_id":protected] => NULL ["is_private":protected] => NULL ["htaccess_path":protected] => NULL } [1] => string(20) "filter_gallery_posts" } ["accepted_args"] => int(1) } ["00000000485616f50000000045405f77filter_directory_posts"] => array(2) { ["function"] => array(2) { [0] => object(BP_Docs_Attachments)#192 (4) { ["doc_id":protected] => NULL ["override_doc_id":protected] => NULL ["is_private":protected] => NULL ["htaccess_path":protected] => NULL } [1] => string(22) "filter_directory_posts" } ["accepted_args"] => int(1) } } [28] => array(1) { ["bp_docs_general_access_protection"] => array(2) { ["function"] => string(33) "bp_docs_general_access_protection" ["accepted_args"] => int(1) } } }Any update on this? I found another issue regarding private/hidden group activity as well, in regard to docs, that might help track this down? The Recent Comments dashboard widget is showing all comments from all group docs and forums regardless of group being private or hidden. I saw in the changelog that this was fixed in 1.1.8, but thought I should mention that it was showing up in my dashboard.
The Recent Comments dashboard widget is showing all comments from all group docs only. Forums are not affected.
I’m sorry to say that I don’t have any new good ideas about the parent doc dropdown menu issue. The troubleshooting you did produced the expected (correct) code, so I haven’t been able to narrow down the problem. I’ve tried several fresh installs and haven’t been able to recreate the problem you’re having. Can you give me more info on your installation? (Which version of WP, BP, BP Docs, PHP and anything else you think could be helpful.)
I am able to reproduce the comment visibility issue you mention–thanks for the report, I’ll create a new issue.
Hi horntons-art-
I think I have a solution to your problem.
Knowing that
WP_Queryhas sort of a strange behavior, where, if you pass it an emptypost__inparameter, it returns everything, I can imagine a similar case where your new user doesn’t have access to any docs, so theBP_Docs_Queryreturns an empty set of post IDs to include, this passes an emptyincludeparameter towp_dropdown_pageswhich internally usesget_pages()which apparently has the same problem asWP_Query. Totally obvious, right? 🙂So the fix is this: in the file
includes/templatetags-edit.phpin the functionbp_docs_edit_parent_dropdown()change the line that reads:$include = array();to
$include = array( 0 );Please let me know if that solves the parent drop down in your case. Thanks!
Brilliant! Adding this hides the drop-down menu all together if there are no docs that the user has access to. Once a document is available to the user the drop-down appears and lists correctly! Thanks for all your help David!
The topic ‘Parent for Doc Drop-down Showing all Docs’ is closed to new replies.