#24345 closed defect (bug) (fixed)
preview link for published posts does not apply the preview_post_link filter
Reported by: | joeybvi | Owned by: | 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)
Change History (30)
#3
follow-up:
↓ 6
@
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
@
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.
#6
in reply to:
↑ 3
@
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
@
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
@
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.
#10
@
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.
@
10 years ago
First pass at get_preview_post_link() function and consolidating 'preview_post_link' filter to single location.
#12
@
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.
This ticket was mentioned in IRC in #wordpress-dev by tomharrigan. View the logs.
10 years ago
#16
@
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:
↓ 25
@
9 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 34170:
#18
@
9 years ago
- Resolution fixed deleted
- Severity changed from minor to normal
- Status changed from closed to reopened
http://example.org/?p=248&preview=1
should be
http://example.org/?p=248&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
#22
@
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.
#24
@
9 years ago
- Keywords has-patch removed
- Resolution set to fixed
- Status changed from reopened to closed
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.