function customizer_wrapper_save($wp_customize) { $data = get_object_vars(json_decode(stripslashes($_POST['customized']))); $type = customizer_wrapper_preview_type(); $controls = array(); foreach ($data as $id => $value) { $type_id = null; if (is_a($control, 'WP_Customize_Image_Control')) { $type_id = 'image'; } else { if (is_a($control, 'WP_Customize_Color_Control')) { $type_id = 'color'; } else { if (isset($control->type)) { $type_id = $control->type; } } } $control = $wp_customize->get_control($id); $controls[$id] = array('control' => $control, 'type' => $type_id); do_action('customizer_wrapper_saved_' . $id, $value, $wp_customize, $type, $controls[$id]); } do_action('customizer_wrapper_save', $data, $wp_customize, $type, $controls); }
function customizer_demo_save($data, $wp_customize, $type, $controls) { $type = customizer_wrapper_preview_type(); $prefix = customizer_demo_prefix(); if ('single' === $type['type']) { foreach ($data as $id => $value) { $item = $controls[$id]; //say you wanted to pull data from the original control //$control = $item[ 'control' ]; //$default = $control->settings[ 'default' ]->default; $delete = false; if ($prefix . 'single-image' === $id) { $attachment = customizer_wrapper_attachment_by_url($value); if (null !== $attachment) { $value = $attachment->ID; } } if (true === $value) { $value = 'true'; } else { if (false === $value) { $value = 'false'; } } if (true === empty($value)) { delete_post_meta($type['id'], $id); } else { update_post_meta($type['id'], $id, $value); } } } }