{
  "$schema": "https://playground.wordpress.net/blueprint-schema.json",
  "meta": {
    "title": "Adminkeep preview",
    "description": "Installs Adminkeep from wordpress.org, switches on a few features that show well, sends some sample emails through wp_mail() and opens the Email Log.",
    "author": "shazzad"
  },
  "landingPage": "/wp-admin/admin.php?page=adminkeep-email-log",
  "preferredVersions": {
    "php": "8.3",
    "wp": "latest"
  },
  "steps": [
    {
      "step": "login",
      "username": "admin"
    },
    {
      "step": "installPlugin",
      "pluginData": {
        "resource": "wordpress.org/plugins",
        "slug": "adminkeep"
      },
      "options": {
        "activate": true
      }
    },
    {
      "step": "runPHP",
      "code": "<?php\nrequire_once '/wordpress/wp-load.php';\n\n// The same writers the settings screen, the REST route and `wp adminkeep` use, so the preview\n// stores exactly what a real site would.\n$registry = \\Adminkeep\\Plugin::instance()->registry();\n$writer   = new \\Adminkeep\\Service\\SettingsWriter( $registry );\n\nforeach ( array( 'disable_comments', 'registration_lock', 'username_privacy', 'custom_css', 'header_footer_code', 'duplicate', 'email_log', 'nice_emails' ) as $feature_id ) {\n\t$feature = $registry->get( $feature_id );\n\n\tif ( $feature ) {\n\t\t$writer->set_enabled( $feature, true );\n\t}\n}\n\n\\Adminkeep\\Feature\\CustomCss::save(\n\t\"/* Saved with Adminkeep. Edit it under Appearance > Custom CSS. */\\n\" .\n\t\"body::before {\\n\" .\n\t\"\\tcontent: \\\"This bar comes from Adminkeep's Custom CSS\\\";\\n\" .\n\t\"\\tdisplay: block;\\n\" .\n\t\"\\tpadding: 8px 16px;\\n\" .\n\t\"\\tbackground: #1e1e1e;\\n\" .\n\t\"\\tcolor: #fff;\\n\" .\n\t\"\\tfont: 14px/1.4 system-ui, sans-serif;\\n\" .\n\t\"\\ttext-align: center;\\n\" .\n\t\"}\\n\"\n);\n\n\\Adminkeep\\Feature\\HeaderFooterCode::save(\n\tarray(\n\t\t'head'   => '<!-- Adminkeep preview: this comment was added under Appearance > Header & Footer Code (page head). -->',\n\t\t'footer' => '<!-- Adminkeep preview: this comment was added under Appearance > Header & Footer Code (footer). -->',\n\t),\n\t1\n);\n"
    },
    {
      "step": "runPHP",
      "code": "<?php\n// A request of its own: Email Log and Nice Default Emails were switched on by the step before, so\n// this load boots them the normal way and every email below goes through their real hooks.\nrequire_once '/wordpress/wp-load.php';\nrequire_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';\nrequire_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';\nrequire_once ABSPATH . WPINC . '/PHPMailer/Exception.php';\n\n// Playground cannot deliver mail. wp_mail() reuses $phpmailer when it already holds a PHPMailer,\n// so this one builds each message as usual and reports it accepted without sending anything;\n// wp_mail_succeeded then fires and the log marks the row Sent.\nclass Adminkeep_Preview_Mailer extends \\PHPMailer\\PHPMailer\\PHPMailer {\n\tpublic function postSend() {\n\t\treturn true;\n\t}\n}\n\n$GLOBALS['phpmailer'] = new Adminkeep_Preview_Mailer( true );\n\n// WordPress sends its own email from wordpress@ plus the site's host, and a Playground host such\n// as 127.0.0.1 is not an address PHPMailer accepts. Only that default is replaced; an email that\n// names its own sender keeps it.\nadd_filter(\n\t'wp_mail_from',\n\tstatic function ( $from ) {\n\t\treturn 0 === strpos( $from, 'wordpress@' ) ? 'wordpress@example.com' : $from;\n\t}\n);\n\n// Example addresses throughout, and the documentation IP core quotes in the reset email, since a\n// blueprint step has no visitor to take one from.\nupdate_option( 'admin_email', 'admin@example.com' );\n\nif ( empty( $_SERVER['REMOTE_ADDR'] ) ) {\n\t$_SERVER['REMOTE_ADDR'] = '203.0.113.24';\n}\n\n// Core account emails, which Nice Default Emails dresses in the HTML layout. The reset link in\n// the second one is taken out by Email Log before it is stored.\n$demo_user = username_exists( 'demo' );\n\nif ( ! $demo_user ) {\n\t$demo_user = wp_insert_user(\n\t\tarray(\n\t\t\t'user_login' => 'demo',\n\t\t\t'user_email' => 'demo@example.org',\n\t\t\t'user_pass'  => wp_generate_password( 24 ),\n\t\t\t'role'       => 'subscriber',\n\t\t)\n\t);\n}\n\nif ( ! is_wp_error( $demo_user ) ) {\n\twp_new_user_notification( $demo_user, null, 'admin' );\n\tretrieve_password( 'demo' );\n}\n\n// A contact-form plugin's email: plain text from a plugin, so it is logged as it was sent.\nwp_mail(\n\t'hello@example.com',\n\t'New message from your website',\n\t\"Name: Alex Example\\n\" .\n\t\"Email: alex@example.org\\n\\n\" .\n\t\"Message:\\n\" .\n\t\"Hi there, do you ship to Canada? I'd like to order two of the ceramic mugs.\\n\\n\" .\n\t\"--\\n\" .\n\t\"Sent from the contact form on your website.\",\n\tarray(\n\t\t'From: Example Store <forms@example.com>',\n\t\t'Reply-To: Alex Example <alex@example.org>',\n\t)\n);\n\n// A shop's HTML order confirmation, logged with its markup and shown rendered in the preview.\n$order_html = '<!DOCTYPE html><html><body style=\"margin:0;padding:24px;background:#f0f2f5;font-family:Helvetica,Arial,sans-serif;color:#1d2327;\">'\n\t. '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"max-width:560px;margin:0 auto;background:#ffffff;border-radius:6px;overflow:hidden;\">'\n\t. '<tr><td style=\"background:#2271b1;padding:28px 32px;color:#ffffff;\">'\n\t. '<div style=\"font-size:13px;letter-spacing:.08em;text-transform:uppercase;opacity:.85;\">Example Store</div>'\n\t. '<h1 style=\"margin:6px 0 0;font-size:24px;font-weight:600;\">Thanks for your order</h1>'\n\t. '</td></tr>'\n\t. '<tr><td style=\"padding:28px 32px;\">'\n\t. '<p style=\"margin:0 0 16px;font-size:15px;line-height:1.5;\">Hi Sam, we have received order <strong>#1042</strong> and are getting it ready. We will email you again when it ships.</p>'\n\t. '<table role=\"presentation\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"font-size:14px;border-collapse:collapse;\">'\n\t. '<tr><th align=\"left\" style=\"padding:8px 0;border-bottom:2px solid #dcdcde;\">Item</th><th align=\"center\" style=\"padding:8px 0;border-bottom:2px solid #dcdcde;\">Qty</th><th align=\"right\" style=\"padding:8px 0;border-bottom:2px solid #dcdcde;\">Price</th></tr>'\n\t. '<tr><td style=\"padding:10px 0;border-bottom:1px solid #f0f0f1;\">Ceramic mug, sea green</td><td align=\"center\" style=\"padding:10px 0;border-bottom:1px solid #f0f0f1;\">2</td><td align=\"right\" style=\"padding:10px 0;border-bottom:1px solid #f0f0f1;\">$36.00</td></tr>'\n\t. '<tr><td style=\"padding:10px 0;border-bottom:1px solid #f0f0f1;\">Linen tea towel</td><td align=\"center\" style=\"padding:10px 0;border-bottom:1px solid #f0f0f1;\">1</td><td align=\"right\" style=\"padding:10px 0;border-bottom:1px solid #f0f0f1;\">$14.00</td></tr>'\n\t. '<tr><td colspan=\"2\" style=\"padding:10px 0;\">Shipping</td><td align=\"right\" style=\"padding:10px 0;\">$5.00</td></tr>'\n\t. '<tr><td colspan=\"2\" style=\"padding:12px 0;border-top:2px solid #dcdcde;font-weight:600;\">Total</td><td align=\"right\" style=\"padding:12px 0;border-top:2px solid #dcdcde;font-weight:600;font-size:16px;\">$55.00</td></tr>'\n\t. '</table>'\n\t. '<p style=\"margin:24px 0 0;\"><a href=\"https://shop.example.com/account/orders/1042/\" style=\"display:inline-block;background:#2271b1;color:#ffffff;text-decoration:none;padding:10px 18px;border-radius:4px;font-size:14px;\">View your order</a></p>'\n\t. '</td></tr>'\n\t. '<tr><td style=\"padding:18px 32px;background:#f6f7f7;font-size:12px;color:#646970;\">Example Store &middot; 1 Example Street, Springfield &middot; <a href=\"https://shop.example.com/\" style=\"color:#646970;\">shop.example.com</a></td></tr>'\n\t. '</table></body></html>';\n\nwp_mail(\n\t'Sam Example <sam@example.org>',\n\t'Your Example Store order #1042',\n\t$order_html,\n\tarray(\n\t\t'From: Example Store <orders@example.com>',\n\t\t'Content-Type: text/html; charset=UTF-8',\n\t)\n);\n"
    }
  ]
}
