-
-
Save mharis/7578123 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SMOFtoRedux() { | |
global $of_options; | |
$options = $of_options; | |
$sections = array(); | |
$section = array(); | |
$fields = array(); | |
foreach($options as $key=>$value) { | |
foreach ($value as $k=>$v) { | |
if (empty($v)) { | |
unset($value[$k]); | |
} | |
} | |
if (isset($value['name'])) { | |
$value['title'] = $value['name']; | |
unset($value['name']); | |
} | |
if (isset($value['std'])) { | |
$value['default'] = $value['std']; | |
unset($value['std']); | |
} | |
if (isset($value['fold'])) { | |
$value['required'] = array($value['fold'], '=' , 1); | |
unset($value['fold']); | |
} | |
switch ($value['type']) { | |
case 'heading': | |
if (isset($value['icon']) && !empty($value['icon']) ) { | |
$value['icon_type'] = "image"; | |
} | |
if (!empty($fields)) { | |
$section['fields'] = $fields; | |
$fields = array(); | |
} | |
if (!empty($section)) { | |
$sections[] = $section; | |
$section = array(); | |
} | |
unset($value['type']); | |
$section = $value; | |
break; | |
case "text": | |
if(isset($value['mod'])) { | |
unset($value['mod']); | |
} | |
break; | |
case "button": // CUSTOM Avada field | |
unset($value); | |
break; | |
case "select": | |
if(isset($value['mod'])) { | |
unset($value['mod']); | |
} | |
break; | |
case "textarea": | |
if(isset($value['cols'])) { | |
unset($value['cols']); | |
} | |
break; | |
case "radio": | |
break; | |
case "checkbox": | |
break; | |
case "multicheck": | |
$value['type'] = "checkbox"; | |
break; | |
case "color": | |
break; | |
case "select_google_font": | |
if (isset($value['preview'])) { | |
unset($value['preview']); | |
} | |
if (isset($value['options'])) { | |
unset($value['options']); | |
} | |
if (isset($value['default'])) { | |
unset($value['default']); | |
} | |
$value['type'] = "typography"; | |
break; | |
case "typography": | |
if (isset($value['preview'])) { | |
unset($value['preview']); | |
} | |
if (isset($value['options'])) { | |
unset($value['options']); | |
} | |
if (isset($value['default'])) { | |
$default = array(); | |
$value['default2'] = $value['default']; | |
if (isset($value['default']['size'])) { | |
$default['font-size'] = $value['default']['size']; | |
$px = filter_var($default['font-size'], FILTER_SANITIZE_NUMBER_INT); | |
$default['units'] = str_replace($px, "", $default['font-size']); | |
} | |
if (isset($value['default']['color'])) { | |
$default['color'] = $value['default']['color']; | |
} | |
if (isset($value['default']['face'])) { | |
//$default['font-family'] = ucfirst($value['default']['face']); | |
} | |
if (isset($value['default']['style'])) { | |
if (strpos(strtolower($value['default']['style']),'bold') !== false) { | |
$default['font-weight'] = "bold"; | |
} | |
if (strpos(strtolower($value['default']['style']),'italic') !== false) { | |
$default['font-style'] = "italic"; | |
} | |
} | |
$value['default'] = $default; | |
} | |
break; | |
case "border": | |
if (isset($value['width'])) { | |
$value['border-width'] = $value['width']; | |
unset($value['width']); | |
} | |
if (isset($value['width'])) { | |
$value['border-color'] = $value['color']; | |
unset($value['color']); | |
} | |
if (isset($value['style'])) { | |
$value['border-style'] = $value['style']; | |
unset($value['style']); | |
} | |
break; | |
case "info": | |
if (isset($value['title'])) { | |
unset($value['title']); | |
} | |
break; | |
case "switch": | |
break; | |
case "images": | |
$value['type'] = "image_select"; | |
break; | |
case "image": | |
$value['type'] = "info"; | |
$value['raw_html'] = true; | |
$value['default'] = '<img src="'.$value['default'].'">'; | |
break; | |
case "slider": | |
$value['type'] = "slides"; | |
break; | |
case "sorter": | |
if (isset($value['default'])) { | |
$value['options'] = $value['default']; | |
unset($value['default']); | |
} | |
break; | |
case "tiles": | |
$value['type'] = "image_select"; | |
$value['tiles'] = true; | |
break; | |
case "backup": | |
case "transfer": | |
unset($value); | |
break; | |
case "sliderui": | |
$value['type'] = "slider"; | |
break; | |
case "upload": | |
case "media": | |
$value['type'] = "media"; | |
if (isset($value['mod']) && $value['mod'] == "min") { | |
unset($value['mod']); | |
} else { | |
$value['url'] = true; | |
} | |
break; | |
default: | |
# code... | |
break; | |
} | |
if (!empty($value)) { | |
$fields[] = $value; | |
} | |
} | |
if (!empty($fields)) { | |
$section['fields'] = $fields; | |
$fields = array(); | |
} | |
if (!empty($section)) { | |
$sections[] = $section; | |
$section = array(); | |
} | |
//print_r($sections); | |
// Uncomment the section below to get the $sections array fully functional with Redux | |
/* | |
if ( !empty( $sections ) ) { | |
echo '$sections = ' . objectToHTML( $sections ) . ';'; | |
exit(); | |
} | |
*/ | |
$ReduxFramework = new ReduxFramework($sections, array('opt_name'=>'SMOFConvert', 'menu_title' => 'SMOF2Redux')); | |
} | |
add_action('init', 'SMOFtoRedux', 100); | |
function objectToHTML($object) { | |
// create html | |
$html = var_export($object, true); | |
// change double spaces to tabs | |
$html = str_replace(" ", "\t", $html); | |
// correctly formats "=> array(" | |
$html = preg_replace('/([\t\r\n]+?)array/', 'array', $html); | |
// Remove number keys from array | |
$html = preg_replace('/[0-9]+ => array/', 'array', $html); | |
// add extra tab at start of each line | |
return str_replace("\n", "\n\t", $html); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment