Skip to content

Commit

Permalink
Simplify loading of plugin text domain
Browse files Browse the repository at this point in the history
The `load_plugin_textdomain()` is now a single line, so it doesn't need
to be in a wrapping function or method. It is moved to the
`plugins_loaded` hook, which is considerably earlier than init, so any strings
defined before then (even if not output) will be translatable too.

The removal of the explicit `load_textdomain()` and variables comes from
https://core.trac.wordpress.org/changeset/25059 which automatically
loads (for example)
wp-content/languages/plugins/genesis-header-nav-en_GB.mo instead of
wp-content/languages/genesis-header-nav/genesis-header-nav-en_GB.mo .
This is therefore a backwards compatibility change but one which
supports the upcoming language packs. It bumps the WP requirement
to 3.7. Move any existing custom .mo to the new location for it to work.

The change from `basename( dirname( __FILE__ ) )` back to the more
standard `dirname( plugin_basename( __FILE__ ) )` comes from the fixes
in https://core.trac.wordpress.org/ticket/16953 which make
`plugin_basename()` resolve symlinked plugins. This bumps the requirement
for WP to 3.9.
  • Loading branch information
GaryJones committed Nov 7, 2014
1 parent 37d17a1 commit 35f91f3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _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+
* WordPress 3.9+
* Genesis 2.1+

## Installation
Expand Down
1 change: 1 addition & 0 deletions genesis-header-nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@

function genesis_header_nav() {
global $genesis_header_nav;
load_plugin_textdomain( 'genesis-header-nav', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
$genesis_header_nav->run();
}
14 changes: 0 additions & 14 deletions includes/class-genesis-header-nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,11 @@ class Genesis_Header_Nav {
* @since 1.0.0
*/
public function run() {
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
add_action( 'genesis_setup', array( $this, 'register_nav_menu' ), 15 );
add_action( 'genesis_header', array( $this, 'show_menu' ), apply_filters( 'genesis_header_nav_priority', 12 ) );
add_filter( 'body_class', array( $this, 'body_classes' ), 15 );
}

/**
* 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.
*
Expand Down

0 comments on commit 35f91f3

Please sign in to comment.