Make WordPress Core

Opened 2 years ago

Closed 19 months ago

Last modified 19 months ago

#54736 closed defect (bug) (fixed)

get_sample_permalink unsets $post->filter even though this is a public property.

Reported by: herregroen's profile herregroen Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.1 Priority: normal
Severity: normal Version: 2.7.1
Component: Posts, Post Types Keywords: has-patch needs-unit-tests
Focuses: Cc:

Description

The property should be set to null rather than being unset.

Unsetting it removes it entirely which means if it's later requested ( such as in WP_Post::__get ) this causes a notice to be thrown that the property doesn't exist.

Attachments (2)

get_sample_permalink_post_filter_null.patch (486 bytes) - added by herregroen 2 years ago.
get_sample_permalink_post_filter_original.patch (944 bytes) - added by herregroen 2 years ago.

Download all attachments as: .zip

Change History (15)

#1 @herregroen
2 years ago

Added an alternative patch which restores the original filter.

#2 @hellofromTonya
2 years ago

  • Component changed from General to Posts, Post Types
  • Keywords has-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to 6.0
  • Version changed from trunk to 2.7.1

Hello @herregroen,

Welcome back to WordPress Core's Trac! Thanks for opening this ticket :)

The unset( $post->filter ) was introduced in #8526 [10213].

Here's an example in action https://3v4l.org/66Nvl.

  • In < PHP 8, it throws a Notice: Undefined property: WP_Post::$filter.
  • In PHP 8, it throws a Warning: Undefined property: WP_Post::$filter.

Moving this ticket into 6.0.

#3 @hellofromTonya
2 years ago

#54735 was marked as a duplicate.

This ticket was mentioned in Slack in #core-test by hellofromtonya. View the logs.


2 years ago

#5 @hellofromTonya
2 years ago

  • Owner set to hellofromTonya
  • Status changed from new to assigned

Assigning to me for review and unit tests.

#7 @peterwilsoncc
2 years ago

I've created an initial patch in the linked pull request:

  • The original filter value is stored early in the function
  • This value is then restored after been replaced with sample

In [53042] it was ensured that the filter was always set in post objects, this is why I am restoring it rather than nulling it.

No tests at present but feel free to push them to the branch on my repo.

#8 @niravsherasiya7707
2 years ago

Hello @peterwilsoncc & @hellofromTonya can I start writing PHPUnit test for the changes made on this PR(https://github.com/WordPress/wordpress-develop/pull/2626).

#9 @hellofromTonya
2 years ago

  • Milestone changed from 6.0 to 6.1

With 6.0 RC1 tomorrow and this issue not introduced in the 6.0 cycle, moving this ticket and ongoing work to 6.1.

#10 @ironprogrammer
20 months ago

@niravsherasiya7707: Absolutely! As Peter mentioned, you could submit unit tests through a PR to Peter's branch, or fork PR 2626 directly and add the tests to your own branch.

Props will pick up Peter's original PR, but if you end up forking the original, it's always nice to mention where it started 🙌🏻

#11 @Rahmohn
20 months ago

@peterwilsoncc I've created a PR adding tests: https://github.com/peterwilsoncc/wordpress-develop/pull/9

Other than that, it's necessary to fix a typo

#12 @peterwilsoncc
19 months ago

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

In 54244:

Posts, Post types: Prevent get_sample_permalink() modifying the post object.

get_sample_permalink() (ab)uses the $post->filter property to indicate a sample permalink is being generated for the post. This change ensures the property is restored to its original value.

Props herregroen, hellofromTonya, peterwilsoncc, Rahmohn, costdev.
Fixes #54736.

Note: See TracTickets for help on using tickets.