예제 #1
0
 function landing_setup()
 {
     load_theme_textdomain('landing', get_template_directory() . '/languages');
     add_theme_support("title-tag");
     add_theme_support('menus');
     add_theme_support('post-thumbnails');
     $menu_name = 'landing';
     $menu_exists = wp_get_nav_menu_object($menu_name);
     if (!$menu_exists) {
         $menu_id = wp_create_nav_menu($menu_name);
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Обо мне', 'landing'), 'menu-item-url' => home_url('/#about'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Резюме', 'landing'), 'menu-item-url' => home_url('/#resume'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Портволио', 'landing'), 'menu-item-url' => home_url('/#portfolio'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Контакты', 'landing'), 'menu-item-url' => home_url('/#contacts'), 'menu-item-status' => 'publish'));
     }
     $menu_name = 'social';
     $menu_exists = wp_get_nav_menu_object($menu_name);
     if (!$menu_exists) {
         $menu_id = wp_create_nav_menu($menu_name);
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Twitter profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-twitter', 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Facebook profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-facebook', 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Github profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-github', 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Vk profile', 'landing'), 'menu-item-target' => '_blank', 'menu-item-url' => '#', 'menu-item-classes' => 'fa fa-vk', 'menu-item-status' => 'publish'));
     }
 }
예제 #2
0
function wptouch_migrate_modded_menu()
{
    $menu_name = 'WPtouch - Recovered Page Menu';
    $menu_object = wp_get_nav_menu_object($menu_name);
    if (!$menu_object) {
        $menu_id = wp_create_nav_menu($menu_name);
        $pages = get_pages(array('post_status' => 'publish', 'sort_column' => 'menu_order, post_title'));
        $menu_items = array();
        $skipped_pages = array();
        foreach ($pages as $page) {
            if (wptouch_menu_is_disabled($page->ID)) {
                $skipped_pages[] = $page->ID;
            } elseif (!in_array($page->post_parent, $skipped_pages)) {
                $parent_id = 0;
                if (isset($menu_items[$page->post_parent])) {
                    $parent_id = $menu_items[$page->post_parent];
                }
                $args = array('menu-item-db-id' => 0, 'menu-item-object-id' => $page->ID, 'menu-item-object' => 'page', 'menu-item-type' => 'post_type', 'menu-item-parent-id' => $parent_id, 'menu-item-status' => 'publish');
                $menu_items[$page->ID] = wp_update_nav_menu_item($menu_id, 0, $args);
                $menu_icon = get_post_meta($page->ID, '_wptouch_pro_menu_item_icon', true);
                if ($menu_icon) {
                    add_post_meta($menu_items[$page->ID], '_wptouch_pro_menu_item_icon', $menu_icon);
                }
            }
        }
    } else {
        $menu_id = $menu_object->ID;
    }
    return $menu_id;
}
 /**
  * create optional test nav menu
  * 
  * At least two custom menus should be created in order to test a theme
  * The standard Theme data file now ships with optimal menus built-in
  * This method actually makes sense with custom WXR files only
  * 
  * @since 0.2
  */
 private function create_test_menus()
 {
     $pages = get_all_page_ids();
     $items = array();
     foreach ($pages as $page_ID) {
         $info = get_page($page_ID);
         $items[$info->post_title] = get_permalink($page_ID);
     }
     # pick three random entries
     $random = array_rand($items, 3);
     # build menus
     $menus = array('Full Menu' => array('slug' => 'full-menu', 'menu_items' => $items), 'Short Menu' => array('slug' => 'short-menu', 'menu_items' => array($items[$random[0]], $items[$random[1]], $items[$random[2]])));
     # register menus
     foreach ($menus as $title => $data) {
         register_nav_menu($data['slug'], $title);
         if (false == is_nav_menu($title)) {
             $menu_ID = wp_create_nav_menu($title);
             foreach ($data['menu_items'] as $name => $url) {
                 $add_item = array('menu-item-type' => 'custom', 'menu-item-url' => $url, 'menu-item-title' => $name);
                 wp_update_nav_menu_item($menu_ID, 0, $add_item);
             }
             WP_CLI::success('Created menu ' . $title);
         }
     }
 }
 function duplicate($id = null, $name = null)
 {
     // sanity check
     if (empty($id) || empty($name)) {
         return false;
     }
     $id = intval($id);
     $name = sanitize_text_field($name);
     $source = wp_get_nav_menu_object($id);
     $source_items = wp_get_nav_menu_items($id);
     $new_id = wp_create_nav_menu($name);
     if (!$new_id) {
         return false;
     }
     // key is the original db ID, val is the new
     $rel = array();
     $i = 1;
     foreach ($source_items as $menu_item) {
         $args = array('menu-item-db-id' => $menu_item->db_id, 'menu-item-object-id' => $menu_item->object_id, 'menu-item-object' => $menu_item->object, 'menu-item-position' => $i, 'menu-item-type' => $menu_item->type, 'menu-item-title' => $menu_item->title, 'menu-item-url' => $menu_item->url, 'menu-item-description' => $menu_item->description, 'menu-item-attr-title' => $menu_item->attr_title, 'menu-item-target' => $menu_item->target, 'menu-item-classes' => implode(' ', $menu_item->classes), 'menu-item-xfn' => $menu_item->xfn, 'menu-item-status' => $menu_item->post_status);
         $parent_id = wp_update_nav_menu_item($new_id, 0, $args);
         $rel[$menu_item->db_id] = $parent_id;
         // did it have a parent? if so, we need to update with the NEW ID
         if ($menu_item->menu_item_parent) {
             $args['menu-item-parent-id'] = $rel[$menu_item->menu_item_parent];
             $parent_id = wp_update_nav_menu_item($new_id, $parent_id, $args);
         }
         // allow developers to run any custom functionality they'd like
         do_action('duplicate_menu_item', $menu_item, $args);
         $i++;
     }
     return $new_id;
 }
