Skip to content

Commit

Permalink
Add a Button to the Welcome page (#373)
Browse files Browse the repository at this point in the history
* Add a button to add myself as a friend

* Change the button to be in a form

* Don't override everything when we find a parser

* Change button to link
  • Loading branch information
akirk authored Oct 16, 2024
1 parent a651b78 commit 2b6779a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion feed-parsers/class-feed-parser-microformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function discover_available_feeds( $content, $url ) {
}
}

if ( isset( $mf['items'] ) ) {
if ( isset( $mf['items'] ) && ! isset( $discovered_feeds[ $url ] ) ) {
$feed_items = $this->parse_hfeed( $mf );
if ( count( $feed_items ) > 0 ) {
$discovered_feeds[ $url ] = array(
Expand Down
15 changes: 9 additions & 6 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1848,10 +1848,12 @@ public function process_admin_add_friend( $vars ) {
return $this->process_admin_add_friend_response( $friend_user, $vars );
}

if ( isset( $vars['friendship'] ) ) {
$rest_url = $vars['friendship'];
} else {
$rest_url = $this->friends->rest->get_friends_rest_url( $feeds );
if ( get_option( 'friends_enable_wp_friendships' ) ) {
if ( isset( $vars['friendship'] ) ) {
$rest_url = $vars['friendship'];
} else {
$rest_url = $this->friends->rest->get_friends_rest_url( $feeds );
}
}
} else {
if ( str_starts_with( $friend_url, home_url() ) ) {
Expand Down Expand Up @@ -1892,8 +1894,9 @@ public function process_admin_add_friend( $vars ) {
$friend_user_login = strtolower( str_replace( ' ', '-', sanitize_user( $better_display_name ) ) );
}
}

$rest_url = $this->friends->rest->get_friends_rest_url( $feeds );
if ( get_option( 'friends_enable_wp_friendships' ) ) {
$rest_url = $this->friends->rest->get_friends_rest_url( $feeds );
}
}

if ( $rest_url ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/class-feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ public function discover_available_feeds( $url ) {
continue;
}
}
$available_feeds[ $link_url ] = $feed;
$available_feeds[ $link_url ] = array_merge( $available_feeds[ $link_url ], $feed );
$available_feeds[ $link_url ]['url'] = $link_url;
}
}
Expand Down
14 changes: 13 additions & 1 deletion templates/admin/welcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
* @package Friends
*/

?>
$first_friend = array(
// translators: %s is Alex Kirk.
'display_name' => sprintf( __( 'Add %s, creator of the Friends plugin, as a friend now', 'friends' ), 'Alex Kirk' ),
'url' => 'https://alex.kirk.at/',
);

?>
<h1><?php esc_html_e( 'Welcome to the Friends Plugin!', 'friends' ); ?></h1>
<p>
<?php esc_html_e( 'With this plugin you can make your WordPress the center of your online activity.', 'friends' ); ?>
Expand All @@ -27,6 +32,13 @@
// translators: %s is the URL of the user's friends page.
echo wp_kses( sprintf( __( 'You can extend your network by <a href=%1$s>subscribing to web sites</a>, <a href=%1$s>sending friend requests</a> or <a href=%2$s>responding to received friend requests</a>.', 'friends' ), '"' . admin_url( 'admin.php?page=add-friend' ) . '"', '"' . admin_url( 'users.php?role=friend_request' ) . '"' ), array( 'a' => array( 'href' => array() ) ) );
?>
<form action="<?php echo esc_url( self_admin_url( 'admin.php?page=add-friend' ) ); ?>" method="post" class="form-horizontal">
<?php wp_nonce_field( 'add-friend' ); ?>
<input type="hidden" name="friend_url" value="<?php echo esc_attr( $first_friend['url'] ); ?>" />
<div class="form-group">
<button class="btn btn-link">→ <?php echo esc_html( $first_friend['display_name'] ); ?></button>
</div>
</form>
</li>
<li>
<span><?php esc_html_e( 'A lot of the functionality you might know from other networks is provided by this plugin, just without outside dependencies.', 'friends' ); ?></span>
Expand Down
2 changes: 2 additions & 0 deletions tests/test-feed-discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function test_alex_kirk_at() {
$this->assertArrayHasKey( 'https://alex.kirk.at/feed/', $feeds );
$this->assertArrayHasKey( 'autoselect', $feeds['https://alex.kirk.at/feed/'] );
$this->assertTrue( $feeds['https://alex.kirk.at/feed/']['autoselect'] );
$this->assertEquals( 'Alex Kirk', User::get_display_name_from_feeds( $feeds ) );
$this->assertEquals( 'alex-kirk', User::get_user_login_from_feeds( $feeds ) );
}

public function test_johnblackbourn() {
Expand Down

0 comments on commit 2b6779a

Please sign in to comment.