Automattic / Co-Authors-Plus

Multiple bylines and Guest Authors for WordPress
https://wordpress.org/plugins/co-authors-plus/
GNU General Public License v2.0
291 stars 204 forks source link

Filter Ajax Suggested Authors #810

Open anthonythorne opened 3 years ago

anthonythorne commented 3 years ago

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 );
anthonythorne commented 3 years ago

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.

rebeccahum commented 3 years ago

Feel free to open a PR with the new filter.

anthonythorne commented 3 years ago

@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

rebeccahum commented 3 years ago

@anthonythorne Are you using a forked version of CAP for pushing the update?

anthonythorne commented 3 years ago

@rebeccahum Thanks for the hint.

Can you see and or access https://github.com/anthonythorne/Co-Authors-Plus/tree/update/%23810

rebeccahum commented 3 years ago

@anthonythorne What authentication error are you receiving?

Yes - I see that forked version.