` by Esipher\Plugin. */ class Cli_Command { /** * Converts an AI site-builder export ZIP into an activatable * WordPress theme. * * ## OPTIONS * * * : Path to the export ZIP file. * * [--dest=] * : Desired theme slug. Defaults to the ZIP's filename, sanitized. * * [--activate] * : Activate the generated theme immediately after installing it. * * [--force] * : Auto-suffix (-2, -3, ...) an existing theme directory with the * same slug instead of failing. * * [--recover-images] * : For a multi-page export, attempt to fetch any cloud-hosted-only * image (one whose actual bytes were never in the downloaded ZIP, * only a pointer back to the original AI site builder's own asset * service) from that original project's still-live hosting. This is * the only network request this plugin ever makes — off by default. * * ## EXAMPLES * * wp esipher convert ./my-export.zip --activate * wp esipher convert ./my-export.zip --recover-images * * @when after_wp_load * * @param string[] $args Positional arguments. * @param array $assoc_args Flags/options. */ public function convert( $args, $assoc_args ) { list( $zip_path ) = $args; $preferred_slug = \WP_CLI\Utils\get_flag_value( $assoc_args, 'dest', pathinfo( $zip_path, PATHINFO_FILENAME ) ); $activate = \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate', false ); $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false ); $recover_images = \WP_CLI\Utils\get_flag_value( $assoc_args, 'recover-images', false ); $result = ( new Converter() )->convert( $zip_path, array( 'preferred_slug' => $preferred_slug, 'activate' => (bool) $activate, 'on_collision' => $force ? 'suffix' : 'fail', 'recover_images' => (bool) $recover_images, 'on_message' => function ( $level, $message ) { if ( 'warning' === $level ) { \WP_CLI::warning( $message ); } else { \WP_CLI::log( $message ); } }, ) ); if ( ! $result->success ) { \WP_CLI::error( $result->error_message ); return; } \WP_CLI::success( sprintf( "Converted '%s' to theme '%s'.", $zip_path, $result->slug ) ); } /** * Restores whichever theme was active immediately before the last * `wp esipher convert --activate`. * * ## EXAMPLES * * wp esipher rollback * * @when after_wp_load * * @param string[] $args Positional arguments (unused). * @param array $assoc_args Flags/options (unused). */ public function rollback( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- required by the WP-CLI command-method signature. try { $restored = ( new Installer() )->rollback(); } catch ( Installer_Exception $e ) { \WP_CLI::error( $e->getMessage() ); return; } \WP_CLI::success( "Restored previous theme '{$restored}'." ); } }