Skip to content

Commit 49f53db

Browse files
committed
add blueprint.json and files used to manage the php code that goes into runPHP step
1 parent 7ead000 commit 49f53db

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"landingPage": "/sample-page/",
3+
"preferredVersions": {
4+
"php": "8.0",
5+
"wp": "latest"
6+
},
7+
"steps": [
8+
{
9+
"step": "login",
10+
"username": "admin",
11+
"password": "password"
12+
},
13+
{
14+
"step": "setSiteOptions",
15+
"options": {
16+
"permalink_structure": "/%year%/%monthnum%/%day%/%postname%/"
17+
}
18+
},
19+
{
20+
"step": "installPlugin",
21+
"pluginZipFile": {
22+
"resource": "wordpress.org/plugins",
23+
"slug": "chatrix"
24+
}
25+
},
26+
{
27+
"step": "runPHP",
28+
"code": "<?php\n\nrequire_once 'wordpress/wp-load.php';\n\n$chatrix_block_simple = '<!-- wp:paragraph --> <p>Below you can see \"Chatrix\" block in action. You can add it anywhere using either <code>/chatrix</code> or by looking up chatrix when choosing which block to insert.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>Even though its not functional in this Playground demo, since it requires its own service worker and that is not compatible with the Playground (running WordPress in your browser) at the moment, you can at least see how it looks and it can be added anywhere you can add a Gutenberg block :)</p> <!-- /wp:paragraph --> <!-- wp:automattic/chatrix {\"instanceId\":\"2530674218113325\",\"defaultHomeserver\":\"matrix.org\"} /-->';\n\n$chatrix_block_2col = <<<CHATRIXBLOCK2COLUMNS\n<!-- wp:paragraph -->\n<p>Below you can see “Chatrix” block in action. You can add it anywhere using either&nbsp;<code>/chatrix</code>&nbsp;or by looking up chatrix when choosing which block to insert.</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:columns -->\n<div class=\"wp-block-columns\">\n<!-- wp:column {\"width\":\"33.33%\"} -->\n<div class=\"wp-block-column\" style=\"flex-basis:33.33%\">\n<!-- wp:paragraph -->\n<p>Here can be some login instructions of participating in the chat window on the right side:</p>\n<!-- /wp:paragraph -->\n</div>\n<!-- /wp:column -->\n<!-- wp:column {\"width\":\"66.66%\"} -->\n<div class=\"wp-block-column\" style=\"flex-basis:66.66%\">\n<!-- wp:automattic/chatrix {\"instanceId\":\"4986644425212020\",\"defaultHomeserver\":\"matrix.org\"} /-->\n</div>\n<!-- /wp:column -->\n</div>\n<!-- /wp:columns -->\n\n<!-- wp:paragraph -->\n<p>Unfortunately, it's not possible to login into Matrix inside of Playground demo, since it requires its own service worker and that is not compatible with the Playground at the moment. You can explore how it looks and how it can be added anywhere you can add a Gutenberg block :)</p>\n<!-- /wp:paragraph -->\nCHATRIXBLOCK2COLUMNS;\n\n$sample_page_post_id = 2;\n\nwp_update_post( array(\n 'ID' => $sample_page_post_id,\n 'post_title' => 'Chatrix [Regular]',\n 'post_content' => $chatrix_block_simple\n) );\n\nwp_insert_post( array(\n 'ID' => 3,\n 'post_title' => 'Chatrix [2 Column]',\n 'post_type' => 'page',\n 'post_status' => 'publish',\n 'post_content' => $chatrix_block_2col\n) );\n\nwp_insert_post( array(\n 'ID' => 4,\n 'post_title' => 'Chatrix [Popup]',\n 'post_type' => 'page',\n 'post_status' => 'publish',\n 'post_content' => '<!-- wp:paragraph --> <p>On this page, you can see the popup widget at the bottom right of your screen. Click on it to show Chatrix.</p> <!-- /wp:paragraph -->'\n) );\n\nupdate_option( 'chatrix_settings', array(\n 'homeserver' => 'matrix.org',\n 'room' => '#matrix:matrix.org',\n 'show_on' => 'specific',\n 'pages' => array(\n 0 => '4'\n )\n) );",
29+
"progress": {
30+
"caption": "Setting Chatrix instances"
31+
}
32+
}
33+
]
34+
}

