feat: add filter for customizable post statuses using plain permalinks#9247
feat: add filter for customizable post statuses using plain permalinks#9247kushagra-goyal-14 wants to merge 4 commits intoWordPress:trunkfrom
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
ecafa53 to
62505d3
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Allow Customization of Post Statuses That Use Plain Permalinks
Overview
This pull request introduces a new filter
wp_force_plain_post_permalink_statusesthat 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 allprotectedpost 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