Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. $menu_control .= '<select style="'. $style .'" name="penci_cat_mega_menu[' . $item->ID . ']" id="" class="widefat code edit-menu-item-url">';
  2. foreach ( $td_category_tree as $category => $category_id ) {
  3. $menu_control .= '<option value="' . $category_id . '"' . selected( $penci_cat_mega_menu, $category_id, false ) . '>' . $category . '</option>';
  4. }
  5.  
  6. function penci_wp_update_nav_menu_item( $menu_id, $menu_item_id, $args ) {
  7.  
  8. // Update meta menu items
  9. if ( isset( $_POST['penci_cat_mega_menu'][$menu_item_id] ) ) {
  10. update_post_meta( $menu_item_id, 'penci_cat_mega_menu', $_POST['penci_cat_mega_menu'][$menu_item_id] );
  11. }
  12. if ( isset( $_POST['penci_number_mega_menu'][$menu_item_id] ) ) {
  13. update_post_meta( $menu_item_id, 'penci_number_mega_menu', $_POST['penci_number_mega_menu'][$menu_item_id] );
  14. }
  15.  
  16. }
  17.  
  18. function hook_wp_nav_menu_objects( $items, $args = '' ) {
  19. $menu_items = array();
  20.  
  21. foreach ( $items as &$item ) {
  22. $item->is_mega_menu = false;
  23.  
  24. // if menu is mega menu, render mega menu
  25. $penci_catid_mega_menu = get_post_meta( $item->ID, 'penci_cat_mega_menu', true );
  26. $penci_number_mega_menu = get_post_meta( $item->ID, 'penci_number_mega_menu', true );
  27. if( ! isset( $penci_number_mega_menu ) || empty ( $penci_number_mega_menu ) ): $penci_number_mega_menu = '1'; endif;
  28.  
  29. if ( ! empty( $penci_catid_mega_menu ) ) {
  30.  
  31. $item->classes[] = 'penci-mega-menu';
  32.  
  33. // add the parent menu
  34. $menu_items[] = $item;
  35.  
  36. // create mega menu item
  37. $post = new stdClass;
  38. $post->ID = 0;
  39. $post->post_author = '';
  40. $post->post_date = '';
  41. $post->post_date_gmt = '';
  42. $post->post_password = '';
  43. $post->post_type = 'menu_penci';
  44. $post->post_status = 'draft';
  45. $post->to_ping = '';
  46. $post->pinged = '';
  47. $post->comment_status = get_option( 'default_comment_status' );
  48. $post->ping_status = get_option( 'default_ping_status' );
  49. $post->post_pingback = get_option( 'default_pingback_flag' );
  50. $post->post_category = get_option( 'default_category' );
  51. $post->page_template = 'default';
  52. $post->post_parent = 0;
  53. $post->menu_order = 0;
  54. $new_item = new WP_Post( $post );
  55.  
  56. /*
  57. * if this is mega menu
  58. * set the is_mega_menu flag
  59. * render content of this mega menu
  60. */
  61. $new_item->is_mega_menu = true; // sent to the menu walkers
  62.  
  63. $new_item->menu_item_parent = $item->ID;
  64.  
  65. $new_item->url = '';
  66. $new_item->title = '';
  67. $new_item->title .= '<div class="penci-megamenu">';
  68. $new_item->title .= penci_return_html_mega_menu( $penci_catid_mega_menu, $penci_number_mega_menu );
  69. $new_item->title .= '</div>';
  70.  
  71. $menu_items[] = $new_item;
  72.  
  73. }
  74. else {
  75. $menu_items[] = $item;
  76. }
  77. } //end foreach
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement