] * : Anzahl der Beispiele, 1 bis 3. * --- * default: 3 * --- * * @param array $args Argumente. * @param array $assoc_args Optionen. */ public function demo( $args, $assoc_args ) { $anzahl = max( 1, min( 3, (int) ( isset( $assoc_args['posts'] ) ? $assoc_args['posts'] : 3 ) ) ); $beispiele = array( array( 'title' => 'Cordless drill X18 review: strong and quick to charge', 'slug' => 'cordless-drill-x18-review', 'quick' => array( 'name' => 'Cordless drill X18', 'summary' => 'Drives 8 mm screws without pilot holes and recharges in 35 minutes. The best choice under 150 € for woodwork.', 'place' => array( 'top' => true, 'bottom' => true, ), ), 'box' => array( 'item' => array( 'type' => 'product', 'sub' => 'Product · Tools', ), 'scale' => 'p10', 'criteria' => array( array( 'label' => 'Torque', 'weight' => 30, 'score' => 9.0, 'measure' => '62 Nm', ), array( 'label' => 'Battery', 'weight' => 25, 'score' => 8.0, 'measure' => '41 min under load', ), array( 'label' => 'Handling', 'weight' => 25, 'score' => 8.5, 'measure' => '1.4 kg', ), array( 'label' => 'Value', 'weight' => 20, 'score' => 7.0, 'measure' => '129 €', ), ), 'pros' => array( 'drives 8 mm screws without pilot holes', 'battery full again in 35 minutes', 'two clean gears' ), 'cons' => array( 'LED dazzles when working overhead', 'case has no room for bits' ), 'verdict' => 'For DIY woodwork the best choice under 150 €. For assembling furniture the predecessor is enough.', 'good_for' => array( 'woodwork', 'furniture' ), 'bad_for' => array( 'daily use on construction sites' ), 'tested' => '6 weeks in a loft conversion, 140 screws, 2 batteries, torque wrench and stopwatch', 'disclosure' => array( 'loan' => true ), ), ), array( 'title' => 'Example film review', 'slug' => 'example-film-review', 'quick' => array( 'name' => 'Example film (2026)', 'summary' => 'Strongly acted and cleverly told, only the score is too loud.', 'place' => array( 'bottom' => true ), ), 'box' => array( 'item' => array( 'type' => 'movie', 'sub' => 'Film · Drama · 128 minutes', ), 'scale' => 's10', 'display' => 'stars', 'criteria' => array( array( 'label' => 'Story', 'weight' => 30, 'score' => 9.8, ), array( 'label' => 'Acting', 'weight' => 25, 'score' => 9.6, ), array( 'label' => 'Direction', 'weight' => 25, 'score' => 8.7, ), array( 'label' => 'Music', 'weight' => 20, 'score' => 6.7, ), ), 'pros' => array( 'the lead carries every scene', 'the twist in the last act works' ), 'cons' => array( 'the music explains feelings the images already show' ), 'verdict' => 'A quiet drama that trusts its audience.', ), ), array( 'title' => 'Notes app review', 'slug' => 'notes-app-review', 'quick' => array( 'name' => 'Example notes app', 'summary' => 'The most pleasant notes app in our test.', 'place' => array( 'bottom' => true ), ), 'box' => array( 'item' => array( 'type' => 'software', 'sub' => 'Software · Notes · iOS, Android, Web', ), 'scale' => 'p10', 'style' => 'night', 'criteria' => array( array( 'label' => 'Features', 'weight' => 30, 'score' => 8.5, ), array( 'label' => 'Ease of use', 'weight' => 25, 'score' => 9.0, ), array( 'label' => 'Privacy', 'weight' => 25, 'score' => 7.5, ), array( 'label' => 'Price', 'weight' => 20, 'score' => 6.0, ), ), 'pros' => array( 'search finds text in photos', 'works fully offline' ), 'cons' => array( 'sync only with a subscription' ), 'verdict' => 'If you want to keep data local only, choose an alternative with its own sync.', ), ), ); // WP-CLI läuft ohne angemeldeten Nutzer: Beispiele gehören dem ersten Administrator, damit Byline und Schema wie im Betrieb aussehen. $autor = get_current_user_id(); if ( ! $autor ) { $admins = get_users( array( 'role' => 'administrator', 'number' => 1, 'orderby' => 'ID', 'fields' => 'ID', ) ); $autor = $admins ? (int) $admins[0] : 0; } for ( $i = 0; $i < $anzahl; $i++ ) { $b = $beispiele[ $i ]; $id = wp_insert_post( array( 'post_author' => $autor, 'post_title' => $b['title'], 'post_name' => $b['slug'], 'post_status' => 'publish', 'post_content' => '

This is an example post with a rating. Click the star at the top of the editor to change it.

', ), true ); if ( is_wp_error( $id ) ) { WP_CLI::warning( $id->get_error_message() ); continue; } ThreeRB_Box::save( $id, ThreeRB_Box::clean( $b['box'] )['box'] ); ThreeRB_Box::save_quick( $id, ThreeRB_Box::quick_clean( $b['quick'] ) ); WP_CLI::log( get_permalink( $id ) ); } WP_CLI::success( 'Example ratings created.' ); } /** * Berechnet die Spiegelfelder aller Bewertungen neu. * * @param array $args Argumente. * @param array $assoc_args Optionen. */ public function recount( $args, $assoc_args ) { $ids = get_posts( array( 'post_type' => ThreeRB_Settings::value( 'post_types' ), 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids', 'meta_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Wartungsbefehl. 'relation' => 'OR', array( 'key' => ThreeRB_Box::META_BOX ), array( 'key' => ThreeRB_Box::META_QUICK ), ), ) ); foreach ( $ids as $id ) { ThreeRB_Box::mirror( (int) $id ); } WP_CLI::success( count( $ids ) . ' ratings recounted.' ); } /** * Zieht Bewertungen aus WP Review um. Alte Daten bleiben unverändert. * * ## OPTIONS * * [--dry-run] * : Nur Vorschau alt gegen neu, nichts wird geschrieben. * * [--undo] * : Umzug zurücknehmen (laut Protokoll, von Hand geänderte Boxen bleiben). * * @param array $args Argumente. * @param array $assoc_args Optionen. */ public function migrate( $args, $assoc_args ) { if ( ! empty( $assoc_args['undo'] ) ) { $r = ThreeRB_Migrate::rollback( '' ); if ( is_wp_error( $r ) ) { WP_CLI::error( $r->get_error_message() ); } WP_CLI::success( $r['removed'] . ' moved ratings removed, ' . count( $r['kept'] ) . ' kept because they were edited.' ); return; } if ( ! empty( $assoc_args['dry-run'] ) ) { $offset = 0; do { $probe = ThreeRB_Migrate::dry_run( $offset, 50 ); foreach ( $probe['items'] as $p ) { WP_CLI::log( sprintf( '#%d %s | %s | %s -> %s | %d/%d criteria | %s', $p['id'], $p['title'], $p['status'], var_export( $p['old_total'], true ), var_export( $p['new_total'], true ), $p['criteria'], $p['old_criteria'], implode( ',', $p['notes'] ) ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export -- Ausgabe für die Shell. } $offset += 50; } while ( $offset < $probe['total'] ); WP_CLI::success( $probe['total'] . ' posts with WP Review data found. Nothing was written.' ); return; } $job = ''; $gesamt = 0; do { $r = ThreeRB_Migrate::run( $job, 50 ); if ( is_wp_error( $r ) ) { WP_CLI::error( $r->get_error_message() ); } $job = $r['job']; $gesamt += $r['moved']; } while ( $r['remaining'] > 0 ); WP_CLI::success( $gesamt . ' ratings moved. WP Review data was not changed.' ); } }