예제 #5
0
/**
 * Register and create a custom BuddyPress menu
 */
function infinity_register_bp_menu($menu_name)
{
    global $blog_id;
    // check BP reqs and if our custom default menu already exists
    if (function_exists('bp_core_get_directory_pages') && BP_ROOT_BLOG == $blog_id && !is_nav_menu($menu_name)) {
        // doesn't exist, create it
        $menu_id = wp_create_nav_menu($menu_name);
        // get bp pages
        $pages = bp_core_get_directory_pages();
        // allowed pages
        $pages_ok = array('activity' => true, 'blogs' => true, 'forums' => true, 'groups' => true, 'links' => true, 'members' => true);
        // loop all pages
        foreach ($pages as $config) {
            // make sure we support this page
            if (array_key_exists($config->name, $pages_ok)) {
                // yep, add page as a nav item
                wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-status' => 'publish', 'menu-item-object' => 'page', 'menu-item-object-id' => $config->id, 'menu-item-title' => $config->title, 'menu-item-attr-title' => $config->title, 'menu-item-classes' => 'icon-' . $config->name));
            }
        }
        // get location settings
        $locations = get_theme_mod('nav_menu_locations');
        // is main menu location set yet?
        if (empty($locations['main-menu'])) {
            // nope, set it
            $locations['main-menu'] = $menu_id;
            // update theme mode
            set_theme_mod('nav_menu_locations', $locations);
        }
    }
}
예제 #6
0
 private function processMenu(&$menu)
 {
     $objMenu = wp_get_nav_menu_object($menu->slug);
     if (!$objMenu) {
         $id = wp_create_nav_menu($menu->slug);
         $objMenu = wp_get_nav_menu_object($menu->slug);
     }
     $menuId = $objMenu->term_id;
     $menu->id = $menuId;
     wp_set_current_user(1);
     $loggedInmenuItems = wp_get_nav_menu_items($menu->slug);
     wp_set_current_user(0);
     $notloggedInmenuItems = wp_get_nav_menu_items($menu->slug);
     $existingMenuItems = array_merge($loggedInmenuItems, $notloggedInmenuItems);
     foreach ($existingMenuItems as $existingMenuItem) {
         $ret = wp_delete_post($existingMenuItem->ID, true);
     }
     foreach ($menu->items as &$objMenuItem) {
         $newTarget = findTargetPostId($objMenuItem->meta->postMeta['_menu_item_object_id'][0]);
         $parentItem = $this->findMenuItem($objMenuItem->meta->postMeta['_menu_item_menu_item_parent'][0]);
         $args = ['menu-item-title' => $objMenuItem->meta->post_title, 'menu-item-position' => $objMenuItem->meta->menu_order, 'menu-item-description' => $objMenuItem->meta->post_content, 'menu-item-attr-title' => $objMenuItem->meta->post_title, 'menu-item-status' => $objMenuItem->meta->post_status, 'menu-item-type' => $objMenuItem->meta->postMeta['_menu_item_type'][0], 'menu-item-object' => $objMenuItem->meta->postMeta['_menu_item_object'][0], 'menu-item-object-id' => $newTarget, 'menu-item-url' => $objMenuItem->meta->postMeta['_menu_item_url'][0], 'menu-item-parent-id' => $parentItem];
         $ret = wp_update_nav_menu_item($menuId, 0, $args);
         $objMenuItem->id = $ret;
         foreach ($objMenuItem->meta->postMeta as $key => $meta) {
             if (in_array($key, $this->skipped_meta_fields) || substr($key, 0, 1) == '_') {
                 continue;
             }
             $val = $meta[0];
             update_post_meta($ret, $key, $val);
         }
     }
 }
