Exemplo n.º 1
3
 function widget($args, $instance)
 {
     ob_start();
     extract($args);
     $title = !empty($instance['title']) ? esc_attr($instance['title']) : __('Custom Menu', 'zn_framework');
     $title = apply_filters('widget_title', $title, $instance, $this->id_base);
     $menu = isset($instance['menu']) ? esc_attr($instance['menu']) : '';
     $style = isset($instance['style']) ? esc_attr($instance['style']) : '';
     $columns = isset($instance['columns']) ? esc_attr($instance['columns']) : '';
     if (empty($menu)) {
         echo 'Please edit the widget and select at least one menu';
         return;
     }
     echo $before_widget;
     if ($title) {
         echo $before_title . $title . $after_title;
     }
     $menu_items = wp_get_nav_menu_items($menu);
     echo '<ul class="menu-' . $menu . ' ' . $style . ' clearfix ">';
     //row
     foreach ((array) $menu_items as $key => $menu_item) {
         $title = $menu_item->title;
         $url = $menu_item->url;
         echo '<li class="' . $columns . '"><a href="' . $url . '">' . $title . '</a></li>';
     }
     echo '</ul>';
     echo $after_widget;
     // Reset the global $the_post as this query will have stomped on it
     wp_reset_postdata();
 }
Exemplo n.º 2
1
 /**
  * Echo the widget content.
  *
  * @since 1.0.0
  *
  * @param array $args     Display arguments including before_title, after_title,
  *                        before_widget, and after_widget.
  * @param array $instance The settings for the particular instance of the widget.
  */
 function widget($args, $instance)
 {
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     echo $args['before_widget'];
     // Render title.
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     $nav_menu_locations = get_nav_menu_locations();
     $menu_id = 0;
     if (isset($nav_menu_locations['social']) && absint($nav_menu_locations['social']) > 0) {
         $menu_id = absint($nav_menu_locations['social']);
     }
     if ($menu_id > 0) {
         $menu_items = wp_get_nav_menu_items($menu_id);
         if (!empty($menu_items)) {
             echo '<ul class="size-medium">';
             foreach ($menu_items as $m_key => $m) {
                 echo '<li>';
                 echo '<a href="' . esc_url($m->url) . '" target="_blank">';
                 echo '<span class="title screen-reader-text">' . esc_attr($m->title) . '</span>';
                 echo '</a>';
                 echo '</li>';
             }
             echo '</ul>';
         }
     }
     echo $args['after_widget'];
 }
Exemplo n.º 3
0
function clear_menu_from_old_woo_pages()
{
    $locations = get_nav_menu_locations();
    $logout = get_page_by_path('my-account/logout');
    $parent = get_page_by_path('my-account');
    $permalink = get_option('permalink_structure');
    $pages_deleted = array(get_option('woocommerce_pay_page_id'), get_option('woocommerce_thanks_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_view_order_page_id'), get_option('woocommerce_change_password_page_id'), get_option('woocommerce_edit_address_page_id'), get_option('woocommerce_lost_password_page_id'));
    foreach ((array) $locations as $name => $menu_ID) {
        $items = wp_get_nav_menu_items($menu_ID);
        foreach ((array) $items as $item) {
            if (!is_null($logout) && !is_null($parent) && $item->object_id == $logout->ID) {
                update_post_meta($item->ID, '_menu_item_object', 'custom');
                update_post_meta($item->ID, '_menu_item_type', 'custom');
                if ($permalink == '') {
                    $new_url = get_permalink($parent->ID) . '&customer-logout';
                } else {
                    wp_update_post(array('ID' => $logout->ID, 'post_name' => 'customer-logout'));
                    $new_url = get_permalink($logout->ID);
                }
                update_post_meta($item->ID, '_menu_item_url', $new_url);
                wp_update_post(array('ID' => $item->ID, 'post_title' => $logout->post_title));
            }
            foreach ($pages_deleted as $page) {
                if ($page && $item->object_id == $page && $item->object == 'page') {
                    wp_delete_post($item->ID);
                }
            }
        }
    }
}
Exemplo n.º 4
0
 public function getMenu($name)
 {
     if (!array_key_exists($name, $this->menus)) {
         $this->load();
         if (!($menu = wp_get_nav_menu_object($name))) {
             throw new \Exception('Erreur menu introuvable');
         }
         $items = wp_get_nav_menu_items($menu->term_id);
         $all_items_inline = array();
         $root_items = array();
         foreach ($items as $item) {
             $objectItem = new MenuItem($item);
             if ($item->menu_item_parent != 0) {
                 if (!isset($all_items_inline[$item->menu_item_parent])) {
                     throw new \Exception('Erreur parent introuvable');
                 }
                 $objectItem->setParent($all_items_inline[$item->menu_item_parent]);
                 $objectItem->getParent()->addChild($objectItem);
             }
             $all_items_inline[$objectItem->getId()] = $objectItem;
             if ($objectItem->getParent() === null) {
                 $root_items[] = $objectItem;
             }
             $objectItem->setCss(get_post_meta($item->ID, '_menu_item_classes', true));
         }
         $this->menus[$name] = new Menu($menu->term_id, $root_items);
     }
     return $this->menus[$name];
 }
Exemplo n.º 5
0
 function set_menu()
 {
     $args = array("order" => "ASC", "orderby" => "menu_order", "post_type" => "nav_menu_item", "post_status" => "publish", "output" => ARRAY_A, "output_key" => "menu_order", "nopaging" => true, "update_post_term_cache" => false);
     $menu_items = wp_get_nav_menu_items($this->get_menu_name(), $args);
     $mns = array();
     $sorted_menu_items = $menu_items_with_children = array();
     foreach ((array) $menu_items as $menu_item) {
         $sorted_menu_items[$menu_item->menu_order] = $menu_item;
         if ($menu_item->menu_item_parent) {
             $menu_items_with_children[$menu_item->menu_item_parent] = true;
         }
         if (!$menu_item->menu_item_parent) {
             $mns[$menu_item->menu_order] = new JSON_API_Application_Navigation_Items($menu_item);
         }
     }
     // Add the menu-item-has-children class where applicable
     if ($menu_items_with_children) {
         foreach ($sorted_menu_items as &$menu_item) {
             if (isset($menu_items_with_children[$menu_item->ID])) {
                 $menu_item->classes[] = 'menu-item-has-children';
             }
         }
     }
     unset($menu_items, $menu_item);
     $this->create_tree($sorted_menu_items);
 }
Exemplo n.º 6
0
 function after_validate_fields($instance = '')
 {
     if (isset($instance['menu_id']) && isset($instance['menu_label']) && !empty($instance['menu_id']) && !empty($instance['menu_label'])) {
         $key = sanitize_key($instance['menu_label']);
         if (isset($instance['custom_container_id']) && !empty($instance['custom_container_id'])) {
             $key = $instance['custom_container_id'];
         } else {
             $instance['custom_container_id'] = $key;
         }
         $menu_link = '#HOME_URL#' . $key;
         $is_link = false;
         $menu_item_id = $menu_item_position = 0;
         $menu_items = wp_get_nav_menu_items($instance['menu_id']);
         foreach ($menu_items as $menu_item) {
             if ($menu_item->url == $menu_link) {
                 $menu_item_id = $menu_item->ID;
                 $menu_item_position = $menu_item->menu_order;
                 break;
             }
         }
         wp_update_nav_menu_item($instance['menu_id'], $menu_item_id, array('menu-item-title' => $instance['menu_label'], 'menu-item-classes' => 'internal', 'menu-item-url' => $menu_link, 'menu-item-position' => $menu_item_position, 'menu-item-status' => 'publish'));
         update_option('menu_check', true);
     }
     return $instance;
 }
