chrisblakley / Nebula

Nebula is a WordPress theme framework that focuses on enhancing development. The core features of Nebula make it a powerful tool for designing, developing, and analyzing WordPress websites consistently, yet its deliberately uncomplicated code syntax also serves as a learning resource for programmers themselves.
https://nebula.gearside.com
GNU General Public License v2.0
141 stars 36 forks source link

Nebula Options are reverting to default value during multisite Nebula updates #2255

Closed chrisblakley closed 1 year ago

chrisblakley commented 1 year ago

When doing a Nebula update on a multi-site install, some Nebula options are reverting to their default values on the first instance of the multi-site (and not subsequent instances). It appears to only be affecting the first sub-site, and only on boolean options (not text-based string input options).

This appears to be due to that theme updates do not happen at the sub-site level– instead they happen on the Network admin which is not associated with a single sub-site's DB table. This means that when Nebula checks for "new" options, it is not seeing it and when it attempts to "create" and set the "new" option, the first (un-prefixed) DB table is updated to the default value.

For example, DB tables in WordPress multisites are prefixed as:

Solutions to this issue would be to:

We can detect if a site is a multisite with is_multisite() and we can count the number of sub-site installs with get_sites(array('count' => true)). This would be how we form the loop.

The function we need to update here is Nebula's check_for_new_options inside of the Admin.php function.

chrisblakley commented 1 year ago

@terencehoverter Unfortunately this is not resolved. We'll have to look into it further. Options are still reverting to default values on multisite installs.

terencehoverter commented 1 year ago

@chrisblakley I'll test some tweaks when updating EXC and UNIV. Assuming you tested on OCR?

chrisblakley commented 1 year ago

Another proposed solution for the options interface itself:

<input name="nebula_options[force_wp_timezone]" value="<?php echo $nebula_options['force_wp_timezone']; ?>"><input id="force_wp_timezone" value="1" type="checkbox" onclick="this.previousSibling.value=1-this.previousSibling.value" <?php checked('1', !empty($nebula_options['force_wp_timezone'])); ?>><label for="force_wp_timezone">Force WP Timezone</label>
chrisblakley commented 1 year ago

Another idea is to try a hidden input field without js and see if the server prioritizes the "later" value:

<!-- Hidden input for the checkbox -->
<input type="hidden" name="checkbox_name" value="0">
<!-- The actual checkbox -->
<input type="checkbox" name="checkbox_name" value="1" checked>

In this example, if the checkbox is unchecked, the "checkbox_name" parameter with a value of "0" will be sent to the server. If it is checked, the "checkbox_name" parameter with a value of "1" will be sent as well- theoretically overriding the 0 value (but that part seems a little risky).

chrisblakley commented 1 year ago

Confirming this is now fixed. The options no longer revert.