From 96c50e488986e2bc7ebc2de1035d5ba7c19fd674 Mon Sep 17 00:00:00 2001 From: Zac Scott Date: Fri, 15 Jan 2021 15:56:16 +1000 Subject: [PATCH] add the filter to User::is_private() so users can choose to bypass or modify this functionality (relates to issue #961) --- src/Model/User.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Model/User.php b/src/Model/User.php index 42acaf403..34417b463 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -143,6 +143,26 @@ public function tear_down() { */ protected function is_private() { + /** + * Filter whether the user is private. + * + * If true, the user will be considered private without further checks. + * + * @param mixed|null|boolean $is_private If set, return without executing the manual query + * to see if the user has published posts. + * @param User $this Instance of the User Model + */ + $is_private = apply_filters( 'graphql_user_model_is_private', null, $this ); + + /** + * If the filter returns true, we can return now as the user is considered private. + * + * Otherwise we need to continue and check if the User should be considered private or not + */ + if ( null !== $is_private ) { + return (bool) $is_private; + } + if ( ! current_user_can( 'list_users' ) && false === $this->owner_matches_current_user() ) { /**