Exemplo n.º 7
0
 public function __construct($menu_term_slug)
 {
     parent::__construct();
     $menu = wp_get_nav_menu_object($menu_term_slug);
     if (!empty($menu)) {
         $this->menu = $menu;
         $nav_menu_items = wp_get_nav_menu_items($this->menu->term_id);
         cfd_tmp_dbg('nav_menu_items_raw.txt', $nav_menu_items, 'print');
         foreach ($nav_menu_items as $item) {
             $menu_item = wp_setup_nav_menu_item($item);
             $menu_item->metadata = get_metadata('post', $item->ID);
             foreach ($menu_item->metadata as $key => &$value) {
                 $value[0] = maybe_unserialize($value[0]);
             }
             if ($menu_item->type == 'post_type') {
                 $menu_item->parent = get_post($menu_item->metadata['_menu_item_object_id'][0]);
             } elseif ($menu_item->type == 'taxonomy' && (!property_exists($menu, 'object') || $menu->object != 'custom')) {
                 $menu_item->term = get_term($menu_item->metadata['_menu_item_object_id'][0], $menu_item->metadata['_menu_item_object'][0]);
             }
             $this->items[] = $menu_item;
         }
     } else {
         throw new Exception(__('Invalid menu id', 'cf-deploy') . ': ' . esc_attr($menu_term_slug));
     }
 }
 function van_check_menu()
 {
     global $VAN;
     //If custom menu exist,get the ID of pages
     if (($locations = get_nav_menu_locations()) && $locations['primary_navi']) {
         $menu = wp_get_nav_menu_object($locations['primary_navi']);
         $menu_items = wp_get_nav_menu_items($menu->term_id);
         $pageID = array();
         foreach ($menu_items as $item) {
             if ($item->object == 'page') {
                 $pageID[] = $item->object_id;
             }
         }
         query_posts(array('post_type' => 'page', 'post__in' => $pageID, 'posts_per_page' => count($pageID), 'orderby' => 'post__in'));
     } else {
         //If custom menu doesn't exist,check default page menu setting in theme options
         //If default page menu setting exist
         if (isset($VAN['pages_navi']) && $VAN['pages_navi'] != '') {
             query_posts(array('post_type' => 'page', 'post__in' => $VAN['pages_navi'], 'posts_per_page' => count($VAN['pages_navi']), 'orderby' => 'menu_order', 'order' => 'ASC'));
         } else {
             //If default page menu setting doesn't exist
             query_posts(array('post_type' => 'page', 'posts_per_page' => 6, 'orderby' => 'menu_order', 'order' => 'ASC'));
         }
     }
 }