예제 #7
0
 private static function setup()
 {
     $menu_id = wp_create_nav_menu(self::$description);
     $locations = get_theme_mod('nav_menu_locations');
     $locations['main-nav'] = $menu_id;
     set_theme_mod('nav_menu_locations', $locations);
 }
예제 #8
0
/**
 *
 * Function for registering wp_nav_menu() in 3 locations
 */
function bb_register_navmenus()
{
    register_nav_menus(array('Top' => __('Top Navigation'), 'Header' => __('Header Navigation'), 'Footer' => __('Footer Navigation')));
    // Check if Top menu exists and make it if not
    if (!is_nav_menu('Top')) {
        $menu_id = wp_create_nav_menu('Top');
        $menu = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
        wp_update_nav_menu_item($menu_id, 1, $menu);
    }
    // Check if Header menu exists and make it if not
    if (!is_nav_menu('Header')) {
        $menu_id = wp_create_nav_menu('Header');
        $menu = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
        wp_update_nav_menu_item($menu_id, 1, $menu);
    }
    // Check if Footer menu exists and make it if not
    if (!is_nav_menu('Footer')) {
        $menu_id = wp_create_nav_menu('Footer');
        $menu = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
        wp_update_nav_menu_item($menu_id, 1, $menu);
    }
    // Get any menu locations that dont have a menu assigned to it and give it on
    /*
    $loc = array('Top', 'Header', 'Footer');
    if ( has_nav_menu( $location )) {
    	$locations = get_nav_menu_locations();
    	return (!empty( $locations[ $location ] ));
    }
    */
}
예제 #9
0
 private function _402()
 {
     /* Fixed double key active_plugins */
     $plugins = get_option('active_plugins');
     if (is_array($plugins)) {
         $_plugins = array();
         foreach ($plugins as $plugin) {
             if (!in_array($plugin, $_plugins)) {
                 array_push($_plugins, $plugin);
             }
         }
         update_option('active_plugins', $_plugins);
     }
     /* Create new menu - top nav  */
     $menu_name = 'Top Navigation';
     //wp_delete_nav_menu( $menu_name );
     $menu_exists = wp_get_nav_menu_object($menu_name);
     if (!$menu_exists) {
         $menu_id = wp_create_nav_menu($menu_name);
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('<i class="fa fa-lock"></i>&nbsp; Login'), 'menu-item-url' => home_url('/?action=login'), 'menu-item-status' => 'publish'));
         wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('<i class="fa fa-pencil-square-o"></i>&nbsp; Register'), 'menu-item-url' => home_url('/?action=register'), 'menu-item-classes' => 'two active', 'menu-item-status' => 'publish'));
         $thememods = 'theme_mods_' . get_option('stylesheet', true);
         $mod = get_option($thememods);
         if (!isset($mod)) {
             $mod = array('nav_menu_locations' => array('top_nav' => $menu_id));
         } else {
             $mod['nav_menu_locations']['top_nav'] = $menu_id;
         }
         add_option($thememods, $mod) || update_option($thememods, $mod);
     }
 }