.wporg/assets/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Run `update_blueprint.sh` after making changes in `blueprint_runphp_step_code.php` so that `.wporg/assets/blueprints/blueprint.json` is updated.
2+
3+
[See blueprint in action on playground](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/automattic/chatrix/main/.wporg/assets/blueprints/blueprint.json)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
require_once 'wordpress/wp-load.php';
4+
5+
$chatrix_block_simple = '<!-- wp:paragraph --> <p>Below you can see "Chatrix" block in action. You can add it anywhere using either <code>/chatrix</code> or by looking up chatrix when choosing which block to insert.</p> <!-- /wp:paragraph --> <!-- wp:paragraph --> <p>Even though its not functional in this Playground demo, since it requires its own service worker and that is not compatible with the Playground (running WordPress in your browser) at the moment, you can at least see how it looks and it can be added anywhere you can add a Gutenberg block :)</p> <!-- /wp:paragraph --> <!-- wp:automattic/chatrix {"instanceId":"2530674218113325","defaultHomeserver":"matrix.org"} /-->';
6+
7+
$chatrix_block_2col = <<<CHATRIXBLOCK2COLUMNS
8+
<!-- wp:paragraph -->
9+
<p>Below you can see “Chatrix” block in action. You can add it anywhere using either&nbsp;<code>/chatrix</code>&nbsp;or by looking up chatrix when choosing which block to insert.</p>
10+
<!-- /wp:paragraph -->
11+
12+
<!-- wp:columns -->
13+
<div class="wp-block-columns">
14+
<!-- wp:column {"width":"33.33%"} -->
15+
<div class="wp-block-column" style="flex-basis:33.33%">
16+
<!-- wp:paragraph -->
17+
<p>Here can be some login instructions of participating in the chat window on the right side:</p>
18+
<!-- /wp:paragraph -->
19+
</div>
20+
<!-- /wp:column -->
21+
<!-- wp:column {"width":"66.66%"} -->
22+
<div class="wp-block-column" style="flex-basis:66.66%">
23+
<!-- wp:automattic/chatrix {"instanceId":"4986644425212020","defaultHomeserver":"matrix.org"} /-->
24+
</div>
25+
<!-- /wp:column -->
26+
</div>
27+
<!-- /wp:columns -->
28+
29+
<!-- wp:paragraph -->
30+
<p>Unfortunately, it's not possible to login into Matrix inside of Playground demo, since it requires its own service worker and that is not compatible with the Playground at the moment. You can explore how it looks and how it can be added anywhere you can add a Gutenberg block :)</p>
31+
<!-- /wp:paragraph -->
32+
CHATRIXBLOCK2COLUMNS;
33+
34+
$sample_page_post_id = 2;
35+
36+
wp_update_post( array(
37+
'ID' => $sample_page_post_id,
38+
'post_title' => 'Chatrix [Regular]',
39+
'post_content' => $chatrix_block_simple
40+
) );
41+
42+
wp_insert_post( array(
43+
'ID' => 3,
44+
'post_title' => 'Chatrix [2 Column]',
45+
'post_type' => 'page',
46+
'post_status' => 'publish',
47+
'post_content' => $chatrix_block_2col
48+
) );
49+
50+
wp_insert_post( array(
51+
'ID' => 4,
52+
'post_title' => 'Chatrix [Popup]',
53+
'post_type' => 'page',
54+
'post_status' => 'publish',
55+
'post_content' => '<!-- wp:paragraph --> <p>On this page, you can see the popup widget at the bottom right of your screen. Click on it to show Chatrix.</p> <!-- /wp:paragraph -->'
56+
) );
57+
58+
update_option( 'chatrix_settings', array(
59+
'homeserver' => 'matrix.org',
60+
'room' => '#matrix:matrix.org',
61+
'show_on' => 'specific',
62+
'pages' => array(
63+
0 => '4'
64+
)
65+
) );

.wporg/update_blueprint.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
if ! command -v jq &> /dev/null ; then
4+
echo "jq is not installed. Please install jq (https://jqlang.github.io/jq/) before running this script."
5+
fi
6+
7+
# Get the directory of the script
8+
script_dir="$(dirname "$(readlink -f "$0")")"
9+
10+
blueprint_location="$script_dir/assets/blueprints/blueprint.json"
11+
phpsrc_location="$script_dir/blueprint_runphp_step_code.php"
12+
13+
jq --arg newCode "$(cat $phpsrc_location)" '.steps[] |= if .step == "runPHP" then .code = $newCode else . end' $blueprint_location > updated_blueprint.json
14+
15+
rm $blueprint_location
16+
mv updated_blueprint.json $blueprint_location

0 commit comments

Comments
 (0)