{
	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
	"preferredVersions": {
		"php": "8.0",
		"wp": "latest"
	},
	"features": {
		"networking": true
	},
	"steps": [
		{
			"step": "login",
			"username": "admin"
		},
		{
			"step": "installPlugin",
			"pluginData": {
				"resource": "wordpress.org/plugins",
				"slug": "inline-context"
			},
			"options": {
				"activate": true
			}
		},
		{
			"step": "runPHP",
			"code": "<?php\nrequire_once 'wordpress/wp-load.php';\n\n// Create default categories for inline context\n$categories = array(\n    array(\n        'name' => 'Internal Article',\n        'slug' => 'internal-article',\n        'meta' => array(\n            'icon_closed' => 'dashicons-admin-links',\n            'icon_open' => 'dashicons-admin-links',\n            'color' => '#0073aa'\n        )\n    ),\n    array(\n        'name' => 'External Article',\n        'slug' => 'external-article',\n        'meta' => array(\n            'icon_closed' => 'dashicons-external',\n            'icon_open' => 'dashicons-external',\n            'color' => '#00a32a'\n        )\n    ),\n    array(\n        'name' => 'Definition',\n        'slug' => 'definition',\n        'meta' => array(\n            'icon_closed' => 'dashicons-book',\n            'icon_open' => 'dashicons-book-alt',\n            'color' => '#826eb4'\n        )\n    ),\n    array(\n        'name' => 'Tip',\n        'slug' => 'tip',\n        'meta' => array(\n            'icon_closed' => 'dashicons-lightbulb',\n            'icon_open' => 'dashicons-lightbulb',\n            'color' => '#f0b849'\n        )\n    )\n);\n\n$created_terms = array();\nforeach ( $categories as $cat ) {\n    $term = wp_insert_term( $cat['name'], 'inline_context_category', array( 'slug' => $cat['slug'] ) );\n    if ( ! is_wp_error( $term ) ) {\n        foreach ( $cat['meta'] as $key => $value ) {\n            update_term_meta( $term['term_id'], $key, $value );\n        }\n        $created_terms[$cat['slug']] = $term['term_id'];\n    }\n}\n\necho 'Demo categories created successfully: ' . count($created_terms);\n?>"
		},
		{
			"step": "runPHP",
			"code": "<?php\nrequire_once 'wordpress/wp-load.php';\n\n// Get category IDs\n$internal_term = get_term_by('slug', 'internal-article', 'inline_context_category');\n$external_term = get_term_by('slug', 'external-article', 'inline_context_category');\n$definition_term = get_term_by('slug', 'definition', 'inline_context_category');\n$tip_term = get_term_by('slug', 'tip', 'inline_context_category');\n\n// Create reusable inline context notes with links\n$notes = array(\n    array(\n        'title' => 'What is Blockchain?',\n        'content' => '<p>A <strong>blockchain</strong> is a distributed ledger technology that maintains a secure and decentralized record of transactions. <a href=\"https://en.wikipedia.org/wiki/Blockchain\" target=\"_blank\" rel=\"noopener noreferrer\">Learn more about blockchain on Wikipedia</a>.</p>',\n        'category' => $external_term ? array( $external_term->term_id ) : array(),\n        'reusable' => true,\n    ),\n    array(\n        'title' => 'Photosynthesis Explained',\n        'content' => '<p>Photosynthesis is the process by which plants convert light energy into chemical energy, producing oxygen as a byproduct. For a detailed explanation, see <a href=\"#getting-started\">our Getting Started section below</a>.</p>',\n        'category' => $internal_term ? array( $internal_term->term_id ) : array(),\n        'reusable' => true,\n    ),\n    array(\n        'title' => 'Machine Learning Definition',\n        'content' => '<p><strong>Machine learning</strong> is a subset of artificial intelligence that enables computers to learn from data without being explicitly programmed. It uses algorithms to identify patterns and make predictions.</p>',\n        'category' => $definition_term ? array( $definition_term->term_id ) : array(),\n        'reusable' => true,\n    ),\n    array(\n        'title' => 'Quick Start Tip',\n        'content' => '<p><strong>Pro tip:</strong> You can create reusable notes and use them across multiple posts! Check out the <a href=\"/wp-admin/edit.php?post_type=inline_context_note\">Notes Library</a> in your admin panel to manage all your inline context notes.</p>',\n        'category' => $tip_term ? array( $tip_term->term_id ) : array(),\n        'reusable' => true,\n    ),\n);\n\n$note_ids = array();\nforeach ( $notes as $note ) {\n    $post_id = wp_insert_post( array(\n        'post_title'   => $note['title'],\n        'post_content' => $note['content'],\n        'post_status'  => 'publish',\n        'post_type'    => 'inline_context_note',\n    ) );\n    \n    if ( $post_id && ! is_wp_error( $post_id ) ) {\n        update_post_meta( $post_id, 'is_reusable', $note['reusable'] );\n        update_post_meta( $post_id, 'used_in_posts', array() );\n        update_post_meta( $post_id, 'usage_count', 0 );\n        if ( ! empty( $note['category'] ) ) {\n            wp_set_object_terms( $post_id, $note['category'], 'inline_context_category', false );\n        }\n        $note_ids[$note['title']] = $post_id;\n    }\n}\n\necho 'Created ' . count($note_ids) . ' reusable inline context notes with categories and links';\n?>"
		},
		{
			"step": "runPHP",
			"code": "<?php\nrequire_once 'wordpress/wp-load.php';\n\n// Get the note IDs we just created\n$blockchain_note = get_page_by_title( 'What is Blockchain?', OBJECT, 'inline_context_note' );\n$photosynthesis_note = get_page_by_title( 'Photosynthesis Explained', OBJECT, 'inline_context_note' );\n$ml_note = get_page_by_title( 'Machine Learning Definition', OBJECT, 'inline_context_note' );\n$tip_note = get_page_by_title( 'Quick Start Tip', OBJECT, 'inline_context_note' );\n\n// Get category IDs for each note\n$blockchain_cats = wp_get_object_terms( $blockchain_note->ID, 'inline_context_category', array('fields' => 'ids') );\n$photosynthesis_cats = wp_get_object_terms( $photosynthesis_note->ID, 'inline_context_category', array('fields' => 'ids') );\n$ml_cats = wp_get_object_terms( $ml_note->ID, 'inline_context_category', array('fields' => 'ids') );\n$tip_cats = wp_get_object_terms( $tip_note->ID, 'inline_context_category', array('fields' => 'ids') );\n\n$blockchain_cat_id = ! empty( $blockchain_cats ) ? $blockchain_cats[0] : '';\n$photosynthesis_cat_id = ! empty( $photosynthesis_cats ) ? $photosynthesis_cats[0] : '';\n$ml_cat_id = ! empty( $ml_cats ) ? $ml_cats[0] : '';\n$tip_cat_id = ! empty( $tip_cats ) ? $tip_cats[0] : '';\n\n// Create demo post using the actual notes\n$post_content = '<!-- wp:paragraph -->\n<p>Modern technology is rapidly evolving. The <a class=\"wp-inline-context\" data-note-id=\"' . ($blockchain_note ? $blockchain_note->ID : '') . '\" data-category-id=\"' . $blockchain_cat_id . '\" data-inline-context=\"' . esc_attr( $blockchain_note ? $blockchain_note->post_content : '' ) . '\" data-anchor-id=\"context-note-blockchain\" href=\"#context-note-blockchain\" role=\"button\" aria-expanded=\"false\">blockchain</a> is revolutionizing digital transactions and creating new possibilities for secure, decentralized systems.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>In the natural world, <a class=\"wp-inline-context\" data-note-id=\"' . ($photosynthesis_note ? $photosynthesis_note->ID : '') . '\" data-category-id=\"' . $photosynthesis_cat_id . '\" data-inline-context=\"' . esc_attr( $photosynthesis_note ? $photosynthesis_note->post_content : '' ) . '\" data-anchor-id=\"context-note-photosynthesis\" href=\"#context-note-photosynthesis\" role=\"button\" aria-expanded=\"false\">photosynthesis</a> plays a crucial role in maintaining Earth&#8217;s atmosphere and supporting the entire ecosystem.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>The concept of <a class=\"wp-inline-context\" data-note-id=\"' . ($ml_note ? $ml_note->ID : '') . '\" data-category-id=\"' . $ml_cat_id . '\" data-inline-context=\"' . esc_attr( $ml_note ? $ml_note->post_content : '' ) . '\" data-anchor-id=\"context-note-machine-learning\" href=\"#context-note-machine-learning\" role=\"button\" aria-expanded=\"false\">machine learning</a> has transformed modern technology and is powering innovations across every industry.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:heading {\"level\":2} -->\n<h2 class=\"wp-block-heading\" id=\"getting-started\">Getting Started</h2>\n<!-- /wp:heading -->\n\n<!-- wp:paragraph -->\n<p>Click any underlined term above to reveal its context note. Notice how some notes contain external links (opening in new tabs) while others have internal links (staying on the same page). <a class=\"wp-inline-context\" data-note-id=\"' . ($tip_note ? $tip_note->ID : '') . '\" data-category-id=\"' . $tip_cat_id . '\" data-inline-context=\"' . esc_attr( $tip_note ? $tip_note->post_content : '' ) . '\" data-anchor-id=\"context-note-tip\" href=\"#context-note-tip\" role=\"button\" aria-expanded=\"false\">Click here for a quick tip</a> about managing your notes.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p>These notes are created as reusable Custom Post Type entries that can be used across multiple posts. Try editing this post in the block editor to see how easy it is to search for and insert existing notes!</p>\n<!-- /wp:paragraph -->\n';\n\n$demo_post = array(\n    'post_title'    => 'Welcome to Inline Context Demo',\n    'post_content'  => $post_content,\n    'post_status'   => 'publish',\n    'post_author'   => 1,\n    'post_type'     => 'post',\n);\n\n$post_id = wp_insert_post( $demo_post );\n\nif ( ! $post_id || is_wp_error( $post_id ) ) {\n    echo 'Failed to create demo post';\n    return;\n}\n\n// Update usage tracking for the notes\n$notes_to_track = array(\n    array( 'note' => $blockchain_note, 'count' => 1 ),\n    array( 'note' => $photosynthesis_note, 'count' => 1 ),\n    array( 'note' => $ml_note, 'count' => 1 ),\n    array( 'note' => $tip_note, 'count' => 1 ),\n);\n\nforeach ( $notes_to_track as $item ) {\n    $note = $item['note'];\n    if ( $note && ! is_wp_error( $note ) ) {\n        // Get existing usage data\n        $used_in = get_post_meta( $note->ID, 'used_in_posts', true );\n        if ( ! is_array( $used_in ) ) {\n            $used_in = array();\n        }\n        \n        // Add this post ID if not already tracked\n        if ( ! in_array( $post_id, $used_in, true ) ) {\n            $used_in[] = $post_id;\n        }\n        \n        // Update meta fields\n        update_post_meta( $note->ID, 'used_in_posts', $used_in );\n        update_post_meta( $note->ID, 'usage_count', count( $used_in ) );\n    }\n}\n\necho 'Demo post created with ID: ' . $post_id . ' using 4 reusable notes with categories and usage tracking';\n?>"
		},
		{
			"step": "runPHP",
			"code": "<?php\nrequire_once 'wordpress/wp-load.php';\n\n// Get the demo post we just created\n$demo_post = get_page_by_title( 'Welcome to Inline Context Demo', OBJECT, 'post' );\n\nif ( $demo_post ) {\n    // Re-save the post to trigger WordPress save hooks and plugin sync\n    wp_update_post( array(\n        'ID' => $demo_post->ID,\n        'post_content' => $demo_post->post_content,\n    ) );\n    \n    echo 'Demo post re-saved with ID: ' . $demo_post->ID . ' to trigger usage tracking sync';\n} else {\n    echo 'Demo post not found for re-save';\n}\n?>"
		},
		{
			"step": "setSiteOptions",
			"options": {
				"blogname": "Inline Context Demo",
				"blogdescription": "Try the Inline Context plugin on WordPress Playground"
			}
		}
	]
}
