. */ if( !function_exists('add_action') ) { header('Status: 403 Forbidden'); header('HTTP/1.1. 403 Forbidden'); exit(); } if( !class_exists('CustomPostTypeArchiveInNavMenu') ) { class CustomPostTypeArchiveInNavMenu { function CustomPostTypeArchiveInNavMenu() { load_plugin_textdomain( 'andromedamedia', false, basename( dirname( __FILE__ ) ) . '/languages' ); add_action( 'admin_head-nav-menus.php', array( &$this, 'cpt_navmenu_metabox' ) ); add_filter( 'wp_get_nav_menu_items', array( &$this,'cpt_archive_menu_filter'), 10, 3 ); } function cpt_navmenu_metabox() { add_meta_box( 'add-cpt', __('Custom Post Type Archives', 'andromedamedia'), array( &$this, 'cpt_navmenu_metabox_content' ), 'nav-menus', 'side', 'default' ); } function cpt_navmenu_metabox_content() { $post_types = get_post_types( array( 'show_in_nav_menus' => true, 'has_archive' => true ), 'object' ); if( $post_types ) : foreach ( $post_types as &$post_type ) { $post_type->classes = array(); $post_type->type = $post_type->name; $post_type->object_id = $post_type->name; $post_type->title = $post_type->labels->name . ' ' . __( 'Archive', 'andromedamedia' ); $post_type->object = 'cpt-archive'; } $walker = new Walker_Nav_Menu_Checklist( array() ); echo '
'; echo '
'; echo ''; echo '
'; echo '
'; echo '

'; echo ''; echo ''; echo ''; echo ''; echo '

'; endif; } function cpt_archive_menu_filter( $items, $menu, $args ) { foreach( $items as &$item ) { if( $item->object != 'cpt-archive' ) continue; $item->url = get_post_type_archive_link( $item->type ); if( get_query_var( 'post_type' ) == $item->type ) { $item->classes[] = 'current-menu-item'; $item->current = true; } } return $items; } } /* Instantiate the plugin */ $CustomPostTypeArchiveInNavMenu = new CustomPostTypeArchiveInNavMenu(); } ?>