/** * Saves/Updates term children (price group children). * * @author Zane M. Kolnik * @since 1.5.1 * @package AJAX */ public function save_term() { parse_str($_POST['form'], $form_data); wp_verify_nonce($_POST['security'], $_POST['action']); $taxonomy = $_POST['taxonomy']; // Update the price group name if it has changed if (!empty($form_data['price_group']['term_id'])) { $parent_obj = get_term_by('id', $form_data['price_group']['term_id'], $taxonomy); if (!empty($parent_obj) && $parent_obj->name != $form_data['price_group']['term_name']) { wp_update_term($form_data['price_group']['term_id'], $taxonomy, array('name' => $form_data['price_group']['term_name'])); } } if (!empty($form_data['terms_children'])) { foreach ($form_data['terms_children'] as $k => $v) { wp_update_term($k, $taxonomy, array('name' => $v['name'])); // Dynamically save ALL fields that are NOT 'name' as // term meta! It would have been nice to store all // meta into an array and loop over saving that, // can't wait for term meta to make it into core. foreach ($v as $kk => $vv) { if ($k != 'name') { sell_media_update_term_meta($k, $kk, $vv); } } } } // Dynamically add new prices for this price group if (!empty($form_data['new_child'])) { foreach ($form_data['new_child'] as $child) { if (!empty($child['name'])) { $term = wp_insert_term($child['name'], $taxonomy, array('parent' => $child['parent'])); // Dynamically save ALL fields that are NOT 'name' as // term meta! if (!is_wp_error($term)) { foreach ($child as $k => $v) { if ($k != 'name') { sell_media_update_term_meta($term['term_id'], $k, $v); } } } } } } wp_send_json(array('sell_media' => true)); }
/** * Save new taxonomy fields * Used to both save and update * * @since 0.1 */ function sell_media_save_extra_taxonomy_fields($term_id) { if (!isset($_POST['meta_value']['default'])) { sell_media_update_term_meta($term_id, 'default', 'off'); } if (!isset($_POST['meta_value']['collection_hidden'])) { if (!empty($_SESSION['sell_media']['collection_password'])) { unset($_SESSION['sell_media']['collection_password']); } } if (isset($_POST['meta_value'])) { $cat_keys = array_keys($_POST['meta_value']); foreach ($cat_keys as $key) { if (!empty($_POST['meta_value'][$key])) { $meta_value[$key] = $_POST['meta_value'][$key]; sell_media_update_term_meta($term_id, $key, wp_filter_nohtml_kses($meta_value[$key])); } else { sell_media_delete_term_meta($term_id, $key); } } } }