/**
  * Include Taxonomy_Switcher if being run
  *
  * @since 1.0.0
  */
 public function taxonomy_switcher_init()
 {
     if (!isset($_GET['taxonomy_switcher']) || 1 != $_GET['taxonomy_switcher'] || !current_user_can('install_plugins') || !isset($_GET['from_tax']) || empty($_GET['from_tax']) || !isset($_GET['to_tax']) || empty($_GET['to_tax'])) {
         return;
     }
     require_once dirname(__FILE__) . '/Taxonomy_Switcher.php';
     $taxonomy_switcher = new Taxonomy_Switcher($_GET);
     $success_notices = $taxonomy_switcher->admin_convert();
     if (empty($success_notices)) {
         return;
     }
     // Save notices
     add_option('taxonomy-switcher-notices', $success_notices, null, 'no');
     // Redirect and strip query string
     wp_redirect(esc_url_raw(add_query_arg('page', $this->ui->admin_slug, admin_url('/tools.php'))));
 }
Ejemplo n.º 2
0
 /**
  * Switch terms from one taxonomy to another.
  *
  * ## OPTIONS
  *
  * --from=<taxonomy>
  * : The Taxonomy to switch from.
  *
  * --to=<taxonomy>
  * : The Taxonomy to switch to.
  *
  * [--parent=<parent>]
  * : The term parent to limit by.
  *
  * [--terms=<terms>]
  * : Comma separated list of term ids to switch.
  *
  * ## EXAMPLES
  *
  *     wp taxonomy-switcher convert --from=category --to=post_tag
  *     wp taxonomy-switcher convert --from=category --to=post_tag --parent=123
  *     wp taxonomy-switcher convert --from=category --to=post_tag --terms=1,2,13
  *
  * @synopsis --from=<taxonomy> --to=<taxonomy> [--parent=<parent>] [--terms=<terms>]
  */
 public function convert($args, $assoc_args)
 {
     $args = $this->map_arg_names($assoc_args);
     $tax_switcher = new Taxonomy_Switcher($this->map_arg_names($assoc_args));
     $count = $tax_switcher->count();
     if (!$count) {
         WP_CLI::error($tax_switcher->notices('no_terms'));
     }
     WP_CLI::log($tax_switcher->notices('switching'));
     if (0 < $tax_switcher->parent) {
         WP_CLI::log($tax_switcher->notices('limit_by_parent'));
     }
     if (!empty($tax_switcher->terms)) {
         WP_CLI::log($tax_switcher->notices('limit_by_terms'));
     }
     set_time_limit(0);
     $tax_switcher->convert();
     WP_CLI::success($tax_switcher->notices('switched'));
 }