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.

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
1 participant