Beispiel #1
0
 /**
  * This hooks into 'customize_register' (available as of WP 3.4) and allows
  * you to add new sections and controls to the Theme Customize screen.
  * 
  * Note: To enable instant preview, we have to actually write a bit of custom
  *  javascript. See live_preview() for more.
  *  
  * @see add_action('customize_register',$func)
  * @param \WP_Customize_Manager $wp_customize
  * @link http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/
  * @since ProGo 0.4
  */
 public static function register($wp_customize)
 {
     // Page Layout Settings
     $wp_customize->add_section('pgb_options[layout]', array('title' => 'ProGo Layout and Options', 'priority' => 10, 'description' => ''));
     $wp_customize->add_setting('pgb_options[container_width]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_container_width')));
     $wp_customize->add_setting('pgb_options[bootstrap_theme]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_bootstrap_theme')));
     $wp_customize->add_control('pgb_options[container_width]', array('label' => __('Page Container Width', 'pgb'), 'section' => 'pgb_options[layout]', 'settings' => 'pgb_options[container_width]', 'type' => 'select', 'choices' => array('full' => 'Full Width (100%)', '1366' => '1366px', '1240' => '1240px', '1170' => '1170px', '1080' => '1080px', '960' => '960px')));
     $wp_customize->add_control('pgb_options[bootstrap_theme]', array('label' => __('Bootstrap Theme', 'pgb'), 'section' => 'pgb_options[layout]', 'settings' => 'pgb_options[bootstrap_theme]', 'type' => 'select', 'choices' => array('default' => 'Default Bootstrap', 'cerulean' => 'Cerulean', 'cosmo' => 'Cosmo', 'cyborg' => 'Cyborg', 'darkly' => 'Darkly', 'flatly' => 'Flatly', 'journal' => 'Journal', 'lumen' => 'Lumen', 'paper' => 'Paper', 'readable' => 'Readable', 'sandstone' => 'Sandstone', 'simplex' => 'Simplex', 'slate' => 'Slate', 'spacelab' => 'Spacelab', 'superhero' => 'Superhero', 'united' => 'United', 'yeti' => 'Yeti')));
     // Logo Settings
     $wp_customize->add_section('pgb_options[logo]', array('title' => 'Logos', 'priority' => 30, 'description' => ''));
     $wp_customize->add_setting('pgb_options[logo_mobile]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_logo')));
     $wp_customize->add_setting('pgb_options[logo_tablet]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_logo')));
     $wp_customize->add_setting('pgb_options[logo_desktop]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_logo')));
     $wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize, 'pgb_options[logo_mobile]', array('label' => __('Navbar Icon / Mobile Logo', 'pgb'), 'section' => 'pgb_options[logo]', 'settings' => 'pgb_options[logo_mobile]', 'description' => 'Add your logo to the Bootstrap <a href="http://getbootstrap.com/components/#navbar-brand-image" target="_blank">Brand Image</a> position. Displayed on screens under 768px wide.')));
     $wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize, 'pgb_options[logo_tablet]', array('label' => __('Tablet Logo', 'pgb'), 'section' => 'pgb_options[logo]', 'settings' => 'pgb_options[logo_tablet]', 'description' => 'Tablet logo is displayed on screens 768px to 1024px wide.')));
     $wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize, 'pgb_options[logo_desktop]', array('label' => __('Desktop Logo', 'pgb'), 'section' => 'pgb_options[logo]', 'settings' => 'pgb_options[logo_desktop]', 'description' => 'Desktop Logo is displayed on screen above 1024px wide.')));
     // Nav Settings
     $wp_customize->add_setting('pgb_options[menu_align]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_menu_align')));
     $wp_customize->add_setting('pgb_options[nav_position]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_nav_position')));
     $wp_customize->add_setting('pgb_options[nav_search]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_nav_search')));
     $wp_customize->add_setting('pgb_options[show_breadcrumb]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_show_breadcrumb')));
     $wp_customize->add_setting('pgb_options[login_link_nav_position]', array('default' => array(), 'type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_array')));
     $wp_customize->add_setting('pgb_options[login_link_page]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_nav_position')));
     $wp_customize->add_setting('pgb_options[login_redirect_page]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_nav_position')));
     $wp_customize->add_control('pgb_options[menu_align]', array('label' => __('Main Menu Alignment', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[menu_align]', 'type' => 'radio', 'choices' => array('right' => 'Right', 'left' => 'Left')));
     $wp_customize->add_control('pgb_options[nav_position]', array('label' => __('Main Navbar Position', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[nav_position]', 'type' => 'radio', 'choices' => array('static' => 'Static', 'fixed' => 'Fixed')));
     $wp_customize->add_control('pgb_options[nav_search]', array('label' => __('Show Search in Main Navbar', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[nav_search]', 'type' => 'checkbox', 'value' => 1, 'description' => 'Adds search field to the far right of the navbar'));
     $wp_customize->add_control('pgb_options[show_breadcrumb]', array('label' => __('Include Breadcrumbs', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[show_breadcrumb]', 'type' => 'checkbox', 'value' => 1));
     $wp_customize->add_control(new PGB_Customize_Multiple_Select_Control($wp_customize, 'pgb_options[login_link_nav_position]', array('label' => __('Show Login Link in Navbar(s)', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[login_link_nav_position]', 'type' => 'multiple-select', 'description' => 'Hold CTRL and click to select or deselect multiple options. Select "none" to disable.', 'choices' => array('-- none --') + get_registered_nav_menus())));
     $wp_customize->add_control('pgb_options[login_link_page]', array('label' => __('Set Login Form Page', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[login_link_page]', 'type' => 'select', 'choices' => array(0 => '* WordPress Default') + pgb_get_pages_by_id()));
     $wp_customize->add_control('pgb_options[login_redirect_page]', array('label' => __('Set Login Redirect Page', 'pgb'), 'section' => 'nav', 'settings' => 'pgb_options[login_redirect_page]', 'type' => 'select', 'description' => '', 'choices' => array(get_option('page_on_front') => '* Front Page') + pgb_get_pages_by_id()));
     // Footer Settings
     $wp_customize->add_section('pgb_options[footer]', array('title' => 'Footer', 'priority' => 130, 'description' => ''));
     $wp_customize->add_setting('pgb_options[footer_show]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_footer_show')));
     $wp_customize->add_setting('pgb_options[footer_columns]', array('type' => 'theme_mod', 'capability' => 'edit_theme_options', 'transport' => 'refresh', 'sanitize_callback' => array('ProGo_Customize', 'sanitize_footer_columns')));
     $wp_customize->add_control('pgb_options[footer_show]', array('label' => __('Show Footer Widgets', 'pgb'), 'section' => 'pgb_options[footer]', 'settings' => 'pgb_options[footer_show]', 'type' => 'checkbox', 'value' => '1'));
     $wp_customize->add_control('pgb_options[footer_columns]', array('label' => __('Number of Columns', 'pgb'), 'section' => 'pgb_options[footer]', 'settings' => 'pgb_options[footer_columns]', 'type' => 'select', 'choices' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4')));
 }
    /**
     * Start the element output.
     *
     * @see Walker_Nav_Menu::start_el()
     * @since 3.0.0
     *
     * @global int $_wp_nav_menu_max_depth
     *
     * @param string $output Passed by reference. Used to append additional content.
     * @param object $item   Menu item data object.
     * @param int    $depth  Depth of menu item. Used for padding.
     * @param array  $args   Not used.
     * @param int    $id     Not used.
     */
    public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
    {
        global $_wp_nav_menu_max_depth;
        $_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
        ob_start();
        $item_id = esc_attr($item->ID);
        $removed_args = array('action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce');
        $original_title = '';
        if ('taxonomy' == $item->type) {
            $original_title = get_term_field('name', $item->object_id, $item->object, 'raw');
            if (is_wp_error($original_title)) {
                $original_title = false;
            }
        } elseif ('post_type' == $item->type) {
            $original_object = get_post($item->object_id);
            $original_title = get_the_title($original_object->ID);
        }
        $classes = array('menu-item menu-item-depth-' . $depth, 'menu-item-' . esc_attr($item->object), 'menu-item-edit-' . (isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ? 'active' : 'inactive'));
        $title = $item->title;
        if (!empty($item->_invalid)) {
            $classes[] = 'menu-item-invalid';
            /* translators: %s: title of menu item which is invalid */
            $title = sprintf(__('%s (Invalid)'), $item->title);
        } elseif (isset($item->post_status) && 'draft' == $item->post_status) {
            $classes[] = 'pending';
            /* translators: %s: title of menu item in draft status */
            $title = sprintf(__('%s (Pending)'), $item->title);
        }
        $title = !isset($item->label) || '' == $item->label ? $title : $item->label;
        $submenu_text = '';
        if (0 == $depth) {
            $submenu_text = 'style="display: none;"';
        }
        ?>
		<li id="menu-item-<?php 
        echo $item_id;
        ?>
" class="<?php 
        echo implode(' ', $classes);
        ?>
">
			<div class="menu-item-bar">
				<div class="menu-item-handle">
					<span class="item-title"><span class="menu-item-title"><?php 
        echo esc_html($title);
        ?>
</span> <span class="is-submenu" <?php 
        echo $submenu_text;
        ?>
><?php 
        _e('sub item');
        ?>
</span></span>
					<span class="item-controls">
						<span class="item-type"><?php 
        echo esc_html($item->type_label);
        ?>
</span>
						<span class="item-order hide-if-js">
							<a href="<?php 
        echo wp_nonce_url(add_query_arg(array('action' => 'move-up-menu-item', 'menu-item' => $item_id), remove_query_arg($removed_args, admin_url('nav-menus.php'))), 'move-menu_item');
        ?>
" class="item-move-up"><abbr title="<?php 
        esc_attr_e('Move up');
        ?>
">&#8593;</abbr></a>
							|
							<a href="<?php 
        echo wp_nonce_url(add_query_arg(array('action' => 'move-down-menu-item', 'menu-item' => $item_id), remove_query_arg($removed_args, admin_url('nav-menus.php'))), 'move-menu_item');
        ?>
" class="item-move-down"><abbr title="<?php 
        esc_attr_e('Move down');
        ?>
">&#8595;</abbr></a>
						</span>
						<a class="item-edit" id="edit-<?php 
        echo $item_id;
        ?>
" title="<?php 
        esc_attr_e('Edit Menu Item');
        ?>
" href="<?php 
        echo isset($_GET['edit-menu-item']) && $item_id == $_GET['edit-menu-item'] ? admin_url('nav-menus.php') : add_query_arg('edit-menu-item', $item_id, remove_query_arg($removed_args, admin_url('nav-menus.php#menu-item-settings-' . $item_id)));
        ?>
"><?php 
        _e('Edit Menu Item');
        ?>
</a>
					</span>
				</div>
			</div>

			<div class="menu-item-settings" id="menu-item-settings-<?php 
        echo $item_id;
        ?>
">
				<?php 
        if ('custom' == $item->type && (strpos($item->post_name, 'login') === false && 'Login' !== $item->post_title)) {
            ?>
					<p class="field-url description description-wide">
						<label for="edit-menu-item-url-<?php 
            echo $item_id;
            ?>
">
							<?php 
            _e('URL');
            ?>
<br />
							<input type="text" id="edit-menu-item-url-<?php 
            echo $item_id;
            ?>
" class="widefat code edit-menu-item-url" name="menu-item-url[<?php 
            echo $item_id;
            ?>
]" value="<?php 
            echo esc_attr($item->url);
            ?>
" />
						</label>
					</p>
				<?php 
        } elseif ('custom' == $item->type && (strpos($item->post_name, 'login') === 0 || 'Login' === $item->post_title)) {
            ?>
					<?php 
            $pages = pgb_get_pages_by_id();
            ?>
					<p class="field-custom description description-wide">
						<label for="edit-menu-item-url-<?php 
            echo $item_id;
            ?>
">
							<?php 
            _e('Login Page URL');
            ?>
<br />
							<select id="edit-menu-item-url-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-url" name="menu-item-url[<?php 
            echo $item_id;
            ?>
]">
								<option value="<?php 
            echo wp_login_url();
            ?>
">-- WordPress Default --</option>
								<?php 
            foreach ($pages as $page_id => $page) {
                ?>
									<option value="<?php 
                echo get_permalink($page_id);
                ?>
" <?php 
                echo esc_attr($item->url) == get_permalink($page_id) ? 'selected="selected"' : '';
                ?>
><?php 
                echo $page;
                ?>
</option>
								<?php 
            }
            ?>
							</select>
						</label>
					</p>
					<p class="field-custom description description-wide">
						<label for="edit-menu-item-logoutpage-<?php 
            echo $item_id;
            ?>
">
							<?php 
            _e('Logout Redirect Page');
            ?>
<br />
							<select id="edit-menu-item-logoutpage-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-logoutpage" name="menu-item-logoutpage[<?php 
            echo $item_id;
            ?>
]">
								<option value="<?php 
            echo get_bloginfo('url');
            ?>
">-- WordPress Home --</option>
								<?php 
            foreach ($pages as $page_id => $page) {
                ?>
									<option value="<?php 
                echo get_permalink($page_id);
                ?>
" <?php 
                echo esc_attr($item->logoutpage) == get_permalink($page_id) ? 'selected="selected"' : '';
                ?>
><?php 
                echo $page;
                ?>
</option>
								<?php 
            }
            ?>
							</select>
						</label>
					</p>
				<?php 
        }
        ?>
				<?php 
        if ('custom' == $item->type && (strpos($item->post_name, 'login') === 0 || 'Login' === $item->post_title)) {
            ?>
					<p class="description description-wide">
						<label for="edit-menu-item-title-<?php 
            echo $item_id;
            ?>
">
							<?php 
            _e('Navigation Label - Login');
            ?>
<br />
							<input type="text" id="edit-menu-item-title-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-title" name="menu-item-title[<?php 
            echo $item_id;
            ?>
]" value="<?php 
            echo esc_attr($item->title);
            ?>
" />
						</label>
					</p>
					<p class="description description-wide">
						<label for="edit-menu-item-logouttext-<?php 
            echo $item_id;
            ?>
">
							<?php 
            _e('Navigation Label - Logout');
            ?>
<br />
							<input type="text" id="edit-menu-item-logouttext-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-logouttext" name="menu-item-logouttext[<?php 
            echo $item_id;
            ?>
]" value="<?php 
            echo esc_attr($item->logouttext);
            ?>
" />
						</label>
					</p>
				<?php 
        } else {
            ?>
					<p class="description description-wide">
						<label for="edit-menu-item-title-<?php 
            echo $item_id;
            ?>
">
							<?php 
            _e('Navigation Label');
            ?>
<br />
							<input type="text" id="edit-menu-item-title-<?php 
            echo $item_id;
            ?>
" class="widefat edit-menu-item-title" name="menu-item-title[<?php 
            echo $item_id;
            ?>
]" value="<?php 
            echo esc_attr($item->title);
            ?>
" />
						</label>
					</p>
				<?php 
        }
        ?>
				<p class="field-title-attribute description description-wide">
					<label for="edit-menu-item-attr-title-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Title Attribute');
        ?>
<br />
						<input type="text" id="edit-menu-item-attr-title-<?php 
        echo $item_id;
        ?>
" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->post_excerpt);
        ?>
" />
					</label>
				</p>
				<p class="field-link-target description">
					<label for="edit-menu-item-target-<?php 
        echo $item_id;
        ?>
">
						<input type="checkbox" id="edit-menu-item-target-<?php 
        echo $item_id;
        ?>
" value="_blank" name="menu-item-target[<?php 
        echo $item_id;
        ?>
]"<?php 
        checked($item->target, '_blank');
        ?>
 />
						<?php 
        _e('Open link in a new window/tab');
        ?>
					</label>
				</p>
				<p class="field-css-classes description description-thin">
					<label for="edit-menu-item-classes-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('CSS Classes (optional)');
        ?>
<br />
						<input type="text" id="edit-menu-item-classes-<?php 
        echo $item_id;
        ?>
" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr(implode(' ', $item->classes));
        ?>
" />
					</label>
				</p>
				<p class="field-xfn description description-thin">
					<label for="edit-menu-item-xfn-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Link Relationship (XFN)');
        ?>
<br />
						<input type="text" id="edit-menu-item-xfn-<?php 
        echo $item_id;
        ?>
" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->xfn);
        ?>
" />
					</label>
				</p>
				<p class="field-description description description-wide">
					<label for="edit-menu-item-description-<?php 
        echo $item_id;
        ?>
">
						<?php 
        _e('Description');
        ?>
<br />
						<textarea id="edit-menu-item-description-<?php 
        echo $item_id;
        ?>
" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php 
        echo $item_id;
        ?>
]"><?php 
        echo esc_html($item->description);
        // textarea_escaped
        ?>
</textarea>
						<span class="description"><?php 
        _e('The description will be displayed in the menu if the current theme supports it.');
        ?>
</span>
					</label>
				</p>


				<p class="field-move hide-if-no-js description description-wide">
					<label>
						<span><?php 
        _e('Move');
        ?>
</span>
						<a href="#" class="menus-move menus-move-up" data-dir="up"><?php 
        _e('Up one');
        ?>
</a>
						<a href="#" class="menus-move menus-move-down" data-dir="down"><?php 
        _e('Down one');
        ?>
</a>
						<a href="#" class="menus-move menus-move-left" data-dir="left"></a>
						<a href="#" class="menus-move menus-move-right" data-dir="right"></a>
						<a href="#" class="menus-move menus-move-top" data-dir="top"><?php 
        _e('To the top');
        ?>
</a>
					</label>
				</p>

				<div class="menu-item-actions description-wide submitbox">
					<?php 
        if ('custom' != $item->type && $original_title !== false) {
            ?>
						<p class="link-to-original">
							<?php 
            printf(__('Original: %s'), '<a href="' . esc_attr($item->url) . '">' . esc_html($original_title) . '</a>');
            ?>
						</p>
					<?php 
        }
        ?>
					<a class="item-delete submitdelete deletion" id="delete-<?php 
        echo $item_id;
        ?>
" href="<?php 
        echo wp_nonce_url(add_query_arg(array('action' => 'delete-menu-item', 'menu-item' => $item_id), admin_url('nav-menus.php')), 'delete-menu_item_' . $item_id);
        ?>
"><?php 
        _e('Remove');
        ?>
</a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php 
        echo $item_id;
        ?>
" href="<?php 
        echo esc_url(add_query_arg(array('edit-menu-item' => $item_id, 'cancel' => time()), admin_url('nav-menus.php')));
        ?>
#menu-item-settings-<?php 
        echo $item_id;
        ?>
"><?php 
        _e('Cancel');
        ?>
</a>
				</div>

				<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo $item_id;
        ?>
" />
				<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->object_id);
        ?>
" />
				<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->object);
        ?>
" />
				<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->menu_item_parent);
        ?>
" />
				<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->menu_order);
        ?>
" />
				<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php 
        echo $item_id;
        ?>
]" value="<?php 
        echo esc_attr($item->type);
        ?>
" />
			</div><!-- .menu-item-settings-->
			<ul class="menu-item-transport"></ul>
		<?php 
        $output .= ob_get_clean();
    }