{
	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
	"landingPage": "/wp-admin/edit.php?post_type=kc_guest",
	"preferredVersions": {
		"php": "8.2",
		"wp": "6.9"
	},
	"steps": [
		{
			"step": "login",
			"username": "admin",
			"password": "password"
		},
		{
			"step": "installPlugin",
			"pluginZipFile": {
				"resource": "wordpress.org/plugins",
				"slug": "koinonia-link"
			},
			"options": {
				"activate": true
			}
		},
		{
			"step": "runPHP",
			"code": "<?php\nrequire_once '/wordpress/wp-load.php';\n\n$user = get_user_by('login', 'admin');\nif ($user) {\n\twp_set_current_user($user->ID);\n}\n\n$active = get_option('active_plugins', array());\n$active = array_values(array_filter($active, function($plugin) {\n\treturn 'kingdom-connect/kingdom-connect.php' !== $plugin;\n}));\nif (!in_array('koinonia-link/koinonia-link.php', $active, true)) {\n\t$active[] = 'koinonia-link/koinonia-link.php';\n}\nupdate_option('active_plugins', $active);\n\nif (!class_exists('KC_Demo_Data')) {\n\t$demo_file = WP_PLUGIN_DIR . '/koinonia-link/includes/class-kc-demo-data.php';\n\tif (file_exists($demo_file)) {\n\t\trequire_once $demo_file;\n\t}\n}\n\nif (class_exists('KC_Demo_Data')) {\n\tif (!class_exists('WP_REST_Request')) {\n\t\t$rest_paths = array(\n\t\t\tABSPATH . 'wp-includes/rest-api.php',\n\t\t\tABSPATH . 'wp-includes/class-wp-rest-request.php'\n\t\t);\n\t\tforeach ($rest_paths as $path) {\n\t\t\tif (file_exists($path)) {\n\t\t\t\trequire_once $path;\n\t\t\t}\n\t\t}\n\t}\n\tif (class_exists('WP_REST_Request')) {\n\t\t$request = new WP_REST_Request('POST', '/koinonia-link/v1/demo-data/generate');\n\t\t$request->set_param('delete_existing', 'true');\n\t\tKC_Demo_Data::get_instance()->rest_generate_demo_data($request);\n\t}\n}\n\n$home_page = get_page_by_path('welcome-home');\nif ($home_page && !is_wp_error($home_page)) {\n\tupdate_option('show_on_front', 'page');\n\tupdate_option('page_on_front', $home_page->ID);\n}\n\n$church_name = 'Koinonia Link Church';\n$church_address = '123 Kingdom Way, Faith City, ST 12345';\n$church_phone = '(555) 555-5555';\n$primary_contact = $user ? $user->ID : 1;\nupdate_option('kingdom_connect_church_name', $church_name);\nupdate_option('kingdom_connect_church_address', $church_address);\nupdate_option('kingdom_connect_church_phone', $church_phone);\nupdate_option('kc_primary_contact', $primary_contact);\nupdate_option('kc_church_worship_style', 'contemporary');\n\n$find_page_by_title = function($title) {\n\t$query = new WP_Query(\n\t\tarray(\n\t\t\t'post_type' => 'page',\n\t\t\t'post_status' => array('publish', 'private', 'draft'),\n\t\t\t's' => $title,\n\t\t\t'posts_per_page' => 50,\n\t\t\t'no_found_rows' => true,\n\t\t\t'fields' => 'ids'\n\t\t)\n\t);\n\tforeach ($query->posts as $page_id) {\n\t\t$page = get_post($page_id);\n\t\tif ($page && $page->post_title === $title) {\n\t\t\treturn absint($page_id);\n\t\t}\n\t}\n\treturn 0;\n};\n\n$ensure_page = function($title, $content, $status, $slug, $template) use ($find_page_by_title) {\n\t$existing_id = $find_page_by_title($title);\n\tif ($existing_id) {\n\t\tif (!empty($template)) {\n\t\t\tupdate_post_meta($existing_id, '_wp_page_template', $template);\n\t\t}\n\t\treturn $existing_id;\n\t}\n\n\t$page_data = array(\n\t\t'post_title' => $title,\n\t\t'post_content' => $content,\n\t\t'post_status' => $status,\n\t\t'post_type' => 'page'\n\t);\n\tif (!empty($slug)) {\n\t\t$page_data['post_name'] = $slug;\n\t}\n\t$page_id = wp_insert_post($page_data, true);\n\tif (!is_wp_error($page_id) && $page_id > 0 && !empty($template)) {\n\t\tupdate_post_meta($page_id, '_wp_page_template', $template);\n\t}\n\treturn (!is_wp_error($page_id) && $page_id > 0) ? $page_id : 0;\n};\n\n$events_id = 0;\n$sermons_id = 0;\n$member_portal_id = 0;\n\n$visit_id = $ensure_page('Plan Your Visit', '<!-- wp:koinonia-link/plan-your-visit /-->' . \"\\n\" . '[kc_plan_visit]', 'publish', '', 'template-plan-visit.php');\nif ($visit_id) {\n\tupdate_option('kc_plan_your_visit_page_id', $visit_id);\n}\n\n$directory_id = $ensure_page('Church Directory', '<h2>Church Directory</h2>\\n<p>Connect with members of our church family.</p>\\n[kc_guest_directory]', 'publish', '', '');\nif ($directory_id) {\n\tupdate_option('kc_directory_page_id', $directory_id);\n}\n\n$groups_id = $ensure_page('Small Groups', '<h2>Small Groups</h2>\\n<p>Find a small group that fits your schedule and interests.</p>\\n[kc_small_groups]', 'publish', '', '');\nif ($groups_id) {\n\tupdate_option('kc_groups_page_id', $groups_id);\n}\n\nif (post_type_exists('kc_event')) {\n\t$events_id = $ensure_page('Events', '<h2>Upcoming Events</h2>\\n<p>Join us for these upcoming events and activities.</p>\\n[kc_events]', 'publish', '', '');\n\tif ($events_id) {\n\t\tupdate_option('kc_events_page_id', $events_id);\n\t}\n}\n\nif (post_type_exists('kc_sermon')) {\n\t$sermons_id = $ensure_page('Sermons', '<h2>Sermons</h2>\\n<p>Listen to our recent sermons and teachings.</p>\\n[kc_sermons]', 'publish', '', '');\n\tif ($sermons_id) {\n\t\tupdate_option('kc_sermons_page_id', $sermons_id);\n\t}\n}\n\n$give_id = $ensure_page('Give', '<h2>Give</h2>\\n<p>Thank you for your generous support of our ministry.</p>\\n[kc_give]', 'publish', '', '');\nif ($give_id) {\n\tupdate_option('kc_give_page_id', $give_id);\n}\n\n$my_giving_id = $ensure_page('My Giving', '<h2>My Giving History</h2>\\n[kc_my_giving]', 'private', '', '');\nif ($my_giving_id) {\n\tupdate_option('kc_my_giving_page_id', $my_giving_id);\n}\n\n$leader_portal_id = $ensure_page('Leader Portal', '<h2>Leader Portal</h2>\\n[kc_leader_toolkit]', 'private', '', '');\nif ($leader_portal_id) {\n\tupdate_option('kc_leader_portal_page_id', $leader_portal_id);\n}\n\n$kiosk_id = $ensure_page('Child Check-In Kiosk', '[kc_checkin_kiosk]', 'publish', 'child-check-in-kiosk', '');\nif ($kiosk_id) {\n\tupdate_option('kc_checkin_kiosk_page_id', $kiosk_id);\n}\n\n$volunteer_id = $ensure_page('Volunteer Portal', '<h2>Classroom Roster</h2>\\n[kc_live_roster]', 'private', 'volunteer-portal', '');\nif ($volunteer_id) {\n\tupdate_option('kc_page_id_volunteer_portal', $volunteer_id);\n}\n\n$group_map_id = $ensure_page('Find a Group', '<h2>Find a Small Group Near You</h2>\\n<p>Use our interactive map to find small groups close to your location.</p>\\n[kc_group_map]', 'publish', 'find-a-group', '');\nif ($group_map_id) {\n\tupdate_option('kc_group_map_page_id', $group_map_id);\n}\n\n$connection_id = $ensure_page('Connect With Us', '<h2>Connect With Us</h2>\\n<p>Fill out this form to get connected with our church community.</p>\\n[kc_connect_card]', 'publish', 'connect-with-us', '');\nif ($connection_id) {\n\tupdate_option('kc_connection_card_page_id', $connection_id);\n}\n\nif (function_exists('shortcode_exists') && shortcode_exists('kc_member_portal')) {\n\t$member_portal_id = $ensure_page('My Church', '<h2>My Church</h2>\\n<p>Manage your profile, view your groups, track your giving, and see your serving schedule.</p>\\n[kc_member_portal]', 'private', 'my-church', '');\n\tif ($member_portal_id) {\n\t\tupdate_option('kc_member_portal_page_id', $member_portal_id);\n\t}\n}\n\n$menu_name = 'Koinonia Link Menu';\n$menu = wp_get_nav_menu_object($menu_name);\n$menu_id = $menu ? $menu->term_id : wp_create_nav_menu($menu_name);\nif (!is_wp_error($menu_id) && $menu_id) {\n\t$items = wp_get_nav_menu_items($menu_id);\n\t$existing = array();\n\tif (!empty($items)) {\n\t\tforeach ($items as $item) {\n\t\t\tif (!empty($item->object_id)) {\n\t\t\t\t$existing[(int) $item->object_id] = true;\n\t\t\t}\n\t\t}\n\t}\n\n\t$add_page = function($page_id) use ($menu_id, &$existing) {\n\t\tif (empty($page_id) || isset($existing[$page_id])) {\n\t\t\treturn;\n\t\t}\n\t\twp_update_nav_menu_item(\n\t\t\t$menu_id,\n\t\t\t0,\n\t\t\tarray(\n\t\t\t\t'menu-item-object-id' => $page_id,\n\t\t\t\t'menu-item-object' => 'page',\n\t\t\t\t'menu-item-type' => 'post_type',\n\t\t\t\t'menu-item-status' => 'publish'\n\t\t\t)\n\t\t);\n\t\t$existing[$page_id] = true;\n\t};\n\n\t$add_page($visit_id);\n\t$add_page($groups_id);\n\t$add_page($events_id);\n\t$add_page($sermons_id);\n\t$add_page($give_id);\n\t$add_page($kiosk_id);\n\t$add_page($connection_id);\n\n\t$locations = get_nav_menu_locations();\n\tif (!empty($locations)) {\n\t\t$assigned = false;\n\t\tforeach ($locations as $location => $assigned_menu) {\n\t\t\tif (empty($assigned_menu)) {\n\t\t\t\t$locations[$location] = $menu_id;\n\t\t\t\t$assigned = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!$assigned && array_key_exists('primary', $locations) && empty($locations['primary'])) {\n\t\t\t$locations['primary'] = $menu_id;\n\t\t}\n\t\tset_theme_mod('nav_menu_locations', $locations);\n\t}\n}\n\nupdate_option('kc_setup_complete', true);"
		}
	]
}
