mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Menus rework. Props ptahdunbar. see #11817
git-svn-id: http://svn.automattic.com/wordpress/trunk@13704 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e2bee8f908
commit
f635d99754
@ -1 +1 @@
|
||||
#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{color:#f00;text-decoration:underline;font-size:11px;float:left;margin-top:5px;}.submitdelete:hover{background-color:#F00;color:#fff;}.save{float:right;}.button-controls{float:left;}.add-to-menu{float:right;}#create-menu-name{width:159px;}#available-links{margin:15px 0 0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}#menu-item-url,#menu-item-name{float:right;width:220px;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .item-title{cursor:pointer;display:block;}.list li .item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .item-title{margin-left:14px;}.list li ul li ul li .item-title{margin-left:28px;}.list li ul li ul li ul li .item-title{margin-left:42px;}.list li ul li ul li ul li ul li .item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl dt{-webkit-border-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li dl dt:hover{cursor:move;}.menu li .item-title{background:url(../images/ico-arrow.png) no-repeat 4px 5px;background-position:center left;padding-left:15px;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}.hide{display:none;}
|
||||
#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{font-size:11px;}#cancel-save{color:#f00;text-decoration:underline;font-size:11px;margin-left:20px;margin-top:5px;}#cancel-save:hover{background-color:#F00;color:#fff;}.button-controls{float:left;}.add-to-menu{float:right;}#manage-menu .inside{padding:0;}#create-menu-name{width:159px;}#available-links{margin:15px 0 0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}.menu-item-textbox{float:right;width:220px;}.howto span{margin-top:4px;display:block;float:left;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .menu-item-title{cursor:pointer;display:block;}.list li .menu-item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .menu-item-title{margin-left:14px;}.list li ul li ul li .menu-item-title{margin-left:28px;}.list li ul li ul li ul li .menu-item-title{margin-left:42px;}.list li ul li ul li ul li ul li .menu-item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .menu-item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl dt{-webkit-border-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li dl dt:hover{cursor:move;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .menu-item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}
|
@ -14,19 +14,16 @@
|
||||
|
||||
/* Button Primary Actions */
|
||||
#menu-container .submit { margin: 0px 0px 10px; padding: 0px; }
|
||||
.submitdelete { color: #ff0000; text-decoration: underline; font-size: 11px; float: left; margin-top: 5px; }
|
||||
.submitdelete:hover { background-color: #FF0000; color: #fff; }
|
||||
.save { float: right; }
|
||||
|
||||
.submitdelete { font-size: 11px; }
|
||||
#cancel-save { color: #ff0000; text-decoration: underline; font-size: 11px; margin-left: 20px; margin-top: 5px; }
|
||||
#cancel-save:hover { background-color: #FF0000; color: #fff; }
|
||||
|
||||
/* Button Secondary Actions */
|
||||
.button-controls { float: left; }
|
||||
.add-to-menu { float: right; }
|
||||
|
||||
/* CSS for switching the main columns *//*
|
||||
#menu-settings-column { clear: none; float: left; }
|
||||
#menu-management #post-body { float: right; margin-left: -340px; margin-right: 0px; }
|
||||
#menu-management #post-body-content { margin-left: 300px; margin-right: 0px; }
|
||||
*/
|
||||
#manage-menu .inside { padding: 0px 0px; }
|
||||
|
||||
/* Create Menu */
|
||||
#create-menu-name { width: 159px; }
|
||||
@ -36,7 +33,8 @@
|
||||
#available-links dt { display: block; }
|
||||
#add-custom-link .howto { font-size: 11px; }
|
||||
#add-custom-link label span { display: block; float: left; margin-top: 5px; padding-right: 5px; }
|
||||
#menu-item-url, #menu-item-name { float: right; width: 220px; }
|
||||
.menu-item-textbox { float: right; width: 220px; }
|
||||
.howto span { margin-top: 4px; display: block; float: left; }
|
||||
|
||||
/* Pages/Categories */
|
||||
.show-all, .hide-all { cursor: pointer; }
|
||||
@ -50,17 +48,17 @@
|
||||
/* Listings */
|
||||
.list li { display: none; margin: 0; margin-bottom: 5px; }
|
||||
|
||||
.list li .item-title { cursor: pointer; display: block; }
|
||||
.list li .item-title input { margin-right: 3px; margin-top: -3px; }
|
||||
.list li .menu-item-title { cursor: pointer; display: block; }
|
||||
.list li .menu-item-title input { margin-right: 3px; margin-top: -3px; }
|
||||
|
||||
.list li ul li .item-title { margin-left: 14px; }
|
||||
.list li ul li ul li .item-title { margin-left: 28px; }
|
||||
.list li ul li ul li ul li .item-title { margin-left: 42px; }
|
||||
.list li ul li ul li ul li ul li .item-title { margin-left: 56px; }
|
||||
.list li ul li ul li ul li ul li ul li .item-title { margin-left: 70px; }
|
||||
.list li ul li ul li ul li ul li ul li ul li .item-title { margin-left: 84px; }
|
||||
.list li ul li ul li ul li ul li ul li ul li ul li .item-title { margin-left: 98px; }
|
||||
.list li ul li ul li ul li ul li ul li ul li ul li ul li .item-title { margin-left: 112px; }
|
||||
.list li ul li .menu-item-title { margin-left: 14px; }
|
||||
.list li ul li ul li .menu-item-title { margin-left: 28px; }
|
||||
.list li ul li ul li ul li .menu-item-title { margin-left: 42px; }
|
||||
.list li ul li ul li ul li ul li .menu-item-title { margin-left: 56px; }
|
||||
.list li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 70px; }
|
||||
.list li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 84px; }
|
||||
.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 98px; }
|
||||
.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title { margin-left: 112px; }
|
||||
|
||||
/* Menu */
|
||||
#menu-container .inside { padding-bottom: 10px; }
|
||||
@ -71,9 +69,9 @@
|
||||
.menu li dl dt:hover { cursor: move; }
|
||||
|
||||
.menu li .item-title { }
|
||||
.menu li ul li { margin-left: 20px; opacity: .7;}
|
||||
.menu li ul li ul li { opacity: .9;}
|
||||
.menu li ul li ul li ul li { opacity: .9;}
|
||||
.menu li ul li { margin-left: 20px; opacity: .7; }
|
||||
.menu li ul li ul li { opacity: .9; }
|
||||
.menu li ul li ul li ul li { opacity: .9; }
|
||||
.menu li ul li ul li ul li ul li { opacity: .95; }
|
||||
|
||||
/* Drag and Drop */
|
||||
@ -85,7 +83,7 @@
|
||||
.item-controls { font-size: 11px; position: absolute; right: 15px; top: -1px; }
|
||||
.item-controls a { text-decoration: none; }
|
||||
.item-controls a:hover { cursor: pointer; }
|
||||
.item-controls .item-delete:hover { color: #ff0000; }
|
||||
.item-controls .menu-item-delete:hover { color: #ff0000; }
|
||||
|
||||
/* Thickbox */
|
||||
#menu-item-settings { display: none; }
|
||||
@ -94,7 +92,4 @@
|
||||
#update-menu-item { color: #fff !important; }
|
||||
#update-menu-item:hover,
|
||||
#update-menu-item:active,
|
||||
#update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; }
|
||||
|
||||
/* Misc */
|
||||
.hide { display: none; }
|
||||
#update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; }
|
@ -1,273 +1,383 @@
|
||||
<?php
|
||||
|
||||
/* Register Metaboxes */
|
||||
add_meta_box( 'create-menu', __('Create Menu'), 'wp_nav_menu_create_metabox', 'menus', 'side', 'core' );
|
||||
add_meta_box( 'add-custom-links', __('Add Custom Links'), 'wp_nav_menu_item_link_metabox', 'menus', 'side', 'default' );
|
||||
wp_nav_menu_post_type_metaboxes();
|
||||
wp_nav_menu_taxonomy_metaboxes();
|
||||
|
||||
/**
|
||||
* Displays a list of links and thier sub items.
|
||||
* Creates metaboxes for any post type menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $counter
|
||||
* @param string $context
|
||||
*/
|
||||
function wp_nav_menu_get_custom_links( $counter, $context ) {
|
||||
$available_links = new WP_Query( );
|
||||
function wp_nav_menu_post_type_metaboxes() {
|
||||
$post_types = get_post_types( array( 'public' => true ), 'object' );
|
||||
|
||||
$args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
|
||||
$link_objects = new WP_Query( $args );
|
||||
if ( !$post_types )
|
||||
return false;
|
||||
|
||||
$items_counter = $counter;
|
||||
|
||||
if ( !$link_objects->posts ) {
|
||||
_e('Not Found');
|
||||
return $items_counter;
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$id = sanitize_title_with_dashes( $post_type->label );
|
||||
|
||||
// delete_transient( "nav_menu_items_{$post_type->name}" );
|
||||
// delete_transient( "nav_menu_sub_items_{$post_type->name}" );
|
||||
|
||||
add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'menus', 'side', 'default', $post_type );
|
||||
}
|
||||
|
||||
// Display Loop
|
||||
foreach ( $link_objects->posts as $item ) {
|
||||
if ( 0 == $item->parent ) {
|
||||
$item = wp_setup_nav_menu_item( $item, 'item', $items_counter );
|
||||
|
||||
switch ( $context ) {
|
||||
case 'menu':
|
||||
?>
|
||||
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $item, 'menu' );
|
||||
$parentli = $item->ID;
|
||||
$items_counter++;
|
||||
$items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'menu' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
break;
|
||||
|
||||
case 'default':
|
||||
?>
|
||||
<li>
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $item, 'default' );
|
||||
$parentli = $item->ID;
|
||||
$items_counter++;
|
||||
$items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $items_counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of pages and thier sub items.
|
||||
* Creates metaboxes for any taxonomy menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $counter
|
||||
* @param string $context
|
||||
*/
|
||||
function wp_nav_menu_get_pages( $counter, $context ) {
|
||||
$pages_args = array(
|
||||
'child_of' => 0,
|
||||
'sort_order' => 'ASC',
|
||||
'sort_column' => 'post_title',
|
||||
'hierarchical' => 1,
|
||||
'exclude' => '',
|
||||
'include' => '',
|
||||
'meta_key' => '',
|
||||
'meta_value' => '',
|
||||
'authors' => '',
|
||||
'parent' => -1,
|
||||
'exclude_tree' => '',
|
||||
'number' => '',
|
||||
'offset' => 0 );
|
||||
|
||||
// Get all pages
|
||||
$pages_array = get_pages( $pages_args );
|
||||
|
||||
$items_counter = $counter;
|
||||
$parentli = $items_counter;
|
||||
|
||||
if ( !$pages_array ) {
|
||||
echo __('Not Found');
|
||||
return $items_counter;
|
||||
function wp_nav_menu_taxonomy_metaboxes() {
|
||||
$taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' );
|
||||
|
||||
if ( !$taxonomies )
|
||||
return false;
|
||||
|
||||
foreach ( $taxonomies as $tax ) {
|
||||
$id = sanitize_title_with_dashes( $tax->label );
|
||||
|
||||
// delete_transient( "nav_menu_items_{$tax->name}" );
|
||||
// delete_transient( "nav_menu_sub_items_{$tax->name}" );
|
||||
|
||||
add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'menus', 'side', 'default', $tax );
|
||||
}
|
||||
|
||||
// Display Loop
|
||||
foreach ( $pages_array as $post ) {
|
||||
if ( $post->post_parent == 0 ) {
|
||||
$post = wp_setup_nav_menu_item( $post, 'page', $items_counter );
|
||||
if ( $context == 'menu' ) {
|
||||
?>
|
||||
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $post, 'menu', $items_counter );
|
||||
$parentli = $post->ID;
|
||||
$items_counter++;
|
||||
$items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'menu' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
} elseif ( $context == 'default' ) {
|
||||
// Sidebar Menu
|
||||
?>
|
||||
<li>
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $post, 'default' );
|
||||
$parentli = $post->ID;
|
||||
$items_counter++;
|
||||
$items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
return $items_counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of categories and thier sub items.
|
||||
* Displays a metabox for managing the active menu being edited.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $counter
|
||||
* @param string $context
|
||||
*/
|
||||
function wp_nav_menu_get_categories( $counter, $context ) {
|
||||
$category_args = array(
|
||||
'type' => 'post',
|
||||
'child_of' => 0,
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
'include_last_update_time' => false,
|
||||
'hierarchical' => 1,
|
||||
'exclude' => '',
|
||||
'include' => '',
|
||||
'number' => '',
|
||||
'pad_counts' => false );
|
||||
function wp_nav_menu_manage_menu_metabox( $object, $menu ) { ?>
|
||||
<div id="submitpost" class="submitbox">
|
||||
<div id="minor-publishing">
|
||||
<div class="misc-pub-section misc-pub-section-last">
|
||||
<label class="howto" for="menu-name">
|
||||
<span><?php _e('Name'); ?></span>
|
||||
<input id="menu-name" name="menu-name" type="text" class="regular-text menu-item-textbox" value="<?php esc_attr_e( $menu['args'][1] ); ?>" />
|
||||
<br class="clear" />
|
||||
</label>
|
||||
</div><!--END .misc-pub-section misc-pub-section-last-->
|
||||
<br class="clear" />
|
||||
</div><!--END #misc-publishing-actions-->
|
||||
<div id="major-publishing-actions">
|
||||
<div id="delete-action">
|
||||
<a class="submitdelete deletion" href="<?php echo wp_nonce_url( admin_url('nav-menus.php?action=delete&menu=' . $menu['args'][0]), 'delete-nav_menu-' . $menu['args'][0] ); ?>"><?php _e('Delete Menu'); ?></a>
|
||||
</div><!--END #delete-action-->
|
||||
|
||||
$items_counter = $counter;
|
||||
|
||||
// Get all categories
|
||||
$categories_array = get_categories( $category_args );
|
||||
|
||||
if ( !$categories_array ) {
|
||||
_e('Not Found');
|
||||
return $items_counter;
|
||||
}
|
||||
|
||||
// Display Loop
|
||||
foreach ( $categories_array as $cat_item ) {
|
||||
if ( $cat_item->parent == 0 ) {
|
||||
$cat_item = wp_setup_nav_menu_item( $cat_item, 'category', $items_counter );
|
||||
// Custom Menu
|
||||
if ( $context == 'menu' ) {
|
||||
?>
|
||||
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
|
||||
<?php
|
||||
echo wp_get_nav_menu_item($cat_item, 'menu');
|
||||
$parentli = $cat_item->cat_ID;
|
||||
$items_counter++;
|
||||
$items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'menu' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
} elseif ( $context == 'default' ) {
|
||||
// Sidebar Menu
|
||||
?>
|
||||
<li>
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $cat_item, 'default' );
|
||||
$parentli = $cat_item->cat_ID;
|
||||
$items_counter++;
|
||||
$items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
return $items_counter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function that gets sub menu items.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $childof
|
||||
* @param string $items_counter
|
||||
* @param string $parentli
|
||||
* @param string $context
|
||||
* @param string $output_type
|
||||
*/
|
||||
function wp_nav_menu_sub_items( $childof, $items_counter, $parentli, $context, $output_type ) {
|
||||
$counter = $items_counter;
|
||||
|
||||
// Custom Menu
|
||||
if ( $output_type == 'menu' ) {
|
||||
$sub_args = array(
|
||||
'child_of' => $childof,
|
||||
'hide_empty' => false,
|
||||
'parent' => $childof);
|
||||
} elseif ( $output_type == 'default' ) {
|
||||
// Sidebar Menu
|
||||
$sub_args = array(
|
||||
'child_of' => $childof,
|
||||
'hide_empty' => false,
|
||||
'parent' => $childof);
|
||||
}
|
||||
|
||||
if ( $context == 'categories' ) {
|
||||
// Get Sub Category Items
|
||||
$item_type = 'category';
|
||||
$sub_array = get_categories($sub_args);
|
||||
} elseif ($context == 'pages') {
|
||||
// Get Sub Page Items
|
||||
$item_type = 'page';
|
||||
$sub_array = get_pages($sub_args);
|
||||
} else {
|
||||
$item_type = 'custom';
|
||||
$sub_array = array();
|
||||
}
|
||||
|
||||
if ( $sub_array ) {
|
||||
?>
|
||||
<ul id="sub-menu-<?php echo $context ?>">
|
||||
<?php
|
||||
// Display Loop
|
||||
foreach ( $sub_array as $sub_item ) {
|
||||
$sub_item = wp_setup_nav_menu_item( $sub_item, $item_type, $counter );
|
||||
if ( $output_type == 'menu' ) {
|
||||
?>
|
||||
<li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>">
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $sub_item, 'menu' );
|
||||
$counter++;
|
||||
$counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'menu' );
|
||||
?>
|
||||
</li>
|
||||
<?php
|
||||
} elseif ( $output_type == 'default' ) {
|
||||
// Sidebar Menu
|
||||
?>
|
||||
<li>
|
||||
<?php
|
||||
echo wp_get_nav_menu_item( $sub_item, 'default' );
|
||||
//$counter++;
|
||||
$counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'default' );
|
||||
?>
|
||||
</li>
|
||||
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<div id="publishing-action">
|
||||
<input class="button-primary" name="save_menu" type="submit" value="<?php esc_attr_e('Save Menu'); ?>" />
|
||||
</div><!--END #publishing-action-->
|
||||
<br class="clear" />
|
||||
</div><!--END #major-publishing-actions-->
|
||||
</div><!--END #submitpost .submitbox-->
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a metabox for creating a new menu.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
function wp_nav_menu_create_metabox() { ?>
|
||||
<p>
|
||||
<input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value="" />
|
||||
<input type="submit" name="create-menu" id="create-menu" class="button" value="<?php esc_attr_e('Create Menu'); ?>" />
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a metabox for the custom links menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
function wp_nav_menu_item_link_metabox() {
|
||||
$args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
|
||||
|
||||
// Cache the query for a day. @todo: Make sure to flush transient when links are updated.
|
||||
$query = get_transient( 'menu_item_query_custom_links' );
|
||||
if ( false == $query ) {
|
||||
$query = new WP_Query( $args );
|
||||
set_transient( 'menu_item_query_custom_links', $query, 86400 );
|
||||
}
|
||||
return $counter;
|
||||
|
||||
?>
|
||||
<p id="menu-item-url-wrap">
|
||||
<label class="howto" for="menu-item-url">
|
||||
<span><?php _e('URL'); ?></span>
|
||||
<input id="custom-menu-item-url" name="custom-menu-item-url" type="text" class="code menu-item-textbox" value="http://" />
|
||||
</label>
|
||||
</p>
|
||||
<br class="clear" />
|
||||
<p id="menu-item-name-wrap">
|
||||
<label class="howto" for="custom-menu-item-name">
|
||||
<span><?php _e('Text'); ?></span>
|
||||
<input id="custom-menu-item-name" name="custom-menu-item-name" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( __('Menu Item') ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<a class="show-all"><?php _e('View All'); ?></a>
|
||||
<a class="hide-all"><?php _e('Hide All'); ?></a>
|
||||
</p>
|
||||
<div id="available-links" class="list-wrap">
|
||||
<div class="list-container">
|
||||
<ul class="list">
|
||||
<?php echo wp_nav_menu_get_items( $query->posts, 'custom' ); ?>
|
||||
</ul>
|
||||
</div><!-- /.list-container-->
|
||||
</div><!-- /#available-links-->
|
||||
<p class="add-to-menu">
|
||||
<a class="button"><?php _e('Add to Menu'); ?></a>
|
||||
</p>
|
||||
<div class="clear"></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a metabox for a post type menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $object Not used.
|
||||
* @param string $post_type The post type object.
|
||||
*/
|
||||
function wp_nav_menu_item_post_type_metabox( $object, $post_type ) {
|
||||
$args = array( 'post_type' => $post_type['args']->name, );
|
||||
|
||||
if ( 'attachment' == $post_type['args']->name )
|
||||
$args['post_status'] = 'any';
|
||||
|
||||
// Cache the query for a day. @todo: Make sure to flush transient when objects are updated.
|
||||
$query = get_transient( "nav_menu_items_{$post_type['args']->name}" );
|
||||
if ( false == $query ) {
|
||||
$query = new WP_Query( $args );
|
||||
set_transient( "nav_menu_items_{$post_type['args']->name}", $query, 86400 );
|
||||
}
|
||||
|
||||
if ( !$query->posts )
|
||||
$error = '<li id="error">'. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .'</li>';
|
||||
|
||||
$pt_names = '';
|
||||
if ( is_array($query->posts) ) {
|
||||
foreach ( $query->posts as $post ) {
|
||||
if ( $post->post_title ) {
|
||||
$pt_names .= htmlentities( $post->post_title ) .'|';
|
||||
} else {
|
||||
$pt_names = sprintf( __('No %s exists'), $post_type['args']->label );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$id = sanitize_title_with_dashes( $post_type['args']->label );
|
||||
?>
|
||||
<p class="quick-search-wrap">
|
||||
<input type="text" class="quick-search regular-text" value="" />
|
||||
<a class="quick-search-submit button-secondary"><?php _e('Search'); ?></a>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<a class="show-all"><?php _e('View All'); ?></a>
|
||||
<a class="hide-all"><?php _e('Hide All'); ?></a>
|
||||
</p>
|
||||
|
||||
<div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap">
|
||||
<div class="list-container">
|
||||
<ul class="list">
|
||||
<?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $query->posts, 'post_type', $post_type['args']->name ); ?>
|
||||
</ul>
|
||||
</div><!-- /.list-container-->
|
||||
</div><!-- /#existing-categories-->
|
||||
<p class="add-to-menu">
|
||||
<a class="button-secondary"><?php _e('Add to Menu'); ?></a>
|
||||
</p>
|
||||
<input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr( $post_type['args']->name ); ?>-names" value="<?php echo esc_js( $pt_names ); ?>" />
|
||||
<br class="clear" />
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
jQuery(document).ready(function(){
|
||||
wp_nav_menu_autocomplete('<?php echo esc_attr($id); ?>');
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a metabox for a taxonomy menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $object Not used.
|
||||
* @param string $taxonomy The taxonomy object.
|
||||
*/
|
||||
function wp_nav_menu_item_taxonomy_metabox( $object, $taxonomy ) {
|
||||
$args = array(
|
||||
'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC',
|
||||
'hide_empty' => false, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '',
|
||||
'include' => '', 'number' => '', 'pad_counts' => false
|
||||
);
|
||||
|
||||
// Cache the query for a day. @todo: Make sure to flush transient when terms are updated.
|
||||
$terms = get_transient( "nav_menu_items_{$taxonomy['args']->name}" );
|
||||
if ( false == $terms ) {
|
||||
$terms = get_terms( $taxonomy['args']->name, $args );
|
||||
set_transient( "nav_menu_items_{$taxonomy['args']->name}", $terms, 86400 );
|
||||
}
|
||||
|
||||
if ( !$terms )
|
||||
$error = '<li id="error">'. sprintf( __( 'No %s exists' ), $taxonomy['args']->label ) .'</li>';
|
||||
|
||||
$term_names = '';
|
||||
if ( is_array($terms) ) {
|
||||
foreach ( $terms as $term ) {
|
||||
if ( $term->name ) {
|
||||
$term_names .= htmlentities( $term->name ) .'|';
|
||||
} else {
|
||||
$term_names = sprintf( __('No %s exists'), $taxonomy['args']->label );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$id = sanitize_title_with_dashes( $taxonomy['args']->label );
|
||||
?>
|
||||
<p class="quick-search-wrap">
|
||||
<input type="text" class="quick-search regular-text" value="" />
|
||||
<a class="quick-search-submit button-secondary"><?php _e('Search'); ?></a>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<a class="show-all"><?php _e('View All'); ?></a>
|
||||
<a class="hide-all"><?php _e('Hide All'); ?></a>
|
||||
</p>
|
||||
|
||||
<div id="existing-<?php echo esc_attr( $id ); ?>" class="list-wrap">
|
||||
<div class="list-container">
|
||||
<ul class="list">
|
||||
<?php echo isset( $error ) ? $error : wp_nav_menu_get_items( $terms, 'taxonomy', $taxonomy['args']->name ); ?>
|
||||
</ul>
|
||||
</div><!-- /.list-container-->
|
||||
</div><!-- /#existing-categories-->
|
||||
<p class="add-to-menu">
|
||||
<a class="button-secondary"><?php _e('Add to Menu'); ?></a>
|
||||
</p>
|
||||
<input type="hidden" class="autocomplete" name="autocomplete-<?php echo esc_attr($taxonomy['args']->name); ?>-names" value="<?php echo esc_js( $term_names ); ?>" />
|
||||
<br class="clear" />
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
// <![CDATA[
|
||||
jQuery(document).ready(function(){
|
||||
wp_nav_menu_autocomplete('<?php echo esc_attr($id); ?>');
|
||||
});
|
||||
// ]]>
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract function for returning all menu items of a menu item type.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $menu_items Array of objects containing all menu items to be displayed.
|
||||
* @param string $object_type Menu item type.
|
||||
* @param string $object Optional. Menu item type name.
|
||||
* @param string $context Optional. The context for how the menu items should be formatted.
|
||||
* @return string $ouput Menu items.
|
||||
*/
|
||||
function wp_nav_menu_get_items( $menu_items, $object_type, $object = null, $context = 'frontend' ) {
|
||||
if ( !$menu_items )
|
||||
return __( 'Not Found' );
|
||||
|
||||
$output = '';
|
||||
$i = 1;
|
||||
foreach ( $menu_items as $menu_item ) {
|
||||
// convert the 'parent' taxonomy property to 'post_parent'
|
||||
// so we don't have to duplicate this entire function.
|
||||
if ( !isset($menu_item->post_parent) )
|
||||
$menu_item->post_parent = $menu_item->parent;
|
||||
|
||||
// Cleanest way to get all attachements
|
||||
if ( 'attachment' == $object )
|
||||
$menu_item->post_parent = 0;
|
||||
|
||||
if ( 0 == $menu_item->post_parent ) {
|
||||
// Setup the menu item
|
||||
$menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
|
||||
$attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
|
||||
|
||||
$output .= '<li'. $attributes .'>';
|
||||
$output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
|
||||
$output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context );
|
||||
$output .= '</li>';
|
||||
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function to retrieve sub menu items.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $childof The Parent ID.
|
||||
* @param string $object_type The object type.
|
||||
* @param string $object The object name.
|
||||
* @return string $output sub menu items.
|
||||
*/
|
||||
function wp_get_nav_menu_sub_items( $childof, $object_type, $object = null, $context = 'frontend' ) {
|
||||
$args = array( 'child_of' => $childof, 'parent' => $childof, 'hide_empty' => false, );
|
||||
|
||||
switch ( $object_type ) {
|
||||
case 'post_type':
|
||||
$hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
|
||||
if ( in_array( $object, $hierarchical_post_types ) ) {
|
||||
$args['post_type'] = $object;
|
||||
$sub_menu_items = get_pages( $args );
|
||||
} else {
|
||||
$sub_menu_items = array();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'taxonomy':
|
||||
if ( is_taxonomy_hierarchical( $object ) ) {
|
||||
$sub_menu_items = get_terms( $object, $args );
|
||||
} else {
|
||||
$sub_menu_items = array();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$sub_menu_items = array();
|
||||
break;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$i = 1;
|
||||
if ( !empty($sub_menu_items) && !is_wp_error($sub_menu_items) ) {
|
||||
$output .= '<ul class="sub-menu menu-item-type-'. $object_type .'">';
|
||||
foreach ( $sub_menu_items as $menu_item ) {
|
||||
// Setup the menu item
|
||||
$menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
|
||||
$attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
|
||||
|
||||
$output .= '<li'. $attributes .'>';
|
||||
$output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
|
||||
$output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object );
|
||||
$output .= '</li>';
|
||||
|
||||
++$i;
|
||||
}
|
||||
$output .= '</ul>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
?>
|
@ -15,13 +15,26 @@ jQuery(document).ready(function($){
|
||||
|
||||
wp_drag_and_drop();
|
||||
|
||||
wp_update_post_data();
|
||||
// Delete AYS
|
||||
$('#update-nav-menu .deletion').click(function(){
|
||||
if ( confirm( navMenuL10n.warnDelete ) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
// Handle Save Button Clicks
|
||||
$('#save_menu').click(function(){
|
||||
return wp_update_post_data();
|
||||
});
|
||||
|
||||
|
||||
// close postboxes that should be closed
|
||||
$('.if-js-closed').removeClass('if-js-closed').addClass('closed');
|
||||
|
||||
// postboxes setup
|
||||
postboxes.add_postbox_toggles('menus');
|
||||
|
||||
// Clear the quick search textbox
|
||||
$('.quick-search').click(function(){
|
||||
$(this).attr( 'value', '' );
|
||||
@ -38,18 +51,14 @@ jQuery(document).ready(function($){
|
||||
});
|
||||
|
||||
// Delete menu item
|
||||
$('#menu-container .item-delete').live( 'click', function(){
|
||||
$('#menu-container .item-delete').live( 'click', function(e){
|
||||
return wp_remove_menu_item( $(this).attr('value') );
|
||||
});
|
||||
|
||||
// Update menu item settings (thickbox)
|
||||
$('#update-menu-item').click(function(){
|
||||
wp_update_menu_item();
|
||||
tb_remove();
|
||||
|
||||
// Give feedback to the user
|
||||
var id = $('#edit-item-id').val();
|
||||
$('#menu-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
|
||||
return tb_remove();
|
||||
});
|
||||
|
||||
// Close thickbox
|
||||
@ -58,55 +67,32 @@ jQuery(document).ready(function($){
|
||||
});
|
||||
|
||||
// Show All Button
|
||||
$('.show-all').click(function(){
|
||||
$(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 10px;' );
|
||||
$(this).offsetParent().find('.list-wrap').css( 'display','block' );
|
||||
$(this).siblings('.quick-search').attr( 'value', '' );
|
||||
$(this).offsetParent().find('.list-wrap li').css( 'display', 'block' );
|
||||
$(this).hide();
|
||||
$(this).siblings('.hide-all').show();
|
||||
$('.show-all').click(function(e){
|
||||
jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'block' );
|
||||
jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'block' );
|
||||
jQuery(e.currentTarget).hide();
|
||||
jQuery(e.currentTarget).siblings('.hide-all').show();
|
||||
});
|
||||
|
||||
// Hide All Button
|
||||
$('.hide-all').click(function(){
|
||||
$(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 0px;' );
|
||||
$(this).offsetParent().find('.list-wrap').css( 'display','none' );
|
||||
$(this).siblings('.quick-search').attr( 'value', 'Search' );
|
||||
$(this).offsetParent().find('.list-wrap li').css( 'display', 'none' );
|
||||
$(this).hide();
|
||||
$(this).siblings('.show-all').show();
|
||||
$('.hide-all').click(function(e){
|
||||
jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'none' );
|
||||
jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'none' );
|
||||
jQuery(e.currentTarget).hide();
|
||||
jQuery(e.currentTarget).siblings('.show-all').show();
|
||||
});
|
||||
|
||||
// Add menu item to queue
|
||||
$('.list input').click(function(){
|
||||
// Add menu items into the menu
|
||||
$('.add-to-menu').click(function(e){
|
||||
return wp_add_checked_items_to_menu(e.currentTarget);
|
||||
});
|
||||
|
||||
var item_type = jQuery(this).parent().siblings('.item-type').val();
|
||||
var item_title = jQuery(this).parent().siblings('.item-title').val();
|
||||
var item_url = jQuery(this).parent().siblings('.item-url').val();
|
||||
var item_id = jQuery(this).parent().siblings('.item-dbid').val();
|
||||
var item_parent_id = jQuery(this).parent().siblings('.item-parent').val();
|
||||
var item_description = jQuery(this).parent().siblings('.item-description').val();
|
||||
// Create a new link then add it to the menu
|
||||
$('#add-custom-links .add-to-menu a').click(function(e){
|
||||
var link_url = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-url').val();
|
||||
var link_name = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-name').val();
|
||||
|
||||
return wp_update_queue( $(this), item_type, item_title, item_url, item_id, item_parent_id, item_description );
|
||||
});
|
||||
|
||||
// Add queued menu items into the menu
|
||||
$('.enqueue a').click(function(){
|
||||
return wp_add_queued_items_to_menu(this);
|
||||
});
|
||||
|
||||
// Create the link, add it to the menu + available links section
|
||||
$('#add-custom-link .add-to-menu a').click(function(){
|
||||
var link_url = $(this).offsetParent().find('#menu-item-url').val();
|
||||
var link_name = $(this).offsetParent().find('#menu-item-name').val();
|
||||
|
||||
wp_add_queued_items_to_menu( this );
|
||||
|
||||
// Don't save the link if it was left with it's default settings
|
||||
if ( 'http://' == link_url || 'Menu Item' == link_name )
|
||||
return;
|
||||
|
||||
// and update the Menu with the new link
|
||||
wp_add_item_to_menu( 'custom', link_name, link_url, 0, 0, '' );
|
||||
// Add link to menu
|
||||
wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_none', '', '' );
|
||||
});
|
||||
});
|
@ -1 +1 @@
|
||||
jQuery(document).ready(function(a){wp_drag_and_drop();wp_update_post_data();a("#save_menu").click(function(){return wp_update_post_data()});a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();tb_remove();var b=a("#edit-item-id").val();a("#menu-"+b+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 10px;");a(this).offsetParent().find(".list-wrap").css("display","block");a(this).siblings(".quick-search").attr("value","");a(this).offsetParent().find(".list-wrap li").css("display","block");a(this).hide();a(this).siblings(".hide-all").show()});a(".hide-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 0px;");a(this).offsetParent().find(".list-wrap").css("display","none");a(this).siblings(".quick-search").attr("value","Search");a(this).offsetParent().find(".list-wrap li").css("display","none");a(this).hide();a(this).siblings(".show-all").show()});a(".list input").click(function(){var d=jQuery(this).parent().siblings(".item-type").val();var g=jQuery(this).parent().siblings(".item-title").val();var c=jQuery(this).parent().siblings(".item-url").val();var e=jQuery(this).parent().siblings(".item-dbid").val();var b=jQuery(this).parent().siblings(".item-parent").val();var f=jQuery(this).parent().siblings(".item-description").val();return wp_update_queue(a(this),d,g,c,e,b,f)});a(".enqueue a").click(function(){return wp_add_queued_items_to_menu(this)});a("#add-custom-link .add-to-menu a").click(function(){var b=a(this).offsetParent().find("#menu-item-url").val();var c=a(this).offsetParent().find("#menu-item-name").val();wp_add_queued_items_to_menu(this);if("http://"==b||"Menu Item"==c){return}wp_add_item_to_menu("custom",c,b,0,0,"")})});
|
||||
jQuery(document).ready(function(a){wp_drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#save_menu").click(function(){return wp_update_post_data()});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("menus");a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(b){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();return tb_remove()});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","block");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","block");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","none");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","none");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){return wp_add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(d){var b=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-url").val();var c=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-name").val();wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,c,b,"","","_none","","")})});
|
@ -8,66 +8,75 @@
|
||||
* @subpackage Administration
|
||||
*/
|
||||
|
||||
/**
|
||||
* Adds a link to the available links section
|
||||
*
|
||||
* @param object e - An object recieved via ajax
|
||||
*/
|
||||
function wp_update_links_list(e) {
|
||||
var link = '<li><dl><dt><label class="item-title"><input type="checkbox" id="link-'+ e.link_id +'" name="'+ e.link_name +'" value="'+ e.link_url +'" />'+ e.link_name +'</label></dt></dl></li>';
|
||||
|
||||
// Prepend the link to the available links section
|
||||
jQuery('#available-links .list').prepend( link );
|
||||
|
||||
// Give feedback to the user
|
||||
jQuery('#available-links .list #link-' + e.link_id).parent().animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
|
||||
function wp_nav_menu_autocomplete( id ) {
|
||||
jQuery('#add-'+ id +' .quick-search').autocomplete(jQuery( '#add-'+ id +' .autocomplete' ).val().split('|'));
|
||||
|
||||
jQuery('#add-'+ id +' .quick-search').result(function(event, data, formatted) {
|
||||
jQuery('#add-'+ id +' .list-wrap').css( 'display', 'block' );
|
||||
jQuery("#add-"+ id +" .list-wrap li:contains('" + data + "')").css( 'display', 'block' );
|
||||
jQuery('#add-'+ id +' .show-all').hide();
|
||||
jQuery('#add-'+ id +' .hide-all').show();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate the thickbox window with the selected menu items
|
||||
*
|
||||
* @param int o - the id of the menu li to edit.
|
||||
* @param int id - the id of the menu li to edit.
|
||||
*/
|
||||
function wp_edit_menu_item( id ) {
|
||||
var itemType = jQuery('#item-type' + id).val();
|
||||
var itemTitle = jQuery('#item-title' + id).val();
|
||||
var itemURL = jQuery('#item-url' + id).val();
|
||||
var itemAttrTitle = jQuery('#item-attr-title' + id).val();
|
||||
var itemTarget = jQuery('#item-target' + id).val();
|
||||
var itemDesc = jQuery('#item-description' + id).val();
|
||||
var item_type = jQuery('#menu-item-type' + id).val();
|
||||
var item_title = jQuery('#menu-item-title' + id).val();
|
||||
var item_link = jQuery('#menu-item-url' + id).val();
|
||||
var item_attr_title = jQuery('#menu-item-attr-title' + id).val();
|
||||
var item_target = jQuery('#menu-item-target' + id).val();
|
||||
var item_description = jQuery('#menu-item-description' + id).val();
|
||||
var item_classes = jQuery('#menu-item-classes' + id).val();
|
||||
var item_xfn = jQuery('#menu-item-xfn' + id).val();
|
||||
|
||||
// Disable the ability to edit the url for page and category items
|
||||
if ( 'page' == itemType || 'category' == itemType )
|
||||
jQuery( '#edit-item-url' ).attr('disabled', 'disabled' );
|
||||
// Only allow custom links to be editable.
|
||||
if ( 'custom' != item_type )
|
||||
jQuery( '#edit-menu-item-url' ).attr('disabled', 'disabled' );
|
||||
|
||||
// Populate the fields for thickbox
|
||||
jQuery( '#edit-item-id' ).val(id);
|
||||
jQuery( '#edit-item-title' ).val(itemTitle);
|
||||
jQuery( '#edit-item-url' ).val(itemURL);
|
||||
jQuery( '#edit-item-attr-title' ).val(itemAttrTitle);
|
||||
jQuery( '#edit-item-target' ).val(itemTarget);
|
||||
jQuery( "#edit-item-target option[value='" + itemTarget + "']" ).attr('selected', 'selected');
|
||||
jQuery( '#edit-item-description' ).val(itemDesc);
|
||||
jQuery( '#edit-menu-item-id' ).val(id);
|
||||
jQuery( '#edit-menu-item-title' ).val(item_title);
|
||||
jQuery( '#edit-menu-item-url' ).val(item_link);
|
||||
jQuery( '#edit-menu-item-attr-title' ).val(item_attr_title);
|
||||
jQuery( '#edit-menu-item-target' ).val(item_target);
|
||||
jQuery( "#edit-menu-item-target option[value='" + item_target + "']" ).attr('selected', 'selected');
|
||||
jQuery( '#edit-menu-item-description' ).val(item_description);
|
||||
jQuery( '#edit-menu-item-classes' ).val(item_classes);
|
||||
jQuery( '#edit-menu-item-xfn' ).val(item_xfn);
|
||||
|
||||
// focus
|
||||
jQuery( '#edit-menu-item-title' ).focus();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the values for the menu item being editing
|
||||
*/
|
||||
function wp_update_menu_item() {
|
||||
var id = jQuery('#edit-item-id').val();
|
||||
var itemTitle = jQuery('#edit-item-title').val();
|
||||
var itemURL = jQuery('#edit-item-url').val();
|
||||
var itemAttrTitle = jQuery('#edit-item-attr-title').val();
|
||||
var itemTarget = jQuery('#edit-item-target').val();
|
||||
var itemDesc = jQuery('#edit-item-description').val();
|
||||
var id = jQuery('#edit-menu-item-id').val();
|
||||
var item_title = jQuery('#edit-menu-item-title').val();
|
||||
var item_link = jQuery('#edit-menu-item-url').val();
|
||||
var item_attr_title = jQuery('#edit-menu-item-attr-title').val();
|
||||
var item_target = jQuery('#edit-menu-item-target').val();
|
||||
var item_description = jQuery('#edit-menu-item-description').val();
|
||||
var item_classes = jQuery('#edit-menu-item-classes').val();
|
||||
var item_xfn = jQuery('#edit-menu-item-xfn').val();
|
||||
|
||||
// update menu item settings
|
||||
jQuery('#menu-' + id).find('.item-title:first').html(itemTitle);
|
||||
jQuery('#item-title' + id).val(itemTitle);
|
||||
jQuery('#item-url' + id).val(itemURL);
|
||||
jQuery('#item-attr-title' + id).val(itemAttrTitle);
|
||||
jQuery('#item-target' + id).val(itemTarget);
|
||||
jQuery('#item-description' + id).val(itemDesc);
|
||||
// update menu item settings
|
||||
jQuery('.menu #menu-item' + id).find('span.item-title').html(item_title);
|
||||
jQuery('.menu #menu-item-title' + id).val(item_title);
|
||||
jQuery('.menu #menu-item-url' + id).val(item_link);
|
||||
jQuery('.menu #menu-item-attr-title' + id).val(item_attr_title);
|
||||
jQuery('.menu #menu-item-target' + id).val(item_target);
|
||||
jQuery('.menu #menu-item-description' + id).val(item_description);
|
||||
jQuery('.menu #menu-item-classes' + id).val(item_classes);
|
||||
jQuery('.menu #menu-item-xfn' + id).val(item_xfn);
|
||||
|
||||
jQuery('.menu #menu-item' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,166 +85,100 @@ function wp_update_menu_item() {
|
||||
* @param int o - the id of the menu li to remove.
|
||||
*/
|
||||
function wp_remove_menu_item( o ) {
|
||||
var todelete = document.getElementById('menu-' + o);
|
||||
var todelete = document.getElementById('menu-item' + o);
|
||||
|
||||
if ( todelete ) {
|
||||
// Give some feedback to the user
|
||||
jQuery( todelete ).find('dt').each(function(){
|
||||
jQuery(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { jQuery(this).parent().parent().remove() } } );
|
||||
});
|
||||
|
||||
wp_update_post_data();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepares menu items for POST
|
||||
*/
|
||||
function wp_update_post_data() {
|
||||
var i = 0;
|
||||
|
||||
jQuery('.menu li').each(function(i) {
|
||||
i = i + 1;
|
||||
var j = jQuery(this).attr('value');
|
||||
|
||||
jQuery(this).find('#item-position' + j).attr('value', i);
|
||||
jQuery(this).attr('id','menu-' + i);
|
||||
jQuery(this).attr('value', i);
|
||||
|
||||
jQuery(this).find('#item-dbid' + j).attr('name','item-dbid' + i);
|
||||
jQuery(this).find('#item-dbid' + j).attr('id','item-dbid' + i);
|
||||
|
||||
jQuery(this).find('#item-postmenu' + j).attr('name','item-postmenu' + i);
|
||||
jQuery(this).find('#item-postmenu' + j).attr('id','item-postmenu' + i);
|
||||
|
||||
var p = jQuery(this).find('#item-parent' + j).parent().parent().parent().attr('value');
|
||||
|
||||
jQuery(this).find('#item-parent' + j).attr('name','item-parent' + i);
|
||||
jQuery(this).find('#item-parent' + j).attr('id','item-parent' + i);
|
||||
|
||||
if (p) {
|
||||
// Do nothing
|
||||
} else {
|
||||
// reset p to be top level
|
||||
p = 0;
|
||||
}
|
||||
|
||||
jQuery(this).find('#item-parent' + j).attr('value', p);
|
||||
|
||||
jQuery(this).find('#item-title' + j).attr('name','item-title' + i);
|
||||
jQuery(this).find('#item-title' + j).attr('id','item-title' + i);
|
||||
|
||||
jQuery(this).find('#item-url' + j).attr('name','item-url' + i);
|
||||
jQuery(this).find('#item-url' + j).attr('id','item-url' + i);
|
||||
|
||||
jQuery(this).find('#item-description' + j).attr('name','item-description' + i);
|
||||
jQuery(this).find('#item-description' + j).attr('id','item-description' + i);
|
||||
|
||||
jQuery(this).find('#item-attr-title' + j).attr('name','item-attr-title' + i);
|
||||
jQuery(this).find('#item-attr-title' + j).attr('id','item-attr-title' + i);
|
||||
|
||||
jQuery(this).find('#item-target' + j).attr('name','item-target' + i);
|
||||
jQuery(this).find('#item-target' + j).attr('id','item-target' + i);
|
||||
|
||||
jQuery(this).find('#item-position' + j).attr('name', 'item-position' + i);
|
||||
jQuery(this).find('#item-position' + j).attr('id', 'item-position' + i);
|
||||
|
||||
jQuery(this).find('#item-type' + j).attr('name', 'item-type' + i);
|
||||
jQuery(this).find('#item-type' + j).attr('id', 'item-type' + i);
|
||||
|
||||
jQuery('#li-count').attr( 'value', i );
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds the item to the menu
|
||||
*
|
||||
* @param string id - The menu item's id
|
||||
* @param string additemtype - Page, Category, or Custom.
|
||||
* @param string itemtext - menu text.
|
||||
* @param string itemurl - url of the menu.
|
||||
* @param int itemid - menu id.
|
||||
* @param int itemparentid - default 0.
|
||||
* @param string itemdescription - the description of the menu item.
|
||||
* @param string item_db_id - The menu item's db id.
|
||||
* @param string item_object_id - The menu item's object id.
|
||||
* @param string item_type - The menu item's object type.
|
||||
* @param string item_append - The menu item's nice name.
|
||||
* @param string item_parent_id - The menu item's parent id.
|
||||
* @param string item_title - The menu item title.
|
||||
* @param string item_url - The menu item url
|
||||
* @param string item_description - The menu item description.
|
||||
* @param string item_attr_title - The title attribute.
|
||||
* @param string item_target - The target attribute.
|
||||
* @param string item_classes - Optional. Additional CSS classes for the menu item
|
||||
* @param string item_xfn - Optional. The rel attribute.
|
||||
*/
|
||||
function wp_add_item_to_menu( item_type, item_title, item_url, item_id, item_parent_id, item_description ) {
|
||||
function wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
|
||||
var randomnumber = wp_get_unique_menu_id();
|
||||
var hidden = wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
|
||||
|
||||
// Adds the item in the queue
|
||||
jQuery('.menu').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_type + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu' + randomnumber + '" id="item-postmenu' + randomnumber + '" value="' + item_id + '" /><input type="hidden" name="item-parent' + randomnumber + '" id="item-parent' + randomnumber + '" value="' + item_parent_id + '" /><input type="hidden" name="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + item_url + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + item_description + '" /><input type="hidden" name="item-position' + randomnumber + '" id="item-position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="item-type' + randomnumber + '" id="item-type' + randomnumber + '" value="' + item_type + '" /><input type="hidden" name="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /></li>');
|
||||
jQuery('.menu').append('<li id="menu-item' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_append + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl>' + hidden + '</li>');
|
||||
|
||||
// Give some feedback to the user
|
||||
jQuery( '.menu #menu-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
|
||||
jQuery( '.menu #menu-item' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
|
||||
|
||||
// Enable drag-n-drop
|
||||
wp_drag_and_drop();
|
||||
|
||||
wp_update_post_data();
|
||||
|
||||
// Reload thickbox
|
||||
tb_init('a.thickbox, area.thickbox, input.thickbox');
|
||||
};
|
||||
|
||||
/*
|
||||
* Queues items in perperation for appendToList
|
||||
*
|
||||
* @param string type - Page, Category, or Custom.
|
||||
* @param string link - menu text.
|
||||
* @param string url - url of the menu.
|
||||
* @param int id - menu id.
|
||||
* @param int parent_id - default 0.
|
||||
* @param string description - the description of the menu item.
|
||||
*/
|
||||
function wp_update_queue( e, item_type, item_title, item_url, item_id, item_parent_id, item_description ) {
|
||||
var randomnumber = wp_get_unique_menu_id();
|
||||
var menu_item_id = jQuery(e).attr('id');
|
||||
|
||||
if ( jQuery(e).attr('checked') ) {
|
||||
// Add menu item to the queue
|
||||
jQuery('#queue').append('<li id="menu-' + randomnumber + '" value="' + randomnumber + '"><div class="dropzone ui-droppable"></div><dl class="ui-droppable"><dt><span class="item-title">' + item_title + '</span><span class="item-controls"><span class="item-type">' + item_type + '</span><a class="item-edit thickbox" id="edit' + randomnumber + '" value="' + randomnumber +'" onClick="wp_edit_menu_item('+ randomnumber +')" title="' + navMenuL10n.thickbox + '" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">' + navMenuL10n.edit + '</a> | <a class="item-delete" id="delete' + randomnumber + '" value="' + randomnumber +'">Delete</a></span></dt></dl><input type="hidden" name="item-postmenu' + randomnumber + '" id="item-postmenu' + randomnumber + '" value="' + item_id + '" /><input type="hidden" name="item-parent' + randomnumber + '" id="item-parent' + randomnumber + '" value="' + item_parent_id + '" /><input type="hidden" name="item-title' + randomnumber + '" id="item-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-url' + randomnumber + '" id="item-url' + randomnumber + '" value="' + item_url + '" /><input type="hidden" name="item-description' + randomnumber + '" id="item-description' + randomnumber + '" value="' + item_description + '" /><input type="hidden" name="item-position' + randomnumber + '" id="item-position' + randomnumber + '" value="' + randomnumber + '" /><input type="hidden" name="item-type' + randomnumber + '" id="item-type' + randomnumber + '" value="' + item_type + '" /><input type="hidden" name="item-attr-title' + randomnumber + '" id="item-attr-title' + randomnumber + '" value="' + item_title + '" /><input type="hidden" name="item-target' + randomnumber + '" id="item-target' + randomnumber + '" value="0" /><input type="hidden" name="item-id' + randomnumber + '" id="item-id' + randomnumber + '" value="'+ menu_item_id +'" /></li>');
|
||||
|
||||
} else {
|
||||
// Remove the item from the queue
|
||||
if ( menu_item_id == jQuery('#queue li input[name^="item-id"]' ).val() ) {
|
||||
jQuery('#queue li input[name^="item-id"]' ).parent().remove()
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Grabs items from the queue and adds them to the menu.
|
||||
*
|
||||
* @param string button - a reference of the button that was clicked
|
||||
* @param string button - a reference to the button that was clicked
|
||||
*/
|
||||
function wp_add_queued_items_to_menu( button ) {
|
||||
// Grab items in queue
|
||||
var items = jQuery('#queue').children();
|
||||
function wp_add_checked_items_to_menu( button ) {
|
||||
// Grab checked items
|
||||
var items = jQuery(button).siblings('.list-wrap').find(':checked');
|
||||
|
||||
// Empty Queue
|
||||
jQuery('#queue').empty();
|
||||
|
||||
// Appends HTML to the menu
|
||||
jQuery('.menu').append( items );
|
||||
|
||||
// Give some feedback to the user
|
||||
// If nothing was checked, cancel
|
||||
if ( 0 == items.length )
|
||||
return false;
|
||||
|
||||
// Loop through each item, grab it's hidden data and add it to the menu.
|
||||
jQuery(items).each(function(){
|
||||
jQuery(this).find('dt').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
|
||||
var item_type = jQuery(this).parent().siblings('.menu-item-type').val();
|
||||
|
||||
if ( 'custom' == item_type ) {
|
||||
var item_attr_title = jQuery(this).parent().siblings('.menu-item-attr-title').val();
|
||||
var item_target = jQuery(this).parent().siblings('.menu-item-target').val();
|
||||
var item_classes = jQuery(this).parent().siblings('.menu-item-classes').val();
|
||||
var item_xfn = jQuery(this).parent().siblings('.menu-item-xfn').val();
|
||||
} else {
|
||||
var item_attr_title = '';
|
||||
var item_target = '_none';
|
||||
var item_classes = '';
|
||||
var item_xfn = '';
|
||||
};
|
||||
|
||||
var item_db_id = jQuery(this).parent().siblings('.menu-item-db-id').val();
|
||||
var item_object_id = jQuery(this).parent().siblings('.menu-item-object-id').val();
|
||||
var item_append = jQuery(this).parent().siblings('.menu-item-append').val();
|
||||
var item_parent_id = jQuery(this).parent().siblings('.menu-item-parent-id').val();
|
||||
var item_title = jQuery(this).parent().siblings('.menu-item-title').val();
|
||||
var item_url = jQuery(this).parent().siblings('.menu-item-url').val();
|
||||
var item_description = jQuery(this).parent().siblings('.menu-item-description').val();
|
||||
|
||||
if ( undefined == item_description ) {
|
||||
item_description = '';
|
||||
};
|
||||
|
||||
// Add the menu item to the menu
|
||||
wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
|
||||
|
||||
// uncheck the menu item in the list
|
||||
jQuery(this).attr( 'checked', false );
|
||||
});
|
||||
|
||||
// Uncheck the checkboxes in the list
|
||||
jQuery(button).offsetParent().find('.list-container input').attr('checked', false);
|
||||
|
||||
wp_update_post_data();
|
||||
|
||||
// Enable drag-n-drop
|
||||
wp_drag_and_drop();
|
||||
|
||||
// Reload thickbox
|
||||
tb_init('a.thickbox, area.thickbox, input.thickbox');
|
||||
};
|
||||
|
||||
/**
|
||||
* Allow the items in the Menu to be dragged and dropped.
|
||||
* Makes the menu items drag and droppable.
|
||||
*/
|
||||
function wp_drag_and_drop() {
|
||||
// Make sure all li's have dropzones
|
||||
@ -251,7 +194,7 @@ function wp_drag_and_drop() {
|
||||
opacity: .8,
|
||||
addClasses: false,
|
||||
helper: 'clone',
|
||||
zIndex: 100,
|
||||
zIndex: 100
|
||||
});
|
||||
|
||||
// make menu item droppable
|
||||
@ -306,6 +249,49 @@ function wp_drag_and_drop() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares menu items for POST.
|
||||
*/
|
||||
function wp_update_post_data() {
|
||||
var i = 0;
|
||||
|
||||
jQuery('.menu li').each(function(i) {
|
||||
i = i + 1;
|
||||
var j = jQuery(this).attr('value');
|
||||
|
||||
jQuery(this).find('#menu-item-position' + j).attr('value', i);
|
||||
jQuery(this).attr('id','menu-item' + i);
|
||||
jQuery(this).attr('value', i);
|
||||
|
||||
jQuery(this).find('#menu-item-db-id' + j).attr('id','menu-item-db-id' + i);
|
||||
jQuery(this).find('#menu-item-object-id' + j).attr('id','menu-item-object-id' + i);
|
||||
jQuery(this).find('#menu-item-append' + j).attr('id', 'menu-item-append' + i);
|
||||
jQuery(this).find('#menu-item-type' + j).attr('id', 'menu-item-type' + i);
|
||||
jQuery(this).find('#menu-item-position' + j).attr('id', 'menu-item-position' + i);
|
||||
|
||||
var p = jQuery(this).find('#menu-item-parent-id' + j).parent().parent().parent().attr('value');
|
||||
jQuery(this).find('#menu-item-parent-id' + j).attr('id','menu-item-parent-id' + i);
|
||||
if (p) {
|
||||
// Do nothing
|
||||
} else {
|
||||
// reset p to be top level
|
||||
p = 0;
|
||||
}
|
||||
jQuery(this).find('#menu-item-parent-id' + j).attr('value', p);
|
||||
|
||||
jQuery(this).find('#menu-item-title' + j).attr('id','menu-item-title' + i);
|
||||
jQuery(this).find('#menu-item-url' + j).attr('id','menu-item-url' + i);
|
||||
jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i);
|
||||
jQuery(this).find('#menu-item-classes' + j).attr('id','menu-item-classes' + i);
|
||||
jQuery(this).find('#menu-item-xfn' + j).attr('id','menu-item-xfn' + i);
|
||||
jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i);
|
||||
jQuery(this).find('#menu-item-attr-title' + j).attr('id','menu-item-attr-title' + i);
|
||||
jQuery(this).find('#menu-item-target' + j).attr('id','menu-item-target' + i);
|
||||
|
||||
jQuery('#li-count').attr( 'value', i );
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a unique number based on how many items are in the menu
|
||||
*/
|
||||
@ -331,4 +317,40 @@ function wp_get_unique_menu_id() {
|
||||
}
|
||||
}
|
||||
return randomnumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the nessecary hidden inputs for each menu item.
|
||||
*
|
||||
* @param string item_db_id - The menu item's db id.
|
||||
* @param string item_object_id - The menu item's object id.
|
||||
* @param string item_type - The menu item's object type.
|
||||
* @param string item_append - The menu item's nice name.
|
||||
* @param string item_parent_id - The menu item's parent id.
|
||||
* @param string item_title - The menu item title.
|
||||
* @param string item_url - The menu item url
|
||||
* @param string item_description - The menu item description.
|
||||
* @param string item_attr_title - The title attribute.
|
||||
* @param string item_target - The target attribute.
|
||||
* @param string item_classes - Optional. Additional CSS classes for the menu item
|
||||
* @param string item_xfn - Optional. The rel attribute.
|
||||
*/
|
||||
function wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
|
||||
var hidden = '';
|
||||
|
||||
hidden += '<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id' + randomnumber + '" value="' + item_db_id + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id' + randomnumber + '" value="' + item_object_id + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-type[]" id="menu-item-type' + randomnumber + '" value="' + item_type + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-append[]" id="menu-item-append' + randomnumber + '" value="' + item_append + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id' + randomnumber + '" value="' + item_parent_id + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-position[]" id="menu-item-position' + randomnumber + '" value="' + randomnumber + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-title[]" id="menu-item-title' + randomnumber + '" value="' + item_title + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title' + randomnumber + '" value="' + item_attr_title + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-url[]" id="menu-item-url' + randomnumber + '" value="' + item_url + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-target[]" id="menu-item-target' + randomnumber + '" value="' + item_target + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-description[]" id="menu-item-description' + randomnumber + '" value="' + item_description + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-classes[]" id="menu-item-classes' + randomnumber + '" value="' + item_classes + '" />';
|
||||
hidden += '<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn' + randomnumber + '" value="' + item_xfn + '" />';
|
||||
|
||||
return hidden;
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -9,170 +9,203 @@
|
||||
* @subpackage Administration
|
||||
*/
|
||||
|
||||
require_once('admin.php');
|
||||
/** Load WordPress Administration Bootstrap */
|
||||
require_once( 'admin.php' );
|
||||
|
||||
/*
|
||||
TODO
|
||||
Add caps: edit_menus, delete_menus
|
||||
*/
|
||||
// Permissions Check
|
||||
if ( ! current_user_can('switch_themes') )
|
||||
wp_die( __( 'Cheatin’ uh?' ));
|
||||
|
||||
// Nav Menu CSS
|
||||
wp_admin_css( 'nav-menu' );
|
||||
|
||||
// jQuery
|
||||
wp_enqueue_script( 'jquery' );
|
||||
wp_enqueue_script( 'jquery-ui-draggable' );
|
||||
wp_enqueue_script( 'jquery-ui-droppable' );
|
||||
wp_enqueue_script( 'jquery-ui-sortable' );
|
||||
wp_enqueue_script( 'jquery-ui-dialog' );
|
||||
wp_enqueue_script( 'jquery-autocomplete' );
|
||||
|
||||
// Nav Menu functions
|
||||
wp_enqueue_script( 'nav-menu-dynamic-functions' );
|
||||
wp_enqueue_script( 'nav-menu-default-items' );
|
||||
wp_enqueue_script( 'jquery-autocomplete' );
|
||||
wp_enqueue_script( 'nav-menu-php-functions' );
|
||||
|
||||
// Metaboxes
|
||||
wp_enqueue_script( 'common' );
|
||||
wp_enqueue_script( 'wp-lists' );
|
||||
wp_enqueue_script( 'postbox' );
|
||||
|
||||
// Thickbox
|
||||
add_thickbox();
|
||||
|
||||
require_once( 'admin-header.php' );
|
||||
// Load all the nav menu interface functions
|
||||
require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
|
||||
|
||||
function wp_reset_nav_menu() {
|
||||
wp_nav_menu_setup( true );
|
||||
return true;
|
||||
}
|
||||
|
||||
// Container for any messages displayed to the user
|
||||
$messages_div = '';
|
||||
$menu_id_in_edit = 0;
|
||||
$updated = false;
|
||||
$advanced_option_descriptions = 'no';
|
||||
|
||||
// Check which menu is selected and if menu is in edit already
|
||||
if ( isset( $_GET['edit-menu'] ) ) {
|
||||
$menu_selected_id = (int) $_GET['edit-menu'];
|
||||
$updated = true;
|
||||
} elseif ( isset( $_POST[ 'menu-id-in-edit' ] ) ) {
|
||||
$menu_selected_id = (int) $_POST[ 'menu-id-in-edit' ];
|
||||
} else {
|
||||
$menu_selected_id = 0;
|
||||
}
|
||||
// Container that stores the name of the active menu
|
||||
$nav_menu_selected_title = '';
|
||||
|
||||
// Delete a menu
|
||||
if ( isset($_GET['delete-menu']) && $_GET['delete-menu'] > 0 ) {
|
||||
// if ( ! current_user_can('delete_menus') )
|
||||
// wp_die( __( 'Cheatin’ uh?' ));
|
||||
// The menu id of the current menu being edited
|
||||
$nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
|
||||
|
||||
$menu_id = (int) $_GET['delete-menu'];
|
||||
check_admin_referer( 'delete_menu-' . $menu_id );
|
||||
// Allowed actions: add, update, delete
|
||||
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
|
||||
|
||||
wp_delete_nav_menu( $menu_id );
|
||||
$messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('Menu successfully deleted.') . '</p></div>';
|
||||
$menu_selected_id = 0;
|
||||
$updated = true;
|
||||
}
|
||||
switch ( $action ) {
|
||||
case 'delete':
|
||||
check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
|
||||
|
||||
// Default Menu to show
|
||||
$menus = wp_get_nav_menus();
|
||||
|
||||
if ( empty($menus) && empty($_POST) ) {
|
||||
wp_create_default_nav_menu();
|
||||
$menus = wp_get_nav_menus();
|
||||
}
|
||||
|
||||
if ( ! $menu_selected_id && ! empty($menus) )
|
||||
$menu_selected_id = $menus[0]->term_id;
|
||||
|
||||
// Get the name of the current Menu
|
||||
$menu_title = '';
|
||||
$valid_menu = false;
|
||||
if ( $menu_selected_id > 0 ) {
|
||||
foreach ( $menus as $menu ) {
|
||||
if ( $menu->term_id == $menu_selected_id ) {
|
||||
$menu_title = $menu->name;
|
||||
$valid_menu = true;
|
||||
break;
|
||||
if ( is_nav_menu($nav_menu_selected_id) ) {
|
||||
wp_delete_nav_menu( $nav_menu_selected_id );
|
||||
$messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('Menu successfully deleted.') . '</p></div>';
|
||||
$nav_menu_selected_id = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'update':
|
||||
check_admin_referer( 'update-nav_menu' );
|
||||
|
||||
// Add Menu
|
||||
if ( isset($_POST['create-menu']) ) {
|
||||
if ( current_theme_supports('nav-menus') ) {
|
||||
$add_nav_menu = esc_html( $_POST['create-menu-name'] );
|
||||
|
||||
if ( $add_nav_menu ) {
|
||||
$add_nav_menu = wp_create_nav_menu( $add_nav_menu );
|
||||
|
||||
if ( is_wp_error( $add_nav_menu ) ) {
|
||||
$messages_div = '<div id="message" class="error fade below-h2"><p>' . $add_nav_menu->get_error_message() . '</p></div>';
|
||||
} else {
|
||||
$nav_menu_selected_id = $add_nav_menu->term_id;
|
||||
$nav_menu_selected_title = $add_nav_menu->name;
|
||||
$messages_div = '<div id="message" class="updated fade below-h2"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), esc_html( $add_nav_menu->name ) ) . '</p></div>';
|
||||
}
|
||||
} else {
|
||||
$messages_div = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>';
|
||||
}
|
||||
unset($add_nav_menu);
|
||||
}
|
||||
}
|
||||
|
||||
// Update menu name
|
||||
if ( isset($_POST['menu-name']) ) {
|
||||
$old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A );
|
||||
$args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], );
|
||||
$new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args );
|
||||
}
|
||||
|
||||
// Update menu items
|
||||
$update_nav_items = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0;
|
||||
$update_nav_menu = is_nav_menu( $nav_menu_selected_id );
|
||||
|
||||
if ( !is_wp_error($update_nav_menu) ) {
|
||||
$menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
|
||||
$parent_menu_ids = array();
|
||||
|
||||
// Loop through all POST variables
|
||||
for ( $k = 0; $k < $update_nav_items; $k++ ) {
|
||||
|
||||
$menu_item_db_id = isset( $_POST['menu-item-db-id'][$k] ) ? $_POST['menu-item-db-id'][$k] : 0;
|
||||
$menu_item_object_id = isset( $_POST['menu-item-object-id'][$k] ) ? $_POST['menu-item-object-id'][$k] : 0;
|
||||
$menu_item_parent_id = isset( $_POST['menu-item-parent-id'][$k] ) ? $_POST['menu-item-parent-id'][$k] : 0;
|
||||
$menu_item_position = isset( $_POST['menu-item-position'][$k] ) ? $_POST['menu-item-position'][$k] : 0;
|
||||
$menu_item_type = isset( $_POST['menu-item-type'][$k] ) ? $_POST['menu-item-type'][$k] : 'custom';
|
||||
$menu_item_append = isset( $_POST['menu-item-append'][$k] ) ? $_POST['menu-item-append'][$k] : 'custom';
|
||||
|
||||
$menu_item_title = isset( $_POST['menu-item-title'][$k] ) ? $_POST['menu-item-title'][$k] : '';
|
||||
$menu_item_url = isset( $_POST['menu-item-url'][$k] ) ? $_POST['menu-item-url'][$k] : '';
|
||||
$menu_item_description = isset( $_POST['menu-item-description'][$k] ) ? $_POST['menu-item-description'][$k]: '';
|
||||
$menu_item_attr_title = isset( $_POST['menu-item-attr-title'][$k] ) ? $_POST['menu-item-attr-title'][$k] : '';
|
||||
$menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : 0;
|
||||
$menu_item_classes = isset( $_POST['menu-item-classes'][$k] ) ? $_POST['menu-item-classes'][$k] : '';
|
||||
$menu_item_xfn = isset( $_POST['menu-item-xfn'][$k] ) ? $_POST['menu-item-xfn'][$k] : '';
|
||||
|
||||
// Menu item title can't be blank
|
||||
if ( '' == $menu_item_title )
|
||||
continue;
|
||||
|
||||
// Populate the menu item
|
||||
$post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
|
||||
'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
|
||||
'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
|
||||
'post_content' => $menu_item_description, 'post_title' => $menu_item_title );
|
||||
|
||||
// New menu item
|
||||
if ( $menu_item_db_id == 0 ) {
|
||||
$menu_item_db_id = wp_insert_post( $post );
|
||||
} elseif ( isset( $menu_items[$menu_item_db_id] ) ) {
|
||||
$post['ID'] = $menu_item_db_id;
|
||||
wp_update_post( $post );
|
||||
unset( $menu_items[$menu_item_db_id] );
|
||||
}
|
||||
$parent_menu_ids[$k] = $menu_item_db_id;
|
||||
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type );
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append );
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id );
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_target', esc_attr($menu_item_target) );
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_classes', esc_attr($menu_item_classes) );
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_xfn', esc_attr($menu_item_xfn) );
|
||||
|
||||
// @todo: only save custom link urls.
|
||||
update_post_meta( $menu_item_db_id, 'menu_item_url', esc_url_raw( $menu_item_url ) );
|
||||
}
|
||||
|
||||
// Remove menu items from the menu that weren't in $_POST
|
||||
if ( !empty( $menu_items ) ) {
|
||||
foreach ( array_keys( $menu_items ) as $menu_item_id ) {
|
||||
wp_delete_post( $menu_item_id );
|
||||
}
|
||||
}
|
||||
$messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ( isset( $_POST['li-count'] ) )
|
||||
$post_counter = $_POST['li-count'];
|
||||
else
|
||||
$post_counter = 0;
|
||||
// Get all nav menus
|
||||
$nav_menus = wp_get_nav_menus();
|
||||
|
||||
// Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
|
||||
if ( isset( $_POST['create-menu'] ) && ! $updated ) {
|
||||
$insert_menu_name = $_POST['create-menu-name'];
|
||||
// Get recently edited nav menu
|
||||
$recently_edited = get_user_option( 'nav_menu_recently_edited' );
|
||||
|
||||
if ( $insert_menu_name ) {
|
||||
$menu = wp_create_nav_menu( $insert_menu_name );
|
||||
if ( is_wp_error( $menu ) ) {
|
||||
$messages_div = '<div id="message" class="error fade below-h2"><p>' . $menu->get_error_message() . '</p></div>';
|
||||
} else {
|
||||
$menus[$menu->term_id] = $menu;
|
||||
$menu_selected_id = $menu->term_id;
|
||||
$menu_id_in_edit = $menu_selected_id;
|
||||
$menu_title = $menu->name;
|
||||
$messages_div = '<div id="message" class="updated fade below-h2"><p>' . sprintf( __('“%s” menu has been created.'), esc_html( $menu->name ) ) . '</p></div>';
|
||||
$post_counter = 0;
|
||||
}
|
||||
// If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu.
|
||||
if ( !$recently_edited && is_nav_menu($nav_menu_selected_id) ) {
|
||||
$recently_edited = $nav_menu_selected_id;
|
||||
|
||||
// Else if $nav_menu_selected_id is not a menu, but $recently_edited is, grab that one.
|
||||
} elseif ( 0 == $nav_menu_selected_id && is_nav_menu($recently_edited) ) {
|
||||
$nav_menu_selected_id = $recently_edited;
|
||||
|
||||
// Else try to grab the first menu from the menus list
|
||||
} elseif ( 0 == $nav_menu_selected_id && ! empty($nav_menus) ) {
|
||||
$nav_menu_selected_id = $nav_menus[0]->term_id;
|
||||
}
|
||||
|
||||
// Update the user's setting
|
||||
if ( $nav_menu_selected_id != $recently_edited && is_nav_menu($nav_menu_selected_id) )
|
||||
update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
|
||||
|
||||
// If there's a menu, get it's name.
|
||||
if ( !$nav_menu_selected_title && $nav_menu_selected_title = is_nav_menu( $nav_menu_selected_id ) ) {
|
||||
$nav_menu_selected_title = $nav_menu_selected_title->name;
|
||||
}
|
||||
|
||||
// The user has no menus.
|
||||
if ( !is_nav_menu( $nav_menu_selected_id ) ) {
|
||||
if ( current_theme_supports('nav-menus') ) {
|
||||
$messages_div = '<div id="message" class="updated"><p>' . __('You haven\'t setup any menus yet. Create a new menu.') . '</p></div>';
|
||||
} else {
|
||||
$messages_div = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>';
|
||||
$messages_div = '<div id="message" class="error"><p>' . __('The current theme does not support menus.') . '</p></div>';
|
||||
}
|
||||
$updated = true;
|
||||
}
|
||||
|
||||
if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
|
||||
$menu_items = wp_get_nav_menu_items( $menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
|
||||
$parent_menu_ids = array();
|
||||
|
||||
// Loop through all POST variables
|
||||
for ( $k = 1; $k <= $post_counter; $k++ ) {
|
||||
$db_id = isset( $_POST['item-dbid'.$k] )? $_POST['item-dbid'.$k] : 0;
|
||||
$object_id = isset( $_POST['item-postmenu'.$k] )? $_POST['item-postmenu'.$k] : 0;
|
||||
$parent_id = isset( $_POST['item-parent'.$k] )? $_POST['item-parent'.$k] : 0;
|
||||
$custom_title = isset( $_POST['item-title'.$k] )? $_POST['item-title'.$k] : '';
|
||||
$custom_linkurl = ( isset( $_POST['item-url'.$k] ) && 'custom' == $_POST['item-type'.$k] ) ? $_POST['item-url'.$k] : '';
|
||||
$custom_description = isset( $_POST['item-description'.$k] )? $_POST['item-description'.$k] : '';
|
||||
|
||||
// doesn't seem to be used by UI
|
||||
$position = isset( $_POST['item-position'.$k] )? $_POST['item-position'.$k] : 0;
|
||||
$linktype = isset( $_POST['item-type'.$k] )? $_POST['item-type'.$k] : 'custom';
|
||||
$custom_anchor_title = isset( $_POST['item-attr-title'.$k] )? $_POST['item-attr-title'.$k] : $custom_title;
|
||||
$new_window = isset( $_POST['item-target'.$k] )? $_POST['item-target'.$k] : 0;
|
||||
|
||||
$post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
|
||||
'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position,
|
||||
'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ),
|
||||
'post_content' => $custom_description, 'post_title' => $custom_title );
|
||||
|
||||
if ( $parent_id > 0 && isset( $parent_menu_ids[$parent_id] ) )
|
||||
$post['post_parent'] = $parent_menu_ids[$parent_id];
|
||||
|
||||
// New menu item
|
||||
if ( $db_id == 0 ) {
|
||||
$db_id = wp_insert_post( $post );
|
||||
} elseif ( isset( $menu_items[$db_id] ) ) {
|
||||
$post['ID'] = $db_id;
|
||||
wp_update_post( $post );
|
||||
unset( $menu_items[$db_id] );
|
||||
}
|
||||
$parent_menu_ids[ $k ] = $db_id;
|
||||
|
||||
update_post_meta( $db_id, 'menu_type', $linktype );
|
||||
update_post_meta( $db_id, 'object_id', $object_id );
|
||||
if ( $new_window )
|
||||
update_post_meta( $db_id, 'menu_new_window', 1 );
|
||||
else
|
||||
update_post_meta( $db_id, 'menu_new_window', 0 );
|
||||
if ( $custom_linkurl )
|
||||
update_post_meta( $db_id, 'menu_link', esc_url_raw( $custom_linkurl ) );
|
||||
|
||||
}
|
||||
if ( !empty( $menu_items ) ) {
|
||||
foreach ( array_keys( $menu_items ) as $menu_id ) {
|
||||
wp_delete_post( $menu_id );
|
||||
}
|
||||
}
|
||||
$messages_div = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>';
|
||||
} else {
|
||||
add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) );
|
||||
}
|
||||
|
||||
// Get the admin header
|
||||
require_once( 'admin-header.php' );
|
||||
?>
|
||||
<div class="wrap">
|
||||
<?php screen_icon(); ?>
|
||||
@ -180,266 +213,110 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
|
||||
<?php echo $messages_div; ?>
|
||||
<div class="hide-if-js error"><p><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></p></div>
|
||||
|
||||
<form onsubmit="wp_update_post_data();" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data">
|
||||
<?php if ( !empty($menus) && count($menus) > 1 ) : ?>
|
||||
<ul class="subsubsub">
|
||||
<?php
|
||||
foreach ( $menus as $menu ) {
|
||||
$sep = end( $menus ) == $menu ? '' : ' | ';
|
||||
if ( ( $menu_id_in_edit == $menu->term_id ) || ( $menu_selected_id == $menu->term_id ) ) { ?>
|
||||
<li><a href='nav-menus.php?edit-menu=<?php echo esc_attr($menu->term_id); ?>' class="current"><?php echo esc_html( $menu->name ); ?></a><?php echo $sep; ?></li>
|
||||
<?php } else { ?>
|
||||
<li><a href='nav-menus.php?edit-menu=<?php echo esc_attr($menu->term_id); ?>'><?php echo esc_html( $menu->name ); ?></a><?php echo $sep; ?></li>
|
||||
<?php }
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
<?php if ( !empty($nav_menus) && count($nav_menus) > 1 ) : ?>
|
||||
<ul class="subsubsub">
|
||||
<?php
|
||||
foreach ( $nav_menus as $_nav_menu ) {
|
||||
$sep = end( $nav_menus ) == $_nav_menu ? '' : ' | ';
|
||||
|
||||
if ( $nav_menu_selected_id == $_nav_menu->term_id )
|
||||
echo '<li><a href="'. admin_url( 'nav-menus.php?action=edit&menu=' . esc_attr($_nav_menu->term_id) ) .'" class="current">'. esc_html( $_nav_menu->name ) .'</a>'. $sep .'</li>';
|
||||
else
|
||||
echo '<li><a href="'. admin_url( 'nav-menus.php?action=edit&menu=' . esc_attr($_nav_menu->term_id) ) .'">'. esc_html( $_nav_menu->name ) .'</a>'. $sep .'</li>';
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="menu-management" class="metabox-holder has-right-sidebar">
|
||||
<div id="menu-management" class="metabox-holder has-right-sidebar">
|
||||
<form id="update-nav-menu" onsubmit="wp_update_post_data();" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data">
|
||||
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
|
||||
<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
|
||||
<?php wp_nonce_field( 'update-nav_menu' ); ?>
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="hidden" name="li-count" id="li-count" value="0" />
|
||||
<input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
|
||||
|
||||
<div id="post-body">
|
||||
<div id="post-body-content">
|
||||
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
|
||||
<?php if ( $valid_menu and ! empty( $menus ) ) : ?>
|
||||
<?php if ( is_nav_menu($nav_menu_selected_id) ) : ?>
|
||||
<div id="menu-container" class="postbox">
|
||||
<h3 class="hndle"><?php echo esc_html( $menu_title ); ?></h3>
|
||||
<h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3>
|
||||
<div class="inside">
|
||||
<input type="hidden" name="li-count" id="li-count" value="0" />
|
||||
<input type="hidden" name="menu-id-in-edit" id="menu-id-in-edit" value="<?php echo esc_attr( $menu_selected_id ); ?>" />
|
||||
<?php
|
||||
if ( $menu_selected_id > 0 )
|
||||
echo wp_get_nav_menu( array( 'type' => 'backend', 'menu' => $menu_selected_id, 'ul_class' => 'menu' ) );
|
||||
?>
|
||||
|
||||
<div id="queue" class="hide">
|
||||
</div><!--/#queue-->
|
||||
|
||||
<?php echo wp_get_nav_menu( array( 'context' => 'backend', 'menu' => $nav_menu_selected_id ) ); ?>
|
||||
|
||||
</div><!-- /.inside -->
|
||||
<!-- /#nav-menu-canvas .postbox-->
|
||||
</div>
|
||||
<p>
|
||||
<script type="text/javascript">
|
||||
wp_update_post_data();
|
||||
</script>
|
||||
<a class="submitdelete deletion" href="<?php echo wp_nonce_url( admin_url('nav-menus.php?delete-menu=' . $menu_selected_id), 'delete_menu-' . $menu_selected_id ); ?>"><?php _e('Delete Menu'); ?></a>
|
||||
<input class="button-primary save" name="save_menu" type="submit" value="<?php esc_attr_e('Save All Changes'); ?>" />
|
||||
<br class="clear" />
|
||||
</p>
|
||||
<script type="text/javascript">
|
||||
wp_update_post_data();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div><!-- /#normal-sortables-->
|
||||
</div><!-- /#post-body-content-->
|
||||
</div><!--- /#post-body -->
|
||||
<div id="menu-settings-column" class="inner-sidebar">
|
||||
<div id="side-sortables" class="meta-box-sortables ui-sortable">
|
||||
|
||||
<div id="create-menu" class="postbox">
|
||||
<h3 class="hndle"><?php esc_html_e('Create Menu'); ?></h3>
|
||||
<div class="inside">
|
||||
<p>
|
||||
<input type="text" name="create-menu-name" id="create-menu-name" class="regular-text" value="" />
|
||||
<input type="submit" name="create-menu" id="create-menu" class="button" value="<?php esc_attr_e('Create Menu'); ?>" />
|
||||
</p>
|
||||
</div><!-- /.inside-->
|
||||
</div><!--END #create-menu-->
|
||||
|
||||
<div id="add-custom-link" class="postbox">
|
||||
<h3 class="hndle"><?php esc_html_e('Add a Custom Link'); ?></h3>
|
||||
<div class="inside">
|
||||
<p id="menu-item-url-wrap">
|
||||
<label class="howto" for="menu-item-url">
|
||||
<span><?php _e('URL'); ?></span>
|
||||
<input id="menu-item-url" name="menu-item-url" type="text" class="code" value="http://" />
|
||||
</label>
|
||||
</p>
|
||||
<br class="clear" />
|
||||
<p id="menu-item-name-wrap">
|
||||
<label class="howto" for="custom-menu-item-name">
|
||||
<span><?php _e('Text'); ?></span>
|
||||
<input id="menu-item-name" type="text" class="regular-text" value="<?php echo esc_attr( __('Menu Item') ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<a class="show-all"><?php _e('View All'); ?></a>
|
||||
<a class="hide-all"><?php _e('Hide All'); ?></a>
|
||||
</p>
|
||||
<div id="available-links" class="list-wrap">
|
||||
<div class="list-container">
|
||||
<ul class="list">
|
||||
<?php $items_counter = wp_nav_menu_get_custom_links( 0, 'default' ); ?>
|
||||
</ul>
|
||||
</div><!-- /.list-container-->
|
||||
</div><!-- /#available-links-->
|
||||
<p class="add-to-menu">
|
||||
<a class="button"><?php _e('Add to Menu'); ?></a>
|
||||
</p>
|
||||
<br class="clear" />
|
||||
</div><!-- /.inside-->
|
||||
</div><!-- /#add-custom-link-->
|
||||
|
||||
<div id="add-pages" class="postbox">
|
||||
<h3 class="hndle"><?php esc_html_e('Add an Existing Page'); ?></h3>
|
||||
<div class="inside">
|
||||
<?php
|
||||
$pages_args = array(
|
||||
'child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'hierarchical' => 1,
|
||||
'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', 'authors' => '',
|
||||
'parent' => -1, 'exclude_tree' => '', 'number' => '', 'offset' => 0
|
||||
);
|
||||
$page_name = '';
|
||||
$pages_array = get_pages( $pages_args );
|
||||
if ( $pages_array ) {
|
||||
foreach ( $pages_array as $post ) {
|
||||
$page_name .= $post->post_title . '|';
|
||||
}
|
||||
} else {
|
||||
$page_name = __('No pages available');
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript" charset="<?php bloginfo('charset'); ?>">
|
||||
jQuery(document).ready(function(){
|
||||
var posts = "<?php echo esc_js( $page_name ); ?>".split('|');
|
||||
jQuery('#add-pages .quick-search').autocomplete(posts);
|
||||
|
||||
|
||||
jQuery('#add-pages .quick-search').result(function(event, data, formatted) {
|
||||
jQuery('#add-pages .list-wrap').css('display','block');
|
||||
jQuery("#add-pages .list-wrap li:contains('" + data + "')").css('display','block');
|
||||
jQuery('#add-pages .show-all').hide();
|
||||
jQuery('#add-pages .hide-all').show();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<p>
|
||||
<input type="text" class="quick-search regular-text" value="" />
|
||||
<a class="quick-search-submit button"><?php _e('Search'); ?></a>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<a class="show-all"><?php _e('View All'); ?></a>
|
||||
<a class="hide-all"><?php _e('Hide All'); ?></a>
|
||||
</p>
|
||||
|
||||
<div id="existing-pages" class="list-wrap">
|
||||
<div class="list-container">
|
||||
<ul class="list">
|
||||
<?php $items_counter = wp_nav_menu_get_pages( $items_counter, 'default' ); ?>
|
||||
</ul>
|
||||
</div><!-- /.list-container-->
|
||||
</div><!-- /#existing-pages-->
|
||||
<p class="add-to-menu enqueue">
|
||||
<a class="button"><?php _e('Add to Menu'); ?></a>
|
||||
</p>
|
||||
<br class="clear" />
|
||||
</div><!-- /.inside-->
|
||||
</div><!--END #add-pages-->
|
||||
|
||||
<div id="add-categories" class="postbox">
|
||||
<h3 class="hndle"><?php esc_html_e('Add an Existing Category'); ?></h3>
|
||||
<div class="inside">
|
||||
<?php
|
||||
// Custom GET categories query
|
||||
// @todo Use API
|
||||
$categories = $wpdb->get_results("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' ORDER BY term_id ASC");
|
||||
$cat_name = '';
|
||||
if ( $categories ) {
|
||||
foreach ( $categories as $category ) {
|
||||
$cat_id = $category->term_id;
|
||||
$cat_args = array(
|
||||
'orderby' => 'name',
|
||||
'include' => $cat_id,
|
||||
'hierarchical' => 1,
|
||||
'order' => 'ASC',
|
||||
);
|
||||
$category_names = get_categories( $cat_args );
|
||||
if ( isset( $category_names[0]->name ) ) {
|
||||
$cat_name .= htmlentities( $category_names[0]->name ).'|';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$cat_name = __('No categories available');
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript" charset="<?php bloginfo('charset'); ?>">
|
||||
jQuery(document).ready(function(){
|
||||
var categories = "<?php echo esc_js($cat_name); ?>".split('|');
|
||||
jQuery('#add-categories .quick-search').autocomplete(categories);
|
||||
jQuery('#add-categories .quick-search').result(function(event, data, formatted) {
|
||||
jQuery('#add-categories .list-wrap').css('display','block');
|
||||
jQuery("#add-categories .list-wrap li:contains('" + data + "')").css('display','block');
|
||||
jQuery('#add-categories .show-all').hide();
|
||||
jQuery('#add-categories .hide-all').show();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<p>
|
||||
<input type="text" class="quick-search regular-text" value="" />
|
||||
<a class="quick-search-submit button"><?php _e('Search'); ?></a>
|
||||
</p>
|
||||
|
||||
<p class="button-controls">
|
||||
<a class="show-all"><?php _e('View All'); ?></a>
|
||||
<a class="hide-all"><?php _e('Hide All'); ?></a>
|
||||
</p>
|
||||
|
||||
<div id="existing-categories" class="list-wrap">
|
||||
<div class="list-container">
|
||||
<ul class="list">
|
||||
<?php $items_counter = wp_nav_menu_get_categories( $items_counter, 'default' ); ?>
|
||||
</ul>
|
||||
</div><!-- /.list-container-->
|
||||
</div><!-- /#existing-categories-->
|
||||
<p class="add-to-menu enqueue">
|
||||
<a class="button"><?php _e('Add to Menu'); ?></a>
|
||||
</p>
|
||||
<br class="clear" />
|
||||
</div><!-- /.inside-->
|
||||
</div><!--END #add-categories-->
|
||||
</div><!-- /#side-sortables-->
|
||||
|
||||
<?php do_meta_boxes( 'menus', 'side', null ); ?>
|
||||
|
||||
</div><!-- /#menu-settings-column -->
|
||||
<br class="clear" />
|
||||
</div><!-- /.metabox-holder has-right-sidebar-->
|
||||
</form>
|
||||
</form><!--/#update-nav-menu-->
|
||||
<br class="clear" />
|
||||
</div><!-- /.metabox-holder has-right-sidebar-->
|
||||
</div><!-- /.wrap-->
|
||||
|
||||
<div id="menu-item-settings">
|
||||
<p class="description">
|
||||
<label for="edit-item-title">
|
||||
<label for="edit-menu-item-title">
|
||||
<?php _e( 'Menu Title' ); ?><br />
|
||||
<input type="text" id="edit-item-title" class="widefat" name="edit-item-title" value="" tabindex="1" />
|
||||
<input type="text" id="edit-menu-item-title" class="widefat" name="edit-menu-item-title" value="" tabindex="1" />
|
||||
</label>
|
||||
</p>
|
||||
<p class="description">
|
||||
<label for="edit-item-url">
|
||||
<label for="edit-menu-item-url">
|
||||
<?php _e( 'URL' ); ?><br />
|
||||
<input type="text" id="edit-item-url" class="widefat code" name="edit-item-url" value="" tabindex="2" />
|
||||
<input type="text" id="edit-menu-item-url" class="widefat code" name="edit-menu-item-url" value="" tabindex="2" />
|
||||
</label>
|
||||
</p>
|
||||
<p class="description">
|
||||
<label for="edit-item-attr-title">
|
||||
<?php _e( 'Attribute Title' ); ?><br />
|
||||
<input type="text" id="edit-item-attr-title" class="widefat" name="edit-item-attr-title" value="" tabindex="3" />
|
||||
<label for="edit-menu-item-attr-title">
|
||||
<?php _e( 'Title Attribute' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-attr-title" class="widefat" name="edit-menu-item-attr-title" value="" tabindex="3" />
|
||||
</label>
|
||||
</p>
|
||||
<p class="description">
|
||||
<label for="edit-item-target">
|
||||
<?php _e( 'Open Link in a new window' ); ?><br />
|
||||
<select id="edit-item-target" class="widefat" name="edit-item-target">
|
||||
<option value="1">Yes</option>
|
||||
<option value="0">No</option>
|
||||
<label for="edit-menu-item-target">
|
||||
<?php _e( 'Link Target' ); ?><br />
|
||||
<select id="edit-menu-item-target" class="widefat" name="edit-menu-item-target" tabindex="4">
|
||||
<option value="_self">Same window or tab</option>
|
||||
<option value="_blank">New window or tab</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p class="description">
|
||||
<label for="edit-item-description">
|
||||
<?php _e( 'Description' ); ?><br />
|
||||
<textarea id="edit-item-description" class="widefat" rows="3" name="edit-item-description" tabindex="4" /></textarea>
|
||||
<label for="edit-menu-item-classes">
|
||||
<?php _e( 'CSS Classes (optional)' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-classes" class="widefat code" name="edit-menu-item-classes" value="" tabindex="5" />
|
||||
</label>
|
||||
</p>
|
||||
<p class="description">
|
||||
<label for="edit-menu-item-xfn">
|
||||
<?php _e( 'Link Relationship (XFN) (optional)' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-xfn" class="widefat code" name="edit-menu-item-xfn" value="" tabindex="6" />
|
||||
</label>
|
||||
</p>
|
||||
<p class="description">
|
||||
<label for="edit-menu-item-description">
|
||||
<?php _e( 'Description (optional)' ); ?><br />
|
||||
<textarea id="edit-menu-item-description" class="widefat" rows="3" name="edit-menu-item-description" tabindex="7" /></textarea>
|
||||
<span class="description">The description will be displayed in the menu if the current theme supports it.</span>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<a id="cancel-save" class="submitdelete deletion"><?php _e('Cancel'); ?></a>
|
||||
<a id="update-menu-item" class="save button-primary" tabindex="5"><?php _e('Save Changes'); ?></a>
|
||||
<a id="update-menu-item" class="save button-primary" tabindex="8"><?php _e('Save Changes'); ?></a>
|
||||
<a id="cancel-save" class="submitdelete deletion" tabindex="9"><?php _e('Cancel'); ?></a>
|
||||
</p>
|
||||
<input type="hidden" id="edit-item-id" name="edit-item-id" value="" />
|
||||
<input type="hidden" id="edit-menu-item-id" name="edit-item-id" value="" />
|
||||
</div><!-- /#menu-item-settings-->
|
||||
|
||||
<?php include( 'admin-footer.php' ); ?>
|
@ -43,7 +43,7 @@
|
||||
|
||||
<div id="access">
|
||||
<div class="skip-link screen-reader-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentyten' ); ?>"><?php _e( 'Skip to content', 'twentyten' ); ?></a></div>
|
||||
<?php wp_nav_menu( 'sort_column=menu_order' ); ?>
|
||||
<?php wp_nav_menu( 'sort_column=menu_order&container_class=menu-header' ); ?>
|
||||
</div><!-- #access -->
|
||||
</div><!-- #masthead -->
|
||||
</div><!-- #header -->
|
||||
|
@ -152,7 +152,7 @@ code {
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
/* The main theme structure */
|
||||
#access .menu,
|
||||
#access .menu-header,
|
||||
#colophon,
|
||||
#branding,
|
||||
#main,
|
||||
@ -360,15 +360,15 @@ a:hover {
|
||||
display:block;
|
||||
float:left;
|
||||
}
|
||||
#access .menu {
|
||||
#access .menu-header {
|
||||
font-size: 13px;
|
||||
margin-left: 12px;
|
||||
}
|
||||
#access .menu ul {
|
||||
#access .menu-header ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
}
|
||||
#access .menu li {
|
||||
#access .menu-header li {
|
||||
float:left;
|
||||
position: relative;
|
||||
}
|
||||
|
@ -23,8 +23,8 @@
|
||||
* @param array $args Arguments
|
||||
*/
|
||||
function wp_nav_menu( $args = array() ) {
|
||||
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'format' => 'div', 'echo' => true,
|
||||
'fallback_cb' => 'wp_page_menu', 'link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );
|
||||
$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
|
||||
'fallback_cb' => 'wp_page_menu', 'before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', );
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$args = apply_filters( 'wp_nav_menu_args', $args );
|
||||
@ -45,23 +45,26 @@ function wp_nav_menu( $args = array() ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( $menu )
|
||||
if ( !is_wp_error($menu) )
|
||||
$args->menu = $menu->term_id;
|
||||
$nav_menu = '';
|
||||
|
||||
if ( 'div' == $args->format ) {
|
||||
if ( $menu )
|
||||
$nav_menu .= '<div id="menu-' . $menu->slug . '" class="' . esc_attr($args->menu_class) . '">';
|
||||
else
|
||||
$nav_menu .= '<div id="menu-default">';
|
||||
if ( 'div' == $args->container ) {
|
||||
$class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : '';
|
||||
|
||||
if ( is_nav_menu($menu) ) {
|
||||
$nav_menu .= '<div id="menu-' . $menu->slug . '"'. $class .'>';
|
||||
} else {
|
||||
$nav_menu .= '<div'. $class .'>';
|
||||
}
|
||||
}
|
||||
|
||||
$nav_menu .= wp_get_nav_menu( $args );
|
||||
|
||||
if ( 'div' == $args->format )
|
||||
if ( 'div' == $args->container )
|
||||
$nav_menu .= '</div>';
|
||||
|
||||
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu );
|
||||
|
||||
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
|
||||
|
||||
if ( $args->echo )
|
||||
echo $nav_menu;
|
||||
@ -80,66 +83,77 @@ function wp_nav_menu( $args = array() ) {
|
||||
* @return mixed $output False if menu doesn't exists, else, returns the menu.
|
||||
**/
|
||||
function wp_get_nav_menu( $args = array() ) {
|
||||
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'ul_class' => '', 'format' => 'div', 'type' => 'frontend',
|
||||
'fallback_cb' => '', 'link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );
|
||||
$defaults = array( 'menu' => '', 'menu_class' => 'menu', 'context' => 'frontend',
|
||||
'fallback_cb' => '', 'before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', );
|
||||
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$args = apply_filters( 'wp_get_nav_menu_args', $args );
|
||||
$args = (object) $args;
|
||||
|
||||
// Variable setup
|
||||
$nav_menu = '';
|
||||
$items = '';
|
||||
$current_parent = 0;
|
||||
$parent_stack = array();
|
||||
$parent_menu_order = array();
|
||||
|
||||
// Get the menu object
|
||||
$menu = wp_get_nav_menu_object( $args->menu );
|
||||
|
||||
// If no menu was found, call the fallback_cb
|
||||
if ( !$menu || is_wp_error($menu) ) {
|
||||
// If the menu exists, get it's items.
|
||||
if ( $menu && !is_wp_error($menu) )
|
||||
$menu_items = wp_get_nav_menu_items( $menu->term_id, 'backend' );
|
||||
|
||||
// If no menu was found or if the menu has no items, call the fallback_cb
|
||||
if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) {
|
||||
if ( function_exists($args->fallback_cb) ) {
|
||||
$_args = array_merge( (array)$args, array('echo' => false) );
|
||||
return call_user_func( $args->fallback_cb, $_args );
|
||||
}
|
||||
}
|
||||
|
||||
$menu_items = wp_get_nav_menu_items( $menu->term_id );
|
||||
$nav_menu = '';
|
||||
$parent_stack = array();
|
||||
$current_parent = 0;
|
||||
$parent_menu_order = array();
|
||||
|
||||
// Setup parentage
|
||||
foreach ( $menu_items as $menu_item )
|
||||
$parent_menu_order[ $menu_item->ID ] = $menu_item->menu_order;
|
||||
|
||||
$ul_class = isset($args->ul_class) ? ' class="'. $args->ul_class .'"' : '';
|
||||
$nav_menu .= '<ul'. $ul_class .'>';
|
||||
|
||||
// Display Loop
|
||||
foreach ( $menu_items as $key => $menu_item ) :
|
||||
foreach ( $menu_items as $key => $menu_item ) {
|
||||
// Setup the $menu_item variables
|
||||
$menu_item = wp_setup_nav_menu_item( $menu_item );
|
||||
$menu_item = wp_setup_nav_menu_item( $menu_item, 'frontend' );
|
||||
|
||||
$maybe_value = 'frontend' == $args->type ? '' : ' value="'. $menu_item->ID .'"';
|
||||
$classes = 'frontend' == $args->type ? ' class="menu-item-'. $menu_item->type . $menu_item->li_class .'"' : '';
|
||||
|
||||
$nav_menu .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>';
|
||||
$nav_menu .= wp_get_nav_menu_item( $menu_item, $args->type, $args );
|
||||
$type = sanitize_title_with_dashes( $menu_item->append );
|
||||
$maybe_value = 'frontend' == $args->context ? '' : ' value="'. $menu_item->ID .'"';
|
||||
$classes = 'frontend' == $args->context ? ' class="menu-item-type-'. $type . $menu_item->li_class .'"' : '';
|
||||
|
||||
$items .= '<li id="menu-item-'. $menu_item->ID .'"'. $maybe_value . $classes .'>';
|
||||
$items .= wp_get_nav_menu_item( $menu_item, $args->context, $args );
|
||||
|
||||
// Indent children
|
||||
$last_item = ( count( $menu_items ) == $menu_item->menu_order );
|
||||
if ( $last_item || $current_parent != $menu_items[ $key + 1 ]->post_parent ) {
|
||||
if ( $last_item || in_array( $menu_items[ $key + 1 ]->post_parent, $parent_stack ) ) {
|
||||
$nav_menu .= '</li>';
|
||||
while ( !empty( $parent_stack ) && ($last_item || $menu_items[ $key + 1 ]->post_parent != $current_parent ) ) {
|
||||
$nav_menu .= '</ul></li>';
|
||||
if ( $last_item || $current_parent != $menu_items[$key + 1]->post_parent ) {
|
||||
if ( $last_item || in_array( $menu_items[$key + 1]->post_parent, $parent_stack ) ) {
|
||||
$items .= '</li>';
|
||||
while ( !empty( $parent_stack ) && ($last_item || $menu_items[$key + 1]->post_parent != $current_parent ) ) {
|
||||
$items .= '</ul></li>';
|
||||
$current_parent = array_pop( $parent_stack );
|
||||
}
|
||||
} else {
|
||||
array_push( $parent_stack, $current_parent );
|
||||
$current_parent = $menu_item->ID;
|
||||
$nav_menu .= '<ul>';
|
||||
$items .= '<ul class="sub-menu">';
|
||||
}
|
||||
} else {
|
||||
$nav_menu .= '</li>';
|
||||
$items .= '</li>';
|
||||
}
|
||||
|
||||
endforeach;
|
||||
}
|
||||
|
||||
// CSS class
|
||||
$ul_class = $args->menu_class ? ' class="'. $args->menu_class .'"' : '';
|
||||
$nav_menu .= '<ul'. $ul_class .'>';
|
||||
|
||||
// Allow plugins to hook into the menu to add their own <li>'s
|
||||
if ( 'frontend' == $args->context ) {
|
||||
$items = apply_filters( 'wp_nav_menu_items', $items, $args );
|
||||
$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
|
||||
$nav_menu .= $items;
|
||||
} else {
|
||||
$nav_menu .= $items;
|
||||
}
|
||||
|
||||
$nav_menu .= '</ul>';
|
||||
|
||||
@ -147,65 +161,97 @@ function wp_get_nav_menu( $args = array() ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a menu item.
|
||||
* Returns the menu item formatted based on it's context.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param object $menu_item The menu item
|
||||
* @param string $context frontend|backend|default
|
||||
* @param array $args See wp_get_nav_menu().
|
||||
**/
|
||||
function wp_get_nav_menu_item( $menu_item, $context, $args = array() ) {
|
||||
$item = '';
|
||||
* @param string $menu_item The menu item to format.
|
||||
* @param string $context The context to which the menu item will be formatted to.
|
||||
* @param string $args Optional. Args used for the 'template' context.
|
||||
* @return string $output The menu formatted menu item.
|
||||
*/
|
||||
function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array() ) {
|
||||
$output = '';
|
||||
switch ( $context ) {
|
||||
case 'frontend':
|
||||
$attr_title = ( isset($menu_item->anchor_title) && '' != $menu_item->anchor_title ) ? ' title="'. esc_attr($menu_item->anchor_title) .'"' : '';
|
||||
$href = isset($menu_item->link) ? ' href="'. esc_url($menu_item->link) .'"' : '';
|
||||
$attributes = ( isset($menu_item->anchor_title) && '' != $menu_item->anchor_title ) ? ' title="'. esc_attr($menu_item->anchor_title) .'"' : '';
|
||||
$attributes .= ( isset($menu_item->target) && '' != $menu_item->target ) ? ' target="'. esc_attr($menu_item->target) .'"' : '';
|
||||
$attributes .= ( isset($menu_item->classes) && '' != $menu_item->classes ) ? ' class="'. esc_attr($menu_item->classes) .'"' : '';
|
||||
$attributes .= ( isset($menu_item->xfn) && '' != $menu_item->xfn ) ? ' rel="'. esc_attr($menu_item->xfn) .'"' : '';
|
||||
$attributes .= ( isset($menu_item->url) && '' != $menu_item->url ) ? ' href="'. esc_attr($menu_item->url) .'"' : '';
|
||||
|
||||
$item .= '<a'. $attr_title . $href . $menu_item->target .'>';
|
||||
$item .= $args->before_link . esc_html( $menu_item->title ) . $args->after_link;
|
||||
$item .= '</a>';
|
||||
$output .= esc_html( $args->before_link );
|
||||
$output .= '<a'. $attributes .'>';
|
||||
$output .= esc_html( $args->before_title . $menu_item->title . $args->after_title );
|
||||
$output .= '</a>';
|
||||
$output .= esc_html( $args->after_link );
|
||||
|
||||
break;
|
||||
|
||||
case 'backend':
|
||||
$item .= '<dl><dt>';
|
||||
$item .= '<span class="item-title">'. esc_html($menu_item->title) .'</span>';
|
||||
$item .= '<span class="item-controls">';
|
||||
$item .= '<span class="item-type">'. esc_html($menu_item->type) .'</span>';
|
||||
$output .= '<dl><dt>';
|
||||
$output .= '<span class="item-title">'. esc_html($menu_item->title) .'</span>';
|
||||
$output .= '<span class="item-controls">';
|
||||
$output .= '<span class="item-type">'. esc_html($menu_item->append) .'</span>';
|
||||
|
||||
// Actions
|
||||
$item .= '<a class="item-edit thickbox" id="edit'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=380&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | ';
|
||||
$item .= '<a class="item-delete" id="delete'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'">'. __('Delete') .'</a>';
|
||||
$output .= '<a class="item-edit thickbox" id="edit'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | ';
|
||||
$output .= '<a class="item-delete" id="delete'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'">'. __('Delete') .'</a>';
|
||||
|
||||
$item .= '</dt></dl>';
|
||||
$output .= '</dt></dl>';
|
||||
|
||||
// Menu Item Settings
|
||||
$item .= '<input type="hidden" id="item-dbid'. esc_attr( $menu_item->menu_order ) .'" name="item-dbid'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->ID ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-postmenu'. esc_attr( $menu_item->menu_order ) .'" name="item-postmenu'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'object_id', true ) ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-parent'. esc_attr( $menu_item->menu_order ) .'" name="item-parent'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->parent_item ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-position'. esc_attr( $menu_item->menu_order ) .'" name="item-position'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-type'. esc_attr( $menu_item->menu_order ) .'" name="item-type'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'menu_type', true ) ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-title'. esc_attr( $menu_item->menu_order ) .'" name="item-title'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->title ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-url'. esc_attr( $menu_item->menu_order ) .'" name="item-url'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->link ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-description'. esc_attr( $menu_item->menu_order ) .'" name="item-description'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->description ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-attr-title'. esc_attr( $menu_item->menu_order ) .'" name="item-attr-title'. esc_attr( $menu_item->menu_order ) .'" value="'.esc_attr( $menu_item->post_excerpt ) .'" />';
|
||||
$item .= '<input type="hidden" id="item-target'. esc_attr( $menu_item->menu_order ) .'" name="item-target'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ? '1' : '0' ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-db-id[]" id="menu-item-db-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->ID ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-object-id[]" id="menu-item-object-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->object_id ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-parent-id[]" id="menu-item-parent-id'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->post_parent ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-position[]" id="menu-item-position'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->menu_order ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-type[]" id="menu-item-type'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->type ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-append[]" id="menu-item-append'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->append ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-title[]" id="menu-item-title'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->title ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-url[]" id="menu-item-url'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->url ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-description[]" id="menu-item-description'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->description ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-classes[]" id="menu-item-classes'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->classes ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-xfn[]" id="menu-item-xfn'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->xfn ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-attr-title[]" id="menu-item-attr-title'. esc_attr( $menu_item->menu_order ) .'" value="'.esc_attr( $menu_item->post_excerpt ) .'" />';
|
||||
$output .= '<input type="hidden" name="menu-item-target[]" id="menu-item-target'. esc_attr( $menu_item->menu_order ) .'" value="'. esc_attr( $menu_item->target ) .'" />';
|
||||
break;
|
||||
|
||||
case 'custom':
|
||||
$menu_id = 'menu-item-' . $menu_item->db_id;
|
||||
$output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( $menu_id ) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>';
|
||||
|
||||
case 'default':
|
||||
$menu_id = 'menu-item-' . $menu_item->ID;
|
||||
$item .= '<label class="item-title"><input type="checkbox" id="'. esc_attr($menu_id) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->link ) .'" />'. $menu_item->title .'</label>';
|
||||
// Menu item hidden fields
|
||||
$output .= '<input type="hidden" class="menu-item-db-id" value="'. esc_attr( $menu_item->db_id ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->parent_id ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-target" value="'. esc_attr( $menu_item->target ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-attr_title" value="'. esc_attr( $menu_item->attr_title ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-description" value="'. esc_attr( $menu_item->description ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-classes" value="'. esc_attr( $menu_item->classes ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-xfn" value="'. esc_attr( $menu_item->xfn ) .'" />';
|
||||
break;
|
||||
|
||||
case 'taxonomy':
|
||||
case 'post_type':
|
||||
$menu_id = 'menu-item-' . $menu_item->db_id;
|
||||
$output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( $menu_id ) .'" name="'. esc_attr( $menu_item->title ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>';
|
||||
|
||||
// Menu Item Settings
|
||||
$item .= '<input type="hidden" class="item-type" value="'. esc_attr( $menu_item->type ) .'" />';
|
||||
$item .= '<input type="hidden" class="item-title" value="'. esc_attr( $menu_item->title ) .'" />';
|
||||
$item .= '<input type="hidden" class="item-url" value="'. esc_attr( $menu_item->link ) .'" />';
|
||||
$item .= '<input type="hidden" class="item-dbid" value="'. esc_attr( $menu_item->ID ) .'" />';
|
||||
$item .= '<input type="hidden" class="item-parent" value="'. esc_attr( $menu_item->parent_item ) .'" />';
|
||||
$item .= '<input type="hidden" class="item-description" value="'. esc_attr( $menu_item->description ) .'" />';
|
||||
// Menu item hidden fields
|
||||
$output .= '<input type="hidden" class="menu-item-db-id" value="0" />';
|
||||
$output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->parent_id ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />';
|
||||
$output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';
|
||||
break;
|
||||
}
|
||||
return apply_filters( 'wp_get_nav_menu_item', $item );
|
||||
|
||||
return $output;
|
||||
}
|
||||
?>
|
@ -48,17 +48,6 @@ function is_nav_menu( $menu ) {
|
||||
return $menu_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all Navigation Menu objects.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return array menu objects
|
||||
*/
|
||||
function wp_get_nav_menus() {
|
||||
return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a navigation menu.
|
||||
*
|
||||
@ -113,33 +102,18 @@ function wp_delete_nav_menu( $menu ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a nav menu named 'Menu 1'.
|
||||
*
|
||||
* This function is called if the user doesn't have any nav menus.
|
||||
* It grabs the first 14 pages, and creates a new default menu.
|
||||
* Returns all Navigation Menu objects.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @return array menu objects
|
||||
*/
|
||||
function wp_create_default_nav_menu() {
|
||||
$menu = wp_create_nav_menu( __('Menu 1'), array('slug' => 'menu-1') );
|
||||
|
||||
if ( is_wp_error($menu) )
|
||||
return;
|
||||
|
||||
$pages = get_pages( array('parent' => 0, 'number' => 15) );
|
||||
$counter = 1;
|
||||
foreach ( $pages as $page ) {
|
||||
$item = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'menu_order' => $counter, 'tax_input' => array( 'nav_menu' => $menu->name), 'post_title' => addslashes($page->post_title) );
|
||||
$item_id = wp_insert_post($item, true);
|
||||
update_post_meta( $item_id, 'menu_type', 'page' );
|
||||
update_post_meta( $item_id, 'object_id', $page->ID );
|
||||
update_post_meta( $item_id, 'menu_new_window', 0 );
|
||||
$counter++;
|
||||
}
|
||||
function wp_get_nav_menus() {
|
||||
return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the menu items of a navigation menu.
|
||||
* Returns all menu items of a navigation menu.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
@ -179,110 +153,91 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a menu item with all it's nessecary data populated.
|
||||
* Adds all the nav menu properties to the $menu_item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $menu_item Menu item.
|
||||
* @param string $type item|category|page.
|
||||
* @param string $position position of the menu item.
|
||||
* @return $menu_item
|
||||
* @param string $menu_item The menu item to modify
|
||||
* @param string $menu_item_type The menu item type (template, custom, post_type, taxonomy).
|
||||
* @param string $menu_item_object Optional. The menu item object type (post type or taxonomy).
|
||||
* @return object $menu_item The modtified menu item.
|
||||
*/
|
||||
function wp_setup_nav_menu_item( $menu_item, $type = 'item', $position = 0 ) {
|
||||
global $parent_menu_order;
|
||||
|
||||
if ( 'item' == $type ) {
|
||||
$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 );
|
||||
$menu_item->target = ( get_post_meta( $menu_item->ID, 'menu_new_window', true ) ) ? 'target="_blank"' : '';
|
||||
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;
|
||||
} elseif ( 'category' == $type ) {
|
||||
$menu_item->type = $type;
|
||||
$menu_item->object_id = $menu_item->term_id;
|
||||
$menu_item->ID = $menu_item->term_id;
|
||||
$menu_item->parent_item = $menu_item->parent;
|
||||
$menu_item->menu_order = $position;
|
||||
} elseif ( 'page' == $type ) {
|
||||
$menu_item->type = $type;
|
||||
$menu_item->object_id = $menu_item->ID;
|
||||
$menu_item->parent_item = $menu_item->post_parent;
|
||||
$menu_item->menu_order = $position;
|
||||
}
|
||||
|
||||
switch ( $menu_item->type ) {
|
||||
case 'page' :
|
||||
$menu_item->link = get_page_link( $menu_item->object_id );
|
||||
|
||||
if ( $menu_item->post_title == '' )
|
||||
$menu_item->title = get_the_title( $menu_item->object_id );
|
||||
else
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
|
||||
if ( $menu_item->post_content == '' )
|
||||
$menu_item->description = get_post_meta( $menu_item->ID, 'page-description', true );
|
||||
else
|
||||
$menu_item->description = $menu_item->post_content;
|
||||
$menu_item->append = _x('Page', 'menu nav item type');
|
||||
break;
|
||||
case 'category' :
|
||||
$menu_item->link = get_category_link( $menu_item->object_id );
|
||||
|
||||
if ( empty($menu_item->post_title) ) {
|
||||
$title_raw = get_category( $menu_item->object_id );
|
||||
$menu_item->title = $title_raw->cat_name;
|
||||
} else {
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
}
|
||||
|
||||
if ( empty($menu_item->post_content) )
|
||||
$menu_item->description = strip_tags( category_description( $menu_item->object_id ) );
|
||||
else
|
||||
$menu_item->description = $menu_item->post_content;
|
||||
$menu_item->append = _x('Category', 'menu nav item type');
|
||||
break;
|
||||
case 'custom' :
|
||||
default :
|
||||
$menu_item->link = esc_url_raw( get_post_meta( $menu_item->ID, 'menu_link', true ) );
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
$menu_item->description = $menu_item->post_content;
|
||||
$menu_item->append = _x('Custom', 'menu nav item type');
|
||||
break;
|
||||
}
|
||||
|
||||
$menu_item->li_class = '';
|
||||
function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_object = '' ) {
|
||||
global $wp_query;
|
||||
|
||||
if ( $menu_item->object_id == $wp_query->get_queried_object_id() )
|
||||
$menu_item->li_class = ' current_page_item';
|
||||
switch ( $menu_item_type ) {
|
||||
case 'frontend':
|
||||
$menu_item->db_id = (int) $menu_item->ID;
|
||||
$menu_item->object_id = get_post_meta( $menu_item->ID, 'menu_item_object_id', true );
|
||||
$menu_item->parent_id = (int) $menu_item->post_parent;
|
||||
$menu_item->type = get_post_meta( $menu_item->ID, 'menu_item_type', true );
|
||||
$menu_item->append = _x( get_post_meta( $menu_item->ID, 'menu_item_append', true ), 'nav menu item type' );
|
||||
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
$menu_item->url = get_post_meta( $menu_item->ID, 'menu_item_url', true );
|
||||
$menu_item->target = get_post_meta( $menu_item->ID, 'menu_item_target', true );
|
||||
|
||||
$menu_item->attr_title = strip_tags( $menu_item->post_excerpt );
|
||||
$menu_item->description = strip_tags( $menu_item->post_content );
|
||||
|
||||
$menu_item->classes = get_post_meta( $menu_item->ID, 'menu_item_classes', true );;
|
||||
$menu_item->xfn = get_post_meta( $menu_item->ID, 'menu_item_xfn', true );
|
||||
$menu_item->li_class = ( $menu_item->object_id == $wp_query->get_queried_object_id() ) ? ' current_page_item' : '';
|
||||
break;
|
||||
|
||||
case 'custom':
|
||||
$menu_item->db_id = (int) $menu_item->ID;
|
||||
$menu_item->object_id = (int) $menu_item->ID;
|
||||
$menu_item->parent_id = (int) $menu_item->post_parent;
|
||||
$menu_item->type = 'custom'; //$menu_item_type
|
||||
$menu_item->append = _x( 'Custom', 'nav menu item type' );
|
||||
|
||||
$menu_item->attr_title = strip_tags( $menu_item->post_excerpt );
|
||||
$menu_item->description = strip_tags( $menu_item->post_content );
|
||||
|
||||
$menu_item->anchor_title = '';
|
||||
/* @todo: update to use tax/post data
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
$menu_item->url = get_post_meta( $menu_item->ID, 'menu_item_url', true );
|
||||
$menu_item->target = get_post_meta( $menu_item->ID, 'menu_item_target', true );
|
||||
break;
|
||||
|
||||
case 'post_type':
|
||||
$menu_item->db_id = 0;
|
||||
$menu_item->object_id = (int) $menu_item->ID;
|
||||
$menu_item->parent_id = (int) $menu_item->post_parent;
|
||||
$menu_item->type = $menu_item_type;
|
||||
|
||||
$object = get_post_type_object( $menu_item_object );
|
||||
$menu_item->append = _x( $object->singular_label, 'nav menu item type' );
|
||||
|
||||
//SET anchor title
|
||||
if (isset($wp_custom_nav_menu_items->custom_anchor_title)) {
|
||||
$anchor_title = $wp_custom_nav_menu_items->custom_anchor_title;
|
||||
}
|
||||
else {
|
||||
$anchor_title = $title;
|
||||
}
|
||||
|
||||
if ($queried_id == $wp_custom_nav_menu_items->post_id) {
|
||||
$li_class = 'class="current_page_item"';
|
||||
}
|
||||
|
||||
if (isset($wp_custom_nav_menu_items->new_window)) {
|
||||
if ($wp_custom_nav_menu_items->new_window > 0) {
|
||||
$target = 'target="_blank"';
|
||||
}
|
||||
else {
|
||||
$target = '';
|
||||
}
|
||||
}
|
||||
*/
|
||||
$menu_item->title = $menu_item->post_title;
|
||||
$menu_item->url = get_post_permalink( $menu_item->ID );
|
||||
$menu_item->target = '_none';
|
||||
|
||||
$menu_item->attr_title = '';
|
||||
$menu_item->description = strip_tags( $menu_item->post_content );
|
||||
break;
|
||||
|
||||
case 'taxonomy':
|
||||
$menu_item->ID = $menu_item->term_id;
|
||||
$menu_item->db_id = 0;
|
||||
$menu_item->object_id = (int) $menu_item->term_id;
|
||||
$menu_item->parent_id = (int) $menu_item->parent;
|
||||
$menu_item->type = $menu_item_type;
|
||||
|
||||
$object = get_taxonomy( $menu_item_object );
|
||||
$menu_item->append = _x( $object->singular_label, 'nav menu item type' );
|
||||
|
||||
$menu_item->title = $menu_item->name;
|
||||
$menu_item->url = get_term_link( $menu_item, $menu_item_object );
|
||||
$menu_item->target = '_none';
|
||||
$menu_item->attr_title = '';
|
||||
$menu_item->description = strip_tags( $menu_item->description );
|
||||
break;
|
||||
}
|
||||
|
||||
$menu_item->classes = get_post_meta( $menu_item->ID, 'menu_item_classes', true );
|
||||
$menu_item->xfn = get_post_meta( $menu_item->ID, 'menu_item_xfn', true );
|
||||
|
||||
return $menu_item;
|
||||
}
|
||||
?>
|
||||
?>
|
@ -397,14 +397,15 @@ function wp_default_scripts( &$scripts ) {
|
||||
) );
|
||||
|
||||
// Custom Navigation
|
||||
$scripts->add( 'nav-menu-default-items', "/wp-admin/js/nav-menu-default-items$suffix.js", false, '20100223' );
|
||||
$scripts->add( 'nav-menu-dynamic-functions', "/wp-admin/js/nav-menu-dynamic-functions$suffix.js", false, '20100225b' );
|
||||
$scripts->add( 'nav-menu-default-items', "/wp-admin/js/nav-menu-default-items$suffix.js", false, '20100315' );
|
||||
$scripts->add( 'nav-menu-dynamic-functions', "/wp-admin/js/nav-menu-dynamic-functions$suffix.js", false, '20100315' );
|
||||
$scripts->localize( 'nav-menu-dynamic-functions', 'navMenuL10n', array(
|
||||
'custom' => _x('Custom', 'menu nav item type'),
|
||||
'page' => _x('Page', 'menu nav item type'),
|
||||
'category' => _x('Category', 'menu nav item type'),
|
||||
'thickbox' => _x('Edit Menu Item', 'Thickbox Title'),
|
||||
'edit' => _x('Edit', 'menu item edit text'),
|
||||
'warnDelete' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
|
||||
) );
|
||||
|
||||
$scripts->add( 'nav-menu-php-functions', "/wp-admin/js/nav-menu-php-functions$suffix.js", false, '20100220' );
|
||||
|
@ -160,7 +160,7 @@ function get_taxonomy( $taxonomy ) {
|
||||
*/
|
||||
function is_taxonomy( $taxonomy ) {
|
||||
global $wp_taxonomies;
|
||||
|
||||
|
||||
return isset($wp_taxonomies[$taxonomy]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user