| 1 |
<?php |
| 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 |
*/ |
| 14 |
|
| 15 |
define( 'BOGO_VERSION', '3.9.3' ); |
| 16 |
|
| 17 |
define( 'BOGO_PLUGIN', __FILE__ ); |
| 18 |
|
| 19 |
define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) ); |
| 20 |
|
| 21 |
define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) ); |
| 22 |
|
| 23 |
define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) ); |
| 24 |
|
| 25 |
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 |
require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php'; |
| 31 |
require_once BOGO_PLUGIN_DIR . '/includes/link-template.php'; |
| 32 |
require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php'; |
| 33 |
require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php'; |
| 34 |
require_once BOGO_PLUGIN_DIR . '/includes/widgets.php'; |
| 35 |
require_once BOGO_PLUGIN_DIR . '/includes/post.php'; |
| 36 |
require_once BOGO_PLUGIN_DIR . '/includes/user.php'; |
| 37 |
require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; |
| 38 |
require_once BOGO_PLUGIN_DIR . '/includes/query.php'; |
| 39 |
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 |
|
| 44 |
if ( is_admin() ) { |
| 45 |
require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
add_action( 'init', 'bogo_init', 10, 0 ); |
| 50 |
|
| 51 |
function bogo_init() { |
| 52 |
bogo_languages(); |
| 53 |
Bogo_POMO::import( determine_locale() ); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 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; |
| 62 |
} |
| 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 |
} |
| 73 |
|
| 74 |
|
| 75 |
add_filter( 'locale', 'bogo_locale', 10, 1 ); |
| 76 |
|
| 77 |
function bogo_locale( $locale ) { |
| 78 |
global $wp_rewrite, $wp_query; |
| 79 |
|
| 80 |
if ( ! did_action( 'plugins_loaded' ) or is_admin() ) { |
| 81 |
return $locale; |
| 82 |
} |
| 83 |
|
| 84 |
static $bogo_locale = ''; |
| 85 |
|
| 86 |
if ( $bogo_locale ) { |
| 87 |
return $bogo_locale; |
| 88 |
} |
| 89 |
|
| 90 |
$default_locale = bogo_get_default_locale(); |
| 91 |
|
| 92 |
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 |
} |
| 101 |
} |
| 102 |
|
| 103 |
if ( isset( $wp_rewrite ) and $wp_rewrite->using_permalinks() ) { |
| 104 |
$url = is_ssl() ? 'https://' : 'http://'; |
| 105 |
$url .= $_SERVER['HTTP_HOST']; |
| 106 |
$url .= $_SERVER['REQUEST_URI']; |
| 107 |
|
| 108 |
$home = set_url_scheme( get_option( 'home' ) ); |
| 109 |
$home = trailingslashit( $home ); |
| 110 |
|
| 111 |
$pattern = '#^' |
| 112 |
. preg_quote( $home ) |
| 113 |
. '(?:' . preg_quote( trailingslashit( $wp_rewrite->index ) ) . ')?' |
| 114 |
. bogo_get_lang_regex() |
| 115 |
. '(/|$)#'; |
| 116 |
|
| 117 |
if ( |
| 118 |
preg_match( $pattern, $url, $matches ) and |
| 119 |
$closest = bogo_get_closest_locale( $matches[1] ) |
| 120 |
) { |
| 121 |
return $bogo_locale = $closest; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
$lang = bogo_get_lang_from_url(); |
| 126 |
|
| 127 |
if ( $lang and $closest = bogo_get_closest_locale( $lang ) ) { |
| 128 |
return $bogo_locale = $closest; |
| 129 |
} |
| 130 |
|
| 131 |
return $bogo_locale = $default_locale; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
add_filter( 'query_vars', 'bogo_query_vars', 10, 1 ); |
| 136 |
|
| 137 |
function bogo_query_vars( $query_vars ) { |
| 138 |
$query_vars[] = 'lang'; |
| 139 |
|
| 140 |
return $query_vars; |
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts', 10, 0 ); |
| 145 |
|
| 146 |
function bogo_enqueue_scripts() { |
| 147 |
wp_enqueue_style( 'bogo', |
| 148 |
plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ), |
| 149 |
array(), BOGO_VERSION, 'all' |
| 150 |
); |
| 151 |
|
| 152 |
if ( is_rtl() ) { |
| 153 |
wp_enqueue_style( 'bogo-rtl', |
| 154 |
plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ), |
| 155 |
array(), BOGO_VERSION, 'all' |
| 156 |
); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate', 10, 0 ); |
| 162 |
|
| 163 |
function bogo_deactivate() { |
| 164 |
bogo_delete_prop( 'lang_rewrite_regex' ); |
| 165 |
} |
| 166 |
|