• Resolved maximinime

    (@maximinime)


    I notice you put in a kind of fix for this here, but it is insufficient. The problem occurs because any call to update a user will check if the preference is POSTed and, if not, set it to false. Users can be updated in many ways without using the default interface, so your field isn’t always present, and the preference goes to default.

    This kind of problem (with checkboxes in general) can be easily solved in forms processed by php. Simply put a hidden input with the same name as the checkbox before the checkbox. If the box isn’t ticked, the hidden value is used. If it is ticked the checkbox’s value overwrites the hidden value in the $_POST array. Basically, avoid using isset() with checkboxes.

    in mailusers_edit_any_user_profile_form() change this:

    <input 	type="checkbox"
    						name="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>"
    						id="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>"
    						value="true"
    						<?php if (get_user_meta($uid, MAILUSERS_ACCEPT_NOTIFICATION_USER_META, true)=='true') echo 'checked="checked"'; ?> ></input>
    				<?php _e('Accept to receive post or page notification emails', MAILUSERS_I18N_DOMAIN); ?><br/>
    				<input 	type="checkbox"
    						name="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>"
    						id="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>"
    						value="true"
    						<?php if (get_user_meta($uid, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META, true)=='true') echo 'checked="checked"'; ?> ></input>

    to this:

    <input type="hidden" name="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>" value="false">
    				<input 	type="checkbox"
    						name="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>"
    						id="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>"
    						value="true"
    						<?php if (get_user_meta($uid, MAILUSERS_ACCEPT_NOTIFICATION_USER_META, true)=='true') echo 'checked="checked"'; ?> ></input>
    				<?php _e('Accept to receive post or page notification emails', MAILUSERS_I18N_DOMAIN); ?><br/>
    				<input type="hidden" name="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>" value="false">
    				<input 	type="checkbox"
    						name="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>"
    						id="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>"
    						value="true"
    						<?php if (get_user_meta($uid, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META, true)=='true') echo 'checked="checked"'; ?> ></input>

    remove this entirely:

    else {
    ?>
    <input 	type="hidden" name="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>" id="<?php echo MAILUSERS_ACCEPT_NOTIFICATION_USER_META; ?>" value="<?php echo (get_user_meta($uid, MAILUSERS_ACCEPT_NOTIFICATION_USER_META, true) === 'true') ? "true" : "false"; ?>"></input>
    <input 	type="hidden" name="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>" id="<?php echo MAILUSERS_ACCEPT_MASS_EMAIL_USER_META; ?>" value="<?php echo (get_user_meta($uid, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META, true) === 'true') ? "true" : "false"; ?>"></input>
    <?php
        }

    then in mailusers_any_user_profile_update() remove:

    } else {
    		update_usermeta($uid, MAILUSERS_ACCEPT_NOTIFICATION_USER_META, 'false');

    and remove:

    } else {
    		update_usermeta($uid, MAILUSERS_ACCEPT_MASS_EMAIL_USER_META, 'false');

    Thanks!

    https://www.ads-software.com/extend/plugins/email-users/

Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘preferences to receive emails revert to 'false' (fix provided)’ is closed to new replies.