| @@ -6,12 +6,12 @@ | ||
| 6 | 6 | Author: Takayuki Miyoshi |
| 7 | 7 | Author URI: http://ideasilo.wordpress.com/ |
| 8 | 8 | Text Domain: bogo |
| 9 | 9 | Domain Path: /languages/ |
| 10 | -Version: 2.9 | |
| 10 | +Version: 2.6 | |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | -define( 'BOGO_VERSION', '2.9' ); | |
| 13 | +define( 'BOGO_VERSION', '2.6' ); | |
| 14 | 14 | |
| 15 | 15 | define( 'BOGO_PLUGIN', __FILE__ ); |
| 16 | 16 | |
| 17 | 17 | define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) ); |
| @@ -20,12 +20,10 @@ | ||
| 20 | 20 | |
| 21 | 21 | define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) ); |
| 22 | 22 | |
| 23 | 23 | require_once BOGO_PLUGIN_DIR . '/includes/functions.php'; |
| 24 | -require_once BOGO_PLUGIN_DIR . '/includes/pomo.php'; | |
| 25 | 24 | require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 26 | 25 | require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 27 | -require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php'; | |
| 28 | 26 | require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php'; |
| 29 | 27 | require_once BOGO_PLUGIN_DIR . '/includes/widgets.php'; |
| 30 | 28 | require_once BOGO_PLUGIN_DIR . '/includes/post.php'; |
| 31 | 29 | require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| @@ -31,9 +29,8 @@ | ||
| 31 | 29 | require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| 32 | 30 | require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; |
| 33 | 31 | require_once BOGO_PLUGIN_DIR . '/includes/query.php'; |
| 34 | 32 | require_once BOGO_PLUGIN_DIR . '/includes/flags.php'; |
| 35 | -require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php'; | |
| 36 | 33 | |
| 37 | 34 | if ( is_admin() ) { |
| 38 | 35 | require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; |
| 39 | 36 | } |
| @@ -47,16 +44,14 @@ | ||
| 47 | 44 | add_action( 'init', 'bogo_init' ); |
| 48 | 45 | |
| 49 | 46 | function bogo_init() { |
| 50 | 47 | bogo_languages(); |
| 51 | - Bogo_POMO::import( get_locale() ); | |
| 52 | 48 | |
| 53 | 49 | if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { |
| 54 | 50 | $locale = get_locale(); |
| 55 | 51 | |
| 56 | - if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) { | |
| 52 | + if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) | |
| 57 | 53 | setcookie( 'lang', $locale, 0, '/' ); |
| 58 | - } | |
| 59 | 54 | } |
| 60 | 55 | } |
| 61 | 56 | |
| 62 | 57 | add_filter( 'locale', 'bogo_locale' ); |
| @@ -63,31 +58,21 @@ | ||
| 63 | 58 | |
| 64 | 59 | function bogo_locale( $locale ) { |
| 65 | 60 | global $wp_rewrite, $wp_query; |
| 66 | 61 | |
| 67 | - if ( ! did_action( 'plugins_loaded' ) ) { | |
| 62 | + if ( ! did_action( 'plugins_loaded' ) ) | |
| 68 | 63 | return $locale; |
| 69 | - } | |
| 70 | 64 | |
| 71 | - static $bogo_locale = ''; | |
| 65 | + if ( is_admin() ) | |
| 66 | + return bogo_get_user_locale(); | |
| 72 | 67 | |
| 73 | - if ( $bogo_locale ) { | |
| 74 | - return $bogo_locale; | |
| 75 | - } | |
| 76 | - | |
| 77 | - if ( is_admin() ) { | |
| 78 | - return $bogo_locale = bogo_get_user_locale(); | |
| 79 | - } | |
| 80 | - | |
| 81 | 68 | $default_locale = bogo_get_default_locale(); |
| 82 | 69 | |
| 83 | 70 | if ( ! empty( $wp_query->query_vars ) ) { |
| 84 | - if ( ( $lang = get_query_var( 'lang' ) ) | |
| 85 | - && $closest = bogo_get_closest_locale( $lang ) ) { | |
| 86 | - return $bogo_locale = $closest; | |
| 87 | - } else { | |
| 88 | - return $bogo_locale = $default_locale; | |
| 89 | - } | |
| 71 | + if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) ) | |
| 72 | + return $closest; | |
| 73 | + else | |
| 74 | + return $default_locale; | |
| 90 | 75 | } |
| 91 | 76 | |
| 92 | 77 | if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { |
| 93 | 78 | $url = is_ssl() ? 'https://' : 'http://'; |
| @@ -96,26 +81,26 @@ | ||
| 96 | 81 | |
| 97 | 82 | $home = set_url_scheme( get_option( 'home' ) ); |
| 98 | 83 | $home = trailingslashit( $home ); |
| 99 | 84 | |
| 100 | - $available_locales = bogo_available_locales(); | |
| 101 | - $available_locales = array_map( 'bogo_lang_slug', $available_locales ); | |
| 102 | - $available_locales = implode( '|', $available_locales ); | |
| 103 | - $pattern = '#^' . preg_quote( $home ) . '(' . $available_locales . ')(/|$)#'; | |
| 85 | + $available_languages = bogo_available_languages(); | |
| 86 | + $available_languages = array_map( 'bogo_lang_slug', array_keys( $available_languages ) ); | |
| 87 | + $available_languages = implode( '|', $available_languages ); | |
| 88 | + $pattern = '#^' . preg_quote( $home ) . '(' . $available_languages . ')(/|$)#'; | |
| 104 | 89 | |
| 105 | 90 | if ( preg_match( $pattern, $url, $matches ) |
| 106 | - && $closest = bogo_get_closest_locale( $matches[1] ) ) { | |
| 107 | - return $bogo_locale = $closest; | |
| 108 | - } | |
| 91 | + && $closest = bogo_get_closest_locale( $matches[1] ) ) | |
| 92 | + return $closest; | |
| 109 | 93 | } |
| 110 | 94 | |
| 111 | 95 | $lang = bogo_get_lang_from_url(); |
| 112 | 96 | |
| 113 | - if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) { | |
| 114 | - return $bogo_locale = $closest; | |
| 115 | - } | |
| 97 | + if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) | |
| 98 | + return $closest; | |
| 116 | 99 | |
| 117 | - return $bogo_locale = $default_locale; | |
| 100 | + $locale = $default_locale; | |
| 101 | + | |
| 102 | + return $locale; | |
| 118 | 103 | } |
| 119 | 104 | |
| 120 | 105 | add_filter( 'query_vars', 'bogo_query_vars' ); |
| 121 | 106 | |
| @@ -123,8 +108,10 @@ | ||
| 123 | 108 | $query_vars[] = 'lang'; |
| 124 | 109 | |
| 125 | 110 | return $query_vars; |
| 126 | 111 | } |
| 112 | + | |
| 113 | +add_shortcode( 'bogo', 'bogo_language_switcher' ); | |
| 127 | 114 | |
| 128 | 115 | add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' ); |
| 129 | 116 | |
| 130 | 117 | function bogo_enqueue_scripts() { |