This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Set Organization posts to 'private' for unauthenticated users. | |
* | |
* @param boolean $is_private Whether the model is private | |
* @param string $model_name Name of the model the filter is currently being executed in | |
* @param mixed $data The un-modeled incoming data | |
* @param string|null $visibility The visibility that has currently been set for the data at this point | |
* @param null|int $owner The user ID for the owner of this piece of data | |
* @param WP_User $current_user The current user for the session | |
* | |
* @return bool Whether post should be considered private. | |
*/ | |
function set_organisation_posts_to_private(bool $is_private, string $model_name, $data, $visibility, $owner, WP_User $current_user) | |
{ | |
$is_organization_post_type = 'organisation' === get_post_type($data); | |
$is_user_authenticated = $current_user->ID !== 0; | |
if ($is_organization_post_type && !$is_user_authenticated) { | |
$is_private = true; | |
} | |
return $is_private; | |
} | |
add_filter('graphql_data_is_private', 'set_organisation_posts_to_private', 10, 6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment