$type, 'post_title' => preg_replace( '/\.[^.]+$/', '', $name ), 'post_status' => 'inherit', ), "$dir/$name" ); wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, "$dir/$name" ) ); $attachments[ $name ] = $id; } $uploads_url = $upload['baseurl'] . '/fixture'; $content = function ( $part ) use ( $fixture, $uploads_url ) { return str_replace( '{{UPLOADS}}', $uploads_url, file_get_contents( "$fixture/content/$part.html" ) ); }; // Options. update_option( 'blogname', 'Theme' ); update_option( 'blogdescription', 'A site for testing how a theme handles real content' ); update_option( 'posts_per_page', 10 ); update_option( 'thread_comments', 1 ); global $wp_rewrite; $wp_rewrite->set_permalink_structure( '/%postname%/' ); // Remove the default content, but keep WooCommerce's pages. $keep = class_exists( 'WooCommerce' ) ? array_map( 'wc_get_page_id', array( 'shop', 'cart', 'checkout', 'myaccount' ) ) : array(); foreach ( get_posts( array( 'post_type' => array( 'post', 'page' ), 'post_status' => 'any', 'numberposts' => -1, 'exclude' => $keep ) ) as $p ) { wp_delete_post( $p->ID, true ); } $sample = wp_insert_term( 'Sample', 'category' )['term_id']; $travel = wp_insert_term( 'Travel and Places to See This Year', 'category' )['term_id']; $short = 'This sample post has one short paragraph, so the excerpt is short too.'; $long = 'This sample post has a longer paragraph. ' . str_repeat( 'The quick brown fox jumps over the lazy dog, and then it rests for a while in the shade of a tall tree. ', 6 ); $para = function ( $text ) { return "\n

$text

\n"; }; // 11 posts, newest first in this list. Every post has the word "sample" for the search. $posts = array( array( 'title' => 'Alignments', 'content' => $content( 'alignments' ), 'image' => 'oleg-laptev-7jQh3EiS8Bs-unsplash-scaled.jpg', 'tags' => array( 'alignments' ), 'comments' => true ), array( 'title' => 'A very long post title that keeps going and going to see how the theme wraps it across several lines on small screens', 'content' => $para( $long ) ), array( 'title' => 'Hi', 'content' => $para( $short ), 'image' => 'sarah-dorweiler-9Z1KRIfpBTM-unsplash-1-scaled.jpg' ), array( 'title' => '', 'content' => $para( 'This sample post has no title.' ) ), array( 'title' => 'Pneumonoultramicroscopicsilicovolcanoconiosis is a long word', 'content' => $para( $short ), 'image' => 'jakub-dziubak-XtUd5SiX464-unsplash-1-1024x684.jpg' ), array( 'title' => 'A post with a custom excerpt', 'content' => $para( $long ), 'excerpt' => 'This sample custom excerpt replaces the generated one.' ), array( 'title' => 'A post with many categories and tags', 'content' => $para( $short ), 'cats' => array( $travel ), 'tags' => array( 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' ) ), array( 'title' => 'A post with a featured image', 'content' => $para( $short ), 'image' => 'oleg-laptev-7jQh3EiS8Bs-unsplash-scaled.jpg' ), array( 'title' => 'A post with a portrait featured image', 'content' => $para( $short ), 'image' => 'lea-l-q-99IzY8Lw-unsplash-1-701x1024.jpg' ), array( 'title' => 'Another short post', 'content' => $para( $short ) ), array( 'title' => 'The oldest post, shown on page 2', 'content' => $para( $short ), 'image' => 'sumner-mahaffey-7Y0NshQLohk-unsplash-scaled.jpg' ), ); $ids = array(); foreach ( $posts as $i => $p ) { $id = wp_insert_post( array( 'post_title' => $p['title'], 'post_content' => $p['content'], 'post_excerpt' => $p['excerpt'] ?? '', 'post_status' => 'publish', 'post_author' => 1, 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( "2026-10-01 -$i days" ) ), 'post_category' => array_merge( array( $sample ), $p['cats'] ?? array() ), 'tags_input' => $p['tags'] ?? array(), ) ); if ( ! empty( $p['image'] ) ) { set_post_thumbnail( $id, $attachments[ $p['image'] ] ); } if ( ! empty( $p['comments'] ) ) { $c1 = wp_insert_comment( array( 'comment_post_ID' => $id, 'comment_author' => 'Alex', 'comment_content' => 'A sample comment from a visitor.', 'comment_approved' => 1, 'comment_date' => '2026-10-02 10:00:00' ) ); wp_insert_comment( array( 'comment_post_ID' => $id, 'comment_author' => 'admin', 'user_id' => 1, 'comment_parent' => $c1, 'comment_content' => 'A reply from the author, one level down.', 'comment_approved' => 1, 'comment_date' => '2026-10-02 11:00:00' ) ); wp_insert_comment( array( 'comment_post_ID' => $id, 'comment_author' => 'Sam', 'comment_content' => 'A second comment, with a longer text so it wraps onto more than one line on a phone screen.', 'comment_approved' => 1, 'comment_date' => '2026-10-03 10:00:00' ) ); } if ( false !== strpos( $p['content'], 'wp:footnotes' ) ) { preg_match_all( '/data-fn="([^"]+)"/', $p['content'], $m ); $notes = array_map( function ( $fn ) { return array( 'id' => $fn, 'content' => 'A sample footnote.' ); }, array_unique( $m[1] ) ); update_post_meta( $id, 'footnotes', wp_slash( wp_json_encode( array_values( $notes ) ) ) ); } $ids[] = $id; } // Pages. $page = function ( $title, $body, $template = '' ) { return wp_insert_post( array( 'post_type' => 'page', 'post_title' => $title, 'post_content' => $body, 'post_status' => 'publish', 'post_author' => 1, 'page_template' => $template ) ); }; $page( 'Sample Page', $content( 'alignments' ) ); // One page per custom template in theme.json. (WooCommerce adds its own // templates to the page template list, so don't use that.) foreach ( WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates() as $slug => $template ) { if ( in_array( 'page', $template['postTypes'] ?? array( 'page' ), true ) ) { $page( 'Template: ' . ( $template['title'] ?? $slug ), $content( 'alignments' ), $slug ); } } // A theme with front-page.html shows it on the homepage whatever the Reading // setting is, so use a static homepage to show the posts page too, at /blog/. // Any other theme shows the latest posts on the homepage, as a new site does. if ( file_exists( get_stylesheet_directory() . '/templates/front-page.html' ) || file_exists( get_template_directory() . '/templates/front-page.html' ) ) { update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $page( 'Home', '' ) ); update_option( 'page_for_posts', $page( 'Blog', '' ) ); } else { update_option( 'show_on_front', 'posts' ); } if ( class_exists( 'WooCommerce' ) ) { require __DIR__ . '/store.php'; } $wp_rewrite->flush_rules( true ); // capture.sh waits for this. update_option( 'theme_screenshots_ready', 1 ); echo "Created " . count( $ids ) . " posts.\n";