commit 3ba4a63cb294582b6010448dba09c4992eeacaff Author: Martien Date: Tue Jun 24 14:34:23 2025 +0200 Add wp-nostr-widget/nostr-widget.php Initial commit, not yet tested. diff --git a/wp-nostr-widget/nostr-widget.php b/wp-nostr-widget/nostr-widget.php new file mode 100644 index 0000000..03ee47f --- /dev/null +++ b/wp-nostr-widget/nostr-widget.php @@ -0,0 +1,111 @@ + __('Shows Nostr posts from a public key and relay(s).', 'nostr_widget_domain')) + ); + } + + public function widget($args, $instance) { + $pubkey = !empty($instance['pubkey']) ? $instance['pubkey'] : ''; + $relays = $this->get_relays_from_instance($instance); + + echo $args['before_widget']; + if (!empty($pubkey) && !empty($relays[0])) { + echo $args['before_title'] . 'Nostr Posts' . $args['after_title']; + $this->display_nostr_posts($pubkey, $relays); + } else { + echo 'Please configure at least a public key and one relay.'; + } + echo $args['after_widget']; + } + + public function form($instance) { + $pubkey = !empty($instance['pubkey']) ? $instance['pubkey'] : ''; + $relays = $this->get_relays_from_instance($instance); + + ?> +

+ + +

+

+ Relay URLs (at least one, max five): + +
+ + Example: https://nostr.band/api/v0/search (for nostr.band) +

+ 8]); + if (is_wp_error($response)) continue; + + $body = wp_remote_retrieve_body($response); + $data = json_decode($body, true); + + if (!empty($data['events'])) { + $posts_found = true; + echo ''; + break; // Stop after first relay with results + } + } + if (!$posts_found) { + echo 'No posts found on any configured relay.'; + } + } +} + +function register_nostr_widget() { + register_widget('Nostr_Widget'); +} +add_action('widgets_init', 'register_nostr_widget');