public function get_feature_price($term_slug) { if (!is_term($term_slug, 'soya-range')) { return; } if (soya_term_has_children($term_slug)) { return; } // $this->feature_price = get_post_meta($this->_features_id, $this->get_feature_meta_key($term_slug), true); }
public function get_feature_meta_key_by_index($term_id, $index, $range = true) { $term = get_term($term_id, 'soya-range'); if (soya_term_has_children($term_id)) { return; } elseif (soya_is_term_child($term_id)) { $parent_term_id = soya_get_term_parent_id($term_id); $parent_term = get_term($parent_term_id, 'soya-range'); $range_value = $range ? '_' . $this->get_feature_range() : ''; $feature_meta_key = $index . '-' . $term->slug . '-' . $parent_term->slug . $range_value; } else { $feature_meta_key = $term->slug . '_' . $index; } return $feature_meta_key; }
function soya_delete_term_post_meta_keys($term_id, $tax) { if ($tax !== 'soya-range') { return; } $meta_keys[$term_id] = soya_make_meta_keys($term_id); if (soya_term_has_children($term_id) && !soya_is_term_child($term_id)) { $term_children = get_term_children($term_id, 'soya-range'); do_action('delete_unwanted_range_values', $meta_keys, 'parent', $term_children); } else { do_action('delete_unwanted_range_values', $meta_keys, 'range_change'); } }
function soya_save_range_tax_fields($term_id) { if (isset($_POST['term_meta'])) { $t_id = $term_id; $term_meta = get_option("taxonomy_{$t_id}"); $range_keys = array_keys($_POST['term_meta']); //$range_keys = array_diff($term_meta, $_POST['term_meta']); $new_term_meta = $_POST['term_meta']; $new_range_type = $new_term_meta['soya_range_type_meta']; $old_range_type = $term_meta['soya_range_type_meta']; $new_depth = $new_term_meta['soya_depth_meta']; $old_depth = $term_meta['soya_depth_meta']; foreach ($range_keys as $key) { if (isset($_POST['term_meta'][$key])) { $term_meta[$key] = $_POST['term_meta'][$key]; } } //check to remove array elements that are not needed when non-class range is selected //set unwanted meta fields for post meta correction $diff = $old_depth - $new_depth; $unwanted_term_meta_values = []; // $there_is_decrease = false; //for child terms if ($new_depth < $old_depth && soya_is_term_child($term_id)) { $term_parent_id = soya_get_term_parent_id($term_id); $parent_term_range_type = soya_get_term_custom_field($term_parent_id, 'soya_range_type_meta'); for ($i = 1; $i <= $diff; $i++) { $index_to_delete = $new_depth + $i; if ($parent_term_range_type === 'class') { // $upper = $term_meta['soya_upper_'.$index_to_delete.'_depth_meta']; // $lower = $term_meta['soya_lower_'.$index_to_delete.'_depth_meta']; $unwanted_term_meta_values[] = array('range_type' => 'class', 'index' => $index_to_delete); unset($term_meta['soya_upper_' . $index_to_delete . '_depth_meta']); unset($term_meta['soya_lower_' . $index_to_delete . '_depth_meta']); } else { $unwanted_term_meta_values[] = array('index' => $index_to_delete, 'range_type' => 'non-class'); //.'-'.$term_meta['soya_lower_'.$index_to_delete.'_depth_meta']; unset($term_meta['soya_lower_' . $index_to_delete . '_depth_meta']); } $unwanted_meta_term_fields[$term_id] = $unwanted_term_meta_values; } // assign unwanted meta term fields to a session variable so that they can deleted on features post type. // $_SESSION['unwanted_term_meta_fields'] = $unwanted_meta_term_fields; do_action('delete_unwanted_range_values', $unwanted_meta_term_fields, 'child'); //for parent terms } elseif ($new_depth < $old_depth && !soya_is_term_child($term_id)) { $term = get_term($term_id, 'soya-range'); $term_children = get_term_children($term_id, 'soya-range'); $range_keys = []; for ($i = 1; $i <= $diff; $i++) { $index_to_delete = $new_depth + $i; $upper = $old_range_type === 'class' ? $term_meta['soya_upper_' . $index_to_delete . '_depth_meta'] : ''; $lower = $term_meta['soya_lower_' . $index_to_delete . '_depth_meta']; $range = empty($upper) ? $lower : $lower . '-' . $upper; $meta_key = empty($term_children) ? $term->slug . '_' . $range : soya_parent_meta_key($term->slug, $term_children, $range); if (is_array($meta_key)) { $unwanted_term_meta_values = array_merge($unwanted_term_meta_values, $meta_key); } else { $unwanted_term_meta_values[] = $meta_key; //(is_array($meta_key)) ? array_merge($unwanted_term_meta_values, $meta_key ) : $unwanted_term_meta_values[] = $meta_key; } unset($term_meta['soya_lower_' . $index_to_delete . '_depth_meta']); if ($old_range_type === 'class') { unset($term_meta['soya_upper_' . $index_to_delete . '_depth_meta']); } } $unwanted_meta_term_fields[$term_id] = $unwanted_term_meta_values; do_action('delete_unwanted_range_values', $unwanted_meta_term_fields, 'parent', $term_children); } // check for change in class $unwanted_old_range_meta = []; if ($old_range_type !== $new_range_type) { $term = get_term($term_id, 'soya-range'); $term_range_type = soya_get_term_custom_field($term_id, 'soya_range_type_meta'); if (!soya_term_has_children($term_id) && !soya_is_term_child($term_id)) { $unwanted_old_range_meta[$term_id] = soya_make_meta_keys($term_id); } elseif (soya_term_has_children($term_id)) { $unwanted_old_range_meta[$term_id] = soya_make_meta_keys($term_id); } do_action('delete_unwanted_range_values', $unwanted_old_range_meta, 'range_change'); // $_SESSION['unwanted_range_type'][$term_id] = $unwanted_old_range_meta; //Unset unwanted term meta fields $unwanted_meta_term_fields = []; if ($old_range_type === 'class' && $new_range_type === 'non-class') { for ($i = 1; $i <= $term_meta['soya_depth_meta']; $i++) { unset($term_meta['soya_upper_' . $i . '_depth_meta']); } } } //check for changes in ranges if (soya_term_has_children($term_id)) { // get ranges old ranges $old_ranges = soya_get_term_range($term_id, $old_depth); //get new meta ranges $new_ranges = []; //soya_get_term_range($term_id, $new_depth); for ($j = 1; $j <= $new_depth; $j++) { $lower_range = $new_term_meta['soya_lower_' . $j . '_depth_meta']; $upper_range = $new_range_type === 'class' ? $new_term_meta['soya_upper_' . $j . '_depth_meta'] : ''; $range = empty($upper_range) ? $lower_range : $lower_range . '-' . $upper_range; $new_ranges[] = $range; } // get unwanted ranges $unwanted_ranges = array_diff($old_ranges, $new_ranges); //get meta keys of unwanted ranges $unwanted_meta_keys[$term_id] = soya_get_meta_keys_by_range($term_id, $unwanted_ranges); //do action to unwanted meta keys //$_SESSION['unwanted_term_meta_fields'] = $unwanted_meta_keys; $term_children = get_term_children($term_id, 'soya-range'); do_action('delete_unwanted_range_values', $unwanted_meta_keys, 'parent', $term_children); } if (!soya_is_term_child($term_id) && !soya_term_has_children($term_id)) { $term = get_term($term_id, 'soya-range'); $old_ranges = soya_get_term_range($term_id, $old_depth); $new_ranges = []; for ($j = 1; $j <= $new_depth; $j++) { $lower_range = $new_term_meta['soya_lower_' . $j . '_depth_meta']; $upper_range = $new_range_type === 'class' ? $new_term_meta['soya_upper_' . $j . '_depth_meta'] : ''; $range = empty($upper_range) ? $lower_range : $lower_range . '-' . $upper_range; $new_ranges[] = $range; } $unwanted_ranges = array_diff($old_ranges, $new_ranges); $unwanted_meta_keys[$term_id] = soya_get_meta_keys_by_range($term_id, $unwanted_ranges); do_action('delete_unwanted_range_values', $unwanted_meta_keys, 'range_change'); } // Save the option array. update_option("taxonomy_{$t_id}", $term_meta); } }
function soya_get_term_options($term_id, $field_type) { if (soya_term_has_children($term_id)) { return; } do_action('soya_get_' . $field_type . '_field', $term_id, $field_type); /* */ //do_action('soya_term_options_'.$id, $options); }