janboddez/share-on-mastodon

Max. No. of Images resets to 4

Closed this issue · 3 comments

Not sure if this is a bug or intentional.
Settings , Share on Mastodon , Images , Max. No. of Images.
Set to 4 , Save , = 4.
Set to 3 , Save , = 3.
Set to 2 , Save , = 2.
Set to 1 , Save , = 1.
Set to 0 , Save , = resets to 4. ?!

That's weird, my validation function should accept 0 as a valid option. The default is 4, though (which is also the max Mastodon supports), so I guess it somehow discounts 0 as valid and then falls back to 4.

Either way, if you don't want any images to get crossposted, can always simply disable all checkboxes (and, if applicable, remove any filters you may have set earlier, for older plugin versions).

The issue seems to be here:

<td><input type="number" min="0" max="4" style="width: 6em;" id="share_on_mastodon_settings[max_images]" name="share_on_mastodon_settings[max_images]" value="<?php echo esc_attr( ! empty( $this->options['max_images'] ) ? $this->options['max_images'] : '4' ); ?>" />

! empty( $this->options['max_images'] ) should become isset( $this->options['max_images'] ). (0 qualifies as "empty," so the value that gets shown is 4, even when it really is 0 in the database!)

I'll verify this later and fix it in the next version.