enable-mastodon-apps icon indicating copy to clipboard operation
enable-mastodon-apps copied to clipboard

Fix post search

Open toolstack opened this issue 1 year ago • 4 comments

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.

toolstack avatar Jan 08 '24 23:01 toolstack

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?

akirk avatar Jan 10 '24 04:01 akirk

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 avatar Jan 10 '24 04:01 toolstack

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 avatar Jan 11 '24 01:01 toolstack

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().

toolstack avatar Jan 11 '24 01:01 toolstack