| @@ -1,19 +1,17 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | - * Plugin Name: Bogo | |
| 4 | - * Description: A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on. | |
| 5 | - * Plugin URI: https://contactform7.com/2025/09/23/multi-language-wordpress-without-vendor-lock-in-risks/ | |
| 6 | - * Author: Rock Lobster Inc. | |
| 7 | - * Author URI: https://github.com/rocklobster-in/ | |
| 8 | - * License: GPL v2 or later | |
| 9 | - * License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
| 10 | - * Version: 3.9.3 | |
| 11 | - * Requires at least: 6.7 | |
| 12 | - * Requires PHP: 7.4 | |
| 13 | - */ | |
| 3 | +Plugin Name: Bogo | |
| 4 | +Description: A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on. | |
| 5 | +Plugin URI: http://ideasilo.wordpress.com/bogo/ | |
| 6 | +Author: Takayuki Miyoshi | |
| 7 | +Author URI: http://ideasilo.wordpress.com/ | |
| 8 | +Text Domain: bogo | |
| 9 | +Domain Path: /languages/ | |
| 10 | +Version: 2.6 | |
| 11 | +*/ | |
| 14 | 12 | |
| 15 | -define( 'BOGO_VERSION', '3.9.3' ); | |
| 13 | +define( 'BOGO_VERSION', '2.6' ); | |
| 16 | 14 | |
| 17 | 15 | define( 'BOGO_PLUGIN', __FILE__ ); |
| 18 | 16 | |
| 19 | 17 | define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) ); |
| @@ -22,15 +20,10 @@ | ||
| 22 | 20 | |
| 23 | 21 | define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) ); |
| 24 | 22 | |
| 25 | 23 | require_once BOGO_PLUGIN_DIR . '/includes/functions.php'; |
| 26 | -require_once BOGO_PLUGIN_DIR . '/includes/language-functions.php'; | |
| 27 | -require_once BOGO_PLUGIN_DIR . '/includes/kses.php'; | |
| 28 | -require_once BOGO_PLUGIN_DIR . '/includes/formatting.php'; | |
| 29 | -require_once BOGO_PLUGIN_DIR . '/includes/pomo.php'; | |
| 30 | 24 | require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 31 | 25 | require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 32 | -require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php'; | |
| 33 | 26 | require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php'; |
| 34 | 27 | require_once BOGO_PLUGIN_DIR . '/includes/widgets.php'; |
| 35 | 28 | require_once BOGO_PLUGIN_DIR . '/includes/post.php'; |
| 36 | 29 | require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| @@ -36,72 +29,53 @@ | ||
| 36 | 29 | require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| 37 | 30 | require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; |
| 38 | 31 | require_once BOGO_PLUGIN_DIR . '/includes/query.php'; |
| 39 | 32 | require_once BOGO_PLUGIN_DIR . '/includes/flags.php'; |
| 40 | -require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php'; | |
| 41 | -require_once BOGO_PLUGIN_DIR . '/includes/shortcodes.php'; | |
| 42 | -require_once BOGO_PLUGIN_DIR . '/includes/block-editor/block-editor.php'; | |
| 43 | 33 | |
| 44 | 34 | if ( is_admin() ) { |
| 45 | 35 | require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; |
| 46 | 36 | } |
| 47 | 37 | |
| 38 | +add_action( 'plugins_loaded', 'bogo_plugins_loaded' ); | |
| 48 | 39 | |
| 49 | -add_action( 'init', 'bogo_init', 10, 0 ); | |
| 40 | +function bogo_plugins_loaded() { | |
| 41 | + load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' ); | |
| 42 | +} | |
| 50 | 43 | |
| 44 | +add_action( 'init', 'bogo_init' ); | |
| 45 | + | |
| 51 | 46 | function bogo_init() { |
| 52 | 47 | bogo_languages(); |
| 53 | - Bogo_POMO::import( determine_locale() ); | |
| 54 | -} | |
| 55 | 48 | |
| 49 | + if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { | |
| 50 | + $locale = get_locale(); | |
| 56 | 51 | |
| 57 | -add_filter( 'pre_determine_locale', 'bogo_pre_determine_locale', 10, 1 ); | |
| 58 | - | |
| 59 | -function bogo_pre_determine_locale( $locale ) { | |
| 60 | - if ( ! empty( $_GET['filter_action'] ) ) { | |
| 61 | - return $locale; | |
| 52 | + if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) | |
| 53 | + setcookie( 'lang', $locale, 0, '/' ); | |
| 62 | 54 | } |
| 63 | - | |
| 64 | - if ( | |
| 65 | - isset( $_GET['lang'] ) and | |
| 66 | - $closest = bogo_get_closest_locale( $_GET['lang'] ) | |
| 67 | - ) { | |
| 68 | - $locale = $closest; | |
| 69 | - } | |
| 70 | - | |
| 71 | - return $locale; | |
| 72 | 55 | } |
| 73 | 56 | |
| 57 | +add_filter( 'locale', 'bogo_locale' ); | |
| 74 | 58 | |
| 75 | -add_filter( 'locale', 'bogo_locale', 10, 1 ); | |
| 76 | - | |
| 77 | 59 | function bogo_locale( $locale ) { |
| 78 | 60 | global $wp_rewrite, $wp_query; |
| 79 | 61 | |
| 80 | - if ( ! did_action( 'plugins_loaded' ) or is_admin() ) { | |
| 62 | + if ( ! did_action( 'plugins_loaded' ) ) | |
| 81 | 63 | return $locale; |
| 82 | - } | |
| 83 | 64 | |
| 84 | - static $bogo_locale = ''; | |
| 65 | + if ( is_admin() ) | |
| 66 | + return bogo_get_user_locale(); | |
| 85 | 67 | |
| 86 | - if ( $bogo_locale ) { | |
| 87 | - return $bogo_locale; | |
| 88 | - } | |
| 89 | - | |
| 90 | 68 | $default_locale = bogo_get_default_locale(); |
| 91 | 69 | |
| 92 | 70 | if ( ! empty( $wp_query->query_vars ) ) { |
| 93 | - if ( | |
| 94 | - $lang = get_query_var( 'lang' ) and | |
| 95 | - $closest = bogo_get_closest_locale( $lang ) | |
| 96 | - ) { | |
| 97 | - return $bogo_locale = $closest; | |
| 98 | - } else { | |
| 99 | - return $bogo_locale = $default_locale; | |
| 100 | - } | |
| 71 | + if ( ( $lang = get_query_var( 'lang' ) ) && $closest = bogo_get_closest_locale( $lang ) ) | |
| 72 | + return $closest; | |
| 73 | + else | |
| 74 | + return $default_locale; | |
| 101 | 75 | } |
| 102 | 76 | |
| 103 | - if ( isset( $wp_rewrite ) and $wp_rewrite->using_permalinks() ) { | |
| 77 | + if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { | |
| 104 | 78 | $url = is_ssl() ? 'https://' : 'http://'; |
| 105 | 79 | $url .= $_SERVER['HTTP_HOST']; |
| 106 | 80 | $url .= $_SERVER['REQUEST_URI']; |
| 107 | 81 | |
| @@ -107,34 +81,30 @@ | ||
| 107 | 81 | |
| 108 | 82 | $home = set_url_scheme( get_option( 'home' ) ); |
| 109 | 83 | $home = trailingslashit( $home ); |
| 110 | 84 | |
| 111 | - $pattern = '#^' | |
| 112 | - . preg_quote( $home ) | |
| 113 | - . '(?:' . preg_quote( trailingslashit( $wp_rewrite->index ) ) . ')?' | |
| 114 | - . bogo_get_lang_regex() | |
| 115 | - . '(/|$)#'; | |
| 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 . ')(/|$)#'; | |
| 116 | 89 | |
| 117 | - if ( | |
| 118 | - preg_match( $pattern, $url, $matches ) and | |
| 119 | - $closest = bogo_get_closest_locale( $matches[1] ) | |
| 120 | - ) { | |
| 121 | - return $bogo_locale = $closest; | |
| 122 | - } | |
| 90 | + if ( preg_match( $pattern, $url, $matches ) | |
| 91 | + && $closest = bogo_get_closest_locale( $matches[1] ) ) | |
| 92 | + return $closest; | |
| 123 | 93 | } |
| 124 | 94 | |
| 125 | 95 | $lang = bogo_get_lang_from_url(); |
| 126 | 96 | |
| 127 | - if ( $lang and $closest = bogo_get_closest_locale( $lang ) ) { | |
| 128 | - return $bogo_locale = $closest; | |
| 129 | - } | |
| 97 | + if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) | |
| 98 | + return $closest; | |
| 130 | 99 | |
| 131 | - return $bogo_locale = $default_locale; | |
| 100 | + $locale = $default_locale; | |
| 101 | + | |
| 102 | + return $locale; | |
| 132 | 103 | } |
| 133 | 104 | |
| 105 | +add_filter( 'query_vars', 'bogo_query_vars' ); | |
| 134 | 106 | |
| 135 | -add_filter( 'query_vars', 'bogo_query_vars', 10, 1 ); | |
| 136 | - | |
| 137 | 107 | function bogo_query_vars( $query_vars ) { |
| 138 | 108 | $query_vars[] = 'lang'; |
| 139 | 109 | |
| 140 | 110 | return $query_vars; |
| @@ -139,27 +109,25 @@ | ||
| 139 | 109 | |
| 140 | 110 | return $query_vars; |
| 141 | 111 | } |
| 142 | 112 | |
| 113 | +add_shortcode( 'bogo', 'bogo_language_switcher' ); | |
| 143 | 114 | |
| 144 | -add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts', 10, 0 ); | |
| 115 | +add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' ); | |
| 145 | 116 | |
| 146 | 117 | function bogo_enqueue_scripts() { |
| 147 | 118 | wp_enqueue_style( 'bogo', |
| 148 | 119 | plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ), |
| 149 | - array(), BOGO_VERSION, 'all' | |
| 150 | - ); | |
| 120 | + array(), BOGO_VERSION, 'all' ); | |
| 151 | 121 | |
| 152 | 122 | if ( is_rtl() ) { |
| 153 | 123 | wp_enqueue_style( 'bogo-rtl', |
| 154 | 124 | plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ), |
| 155 | - array(), BOGO_VERSION, 'all' | |
| 156 | - ); | |
| 125 | + array(), BOGO_VERSION, 'all' ); | |
| 157 | 126 | } |
| 158 | 127 | } |
| 159 | 128 | |
| 160 | - | |
| 161 | -add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate', 10, 0 ); | |
| 129 | +add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' ); | |
| 162 | 130 | |
| 163 | 131 | function bogo_deactivate() { |
| 164 | 132 | bogo_delete_prop( 'lang_rewrite_regex' ); |
| 165 | 133 | } |