Skip to content

Add STDIN support to wp media import#221

Merged
swissspidy merged 14 commits intomainfrom
copilot/add-stdin-support-to-media-import
Mar 21, 2026
Merged

Add STDIN support to wp media import#221
swissspidy merged 14 commits intomainfrom
copilot/add-stdin-support-to-media-import

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

Plan: Add STDIN support to wp media import

  • Understand current implementation
  • Implement STDIN support
  • Add tests
  • Validate implementation
  • Address test failures
    • Fix file type detection using mime_content_type()
    • Add check for empty STDIN content
    • Map MIME types to proper file extensions
    • Fix test to use --field=post_name instead of --field=name
    • Fix title generation for STDIN imports to use filename instead of '-'
    • Fix double extension issue when user provides extension in --file_name
    • Stream STDIN directly to temp file to avoid memory issues
    • Update test expectations after fixing double extension bug

Latest Fix

Updated test expectations to match the corrected behavior after fixing the double extension bug.

Before the double extension fix:

  • Filename: my-image.png.png (buggy)
  • Title: my-image.png (extension stripped from filename)
  • post_name: my-image-png (WordPress sanitizes dots to hyphens)

After the double extension fix:

  • Filename: my-image.png (correct)
  • Title: my-image (extension stripped from filename)
  • post_name: my-image (no dots to sanitize)

The test was written to match the buggy behavior, so it needed to be updated to expect the correct post_name of my-image instead of my-image-png.

Original prompt

This section details on the original issue you should resolve

<issue_title>wp media import to be able to import from STDIN</issue_title>
<issue_description>For example:

$ curl http://example.com/large-file.png | wp media import -

Related:
wp-cli/entity-command#96</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 14, 2026 21:38
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for importing media from STDIN Add STDIN support to wp media import Feb 14, 2026
Copilot AI requested a review from swissspidy February 14, 2026 21:42
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 84.84848% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Media_Command.php 84.84% 10 Missing ⚠️

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy marked this pull request as ready for review March 21, 2026 06:22
@swissspidy swissspidy requested a review from a team as a code owner March 21, 2026 06:22
Copilot AI review requested due to automatic review settings March 21, 2026 06:22

This comment was marked as resolved.

swissspidy and others added 2 commits March 21, 2026 08:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy swissspidy merged commit 02cb9ec into main Mar 21, 2026
60 checks passed
@swissspidy swissspidy deleted the copilot/add-stdin-support-to-media-import branch March 21, 2026 18:05
@swissspidy swissspidy added this to the 2.2.7 milestone Mar 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:media-import Related to 'media import' command scope:distribution Related to distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp media import to be able to import from STDIN

3 participants