예제 #10
0
function xt_install_menu($global)
{
    $menu_id = wp_create_nav_menu('新淘客菜单');
    if ($menu_id) {
        //home
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => '首页', 'menu-item-status' => 'publish', 'menu-item-position' => 1));
        //shares
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_shares_search_url(), 'menu-item-title' => '逛街啦', 'menu-item-status' => 'publish', 'menu-item-position' => 2));
        //albums
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_albums_search_url(), 'menu-item-title' => '专辑', 'menu-item-status' => 'publish', 'menu-item-position' => 3));
        //taobaos
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_taobao_search_url(), 'menu-item-title' => '淘宝', 'menu-item-status' => 'publish', 'menu-item-position' => 6));
        //paipais
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_paipai_search_url(), 'menu-item-title' => '拍拍', 'menu-item-status' => 'publish', 'menu-item-position' => 7));
        //bijias
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_bijia_search_url(), 'menu-item-title' => '比价', 'menu-item-status' => 'publish', 'menu-item-position' => 8));
        //tuans
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_tuan_search_url(), 'menu-item-title' => '团购', 'menu-item-status' => 'publish', 'menu-item-position' => 9));
        //coupons
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_coupon_search_url(), 'menu-item-title' => '折扣', 'menu-item-status' => 'publish', 'menu-item-position' => 10));
        //temais
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_get_temai_search_url(), 'menu-item-title' => '特卖', 'menu-item-status' => 'publish', 'menu-item-position' => 11));
        //stars
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_site_url('stars'), 'menu-item-title' => '明星', 'menu-item-status' => 'publish', 'menu-item-position' => 12));
        //brands
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'custom', 'menu-item-url' => xt_site_url('brands'), 'menu-item-title' => '品牌', 'menu-item-status' => 'publish', 'menu-item-position' => 13));
        set_theme_mod('nav_menu_locations', array('primary' => $menu_id));
        $global['isMenu'] = 1;
        update_option(XT_OPTION_GLOBAL, $global);
    }
}
예제 #11
0
function rksnwp_add_sentinote_menu()
{
    $menu = apply_filters('sentinote_menu_name_filter', __('Sentinote Menu'));
    $menu_exists = wp_get_nav_menu_object($menu);
    if (!$menu_exists) {
        $menu_id = wp_create_nav_menu($menu);
    }
}
예제 #12
0
function register_navmenus()
{
    register_nav_menus(array('Header' => __('Header Navigation')));
    // Check if Header menu exists and make it if not
    if (!is_nav_menu('Header')) {
        $menu_id = wp_create_nav_menu('Header');
    }
}
예제 #13
0
 function make_menu($menu_name)
 {
     $menu_exists = wp_get_nav_menu_object($menu_name);
     // If it doesn't exist, let's create it.
     if (!$menu_exists) {
         $menu_id = wp_create_nav_menu($menu_slug);
     }
 }
예제 #14
0
/**
 * Register default menu.
 *
 * @since 1.0.0
 */
