WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#18674 closed defect (bug) (fixed)

Filter in adjacent_post_link is broken

Reported by: Otto42 Owned by:
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.2.1
Component: Permalinks Keywords: has-patch
Focuses: Cc:

Description

A filter in the adjacent_post_link function looks like this:

$adjacent = $previous ? 'previous' : 'next';
echo apply_filters( "{$adjacent}_post_link", $format, $link );

The intent here seems fairly clear, in that the $format and $link variables are arguments to the original function call.

However, the function itself overwrites both of those variables before it ever gets there. The result is that both $format and $link are useless by this point, and so you can't create a different link with the same format as the original call wanted. All you can do is to replace it entirely, without knowing what format was wanted.

So as it stands, these arguments to the filter are more than a little useless.

To fix this, adjacent_post_link shouldn't overwrite its own arguments here, so it can pass the information further on to the filter. Furthermore, the filter itself should be an actual filter, passing the $format and $link as second and third arguments to the function.

Patch upcoming.

Attachments (1)

18764.patch (1.7 KB) - added by Otto42 4 years ago.

Download all attachments as: .zip

Change History (7)

@Otto424 years ago

comment:1 @solarissmoke4 years ago

  • Keywords has-patch added

comment:2 @nacin4 years ago

I would rather leave this broken which will make it easier to overhaul the code in #17807.

comment:3 @Otto424 years ago

The two are not incompatible. #17807 can be fixed while also correcting the filter.

The existing filter, as it stands, is totally useless. At minimum, a differently named filter needs to be introduced so that code can correctly override the output of the function.

comment:4 @nacin4 years ago

Ah, this is the output filter. Alright.

comment:5 @nacin3 years ago

  • Milestone changed from Awaiting Review to 3.5

Let's handle this with #19640.

comment:6 @ryan3 years ago

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.