Skip to content
Browse files

make --user a global parameter. fixes #81

  • Loading branch information...
1 parent 455f55d commit b4c5b3381f814385e9d2eb5d5f9120d6a1db1937 @scribu scribu committed
Showing with 14 additions and 24 deletions.
  1. +0 −24 src/php/wp-cli/commands/internals/export.php
  2. +14 −0 src/php/wp-cli/wp-cli.php
View
24 src/php/wp-cli/commands/internals/export.php
@@ -20,7 +20,6 @@ public static function help() {
Required parameters:
--path Full Path to directory where WXR export files should be stored
- --user Username/ID the import should run as
Optional filters:
--start_date Export only posts new than this date in format YYYY-MM-DD
@@ -40,7 +39,6 @@ public static function help() {
public function validate_arguments( $args, $assoc_args ) {
$defaults = array(
'path' => NULL,
- 'user' => NULL,
'start_date' => NULL,
'end_date' => NULL,
'post_type' => NULL,
@@ -87,28 +85,6 @@ private function check_path( $path ) {
return true;
}
- private function check_user( $user ) {
- if ( empty( $user ) ) {
- WP_CLI::warning( 'missing --user parameter' );
- return false;
- }
-
- if ( is_numeric( $user ) ) {
- $user_id = (int) $user;
- } else {
- $user_id = (int) username_exists( $user );
- }
- if ( !$user_id || !wp_set_current_user( $user_id ) ) {
- WP_CLI::error( sprintf( "Could not get a user_id for this user: %s", var_export( $user_id, true ) ) );
- exit;
- }
-
- $current_user = wp_get_current_user();
- $this->user_id = (int) $user_id;
-
- return true;
- }
-
private function check_start_date( $date ) {
if ( is_null( $date ) )
return true;
View
14 src/php/wp-cli/wp-cli.php
@@ -78,6 +78,20 @@
}
}
+// Set the user
+if ( isset( $assoc_args['user'] ) ) {
+ $user = $assoc_args['user'];
+ if ( is_numeric( $user ) ) {
+ $user_id = (int) $user;
+ } else {
+ $user_id = (int) username_exists( $user );
+ }
+ if ( !$user_id || !wp_set_current_user( $user_id ) ) {
+ WP_CLI::error( sprintf( 'Could not get a user_id for this user: %s', var_export( $user, true ) ) );
+ }
+ unset( $user);
+}
+
// Set filesystem method
add_filter( 'filesystem_method', function() { return 'direct'; }, 99 );

0 comments on commit b4c5b33

Please sign in to comment.
Something went wrong with that request. Please try again.