function beans_do_register_default_menu()
{
    // Stop here if a menu already exists.
    if (wp_get_nav_menus()) {
        return;
    }
    // Set up default menu.
    wp_update_nav_menu_item(wp_create_nav_menu(__('Navigation', 'beans')), 0, array('menu-item-title' => __('Home', 'beans'), 'menu-item-classes' => 'home', 'menu-item-url' => home_url('/'), 'menu-item-status' => 'publish'));
}
예제 #15
0
function create_pages()
{
    // Argument dla strony Głównej
    $main_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'main', 'page_template' => 'page-templates/main.php', 'post_title' => 'Główna', 'post_content' => '');
    if (get_page_by_title('Główna') == null) {
        $main_page = wp_insert_post($main_page_args);
        update_option('page_on_front', $main_page);
        update_option('show_on_front', 'page');
        echo '<div class="updated"> <p>Utworzono stronę "Główna"</p></div>';
    }
    // Argument dla strony Blog
    $blog_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'blog', 'page_template' => 'page-templates/blog.php', 'post_title' => 'Blog', 'post_content' => '');
    if (get_page_by_title('Blog') == null) {
        wp_insert_post($blog_page_args);
        echo '<div class="updated"> <p>Utworzono stronę "Blog"</p></div>';
    }
    // Argument dla strony Projekty
    $projects_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'projects', 'page_template' => 'page-templates/projects.php', 'post_title' => 'Projekty', 'post_content' => '');
    if (get_page_by_title('Projekty') == null) {
        wp_insert_post($projects_page_args);
        echo '<div class="updated"> <p>Utworzono stronę "Projekty"</p></div>';
    }
    // Argument dla strony Login
    $login_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'login', 'page_template' => 'page-templates/login.php', 'post_title' => 'Logowanie', 'post_content' => '');
    if (get_page_by_title('Logowanie') == null) {
        wp_insert_post($login_page_args);
        echo '<div class="updated"> <p>Utworzono stronę "Logowanie"</p></div>';
    }
    // Argument dla strony Członkowie
    $members_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'members', 'page_template' => 'page-templates/members.php', 'post_title' => 'Członkowie', 'post_content' => '');
    if (get_page_by_title('Członkowie') == null) {
        wp_insert_post($members_page_args);
        echo '<div class="updated"> <p>Utworzono stronę "Członkowie"</p></div>';
    }
    // Argument dla strony O nas
    $about_page_args = array('post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'about', 'post_title' => 'O nas', 'post_content' => 'Jakiś tekst o nas');
    if (get_page_by_title('O nas') == null) {
        wp_insert_post($about_page_args);
        echo '<div class="updated"> <p>Utworzono stronę "O nas"</p></div>';
    }
    // Tworzymy menu i dodajemy do niego pozycje //
    if (!is_nav_menu('topbar_menu')) {
        $menu_id = wp_create_nav_menu('topbar_menu');
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'Blog', 'menu-item-object' => 'page', 'menu-item-object-id' => get_page_by_path('blog')->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'Członkowie', 'menu-item-object' => 'page', 'menu-item-object-id' => get_page_by_path('members')->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
        wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => 'O nas', 'menu-item-object' => 'page', 'menu-item-object-id' => get_page_by_path('about')->ID, 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
        // Grab the theme locations and assign our newly-created menu
        // to the BuddyPress menu location.
        if (!has_nav_menu('topbar_menu')) {
            $locations = get_theme_mod('nav_menu_locations');
            $locations['main_menu'] = $menu_id;
            set_theme_mod('nav_menu_locations', $locations);
            echo '<div class="updated"> <p>Utworzono menu</p></div>';
        }
    }
}
 /**
  * Creates the menu with given name
  * 
  * If a menu with given name exists this method will return its id.
  * If $location parameter is passed this method will assign the menu with given $name to such location
  * 
  * @param string $name the menu name
  * @param string $location
  * @return Ambigous <mixed, boolean, unknown, multitype:, NULL, WP_Error, object, array|object, string, number, error, multitype:mixed unknown , multitype:number mixed , multitype:number Ambigous <string, NULL> >
  */
 public function create_menu($name, $location = null)
 {
     $id = wp_get_nav_menu_object($name) ? wp_get_nav_menu_object($name) : wp_create_nav_menu($name);
     if (!(is_null($location) || has_nav_menu($location))) {
         $locations = get_theme_mod('nav_menu_locations');
         $locations[$location] = $id;
         set_theme_mod('nav_menu_locations', $locations);
     }
     return is_object($id) ? intval($id->term_id) : $id;
 }
function estatik_activate()
{
    create_estatik_tables();
    add_role('agent_role', 'Agent', array('read' => true));
    $menu_name = 'view_first';
    $menu_exists = wp_get_nav_menu_object($menu_name);
    if (!$menu_exists) {
        wp_create_nav_menu($menu_name);
    }
    es_reset_permalinks();
}
예제 #18
0
 /**
  * Create the header menu and apply to header menu
  *
  * @access public
  * @since 1.0.0
  */
 function create_menus()
 {
     $otm_nav_theme_mod = false;
     if (!has_nav_menu('header-menu')) {
         $primary_nav_id = wp_create_nav_menu(__('Header Menu', 'evans-mu'), array('slug' => 'header-menu'));
         $otm_nav_theme_mod['header-menu'] = $primary_nav_id;
     }
     if ($otm_nav_theme_mod) {
         set_theme_mod('nav_menu_locations', $otm_nav_theme_mod);
     }
 }
 public function createMenu($menu_name)
 {
     $this->createdMenu = $new_menu = wp_create_nav_menu($menu_name);
     if (is_numeric($new_menu)) {
         foreach ($this->menu_items as $menu_item) {
             $this->setMenuItem($menu_item);
             $this->counter++;
         }
     }
     return json_encode($this->createdMenu);
 }
예제 #20
0
 /**
  * Create a new nav menu
  *
  * @param  string $name
  *
  * @return int|bool
  */
 private function create_nav_menu($name)
 {
     $exists = wp_get_nav_menu_object($name);
     if (!empty($exists->term_id)) {
         return absint($exists->term_id);
     }
     $id = wp_create_nav_menu($name);
     if (is_wp_error($id)) {
         return false;
     }
     return absint($id);
 }
예제 #21
0
파일: menu.php 프로젝트: Getbeans/Beans
/**
 * Register default menu.
 *
 * @since 1.0.0
 */
function beans_do_register_default_menu()
{
    // Stop here if a menu already exists.
    if (wp_get_nav_menus()) {
        return;
    }
    $name = __('Navigation', 'tm-beans');
    // Set up default menu if it doesn't exists.
    if (!wp_get_nav_menu_object($name)) {
        wp_update_nav_menu_item(wp_create_nav_menu($name), 0, array('menu-item-title' => __('Home', 'tm-beans'), 'menu-item-classes' => 'home', 'menu-item-url' => home_url('/'), 'menu-item-status' => 'publish'));
    }
}
예제 #22
0
파일: setup.php 프로젝트: jun200/wordpress
 function wplook_setup()
 {
     // This theme styles the visual editor with editor-style.css to match the theme style.
     add_editor_style();
     // Add default posts and comments RSS feed links to head
     function register_my_menus()
     {
         register_nav_menus(array('primary' => __('StylishWP Main Navigation', 'wplook')));
     }
     add_action('init', 'register_my_menus');
     wp_create_nav_menu('StylishWP Main Menu', array('slug' => 'primary'));
 }
예제 #23
0
/**
 * Register and create a default menu in CBOX.
 *
 * @param array $args Arguments to register the default menu:
 *  'menu_name' - The internal menu name we should give our new menu.
 *  'location' - The nav menu location we want our new menu to reside.
 *  'pages' - Associative array of pages. Sample looks like this:
 *       array(
 *            array(
 *                 'title'    => 'Home',
 *                 'position' => 0,
 *                 'url'      => home_url( '/' ) // custom url
 *            ),
 *            array(
 *                 'title'        => 'Members',
 *                 'position'     => 10,
 *                 'bp_directory' => 'members'   // match bp component
 *            ),
 *       )
 */
function cbox_theme_register_default_menu($args = array())
{
    global $blog_id;
    if (empty($args['menu_name']) || empty($args['location']) || empty($args['pages'])) {
        return false;
    }
    if (!is_array($args['pages'])) {
        return false;
    }
    // check BP reqs and if our custom default menu already exists
    if (function_exists('bp_core_get_directory_pages') && BP_ROOT_BLOG == $blog_id && !is_nav_menu($args['menu_name'])) {
        // menu doesn't exist, so create it
        $menu_id = wp_create_nav_menu($args['menu_name']);
        // get bp pages
        $bp_pages = bp_core_get_directory_pages();
        // now, add the pages to our menu
        foreach ($args['pages'] as $page) {
            // default args
            $params = array('menu-item-status' => 'publish', 'menu-item-title' => $page['title'], 'menu-item-classes' => 'icon-' . !empty($page['bp_directory']) ? $page['bp_directory'] : sanitize_title($page['title']), 'menu-item-position' => $page['position']);
            // support custom menu type
            if (!empty($page['type'])) {
                $params['menu-item-type'] = $page['type'];
            }
            // support custom url
            if (!empty($page['url'])) {
                $params['menu-item-url'] = $page['url'];
            }
            // add additional args for bp directories
            if (!empty($page['bp_directory'])) {
                // bp directory page doesn't exist, so stop!
                if (!array_key_exists($page['bp_directory'], get_object_vars($bp_pages))) {
                    continue;
                }
                // yep, add page as a nav item
                $params['menu-item-type'] = 'post_type';
                $params['menu-item-object'] = 'page';
                $params['menu-item-object-id'] = $bp_pages->{$page['bp_directory']}->id;
            }
            wp_update_nav_menu_item($menu_id, 0, $params);
            $params = array();
        }
        // get location settings
        $locations = get_theme_mod('nav_menu_locations');
        // is our menu location set yet?
        if (empty($locations[$args['location']])) {
            // nope, set it
            $locations[$args['location']] = $menu_id;
            // update theme mode
            set_theme_mod('nav_menu_locations', $locations);
        }
        return true;
    }
}
예제 #24
0
파일: menu.php 프로젝트: ryanshoover/wp-cli
 /**
  * Create a new menu
  *
  * <menu-name>
  * : A descriptive name for the menu
  *
  * [--porcelain]
  * : Output just the new menu id.
  *
  * ## EXAMPLES
  *
  *     wp menu create "My Menu"
  */
 public function create($args, $assoc_args)
 {
     $menu_id = wp_create_nav_menu($args[0]);
     if (is_wp_error($menu_id)) {
         WP_CLI::error($menu_id->get_error_message());
     } else {
         if (\WP_CLI\Utils\get_flag_value($assoc_args, 'porcelain')) {
             WP_CLI::line($menu_id);
         } else {
             WP_CLI::success("Created menu {$menu_id}.");
         }
     }
 }
