akirk / enable-mastodon-apps

Allow accessing your WordPress blog with Mastodon clients
https://wordpress.org/plugins/enable-mastodon-apps
GNU General Public License v2.0
34 stars 5 forks source link

Fix post search #56

Open toolstack opened 8 months ago

toolstack commented 8 months ago

Search uses tokens for authentication so check to see if we have a current token in addition to a logged in user.

Cleanup the parameter passing to $this->get_posts() as well as otherwise some values can be set to null which break wp_getposts() in some circumstances.

akirk commented 8 months ago

Search uses tokens for authentication so check to see if we have a current token in addition to a logged in user.

To be honest, it's been a while since I touched this part of the code but when the user has a token they should be logged in, no?

toolstack commented 8 months ago

To be honest, it's been a while since I touched this part of the code but when the user has a token they should be logged in, no?

I think so now, but when I wrote this I was still getting used to the codebase and this was the solution I came up with. Let me double check it and swap over to the logged in user call if it works.

toolstack commented 8 months ago

Ok, I double checked it and no, during a token auth session the wp user is not set:

https://github.com/akirk/enable-mastodon-apps/blob/fafa41334772e7c5d45fd03f0467c46856f7c829/includes/class-mastodon-api.php#L777-L787

I think it should be though, so I'll change the PR to add that code just above the was_used() call like it is in the logged in session.

toolstack commented 8 months ago

In fact, looking a little deeper, have_token_permission() is only used for search, not anywhere else and adding the login code makes it identical to logged_in_permission(), so I think we should simply remove have_token_permission() and switch search over to logged_in_permission().