Fix for checkboxes not reflecting current values
-
I hereby want to present a solution for an unsolved problem, already described in several threads:
In short: When changing the values on the frontend and saving, they are successfully updated in the database. However, as soon as the page reloads, these changes are not reflected in the checkboxes.
also seen in not saving options
The reason for this issue is pretty simple.
Just edit
wp-content/plugins/selfhost-google-fonts/inc/admin.php
and look for the section starting with$options->add_field(array( 'name' => esc_html__('Disable for Admins', 'sphere-sgf'), 'desc' => esc_html__('Disable processing for logged in admin users or any user with capability "manage_options". (Useful if using a pagebuilder that conflicts)',$ 'id' => 'disable_for_admins', 'type' => 'checkbox', 'default' => 0, 'attributes' => array('data-conditional-id' => 'enabled'), ));
have a look for the sections similar to the above one: “process_enqueues”, “process_css_files”, “process_css_inline” and “protocol_relative”. Now just correct their default values to
'default' => 0,
instead of'default' => 1,
.After you changed the default value to 0 for all of these sections and save the file, the checkboxes will reflect the real status.
The reason behind this:
If the option is enabled it is written to the configuration string in the database. If the option is not enabled it is not existant in the database’s configuration string and therefore the default value is used for status reflection. This means that the default should be 0 instead of 1 so that it correctly reflects the current status. If nothing is in the database the checkbox will reflect that the option is deactivated. If you activate it the default value 0 will be overwritten by the database value and will also correctly reflect that the option is enabled, now.Pretty easy to fix.
@asadkn: It would be great if this could be integrated in a new, upcoming version. I would also open a pull request on github but sadly the code base on github is an old one (for example it’s missing the protocol_relative option) so it’s not a good idea to continue on that basis.
- The topic ‘Fix for checkboxes not reflecting current values’ is closed to new replies.