예제 #25
0
 function ready_ecommerce_setup()
 {
     global $wpdb;
     /* Language Support */
     load_theme_textdomain('ready_ecommerce', get_template_directory() . '/languages');
     $locale = get_locale();
     $locale_file = get_template_directory() . "/languages/{$locale}.php";
     if (is_readable($locale_file)) {
         require_once $locale_file;
     }
     /* Add default posts and comments RSS feed links to head */
     add_theme_support('automatic-feed-links');
     /* This theme uses wp_nav_menu() in two location.*/
     register_nav_menus(array('primary' => __('Primary Menu', 'ready_ecommerce'), 'top' => __('Top "Drop-Down" Menu', 'ready_ecommerce')));
     /* Create theme custom menu */
     $name = 'Ready! Ecommerce Menu';
     $menu = wp_get_nav_menu_object($name);
     if (!$menu) {
         $menu_id = wp_create_nav_menu($name);
         $options = get_option('nav_menu_options');
         $options['auto_add'][] = $menu_id;
         update_option('nav_menu_options', $options);
         $itemData = array('menu-item-type' => 'custom', 'menu-item-url' => get_home_url('/'), 'menu-item-title' => 'Home');
         wp_update_nav_menu_item($menu_id, 0, $itemData);
         // if Ready! Commerce plugin is already installed add the pages to menu
         require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         // Need for plugins_api
     } else {
         $menu_id = $menu->term_id;
     }
     /* Set Custom Menu */
     if (!has_nav_menu('primary')) {
         $locations = get_theme_mod('nav_menu_locations');
         $locations['primary'] = $menu_id;
         set_theme_mod('nav_menu_locations', $locations);
     }
     if (!has_nav_menu('top')) {
         $locations = get_theme_mod('nav_menu_locations');
         $locations['top'] = $menu_id;
         set_theme_mod('nav_menu_locations', $locations);
     }
     /* Activate Social Links Module */
     $social_links = new SocialLinks();
     $social_links->social_links_install();
     /* Add support for the Aside and Gallery Post Formats */
     add_theme_support('post-formats', array('aside', 'image', 'gallery'));
     if (class_exists('frame')) {
         frame::_()->getModule('options')->getModel('')->put(array('code' => 'default_theme', 'value' => 'ready_ecommerce_theme'));
     }
     wp_update_term(1, 'category', array('name' => 'Shop', 'slug' => 'shop'));
 }
