Skip to content

theme_mod options cleanup #31

@joemaller

Description

@joemaller

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions