Skip to:
Content

BuddyPress.org

Opened 4 months ago

Closed 3 months ago

#9086 closed defect (bug) (fixed)

Filter on `wp_unique_post_slug` issue

Reported by: ahegyes's profile ahegyes Owned by: imath's profile imath
Milestone: 12.4.0 Priority: normal
Severity: normal Version: 12.0.0
Component: Core Keywords: has-patch has-unit-tests commit
Cc:

Description

Hello!

Version 12.0.0 introduced a new filter function called bp_core_set_unique_directory_page_slug attached to the filter wp_unique_post_slug.

My understanding is that the function wants to avoid any duplicate post_name entries across the post types buddypress and page. However, it seems to fail in doing that and causes issues in certain cases.

For example, it tries to accomplish its goal by first querying a list of posts of type buddypress and page (https://github.com/buddypress/buddypress/blob/b5f1c43598581173edb3cbd2686ae075f912ae87/src/bp-core/bp-core-functions.php#L1002-L1008). However, since it doesn't use the limit or numberposts argument, only the top 5 posts will be returned instead of all of them.

Moreover, it doesn't handle hiearchies properly. Normally, pages are allowed to have the same post_name as long as they have different parents. However, this function doesn't take that into account.

In my scenario, I tried adding a page named Program as child of page B. However, this function's get_posts included another page named Program which is a child of page A. WordPress allows this, but this function changed the slug to program-2 for the child of B because the child of A happened to be amongst those 5 queried posts.

Change History (9)

#1 @imath
4 months ago

  • Milestone changed from Awaiting Review to 12.3.0
  • Version changed from 12.2.0 to 12.0.0

Thanks for your report. I'll look at it asap.

#2 @imath
4 months ago

  • Milestone changed from 12.3.0 to 12.4.0

This ticket was mentioned in PR #256 on buddypress/buddypress by imath.


3 months ago
#3

  • Keywords has-patch has-unit-tests added

This PR also improves how Slug check is performed only requesting for pages / BuddyPress directories potentially having the same post_name and not being a child of another item.

Trac ticket: https://buddypress.trac.wordpress.org/ticket/9086

#4 @imath
3 months ago

Hi @ahegyes

I believe the above PR is fixing the issue, can you confirm?
Thanks in advance.

This ticket was mentioned in Slack in #buddypress by emaralive. View the logs.


3 months ago

#6 @emaralive
3 months ago

@imath, tested under the following conditions:

Without PR #256:

  1. Created page A, slug = a
  2. Created page Program as child of page A, slug = program
  3. Created page B, slug = b
  4. Created page Program as child of page B, slug = program-2

With PR #256:

  1. Created page A, slug = a
  2. Created page Program as child of page A, slug = program
  3. Created page B, slug = b
  4. Created page Program as child of page B, slug = program

Conclusion:
PR #256 provides a remedy for the reported issue.

#7 @imath
3 months ago

  • Keywords commit added

Hi @emaralive

Thanks a billion for your tests and confirmation ❤️. I'll commit the PR shortly and we'll respect our plan about packaging a 12.4.0 release tomorrow 🤝

#8 @imath
3 months ago

In 13777:

Improve the page / buddypress post types slugs unicity checks

To avoid slug conflicts between the page & buddypress post types as both URI Schemas put their slugs right after the site domain, 12.0.0 introduced a filter to extend the WordPress built-in check performed by wp_unique_post_slug().

This filter needed to be improve to :

  • make sure to allow WordPress sub-pages to have the same slugs than the BP Directory ones as in this case the URI Schemas puts the parent page slug before the sub-page one.
  • only request the page or buddypress post types having the same post_name than the page or buddypress post type being inserted.

Props ahegyes, emaralive

See #9086 (trunk)
Closes https://github.com/buddypress/buddypress/pull/256

#9 @imath
3 months ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 13778:

Improve the page / buddypress post types slugs unicity checks

To avoid slug conflicts between the page & buddypress post types as both URI Schemas put their slugs right after the site domain, 12.0.0 introduced a filter to extend the WordPress built-in check performed by wp_unique_post_slug().

This filter needed to be improve to :

  • make sure to allow WordPress sub-pages to have the same slugs than the BP Directory ones as in this case the URI Schemas puts the parent page slug before the sub-page one.
  • only request the page or buddypress post types having the same post_name than the page or buddypress post type being inserted.

Props ahegyes, emaralive

Fixes #9086 (branch 12.0)

Note: See TracTickets for help on using tickets.