Skip to content

Enhance attachment handling: Use attachment file URL when the pages are disabled#11772

Open
shreyasikhar wants to merge 3 commits intoWordPress:trunkfrom
shreyasikhar:ticket/65169
Open

Enhance attachment handling: Use attachment file URL when the pages are disabled#11772
shreyasikhar wants to merge 3 commits intoWordPress:trunkfrom
shreyasikhar:ticket/65169

Conversation

@shreyasikhar
Copy link
Copy Markdown

@shreyasikhar shreyasikhar commented May 8, 2026

Summary

This PR makes WordPress consistently respect the wp_attachment_pages_enabled option 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

  • In get_sample_permalink_html() (wp-admin permalink UI), when:
    • the post type is attachment, and
    • wp_attachment_pages_enabled is disabled,
  • the “View” link now uses wp_get_attachment_url() instead of get_permalink().

2) Media templates: Hide “Attachment Page” link options when disabled

  • In wp_print_media_templates():
    • “Attachment Page” options are only rendered when wp_attachment_pages_enabled is enabled.
    • Gallery default/selection behavior is adjusted so that when attachment pages are disabled, “Media File” is treated as the default and “Attachment Page” is not offered.

3) Settings: Provide a UI toggle for wp_attachment_pages_enabled

  • Adds an “Attachment pages” section to Settings → Media (options-media.php) with a checkbox:
    • “Enable attachment pages for uploaded media files”
    • Description clarifies that when disabled, attachment page URLs redirect to the media file URL.
  • Registers the option in options.php so it’s saved via the Settings API.
image

4) Tests

  • Adds a PHPUnit test to verify get_sample_permalink_html() uses the attachment file URL when attachment pages are disabled.
  • Adds PHPUnit tests to confirm wp_print_media_templates() hides attachment-page link options when disabled and shows them when enabled.
  • Includes a small test reference update related to the ticket.

Behavior impact

  • User-facing: prevents generating/showing links to attachment pages when that feature is disabled, aligning UI output with site configuration.
  • Scope: admin permalink “View” link for attachments, media templates link options, Media Settings UI + option registration, and test coverage.

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_enabled and drafting the corresponding code/test updates.

shreyasikhar and others added 2 commits May 8, 2026 15:36
…isabled and update media templates accordingly.

Co-authored-by: Copilot <copilot@github.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props shreyasikhar26.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant