@@ -419,66 +419,45 @@ protected function fetch_events_via_api( $limit, $location ) {
419419 }
420420
421421 /**
422- * Get custom dashboard RSS widgets .
422+ * Get custom dashboard RSS feeds .
423423 *
424- * Collects feeds from:
425- * 1. The 'microsub_dashboard_feeds' filter (for plugins to register their feeds)
426- * 2. The 'dashboard_widget_options' option (for user-added RSS widgets)
424+ * Collects feeds from the 'microsub_dashboard_feeds' filter.
425+ * Plugins can use this to expose their dashboard RSS widgets.
427426 *
428427 * @return array
429428 */
430429 protected function get_rss_widgets () {
431- $ widgets = array ();
432-
433430 /**
434431 * Filter to register dashboard RSS feeds with Microsub.
435432 *
436433 * Plugins can use this to expose their dashboard RSS widgets.
437434 *
435+ * Example:
436+ * add_filter( 'microsub_dashboard_feeds', function( $feeds ) {
437+ * $feeds[] = array(
438+ * 'id' => 'my_plugin_news',
439+ * 'name' => __( 'My Plugin News', 'my-plugin' ),
440+ * 'url' => 'https://example.com/feed/',
441+ * );
442+ * return $feeds;
443+ * } );
444+ *
438445 * @param array $feeds Array of feeds, each with 'id', 'name', and 'url' keys.
439446 */
440- $ plugin_feeds = \apply_filters ( 'microsub_dashboard_feeds ' , array () );
441-
442- if ( \is_array ( $ plugin_feeds ) ) {
443- foreach ( $ plugin_feeds as $ feed ) {
444- if ( ! empty ( $ feed ['id ' ] ) && ! empty ( $ feed ['url ' ] ) ) {
445- $ widgets [] = array (
446- 'id ' => $ feed ['id ' ],
447- 'name ' => ! empty ( $ feed ['name ' ] ) ? $ feed ['name ' ] : $ feed ['id ' ],
448- 'url ' => $ feed ['url ' ],
449- );
450- }
451- }
452- }
453-
454- // Also check dashboard_widget_options for user-added RSS widgets.
455- $ options = \get_option ( 'dashboard_widget_options ' , array () );
447+ $ feeds = \apply_filters ( 'microsub_dashboard_feeds ' , array () );
456448
457- if ( \is_array ( $ options ) ) {
458- foreach ( $ options as $ widget_id => $ settings ) {
459- if ( ! \is_array ( $ settings ) ) {
460- continue ;
461- }
462-
463- // Check for feed URL in common keys.
464- $ url = null ;
465- if ( ! empty ( $ settings ['url ' ] ) ) {
466- $ url = $ settings ['url ' ];
467- } elseif ( ! empty ( $ settings ['link ' ] ) && \filter_var ( $ settings ['link ' ], \FILTER_VALIDATE_URL ) ) {
468- // 'link' is sometimes the feed URL in older widgets.
469- $ url = $ settings ['link ' ];
470- }
471-
472- if ( ! $ url ) {
473- continue ;
474- }
449+ if ( ! \is_array ( $ feeds ) ) {
450+ return array ();
451+ }
475452
476- $ title = ! empty ( $ settings [ ' title ' ] ) ? $ settings [ ' title ' ] : $ widget_id ;
453+ $ widgets = array () ;
477454
455+ foreach ( $ feeds as $ feed ) {
456+ if ( ! empty ( $ feed ['id ' ] ) && ! empty ( $ feed ['url ' ] ) ) {
478457 $ widgets [] = array (
479- 'id ' => $ widget_id ,
480- 'name ' => $ title ,
481- 'url ' => $ url ,
458+ 'id ' => $ feed [ ' id ' ] ,
459+ 'name ' => ! empty ( $ feed [ ' name ' ] ) ? $ feed [ ' name ' ] : $ feed [ ' id ' ] ,
460+ 'url ' => $ feed [ ' url ' ] ,
482461 );
483462 }
484463 }
0 commit comments