Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryJones committed Nov 12, 2014
2 parents a5503ad + 314180f commit a6e84aa
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 68 deletions.
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The default method of getting a menu to appear in the top right of a site using

> "_I can't think of any good reason to use an aside in a header... what the hell would it be contextually related to? The logo? lol_" - **Robert Neu**
This plugin registers a new menu location called Header and, if a menu is assigned to it, displays it before the Header Right area. If you don't have any widgets in the Header Right area, then Genesis ensures that none of that widget area markup is output, so you end up with code like screenshot 2. If you do want a widget in the Header Right area, that's fine - it can be positioned and styled as you want, without negatively affecting the navigation menu as well.
This plugin registers a new menu location called Header and, if a menu is assigned to it, displays it after the Header Right area. If you don't have any widgets in the Header Right area, then Genesis ensures that none of that widget area markup is output, so you end up with code like screenshot 2. If you do want a widget in the Header Right area, that's fine - it can be positioned and styled as you want, without negatively affecting the navigation menu as well.

## Screenshots

Expand All @@ -24,7 +24,8 @@ _Screenshot 1: Markup using Custom Menu widget. Note the `aside`, `section` and
_Screenshot 2: Markup using this plugin. `nav` is a sibling element to the title area `div`._

## Requirements
* WordPress 3.0+
* PHP 5.3+
* WordPress 3.9+
* Genesis 2.1+

## Installation
Expand Down Expand Up @@ -65,6 +66,10 @@ Once activated, head to Appearance -> Menus. Create a menu as usual, and assign

The hook that filters the menu was called `genesis_do_header_nav` but is now called `genesis_header_nav` due to using the `genesis_header_nav()` function in Genesis 2.1.

**2.0.0:** Custom language files previously loaded from (example) `WP_LANG_DIR . '/genesis-header-nav/genesis-header-nav-en_GB.po'` now need to be placed at `WP_LANG_DIR . '/plugins/genesis-header-nav-en_GB.po'`, as per language packs.

**2.0.0:** This plugin uses PHP namespaces, so you'll need PHP 5.3+ powering your site.

## Customising

### CSS
Expand All @@ -83,14 +88,21 @@ Adjust the width as needed to allow enough space for your title area and menu it

### Priority

The plugin includes a `genesis_header_nav_priority` filter, with a default value of 12. Use a value of 6-9 to add the nav before the title + widget area, or 11-14 to add it after. If you want to add it in between, you'll need to remove and re-build `genesis_do_header()` function so that the output of the widget area is in a different function that can be hooked to a later priority.
The plugin includes a `genesis_header_nav_priority` filter, with a default value of `12`. Use the following values to reposition the nav accordingly:

* Before the `<header>` element, inside the `.site-container`: 0-4
* Before the title + widget area: 5-9
* After the title + widget area: 10-14
* After the `<header>` element: 15+

If you want to add it in between the title and widget area, you'll need to unhook and re-build `genesis_do_header()` function so that the output of the widget area is in a different function that can be hooked to a later priority.

To add the nav before the title + widget area markup in the source, you can use the following:
As an example, to add the nav before the title + widget area markup in the source, you can use the following:

