public function addCustomizerSaveFilter($value, $optionName, $oldValue)
{
$theme = get_option('stylesheet');
// Intercept theme mods only.
if (strpos($optionName, 'theme_mods_' . $theme) !== 0) {
return $value;
}
// We expect theme mods to be an array.
if (!is_array($value)) {
return $value;
}
// Checks whether a Titan customizer is in place.
$customizerUsed = false;
// Go through all our customizer options and filter them for saving.
$optionIDs = array();
if (!empty($this->mainContainers['customizer'])) {
foreach ($this->mainContainers['customizer'] as $customizer) {
foreach ($customizer->options as $option) {
if (!empty($option->settings['id'])) {
$optionID = $option->settings['id'];
$themeModName = $this->optionNamespace . '_' . $option->settings['id'];
if (!array_key_exists($themeModName, $value)) {
continue;
}
$customizerUsed = true;
// Try and unserialize if possible.
$tempValue = $value[$themeModName];
if (is_serialized($tempValue)) {
$tempValue = unserialize($tempValue);
}
// Hook 'tf_save_option_{namespace}'.
$newValue = apply_filters('tf_save_option_' . $this->optionNamespace, $tempValue, $option->settings['id']);
// Hook 'tf_save_option_{namespace}_{optionID}'.
$newValue = apply_filters('tf_save_option_' . $themeModName, $tempValue);
// We mainly check for equality here so that we won't have to serialize IF the value wasn't touched anyway.
if ($newValue != $tempValue) {
if (is_array($newValue)) {
$newValue = serialize($newValue);
}
$value[$themeModName] = $newValue;
}
}
}
}
}
if ($customizerUsed) {
/** This action is documented in class-admin-page.php */
$namespace = $this->optionNamespace;
do_action("tf_pre_save_options_{$namespace}", $this->mainContainers['customizer']);
}
return $value;
}