Skip to content

Commit

Permalink
Allow non-protocol feed URLs in Edit Feed screen. (#282)
Browse files Browse the repository at this point in the history
* Also resolve non-protocol feed URL when adding it through the feeds list

* Fix delete button

* Also for newly added feeds
  • Loading branch information
akirk authored Jan 18, 2024
1 parent 22bacf6 commit fc84095
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion friends-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} );
Expand Down
13 changes: 12 additions & 1 deletion includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );

Expand All @@ -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 );
}
Expand Down

0 comments on commit fc84095

Please sign in to comment.