From fc84095e9bc72a6e3dff63d2ef9c586d0e831f4a Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Thu, 18 Jan 2024 19:01:05 +0100 Subject: [PATCH] Allow non-protocol feed URLs in Edit Feed screen. (#282) * Also resolve non-protocol feed URL when adding it through the feeds list * Fix delete button * Also for newly added feeds --- friends-admin.js | 2 +- includes/class-admin.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/friends-admin.js b/friends-admin.js index 0cc66ade..7708d6fa 100644 --- a/friends-admin.js +++ b/friends-admin.js @@ -200,7 +200,7 @@ jQuery( function ( $ ) { $( document ).on( 'click', '.delete-feed', function () { // eslint-disable-next-line no-alert if ( window.confirm( friends.delete_feed_question ) ) { - $( this ).closest( 'tr' ).remove(); + $( this ).closest( 'li' ).remove(); } return false; } ); diff --git a/includes/class-admin.php b/includes/class-admin.php index 766de34a..954cbc80 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -1409,6 +1409,10 @@ public function process_admin_edit_friend_feeds() { } $feed['active'] = true; + $protocol = wp_parse_url( $feed['url'], PHP_URL_SCHEME ); + if ( ! $protocol ) { + $feed['url'] = apply_filters( 'friends_rewrite_incoming_url', 'https://' . $feed['url'], $feed['url'] ); + } $new_feed = $friend->subscribe( $feed['url'], $feed ); if ( is_wp_error( $new_feed ) ) { do_action( 'friends_process_feed_item_submit_error', $new_feed, $feed ); @@ -1426,6 +1430,11 @@ public function process_admin_edit_friend_feeds() { $user_feed = $existing_feeds[ $term_id ]; unset( $existing_feeds[ $term_id ] ); + $protocol = wp_parse_url( $feed['url'], PHP_URL_SCHEME ); + if ( ! $protocol ) { + $feed['url'] = apply_filters( 'friends_rewrite_incoming_url', 'https://' . $feed['url'], $feed['url'] ); + } + if ( $user_feed->get_url() !== $feed['url'] ) { do_action( 'friends_user_feed_deactivated', $user_feed ); @@ -1435,7 +1444,9 @@ public function process_admin_edit_friend_feeds() { if ( $feed['active'] ) { $new_feed = $friend->subscribe( $feed['url'], $feed ); - do_action( 'friends_user_feed_activated', $new_feed ); + if ( ! is_wp_error( $new_feed ) ) { + do_action( 'friends_user_feed_activated', $new_feed ); + } } else { $new_feed = $friend->save_feed( $feed['url'], $feed ); }