function bogo_admin_enqueue_scripts($hook_suffix)
{
    if (false !== strpos($hook_suffix, 'bogo-tools') || 'widgets.php' == $hook_suffix || 'user-edit.php' == $hook_suffix) {
        wp_enqueue_style('bogo-admin', plugins_url('admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME), array(), BOGO_VERSION, 'all');
        return;
    }
    if ('nav-menus.php' == $hook_suffix) {
        $nav_menu_id = absint(get_user_option('nav_menu_recently_edited'));
        $nav_menu_items = wp_get_nav_menu_items($nav_menu_id);
        $locales = array();
        foreach ((array) $nav_menu_items as $item) {
            $locales[$item->db_id] = $item->bogo_locales;
        }
        $prefix = 'menu-item-bogo-locale';
        wp_enqueue_script('bogo-admin', plugins_url('admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME), array('jquery'), BOGO_VERSION, true);
        wp_localize_script('bogo-admin', '_bogo', array('availableLanguages' => bogo_available_languages('orderby=value'), 'locales' => $locales, 'selectorLegend' => __('Displayed on pages in', 'bogo'), 'cbPrefix' => $prefix));
        wp_enqueue_style('bogo-admin', plugins_url('admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME), array(), BOGO_VERSION, 'all');
        return;
    }
    if ('options-general.php' == $hook_suffix) {
        wp_enqueue_script('bogo-admin', plugins_url('admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME), array('jquery'), BOGO_VERSION, true);
        wp_localize_script('bogo-admin', '_bogo', array('defaultLocale' => bogo_get_default_locale()));
        return;
    }
}
Exemplo n.º 10
0
 public function getPathFromNavMenu($postId)
 {
     $path = array();
     if (is_page()) {
         if ($this->menuItems === null) {
             $locations = get_nav_menu_locations();
             if (isset($locations['prime_nav_menu'])) {
                 $this->menuItems = wp_get_nav_menu_items($locations['prime_nav_menu']);
             } else {
                 $this->menuItems = false;
             }
         }
         if ($this->menuItems) {
             foreach ($this->menuItems as $menuItem) {
                 if ($menuItem->object_id == $postId) {
                     $node = $this->getNode($menuItem);
                     if ($node) {
                         $path[] = $node;
                     }
                     if ($menuItem->menu_item_parent) {
                         $parentNodes = $this->getParentNodes($menuItem->menu_item_parent);
                         $path = array_merge($path, $parentNodes);
                     }
                     break;
                 }
             }
         }
     }
     $path = array_reverse($path);
     return $path;
 }
 public function addClass($classes, $item)
 {
     if (!($this->postType = $this->getPostType())) {
         return $classes;
     }
     if ($this->isActive($item)) {
         $classes[] = 'current-menu-item';
     }
     /**
      * Parents & ancestors
      */
     if (count(array_intersect(array('current-menu-item', 'current-menu-parent', 'current-menu-ancestor'), $classes)) == 0) {
         $navMenu = wp_get_post_terms($item->ID, 'nav_menu');
         if (count($navMenu) > 0) {
             if (isset($this->_cache[$navMenu[0]->term_id])) {
                 $menuItems = $this->_cache[$navMenu[0]->term_id];
             } else {
                 $menuItems = wp_get_nav_menu_items($navMenu[0]->term_id);
                 $this->_cache[$navMenu[0]->term_id] = $menuItems;
             }
             foreach ($menuItems as $menuItem) {
                 if ($this->isActive($menuItem)) {
                     if ($depth = $this->findActiveDepth($menuItem, $item, $menuItems)) {
                         if ($depth == 1) {
                             $classes[] = 'current-menu-parent';
                         } elseif ($depth > 1) {
                             $classes[] = 'current-menu-ancestor';
                         }
                     }
                 }
             }
         }
     }
     return $classes;
 }
Exemplo n.º 12
0
  * 
  */
 load_theme_textdomain('szia', get_template_directory() . '/languages');
 // This theme styles the visual editor with editor-style.css to match the theme style.
 add_editor_style();
 // Custom Header
 $defaults = array('default-image' => '', 'random-default' => false, 'width' => 0, 'height' => 0, 'flex-height' => false, 'flex-width' => false, 'default-text-color' => '', 'header-text' => true, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '');
 add_theme_support('custom-header', $defaults);
 // Adds RSS feed links to <head> for posts and comments.
 add_theme_support('automatic-feed-links');
 // This theme supports a variety of post formats.
 add_theme_support('post-formats', array('gallery', 'image', 'video'));
 // This theme uses wp_nav_menu() in one location.
 register_nav_menu('primary', __('Primary Menu', 'szia'));
 register_nav_menu('secondary', __('Secondary Menu', 'szia'));
 /*
  * This theme supports custom background color and image, and here
  * we also set up the default background color.
  */
 add_theme_support('custom-background', array('default-color' => 'e6e6e6'));
 // This theme uses a custom image size for featured images, displayed on "standard" posts.
 add_theme_support('post-thumbnails');
 //set_post_thumbnail_size( 590, 211 ); // Unlimited height, soft crop
 // Used for large feature (header) images.
 //add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
Exemplo n.º 13
0
function menu_endpoint($data)
{
    $args = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 'update_post_term_cache' => false);
    $menu = wp_get_nav_menu_items($data['id'], $args);
    $fallback_menu = wp_get_nav_menu_items('2', $args);
    $menu = json_decode(json_encode($menu), true);
    $fallback_menu = json_decode(json_encode($fallback_menu), true);
    if ($menu != false) {
        $menu = $menu;
    } else {
        $menu = $fallback_menu;
    }
    for ($i = 0; $i < sizeof($menu); $i++) {
        unset($menu[$i]['post_password']);
        unset($menu[$i]['post_name']);
        unset($menu[$i]['to_ping']);
        unset($menu[$i]['pinged']);
        unset($menu[$i]['post_modified']);
        unset($menu[$i]['post_modified_gmt']);
        unset($menu[$i]['post_content_filtered']);
        unset($menu[$i]['post_parent']);
        unset($menu[$i]['post_mime_type']);
        unset($menu[$i]['comment_count']);
        unset($menu[$i]['filter']);
        unset($menu[$i]['object']);
        unset($menu[$i]['type']);
        unset($menu[$i]['post_date']);
        unset($menu[$i]['post_date_gmt']);
        $menu[$i]['template'] = split('.php', get_page_template_slug($menu[$i]['object_id']))[0];
    }
    //if the id would return nothing - return the default menu
    return $menu;
}
Exemplo n.º 14
0
 function ut_prepare_front_query()
 {
     /* needed variables and arrays */
     $ut_query_pages = array();
     /* check if primary navigation has been created and set */
     if (has_nav_menu('primary')) {
         /* get primary navigation ID */
         $ut_theme_locations = get_nav_menu_locations();
         $ut_menu_objects = get_term($ut_theme_locations['primary'], 'nav_menu');
         $ut_menu_id = $ut_menu_objects->term_id;
         /* now we get all menu items from primary navigation  */
         $menu_args = array('orderby' => 'menu_order');
         $ut_menu_items = wp_get_nav_menu_items($ut_menu_id, $menu_args);
         /* create an array of page ID's for query_posts() */
         foreach ((array) $ut_menu_items as $key => $ut_menu_item) {
             $blog_page_id = get_option('page_for_posts');
             $frontpage_id = get_option('page_on_front');
             if ($ut_menu_item->menutype == 'section' && $blog_page_id != $ut_menu_item->object_id && $frontpage_id != $ut_menu_item->object_id) {
                 $ut_query_pages[] = $ut_menu_item->object_id;
                 /* get child pages */
                 $children = ut_get_posts_children_ids($ut_menu_item->object_id);
                 $ut_query_pages = array_merge($ut_query_pages, $children);
             }
         }
         /* return query arguements */
         if (!empty($ut_query_pages)) {
             /* query args for main query  */
             $pagequery = array('posts_per_page' => count($ut_query_pages), 'post_type' => 'page', 'post__in' => $ut_query_pages, 'orderby' => 'post__in');
             return $pagequery;
         } else {
             /* return empty arguments */
             return array();
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Create a new variable containing the IDs and icons of menu items to be used by the SCSS file
  *
  * @param array $vars
  * @param string $location
  * @param string $theme
  * @param int $menu_id
  * @return string - all custom SCSS vars
  * @since 1.0
  */
 public function add_custom_icons_var_to_scss($vars, $location, $theme, $menu_id)
 {
     $menu_items = wp_get_nav_menu_items($menu_id);
     $custom_vars = array();
     if (is_array($menu_items)) {
         foreach ($menu_items as $menu_order => $item) {
             if ($settings = get_post_meta($item->ID, "_megamenu", true)) {
                 if (isset($settings['icon']) && $settings['icon'] == 'custom' && isset($settings['custom_icon']['id']) && intval($settings['custom_icon']['id']) > 0) {
                     $id = $settings['custom_icon']['id'];
                     $width = $settings['custom_icon']['width'];
                     $height = $settings['custom_icon']['height'];
                     $vertical_align = $settings['custom_icon']['vertical_align'];
                     $styles = array('id' => $item->ID, 'custom_icon_url' => "'" . apply_filters("megamenu_custom_icon_url", $this->get_resized_image_url($id, $width, $height)) . "'", 'custom_icon_width' => $width . 'px', 'custom_icon_height' => $height . 'px', 'custom_icon_2x_url' => "'" . apply_filters("megamenu_custom_icon_url", $this->get_resized_image_url($id, $width * 2, $height * 2)) . "'", 'custom_icon_2x_width' => $width * 2 . 'px', 'custom_icon_2x_height' => $height * 2 . 'px', 'custom_icon_vertical_align' => $vertical_align);
                     $custom_vars[$item->ID] = $styles;
                 }
             }
         }
     }
     //$custom_icons:(
     // (123, red, 150px),
     // (456, green, null),
     // (789, blue, 90%),());
     if (count($custom_vars)) {
         $list = "(";
         foreach ($custom_vars as $id => $vals) {
             $list .= "(" . implode(",", $vals) . "),";
         }
         // Always add an empty list item to meke sure there are always at least 2 items in the list
         // Lists with a single item are not treated the same way by SASS
         $list .= "());";
         $vars['custom_icons'] = $list;
     }
     return $vars;
 }
Exemplo n.º 16
0
 protected function getItems($menu)
 {
     $items = [];
     // Get all items for the current menu
     if ($menu && !is_wp_error($menu)) {
         $menu_items = wp_get_nav_menu_items($menu->term_id);
     }
     // Check if the menu is not empty
     if (!$menu_items) {
         $items[] = ['name' => '', 'label' => 'No items', 'disabled' => true];
     } else {
         $walker = new AssignmentsWalker();
         $new_menu_items = [];
         foreach ($menu_items as $new_menu_item) {
             $new_menu_item->id = $new_menu_item->ID;
             $new_menu_item->parent_id = empty($new_menu_item->menu_item_parent) ? get_post_meta($new_menu_item->ID, '_menu_item_menu_item_parent', true) : $new_menu_item->menu_item_parent;
             $new_menu_items[] = $new_menu_item;
         }
         $menu_items = $walker->walk($new_menu_items, 0);
         foreach ($menu_items as $menu_item) {
             $items[] = ['name' => $menu_item->ID, 'label' => $menu_item->level > 0 ? str_repeat('—', $menu_item->level) . ' ' . $menu_item->title : $menu_item->title, 'disabled' => false];
         }
     }
     return apply_filters('g5_assignments_' . $menu->slug . '_menu_list_items', $items, $menu->slug, $this->type);
 }
function acp_skiplinks_output()
{
    check_ajax_referer('acp-sec-skiplinks', 'security');
    $hp_skiplinks = get_option('acp_skiplinks_home', false);
    if ($hp_skiplinks) {
        $menu_name = is_home() || is_front_page() ? 'skiplinks-home' : 'skiplinks';
    } else {
        $menu_name = 'skiplinks';
    }
    if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
        $menu = wp_get_nav_menu_object($locations[$menu_name]);
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        $menu_side = get_option('acp_skiplinks_side', false);
        $menu_list = '<ul id="acp_skiplinks" role="navigation" class="' . $menu_side . '">';
        foreach ((array) $menu_items as $key => $menu_item) {
            $title = $menu_item->title;
            $url = $menu_item->url;
            $menu_list .= '<li><a href="' . $url . '" class="skiplinks">' . $title . '</a></li>';
        }
        $menu_list .= '</ul></nav>';
    } else {
        $menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
    }
    if (get_option('acp_skiplinks', false)) {
        echo $menu_list;
    }
    die;
}
Exemplo n.º 18
-1
/**
 * Grab latest post title by an author!
 *
 * @param array $data Options for the function.
 * @return string|null Post title for the latest,
 * or null if none.
 */
function get_menu_function($data)
{
    error_log($data['name']);
    $args = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true, 'update_post_term_cache' => false);
    $items = wp_get_nav_menu_items($data['name'], $args);
    return $items;
}
Exemplo n.º 19
-1
 function page_menu($menu_name)
 {
     if (($locations = get_nav_menu_locations()) && isset($locations[$menu_name])) {
         $count = 0;
         $menu = wp_get_nav_menu_object($locations[$menu_name]);
         $menu_items = wp_get_nav_menu_items($menu->term_id);
         $menu_list = '<div class="portfolio_blocks">';
         foreach ((array) $menu_items as $key => $menu_item) {
             $count++;
             $menu_list .= '<div class="blocks_block">
                                 <div class="block_content">
                                     <figure class="block_content--image">
                                         ' . get_the_post_thumbnail($menu_item->object_id, 'full') . '
                                     </figure>
                                     <div class="block_content--heading">
                                         <h4 class="block_content--title">' . $menu_item->title . '</h4>
                                     </div>
                                     <a href="' . get_permalink($menu_item->object_id) . '" class="block_content--link"></a>
                                 </div>
                             </div>';
         }
         $menu_list .= '</div>';
     } else {
         $menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
     }
     // $menu_list now ready to output
     echo $menu_list;
 }
Exemplo n.º 20
-1
 /**
  * Returns menu items from a menu
  */
 public static function get_menu_items($menu_id)
 {
     if ($menu_id && !empty(self::$menus[$menu_id])) {
         return wp_get_nav_menu_items(self::$menus[$menu_id]->term_id);
     }
     return false;
 }
Exemplo n.º 21
-1
function seattlemennonite_section()
{
    $locations = get_nav_menu_locations();
    if (isset($locations['primary'])) {
        $menu = wp_get_nav_menu_object($locations['primary']);
        // Get an array of menu items.
        $menu_items = wp_get_nav_menu_items($menu->term_id);
        _wp_menu_item_classes_by_context($menu_items);
        // These classes indicate that this is the current menu item.
        $current_classes = array('current-menu-ancestor', 'current-menu-item', 'current-post-ancestor');
        // Create an array that maps the id of the menu item to
        // the item object.
        $map = array();
        foreach ((array) $menu_items as $key => $menu_item) {
            $map[$menu_item->db_id] = $menu_item;
        }
        unset($menu_items);
        // Loop through the menu items looking for the current one.
        foreach ($map as $key => $menu_item) {
            if (array_intersect($current_classes, $menu_item->classes)) {
                return seattlemennonite_get_section($map, $menu_item);
            }
        }
    }
}
Exemplo n.º 22
-1
 /**
  * Create a new variable containing the IDs and icons of menu items to be used by the SCSS file
  *
  * @param array $vars
  * @param string $location
  * @param string $theme
  * @param int $menu_id
  * @return array - all custom SCSS vars
  * @since 1.3
  */
 public function add_vars_to_scss($vars, $location, $theme, $menu_id)
 {
     $menu_items = wp_get_nav_menu_items($menu_id);
     $custom_vars = array();
     if (is_array($menu_items)) {
         foreach ($menu_items as $menu_order => $item) {
             if ($settings = get_post_meta($item->ID, "_megamenu", true)) {
                 if (isset($settings['replacements']['type']) && in_array($settings['replacements']['type'], array('search'))) {
                     $styles = array('id' => $item->ID, 'search_height' => isset($settings['replacements']['search']['height']) ? $settings['replacements']['search']['height'] : '30px', 'search_text_color' => isset($settings['replacements']['search']['text_color']) ? $settings['replacements']['search']['text_color'] : '#333', 'search_icon_color_closed' => isset($settings['replacements']['search']['icon_color_closed']) ? $settings['replacements']['search']['icon_color_closed'] : '#fff', 'search_icon_color_open' => isset($settings['replacements']['search']['icon_color_open']) ? $settings['replacements']['search']['icon_color_open'] : '#333', 'search_background_color_closed' => isset($settings['replacements']['search']['background_color_closed']) ? $settings['replacements']['search']['background_color_closed'] : 'transparent', 'search_background_color_open' => isset($settings['replacements']['search']['background_color_open']) ? $settings['replacements']['search']['background_color_open'] : '#fff', 'search_border_radius' => isset($settings['replacements']['search']['border_radius']) ? $settings['replacements']['search']['border_radius'] : '2px');
                     $custom_vars[$item->ID] = $styles;
                 }
             }
         }
     }
     //$custom_styles:(
     // (123, red, 150px),
     // (456, green, null),
     // (789, blue, 90%),());
     if (count($custom_vars)) {
         $list = "(";
         foreach ($custom_vars as $id => $vals) {
             $list .= "(" . implode(",", $vals) . "),";
         }
         // Always add an empty list item to meke sure there are always at least 2 items in the list
         // Lists with a single item are not treated the same way by SASS
         $list .= "());";
         $vars['replacements_search'] = $list;
     } else {
         $vars['replacements_search'] = "()";
     }
     return $vars;
 }
Exemplo n.º 23
-1
function get_header_images()
{
    global $wphi_dir;
    $menus = get_terms('nav_menu', array('hide_empty' => true));
    $wp_header_images = get_option('wp_header_images');
    $arr = array();
    $arr_obj = array();
    $page_id = get_the_ID();
    foreach ($menus as $menu) {
        $menu_items = wp_get_nav_menu_items($menu->name);
        if (!empty($menu_items)) {
            foreach ($menu_items as $items) {
                $parent = $items->menu_item_parent;
                $arr[$items->ID] = $parent;
                $arr_obj[$items->object_id] = $items->ID;
            }
        }
    }
    $parent_id = $arr_obj[$page_id];
    $img_id = $wp_header_images[$parent_id];
    if ($img_id > 0) {
        $img_url = wp_get_attachment_url($img_id);
        if ($img_url != '') {
            include $wphi_dir . 'templates/header_images.php';
        }
    }
}
Exemplo n.º 24
-1
 private function setupBaseInfo()
 {
     if (null == $this->current_url) {
         $this->current_url = GantryFactMenu::_curPageURL();
     }
     if (null == $this->menu_items) {
         $this->menu_items = wp_get_nav_menu_items(wp_get_nav_menu_object($this->type));
     }
     if (null == $this->fact_menu_item) {
         foreach ($this->menu_items as $item) {
             if ($item->ID == $this->id) {
                 $this->fact_menu_item = $item;
                 break;
             }
         }
     }
     if (null == $this->children) {
         $this->children = array();
         $list = array();
         foreach ($this->menu_items as $item) {
             $thisref =& $this->children[$item->ID];
             $thisref['parent_id'] = $item->menu_item_parent;
             if ($item->menu_item_parent == 0) {
                 $list[$item->ID] =& $thisref;
             } else {
                 $this->children[$item->menu_item_parent]['children'][] = $item->ID;
             }
         }
     }
 }
Exemplo n.º 25
-1
 /**
  * Get menu items from the platform.
  *
  * @param int $levels
  * @return array    List of routes to the pages.
  */
 protected function getItemsFromPlatform($params)
 {
     if (is_admin()) {
         $gantry = static::gantry();
         $menus = array_flip($gantry['menu']->getMenus());
         $id = isset($menus[$params['menu']]) ? $menus[$params['menu']] : 0;
         // Save global menu settings into Wordpress.
         $menuObject = wp_get_nav_menu_object($id);
         if (is_wp_error($menuObject)) {
             return null;
         }
         // Get all menu items.
         $unsorted_menu_items = wp_get_nav_menu_items($id, ['post_status' => 'draft,publish']);
         $menuItems = [];
         foreach ($unsorted_menu_items as $menuItem) {
             $tree = $menuItem->menu_item_parent ? $menuItems[$menuItem->menu_item_parent]->tree : [];
             $menuItem->level = count($tree);
             $menuItem->tree = array_merge($tree, [$menuItem->db_id]);
             $menuItem->path = implode('/', $menuItem->tree);
             $menuItems[$menuItem->db_id] = $menuItem;
         }
         return $menuItems;
     }
     $menu = $this->getWPMenu($params);
     if ($menu) {
         return $this->buildList($menu->get_items());
     }
     return null;
 }
Exemplo n.º 26
-1
function ac_activation_setup_menus()
{
    // Create the menu
    $roots_nav_theme_mod = false;
    $primary_nav = wp_get_nav_menu_object('Primary Navigation');
    if (!$primary_nav) {
        $primary_nav_id = wp_create_nav_menu('Primary Navigation', array('slug' => 'primary_navigation'));
        $roots_nav_theme_mod['primary_navigation'] = $primary_nav_id;
    } else {
        $roots_nav_theme_mod['primary_navigation'] = $primary_nav->term_id;
    }
    if ($roots_nav_theme_mod) {
        set_theme_mod('nav_menu_locations', $roots_nav_theme_mod);
    }
    // Add the pages to the menu
    $primary_nav = wp_get_nav_menu_object('Primary Navigation');
    $primary_nav_term_id = (int) $primary_nav->term_id;
    $menu_items = wp_get_nav_menu_items($primary_nav_term_id);
    if (!$menu_items || empty($menu_items)) {
        $pages = get_pages();
        foreach ($pages as $page) {
            $item = array('menu-item-object-id' => $page->ID, 'menu-item-object' => 'page', 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish');
            wp_update_nav_menu_item($primary_nav_term_id, 0, $item);
        }
    }
}
/**
 * Get menu's data from his id
 * @param  array $data WP REST API data variable
 * @return object Menu's data with his items
 */
function wp_api_v2_menus_get_menu_data($data)
{
    $menu = new stdClass();
    $menu = wp_get_nav_menu_object($data['id']);
    $menu->items = wp_get_nav_menu_items($menu->term_id);
    return $menu;
}
Exemplo n.º 28
-1
 /**
  * Clear out the menu
  */
 public function clearMenu($menu_id)
 {
     $menu_items = wp_get_nav_menu_items($menu_id);
     foreach ($menu_items as $i) {
         wp_delete_post($i->ID, true);
     }
 }
/**
 *
 * Pulls the menus into a hierarchical array
 *
 */
function wp_get_menu_array($current_menu)
{
    $array_menu = wp_get_nav_menu_items($current_menu);
    $menu = array();
    foreach ($array_menu as $m) {
        if (empty($m->menu_item_parent)) {
            $menu[$m->ID] = array();
            $menu[$m->ID]['ID'] = $m->object_id;
            $menu[$m->ID]['type'] = $m->object;
            $menu[$m->ID]['title'] = $m->title;
            $menu[$m->ID]['url'] = $m->url;
            $menu[$m->ID]['children'] = array();
        }
    }
    $submenu = array();
    foreach ($array_menu as $m) {
        if ($m->menu_item_parent) {
            $submenu[$m->ID] = array();
            $submenu[$m->ID]['ID'] = $m->object_id;
            $submenu[$m->ID]['type'] = $m->object;
            $submenu[$m->ID]['title'] = $m->title;
            $submenu[$m->ID]['url'] = $m->url;
            $menu[$m->menu_item_parent]['children'][$m->ID] = $submenu[$m->ID];
        }
    }
    return $menu;
}
Exemplo n.º 30
-1
function tucson_ebor_mega_menu($atts, $content = null)
{
    extract(shortcode_atts(array('child_menu' => '', 'title' => '', 'columns' => '4'), $atts));
    switch ($columns) {
        case $columns == 4:
            $col_md = 3;
            break;
        case $columns == 3:
            $col_md = 4;
            break;
        case $columns == 2:
            $col_md = 6;
            break;
        case $columns == 1:
            $col_md = 12;
            break;
        default:
            $col_md = 3;
            break;
    }
    $items = wp_get_nav_menu_items($child_menu);
    $output = '<div class="col-md-' . $col_md . '"><ul class="sub-menu"><li>';
    if ($title) {
        $output .= '<span class="mega-menu-sub-title">' . $title . '</span>';
    }
    $output .= '<ul class="sub-menu">';
    if ($items) {
        foreach ($items as $item) {
            $output .= '<li><a href="' . $item->url . '" target="' . $item->target . '">' . $item->title . '</a></li>';
        }
    }
    $output .= '</ul></li></ul></div>';
    return $output;
}