Automattic / wordpress-activitypub

ActivityPub for WordPress
https://wordpress.org/plugins/activitypub/
MIT License
482 stars 73 forks source link

Custom author archive URLs seem to have broken #684

Closed janboddez closed 7 months ago

janboddez commented 7 months ago

Quick summary

So I moved Mastodon accounts, and have the old account forward to the new one etc. etc. I'm not seeing new posts appear in my Mastodon timeline. At first it said "Follow Requested," so I unfollowed and refollowed. Now it appears I'm following the blog. Checked Users > Followers, and guess what, the new account is not there ...?

Steps to reproduce

  1. From a Mastodon account, follow a WordPress account that has ActivityPub enabled.
  2. Move Mastodon account.
  3. Notice that ... somehow WordPress ignores the new account, and seemingly ignores follow requests from it. It doesn't seem to send to the account's server/inbox, either.
  4. Other followers (that didn't move) still see the posts as before.

What you expected to happen

That either WordPress would register the move (accept the new follow request and possible delete the old follower account) or that it'd at least respect/confirm a subsequent follow from the new account.

What actually happened

Posts aren't posted to the new account's server. The account does not show up in Users > Followers even after an explicit (and seemingly confirmed!) unfollow/refollow.

Impact

One

Available workarounds?

No but the platform is still usable

Logs or notes

No response

janboddez commented 7 months ago

[E]ven after an explicit (and seemingly confirmed!) unfollow/refollow

Looks like this is a Mastodon quirk. When I again click "Unfollow," it asks me if I want to cancel the follow request. Also the blog never appears under the Mastodon's account "following" list.

janboddez commented 7 months ago

Seems to happen also when I want to follow my other account from the same Masto server, so I'm now suspecting my own WordPress setup ...

Edit: even more so now that I can follow @pfefferle@notiz.blog just fine. :-)

janboddez commented 7 months ago

Removed my "must-use" AP plugins, disabled caching, removed the Disable REST Access plugin, still no dice. We'll see, I guess.

pfefferle commented 7 months ago

Can you provide me the WebFinger IDs you tried? Maybe I can help!?!

pfefferle commented 7 months ago

Have you used the latest master branch?

janboddez commented 7 months ago

Can you provide me the WebFinger IDs you tried? Maybe I can help!?!

Good call, I did break my author page/profile by removing those mu-plugins ... Doesn't resolve the issue, though.

Have you used the latest master branch?

I did use it, maybe like a week ago. Then noticed some error I can't remember and reinstalled v2.0.1 from the WP repo.

Could that have broken something? Maybe run a migration which should've been reverted?

janboddez commented 7 months ago

So, it can't find my user.

// Incoming "Activity"
[02-Feb-2024 18:02:44 UTC] array (
  '@context' => 'https://www.w3.org/ns/activitystreams',
  'id' => 'https://indieweb.social/eb53cc3a-f56f-4a3f-8748-c124450b6a9e',
  'type' => 'Follow',
  'actor' => 'https://indieweb.social/users/janboddez',
  'object' => 'https://jan.boddez.net/author/jan',
)

// The `$user` in `Follow::handle_follow()`
[02-Feb-2024 18:02:44 UTC] WP_Error::__set_state(array(
   'errors' => 
  array (
    'activitypub_no_user_found' => 
    array (
      0 => 'User not found',
    ),
  ),
   'error_data' => 
  array (
    'activitypub_no_user_found' => 
    array (
      'status' => 404,
    ),
  ),
   'additional_data' => 
  array (
  ),
))

Guessing this was introduced together with the new "server"?

I have to look at Users::get_by_resource(). Looks like it can't find my user because I use a "custom" author URL. It used to work fine, though, in older versions.

janboddez commented 7 months ago

Looks like https://github.com/Automattic/wordpress-activitypub/blob/4a7743642773d61495aec96f3454ee5aa05d2fb1/includes/functions.php#L133 is failing me. Not sure how it worked before, but it did.

Would be nice if I could somehow ... filter this. Or if we could go back to how it was. :-D

janboddez commented 7 months ago

$wp_rewrite->get_author_permastruct() equals /articles/author/ ("articles" being my main blog's front), while my author URL is https://jan.boddez.net/author/jan.

Last I checked it was not possible to change the author permastruct; I'd have to look up how I'm overriding the author URL. I didn't want the "articles" in there because I have ActivityPub enabled also for "notes," and my notes don't have articles in their URL. In other words, I needed my author URL and ActivityPub URL, which are the same, to be more generic.

I set this up before the "blog user" was a thing, and never bothered trying that out, since it was working okay for me.

Also, since my homepage lists only "articles," I didn't want my AP profile to be my homepage. Didn't want people to open up my "profile" and not see any of my notes, which are visible on their (e.g., Masto) timelines. My author page (with non-standard, I guess URL) much better reflects what Mastodon shows. In fact, I was looking to eventually add the Followers button there, and my bio and avatar, etc. (but not on the homepage, at least ... not initially).

janboddez commented 7 months ago

Anyway, I guess the fact that it did actually work before might make this a bug after all? And it would also seem that I'm the only person affected. :-D

janboddez commented 7 months ago

Last I checked it was not possible to change the author permastruct; I'd have to look up how I'm overriding the author URL.

add_filter( 'author_link', function( $link ) {
  return str_replace( home_url( 'articles' ), home_url(), $link );
} );

add_filter( 'author_rewrite_rules', function( $author_rewrite ) {
  $keys = array_keys( $author_rewrite );
  $keys = array_map( function( $item ) {
    return preg_replace( "~^articles/~", '', $item );
}, $keys );

  return array_combine( $keys, array_values( $author_rewrite ) );
} );

Bit hacky perhaps, with that hardcoded articles. 😅 But that dang "front" is hardcoded in the "author permastruct" is why: https://github.com/WordPress/wordpress-develop/blob/8338c630284124bbe79dc871822d6767e3b45f0b/src/wp-includes/class-wp-rewrite.php#L675-L675

I think I tried overwriting the author_structure property in the global $wp_rewrite object ... but that seems even hackier?


Would it not be possible/easier to loop over get_users() and compare to get_author_posts_url( $user->ID ) or something? Rather than rely on the author permastruct?

janboddez commented 7 months ago

I think I tried overwriting the author_structure property in the global $wp_rewrite object ... but that seems even hackier?

Problem seems solved by adding also:

add_action( 'init', function() {
  global $wp_rewrite;
  $wp_rewrite->author_base = 'author';
  $wp_rewrite->author_structure = '/author/%author%';
} );

Not sure this is actually correct, but we'll find out, I guess. Guess so, had a issue before but that was due to some posts not having an author, apparently.

janboddez commented 7 months ago

Made it work, guess I should close this, there's probably other things that require more focus, maybe someone else finds it useful in the future. Glad I still brought it up, wouldn't have come this far if I hadn't.