Opened 10 years ago
Last modified 10 years ago
#39850 new enhancement
WordPress embedded links drop query vars from URL
| Reported by: | charleslf | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Embeds | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description (last modified by )
When embedding a WordPress page within another post, any query strings that are passed in the URL get dropped.
For example, if embedding http://example.com/page-name/?foo=bar, the actual URL that gets passed to the oEmbed function (and later on to the template files) is http://example.com/page-name/embed/ (foo=bar gets dropped).
The link inside the blockquote also drops the url query variable and links to http://example.com/page-name/ instead of http://example.com/page-name/?foo=bar
As I see, this occurs because the wp_filter_pre_oembed_result function in embed.php uses url_to_postid to get the embeded post's ID, and later get_post_embed_url uses that ID to create the embed permalink. So naturally any url query vars are not preserved in the final URL construction.
Similarly in get_post_embed_html, the function uses esc_url( get_permalink( $post ) ), thus reconstructing the permalink without knowledge of the initial url.
I encountered this when embedded a specific photo gallery (from nextcellent plugin), but I assume some other plugins such as language/translation ones may also be affected.
I don't think the URL's should be dropping any of the query variables.
However, if that is a requirement, it would be good to also pass on the original url in the post_embed_url hook to allow plugin developers to make sure to add any parameters from the original url that got dropped off in the embedded url.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Previous discussion on Slack about this: https://wordpress.slack.com/archives/core/p1486845896008270
Passing the request URL to the
post_embed_urlfilter would mean adding it to theget_post_embed_html()function and all functions using it, i.e.print_embed_sharing_dialog(),get_oembed_response_data_rich(),wp_filter_pre_oembed_result(). At a quick glance, it seems doable, but it would also make everything more complex.My proposed (untested) workaround on Slack: