feat: add filter for customizable post statuses using plain permalinks #9247
+179
−1
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.
Allow Customization of Post Statuses That Use Plain Permalinks
Overview
This pull request introduces a new filter
wp_force_plain_post_permalink_statuses
that allows developers to customize which post statuses should use plain permalinks (e.g.,/?p=123
) instead of pretty permalinks (e.g.,/my-post-title/
).This addresses the long-standing issue where scheduled posts show inconsistent permalink formats - pretty permalinks in the admin interface but plain permalinks in theme templates and functions like
the_permalink()
.Trac Ticket: #32322
Issue Fixed
Scheduled Posts Show Inconsistent Permalink Formats
Problem:
Scheduled posts (status =
future
) display different permalink formats in different contexts:/my-scheduled-post/
)/?p=123
)Root Cause:
The
wp_force_plain_post_permalink()
function treats allprotected
post statuses (includingfuture
) as requiring plain permalinks for security, but this creates user confusion since scheduled posts are meant to be public eventually.Solution:
Introduced a filterable array of post statuses that should use plain permalinks, allowing developers to customize this behavior on a per-site basis while maintaining security for truly sensitive content.
Code Changes
New Filter Implementation
Updated Logic
Usage Examples
Basic: Allow Scheduled Posts Pretty Permalinks
Advanced: Selective by Post Type
Conditional by User Capability
Testing Instructions
Test Case 1: Default Behavior (Unchanged)
the_permalink()
in a theme template - should show plain permalinkTest Case 2: Enable Pretty Permalinks for Future Posts
the_permalink()
in a theme template/my-scheduled-post/
)Test Case 3: Selective Application
Test Case 4: Security Maintained
Test Case 5: Direct Access