/** * Convert the NextGen Gallery Shortcodes in posts in this site into WordPress gallery shortcodes. * * ## OPTIONS * * ## EXAMPLES * * wp escape-ngg convert * */ public function convert() { $count = Escape_NextGen_Gallery::init()->count(); WP_CLI::log(sprintf('Processing %d posts with NextGen Gallery shortcodes', $count)); set_time_limit(0); $uploads = wp_upload_dir(); $baseurl = $uploads['baseurl']; $post_ids = Escape_NextGen_Gallery::init()->get_post_ids(); $progress = new \cli\progress\Bar('Progress', $count); foreach ($post_ids as $post_id) { $progress->tick(); Escape_NextGen_Gallery::init()->process_post($post_id); } $progress->finish(); foreach (Escape_NextGen_Gallery::init()->infos as $info) { WP_CLI::log($info); } foreach (Escape_NextGen_Gallery::init()->warnings as $warning) { WP_CLI::warning($warning); } $lines = array((object) array('Converted' => 'posts converted', 'Count' => Escape_NextGen_Gallery::init()->posts_count), (object) array('Converted' => 'images converted', 'Count' => Escape_NextGen_Gallery::init()->images_count)); $fields = array('Converted', 'Count'); \WP_CLI\Utils\format_items('table', $lines, $fields); }
$attr['exclude'] = implode(',', $existing_attachments_ids); } $gallery = '[gallery'; foreach ($attr as $key => $value) { $gallery .= sprintf(' %s="%s"', esc_attr($key), esc_attr($value)); } $gallery .= ']'; // Booyaga! $pristine_content = $post->post_content; $post->post_content = preg_replace('#\\[nggallery[^\\]]*\\]#i', $gallery, $post->post_content); $post->post_content = apply_filters('engg_post_content', $post->post_content, $pristine_content, $attr, $post, $gallery); wp_update_post($post); $this->posts_count++; $this->infos[] = sprintf("Updated post %d", $post->ID); } /** * @param int $limit How many posts to get * * @return void **/ public function get_post_ids($limit = -1) { $args = array('s' => '[nggallery', 'post_type' => array('post', 'page'), 'post_status' => 'any', 'nopaging' => true, 'fields' => 'ids', 'posts_per_page' => $limit); $args = apply_filters('escape_ngg_query_args', $args); $query = new WP_Query($args); return $query->posts; } } // Initiate the singleton Escape_NextGen_Gallery::init();