function hw_menu_style3_add_home_link($items, $args, $params) { //get theme args if ($params['function'] !== __FUNCTION__) { return $items; } $theme = $params['args'][0]; $menu = HW_NAVMENU::get_menu_name($args); //get current menu if ($menu != $theme['menu']) { return $items; } //compare real-value to which value that keep in theme args $icon = '<img src="' . plugins_url('images/iconhome.png', __FILE__) . '" alt="home" title="Trang chủ" style="float:left"/>'; $args->link_before = ''; $args->link_after = ''; $args->before = ''; $args->after = ''; $homeMenuItem = $args->before . '<a class="home1" href="' . home_url('/') . '">' . $args->link_before . $icon . $args->link_after . '</a>' . $args->after; /*$menu = HW_NAVMENU::get_menu_name($args); if (is_front_page()) $class='active';else $class = ''; $homeMenuItem='<li class="' . $class . '">' . $args->before . '<a class="home active" href="' . home_url('/') . '" title="Trang ch?">'. $args->link_before . '' . $args->link_after . '</a>' . $args->after . '</li>'; $items=$homeMenuItem . $items;*/ return $homeMenuItem . $items; }
/** * 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); } }
/** * 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; }
function hw_menu_style4_add_home_link($items, $args, $params) { //get theme args if ($params['function'] !== __FUNCTION__) { return $items; } $theme = $params['args'][0]; $menu = HW_NAVMENU::get_menu_name($args); //get current menu if ($menu != $theme['menu']) { return $items; } //compare real-value to which value that keep in theme args $homeMenuItem = '<li ><a class="home456546" href="' . home_url('/') . '">' . $args->link_before . 'XX' . $args->link_after . '</a>' . $args->after . '</li>'; /*$menu = HW_NAVMENU::get_menu_name($args); if (is_front_page()) $class='active';else $class = ''; $homeMenuItem='<li class="' . $class . '">' . $args->before . '<a class="home active" href="' . home_url('/') . '" title="Trang chủ">'. $args->link_before . '' . $args->link_after . '</a>' . $args->after . '</li>'; $items=$homeMenuItem . $items;*/ return $homeMenuItem . $items; }
/** * close ul tag for children elements * @param string $output * @param int $depth * @param array $args */ public function end_lvl(&$output, $depth = 0, $args = array()) { $indent = $depth ? str_repeat("t", $depth) : ''; if (isset($args->twig) && HW_NAVMENU::twig_asset_exists('end_lvl.twig', $args->twig)) { $tpl = $args->twig->loadTemplate('end_lvl.twig'); $output .= $tpl->render(array('indent' => $indent, 'args' => $args)); } else { $output .= $indent . "</ul>\n"; } #parent::end_lvl($output, $depth, $args); #don't use }
/** * return this instance of the class */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
exit; } define('HW_MENU_URL', plugins_url('', __FILE__)); define('HW_MENU_PATH', plugin_dir_path(__FILE__)); define('HW_MENU_PLUGIN_FILE', __FILE__); //activation hook include_once 'menu-install.php'; /** * load common functions */ include_once 'includes/functions.php'; /** * wp_nav_menu settings */ include_once 'includes/admin/menu-settings.php'; /** * add custom metabox to page of menus manager */ include_once 'includes/metabox-navmenu-page.php'; //beta (un-complete) /** * menu item custom fields */ include_once 'includes/admin/menu-item-custom-fields.php'; /** * show all menu setting in action */ include_once 'includes/navmenu.php'; //run HW_NAVMENU::getInstance();
/** * @param string $output * @param int $depth * @param array $args */ public function end_lvl(&$output, $depth = 0, $args = array()) { if ('list' != $args['style']) { return; } $indent = str_repeat("\t", $depth); if (isset($args['twig']) && HW_NAVMENU::twig_asset_exists('end_lvl.twig', $args['twig'])) { $tpl = $args['twig']->loadTemplate('end_lvl.twig'); $output .= $tpl->render(array('indent' => $indent, 'args' => $args)); } else { $output .= "{$indent}</ul>\n"; } }
/** * 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); }