] * : URL on this site to audit. Omit to audit everything llms.txt covers. * * [--force] * : Ignore cached results and refetch. * * [--format=] * : table, csv, json or yaml. Default: table. * * ## EXAMPLES * * wp oorank audit https://example.com/pricing/ * wp oorank audit --force --format=csv * * @param array $args Positional arguments. * @param array $assoc_args Associative arguments. */ public function audit( $args, $assoc_args ) { $audit = oorank()->audit; $force = ! empty( $assoc_args['force'] ); $format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table'; if ( ! empty( $args[0] ) ) { $result = $audit->audit( $args[0], 0, $force ); if ( is_wp_error( $result ) ) { WP_CLI::error( $result->get_error_message() ); } WP_CLI\Utils\format_items( $format, array_map( static function ( $check ) { return array( 'check' => $check['key'], 'scope' => isset( $check['scope'] ) ? $check['scope'] : 'page', 'status' => $check['status'], 'weight' => $check['weight'], 'message' => $check['message'], ); }, $result['checks'] ), array( 'check', 'scope', 'status', 'weight', 'message' ) ); WP_CLI::success( sprintf( /* translators: 1: overall score, 2: page score, 3: site score. */ __( 'Score %1$d of 100 (page %2$d, site %3$d).', 'oorank' ), (int) $result['score'], isset( $result['scores']['page'] ) ? (int) $result['scores']['page'] : (int) $result['score'], isset( $result['scores']['site'] ) ? (int) $result['scores']['site'] : 0 ) ); return; } $ids = $audit->scannable_ids(); if ( empty( $ids ) ) { WP_CLI::warning( __( 'Nothing to scan — no post types are selected for llms.txt.', 'oorank' ) ); return; } $progress = WP_CLI\Utils\make_progress_bar( __( 'Auditing', 'oorank' ), count( $ids ) ); $failed = 0; foreach ( $ids as $id ) { $result = $audit->audit_post( $id, $force ); if ( is_wp_error( $result ) ) { ++$failed; } $progress->tick(); } $progress->finish(); $report = $audit->report(); WP_CLI::success( sprintf( /* translators: 1: number of items audited, 2: average score, 3: number that failed. */ __( '%1$d audited, average %2$d of 100, %3$d could not be fetched.', 'oorank' ), count( $ids ), (int) $report['average'], $failed ) ); } /** * Manage llms.txt. * * ## OPTIONS * * * : regenerate or show. * * [--variant=] * : index or full, for show. Default: index. * * ## EXAMPLES * * wp oorank llms regenerate * wp oorank llms show --variant=full * * @param array $args Positional arguments. * @param array $assoc_args Associative arguments. */ public function llms( $args, $assoc_args ) { $llms = oorank()->llms_txt; $action = isset( $args[0] ) ? $args[0] : ''; if ( 'regenerate' === $action ) { $llms->rebuild(); WP_CLI::success( sprintf( /* translators: 1: llms.txt size in bytes, 2: llms-full.txt size in bytes. */ __( 'Rebuilt: llms.txt %1$d bytes, llms-full.txt %2$d bytes.', 'oorank' ), strlen( $llms->get_index() ), strlen( $llms->get_full() ) ) ); return; } if ( 'show' === $action ) { $variant = ( isset( $assoc_args['variant'] ) && 'full' === $assoc_args['variant'] ) ? 'full' : 'index'; WP_CLI::line( 'full' === $variant ? $llms->get_full() : $llms->get_index() ); return; } WP_CLI::error( __( 'Unknown action. Use regenerate or show.', 'oorank' ) ); } /** * Show or change AI crawler access. * * ## OPTIONS * * [] * : Bot slug to change. Omit to list every crawler and its state. * * [--allow] * : Allow the named crawler. * * [--block] * : Block the named crawler. * * ## EXAMPLES * * wp oorank bots * wp oorank bots gptbot --block * * @param array $args Positional arguments. * @param array $assoc_args Associative arguments. */ public function bots( $args, $assoc_args ) { $settings = oorank()->settings; $states = oorank()->bots->states(); $registry = Oorank_Bot_Manager::registry(); if ( empty( $args[0] ) ) { $rows = array(); foreach ( $registry as $slug => $entry ) { $rows[] = array( 'slug' => $slug, 'name' => $entry['name'], 'operator' => $entry['operator'], 'category' => $entry['category'], 'state' => isset( $states[ $slug ] ) ? $states[ $slug ] : Oorank_Bot_Manager::ALLOW, ); } WP_CLI\Utils\format_items( 'table', $rows, array( 'slug', 'name', 'operator', 'category', 'state' ) ); return; } $slug = sanitize_key( $args[0] ); if ( ! isset( $registry[ $slug ] ) ) { WP_CLI::error( __( 'Unknown crawler slug. Run `wp oorank bots` for the list.', 'oorank' ) ); } $block = ! empty( $assoc_args['block'] ); $allow = ! empty( $assoc_args['allow'] ); if ( $block === $allow ) { WP_CLI::error( __( 'Pass exactly one of --allow or --block.', 'oorank' ) ); } $current = $settings->get(); $current['bots'][ $slug ] = $block ? Oorank_Bot_Manager::BLOCK : Oorank_Bot_Manager::ALLOW; $settings->update( $current ); WP_CLI::success( sprintf( /* translators: 1: crawler name, 2: new state. */ __( '%1$s is now %2$s.', 'oorank' ), $registry[ $slug ]['name'], $block ? 'block' : 'allow' ) ); } }