OSDN Git Service

Rename arguments to make more logical sense
authorgoldenapples <goldenapplesdesign@gmail.com>
Thu, 28 Mar 2013 17:21:07 +0000 (10:21 -0700)
committergoldenapples <goldenapplesdesign@gmail.com>
Thu, 25 Apr 2013 19:43:30 +0000 (12:43 -0700)
Use the same field labels as are used by the admin media uploader, to
avoid confusion: title / caption / alt / description; rather than the
variable names used internally, where 'description' is really title and
so on.

man-src/media-import.txt
man/media-import.1
php/commands/media.php

index d619298..e937ada 100644 (file)
@@ -6,17 +6,33 @@
        If file is recognized as a URL (for example, with a scheme of http or ftp), the file will be 
        downloaded to a temp file before being sideloaded.
 
-* `--post-id=<post_id>`
+* `--post_id=<post_id>`
 
-       ID of the post to attach the imported files to.
+       ID of the post to attach the imported files to
+
+* `--title=<title>`
+
+       Attachment title (post title field)
+
+* `--caption=<caption>`
+
+       Caption for attachent (post excerpt field)
+
+* `--alt=<alt_text>`
+
+       Alt text for image (saved as post meta)
 
 * `--desc=<description>`
 
-       "Description" field (post title) of attachment post
+       "Description" field (post content) of attachment post
 
 
 ## EXAMPLES
 
        wp media import ~/Pictures/**/*.jpg
 
-       wp media import ~/Downloads/image.png --post_id=123 --desc="A downloaded picture"
+       wp media import ~/Downloads/image.png --post_id=123 --title="A downloaded picture"
+
+       wp media import http://s.wordpress.org/style/images/wp-header-logo.png --title='The WordPress logo' --alt="Semantic personal publishing"
+
+
index 9bce04b..0af6e24 100644 (file)
@@ -4,10 +4,10 @@
 .TH "WP\-MEDIA\-IMPORT" "1" "" "WP-CLI"
 .
 .SH "NAME"
-\fBwp\-media\-import\fR \- Sideload images from file(s) and import as attachments, optionally attached to a post
+\fBwp\-media\-import\fR \- Sideload images from local file(s) or URL and import as attachments, optionally attached to a post
 .
 .SH "SYNOPSIS"
-wp media import \fIfile\fR\.\.\. [\-\-post_id=\fIpost_id\fR] [\-\-desc=\fIdescription\fR]
+wp media import \fIfile\fR\.\.\. [\-\-post_id=\fIpost_id\fR] [\-\-title=\fItitle\fR] [\-\-caption=\fIcaption\fR] [\-\-alt=\fIalt_text\fR] [\-\-desc=\fIdescription\fR]
 .
 .SH "OPTIONS"
 .
@@ -18,16 +18,34 @@ wp media import \fIfile\fR\.\.\. [\-\-post_id=\fIpost_id\fR] [\-\-desc=\fIdescri
 Path to file or files to be imported\. Supports the glob(3) capabilities of the current shell\. If file is recognized as a URL (for example, with a scheme of http or ftp), the file will be downloaded to a temp file before being sideloaded\.
 .
 .IP "\(bu" 4
-\fB\-\-post\-id=<post_id>\fR
+\fB\-\-post_id=<post_id>\fR
 .
 .IP
-ID of the post to attach the imported files to\.
+ID of the post to attach the imported files to
+.
+.IP "\(bu" 4
+\fB\-\-title=<title>\fR
+.
+.IP
+Attachment title (post title field)
+.
+.IP "\(bu" 4
+\fB\-\-caption=<caption>\fR
+.
+.IP
+Caption for attachent (post excerpt field)
+.
+.IP "\(bu" 4
+\fB\-\-alt=<alt_text>\fR
+.
+.IP
+Alt text for image (saved as post meta)
 .
 .IP "\(bu" 4
 \fB\-\-desc=<description>\fR
 .
 .IP
-"Description" field (post title) of attachment post
+"Description" field (post content) of attachment post
 .
 .IP "" 0
 .
@@ -37,7 +55,9 @@ ID of the post to attach the imported files to\.
 
 wp media import ~/Pictures/**/*\.jpg
 
-wp media import ~/Downloads/image\.png \-\-post_id=123 \-\-desc="A downloaded picture"
+wp media import ~/Downloads/image\.png \-\-post_id=123 \-\-title="A downloaded picture"
+
+wp media import http://s\.wordpress\.org/style/images/wp\-header\-logo\.png \-\-title=\'The WordPress logo\' \-\-alt="Semantic personal publishing"
 .
 .fi
 
index 475972e..be4eebf 100644 (file)
@@ -56,7 +56,7 @@ class Media_Command extends WP_CLI_Command {
        /**
         * Sideload images from local file(s) or URL and import as attachments, optionally attached to a post
         *
-        * @synopsis <file>... [--post_id=<post_id>] [--desc=<description>]
+        * @synopsis <file>... [--post_id=<post_id>] [--title=<title>] [--caption=<caption>] [--alt=<alt_text>] [--desc=<description>]
         */
        function import( $args, $assoc_args = array() ) {
 
@@ -64,6 +64,9 @@ class Media_Command extends WP_CLI_Command {
                        $assoc_args,
                        array(
                                'post_id' => 0,
+                               'title' => null,
+                               'caption' => null,
+                               'alt' => null,
                                'desc' => null
                        )
                );
@@ -88,7 +91,18 @@ class Media_Command extends WP_CLI_Command {
                                'tmp_name' => $file,
                                'name' => basename( $file )
                        );
-                       $success = media_handle_sideload( $file_array, $assoc_args['post_id'], $assoc_args['desc'] );
+
+                       $post_array= array(
+                               'post_title' => $assoc_args['title'],
+                               'post_excerpt' => $assoc_args['caption'],
+                               'post_content' => $assoc_args['desc']
+                       );
+
+                       $success = media_handle_sideload( $file_array, $assoc_args['post_id'], $assoc_args['title'], $post_array );
+
+                       if ( !is_wp_error( $success ) && $assoc_args['alt'] )
+                               update_post_meta( $success, '_wp_attachment_image_alt', $assoc_args['alt'] );
+
                        if ( is_wp_error( $success ) )
                                WP_CLI::error(
                                        sprintf(