forked from kovshenin/escape-ngg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-cli.php
73 lines (57 loc) · 1.67 KB
/
wp-cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Commands to help you escape NextGen Gallery
*
*/
class ENGG_Command extends WP_CLI_Command {
public function __construct() {
}
/**
* Count the number of posts with NextGen Gallery Shortcodes in this site.
*
* ## OPTIONS
*
* ## EXAMPLES
*
* wp escape-ngg count
*
*/
public function count() {
WP_CLI::log( Escape_NextGen_Gallery::init()->count() );
}
/**
* 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 );
}
}
WP_CLI::add_command( 'escape-ngg', 'ENGG_Command' );