/** * convert xml to valid element known as domelement * @param $item * @return DOMElement|HWIE_Param */ public function convert_element($item) { return HWIE_Param::get_hw_element($item, false); }
/** * add term taxonomy * @param $term_data */ public function add_term($term_data) { $tax = isset($term_data['taxonomy']) ? $term_data['taxonomy'] : ''; $slug = isset($term_data['slug']) ? $term_data['slug'] : ''; $name = isset($term_data['name']) ? $term_data['name'] : ''; $description = isset($term_data['description']) ? $term_data['description'] : ''; $parent = isset($term_data['parent']) ? $term_data['parent'] : ''; $menu_location = isset($term_data['menu_location']) ? $term_data['menu_location'] : ''; //for nav_menu //valid if ($name && !$slug) { $slug = sanitize_title($name); } if (!$name && $slug) { $name = $slug; } if (!$name && $slug) { return; } if ($tax == 'category') { $tag = 'wp:category'; $term_taxonomy = ''; $term_slug = 'wp:category_nicename'; $term_name = 'wp:cat_name'; $term_parent = 'wp:category_parent'; $term_desc = 'wp:category_description'; } elseif ($tax == 'post_tag') { $tag = 'wp:tag'; $term_taxonomy = ''; $term_slug = 'wp:tag_slug'; $term_name = 'wp:tag_name'; $term_parent = ''; $term_desc = 'wp:tag_description'; } else { $tag = 'wp:term'; $term_taxonomy = 'wp:term_taxonomy'; $term_slug = 'wp:term_slug'; $term_name = 'wp:term_name'; $term_parent = 'wp:term_parent'; $term_desc = 'wp:term_description'; } $term = $this->createElement($tag); //taxonomy if ($term_taxonomy && $tax) { $term->appendChild($this->createElement($term_taxonomy, $this->cdata($tax))); } $term->appendChild($this->createElement($term_slug, $this->cdata($slug))); //slug $term->appendChild($this->createElement($term_name, $this->cdata($name))); //name if ($term_parent && $parent) { //parent if (!is_object($parent)) { $term->appendChild($this->createElement($term_parent, $this->cdata($parent))); } else { if (HWIE_Param::get_hw_element($parent, false)) { $term->appendChild($term->ownerDocument->importNode(HWIE_Param::get_hw_element($parent, false), true)); } } } if ($description) { $term->appendChild($this->createElement($term_desc, $this->cdata($description))); } //term description //bind menu location if ($menu_location) { $term->appendChild($this->createElement('wp:menu_location', $this->cdata($menu_location))); } if (!$this->get('term_' . $term_data['taxonomy'] . '_' . $slug)) { $this->posts->appendChild($term); $this->add('term_' . $term_data['taxonomy'] . '_' . $slug, array('element' => $term, 'data' => $term_data)); } }