PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.2.3
Kubio AI Page Builder v1.2.3
2.9.1 2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / DemoSites / WpCliCommand.php
kubio / lib / src / DemoSites Last commit date
DemoSites.php 4 years ago DemoSitesHelpers.php 4 years ago DemoSitesImportBlockMap.php 4 years ago DemoSitesImporter.php 4 years ago DemoSitesLogger.php 4 years ago DemoSitesRepository.php 4 years ago WXRExporter.php 4 years ago WXRImporter.php 4 years ago WpCliCommand.php 4 years ago
WpCliCommand.php
109 lines
1 <?php
2
3 use IlluminateAgnostic\Str\Support\Arr;
4 use Kubio\DemoSites\DemoSitesImporter;
5 use Kubio\DemoSites\DemoSitesRepository;
6
7 /**
8 * Implements example command.
9 */
10 class DemoSites_Import_Command {
11
12 /**
13 * Import a Kubio design.
14 *
15 * ## OPTIONS
16 *
17 * <design-name>
18 * : The slug of the design to import.
19 *
20 * [--verify-ssl=<bool>]
21 * : Whatever or not to enforce SSL on requests.
22 * Default: true
23 *
24 * [--scope=<string>]
25 * : Whatever or not to enforce SSL on requests.
26 * Default: null
27 *
28 * ## EXAMPLES
29 *
30 * wp kubio:import-design accounting-demo-site
31 *
32 * @when after_wp_load
33 * @param $args
34 * @param $assoc_args
35 * @throws \WP_CLI\ExitException
36 */
37 public function __invoke( $args, $assoc_args ) {
38
39 ini_set( 'max_execution_time', 0 );
40 set_time_limit( 0 );
41
42 if ( empty( $args[0] ) || ! is_string( $args[0] ) ) {
43 \WP_CLI::error( 'This command expects the first argument to be an importable design slug.' );
44 return;
45 }
46
47 // Interpret some associative arguments as booleans.
48 foreach ( $assoc_args as $assoc_arg_key => $assoc_arg_value ) {
49
50 switch ( $assoc_arg_key ) {
51 case 'verify-ssl':
52 $assoc_args[ $assoc_arg_key ] =
53 boolval( json_decode( $assoc_arg_value ) );
54 break;
55 }
56 }
57
58 $defaults = array(
59 'verify-ssl' => true,
60 );
61
62 $assoc_args = wp_parse_args( $assoc_args, $defaults );
63 $designName = $args[0];
64 $repo = new DemoSitesRepository();
65
66 $repo->retrieveDemoSites( false, $assoc_args['verify-ssl'], Arr::get( $assoc_args, 'scope', null ) );
67 $data = get_transient( 'kubio-demo-sites-repository' );
68
69 if ( ! Arr::get( (array) $data, "demos.{$designName}" ) ) {
70 \WP_CLI::error( '"' . $designName . '" is not a valid design slug.' );
71 return;
72 }
73
74 WP_CLI::line( 'Let\'s import "' . $designName . '" ...' );
75
76 $importer_args = array(
77 'slug' => $designName,
78 'before_import_action' => 'init',
79 );
80
81 if ( ! empty( $assoc_args['non-ssl'] ) ) {
82 $importer_args['allow--non-ssl'] = $assoc_args['non-ssl'];
83 }
84
85 $importer = new DemoSitesImporter( 'cli', $importer_args );
86
87 foreach ( $importer->getBeforeImportActions() as $key => $step ) {
88 $importer_args['before_import_action'] = $step;
89 $importer_args['first_call'] = $key === 0;
90 $importer->executeBeforeImportAction( $step, false );
91 }
92
93 \WP_CLI::line( 'Start importing content' );
94
95 $importer->cliImportDemoData();
96
97 \WP_CLI::line( 'Finishing import' );
98
99 WP_CLI::success( '"' . $designName . '" was successfully imported!' );
100
101 // remove scoped transient
102 delete_transient( 'kubio-demo-sites-repository' );
103 }
104 }
105
106 if ( defined( 'WP_CLI' ) && WP_CLI ) {
107 WP_CLI::add_command( 'kubio:import-design', 'DemoSites_Import_Command' );
108 }
109