Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

theme_mod options cleanup #31

Open
joemaller opened this issue Oct 14, 2022 · 0 comments
Open

theme_mod options cleanup #31

joemaller opened this issue Oct 14, 2022 · 0 comments
Assignees

Comments

@joemaller
Copy link
Member

Versioned theme_mods values are still being written to the database. They're messy and useless. These shouldn't actually be written, but it might be a good idea to try and clean up orphans when writing the new values. The return on line 329 doesn't seem to be preventing the value from being written under the longer name?

public function readOption($val, $opt)
{
$optBase = preg_replace($this->semverRegex, '', $opt);
// if $optBase and $opt match, getting the option will nest infinitely
return $optBase === $opt ? $val : get_option($optBase);
}
public function writeOption($val, $oldVal, $opt)
{
$optBase = preg_replace($this->semverRegex, '', $opt);
/**
* Because this filter is triggered _from inside_ update_option(),
* calling update_option() again with the same inputs would cause
* WordPress to nest infinitely and crash the server.
*
* We must check that $optBase and $opt are different before we can
* update the value attached to the corrected option name.
*/
if ($optBase !== $opt) {
update_option($optBase, $val);
/**
* Returning $oldVal short-circuits the original update_option()
* call. Since we've already updated the value under the modified
* name, there's no need to write an extra wp_options entry which
* will never be used.
*/
return $oldVal;
}
return $val;
}

image

@joemaller joemaller self-assigned this Oct 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant