Co-Authors-Plus
Co-Authors-Plus copied to clipboard
Filter Ajax Suggested Authors
Due to the requirements of a project that I am working on, the authors need to be filtered in a more complex manner than coauthors_search_authors_get_terms_args
can offer.
While coauthors_edit_ignored_authors
would not be feasible to add 100,000s of user ids.
The requirement is to both check the logged-in user's meta and role, and then the coauthors. This would be easily achieved with a filter within the coauthors plugin either as below in the search_authors
method or within the ajax_suggest
method.
In respect to version 3.4.8
In file co-authors-plus.php
for method search_authors()
and before the return statement return (array) $found_users;
Adding a final filter for the returned coauthors.
Something like;
/**
* Filter: coauthors_search_authors_found_users
* Filters the found users array. Allowing for final additional checks such as current
* logged-in user, meta, roles, and capabilities in comparison to those of the found users.
*
* @param array $found_users The found authors.
*/
$found_users = apply_filters( 'coauthors_search_authors_found_users', $found_users );
My current workaround is to deregister your admin-ajax method for ajax_suggest and run a copied version with the updated code. However, this doesn't work if your plugin updates the return format which it did recently.
Feel free to open a PR with the new filter.
@rebeccahum do you have a document that I may have missed in regards to procedures, branch names, etc for opening a PR?
I created the branch update/#810
and I receive the authentication error when trying to push. Obviously, I am missing a process.
Thanks
@anthonythorne Are you using a forked version of CAP for pushing the update?
@rebeccahum Thanks for the hint.
Can you see and or access https://github.com/anthonythorne/Co-Authors-Plus/tree/update/%23810
@anthonythorne What authentication error are you receiving?
Yes - I see that forked version.