function free01_setup()
{
    /***** Navigation & Menu *****/
    $menus = array(__('Main menu', 'free01') => __('Main menu', 'free01'));
    foreach ($menus as $key => $value) {
        if (!is_nav_menu($key)) {
            wp_update_nav_menu_item(wp_create_nav_menu($key), 1);
        }
    }
    if (function_exists('register_nav_menus')) {
        register_nav_menus($menus);
    }
    remove_action('wp_head', '_admin_bar_bump_cb');
}
예제 #27
0
function degrona15_setup_options()
{
    // update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
    $hello_world = get_post(1, 'ARRAY_A');
    // By default we check only english and finnish versions of default post/page
    // TODO: swedish check
    if ($hello_world && $hello_world['post_title'] == 'Hello world!' || $hello_world['post_title'] == 'Moikka maailma!') {
        wp_update_post(array('ID' => 1, 'post_title' => __('Newsletter: Welcome to WordPress!', 'DeGrona15'), 'post_name' => __('newsletter-welcome-to-wordpress', 'DeGrona15'), 'post_content' => __('This is an example post. Posts can be used for example for blog texts. You can delete this post in admin panel &rarr; Posts &rarr; All Posts &rarr; choose "Newsletter: Welcome to WordPress" and move it to the trash. You can write new posts by clicking the "Add New"-button in Posts -page.', 'DeGrona15')));
    }
    $sample_page = get_post(2, 'ARRAY_A');
    // By default we check only english and finnish versions of default post/page
    // TODO: swedish check
    if ($sample_page && $sample_page['post_title'] == 'Sample Page' || $sample_page['post_title'] == 'Esimerkkisivu') {
        wp_update_post(array('ID' => 2, 'post_title' => __('Home', 'DeGrona15'), 'post_name' => __('home', 'DeGrona15'), 'post_content' => ''));
        update_option('page_on_front', 2);
        update_option('show_on_front', 'page');
    }
    $posts_page_id = get_option('page_for_posts');
    $blog_page_already_exists = false;
    if (!$posts_page_id && !get_page_by_path('blogi')) {
        $posts_page_id = wp_insert_post(array('post_title' => __('Blog', 'DeGrona15'), 'post_name' => __('blog', 'DeGrona15'), 'post_status' => 'publish', 'post_type' => 'page'));
        if ($posts_page_id) {
            update_option('page_for_posts', $posts_page_id);
        }
    } else {
        $blog_page_already_exists = true;
    }
    if (!has_nav_menu('top-bar-l')) {
        $menus = get_terms('nav_menu', array('hide_empty' => true));
        if (!$menus) {
            $menu_id = wp_create_nav_menu(__('The Main Menu', 'DeGrona15'));
            /**
             * Set up default menu items
             * If posts page is set above: add blog-page to menu as well
             */
            wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Home', 'DeGrona15'), 'menu-item-url' => home_url('/'), 'menu-item-status' => 'publish'));
            if ($posts_page_id && !$blog_page_already_exists) {
                wp_update_nav_menu_item($menu_id, 0, array('menu-item-title' => __('Blog', 'DeGrona15'), 'menu-item-object-id' => $posts_page_id, 'menu-item-object' => 'page', 'menu-item-type' => 'post_type', 'menu-item-status' => 'publish'));
            }
            // Add menu to mobile and top-bar-l
            $menu_defaults = array('mobile-off-canvas' => $menu_id, 'top-bar-l' => $menu_id);
            set_theme_mod('nav_menu_locations', $menu_defaults);
        } else {
            // Add menu to mobile and top-bar-l
            $menu_defaults = array('mobile-off-canvas' => $menus[0]->term_id, 'top-bar-l' => $menus[0]->term_id);
            set_theme_mod('nav_menu_locations', $menu_defaults);
        }
    }
}
예제 #28
0
 /**
  * Convert existing nestedpages_menu option to menu ID rather than string/name
  * @since 1.1.5
  */
 private function convertMenuToID()
 {
     if (version_compare($this->current_version, '1.1.5', '<')) {
         $menu_option = get_option('nestedpages_menu');
         $menu = get_term_by('name', $menu_option, 'nav_menu');
         if ($menu) {
             delete_option('nestedpages_menu');
             update_option('nestedpages_menu', $menu->term_id);
         } else {
             delete_option('nestedpages_menu');
             $menu_id = wp_create_nav_menu('Nested Pages');
             update_option('nestedpages_menu', $menu_id);
         }
     }
 }
예제 #29
0
 function charitas_setup()
 {
     /*-----------------------------------------------------------
     		Make theme available for translation
     	-----------------------------------------------------------*/
     load_theme_textdomain('charitas', get_template_directory() . '/languages');
     /*-----------------------------------------------------------
     		Theme style for the visual editor
     	-----------------------------------------------------------*/
     add_editor_style('css/editor-style.css');
     /*-----------------------------------------------------------
     		Add default posts and comments RSS feed links to head
     	-----------------------------------------------------------*/
     add_theme_support('automatic-feed-links');
     /*-----------------------------------------------------------
     		Enable support for Title Tag
     	-----------------------------------------------------------*/
     add_theme_support('title-tag');
     /*-----------------------------------------------------------
     		Enable support for Post Thumbnails on posts and pages
     	-----------------------------------------------------------*/
     add_theme_support('post-thumbnails');
     add_image_size('charitas-lite-small-thumb', 272, 150, true);
     add_image_size('charitas-lite-medium-thumb', 500, 277, true);
     add_image_size('charitas-lite-big-thumb', 1200, 661, true);
     /*-----------------------------------------------------------
     		Register menu
     	-----------------------------------------------------------*/
     function register_my_menus()
     {
         register_nav_menus(array('primary' => __('Main Menu', 'charitas'), 'language' => __('Language Menu', 'charitas')));
     }
     add_action('init', 'register_my_menus');
     wp_create_nav_menu('Main Menu', array('slug' => 'primary'));
     wp_create_nav_menu('Language Menu', array('slug' => 'language'));
     /*-----------------------------------------------------------
     		Enable support for Post Formats
     	-----------------------------------------------------------*/
     add_theme_support('post-formats', array('gallery', 'video', 'status'));
     /*-----------------------------------------------------------
     		Add theme Support Custom Background
     	-----------------------------------------------------------*/
     add_theme_support('custom-background');
     /*-----------------------------------------------------------
     		Add theme Support  Custom Header
     	-----------------------------------------------------------*/
     add_theme_support('custom-header');
 }
예제 #30
-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);
        }
    }
}