| 958 | * Displays a metabox for the post type archives menu item. |
| 959 | * |
| 960 | * @since 3.0.0 |
| 961 | * |
| 962 | * @param string $object Not used. |
| 963 | * @param string $post_type_archives_list The post type archives object. |
| 964 | */ |
| 965 | function wp_nav_menu_item_post_type_archives_meta_box( $object, $post_type_archives_list ) { |
| 966 | global $_nav_menu_placeholder, $nav_menu_selected_id; |
| 967 | |
| 968 | $post_type_name = 'posttype-archives'; |
| 969 | |
| 970 | // paginate browsing for large numbers of post objects |
| 971 | $per_page = 50; |
| 972 | $pagenum = isset( $_REQUEST[$post_type_name . '-tab'] ) && isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 1; |
| 973 | $offset = 0 < $pagenum ? $per_page * ( $pagenum - 1 ) : 0; |
| 974 | |
| 975 | $walker = new Walker_Nav_Menu_Checklist; |
| 976 | |
| 977 | $current_tab = 'all'; |
| 978 | if ( isset( $_REQUEST[$post_type_name . '-tab'] ) && in_array( $_REQUEST[$post_type_name . '-tab'], array('all', 'search') ) ) { |
| 979 | $current_tab = $_REQUEST[$post_type_name . '-tab']; |
| 980 | } |
| 981 | |
| 982 | if ( ! empty( $_REQUEST['quick-search-' . $post_type_name] ) ) { |
| 983 | $current_tab = 'search'; |
| 984 | } |
| 985 | |
| 986 | $removed_args = array( |
| 987 | 'action', |
| 988 | 'customlink-tab', |
| 989 | 'edit-menu-item', |
| 990 | 'menu-item', |
| 991 | 'page-tab', |
| 992 | '_wpnonce', |
| 993 | ); |
| 994 | |
| 995 | foreach ( $post_type_archives_list['args'] as $post_type_archive ) { |
| 996 | $post_type_archives[$post_type_archive->label] = $post_type_archive; |
| 997 | } |
| 998 | |
| 999 | ?> |
| 1000 | <div id="<?php echo $post_type_name; ?>" class="posttypediv"> |
| 1001 | <ul id="<?php echo $post_type_name; ?>-tabs" class="posttype-tabs add-menu-item-tabs"> |
| 1002 | <?php /*<li <?php echo ( 'most-recent' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'most-recent', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $post_type_name; ?>-most-recent"><?php _e('Most Recent'); ?></a></li> */ ?> |
| 1003 | <li <?php echo ( 'all' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'all', remove_query_arg($removed_args))); ?>#<?php echo $post_type_name; ?>-all"><?php _e('View All'); ?></a></li> |
| 1004 | <li <?php echo ( 'search' == $current_tab ? ' class="tabs"' : '' ); ?>><a class="nav-tab-link" href="<?php if ( $nav_menu_selected_id ) echo esc_url(add_query_arg($post_type_name . '-tab', 'search', remove_query_arg($removed_args))); ?>#tabs-panel-<?php echo $post_type_name; ?>-search"><?php _e('Search'); ?></a></li> |
| 1005 | </ul> |
| 1006 | <div class="tabs-panel <?php |
| 1007 | echo ( 'search' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); |
| 1008 | ?>" id="tabs-panel-<?php echo $post_type_name; ?>-search"> |
| 1009 | <?php |
| 1010 | if ( isset( $_REQUEST['quick-search-' . $post_type_name] ) ) { |
| 1011 | $searched = esc_attr( $_REQUEST['quick-search-' . $post_type_name] ); |
| 1012 | $search_results = get_posts( array( 's' => $searched, 'post_type' => $post_type_name, 'fields' => 'all', 'order' => 'DESC', ) ); |
| 1013 | } else { |
| 1014 | $searched = ''; |
| 1015 | $search_results = array(); |
| 1016 | } |
| 1017 | ?> |
| 1018 | <p class="quick-search-wrap"> |
| 1019 | <input type="text" class="quick-search input-with-default-title" title="<?php esc_attr_e('Search'); ?>" value="<?php echo $searched; ?>" name="quick-search-<?php echo $post_type_name; ?>" /> |
| 1020 | <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> |
| 1021 | <?php submit_button( __( 'Search' ), 'quick-search-submit button-secondary hide-if-js', 'submit', false ); ?> |
| 1022 | </p> |
| 1023 | |
| 1024 | <ul id="<?php echo $post_type_name; ?>-search-checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear"> |
| 1025 | <?php if ( ! empty( $search_results ) && ! is_wp_error( $search_results ) ) : ?> |
| 1026 | <?php |
| 1027 | $args['walker'] = $walker; |
| 1028 | echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $search_results), 0, (object) $args ); |
| 1029 | ?> |
| 1030 | <?php elseif ( is_wp_error( $search_results ) ) : ?> |
| 1031 | <li><?php echo $search_results->get_error_message(); ?></li> |
| 1032 | <?php elseif ( ! empty( $searched ) ) : ?> |
| 1033 | <li><?php _e('No results found.'); ?></li> |
| 1034 | <?php endif; ?> |
| 1035 | </ul> |
| 1036 | </div><!-- /.tabs-panel --> |
| 1037 | |
| 1038 | |
| 1039 | <div id="<?php echo $post_type_name; ?>-all" class="tabs-panel tabs-panel-view-all <?php |
| 1040 | echo ( 'all' == $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive' ); |
| 1041 | ?>"> |
| 1042 | <?php if ( ! empty( $page_links ) ) : ?> |
| 1043 | <div class="add-menu-item-pagelinks"> |
| 1044 | <?php echo $page_links; ?> |
| 1045 | </div> |
| 1046 | <?php endif; ?> |
| 1047 | <ul id="<?php echo $post_type_name; ?>checklist" class="list:<?php echo $post_type_name?> categorychecklist form-no-clear"> |
| 1048 | <?php |
| 1049 | $args['walker'] = $walker; |
| 1050 | |
| 1051 | $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $post_type_archives), 0, (object) $args ); |
| 1052 | |
| 1053 | if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) { |
| 1054 | $checkbox_items = preg_replace('/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items); |
| 1055 | } |
| 1056 | |
| 1057 | echo $checkbox_items; |
| 1058 | ?> |
| 1059 | </ul> |
| 1060 | <?php if ( ! empty( $page_links ) ) : ?> |
| 1061 | <div class="add-menu-item-pagelinks"> |
| 1062 | <?php echo $page_links; ?> |
| 1063 | </div> |
| 1064 | <?php endif; ?> |
| 1065 | </div><!-- /.tabs-panel --> |
| 1066 | |
| 1067 | |
| 1068 | <p class="button-controls"> |
| 1069 | <span class="list-controls"> |
| 1070 | <a href="<?php |
| 1071 | echo esc_url(add_query_arg( |
| 1072 | array( |
| 1073 | $post_type_name . '-tab' => 'all', |
| 1074 | 'selectall' => 1, |
| 1075 | ), |
| 1076 | remove_query_arg($removed_args) |
| 1077 | )); |
| 1078 | ?>#<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> |
| 1079 | </span> |
| 1080 | |
| 1081 | <span class="add-to-menu"> |
| 1082 | <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> |
| 1083 | <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" id="submit-<?php echo $post_type_name; ?>" /> |
| 1084 | </span> |
| 1085 | </p> |
| 1086 | |
| 1087 | </div><!-- /.posttypediv --> |
| 1088 | <?php |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | /** |