OSDN Git Service

media: don't call get_post() if --post_id isn't even passed
authorscribu <mail@scribu.net>
Thu, 11 Jul 2013 21:04:47 +0000 (00:04 +0300)
committerscribu <mail@scribu.net>
Thu, 11 Jul 2013 21:05:18 +0000 (00:05 +0300)
php/commands/media.php

index 4ffda25..0726f6a 100644 (file)
@@ -63,15 +63,18 @@ class Media_Command extends WP_CLI_Command {
         */
        function import( $args, $assoc_args = array() ) {
                $assoc_args = wp_parse_args( $assoc_args, array(
-                       'post_id' => false,
                        'title' => null,
                        'caption' => null,
                        'alt' => null,
                        'desc' => null
                ) );
 
-               if ( !get_post( $assoc_args['post_id'] ) ) {
-                       WP_CLI::warning( "Invalid --post_id" );
+               if ( isset( $assoc_args['post_id'] ) ) {
+                       if ( !get_post( $assoc_args['post_id'] ) ) {
+                               WP_CLI::warning( "Invalid --post_id" );
+                               $assoc_args['post_id'] = false;
+                       }
+               } else {
                        $assoc_args['post_id'] = false;
                }