janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Missed alt text on 1/2 images #43

Closed cogdog closed 1 year ago

cogdog commented 1 year ago

The post to Mastodon for this blog post https://cogdogblog.com/2022/12/experiment-this/

published here https://social.fossdle.org/@cogdog/109508139573247437

Includes the alt text for one image (photo of a building) but skipped it for the other (screenshot of PleaseCaptionBot).

janboddez commented 1 year ago

That's interesting. The plugin calls the exact same function for each and every image.

It checks WordPress post meta for the image alt text here: https://github.com/janboddez/share-on-mastodon/blob/4353e6bbb8092651d27edc46a879301f79cee3e4/includes/class-post-handler.php#L451

Supposing the alt text was there when the post got submitted. Maybe the character limit is being hit? I'll try to reproduce when I find the time.

janboddez commented 1 year ago

Tried with a random image and the very same alt text except that WordPress, when I enter it, seems to strip the newline characters from it, and it goes through OK.

@cogdog how experienced are you, with modding WordPress or PHP in general? I could send you a modified plugin which would log Mastodon's response, provided WordPress's debug logging is enabled.

I could also just strip newline characters from alt text before it gets sent and hope that does the trick. (The second image---the one that works, I mean---does not have newline chars in its description, so who knows?)

cogdog commented 1 year ago

Thanks for the quick response! I do not usually put newlines in , so I can try a second test.

I have lots of experience modding WordPress and writing themes, plugins, but I tihnk you found what I should test. I will either edit the alt and see if I can post again, or try a second test.

cogdog commented 1 year ago

Hmmm, I unlinked the mastodon post, removed new lines from the alt text, and reshared to Mastodon... still w/o alt text

https://social.fossdle.org/@cogdog/109509216039972724

I will maybe do a whole new post as a check

janboddez commented 1 year ago

If you could edit the plugin, add an error_log( $alt ); right after the line where it fetches the alt text, that'd help already. It should not be empty (obviously).

The image ID is 72415; it may be interesting to look in the wp_postmeta table in the database, see if there's a _wp_attachment_image_alt value for it.

I mean, it should be there because it displays on your site.

What could also help is if you add a error_log( print_r( $response, true ) ); just before https://github.com/janboddez/share-on-mastodon/blob/4353e6bbb8092651d27edc46a879301f79cee3e4/includes/class-post-handler.php#L484

This would print the entire response from Mastodon to debug.log (if it's enabled, at least). It could contain a clue.

Last possibility (that I can think of) is some encoding thing. We use two dashes and a "random" string to mark off the alt text: https://github.com/janboddez/share-on-mastodon/blob/4353e6bbb8092651d27edc46a879301f79cee3e4/includes/class-post-handler.php#L456 maybe there's a conflict or something there? Although the "random" string is just a hashed timestamp, so the chances of it being the same on two occasions are quite small.

janboddez commented 1 year ago

Speaking of, it could be the two dashes in there ... Maybe Mastodon/Rails wrongly (?) interprets them as the start of another boundary or something ... So that'd be another easy thing to try (although it wouldn't explain why it seemed to work on my end).

cogdog commented 1 year ago

Thanks much for offering suggestions, Jan. I am fairly sure it was just some weird thing I entered in the alt text box. I ended up going an easier route with an IFTTT action off of my RSS feed.