Fix get_post_oembed_url_function for draft and schedule posts #7747
+76
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trac Ticket: Core-42733
Problem
The
get_post_embed_url()
function was failing to generate the correct embed URLs for draft and scheduled posts when pretty permalinks were enabled. The issue specifically occurred for these draft and scheduled posts, where the embed URLs were being generated incorrectly:When pretty permalinks were disabled, the function correctly generated embed URLs for draft and scheduled posts with the
?embed=true
query parameter (e.g., http://example.com/?p=8&embed=true), which is recognized as a valid embed URL by WordPress.When pretty permalinks were enabled, the function incorrectly generated URLs like http://example.com/?p=8/embed/ for draft and scheduled posts. These URLs were not recognized as embed URLs, causing the
is_embed()
check to fail (returning false instead of the expected true).This discrepancy occurred because
get_permalink()
does not return pretty permalinks for draft or scheduled posts. As a result, the embed URL logic was inconsistent for draft and scheduled posts, leading to test failures.Solution
get_post_embed_url()
has been updated to consistently generate correct embed URLs for all posts (published, draft, or scheduled), regardless of whether pretty permalinks are enabled.Key changes include
For Published Posts
When pretty permalinks are enabled, the embed URL now correctly ends with /embed/ (e.g., http://example.com/my-post/embed/), as expected.
If pretty permalinks are disabled, the function falls back to using the ?embed=true query parameter format (e.g., http://example.com/?p=8&embed=true).
For Draft and Scheduled Posts
Fallback Logic:
/embed/
path to avoid generating invalid URLs. In cases where the permalink structure conflicts, the function defaults to the query string format (?embed=true
).Benefits
Consistent URL Format: Ensures that embed URLs are correctly generated for all post statuses (published, draft, and scheduled), regardless of the permalink structure.
Correct Handling of Pretty Permalinks: Fixes the issue where pretty permalinks caused the function to generate invalid embed URLs for draft and scheduled posts. Now,
get_post_embed_url()
always returns a valid embed URL with the correct format.