Skip to content

Instantly share code, notes, and snippets.

@benbalter
Last active June 19, 2026 16:12
Show Gist options
  • Select an option

  • Save benbalter/07b6352e61bcc8889b090e06b73a149e to your computer and use it in GitHub Desktop.

Select an option

Save benbalter/07b6352e61bcc8889b090e06b73a149e to your computer and use it in GitHub Desktop.
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"landingPage": "/wp-admin/edit.php?post_type=document",
"preferredVersions": {
"php": "8.3",
"wp": "latest"
},
"features": {
"networking": true
},
"login": true,
"steps": [
{
"step": "login",
"username": "admin",
"password": "password"
},
{
"step": "installPlugin",
"pluginData": {
"resource": "wordpress.org/plugins",
"slug": "wp-document-revisions"
},
"options": {
"activate": true
}
},
{
"step": "runPHP",
"code": "<?php\n// Seed realistic WP Document Revisions content for WordPress.org screenshots.\nrequire '/wordpress/wp-load.php';\n\n// Avoid side effects (email notifications) during seeding.\nadd_filter( 'pre_wp_mail', '__return_true' );\n\nwp_set_current_user( 1 ); // admin, has all document caps.\n\n/** Create (or fetch) a user with a friendly display name and role. */\nfunction s_user( $login, $display, $email, $role = 'author' ) {\n\t$u = get_user_by( 'login', $login );\n\tif ( $u ) {\n\t\treturn $u->ID;\n\t}\n\t$id = wp_create_user( $login, 'password', $email );\n\t( new WP_User( $id ) )->set_role( $role );\n\t$parts = explode( ' ', $display );\n\twp_update_user( array(\n\t\t'ID' => $id,\n\t\t'display_name' => $display,\n\t\t'first_name' => $parts[0],\n\t\t'last_name' => isset( $parts[1] ) ? $parts[1] : '',\n\t) );\n\treturn $id;\n}\n\n$jane = s_user( 'jdoe', 'Jane Doe', 'jane@example.com' );\n$alex = s_user( 'asmith', 'Alex Smith', 'alex@example.com' );\n$maria = s_user( 'mgarcia', 'Maria Garcia', 'maria@example.com' );\n// The user we browse as for screenshots \u2014 Editor role keeps the admin menu lean.\n$editor = s_user( 'editor', 'Sam Lee', 'sam@example.com', 'editor' );\n$admin = 1;\n\n// Ensure the default workflow states exist before we assign them \u2014 on a fresh\n// install the plugin doesn't create them until a later admin_init. Give each a\n// description so the Workflow States screen looks configured.\n$ws_desc = array(\n\t'Initial Draft' => 'Newly created \u2014 not yet submitted for review.',\n\t'In Progress' => 'Actively being worked on by the document owner.',\n\t'Under Review' => 'Submitted and awaiting approver feedback.',\n\t'Final' => 'Approved and published \u2014 no further changes expected.',\n);\nforeach ( $ws_desc as $ws => $desc ) {\n\t$existing = term_exists( $ws, 'workflow_state' );\n\tif ( ! $existing ) {\n\t\twp_insert_term( $ws, 'workflow_state', array( 'description' => $desc ) );\n\t} else {\n\t\twp_update_term( (int) $existing['term_id'], 'workflow_state', array( 'description' => $desc ) );\n\t}\n}\n\n/** WPDR stores the attachment id inside an HTML comment in post_content. */\nfunction s_fmt( $att_id ) {\n\treturn '<!-- WPDR ' . (int) $att_id . ' -->';\n}\n\n/** Create a file + attachment (one version of a document). */\nfunction s_attach( $doc_id, $filename, $mime, $author, $date ) {\n\t$up = wp_upload_dir();\n\t$unique = wp_unique_filename( $up['path'], $filename );\n\t$path = trailingslashit( $up['path'] ) . $unique;\n\tfile_put_contents( $path, \"Sample document file: $filename\\n\" );\n\t$att_id = wp_insert_attachment( array(\n\t\t'post_title' => pathinfo( $filename, PATHINFO_FILENAME ),\n\t\t'post_mime_type' => $mime,\n\t\t'post_status' => 'inherit',\n\t\t'post_parent' => $doc_id,\n\t\t'post_author' => $author,\n\t\t'post_date' => $date,\n\t\t'post_date_gmt' => $date,\n\t\t'guid' => trailingslashit( $up['url'] ) . $unique,\n\t), $path, $doc_id );\n\treturn $att_id;\n}\n\n/**\n * Create a document with a backdated revision history.\n *\n * @param string $title Human document title (no extension).\n * @param string $state Workflow state term name.\n * @param string $filename Attachment filename (with extension).\n * @param string $mime MIME type.\n * @param array $versions Oldest-first list of [days_ago, author_id, summary].\n */\nfunction s_document( $title, $state, $filename, $mime, $versions ) {\n\tglobal $wpdb;\n\n\t// Build attachment + date for each version.\n\t$rows = array();\n\tforeach ( $versions as $v ) {\n\t\t$rows[] = array(\n\t\t\t'days' => $v[0],\n\t\t\t'author' => $v[1],\n\t\t\t'summary' => isset( $v[2] ) ? $v[2] : '',\n\t\t\t'date' => gmdate( 'Y-m-d H:i:s', strtotime( \"-{$v[0]} days\" ) ),\n\t\t);\n\t}\n\t$first = $rows[0];\n\t$last = end( $rows );\n\treset( $rows );\n\n\t// Create the document (parent) \u2014 represents the LATEST version.\n\t$doc_id = wp_insert_post( array(\n\t\t'post_type' => 'document',\n\t\t'post_status' => 'publish',\n\t\t'post_title' => $title,\n\t\t'post_author' => $last['author'],\n\t\t'post_date' => $first['date'],\n\t\t'post_content' => '',\n\t) );\n\n\t// Workflow state (assign by name; term is guaranteed to exist above).\n\twp_set_object_terms( $doc_id, $state, 'workflow_state', false );\n\n\t// One attachment per version, parented to the document.\n\t$atts = array();\n\tforeach ( $rows as $r ) {\n\t\t$atts[] = s_attach( $doc_id, $filename, $mime, $r['author'], $r['date'] );\n\t}\n\t$last_att = end( $atts );\n\n\t// Point the parent at the latest attachment; set modified date/author/summary.\n\t$wpdb->update(\n\t\t$wpdb->posts,\n\t\tarray(\n\t\t\t'post_content' => s_fmt( $last_att ),\n\t\t\t'post_excerpt' => $last['summary'],\n\t\t\t'post_author' => $last['author'],\n\t\t\t'post_modified' => $last['date'],\n\t\t\t'post_modified_gmt' => $last['date'],\n\t\t),\n\t\tarray( 'ID' => $doc_id )\n\t);\n\tupdate_post_meta( $doc_id, '_document_attachment_id', $last_att );\n\n\t// Insert backdated child revisions for the PRIOR versions (oldest..n-1).\n\t$count = count( $rows );\n\tfor ( $i = 0; $i < $count - 1; $i++ ) {\n\t\twp_insert_post( array(\n\t\t\t'post_type' => 'revision',\n\t\t\t'post_status' => 'inherit',\n\t\t\t'post_parent' => $doc_id,\n\t\t\t'post_author' => $rows[ $i ]['author'],\n\t\t\t'post_content' => s_fmt( $atts[ $i ] ),\n\t\t\t'post_excerpt' => $rows[ $i ]['summary'],\n\t\t\t'post_title' => $title,\n\t\t\t'post_name' => $doc_id . '-revision-v' . ( $i + 1 ),\n\t\t\t'post_date' => $rows[ $i ]['date'],\n\t\t\t'post_date_gmt' => $rows[ $i ]['date'],\n\t\t\t'post_modified' => $rows[ $i ]['date'],\n\t\t\t'post_modified_gmt' => $rows[ $i ]['date'],\n\t\t) );\n\t}\n\n\tclean_post_cache( $doc_id );\n\twp_cache_delete( $doc_id, 'document_revisions' );\n\twp_cache_delete( $doc_id, 'document_revision_indices' );\n\n\treturn $doc_id;\n}\n\n$xlsx = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n$docx = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';\n$pptx = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';\n$pdf = 'application/pdf';\n\n// 1) Money shot: rich 5-revision history, multiple collaborators.\ns_document( 'Q3 2025 Financial Report', 'Under Review', 'q3-2025-financial-report.xlsx', $xlsx, array(\n\tarray( 21, $jane, 'Initial draft from accounting' ),\n\tarray( 17, $jane, 'Added regional revenue breakdown' ),\n\tarray( 12, $alex, 'Incorporated CFO feedback on margins' ),\n\tarray( 6, $jane, 'Updated with final Q3 actuals' ),\n\tarray( 2, $maria, 'Reviewed \u2014 ready for board sign-off' ),\n) );\n\n// 2) Final doc.\ns_document( 'Employee Handbook', 'Final', 'employee-handbook.docx', $docx, array(\n\tarray( 40, $alex, 'Migrated 2024 handbook to new template' ),\n\tarray( 25, $maria, 'Updated PTO and remote-work policies' ),\n\tarray( 10, $alex, 'Approved by Legal \u2014 published' ),\n) );\n\n// 3) In progress + currently locked (see lock below).\n$roadmap = s_document( '2026 Product Roadmap', 'In Progress', '2026-product-roadmap.pptx', $pptx, array(\n\tarray( 14, $editor, 'Outlined Q1\u2013Q2 themes' ),\n\tarray( 8, $maria, 'Added engineering capacity estimates' ),\n\tarray( 3, $editor, 'Reordered priorities after planning' ),\n) );\n\n// 4) Fresh draft.\ns_document( 'Board Meeting Minutes \u2014 June', 'Initial Draft', 'board-minutes-june.docx', $docx, array(\n\tarray( 1, $maria, 'First pass \u2014 pending chair review' ),\n) );\n\n// 5) Another final.\ns_document( 'Brand Guidelines', 'Final', 'brand-guidelines.pdf', $pdf, array(\n\tarray( 60, $admin, 'Rebrand rollout \u2014 v1' ),\n\tarray( 30, $admin, 'Added logo clear-space rules' ),\n) );\n\n// Show \"Currently Editing\" in the list: an active lock on the roadmap by Maria.\nupdate_post_meta( $roadmap, '_edit_lock', ( time() + DAY_IN_SECONDS ) . ':' . $maria );\nupdate_post_meta( $roadmap, '_edit_last', $maria );\n\necho \"SEED_OK documents=\" . wp_count_posts( 'document' )->publish;\n"
},
{
"step": "login",
"username": "editor",
"password": "password"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment