Skip to content

Commit

Permalink
Merge pull request #35 from ethanclevenger91/handle-query-string
Browse files Browse the repository at this point in the history
Handle query strings on URL import.
  • Loading branch information
danielbachhuber committed Aug 16, 2017
2 parents 4a19de5 + db6a9a9 commit 3b3b817
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions features/media-import.feature
Expand Up @@ -14,6 +14,17 @@ Feature: Manage WordPress attachments
Success: Imported 1 of 1 items.
"""

Scenario: Import media from remote URL with query string
When I run `wp media import 'http://via.placeholder.com/350x150.jpg?text=Foo'`
Then STDOUT should contain:
"""
Imported file 'http://via.placeholder.com/350x150.jpg?text=Foo' as attachment ID
"""
And STDOUT should contain:
"""
Success: Imported 1 of 1 items.
"""

Scenario: Fail to import missing image
When I try `wp media import gobbledygook.png`
Then STDERR should be:
Expand Down
4 changes: 3 additions & 1 deletion src/Media_Command.php
Expand Up @@ -250,6 +250,7 @@ function import( $args, $assoc_args = array() ) {
} else {
$tempfile = $this->make_copy( $file );
}
$name = Utils\basename( $file );
} else {
$tempfile = download_url( $file );
if ( is_wp_error( $tempfile ) ) {
Expand All @@ -260,11 +261,12 @@ function import( $args, $assoc_args = array() ) {
$errors++;
continue;
}
$name = strtok( Utils\basename( $file ), '?' );
}

$file_array = array(
'tmp_name' => $tempfile,
'name' => Utils\basename( $file )
'name' => $name,
);

$post_array= array(
Expand Down

0 comments on commit 3b3b817

Please sign in to comment.