PluginProbe
Bogo / 3.8
Bogo v3.8
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
bogo / bogo.php

bogo.php in Bogo 3.8, at bogo.php

157 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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://ideasilo.wordpress.com/bogo/
6 * Author: Takayuki Miyoshi
7 * Author URI: https://ideasilo.wordpress.com/
8 * License: GPL v2 or later
9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 * Text Domain: bogo
11 * Domain Path: /languages/
12 * Version: 3.8
13 * Requires at least: 6.4
14 * Requires PHP: 7.4
15 */
16
17 define( 'BOGO_VERSION', '3.8' );
18
19 define( 'BOGO_PLUGIN', __FILE__ );
20
21 define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) );
22
23 define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) );
24
25 define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) );
26
27 require_once BOGO_PLUGIN_DIR . '/includes/functions.php';
28 require_once BOGO_PLUGIN_DIR . '/includes/language-functions.php';
29 require_once BOGO_PLUGIN_DIR . '/includes/formatting.php';
30 require_once BOGO_PLUGIN_DIR . '/includes/pomo.php';
31 require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php';
32 require_once BOGO_PLUGIN_DIR . '/includes/link-template.php';
33 require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php';
34 require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php';
35 require_once BOGO_PLUGIN_DIR . '/includes/widgets.php';
36 require_once BOGO_PLUGIN_DIR . '/includes/post.php';
37 require_once BOGO_PLUGIN_DIR . '/includes/user.php';
38 require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
39 require_once BOGO_PLUGIN_DIR . '/includes/query.php';
40 require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
41 require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php';
42 require_once BOGO_PLUGIN_DIR . '/includes/shortcodes.php';
43 require_once BOGO_PLUGIN_DIR . '/includes/block-editor/block-editor.php';
44
45 if ( is_admin() ) {
46 require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
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 add_filter( 'pre_determine_locale', 'bogo_pre_determine_locale', 10, 1 );
57
58 function bogo_pre_determine_locale( $locale ) {
59 if ( ! empty( $_GET['filter_action'] ) ) {
60 return $locale;
61 }
62
63 if ( isset( $_GET['lang'] )
64 and $closest = bogo_get_closest_locale( $_GET['lang'] ) ) {
65 $locale = $closest;
66 }
67
68 return $locale;
69 }
70
71 add_filter( 'locale', 'bogo_locale', 10, 1 );
72
73 function bogo_locale( $locale ) {
74 global $wp_rewrite, $wp_query;
75
76 if ( ! did_action( 'plugins_loaded' ) or is_admin() ) {
77 return $locale;
78 }
79
80 static $bogo_locale = '';
81
82 if ( $bogo_locale ) {
83 return $bogo_locale;
84 }
85
86 $default_locale = bogo_get_default_locale();
87
88 if ( ! empty( $wp_query->query_vars ) ) {
89 if ( $lang = get_query_var( 'lang' )
90 and $closest = bogo_get_closest_locale( $lang ) ) {
91 return $bogo_locale = $closest;
92 } else {
93 return $bogo_locale = $default_locale;
94 }
95 }
96
97 if ( isset( $wp_rewrite )
98 and $wp_rewrite->using_permalinks() ) {
99 $url = is_ssl() ? 'https://' : 'http://';
100 $url .= $_SERVER['HTTP_HOST'];
101 $url .= $_SERVER['REQUEST_URI'];
102
103 $home = set_url_scheme( get_option( 'home' ) );
104 $home = trailingslashit( $home );
105
106 $pattern = '#^'
107 . preg_quote( $home )
108 . '(?:' . preg_quote( trailingslashit( $wp_rewrite->index ) ) . ')?'
109 . bogo_get_lang_regex()
110 . '(/|$)#';
111
112 if ( preg_match( $pattern, $url, $matches )
113 and $closest = bogo_get_closest_locale( $matches[1] ) ) {
114 return $bogo_locale = $closest;
115 }
116 }
117
118 $lang = bogo_get_lang_from_url();
119
120 if ( $lang
121 and $closest = bogo_get_closest_locale( $lang ) ) {
122 return $bogo_locale = $closest;
123 }
124
125 return $bogo_locale = $default_locale;
126 }
127
128 add_filter( 'query_vars', 'bogo_query_vars', 10, 1 );
129
130 function bogo_query_vars( $query_vars ) {
131 $query_vars[] = 'lang';
132
133 return $query_vars;
134 }
135
136 add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts', 10, 0 );
137
138 function bogo_enqueue_scripts() {
139 wp_enqueue_style( 'bogo',
140 plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ),
141 array(), BOGO_VERSION, 'all'
142 );
143
144 if ( is_rtl() ) {
145 wp_enqueue_style( 'bogo-rtl',
146 plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ),
147 array(), BOGO_VERSION, 'all'
148 );
149 }
150 }
151
152 add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate', 10, 0 );
153
154 function bogo_deactivate() {
155 bogo_delete_prop( 'lang_rewrite_regex' );
156 }
157