diff --git a/wp-api-consumer.php b/wp-api-consumer.php new file mode 100644 index 0000000..05ec157 --- /dev/null +++ b/wp-api-consumer.php @@ -0,0 +1,48 @@ + 4 ] ); // 4 s hard stop + $state = is_wp_error( $r ) ? '' : trim( wp_remote_retrieve_body( $r ) ); + set_transient( 'ds_state', $state, 10 ); + } + return $state; +} + +/** + * Returns a coloured dot (🟢 / 🔴) or ⚪ if the API is unreachable. + */ +function ds_render() { + $s = strtolower( ds_get_state() ); + if ( 'true' === $s ) return '🟢'; + if ( 'false' === $s ) return '🔴'; + return '⚪'; +} +add_shortcode( 'door_state', 'ds_render' ); // [door_state] + +/** + * Automatically append the indicator to a menu (optional). + * Replace 'primary' with your theme’s menu slug if different. + */ +function ds_menu_item( $items, $args ) { + if ( 'primary' === $args->theme_location ) { + $items .= '