Compare commits
8 Commits
42345c47b9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 23eb896c71 | |||
| 05c4e67266 | |||
| 5bd7dcd9d2 | |||
| 88b145d6b3 | |||
| b21a0f03aa | |||
| 55c20df3b5 | |||
| 0ed97819fe | |||
| 6fa42e8f45 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -47,3 +47,9 @@ wp-config.php
|
|||||||
# Note: If you wish to whitelist themes,
|
# Note: If you wish to whitelist themes,
|
||||||
# uncomment the next line
|
# uncomment the next line
|
||||||
#/wp-content/themes
|
#/wp-content/themes
|
||||||
|
|
||||||
|
# ---> Node.js
|
||||||
|
/node_modules/
|
||||||
|
/package-lock.json
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
README.md
21
README.md
@@ -2,4 +2,23 @@
|
|||||||
|
|
||||||
# wp-spaceapi-consumer
|
# wp-spaceapi-consumer
|
||||||
|
|
||||||
Small WordPress plugin to consume an SpaceAPI endpoint and indicate on the WordPress website if the Space is Open or Closed
|
Small WordPress plugin to consume an SpaceAPI endpoint and indicate on the WordPress website if the Space is Open or Closed
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### WordPress Editor Block (Gutenberg)
|
||||||
|
|
||||||
|
You can use the `Space Status` block in the WordPress editor to display the status of the SpaceAPI endpoint.
|
||||||
|
|
||||||
|
### Shortcode
|
||||||
|
|
||||||
|
You can use the shortcode `[space_status]` to display the status of the SpaceAPI endpoint on your WordPress site.
|
||||||
|
|
||||||
|
### Widget
|
||||||
|
|
||||||
|
You can also use the widget `SpaceAPI Status` to display the status of the SpaceAPI endpoint in your WordPress sidebar or footer.
|
||||||
|
|
||||||
|
## Changes
|
||||||
|
|
||||||
|
### 0.4.x
|
||||||
|
- Added WordPress Editor Block (Gutenberg) support
|
||||||
21
blocks-register.php
Normal file
21
blocks-register.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
// Exit if accessed directly.
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ssi_register_space_status_block() : void {
|
||||||
|
$asset_path = plugin_dir_path( __FILE__ ) . 'build/space-status';
|
||||||
|
register_block_type( $asset_path, [
|
||||||
|
'render_callback' => 'ssi_render_block',
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
add_action( 'init', 'ssi_register_space_status_block' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server‑side markup for the block.
|
||||||
|
*/
|
||||||
|
function ssi_render_block( array $attributes, string $content ) : string {
|
||||||
|
// Re‑use existing helper & CSS class logic.
|
||||||
|
return ssi_shortcode();
|
||||||
|
}
|
||||||
15
build/space-status/block.json
Normal file
15
build/space-status/block.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"apiVersion": 3,
|
||||||
|
"name": "wp-spaceapi-consumer/space-status",
|
||||||
|
"title": "Space Status",
|
||||||
|
"description": "Show whether the space is open or closed (SpaceAPI consumer).",
|
||||||
|
"category": "widgets",
|
||||||
|
"icon": "building",
|
||||||
|
"textdomain": "wp-spaceapi-consumer",
|
||||||
|
"style": "file:./style.css",
|
||||||
|
"editorStyle": "file:./editor.css",
|
||||||
|
"editorScript": "file:./index.js",
|
||||||
|
"supports": {
|
||||||
|
"html": false
|
||||||
|
}
|
||||||
|
}
|
||||||
1
build/space-status/index.asset.php
Normal file
1
build/space-status/index.asset.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-blocks', 'wp-i18n', 'wp-server-side-render'), 'version' => 'e81eff0b8644d0be4dac');
|
||||||
1
build/space-status/index.js
Normal file
1
build/space-status/index.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
(()=>{"use strict";var e={n:r=>{var s=r&&r.__esModule?()=>r.default:()=>r;return e.d(s,{a:s}),s},d:(r,s)=>{for(var t in s)e.o(s,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:s[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};window.wp.i18n;const r=window.wp.blocks,s=window.wp.serverSideRender;var t=e.n(s);const o=window.ReactJSXRuntime;(0,r.registerBlockType)("wp-spaceapi-consumer/space-status",{edit:()=>(0,o.jsx)(t(),{block:"wp-spaceapi-consumer/space-status"}),save:()=>null})})();
|
||||||
15
package.json
Normal file
15
package.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "wp-spaceapi-consumer",
|
||||||
|
"version": "0.0.0-private",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"build": "wp-scripts build",
|
||||||
|
"start": "wp-scripts start"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@wordpress/scripts": "^30.18.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/space-status/block.json
Normal file
13
src/space-status/block.json
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"apiVersion": 3,
|
||||||
|
"name": "wp-spaceapi-consumer/space-status",
|
||||||
|
"title": "Space Status",
|
||||||
|
"description": "Show whether the space is open or closed (SpaceAPI consumer).",
|
||||||
|
"category": "widgets",
|
||||||
|
"icon": "building",
|
||||||
|
"textdomain": "wp-spaceapi-consumer",
|
||||||
|
"style": "file:./style.css",
|
||||||
|
"editorStyle": "file:./editor.css",
|
||||||
|
"editorScript": "file:./index.js",
|
||||||
|
"supports": { "html": false }
|
||||||
|
}
|
||||||
7
src/space-status/editor.css
Normal file
7
src/space-status/editor.css
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/* Editor-only: make the pill obvious & easy to select */
|
||||||
|
.wp-block-wp-spaceapi-consumer-space-status {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border: 1px dashed var(--wp-admin-theme-color, #007cba);
|
||||||
|
border-radius: 9999px;
|
||||||
|
}
|
||||||
12
src/space-status/index.js
Normal file
12
src/space-status/index.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
|
import { registerBlockType } from '@wordpress/blocks';
|
||||||
|
import ServerSideRender from '@wordpress/server-side-render';
|
||||||
|
|
||||||
|
registerBlockType( 'wp-spaceapi-consumer/space-status', {
|
||||||
|
edit: () => (
|
||||||
|
<ServerSideRender
|
||||||
|
block="wp-spaceapi-consumer/space-status"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
save: () => null, // dynamic block — markup comes from PHP
|
||||||
|
} );
|
||||||
1
src/space-status/style.css
Normal file
1
src/space-status/style.css
Normal file
@@ -0,0 +1 @@
|
|||||||
|
@import url('../../wp-spaceapi-consumer-style.css');
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
/* space-status.css – styles the indicator as a pill‑shaped button */
|
/* space-status.css - styles the indicator as a pill-shaped button */
|
||||||
|
|
||||||
.space-status-indicator {
|
.space-status-indicator {
|
||||||
display:inline-flex;
|
display:inline-flex;
|
||||||
align-items:center;
|
align-items:center;
|
||||||
gap:0.4em;
|
gap:0.4em;
|
||||||
padding:0.25em 0.75em;
|
padding:0.25em 0.75em;
|
||||||
border-radius:1em; /* fully‑rounded corners */
|
border-radius:1em; /* fully-rounded corners */
|
||||||
font-size:0.95em;
|
font-size:0.95em;
|
||||||
font-weight:600;
|
font-weight:600;
|
||||||
line-height:1;
|
line-height:1;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* Plugin Slug: wp-spaceapi-consumer
|
* Plugin Slug: wp-spaceapi-consumer
|
||||||
* Plugin URI: https://gitea.alluna.pt/jfig/wp-spaceapi-consumer
|
* Plugin URI: https://gitea.alluna.pt/jfig/wp-spaceapi-consumer
|
||||||
* Description: WordPress plugin to consume a SpaceAPI endpoint and indicate if the Space is Open or Closed
|
* Description: WordPress plugin to consume a SpaceAPI endpoint and indicate if the Space is Open or Closed
|
||||||
* Version: 0.3.0
|
* Version: 0.4.2
|
||||||
* Author: Joao Figueiredo, LCD Porto Team, ChatGPT o3
|
* Author: Joao Figueiredo, LCD Porto Team, ChatGPT o3
|
||||||
* Author URI: https://lcdporto.org
|
* Author URI: https://lcdporto.org
|
||||||
* License: MIT
|
* License: MIT
|
||||||
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Constants are expected in wp-spaceapi-consumer-config.php located in the same
|
| Constants are expected in wp-spaceapi-consumer-config.php located in the same
|
||||||
| directory. If that file is missing, sane defaults are used so the plugin
|
| directory. If that file is missing, sane defaults are used so the plugin
|
||||||
| still works out‑of‑the‑box.
|
| still works out-of-the-box.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$config_file = plugin_dir_path( __FILE__ ) . 'wp-spaceapi-consumer-config.php';
|
$config_file = plugin_dir_path( __FILE__ ) . 'wp-spaceapi-consumer-config.php';
|
||||||
@@ -37,7 +37,7 @@ if ( file_exists( $config_file ) ) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Core – fetch & cache
|
| Core - fetch & cache
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -45,8 +45,8 @@ if ( file_exists( $config_file ) ) {
|
|||||||
* Retrieves space open status (boolean) with transient caching.
|
* Retrieves space open status (boolean) with transient caching.
|
||||||
*
|
*
|
||||||
* Supported JSON payloads (any case):
|
* Supported JSON payloads (any case):
|
||||||
* – true / false (bare boolean)
|
* - true / false (bare boolean)
|
||||||
* – {"state": {"open": true}} (SpaceAPI standard)
|
* - {"state": {"open": true}} (SpaceAPI standard)
|
||||||
*
|
*
|
||||||
* @return bool True if open, false if closed (or on error).
|
* @return bool True if open, false if closed (or on error).
|
||||||
*/
|
*/
|
||||||
@@ -117,7 +117,7 @@ add_shortcode( 'door_status', 'ssi_shortcode' );
|
|||||||
|
|
||||||
function ssi_admin_bar( WP_Admin_Bar $bar ) : void {
|
function ssi_admin_bar( WP_Admin_Bar $bar ) : void {
|
||||||
if ( ! current_user_can( 'read' ) ) {
|
if ( ! current_user_can( 'read' ) ) {
|
||||||
return; // Logged‑in users only.
|
return; // Logged-in users only.
|
||||||
}
|
}
|
||||||
|
|
||||||
$open = ssi_get_status();
|
$open = ssi_get_status();
|
||||||
@@ -135,7 +135,7 @@ add_action( 'admin_bar_menu', 'ssi_admin_bar', 1000 );
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Front‑end inline CSS (kept minimal)
|
| Front-end inline CSS (kept minimal)
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ add_action( 'admin_enqueue_scripts', 'ssi_enqueue_assets' ); // so the Admin Bar
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| WP‑CLI command (optional)
|
| WP-CLI command (optional)
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -167,4 +167,10 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gutenberg block support (dynamic Space Status block)
|
||||||
|
if ( function_exists( 'register_block_type' ) ) {
|
||||||
|
require_once plugin_dir_path( __FILE__ ) . 'blocks-register.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// End of file
|
// End of file
|
||||||
|
|||||||
Reference in New Issue
Block a user