WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 6 years ago

Last modified 6 years ago

#15963 closed defect (bug) (fixed)

Don't try to add orphaned pages' parents' slugs to the page URL

Reported by: filosofo Owned by: DrewAPicture
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.1
Component: Posts, Post Types Keywords: has-patch needs-docs
Focuses: Cc:

Description

If a page becomes orphaned---in other words, if a page points to a parent object that doesn't exist any more---get_page_uri() doesn't sanity check that the parent object actually exists.

Patch does the check without any extra work, by moving stuff around.

Attachments (8)

avoid-notice-on-orphaned-pages.15963.diff (748 bytes) - added by filosofo 11 years ago.
15963.2.diff (429 bytes) - added by MikeHansenMe 9 years ago.
checks the status of the parent page before adding it to uri
15963.3.diff (438 bytes) - added by SergeyBiryukov 9 years ago.
Original patch, refreshed
15963.3.alt.diff (447 bytes) - added by SergeyBiryukov 9 years ago.
Same as 15963.2.diff, with proper formatting
15963.4.diff (491 bytes) - added by MikeHansenMe 6 years ago.
15963.4.2.diff (505 bytes) - added by chriscct7 6 years ago.
15963.5.diff (1.4 KB) - added by MikeHansenMe 6 years ago.
15963.filter.patch (423 bytes) - added by tanner m 6 years ago.

Download all attachments as: .zip

Change History (28)

@MikeHansenMe
9 years ago

checks the status of the parent page before adding it to uri

#1 @MikeHansenMe
9 years ago

  • Keywords needs-testing 2nd-opinion added

This seems to fix the problem in version (3.5-alpha-21751).

Code used to test:
<?php
$uri = get_page_uri(get_the_ID());
echo '<a href="'. $uri .'">The Page</a>';
?>
The output :
<a href="sample-page/thistoo">The Page</a>

My main concern is I was not using permalinks...
However the patch does show "thistoo" if I delete "Sample Page".

Last edited 9 years ago by MikeHansenMe (previous) (diff)

@SergeyBiryukov
9 years ago

Original patch, refreshed

@SergeyBiryukov
9 years ago

Same as 15963.2.diff, with proper formatting

#2 @MikeHansenMe
9 years ago

  • Cc mdhansen@… added

#3 @nacin
8 years ago

  • Component changed from General to Post Types

#4 @chriscct7
6 years ago

  • Keywords needs-refresh added; 3.2-early needs-testing 2nd-opinion removed
  • Milestone changed from Future Release to 4.4
  • Owner set to chriscct7
  • Status changed from new to assigned

@MikeHansenMe
6 years ago

#5 @MikeHansenMe
6 years ago

  • Keywords needs-refresh removed

@chriscct7
6 years ago

#6 @chriscct7
6 years ago

Careful there @MikeHansenMe with those string comparisons ;)

#7 @MikeHansenMe
6 years ago

looks like 15963.3.alt.diff also had that issue.. My bad. Nice catch!

This ticket was mentioned in Slack in #meta by chriscct7. View the logs.


6 years ago

#9 @wonderboymusic
6 years ago

  • Keywords needs-unit-tests added

@MikeHansenMe
6 years ago

#10 @MikeHansenMe
6 years ago

  • Keywords needs-unit-tests removed

15963.5.diff adds unit tests and updates the patch to be a bit simpler. Since it was referencing a post object anyway, we can avoid the call to get_post_status.

#11 @wonderboymusic
6 years ago

  • Owner changed from chriscct7 to wonderboymusic
  • Status changed from assigned to reviewing

#12 @wonderboymusic
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 34001:

In get_page_uri(), do not add parent slugs to orphaned pages.

Adds unit test.

Props filosofo, MikeHansenMe, MikeHansenMe, chriscct7.
Fixes #15963.

#13 @tanner m
6 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Hey guys! This patch is causing an issue for me as I have programmatically set private posts as parent. Can we add a filter to the output? I've included a patch.

#14 @wonderboymusic
6 years ago

  • Keywords needs-docs added

needs filter docs - up for grabs

#15 @DrewAPicture
6 years ago

  • Owner changed from wonderboymusic to DrewAPicture
  • Status changed from reopened to accepted

#16 @DrewAPicture
6 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 35510:

Pages: Introduce the get_page_uri filter, which makes it possible to manipulate a given page's URI before it's returned from the like-named get_page_uri().

Props tanner-m for the initial patch.
Fixes #15963.

#17 @tanner m
6 years ago

Awesome, thanks @DrewAPicture and @wonderboymusic!

This ticket was mentioned in Slack in #bbpress by tharsheblows. View the logs.


6 years ago

#19 @dd32
6 years ago

In 36094:

Pages: get_page_uri() should return the URI at which the resource being accessed is available at, this may include non-'publish' status posts.

Reverts [34001] and fixes the original issue in #15963 - avoiding a PHP Notice for when the post doesn't exist.

Props tharsheblows.
See #15963.
Fixes #35084.

#20 @dd32
6 years ago

In 36105:

Pages: get_page_uri() should return the URI at which the resource being accessed is available at, this may include non-'publish' status posts.

Reverts [34001] and fixes the original issue in #15963 - avoiding a PHP Notice for when the post doesn't exist.

Merges [36094] to the 4.4 branch.
Props tharsheblows.
See #15963.
Fixes #35084.

Note: See TracTickets for help on using tickets.