Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User connections hasPublishedPosts should not allow ATTACHMENT value #2963

Open
2 of 3 tasks
justlevine opened this issue Oct 7, 2023 · 0 comments
Open
2 of 3 tasks
Labels
Component: Connections Issues related to connections ObjectType: User Status: Discussion Requires a discussion to proceed Type: Bug Something isn't working

Comments

@justlevine
Copy link
Collaborator

Description

The UserConnectionWhereArgs.hasPublishedPosts is currently of type ContentTypeEnum, which offers ATTACHMENT as a possible value.

However, the underling has_published_posts query arg does not support filtering by attachment.

$query = new \WP_User_Query( [
  'has_published_posts' => 'attachment'
] );

error_log( print_r( $query->get_results() ) ); // will always return an empty array.

This is confirmed in our test suite (part of #2996) as well.

As a quick "fix", I recommend adding a graphql_debug() message alerting users to the bug.

Long term, I suggest we deprecate hasPublishedPosts in favor of something like hasPublishedContent, which uses an enum type that doesnt include attachments.

Steps to reproduce

  1. Create an attachment for a specific user and post:
$attachment_id = wp_insert_attachment(
	[
		'post_author' => $user_id,
		'post_type'   => 'attachment',
		'post_status' => 'inherit',
		'post_title'  => 'Test attachment for PostTypeQueryForMedia',
		'post_parent' => $post_id,
	]
);
  1. Query for users with hasPublishedPosts: ATTACHMENT:
query {
  users ( where: { hasPublishedPosts: ATTACHMENT } ) {
    nodes {
      databaseId
    }
  }
}
  1. Confirm no users are returned.

Additional context

I didnt create a PR to deprecate hasPublishedPosts and create hasPublishedContent because I'm thinking that a "sans-attachment" enum is likely necessary/useful in other parts of the codebase 🤔

WPGraphQL Version

1.16.0

WordPress Version

6.3.1

PHP Version

8.1.15

Additional environment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Connections Issues related to connections ObjectType: User Status: Discussion Requires a discussion to proceed Type: Bug Something isn't working
Projects
Status: 💬 In Discussion
Development

No branches or pull requests

1 participant