Make WordPress Core

Opened 12 years ago

Closed 9 years ago

Last modified 9 years ago

#24345 closed defect (bug) (fixed)

preview link for published posts does not apply the preview_post_link filter

Reported by: joeybvi's profile joeybvi Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: lowest
Severity: normal Version: 3.5.1
Component: Posts, Post Types Keywords:
Focuses: administration Cc:

Description

The "Preview Changes" button in the admin section (as created in wp-admin/includes/meta-boxes.php lines 40-49) does not apply the preview_post_link filter if the post has already been published (line 41).

The patch from #19378 ensures that the javascript that is called to open the preview link in a new tab/window DOES apply the preview_post_link filter, so if you click the link normally it will use the correct URL. However, hovering over the "Preview Changes" button shows the incorrect URL, and right-clicking the button and opening in a new tab/window opens the incorrect URL as well.

I have attached a patch that applies the preview_post_link filter to the link created for published posts.

Attachments (4)

24345.patch (585 bytes) - added by joeybvi 12 years ago.
preview.diff (10.9 KB) - added by TomHarrigan 10 years ago.
First pass at get_preview_post_link() function and consolidating 'preview_post_link' filter to single location.
24345.diff (9.6 KB) - added by wonderboymusic 9 years ago.
24345.2.diff (435 bytes) - added by kitchin 9 years ago.
Fix failing test: phpunit tests/phpunit/tests/admin/includesPost.php

Download all attachments as: .zip

Change History (30)

@joeybvi
12 years ago

#1 @SergeyBiryukov
12 years ago

  • Milestone changed from Awaiting Review to 3.6

#2 follow-up: @nacin
11 years ago

It seems like a few areas ignore the preview_post_link filter, including a bunch of messages in edit-form-advanced.php, wp_ajax_get_permalink(). At some point, we should have a get_preview_post_link( $post ) function to consolidate all of this.

Could this potentially break something? "Preview (Changes)" isn't just a link, it is a form POST, which is unlike most situations.

#3 follow-up: @nacin
11 years ago

  • Keywords 3.7-early added
  • Milestone changed from 3.6 to Future Release

After re-reading the bug report and talking briefly with danielbachhuber, this makes more sense. I will say though, part of the problem is that clicking this button submits a form (to a new window), so right clicking it and opening it in a new window is actually just "Preview", not previewing any unsaved "Changes".

This isn't a regression, and it's minor (since the button works normally, and degrades in functionality when you right-click anyway), so I'm moving this to 3.7. I would be interested in seeing a small plugin or snippet that uses the preview_post_link filter in an interesting way, because I can't say I've experienced the use case. I'm especially curious why, given a use case, there haven't been more tickets raised for the lack of preview_post_link filters in a few areas (like post updated messages as mentioned above)?

#4 @joeybvi
11 years ago

We use it, along with a few other filters, to help with having our admin interface in a different location from the front-end:

function fix_preview_link($link) {
        return str_replace('ADMIN_LOCATION', 'FRONT_END_LOCATION', $link);
}
add_filter('preview_post_link', 'fix_preview_link');

I do agree that the links in messages should be fixed as well. I'm surprised I haven't heard about this in our company yet. I will take a look at them when I get a few free minutes.

I'm not sure what the best thing to do about right-clicking and opening in a new window being "Preview without changes" is.

#5 @wonderboymusic
11 years ago

  • Milestone changed from Future Release to 3.7

these are all marked 3.7-early

#6 in reply to: ↑ 3 @aaroncampbell
11 years ago

Replying to nacin:

I would be interested in seeing a small plugin or snippet that uses the preview_post_link filter in an interesting way, because I can't say I've experienced the use case.

We've had to do this for a client or two that use WP as the back end of their site but use something else for displaying the front end. Having an accurate preview means using their front end software.

Currently it means using both the preview_post_link filter as well as some JS to override the links elsewhere. It's not a great solution, so having the preview_post_link filter put in use everywhere (possibly split into preview_post_link and preview_post_action?) would be really nice.

#7 in reply to: ↑ 2 @aaroncampbell
11 years ago

Replying to nacin:

