/**
  * update nav menu location
  * @param $location
  * @param $menu_id
  */
 public static function set_menu_location($location, $menu_id)
 {
     // Set the menu to primary menu location
     /*$locations = get_theme_mod( 'nav_menu_locations' );
       $locations[$location] = $menu_id;
       set_theme_mod ( 'nav_menu_locations', $locations );
       */
     if (class_exists('HW_NAVMENU', 0)) {
         HW_NAVMENU::set_menu_location($location, $menu_id);
     }
 }
Ejemplo n.º 2
0
 /**
  * validation form fields
  * @param $values
  * @return mixed
  */
 public function validation_tab_filter($values)
 {
     $locations = get_registered_nav_menus();
     foreach ($values as $field => $menu) {
         foreach (array_keys($locations) as $location) {
             if ($this->real_field_name($field) == HW_Validation::valid_apf_slug($location)) {
                 HW_NAVMENU::set_menu_location($location, $menu);
                 break;
             }
         }
     }
     return $values;
 }
Ejemplo n.º 3
0
 /**
  * Create new terms based on import information
  *
  * Doesn't create a term its slug already exists
  */
 function _process_terms()
 {
     $this->terms = apply_filters('wp_import_terms', $this->terms);
     if (empty($this->terms)) {
         return;
     }
     foreach ($this->terms as $term) {
         $cat['taxonomy'] = $term['term_taxonomy'];
         //by hoang, since we save term in result table & i need to know what taxonomy for the current term
         // if the term already exists in the correct taxonomy leave it alone
         $term_id = term_exists($term['slug'], $term['term_taxonomy']);
         if ($term_id) {
             if (is_array($term_id)) {
                 $term_id = $term_id['term_id'];
             }
             $term['term_id'] = (int) $term_id;
             //by hoang, because we not use import_id feature
             if (!empty($term['term_id'])) {
                 $this->tracker->add_import('term', $term, $term);
                 $this->processed_terms[intval($term['term_id'])] = (int) $term_id;
             }
             //bind menu location
             if (!empty($term['menu_location']) && class_exists('HW_NAVMENU', false)) {
                 HW_NAVMENU::set_menu_location($term['menu_location'], $term_id);
             }
             continue;
         }
         if (!empty($term['term_parent']) && $term['term_parent'] instanceof HWIE_Module_Import_Results) {
             //import result for term_parent
             $term['term_parent']->init($this->parser->importer, $this->parser->_get_option('data', array()));
             $term['term_parent'] = $term['term_parent']->parse_data()->value;
             //parse category parent id
             if (is_array($term['term_parent'])) {
                 $term['term_parent'] = $term['term_parent']['term_id'];
             }
         }
         if (empty($term['term_parent'])) {
             $parent = 0;
         } else {
             $parent = term_exists($term['term_parent'], $term['term_taxonomy']);
             if (is_array($parent)) {
                 $parent = $parent['term_id'];
             }
         }
         $description = isset($term['term_description']) ? $term['term_description'] : '';
         $termarr = array('slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent));
         $id = wp_insert_term($term['term_name'], $term['term_taxonomy'], $termarr);
         if (!is_wp_error($id)) {
             $term['term_id'] = $id['term_id'];
             //by hoang, because we not use import_id feature
             if (!empty($term['term_id'])) {
                 $this->tracker->add_import('term', $term, $term);
                 $this->processed_terms[intval($term['term_id'])] = $id['term_id'];
             }
             //bind menu location
             if (!empty($term['menu_location']) && class_exists('HW_NAVMENU', false)) {
                 HW_NAVMENU::set_menu_location($term['menu_location'], $term['term_id']);
             }
         } else {
             printf(__('Failed to import %s %s', 'wordpress-importer'), esc_html($term['term_taxonomy']), esc_html($term['term_name']));
             if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                 echo ': ' . $id->get_error_message();
             }
             echo '<br />';
             continue;
         }
     }
     unset($this->terms);
 }