diff --git a/wp-admin/custom-navigation.php b/wp-admin/custom-navigation.php index 8f61ebc62f..660d885e8a 100644 --- a/wp-admin/custom-navigation.php +++ b/wp-admin/custom-navigation.php @@ -176,22 +176,19 @@ function wp_custom_navigation() { $messagesdiv = '

' . __('The menu has been updated.') . '

'; } - //DISPLAY Custom Navigation + // DISPLAY Custom Navigation ?>

' . __('The Custom Menu has not been Enabled yet. Please enable it in order to use it -------->') . '

'; - } - ?> @@ -215,9 +212,9 @@ function wp_custom_navigation() { 0 ) { - //SET output type + // SET output type $output_type = "backend"; - //MAIN OUTPUT FUNCTION + // MAIN OUTPUT FUNCTION wp_custom_navigation_output( 'type='.$output_type.'&name='.$menu_title.'&id='.$menu_selected_id ); } ?> @@ -248,7 +245,7 @@ function wp_custom_navigation() { term_id ) || ( $menu_selected_id == $menu->term_id ) ) @@ -314,16 +311,12 @@ function wp_custom_navigation() { 0 ) @@ -381,7 +374,7 @@ function wp_custom_navigation() { $page_name .= htmlentities($post->post_title).'|'; } } else { - $page_name = "No pages available"; + $page_name = __('No pages available'); } ?> @@ -448,7 +441,7 @@ function wp_custom_navigation() { $cat_name = ''; //CHECK for results if ( $categories ) { - foreach( $categories as $category ) { + foreach ( $categories as $category ) { $cat_id = $category->term_id; $cat_args = array( @@ -507,8 +500,8 @@ function wp_custom_navigation() { @@ -557,7 +550,6 @@ function wp_custom_navigation() {
0 ) { @@ -57,110 +57,70 @@ function wp_custom_navigation_delete_menu( $menu_term_id ) { } } -/*-----------------------------------------------------------------------------------*/ -/* Custom Navigation Functions */ -/* wp_custom_navigation_output() displays the menu in the back/frontend -/* wp_custom_navigation_sub_items() is a recursive sub menu item function -/* wp_custom_nav_get_pages() -/* wp_custom_nav_get_categories() -/* wp_custom_navigation_default_sub_items() is a recursive sub menu item function -/*-----------------------------------------------------------------------------------*/ +function setup_menu_item($menu_item) { + global $parent_menu_order; -/*-----------------------------------------------------------------------------------*/ -/* Main Output Function -/* args list -/* type - frontend or backend -/* name - name of your menu -/* id - id of menu in db -/* desc - 1 = show descriptions, 2 = dont show descriptions -/* before_title - html before title is outputted in tag -/* after_title - html after title is outputted in tag -/*-----------------------------------------------------------------------------------*/ + $menu_item->type = get_post_meta($menu_item->ID, 'menu_type', true); + $menu_item->object_id = get_post_meta($menu_item->ID, 'object_id', true); + //$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order; + if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) ) + $menu_item->parent_item = $parent_menu_order[ $menu_item->post_parent ]; + else + $menu_item->parent_item = 0; -function wp_custom_navigation_output( $args = array() ) { - - // Defaults - $defaults = array( 'type' => 'frontend', 'name' => 'Menu 1', 'id' => 0, 'desc' => 2, 'before_title' => '', 'after_title' => ''); - - $args = wp_parse_args($args, $defaults); - extract($args, EXTR_SKIP); - - $menu_objects = get_objects_in_term( $id, 'nav_menu' ); - $menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' ); - //O verride for menu descriptions - $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options'); - if ( $advanced_option_descriptions == 'no' ) - $desc = 2; - - $queried_id = 0; - global $wp_query; - if ( is_page() ) - $queried_id = $wp_query->get_queried_object_id(); - elseif ( is_category() ) - $queried_id = $wp_query->get_queried_object_id(); - - $parent_stack = array(); - $current_parent = 0; - $parent_menu_order = array(); - // Display Loop - foreach ( $menu_items as $key => $menu_item ) { - $menu_type = get_post_meta($menu_item->ID, 'menu_type', true); - $object_id = get_post_meta($menu_item->ID, 'object_id', true); - $parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order; - if ( isset( $parent_menu_order[ $menu_item->post_parent ] ) ) - $parent_item = $parent_menu_order[ $menu_item->post_parent ]; + switch ( $menu_item->type ) { + // Page Menu Item + case 'page': + if ( $menu_item->guid == '' ) + $menu_item->link = get_permalink( $menu_item->object_id ); else - $parent_item = 0; + $menu_item->link = $menu_item->guid; - switch ( $menu_type ) { - // Page Menu Item - case 'page': - if ( $menu_item->guid == '' ) - $link = get_permalink( $object_id ); - else - $link = $menu_item->guid; + if ( $menu_item->post_title == '' ) + $menu_item->title = htmlentities( get_the_title( $menu_item->object_id ) ); + else + $menu_item->title = htmlentities( $menu_item->post_title ); - if ( $menu_item->post_title == '' ) - $title = htmlentities( get_the_title( $object_id ) ); - else - $title = htmlentities( $menu_item->post_title ); + if ( $menu_item->post_content == '' ) + $menu_item->description = htmlentities( get_post_meta( $menu_item->ID, 'page-description', true ) ); + else + $menu_item->description = htmlentities( $menu_item->post_content ); + $menu_item->target = ''; + break; + // Category Menu Item + case 'category': + if ( $menu_item->guid == '' ) + $menu_item->link = get_category_link( $menu_item->object_id ); + else + $menu_item->link = $menu_item->guid; - if ( $menu_item->post_content == '' ) - $description = htmlentities( get_post_meta( $menu_item->ID, 'page-description', true ) ); - else - $description = htmlentities( $menu_item->post_content ); - $target = ''; - break; - // Category Menu Item - case 'category': - if ( $menu_item->guid == '' ) - $link = get_category_link( $object_id ); - else - $link = $menu_item->guid; - - if ( $menu_item->post_title == '' ) { - $title_raw = get_categories( array('include' => $object_id) ); - $title = htmlentities($title_raw[0]->cat_name); - } else { - $title = htmlentities( $menu_item->post_title ); - } - - if ( $menu_item->post_content == '' ) - $description = htmlentities( strip_tags( category_description( $object_id ) ) ); - else - $description = htmlentities( $menu_item->post_content ); - $target = ''; - break; - default: - // Custom Menu Item - $link = $menu_item->guid; - $title = htmlentities( $menu_item->post_title ); - $description = htmlentities( $menu_item->post_content ); - $target = 'target="_blank"'; - break; + if ( $menu_item->post_title == '' ) { + $title_raw = get_categories( array('include' => $menu_item->object_id) ); + $menu_item->title = htmlentities($title_raw[0]->cat_name); + } else { + $menu_item->title = htmlentities( $menu_item->post_title ); } - $li_class = ''; + if ( $menu_item->post_content == '' ) + $menu_item->description = htmlentities( strip_tags( category_description( $menu_item->object_id ) ) ); + else + $menu_item->description = htmlentities( $menu_item->post_content ); + $menu_item->target = ''; + break; + default: + // Custom Menu Item + $menu_item->link = $menu_item->guid; + $menu_item->title = htmlentities( $menu_item->post_title ); + $menu_item->description = htmlentities( $menu_item->post_content ); + $menu_item->target = 'target="_blank"'; + break; + } + + $menu_item->li_class = ''; + global $wp_query; + if ( $menu_item->ID == $wp_query->get_queried_object_id() ) + $menu_item->li_class = 'class="current_page_item"'; + /* @todo: update to use tax/post data //SET anchor title @@ -184,42 +144,88 @@ function wp_custom_navigation_output( $args = array() ) { } } */ + + return $menu_item; +} + +/*-----------------------------------------------------------------------------------*/ +/* Custom Navigation Functions */ +/* wp_custom_navigation_output() displays the menu in the back/frontend +/* wp_custom_nav_get_pages() +/* wp_custom_nav_get_categories() +/* wp_custom_navigation_default_sub_items() is a recursive sub menu item function +/*-----------------------------------------------------------------------------------*/ + +/*-----------------------------------------------------------------------------------*/ +/* Main Output Function +/* args list +/* type - frontend or backend +/* name - name of your menu +/* id - id of menu in db +/* desc - 1 = show descriptions, 2 = dont show descriptions +/* before_title - html before title is outputted in tag +/* after_title - html after title is outputted in tag +/*-----------------------------------------------------------------------------------*/ +function wp_custom_navigation_output( $args = array() ) { + // Defaults + $defaults = array( 'type' => 'frontend', 'name' => 'Menu 1', 'id' => 0, 'desc' => 2, 'before_title' => '', 'after_title' => ''); + + $args = wp_parse_args($args, $defaults); + extract($args, EXTR_SKIP); + + $menu_objects = get_objects_in_term( $id, 'nav_menu' ); + $menu_items = wp_custom_navigation_get_menu_items( $menu_objects, 'menu_order' ); + // Override for menu descriptions + $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options'); + if ( $advanced_option_descriptions == 'no' ) + $desc = 2; + + $parent_stack = array(); + $current_parent = 0; + $parent_menu_order = array(); + // Setup parentage + foreach ( $menu_items as $key => $menu_item ) { + $parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order; + } + + // Display Loop + foreach ( $menu_items as $key => $menu_item ) { + $menu_item = setup_menu_item($menu_item); // List Items - ?>
  • @@ -657,13 +482,13 @@ function wp_custom_nav_get_categories($counter, $type) { $description = htmlentities(strip_tags($cat_item->description)); ?> - cat_name; ?> Add to Custom Menu + cat_name); ?> =" title="="" src="" /> cat_ID; ?> cat_ID, $intCounter, $parentli, 'categories','default'); + // Recursive function + $intCounter = wp_custom_navigation_default_sub_items($cat_item->cat_ID, $intCounter, $parentli, 'categories', 'default'); ?>
  • @@ -682,12 +507,12 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli $counter = $intCounter; // Custom Menu - if ($output_type == 'menu') { + if ( $output_type == 'menu' ) { $sub_args = array( 'child_of' => $childof, 'hide_empty' => false, 'parent' => $childof); - } elseif ($output_type == 'default') { + } elseif ( $output_type == 'default' ) { // Sidebar Menu $sub_args = array( 'child_of' => $childof, @@ -708,15 +533,14 @@ function wp_custom_navigation_default_sub_items($childof, $intCounter, $parentli if ( $sub_array ) { ?> -