It seems like a few areas ignore the preview_post_link filter, including a bunch of messages in edit-form-advanced.php, wp_ajax_get_permalink(). At some point, we should have a get_preview_post_link( $post ) function to consolidate all of this.

Looks like JJJ did this in http://core.trac.wordpress.org/attachment/ticket/24131/24131-post-preview.patch for #24131

#8 @nacin
11 years ago

  • Milestone changed from 3.7 to 3.8

A clean, simple patch that implements get_preview_post_link() and uses it everywhere gets a +1 and commit from me.

#9 @matt
11 years ago

  • Priority changed from normal to lowest
  • Severity changed from normal to minor

#10 @DrewAPicture
11 years ago

  • Keywords needs-patch 3.9-early added; has-patch needs-testing 3.7-early removed
  • Milestone changed from 3.8 to Future Release

Sounds like a get_preview_post_link() solution would be ideal. Too late for 3.8, though.

#11 @jeremyfelt
11 years ago

  • Component changed from Administration to Posts, Post Types
  • Focuses admin added

@TomHarrigan
10 years ago

First pass at get_preview_post_link() function and consolidating 'preview_post_link' filter to single location.

#12 @TomHarrigan
10 years ago

  • Keywords has-patch added; needs-patch removed

Went through and created get_preview_post_link() function and used it in (I believe) all areas where preview links are used. The 'preview_post_link' filter now only occurs inside that function, in the wp-includes/link-template.php file.

get_preview_post_link() accepts a required ID, optional array of query args, and an optional URL string. The third parameter was created to handle the case of _wp_link_page() for adding things like the pagination base and such when using <!--nextpage--> in a post, for example.

#14 @TomHarrigan
10 years ago

  • Keywords 3.9-early removed

This ticket was mentioned in IRC in #wordpress-dev by tomharrigan. View the logs.


10 years ago

@wonderboymusic
9 years ago

#16 @wonderboymusic
9 years ago

  • Milestone changed from Future Release to 4.4

TomHarrigan - take a look at 24345.diff, I refreshed and simplified where possible.

#17 follow-up: @wonderboymusic
9 years ago

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

In 34170:

Create a function, get_preview_post_link(), to DRY the logic for applying the 'preview_post_link' filter to a URL.

Props TomHarrigan, wonderboymusic.
Fixes #24345.

@kitchin
9 years ago

Fix failing test: phpunit tests/phpunit/tests/admin/includesPost.php

#18 @kitchin
9 years ago

  • Resolution fixed deleted
  • Severity changed from minor to normal
  • Status changed from closed to reopened

http://example.org/?p=248&#038;preview=1 should be
http://example.org/?p=248&#038;preview=true according to the test and previous behavior.

This ticket was mentioned in Slack in #core by kitchin. View the logs.


9 years ago

#20 @johnbillion
9 years ago

In 34175:

Correct the value of the preview query variable added by get_preview_post_link().

See #24345
Props kitchin

#21 @johnbillion
9 years ago

In 34176:

Improve the docblocks for the get_preview_post_link() function and the preview_post_link filter.

See #24345

#22 @paulwilde
9 years ago

[34170] didn't remove the references of the old filter "This filter is documented in wp-admin/includes/meta-boxes.php".

See line 1161 of wp-admin/includes/class-wp-posts-list-table.php and line 1322 of wp-admin/includes/post.php.

#23 @johnbillion
9 years ago

In 34178:

Remove outdated references to the preview_post_link filter docs.

See #24345
Props paulwilde

#24 @johnbillion
9 years ago

  • Keywords has-patch removed
  • Resolution set to fixed
  • Status changed from reopened to closed

#25 in reply to: ↑ 17 @dimadin
9 years ago

Replying to wonderboymusic:

You made mistake in [34170]. In changelog for preview_post_link filter, you changed version number of when second parameter $post was introduced, it was from 4.0.0, not 4.4.0.

#26 @DrewAPicture
9 years ago

In 34363:

Docs: The $post parameter has been passed to the preview_post_link since 4.0.0.

Fixes a version mixup introduced in [34170].

Props dimadin.
See #24345.

Note: See TracTickets for help on using tickets.