~~~php
add_filter( 'genesis_header_nav_priority', 'prefix_genesis_header_nav_priority' );
/**
* Change the order of the nav within the header (Genesis Header Nav plugin)
* Change the order of the nav within the header (Genesis Header Nav plugin).
*
* @param int $priority Existing priority. Default is 12.
*
Expand Down Expand Up @@ -126,8 +138,14 @@ function prefix_genesis_header_nav_name( $translated_text, $original_text, $doma
If you want the menu to not display, perhaps on a landing page, then you can do the following:

~~~php
if ( class_exists( 'Genesis_Header_Nav' ) ) {
remove_action( 'genesis_header', array( Genesis_Header_Nav::get_instance(), 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
add_action( 'init', 'prefix_genesis_header_nav_remove', 11 );
/**
* Remove Genesis Header Nav menu.
*/
function prefix_genesis_header_nav_remove() {
if ( function_exists( 'Gamajo\GenesisHeaderNav\get_plugin' ) ) {
remove_action( 'genesis_header', array( Gamajo\GenesisHeaderNav\get_plugin(), 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
}
}
~~~

Expand Down
47 changes: 39 additions & 8 deletions genesis-header-nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
/**
* Genesis Header Nav
*
* @package GenesisHeaderNav
* @author Gary Jones <[email protected]>
* @package Genesis_Header_Nav
* @author Gary Jones
* @license GPL-2.0+
* @link https://github.com/GaryJones/genesis-header-nav
* @copyright 2013 Gary Jones, Gamajo Tech
Expand All @@ -12,7 +12,7 @@
* Plugin Name: Genesis Header Nav
* Plugin URI: https://github.com/GaryJones/genesis-header-nav
* Description: Registers a menu location and displays it inside the header for a Genesis Framework child theme.
* Version: 1.3.1
* Version: 2.0.0
* Author: Gary Jones
* Author URI: http://gamajo.com/
* Text Domain: genesis-header-nav
Expand All @@ -23,19 +23,50 @@
* GitHub Branch: master
*/

namespace Gamajo\GenesisHeaderNav;

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}

require_once plugin_dir_path( __FILE__ ) . 'class-genesis-header-nav.php';
// Main class file.
require_once plugin_dir_path( __FILE__ ) . 'includes/class-genesis-header-nav.php';

/**
* Get plugin object.
*
* Instantiates it if necessary.
*
* @since 2.0.0
*
* @return Gamajo\GenesisHeaderNav\Plugin
*/
function get_plugin() {
static $plugin = NULL;
if ( is_null( $plugin ) ) {
$plugin = new Plugin;
}
return $plugin;
}

add_action( 'plugins_loaded', __NAMESPACE__ . '\\genesis_header_nav_i18n' );
/**
* Load Genesis Header Nav plugin text domain.
*
* @since 2.0.0
*/
function genesis_header_nav_i18n() {
load_plugin_textdomain( 'genesis-header-nav', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}

add_action( 'after_setup_theme', 'genesis_header_nav_run' );
add_action( 'after_setup_theme', __NAMESPACE__ . '\\genesis_header_nav_run' );
/**
* Run the plugin.
* Run Genesis Header Nav plugin.
*
* @since 1.3.1
* @since 2.0.0
*/
function genesis_header_nav_run() {
Genesis_Header_Nav::get_instance();
$plugin = get_plugin();
$plugin->run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@
/**
* Genesis Header Nav
*
* @package GenesisHeaderNav
* @author Gary Jones <[email protected]>
* @package Genesis_Header_Nav
* @author Gary Jones
* @license GPL-2.0+
* @link https://github.com/GaryJones/genesis-header-nav
* @copyright 2013 Gary Jones, Gamajo Tech
*/

namespace Gamajo\GenesisHeaderNav;

/**
* Plugin class.
*
* @package GenesisHeaderNav
* @author Gary Jones <[email protected]>
* @package Genesis_Header_Nav
* @author Gary Jones
*/
class Genesis_Header_Nav {

/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;

class Plugin {
/**
* Initialize the plugin by setting localization, filters, and administration functions.
*
Expand All @@ -35,49 +27,19 @@ class Genesis_Header_Nav {
*
* @since 1.0.0
*/
private function __construct() {
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
public function run() {
add_action( 'init', array( $this, 'register_nav_menu' ) );
add_action( 'genesis_header', array( $this, 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
add_filter( 'body_class', array( $this, 'body_classes' ), 15 );
}

/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}

return self::$instance;
}

/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
$domain = 'genesis-header-nav';
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );

load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages' );
}

/**
* Register the menu location.
*
* @since 1.0.0
*/
public function register_nav_menu() {
register_nav_menus( array( 'header' => __( 'Header', 'genesis-header-nav' ) ) );
register_nav_menu( 'header', __( 'Header', 'genesis-header-nav' ) );
}

/**
Expand Down Expand Up @@ -129,5 +91,4 @@ public function body_classes( array $classes ) {

return $classes;
}

}
10 changes: 5 additions & 5 deletions languages/genesis-header-nav.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# This file is distributed under the GPL-2.0+.
msgid ""
msgstr ""
"Project-Id-Version: Genesis Header Nav v1.3.0\n"
"POT-Creation-Date: 2014-10-30 00:13:00+0000\n"
"PO-Revision-Date: 2014-10-30 00:13:00+0000\n"
"Project-Id-Version: Genesis Header Nav v2.0.0\n"
"POT-Creation-Date: 2014-11-12 22:13:00+0000\n"
"PO-Revision-Date: 2014-11-12 22:13:00+0000\n"
"Report-Msgid-Bugs-To: https://github.com/GaryJones/genesis-header-nav/issues \n"
"Last-Translator: Gary Jones <[email protected]>\n"
"Last-Translator: Gary Jones\n"
"Language-Team: English https://github.com/GaryJones/genesis-header-nav \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand All @@ -22,6 +22,6 @@ msgstr ""
"X-Poedit-SearchPath-0: .\n"
"X-Textdomain-Support: yes"

#: class-genesis-header-nav.php:76
#: includes/class-genesis-header-nav.php:42
msgid "Header"
msgstr ""

0 comments on commit a6e84aa

Please sign in to comment.