Skip to content

Commit

Permalink
Merge pull request #86 from diggy/fix-wp-pll-option-sync/unsync
Browse files Browse the repository at this point in the history
fix wp pll option sync/unsync
  • Loading branch information
diggy committed Aug 9, 2017
2 parents d32d8ce + a97e694 commit c5f0414
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Commands/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function sync( $args, $assoc_args ) {

if ( $args[0] === 'all' ) {

$this->pll->model->options['sync'] = array_fill_keys( array_keys( $this->options_sync ), 1 );
$this->pll->model->options['sync'] = array_keys( $this->options_sync );

# update options, default category and nav menu locations
$this->pll->model->update_default_lang( $this->api->default_language() );
Expand All @@ -277,7 +277,7 @@ public function sync( $args, $assoc_args ) {
$settings = (array) $this->pll->model->options['sync'];

# update current settings
$settings = array_merge( $settings, array_fill_keys( $args, 1 ) );
$settings = array_merge( $settings, $args );

$this->pll->model->options['sync'] = $settings;

Expand Down Expand Up @@ -332,19 +332,20 @@ public function unsync( $args, $assoc_args ) {
$args = explode( ',', $args[0] );

# validate args
foreach ( $args as $key ) {
foreach ( $args as $i => $key ) {
if ( ! in_array( $key, array_keys( $this->options_sync ) ) ) {
return $this->cli->error( sprintf( 'Invalid key: %s', $key ) );
unset( $args[$i] );
$this->cli->warning( sprintf( 'Invalid key: %s', $key ) );
}
}

# get current settings
$settings = (array) $this->pll->model->options['sync'];

# update current settings
$settings = array_diff_key( $settings, array_fill_keys( $args, 1 ) );
$settings = array_diff( $settings, $args );

$this->pll->model->options['sync'] = $settings;
$this->pll->model->options['sync'] = array_values( $settings );

# update options, default category and nav menu locations
$this->pll->model->update_default_lang( $this->api->default_language() );
Expand Down

0 comments on commit c5f0414

Please sign in to comment.