{
    "$schema": "https://playground.wordpress.net/blueprint-schema.json",
    "landingPage": "/",
    "preferredVersions": {
        "php": "8.2",
        "wp": "latest"
    },
    "features": {
        "networking": true
    },
    "login": true,
    "steps": [
        {
            "step": "installPlugin",
            "pluginData": {
                "resource": "wordpress.org/plugins",
                "slug": "gallery-showcase"
            },
            "options": {
                "activate": true
            }
        },
        {
            "step": "runPHP",
            "code": "<?php\nrequire_once '/wordpress/wp-load.php';\nrequire_once ABSPATH . 'wp-admin/includes/image.php';\n\n// Generated placeholder images (rather than a bundled sample image file):\n// this plugin ships no photo-like sample asset (only UI chrome - fancybox\n// sprites, lightbox arrows, a background-fallback PNG), and a bundled file\n// would also have to survive .distignore filtering into the real shipped\n// package to be usable here (a prior sibling blueprint pass in this org\n// broke its live demo exactly that way, by referencing a .wordpress-org/\n// display-asset that's excluded from the actual plugin package). Generating\n// the images inline with GD has no such dependency.\nif ( ! function_exists( 'imagecreatetruecolor' ) ) {\n\tthrow new RuntimeException( 'GD library is not available in this Playground PHP build.' );\n}\n\n$upload_dir = wp_upload_dir();\n$colors     = array(\n\tarray(\n\t\t'label' => 'One',\n\t\t'r'     => 220,\n\t\t'g'     => 90,\n\t\t'b'     => 90,\n\t),\n\tarray(\n\t\t'label' => 'Two',\n\t\t'r'     => 90,\n\t\t'g'     => 170,\n\t\t'b'     => 220,\n\t),\n\tarray(\n\t\t'label' => 'Three',\n\t\t'r'     => 120,\n\t\t'g'     => 190,\n\t\t'b'     => 110,\n\t),\n\tarray(\n\t\t'label' => 'Four',\n\t\t'r'     => 230,\n\t\t'g'     => 180,\n\t\t'b'     => 70,\n\t),\n\tarray(\n\t\t'label' => 'Five',\n\t\t'r'     => 170,\n\t\t'g'     => 110,\n\t\t'b'     => 200,\n\t),\n\tarray(\n\t\t'label' => 'Six',\n\t\t'r'     => 90,\n\t\t'g'     => 200,\n\t\t'b'     => 180,\n\t),\n);\n\n/**\n * Generates one solid-color placeholder PNG with a centered label, and\n * registers it as a real media library attachment. PNG rather than JPEG:\n * WordPress Playground's PHP-in-WebAssembly build has unreliable/absent\n * libjpeg support in its bundled GD extension, so imagejpeg() can silently\n * produce a broken or empty file there even though it works fine on a\n * normal server - PNG encoding has no such dependency.\n */\nfunction gs_demo_attachment( $color, $index, $upload_dir ) {\n\t$width  = 640;\n\t$height = 480;\n\t$image  = imagecreatetruecolor( $width, $height );\n\t$bg     = imagecolorallocate( $image, $color['r'], $color['g'], $color['b'] );\n\timagefill( $image, 0, 0, $bg );\n\n\t$white = imagecolorallocate( $image, 255, 255, 255 );\n\t$text  = 'Gallery Showcase Demo ' . $color['label'];\n\t$font  = 5;\n\t$tw    = imagefontwidth( $font ) * strlen( $text );\n\t$th    = imagefontheight( $font );\n\timagestring( $image, $font, (int) ( ( $width - $tw ) / 2 ), (int) ( ( $height - $th ) / 2 ), $text, $white );\n\n\t$filename  = 'gallery-showcase-demo-' . $index . '.png';\n\t$file_path = trailingslashit( $upload_dir['path'] ) . $filename;\n\timagepng( $image, $file_path );\n\timagedestroy( $image );\n\n\t$filetype      = wp_check_filetype( $filename, null );\n\t$attachment_id = wp_insert_attachment(\n\t\tarray(\n\t\t\t'post_mime_type' => $filetype['type'],\n\t\t\t'post_title'     => 'Gallery Showcase Demo Image ' . $color['label'],\n\t\t\t'post_content'   => '',\n\t\t\t'post_status'    => 'inherit',\n\t\t),\n\t\t$file_path\n\t);\n\tif ( is_wp_error( $attachment_id ) ) {\n\t\treturn 0;\n\t}\n\t$attachment_data = wp_generate_attachment_metadata( $attachment_id, $file_path );\n\twp_update_attachment_metadata( $attachment_id, $attachment_data );\n\n\treturn $attachment_id;\n}\n\n$attachment_ids = array();\nforeach ( $colors as $index => $color ) {\n\t$attachment_ids[] = gs_demo_attachment( $color, $index + 1, $upload_dir );\n}\n$attachment_ids = array_filter( $attachment_ids );\n\n$gs_gallery_details = array();\nforeach ( $attachment_ids as $i => $attachment_id ) {\n\t$gs_gallery_details[ $attachment_id ] = array(\n\t\t'title' => 'Demo Photo ' . ( $i + 1 ),\n\t\t'desc'  => 'A generated placeholder image for the Gallery Showcase demo.',\n\t);\n}\n\n$default_options = function_exists( 'gs_default_values' ) ? gs_default_values() : array();\n\n// Layout 1: Grid, 4 columns, all six images, titles shown.\n$grid_ids     = $attachment_ids;\n$grid_details = $gs_gallery_details;\n$grid_options = array_merge(\n\t$default_options,\n\tarray(\n\t\t'layout_type'     => 'grid',\n\t\t'column_desktop'  => 4,\n\t\t'image_size'      => 'full',\n\t\t'display_title'   => 0,\n\t\t'display_content' => 1,\n\t)\n);\n$grid_post_id = wp_insert_post(\n\tarray(\n\t\t'post_title'  => 'Grid Gallery Demo',\n\t\t'post_type'   => 'gs_layouts',\n\t\t'post_status' => 'publish',\n\t\t'post_name'   => 'grid-gallery-demo',\n\t),\n\ttrue\n);\nif ( is_wp_error( $grid_post_id ) ) {\n\tthrow new RuntimeException( $grid_post_id->get_error_message() );\n}\nupdate_post_meta( $grid_post_id, 'gs_gallery_images', implode( ',', $grid_ids ) );\nupdate_post_meta( $grid_post_id, 'gs_gallery_details', $grid_details );\nupdate_post_meta( $grid_post_id, 'gs_optoins', $grid_options );\n\n// Layout 2: Masonry, 3 columns, first four images, titles + descriptions shown.\n$masonry_ids     = array_slice( $attachment_ids, 0, 4 );\n$masonry_details = array_intersect_key( $gs_gallery_details, array_flip( $masonry_ids ) );\n$masonry_options = array_merge(\n\t$default_options,\n\tarray(\n\t\t'layout_type'     => 'masonry',\n\t\t'column_desktop'  => 3,\n\t\t'image_size'      => 'full',\n\t\t'display_title'   => 0,\n\t\t'display_content' => 0,\n\t)\n);\n$masonry_post_id = wp_insert_post(\n\tarray(\n\t\t'post_title'  => 'Masonry Gallery Demo',\n\t\t'post_type'   => 'gs_layouts',\n\t\t'post_status' => 'publish',\n\t\t'post_name'   => 'masonry-gallery-demo',\n\t),\n\ttrue\n);\nif ( is_wp_error( $masonry_post_id ) ) {\n\tthrow new RuntimeException( $masonry_post_id->get_error_message() );\n}\nupdate_post_meta( $masonry_post_id, 'gs_gallery_images', implode( ',', $masonry_ids ) );\nupdate_post_meta( $masonry_post_id, 'gs_gallery_details', $masonry_details );\nupdate_post_meta( $masonry_post_id, 'gs_optoins', $masonry_options );\n\n// Demo page using both shortcodes.\n$page_content = \"<!-- wp:heading --><h2>Grid Layout</h2><!-- /wp:heading -->\\n\\n\"\n\t. '<!-- wp:shortcode -->[gallery_showcase layout=\"grid-gallery-demo\"]<!-- /wp:shortcode -->'\n\t. \"\\n\\n<!-- wp:heading --><h2>Masonry Layout</h2><!-- /wp:heading -->\\n\\n\"\n\t. '<!-- wp:shortcode -->[gallery_showcase layout=\"masonry-gallery-demo\"]<!-- /wp:shortcode -->';\n\n$page_id = wp_insert_post(\n\tarray(\n\t\t'post_title'   => 'Gallery Showcase Demo',\n\t\t'post_status'  => 'publish',\n\t\t'post_type'    => 'page',\n\t\t'post_content' => $page_content,\n\t),\n\ttrue\n);\nif ( is_wp_error( $page_id ) ) {\n\tthrow new RuntimeException( $page_id->get_error_message() );\n}\n\nupdate_option( 'show_on_front', 'page' );\nupdate_option( 'page_on_front', $page_id );\n"
        }
    ]
}
