Skip to content

No model for attachments in graphql_data_is_private #2481

Discussion options

You must be logged in to vote

Hey @maurocolella ,

As you noted, $data->post_type should show attachment.

Typically a Model describes how the data is shaped and not the content that is stored inside of it, and attachments are a WP_Post_Type hence the model name.

To distinguish attachments from other post types in graphql_data_is_private, you can do the following:

add_filter(
  'graphql_data_is_private',
  function( $is_private, $model_name, $data, $visibility, $owner, $current_user ) {
    if( 'PostObject' === $model_name && 'attachment' === $data->post_type ) {
      // return some check based on the $owner and $current_user
    }
    // For anything else..
    return $is_private;
  },
  10,
  6
);

Let us know if that…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jasonbahl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question Further information is requested Close Candidate Needs confirmation before closing has: solution A solution to this issue has been provided.
2 participants
Converted from issue

This discussion was converted from issue #2174 on August 17, 2022 21:14.