PluginProbe
Bogo / 2.8.1
Bogo v2.8.1
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 2.8.1, at bogo.php

141 lines 3.8 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: 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.8.1
11 */
12
13 define( 'BOGO_VERSION', '2.8.1' );
14
15 define( 'BOGO_PLUGIN', __FILE__ );
16
17 define( 'BOGO_PLUGIN_BASENAME', plugin_basename( BOGO_PLUGIN ) );
18
19 define( 'BOGO_PLUGIN_NAME', trim( dirname( BOGO_PLUGIN_BASENAME ), '/' ) );
20
21 define( 'BOGO_PLUGIN_DIR', untrailingslashit( dirname( BOGO_PLUGIN ) ) );
22
23 require_once BOGO_PLUGIN_DIR . '/includes/functions.php';
24 require_once BOGO_PLUGIN_DIR . '/includes/rewrite.php';
25 require_once BOGO_PLUGIN_DIR . '/includes/link-template.php';
26 require_once BOGO_PLUGIN_DIR . '/includes/language-switcher.php';
27 require_once BOGO_PLUGIN_DIR . '/includes/nav-menu.php';
28 require_once BOGO_PLUGIN_DIR . '/includes/widgets.php';
29 require_once BOGO_PLUGIN_DIR . '/includes/post.php';
30 require_once BOGO_PLUGIN_DIR . '/includes/user.php';
31 require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php';
32 require_once BOGO_PLUGIN_DIR . '/includes/query.php';
33 require_once BOGO_PLUGIN_DIR . '/includes/flags.php';
34 require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php';
35
36 if ( is_admin() ) {
37 require_once BOGO_PLUGIN_DIR . '/admin/admin.php';
38 }
39
40 add_action( 'plugins_loaded', 'bogo_plugins_loaded' );
41
42 function bogo_plugins_loaded() {
43 load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' );
44 }
45
46 add_action( 'init', 'bogo_init' );
47
48 function bogo_init() {
49 bogo_languages();
50
51 if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) {
52 $locale = get_locale();
53
54 if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) {
55 setcookie( 'lang', $locale, 0, '/' );
56 }
57 }
58 }
59
60 add_filter( 'locale', 'bogo_locale' );
61
62 function bogo_locale( $locale ) {
63 global $wp_rewrite, $wp_query;
64
65 if ( ! did_action( 'plugins_loaded' ) ) {
66 return $locale;
67 }
68
69 if ( is_admin() ) {
70 return bogo_get_user_locale();
71 }
72
73 $default_locale = bogo_get_default_locale();
74
75 if ( ! empty( $wp_query->query_vars ) ) {
76 if ( ( $lang = get_query_var( 'lang' ) )
77 && $closest = bogo_get_closest_locale( $lang ) ) {
78 return $closest;
79 } else {
80 return $default_locale;
81 }
82 }
83
84 if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) {
85 $url = is_ssl() ? 'https://' : 'http://';
86 $url .= $_SERVER['HTTP_HOST'];
87 $url .= $_SERVER['REQUEST_URI'];
88
89 $home = set_url_scheme( get_option( 'home' ) );
90 $home = trailingslashit( $home );
91
92 $available_locales = bogo_available_locales();
93 $available_locales = array_map( 'bogo_lang_slug', $available_locales );
94 $available_locales = implode( '|', $available_locales );
95 $pattern = '#^' . preg_quote( $home ) . '(' . $available_locales . ')(/|$)#';
96
97 if ( preg_match( $pattern, $url, $matches )
98 && $closest = bogo_get_closest_locale( $matches[1] ) ) {
99 return $closest;
100 }
101 }
102
103 $lang = bogo_get_lang_from_url();
104
105 if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) {
106 return $closest;
107 }
108
109 $locale = $default_locale;
110
111 return $locale;
112 }
113
114 add_filter( 'query_vars', 'bogo_query_vars' );
115
116 function bogo_query_vars( $query_vars ) {
117 $query_vars[] = 'lang';
118
119 return $query_vars;
120 }
121
122 add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' );
123
124 function bogo_enqueue_scripts() {
125 wp_enqueue_style( 'bogo',
126 plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ),
127 array(), BOGO_VERSION, 'all' );
128
129 if ( is_rtl() ) {
130 wp_enqueue_style( 'bogo-rtl',
131 plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ),
132 array(), BOGO_VERSION, 'all' );
133 }
134 }
135
136 add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' );
137
138 function bogo_deactivate() {
139 bogo_delete_prop( 'lang_rewrite_regex' );
140 }
141