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

fix: authors and guest authors in homepage posts #1083

Merged
merged 7 commits into from
Mar 31, 2022

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Mar 30, 2022

All Submissions:

Changes proposed in this Pull Request:

This PR supersedes #1082. Testing instructions remain the same except for an additional testing step at the end (see bolded header below). 8ddcee8 is the only new commit in this branch vs #1082, if that helps with code review.

Fixes four bugs related to author querying:

  1. A SQL syntax error when filtering Homepage Posts blocks by authors and including at least one Co-Authors Plus guest author
  2. When filtering Homepage Posts blocks by CAP guest authors, posts by linked user accounts are not included in the results
  3. An unhandled include query param when fetching saved authors to display in the block sidebar controls
  4. When filtering by a WP user, posts that were created by that user but are attributed to an unrelated CAP guest author are also fetched

How to test the changes in this Pull Request:

SQL syntax error and linked accounts

  1. On master, add several Homepage Posts blocks to a post and filter them by a regular WP user, a guest author with no linked account, and a guest author with a linked account. For ease of testing, use the same authors in all blocks and add separators between block instances so you can easily see where one block ends and the next begins.
  2. Observe that the posts shown in the editor vs. the front-end are different, and that the front-end blocks in particular don't show all of the posts you would expect:
  • Likely only the first block instance will show any posts at all.
  • For the guest author with linked account, posts that are attributed to the linked account are not shown—only posts directly attributed to the guest author.
  • In the debug log, you'll probably see a SQL syntax error similar to this:
WordPress database error Not unique table/alias: 'wp_term_relationships' for query SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
  1. Check out this branch and refresh both editor and front-end. Confirm that both environments show all the posts you would expect and that the posts match in editor vs. front-end. Confirm that the issues outlined in step 4 no longer apply.

Saved authors in block sidebar controls

  1. Switch back to master and refresh the editor with your test blocks.
  2. Select one of the blocks and expand the "Display Settings" sidebar. Observe that in the Authors field, not all of the authors you had saved before are shown here.
  3. Check out this branch and refresh. Confirm that you now see all WP users and guest authors in the Authors field.

Unrelated CAP guest author posts

  1. Log in as a WP user and publish a brand new post, then assign an unrelated/unlinked CAP guest author to the post (removing the WP user from the authors UI).
  2. Switch back to master. In one of the test Homepage Posts blocks, filter by the WP user in step 1. Observe that in the editor and on the front-end, the block displays post(s) created by the WP user but assigned to unrelated guest authors.
  3. Check out this branch, refresh, confirm that the block only shows posts that are directly attributed to the WP user.

Posts Carousel block

No changes were made to the Posts Carousel block, but it uses some of the same query functions and endpoints, so we should test it in the editor and on the front-end to ensure it still behaves as expected.

NEW TEST CASE: subsequent non-author queries

8ddcee8 introduces a fix for an unsolved bug present in #1082. In that PR, any WP queries after the wpuser+coauthors queries would inherit the join and where clause filtering done by those queries, even if the filter callback is removed. This fix now simplifies the use of the posts_clauses filter callback and preemtively strips all custom join and where modifications before each query.

  1. On hotfix/author-query-in-homepage-posts, add two Homepage Posts blocks to a page: one with an author filter containing both WP users and CAP guest authors, and the other with no filters.
  2. On the front-end, observe that the second block renders no posts. This is because it's inheriting the clause filtering from the previous block.
  3. Check out this branch and confirm that all blocks render the expected posts.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo changed the title Fix/author query in homepage posts fix: authors and guest authors in homepage posts Mar 30, 2022
@dkoo dkoo requested review from miguelpeixe and kariae March 30, 2022 22:39
@dkoo dkoo self-assigned this Mar 30, 2022
@dkoo dkoo marked this pull request as ready for review March 30, 2022 22:40
@dkoo dkoo requested a review from a team as a code owner March 30, 2022 22:40
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the work done in 8ddcee8 👏

Also can confirm that it fixes the described bug of unwanted inherited query clauses!

Left a tiny nit below:

includes/class-newspack-blocks.php Show resolved Hide resolved
includes/class-newspack-blocks.php Outdated Show resolved Hide resolved
@dkoo dkoo requested a review from miguelpeixe March 31, 2022 16:28
Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@dkoo dkoo merged commit 038d9a4 into master Mar 31, 2022
@dkoo dkoo deleted the fix/author-query-in-homepage-posts branch March 31, 2022 17:05
matticbot pushed a commit that referenced this pull request Mar 31, 2022
# [1.47.0-alpha.1](v1.46.1...v1.47.0-alpha.1) (2022-03-31)

### Bug Fixes

* **author-list:** handle alphabetizing last names containing spaces ([#1057](#1057)) ([1af7e19](1af7e19))
* authors and guest authors in homepage posts ([#1083](#1083)) ([038d9a4](038d9a4))
* donate block non-default styles grid breakpoint ([#1078](#1078)) ([5450e57](5450e57))
* **homepage-posts:** post fetch for widget blocks ([#1066](#1066)) ([3734a3f](3734a3f))

### Features

* add alternate and minimal styles to donate block ([#1068](#1068)) ([3c914d2](3c914d2))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.47.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Apr 5, 2022
# [1.47.0](v1.46.1...v1.47.0) (2022-04-05)

### Bug Fixes

* **author-list:** handle alphabetizing last names containing spaces ([#1057](#1057)) ([1af7e19](1af7e19))
* authors and guest authors in homepage posts ([#1083](#1083)) ([038d9a4](038d9a4))
* donate block non-default styles grid breakpoint ([#1078](#1078)) ([5450e57](5450e57))
* **homepage-posts:** post fetch for widget blocks ([#1066](#1066)) ([3734a3f](3734a3f))
* incorrect nesting of tax_query args ([#1087](#1087)) ([a613874](a613874))

### Features

* add alternate and minimal styles to donate block ([#1068](#1068)) ([3c914d2](3c914d2))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.47.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants