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 get_default_page_id_by_type #205

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Fix get_default_page_id_by_type #205

wants to merge 2 commits into from

Conversation

ilicfilip
Copy link
Collaborator

Context

Recently we added a feature which should pre-select page for the page type in the "Your Pages" section on the Settings page. It works by searching through existing pages' titles, any found matches for specific page type are compared to matches found for other page types and any overlapping results are excluded. What is left is returned as a suggestion.

There is a bug there, which @tacoverdo described in #201 and I believe it was introduced when then feature was refactored.

I think that $posts here shouldn't be always set to contact pages and return empty( $posts ) ? 0 : $posts[0]; (on line 332) will execute after the first loop iteration (which means other page types wont be checked).

I refactored get_default_page_id_by_type to be simpler and to me it looks like it does the same thing, but I will need another pair of eyes since I didn't implement this and I might be wrong.

Also I changed homepage subarray to be just home page ID, instead of the WP_Post object, to be consistent with the others. As far I saw it doesnt have to be an object and it might be set to it because in initial implementation Post objects were used for other subarrays as well (but then we changed it so get_posts_by_title method returns just IDs to be lighter).

Summary

This PR can be summarized in the following changelog entry:

Fixes suggested pages for "Your pages" section on Settings page.

Quality assurance

  • I have tested this code to the best of my abilities.
  • I have added unit tests to verify the code works as intended.
  • I have checked that the base branch is correctly set.

Fixes #201

Copy link
Contributor

Test on Playground
Test this pull request on the Playground or download the zip.

@ilicfilip ilicfilip requested a review from aristath December 30, 2024 07:11
@jdevalk
Copy link
Member

jdevalk commented Jan 6, 2025

Should I see a change in behavior here on Playground @ilicfilip ?

Maybe @tacoverdo you can look at this one as well?

@ilicfilip
Copy link
Collaborator Author

The thing here is that bug depends on the existing pages, since we search through them to detect best suggestions, so I dont think this can be replicated on Playground.

I can double check with @tacoverdo, for example apply the fix on his site directly, but the best would be that @aristath takes a look at it as well since he initially implemented this feature.

@jdevalk
Copy link
Member

jdevalk commented Jan 6, 2025

Ok I'll wait on @aristath to review this one!

@tacoverdo
Copy link

I can replicate the behavior as follows on Playground:

  • Start playground via the link above
  • Create a page called 'contact'.
  • Go to the PP settings.
  • Try to change the setting for 'contact page' from "I have this page" to "I don't have this page yet"
  • Click Save

For me, it still jumps back to "I have this page".

@ilicfilip
Copy link
Collaborator Author

Checking, but that might be kind of what we want - to suggest a page to a user if selection wasn't made previously.

The actual bug which was fixed, and it was more obvious in your initial issue, is that suggestions were wrong. In your video you were seeing the issue on the FAQ page, but the page which was suggested was "Contact" page (which shouldn't be suggested in that context at all).

@ilicfilip
Copy link
Collaborator Author

@tacoverdo , what I said above is correct - that is the way we offer a suggestion to a user when we hasn't selected a page previously or marked it as "My site doesn't need this page".

What would we like to do here, to suggest a page (and make selections) only when user loads the settings page for the first time? If pages are pre-selected, is it clear that user needs to be save the Settings page in order for selection to take an effect?

@jdevalk jdevalk added this to the 1.0.3 milestone Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switching to "I don't have this page" on the settings page doesn't properly save the setting
3 participants