] * : Pack to install (e.g. core, woocommerce). Omit to list packs. * * [--force] * : Overwrite guides that already exist with the library version. * * ## EXAMPLES * * wp hintwise library * wp hintwise library core * * @param array $args Positional. * @param array $assoc Named. */ public function library( $args, $assoc ) { if ( empty( $args[0] ) ) { $rows = array(); $installed = Hintwise_Library::installed(); foreach ( Hintwise_Library::packs() as $id => $p ) { $guides = $p['available'] ? Hintwise_Library::guides( $id ) : array(); $rows[] = array( 'pack' => $id, 'title' => $p['title'], 'available' => Hintwise_Library::can_install( $id ) ? 'yes' : ( $p['pro'] && ! hintwise_is_pro() ? 'pro' : 'no' ), 'guides' => count( $guides ), 'installed' => count( array_intersect_key( $installed, array_flip( wp_list_pluck( $guides, 'id' ) ) ) ), ); } WP_CLI\Utils\format_items( 'table', $rows, array( 'pack', 'title', 'available', 'guides', 'installed' ) ); return; } $r = Hintwise_Library::install( $args[0], array(), ! empty( $assoc['force'] ) ); if ( is_wp_error( $r ) ) { WP_CLI::error( $r->get_error_message() ); } WP_CLI::success( sprintf( 'Created %d, updated %d, skipped %d.', $r['created'], $r['updated'], $r['skipped'] ) ); } /** * Exports all guides to JSON. * * ## OPTIONS * * [--file=] * : Write to this file instead of STDOUT. * * @param array $args Positional. * @param array $assoc Named. */ public function export( $args, $assoc ) { $json = wp_json_encode( Hintwise_Transfer::export(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); if ( ! empty( $assoc['file'] ) ) { file_put_contents( $assoc['file'], $json ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents WP_CLI::success( 'Exported to ' . $assoc['file'] ); return; } WP_CLI::line( $json ); } /** * Imports guides from a JSON export. * * ## OPTIONS * * * : Export file. * * @param array $args Positional. */ public function import( $args ) { if ( ! is_readable( $args[0] ) ) { WP_CLI::error( 'Cannot read ' . $args[0] ); } $r = Hintwise_Transfer::import( json_decode( (string) file_get_contents( $args[0] ), true ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents if ( is_wp_error( $r ) ) { WP_CLI::error( $r->get_error_message() ); } WP_CLI::success( sprintf( 'Imported %d guides.', $r['created'] ) ); } /** * Copies WP Help documents into guides, with their order, sections and links. Documents * copied before are skipped, so it is safe to run again. WP Help itself is not changed. * * ## OPTIONS * * [--dry-run] * : Only report what would be imported. * * [--menu-label] * : Also use WP Help's menu name (e.g. "Publishing Help") for the Site Guide menu. * * ## EXAMPLES * * wp hintwise import-wp-help --dry-run * wp hintwise import-wp-help --menu-label * * @subcommand import-wp-help * * @param array $args Positional. * @param array $assoc Named. */ public function import_wp_help( $args, $assoc ) { $dry = ! empty( $assoc['dry-run'] ); $r = Hintwise_WP_Help::import( array( 'dry_run' => $dry, 'menu_label' => ! empty( $assoc['menu-label'] ), ) ); WP_CLI::success( sprintf( '%s %d WP Help documents, skipped %d imported before.', $dry ? 'Would import' : 'Imported', $r['created'], $r['skipped'] ) ); } }