PluginProbe
Bogo / 2.9
Bogo v2.9
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
← All changes | bogo.php +43 -62 trunk2.9 View file →
@@ -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.9
11 +*/
14 12
15 -define( 'BOGO_VERSION', '3.9.3' );
13 +define( 'BOGO_VERSION', '2.9' );
16 14
17 15 define( 'BOGO_PLUGIN', __FILE__ );
18 16
19 17 define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) );
@@ -22,11 +20,8 @@
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 24 require_once BOGO_PLUGIN_DIR . '/includes/pomo.php';
30 25 require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php';
31 26 require_once BOGO_PLUGIN_DIR . '/includes/link-template.php';
32 27 require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php';
@@ -37,48 +32,40 @@
37 32 require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
38 33 require_once BOGO_PLUGIN_DIR . '/includes/query.php';
39 34 require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
40 35 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 36
44 37 if ( is_admin() ) {
45 38 require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
46 39 }
47 40
41 +add_action( 'plugins_loaded', 'bogo_plugins_loaded' );
48 42
49 -add_action( 'init', 'bogo_init', 10, 0 );
43 +function bogo_plugins_loaded() {
44 + load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' );
45 +}
50 46
47 +add_action( 'init', 'bogo_init' );
48 +
51 49 function bogo_init() {
52 50 bogo_languages();
53 - Bogo_POMO::import( determine_locale() );
54 -}
51 + Bogo_POMO::import( get_locale() );
55 52
53 + if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
54 + $locale = get_locale();
56 55
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;
56 + if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) {
57 + setcookie( 'lang', $locale, 0, '/' );
58 + }
62 59 }
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 60 }
73 61
62 +add_filter( 'locale', 'bogo_locale' );
74 63
75 -add_filter( 'locale', 'bogo_locale', 10, 1 );
76 -
77 64 function bogo_locale( $locale ) {
78 65 global $wp_rewrite, $wp_query;
79 66
80 - if ( ! did_action( 'plugins_loaded' ) or is_admin() ) {
67 + if ( ! did_action( 'plugins_loaded' ) ) {
81 68 return $locale;
82 69 }
83 70
84 71 static $bogo_locale = '';
@@ -86,15 +73,17 @@
86 73 if ( $bogo_locale ) {
87 74 return $bogo_locale;
88 75 }
89 76
77 + if ( is_admin() ) {
78 + return $bogo_locale = bogo_get_user_locale();
79 + }
80 +
90 81 $default_locale = bogo_get_default_locale();
91 82
92 83 if ( ! empty( $wp_query->query_vars ) ) {
93 - if (
94 - $lang = get_query_var( 'lang' ) and
95 - $closest = bogo_get_closest_locale( $lang )
96 - ) {
84 + if ( ( $lang = get_query_var( 'lang' ) )
85 + && $closest = bogo_get_closest_locale( $lang ) ) {
97 86 return $bogo_locale = $closest;
98 87 } else {
99 88 return $bogo_locale = $default_locale;
100 89 }
@@ -99,9 +88,9 @@
99 88 return $bogo_locale = $default_locale;
100 89 }
101 90 }
102 91
103 - if ( isset( $wp_rewrite ) and $wp_rewrite->using_permalinks() ) {
92 + if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
104 93 $url = is_ssl() ? 'https://' : 'http://';
105 94 $url .= $_SERVER['HTTP_HOST'];
106 95 $url .= $_SERVER['REQUEST_URI'];
107 96
@@ -107,18 +96,15 @@
107 96
108 97 $home = set_url_scheme( get_option( 'home' ) );
109 98 $home = trailingslashit( $home );
110 99
111 - $pattern = '#^'
112 - . preg_quote( $home )
113 - . '(?:' . preg_quote( trailingslashit( $wp_rewrite->index ) ) . ')?'
114 - . bogo_get_lang_regex()
115 - . '(/|$)#';
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 . ')(/|$)#';
116 104
117 - if (
118 - preg_match( $pattern, $url, $matches ) and
119 - $closest = bogo_get_closest_locale( $matches[1] )
120 - ) {
105 + if ( preg_match( $pattern, $url, $matches )
106 + && $closest = bogo_get_closest_locale( $matches[1] ) ) {
121 107 return $bogo_locale = $closest;
122 108 }
123 109 }
124 110
@@ -123,9 +109,9 @@
123 109 }
124 110
125 111 $lang = bogo_get_lang_from_url();
126 112
127 - if ( $lang and $closest = bogo_get_closest_locale( $lang ) ) {
113 + if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) {
128 114 return $bogo_locale = $closest;
129 115 }
130 116
131 117 return $bogo_locale = $default_locale;
@@ -130,11 +116,10 @@
130 116
131 117 return $bogo_locale = $default_locale;
132 118 }
133 119
120 +add_filter( 'query_vars', 'bogo_query_vars' );
134 121
135 -add_filter( 'query_vars', 'bogo_query_vars', 10, 1 );
136 -
137 122 function bogo_query_vars( $query_vars ) {
138 123 $query_vars[] = 'lang';
139 124
140 125 return $query_vars;
@@ -139,27 +124,23 @@
139 124
140 125 return $query_vars;
141 126 }
142 127
128 +add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' );
143 129
144 -add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts', 10, 0 );
145 -
146 130 function bogo_enqueue_scripts() {
147 131 wp_enqueue_style( 'bogo',
148 132 plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ),
149 - array(), BOGO_VERSION, 'all'
150 - );
133 + array(), BOGO_VERSION, 'all' );
151 134
152 135 if ( is_rtl() ) {
153 136 wp_enqueue_style( 'bogo-rtl',
154 137 plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ),
155 - array(), BOGO_VERSION, 'all'
156 - );
138 + array(), BOGO_VERSION, 'all' );
157 139 }
158 140 }
159 141
160 -
161 -add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate', 10, 0 );
142 +add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' );
162 143
163 144 function bogo_deactivate() {
164 145 bogo_delete_prop( 'lang_rewrite_regex' );
165 146 }