Skip to content

Commit a6e84aa

Browse files
committed
Merge branch 'release/2.0.0'
2 parents a5503ad + 314180f commit a6e84aa

File tree

4 files changed

+78
-68
lines changed

4 files changed

+78
-68
lines changed

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The default method of getting a menu to appear in the top right of a site using
1111

1212
> "_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**
1313
14-
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.
14+
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.
1515

1616
## Screenshots
1717

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

2626
## Requirements
27-
* WordPress 3.0+
27+
* PHP 5.3+
28+
* WordPress 3.9+
2829
* Genesis 2.1+
2930

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

6667
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.
6768

69+
**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.
70+
71+
**2.0.0:** This plugin uses PHP namespaces, so you'll need PHP 5.3+ powering your site.
72+
6873
## Customising
6974

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

8489
### Priority
8590

86-
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.
91+
The plugin includes a `genesis_header_nav_priority` filter, with a default value of `12`. Use the following values to reposition the nav accordingly:
92+
93+
* Before the `<header>` element, inside the `.site-container`: 0-4
94+
* Before the title + widget area: 5-9
95+
* After the title + widget area: 10-14
96+
* After the `<header>` element: 15+
97+
98+
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.
8799

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

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

128140
~~~php
129-
if ( class_exists( 'Genesis_Header_Nav' ) ) {
130-
remove_action( 'genesis_header', array( Genesis_Header_Nav::get_instance(), 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
141+
add_action( 'init', 'prefix_genesis_header_nav_remove', 11 );
142+
/**
143+
* Remove Genesis Header Nav menu.
144+
*/
145+
function prefix_genesis_header_nav_remove() {
146+
if ( function_exists( 'Gamajo\GenesisHeaderNav\get_plugin' ) ) {
147+
remove_action( 'genesis_header', array( Gamajo\GenesisHeaderNav\get_plugin(), 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
148+
}
131149
}
132150
~~~
133151

genesis-header-nav.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/**
33
* Genesis Header Nav
44
*
5-
* @package GenesisHeaderNav
6-
* @author Gary Jones <gary@garyjones.co.uk>
5+
* @package Genesis_Header_Nav
6+
* @author Gary Jones
77
* @license GPL-2.0+
88
* @link https://github.com/GaryJones/genesis-header-nav
99
* @copyright 2013 Gary Jones, Gamajo Tech
@@ -12,7 +12,7 @@
1212
* Plugin Name: Genesis Header Nav
1313
* Plugin URI: https://github.com/GaryJones/genesis-header-nav
1414
* Description: Registers a menu location and displays it inside the header for a Genesis Framework child theme.
15-
* Version: 1.3.1
15+
* Version: 2.0.0
1616
* Author: Gary Jones
1717
* Author URI: http://gamajo.com/
1818
* Text Domain: genesis-header-nav
@@ -23,19 +23,50 @@
2323
* GitHub Branch: master
2424
*/
2525

26+
namespace Gamajo\GenesisHeaderNav;
27+
2628
// If this file is called directly, abort.
2729
if ( ! defined( 'WPINC' ) ) {
2830
die;
2931
}
3032

31-
require_once plugin_dir_path( __FILE__ ) . 'class-genesis-header-nav.php';
33+
// Main class file.
34+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-genesis-header-nav.php';
35+
36+
/**
37+
* Get plugin object.
38+
*
39+
* Instantiates it if necessary.
40+
*
41+
* @since 2.0.0
42+
*
43+
* @return Gamajo\GenesisHeaderNav\Plugin
44+
*/
45+
function get_plugin() {
46+
static $plugin = NULL;
47+
if ( is_null( $plugin ) ) {
48+
$plugin = new Plugin;
49+
}
50+
return $plugin;
51+
}
52+
53+
add_action( 'plugins_loaded', __NAMESPACE__ . '\\genesis_header_nav_i18n' );
54+
/**
55+
* Load Genesis Header Nav plugin text domain.
56+
*
57+
* @since 2.0.0
58+
*/
59+
function genesis_header_nav_i18n() {
60+
load_plugin_textdomain( 'genesis-header-nav', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
61+
}
3262

33-
add_action( 'after_setup_theme', 'genesis_header_nav_run' );
63+
add_action( 'after_setup_theme', __NAMESPACE__ . '\\genesis_header_nav_run' );
3464
/**
35-
* Run the plugin.
65+
* Run Genesis Header Nav plugin.
3666
*
37-
* @since 1.3.1
67+
* @since 2.0.0
3868
*/
3969
function genesis_header_nav_run() {
40-
Genesis_Header_Nav::get_instance();
70+
$plugin = get_plugin();
71+
$plugin->run();
4172
}

class-genesis-header-nav.php renamed to includes/class-genesis-header-nav.php

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,22 @@
22
/**
33
* Genesis Header Nav
44
*
5-
* @package GenesisHeaderNav
6-
* @author Gary Jones <gary@garyjones.co.uk>
5+
* @package Genesis_Header_Nav
6+
* @author Gary Jones
77
* @license GPL-2.0+
88
* @link https://github.com/GaryJones/genesis-header-nav
99
* @copyright 2013 Gary Jones, Gamajo Tech
1010
*/
1111

12+
namespace Gamajo\GenesisHeaderNav;
13+
1214
/**
1315
* Plugin class.
1416
*
15-
* @package GenesisHeaderNav
16-
* @author Gary Jones <gary@garyjones.co.uk>
17+
* @package Genesis_Header_Nav
18+
* @author Gary Jones
1719
*/
18-
class Genesis_Header_Nav {
19-
20-
/**
21-
* Instance of this class.
22-
*
23-
* @since 1.0.0
24-
*
25-
* @var object
26-
*/
27-
protected static $instance = null;
28-
20+
class Plugin {
2921
/**
3022
* Initialize the plugin by setting localization, filters, and administration functions.
3123
*
@@ -35,49 +27,19 @@ class Genesis_Header_Nav {
3527
*
3628
* @since 1.0.0
3729
*/
38-
private function __construct() {
39-
add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) );
30+
public function run() {
4031
add_action( 'init', array( $this, 'register_nav_menu' ) );
4132
add_action( 'genesis_header', array( $this, 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
4233
add_filter( 'body_class', array( $this, 'body_classes' ), 15 );
4334
}
4435

45-
/**
46-
* Return an instance of this class.
47-
*
48-
* @since 1.0.0
49-
*
50-
* @return object A single instance of this class.
51-
*/
52-
public static function get_instance() {
53-
// If the single instance hasn't been set, set it now.
54-
if ( null == self::$instance ) {
55-
self::$instance = new self;
56-
}
57-
58-
return self::$instance;
59-
}
60-
61-
/**
62-
* Load the plugin text domain for translation.
63-
*
64-
* @since 1.0.0
65-
*/
66-
public function load_plugin_textdomain() {
67-
$domain = 'genesis-header-nav';
68-
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
69-
70-
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
71-
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages' );
72-
}
73-
7436
/**
7537
* Register the menu location.
7638
*
7739
* @since 1.0.0
7840
*/
7941
public function register_nav_menu() {
80-
register_nav_menus( array( 'header' => __( 'Header', 'genesis-header-nav' ) ) );
42+
register_nav_menu( 'header', __( 'Header', 'genesis-header-nav' ) );
8143
}
8244

8345
/**
@@ -129,5 +91,4 @@ public function body_classes( array $classes ) {
12991

13092
return $classes;
13193
}
132-
13394
}

languages/genesis-header-nav.pot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# This file is distributed under the GPL-2.0+.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Genesis Header Nav v1.3.0\n"
6-
"POT-Creation-Date: 2014-10-30 00:13:00+0000\n"
7-
"PO-Revision-Date: 2014-10-30 00:13:00+0000\n"
5+
"Project-Id-Version: Genesis Header Nav v2.0.0\n"
6+
"POT-Creation-Date: 2014-11-12 22:13:00+0000\n"
7+
"PO-Revision-Date: 2014-11-12 22:13:00+0000\n"
88
"Report-Msgid-Bugs-To: https://github.com/GaryJones/genesis-header-nav/issues \n"
9-
"Last-Translator: Gary Jones <gary@garyjones.co.uk>\n"
9+
"Last-Translator: Gary Jones\n"
1010
"Language-Team: English https://github.com/GaryJones/genesis-header-nav \n"
1111
"MIME-Version: 1.0\n"
1212
"Content-Type: text/plain; charset=UTF-8\n"
@@ -22,6 +22,6 @@ msgstr ""
2222
"X-Poedit-SearchPath-0: .\n"
2323
"X-Textdomain-Support: yes"
2424

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

0 commit comments

Comments
 (0)