Skip to:
Content

bbPress.org

Changeset 6507


Ignore:
Timestamp:
06/09/2017 02:46:51 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Languages: Deprecate custom bbPress /languages/bbpress/ directory.

  • It's still supported if it exists, otherwise it's skipped.
  • Introduce new base property to the bbPress class to help with targeting the global directory.

This results in 1 fewer call to load_textdomain() and 2 fewer if the old directory is not in place.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bbpress.php

    r6498 r6507  
    213213        $this->file       = __FILE__;
    214214        $this->basename   = apply_filters( 'bbp_plugin_basename', str_replace( array( 'build/', 'src/' ), '', plugin_basename( $this->file ) ) );
     215        $this->base_dir   = apply_filters( 'bbp_plugin_base_dir', trailingslashit( dirname( $this->basename ) ) );
    215216
    216217        // Path and URL
     
    223224
    224225        // Languages
     226        $this->lang_base    = apply_filters( 'bbp_lang_base',    trailingslashit( $this->base_dir   . 'languages' ) );
    225227        $this->lang_dir     = apply_filters( 'bbp_lang_dir',     trailingslashit( $this->plugin_dir . 'languages' ) );
    226228
     
    486488    public function load_textdomain() {
    487489
    488         // Traditional WordPress plugin locale filter
    489         $locale        = apply_filters( 'plugin_locale', get_locale(), $this->domain );
    490         $mofile        = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
    491 
    492         // Setup paths to current locale file
    493         $mofile_local  = $this->lang_dir . $mofile;
    494         $mofile_global = WP_LANG_DIR . '/bbpress/' . $mofile;
    495 
    496         // Look in global /wp-content/languages/bbpress folder
    497         load_textdomain( $this->domain, $mofile_global );
    498 
    499         // Look in local /wp-content/plugins/bbpress/languages/ folder
    500         load_textdomain( $this->domain, $mofile_local );
     490        // Define the old directory
     491        $old_dir = WP_LANG_DIR . '/bbpress/';
     492
     493        // Old location, deprecated in 2.6.0
     494        if ( is_dir( $old_dir ) ) {
     495
     496            // Get locale & file-name
     497            $type   = is_admin() ? get_user_locale() : get_locale();
     498            $locale = apply_filters( 'plugin_locale', $type, $this->domain );
     499            $mofile = sprintf( '%1$s-%2$s.mo', $this->domain, $locale );
     500
     501            // Look in global /wp-content/languages/bbpress/ folder
     502            load_textdomain( $this->domain, $old_dir . $mofile );
     503        }
    501504
    502505        // Look in global /wp-content/languages/plugins/
    503         load_plugin_textdomain( $this->domain );
     506        load_plugin_textdomain( $this->domain, false, $this->lang_base );
    504507    }
    505508
Note: See TracChangeset for help on using the changeset viewer.