Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active January 23, 2024 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soderlind/9bfce2ba83215125f92994f97b5c1702 to your computer and use it in GitHub Desktop.
Save soderlind/9bfce2ba83215125f92994f97b5c1702 to your computer and use it in GitHub Desktop.
WordPress Playground blueprint for a block plugin.

Live Preview for Jobbnorge Block

Plugin Previews are now available for opt-in, I've added a live preview to my block plugin

On wordpress.org, there are two things required for a plugin preview button to appear to all users:

  1. A valid blueprint.json file must be provided in the plugins assets/blueprints sub-directory.
  2. The plugin preview must be set to “public” from the plugin’s Advanced view by a committer.

Read the blueprint documentation for more information.

btw:

  1. The blueprint.json below has comments. If you use it as a template. remove the _comment* keys and values.

  2. I know that post id 2 exist, so instead of doing wp_inser_post I do

    wp_update_post( array('ID' => 2, 'post_title'    => 'My Title','post_content'  => '<!-- my content /-->' ) );

    and redirect to post 2.

{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"_comment1": "This is the landing page URL, Also see the runPHP step below",
"landingPage": "/wp-admin/post.php?post=2&action=edit",
"_comment2": "These are the preferred versions for PHP and WordPress",
"preferredVersions": {
"php": "8.1",
"wp": "latest"
},
"_comment3": "These are the PHP extension bundles",
"phpExtensionBundles": [
"_comment3.1": "kitchen-sink = gd, mbstring, iconv, openssl, libxml, xml, dom, simplexml, xmlreader and xmlwriter",
"kitchen-sink"
],
"_comment4": "These are the features",
"features": {
"_comment4.1": "Network access is required. The plugin needs access to the Jobbnorge API",
"networking": true
},
"_comment5": "These are the steps",
"steps": [
{
"_comment5.1": "This is the login step",
"step": "login",
"username": "admin",
"password": "password"
},
{
"_comment5.2": "This is the plugin installation step",
"step": "installPlugin",
"pluginZipFile": {
"resource": "wordpress.org/plugins",
"slug": "jobbnorge-block"
},
"options": {
"activate": true
}
},
{
"_comment5.3": "Use wp_update_post. post ID 2 exists (default sample page), I updated it with my content and made it my landing page",
"step": "runPHP",
"code": "<?php require '/wordpress/wp-load.php'; wp_update_post( array('ID' => 2, 'post_title' => 'Jobbnorge','post_content' => '<!-- wp:dss/jobbnorge {\"employerID\":\"1981,1992,1980,2770,1989,1994,1986,1984,1985,1987,1996,1988,1982,1983,1995,1993,1991\"} /-->' ) );"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment