Enhance attachment handling: Use attachment file URL when the pages are disabled#11772
Enhance attachment handling: Use attachment file URL when the pages are disabled#11772shreyasikhar wants to merge 3 commits intoWordPress:trunkfrom
Conversation
…isabled and update media templates accordingly. Co-authored-by: Copilot <copilot@github.com>
|
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. |
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. |
Summary
This PR makes WordPress consistently respect the
wp_attachment_pages_enabledoption across core UI surfaces. When attachment pages are disabled, attachment “View” links and media UI no longer surface attachment-page URLs; instead they point to (or default to) the underlying media file URL. It also introduces a Media Settings toggle for the option and adds/updates PHPUnit coverage for both enabled and disabled states.Trac ticket: https://core.trac.wordpress.org/ticket/65169
What’s changed
1) Admin: Attachment “View” link respects disabled attachment pages
get_sample_permalink_html()(wp-admin permalink UI), when:attachment, andwp_attachment_pages_enabledis disabled,wp_get_attachment_url()instead ofget_permalink().2) Media templates: Hide “Attachment Page” link options when disabled
wp_print_media_templates():wp_attachment_pages_enabledis enabled.3) Settings: Provide a UI toggle for
wp_attachment_pages_enabledoptions-media.php) with a checkbox:options.phpso it’s saved via the Settings API.4) Tests
get_sample_permalink_html()uses the attachment file URL when attachment pages are disabled.wp_print_media_templates()hides attachment-page link options when disabled and shows them when enabled.Behavior impact
Use of AI Tools
AI assistance: Yes
Tool(s): GitHub Copilot
Model(s): GPT-5.1
Used for: Identifying relevant locations to respect
wp_attachment_pages_enabledand drafting the corresponding code/test updates.