PluginProbe ʕ •ᴥ•ʔ
WP Multibyte Patch / 2.9.1
WP Multibyte Patch v2.9.1
trunk 1.4.2 1.5 1.5.1 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.7 1.8 1.9 2.0 2.1.1 2.2 2.3 2.3.1 2.4 2.5 2.6 2.7 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.9 2.9.1 2.9.2 2.9.3
wp-multibyte-patch / wp-multibyte-patch.php
wp-multibyte-patch Last commit date
ext 1 year ago includes 1 year ago languages 13 years ago readme.txt 1 year ago wp-multibyte-patch.php 1 year ago wplink.php 6 years ago wpmp-config-sample-ja.php 5 years ago wpmp-load.php 12 years ago
wp-multibyte-patch.php
578 lines
1 <?php
2 /*
3 Plugin Name: WP Multibyte Patch
4 Description: Multibyte functionality enhancement for the WordPress Japanese package.
5 Version: 2.9.1
6 Plugin URI: https://eastcoder.com/code/wp-multibyte-patch/
7 Author: Seisuke Kuraishi
8 Author URI: https://tinybit.co.jp/
9 License: GPLv2
10 Text Domain: wp-multibyte-patch
11 Domain Path: /languages
12 */
13
14 /**
15 * Multibyte functionality enhancement for the WordPress Japanese package.
16 *
17 * @package WP_Multibyte_Patch
18 * @version 2.9.1
19 * @author Seisuke Kuraishi <210pura@gmail.com>
20 * @copyright Copyright (c) 2025 Seisuke Kuraishi, Tinybit Inc.
21 * @license https://opensource.org/licenses/gpl-2.0.php GPLv2
22 * @link https://eastcoder.com/code/wp-multibyte-patch/
23 */
24
25 /**
26 * @package WP_Multibyte_Patch
27 */
28 class multibyte_patch {
29
30 // Do not edit this section. Use wpmp-config.php instead.
31 public $conf = array(
32 'excerpt_mblength' => 110,
33 'excerpt_more' => ' [&hellip;]',
34 'comment_excerpt_mblength' => 40,
35 'dashboard_recent_drafts_mblength' => 40,
36 'patch_wp_mail' => false,
37 'patch_incoming_trackback' => false,
38 'patch_incoming_pingback' => false,
39 'patch_wp_trim_excerpt' => true,
40 'patch_wp_trim_words' => false,
41 'patch_get_comment_excerpt' => true,
42 'patch_dashboard_recent_drafts' => true,
43 'patch_process_search_terms' => false,
44 'patch_admin_custom_css' => false,
45 'patch_wplink_js' => true,
46 'patch_force_character_count' => false,
47 'patch_force_twentytwelve_open_sans_off' => false,
48 'patch_force_twentythirteen_google_fonts_off' => false,
49 'patch_force_twentyfourteen_google_fonts_off' => false,
50 'patch_force_twentyfifteen_google_fonts_off' => false,
51 'patch_force_twentysixteen_google_fonts_off' => false,
52 'patch_force_twentyseventeen_google_fonts_off' => false,
53 'patch_sanitize_file_name' => true,
54 'patch_sanitize_feed_xml_text' => false,
55 'patch_bp_create_excerpt' => false,
56 'bp_excerpt_mblength' => 110,
57 'bp_excerpt_more' => ' [&hellip;]'
58 );
59
60 protected $blog_encoding = 'UTF-8';
61 protected $has_mbfunctions = false;
62 protected $mbfunctions_required = false;
63 protected $has_mb_strlen = false;
64 protected $debug_suffix = '';
65 protected $textdomain = 'wp-multibyte-patch';
66 protected $lang_dir = 'languages';
67 protected $required_version = '4.5';
68 protected $query_based_vars = array();
69 protected $has_pcre_utf8 = false;
70
71 // For fallback purpose only. (1.6)
72 public function guess_encoding( $string, $encoding = '' ) {
73 $blog_encoding = $this->blog_encoding;
74
75 if ( !$encoding && seems_utf8( $string ) )
76 return 'UTF-8';
77 elseif ( !$encoding )
78 return $blog_encoding;
79 else
80 return $encoding;
81 }
82
83 // For fallback purpose only. (1.6)
84 public function convenc( $string, $to_encoding, $from_encoding = '' ) {
85 $blog_encoding = $this->blog_encoding;
86
87 if ( '' == $from_encoding )
88 $from_encoding = $blog_encoding;
89
90 if ( strtoupper( $to_encoding ) == strtoupper( $from_encoding ) )
91 return $string;
92 else
93 return mb_convert_encoding( $string, $to_encoding, $from_encoding );
94 }
95
96 public function incoming_trackback( $commentdata ) {
97 if ( 'trackback' != $commentdata['comment_type'] )
98 return $commentdata;
99
100 if ( false === $this->conf['patch_incoming_trackback'] )
101 return $commentdata;
102
103 $title = isset( $_POST['title'] ) ? wp_unslash( $_POST['title'] ) : '';
104 $excerpt = isset( $_POST['excerpt'] ) ? wp_unslash( $_POST['excerpt'] ) : '';
105 $blog_name = isset( $_POST['blog_name'] ) ? wp_unslash( $_POST['blog_name'] ) : '';
106 $blog_encoding = $this->blog_encoding;
107
108 $from_encoding = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
109
110 if ( empty( $from_encoding ) && preg_match( "/^.*charset=([a-zA-Z0-9\-_]+).*$/i", $_SERVER['CONTENT_TYPE'], $matched ) ) {
111 $from_encoding = isset( $matched[1] ) ? $matched[1] : '';
112 }
113
114 $from_encoding = str_replace( array( ',', ' ' ), '', strtoupper( trim( $from_encoding ) ) );
115 $from_encoding = $this->guess_encoding( $excerpt . $title . $blog_name, $from_encoding );
116
117 $title = $this->convenc( $title, $blog_encoding, $from_encoding );
118 $blog_name = $this->convenc( $blog_name, $blog_encoding, $from_encoding );
119 $excerpt = $this->convenc( $excerpt, $blog_encoding, $from_encoding );
120
121 $title = strip_tags( $title );
122 $excerpt = strip_tags( $excerpt );
123
124 $title = ( strlen( $title ) > 250 ) ? mb_strcut( $title, 0, 250, $blog_encoding ) . '&#8230;' : $title;
125 $excerpt = ( strlen( $excerpt ) > 255 ) ? mb_strcut( $excerpt, 0, 252, $blog_encoding ) . '&#8230;' : $excerpt;
126
127 $commentdata['comment_author'] = wp_slash( $blog_name );
128 $commentdata['comment_content'] = wp_slash( "<strong>$title</strong>\n\n$excerpt" );
129
130 return $commentdata;
131 }
132
133 public function pre_remote_source( $remote_source, $pagelinkedto ) {
134 $this->pingback_ping_remote_source = $remote_source;
135 $this->pingback_ping_pagelinkedto = $pagelinkedto;
136 return $remote_source;
137 }
138
139 public function incoming_pingback( $commentdata ) {
140 if ( 'pingback' != $commentdata['comment_type'] )
141 return $commentdata;
142
143 if ( false === $this->conf['patch_incoming_pingback'] )
144 return $commentdata;
145
146 $pagelinkedto = $this->pingback_ping_pagelinkedto;
147 $remote_source = $this->pingback_ping_remote_source;
148
149 $remote_source = preg_replace( "/" . preg_quote( '<!DOC', '/' ) . "/i", '<DOC', $remote_source );
150 $remote_source = preg_replace( "/[\r\n\t ]+/", ' ', $remote_source );
151 $remote_source = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/i", "\n\n", $remote_source );
152
153 preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle );
154 $title = isset( $matchtitle[1] ) ? $matchtitle[1] : '';
155
156 preg_match( "/<meta[^<>]+charset=\"*([a-zA-Z0-9\-_]+)\"*[^<>]*>/i", $remote_source, $matches );
157 $charset = isset( $matches[1] ) ? $matches[1] : '';
158 $from_encoding = $this->guess_encoding( strip_tags( $remote_source ), $charset );
159 $blog_encoding = $this->blog_encoding;
160
161 $remote_source = strip_tags( $remote_source, '<a>' );
162 $remote_source = $this->convenc( $remote_source, $blog_encoding, $from_encoding );
163 $p = explode( "\n\n", $remote_source );
164
165 foreach ( $p as $para ) {
166 if ( strpos( $para, $pagelinkedto ) !== false && preg_match( "/^([^<>]*)(\<a[^<>]+[\"']" . preg_quote( $pagelinkedto, '/' ) . "[\"'][^<>]*\>)([^<>]+)(\<\/a\>)(.*)$/i", $para, $context ) )
167 break;
168 }
169
170 if ( empty( $context ) )
171 return $commentdata;
172
173 $context[1] = strip_tags( $context[1] );
174 $context[5] = strip_tags( $context[5] );
175 $len_max = 250;
176 $len_c3 = strlen( $context[3] );
177
178 if ( $len_c3 > $len_max ) {
179 $excerpt = mb_strcut( $context[3], 0, 250, $blog_encoding );
180 } else {
181 $len_c1 = strlen( $context[1] );
182 $len_c5 = strlen( $context[5] );
183 $len_left = $len_max - $len_c3;
184 $len_left_even = ceil( $len_left / 2 );
185
186 if ( $len_left_even > $len_c1 ) {
187 $context[5] = mb_strcut( $context[5], 0, $len_left - $len_c1, $blog_encoding );
188 }
189 elseif ( $len_left_even > $len_c5 ) {
190 $context[1] .= "\t\t\t\t\t\t";
191 $context[1] = mb_strcut( $context[1], $len_c1 - ( $len_left - $len_c5 ), $len_c1 + 6, $blog_encoding );
192 $context[1] = preg_replace( "/\t*$/", '', $context[1] );
193 }
194 else {
195 $context[1] .= "\t\t\t\t\t\t";
196 $context[1] = mb_strcut( $context[1], $len_c1 - $len_left_even, $len_c1 + 6, $blog_encoding );
197 $context[1] = preg_replace( "/\t*$/", '', $context[1] );
198 $context[5] = mb_strcut( $context[5], 0, $len_left_even, $blog_encoding );
199 }
200
201 $excerpt = $context[1] . $context[3] . $context[5];
202 }
203
204 $commentdata['comment_content'] = '[&#8230;] ' . esc_html( $excerpt ) . ' [&#8230;]';
205 $commentdata['comment_content'] = wp_slash( $commentdata['comment_content'] );
206 $commentdata['comment_author'] = $this->convenc( $title, $blog_encoding, $from_encoding );
207 $commentdata['comment_author'] = wp_slash( $commentdata['comment_author'] );
208
209 return $commentdata;
210 }
211
212 public function preprocess_comment( $commentdata ) {
213 if ( $commentdata['comment_type'] == 'trackback' )
214 return $this->incoming_trackback( $commentdata );
215 elseif ( $commentdata['comment_type'] == 'pingback' )
216 return $this->incoming_pingback( $commentdata );
217 else
218 return $commentdata;
219 }
220
221 public function trim_multibyte_excerpt( $text = '', $length = 110, $more = ' [&hellip;]', $encoding = 'UTF-8' ) {
222 $text = strip_shortcodes( $text );
223
224 if ( function_exists( 'excerpt_remove_blocks' ) )
225 $text = excerpt_remove_blocks( $text );
226
227 $text = str_replace( ']]>', ']]&gt;', $text );
228 $text = strip_tags( $text );
229 $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
230
231 if ( $this->mb_strlen( $text, $encoding ) > $length )
232 $text = mb_substr( $text, 0, $length, $encoding ) . $more;
233
234 return $text;
235 }
236
237 public function bp_create_excerpt( $text = '' ) {
238 return $this->trim_multibyte_excerpt( $text, $this->conf['bp_excerpt_mblength'], $this->conf['bp_excerpt_more'], $this->blog_encoding );
239 }
240
241 public function bp_get_activity_content_body( $content = '' ) {
242 return preg_replace( "/<a [^<>]+>([^<>]+)<\/a>(" . preg_quote( $this->conf['bp_excerpt_more'], '/' ) . "<\/p>)$/", "$1$2", $content );
243 }
244
245 public function get_comment_excerpt( $excerpt = '', $comment_ID = 0, $comment = '' ) {
246 $blog_encoding = $this->blog_encoding;
247
248 if ( ! post_password_required( $comment->comment_post_ID ) ) {
249 $excerpt = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
250 } else {
251 $excerpt = __( 'Password protected' );
252 }
253
254 if ( $this->mb_strlen( $excerpt, $blog_encoding ) > $this->conf['comment_excerpt_mblength'] )
255 $excerpt = mb_substr( $excerpt, 0, $this->conf['comment_excerpt_mblength'], $blog_encoding ) . '&hellip;';
256
257 return $excerpt;
258 }
259
260 public function excerpt_mblength() {
261 if ( isset( $this->query_based_vars['excerpt_mblength'] ) && (int) $this->query_based_vars['excerpt_mblength'] )
262 $length = (int) $this->query_based_vars['excerpt_mblength'];
263 else
264 $length = (int) $this->conf['excerpt_mblength'];
265
266 return apply_filters( 'excerpt_mblength', $length );
267 }
268
269 public function excerpt_more() {
270 if ( isset( $this->query_based_vars['excerpt_more'] ) )
271 return $this->query_based_vars['excerpt_more'];
272 else
273 return $this->conf['excerpt_more'];
274 }
275
276 public function sanitize_file_name( $name ) {
277 $info = pathinfo( $name );
278 $ext = !empty( $info['extension'] ) ? '.' . $info['extension'] : '';
279 $name = str_replace( $ext, '', $name );
280 $name_enc = rawurlencode( $name );
281 $name = ( $name == $name_enc ) ? $name . $ext : md5( $name ) . $ext;
282 return $name;
283 }
284
285 public function wplink_js( &$scripts ) {
286 global $pagenow;
287
288 $file = dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) . "/wp-includes/js/wplink{$this->debug_suffix}.js";
289
290 if( ! is_admin() || ! isset( $pagenow ) || ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) || ! is_file( $file ) )
291 return;
292
293 $debug_qs = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '?sd=1' : '';
294
295 $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "wplink.php{$debug_qs}", array( 'jquery', 'wp-a11y' ), false, 1 );
296 }
297
298 public function wplink_js_minimum_input_length( $translations = '', $text = '', $context = '' ) {
299 if ( 'minimum input length for searching post links' === $context && '3' === $text ) {
300 return '2';
301 }
302
303 return $translations;
304 }
305
306 public function force_character_count( $translations = '', $text = '', $context = '' ) {
307 if ( 'word count: words or characters?' == $context && 'words' == $text )
308 return 'characters';
309
310 if ( 'Word count type. Do not translate!' == $context && 'words' == $text )
311 return 'characters_including_spaces';
312
313 return $translations;
314 }
315
316 public function force_twentytwelve_open_sans_off() {
317 wp_dequeue_style( 'twentytwelve-fonts' );
318 }
319
320 public function force_twentythirteen_google_fonts_off() {
321 wp_dequeue_style( 'twentythirteen-fonts' );
322 }
323
324 public function force_twentyfourteen_google_fonts_off() {
325 wp_dequeue_style( 'twentyfourteen-lato' );
326 }
327
328 public function force_twentyfifteen_google_fonts_off() {
329 wp_dequeue_style( 'twentyfifteen-fonts' );
330 }
331
332 public function force_twentysixteen_google_fonts_off() {
333 wp_dequeue_style( 'twentysixteen-fonts' );
334 }
335
336 public function force_twentyseventeen_google_fonts_off() {
337 wp_dequeue_style( 'twentyseventeen-fonts' );
338 }
339
340 public function remove_editor_style( $file = '' ) {
341 global $editor_styles;
342
343 if ( ! is_admin() || empty( $editor_styles ) || ! is_array( $editor_styles ) )
344 return;
345
346 foreach ( $editor_styles as $key => $value ) {
347 if( $file === $value )
348 unset( $editor_styles[$key] );
349 }
350 }
351
352 public function sanitize_xml_text( $text, $replace = '' ) {
353 if ( 'UTF-8' !== $this->blog_encoding || ! $this->has_pcre_utf8 )
354 return $text;
355
356 if ( $this->has_mbfunctions )
357 $text = @mb_convert_encoding( $text, 'UTF-8', 'UTF-8' );
358 elseif ( function_exists( 'iconv' ) )
359 $text = @iconv( 'UTF-8', 'UTF-8', $text );
360
361 return @preg_replace( '/[^\x9\xA\xD\x20-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]+/u', $replace, $text );
362 }
363
364 public function query_based_settings() {
365 $is_query_funcs = array( 'is_feed', 'is_404', 'is_search', 'is_tax', 'is_front_page', 'is_home', 'is_attachment', 'is_single', 'is_page', 'is_category', 'is_tag', 'is_author', 'is_date', 'is_archive', 'is_paged' );
366
367 foreach ( $is_query_funcs as $func ) {
368 if ( isset( $this->conf['excerpt_mblength.' . $func] ) && !isset( $this->query_based_vars['excerpt_mblength'] ) && $func() )
369 $this->query_based_vars['excerpt_mblength'] = $this->conf['excerpt_mblength.' . $func];
370
371 if ( isset( $this->conf['excerpt_more.' . $func] ) && !isset( $this->query_based_vars['excerpt_more'] ) && $func() )
372 $this->query_based_vars['excerpt_more'] = $this->conf['excerpt_more.' . $func];
373 }
374 }
375
376 // The fallback only works with UTF-8 blog.
377 public function mb_strlen( $str = '', $encoding = 'UTF-8' ) {
378 if ( $this->has_mb_strlen )
379 return mb_strlen( $str, $encoding );
380 else
381 return preg_match_all( "/./us", $str, $match );
382 }
383
384 public function is_wp_required_version( $required_version ) {
385 global $wp_version;
386 return version_compare( $wp_version, $required_version, '<' ) ? false : true;
387 }
388
389 public function filters_after_template_redirect() {
390 if ( is_feed() ) {
391 if ( false !== $this->conf['patch_sanitize_feed_xml_text'] ) {
392 add_filter( 'the_title_rss', array( $this, 'sanitize_xml_text' ), 99 );
393 add_filter( 'the_content_feed', array( $this, 'sanitize_xml_text' ), 99 );
394 add_filter( 'the_excerpt_rss', array( $this, 'sanitize_xml_text' ), 99 );
395 add_filter( 'comment_text_rss', array( $this, 'sanitize_xml_text' ), 99 );
396 add_filter( 'comment_text', array( $this, 'sanitize_xml_text' ), 99 );
397 }
398 }
399 }
400
401 public function filters_after_setup_theme() {
402 // add filter
403 if ( false !== $this->conf['patch_force_character_count']) {
404 if ( 'characters_including_spaces' != _x( 'words', 'Word count type. Do not translate!' ) )
405 add_filter( 'gettext_with_context', array( $this, 'force_character_count' ), 10, 3 );
406 }
407
408 if ( false !== $this->conf['patch_force_twentytwelve_open_sans_off'] && 'twentytwelve' == get_template() ) {
409 add_action( 'wp_enqueue_scripts', array( $this, 'force_twentytwelve_open_sans_off' ), 99 );
410 add_action( 'admin_print_styles-appearance_page_custom-header', array( $this, 'force_twentytwelve_open_sans_off' ), 99 );
411 }
412
413 if ( false !== $this->conf['patch_force_twentythirteen_google_fonts_off'] && 'twentythirteen' == get_template() ) {
414 add_action( 'wp_enqueue_scripts', array( $this, 'force_twentythirteen_google_fonts_off' ), 99 );
415 add_action( 'admin_print_styles-appearance_page_custom-header', array( $this, 'force_twentythirteen_google_fonts_off' ), 99 );
416 }
417
418 if ( false !== $this->conf['patch_force_twentyfourteen_google_fonts_off'] && 'twentyfourteen' == get_template() ) {
419 add_action( 'wp_enqueue_scripts', array( $this, 'force_twentyfourteen_google_fonts_off' ), 99 );
420 add_action( 'admin_print_scripts-appearance_page_custom-header', array( $this, 'force_twentyfourteen_google_fonts_off' ), 99 );
421 }
422
423 if ( false !== $this->conf['patch_force_twentyfifteen_google_fonts_off'] && 'twentyfifteen' == get_template() ) {
424 add_action( 'wp_enqueue_scripts', array( $this, 'force_twentyfifteen_google_fonts_off' ), 99 );
425
426 if ( function_exists( 'twentyfifteen_fonts_url' ) )
427 $this->remove_editor_style( twentyfifteen_fonts_url() );
428 }
429
430 if ( false !== $this->conf['patch_force_twentysixteen_google_fonts_off'] && 'twentysixteen' == get_template() ) {
431 add_action( 'wp_enqueue_scripts', array( $this, 'force_twentysixteen_google_fonts_off' ), 99 );
432
433 if ( function_exists( 'twentysixteen_fonts_url' ) )
434 $this->remove_editor_style( twentysixteen_fonts_url() );
435 }
436
437 if ( false !== $this->conf['patch_force_twentyseventeen_google_fonts_off'] && 'twentyseventeen' == get_template() ) {
438 add_action( 'wp_enqueue_scripts', array( $this, 'force_twentyseventeen_google_fonts_off' ), 99 );
439
440 if ( function_exists( 'twentyseventeen_fonts_url' ) )
441 $this->remove_editor_style( twentyseventeen_fonts_url() );
442 }
443
444 if ( false !== $this->conf['patch_wplink_js'] ) {
445 if ( $this->is_wp_required_version( '5.4-beta1' ) ) {
446 if ( '2' !== _x( '3', 'minimum input length for searching post links' ) ) {
447 add_filter( 'gettext_with_context', array( $this, 'wplink_js_minimum_input_length' ), 10, 3 );
448 }
449 }
450 else {
451 add_action( 'wp_default_scripts', array( $this, 'wplink_js' ), 9 );
452 }
453 }
454 }
455
456 public function filters() {
457 // add filter
458 add_filter( 'preprocess_comment', array( $this, 'preprocess_comment' ), 99 );
459
460 if ( false !== $this->conf['patch_incoming_pingback'] )
461 add_filter( 'pre_remote_source', array( $this, 'pre_remote_source' ), 10, 2 );
462
463 if ( false !== $this->conf['patch_wp_trim_excerpt'] ) {
464 add_filter( 'excerpt_length', array( $this, 'excerpt_mblength' ), 99 );
465 add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 9 );
466 }
467
468 if ( false !== $this->conf['patch_get_comment_excerpt'] )
469 add_filter( 'get_comment_excerpt', array( $this, 'get_comment_excerpt' ), 10, 3 );
470
471 if ( false !== $this->conf['patch_sanitize_file_name'] )
472 add_filter( 'sanitize_file_name', array( $this, 'sanitize_file_name' ) );
473
474 if ( false !== $this->conf['patch_bp_create_excerpt'] ) {
475 add_filter( 'bp_create_excerpt', array( $this, 'bp_create_excerpt' ), 99 );
476 add_filter( 'bp_get_activity_content_body', array( $this, 'bp_get_activity_content_body' ), 99 );
477 }
478
479 if ( method_exists( $this, 'wp_trim_words' ) && false !== $this->conf['patch_wp_trim_words'] )
480 add_filter( 'wp_trim_words', array( $this, 'wp_trim_words' ), 99, 4 );
481
482 // add action
483 add_action( 'wp', array( $this, 'query_based_settings' ) );
484
485 if ( method_exists( $this, 'process_search_terms' ) && false !== $this->conf['patch_process_search_terms'] )
486 add_action( 'sanitize_comment_cookies', array( $this, 'process_search_terms' ) );
487
488 if ( method_exists( $this, 'wp_mail' ) && false !== $this->conf['patch_wp_mail'] ) {
489 if( $this->is_wp_required_version( '5.5-RC2' ) && method_exists( $this, 'patch_wp_mail_with_custom_phpmailer' ) ) {
490 add_filter( 'wp_mail', array( $this, 'patch_wp_mail_with_custom_phpmailer' ), 99 );
491 }
492 else {
493 add_action( 'phpmailer_init', array( $this, 'wp_mail' ) );
494 }
495 }
496
497 if ( method_exists( $this, 'admin_custom_css' ) && false !== $this->conf['patch_admin_custom_css'] ) {
498 add_action( 'admin_enqueue_scripts', array( $this, 'admin_custom_css' ), 99 );
499 add_action( 'customize_controls_enqueue_scripts', array( $this, 'admin_custom_css' ), 99 );
500 }
501
502 add_action( 'after_setup_theme', array( $this, 'filters_after_setup_theme' ), 99 );
503 add_action( 'template_redirect', array( $this, 'filters_after_template_redirect' ) );
504 }
505
506 public function mbfunctions_exist() {
507 return (
508 function_exists( 'mb_convert_encoding' ) &&
509 function_exists( 'mb_convert_kana' ) &&
510 function_exists( 'mb_detect_encoding' ) &&
511 function_exists( 'mb_strcut' ) &&
512 function_exists( 'mb_strlen' )
513 ) ? true : false;
514 }
515
516 public function activation_check() {
517 $required_version = $this->required_version;
518
519 if ( !$this->is_wp_required_version( $required_version ) ) {
520 deactivate_plugins( __FILE__ );
521 exit( sprintf( __( 'Sorry, WP Multibyte Patch requires WordPress %s or later.', 'wp-multibyte-patch' ), $required_version ) );
522 }
523 elseif ( !$this->has_mbfunctions && $this->mbfunctions_required ) {
524 deactivate_plugins( __FILE__ );
525 exit( __( 'Sorry, WP Multibyte Patch requires <a href="http://www.php.net/manual/en/mbstring.installation.php" target="_blank">mbstring</a> functions.', 'wp-multibyte-patch' ) );
526 }
527 }
528
529 public function load_conf() {
530 $wpmp_conf = array();
531
532 if ( file_exists( WP_CONTENT_DIR . '/wpmp-config.php' ) )
533 require_once WP_CONTENT_DIR . '/wpmp-config.php';
534
535 if ( is_multisite() ) {
536 $blog_id = get_current_blog_id();
537 if ( file_exists( WP_CONTENT_DIR . '/wpmp-config-blog-' . $blog_id . '.php' ) )
538 require_once WP_CONTENT_DIR . '/wpmp-config-blog-' . $blog_id . '.php';
539 }
540
541 $this->conf = array_merge( $this->conf, $wpmp_conf );
542 }
543
544 public function __construct() {
545 $this->load_conf();
546 $this->blog_encoding = get_option( 'blog_charset' );
547
548 if ( preg_match( '/^utf-?8$/i', $this->blog_encoding ) || empty( $this->blog_encoding ) )
549 $this->blog_encoding = 'UTF-8';
550
551 // mbstring functions are required for non UTF-8 blog.
552 if ( 'UTF-8' !== $this->blog_encoding )
553 $this->mbfunctions_required = true;
554
555 $this->has_mbfunctions = $this->mbfunctions_exist();
556 $this->has_mb_strlen = function_exists( 'mb_strlen' );
557 $this->has_pcre_utf8 = @preg_match( '/^.$/u', "\xC2\xA9" );
558 $this->debug_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
559
560 load_plugin_textdomain( $this->textdomain, false, dirname( plugin_basename( __FILE__ ) ) . '/' . $this->lang_dir );
561 register_activation_hook( __FILE__, array( $this, 'activation_check' ) );
562 $this->filters();
563 }
564 }
565
566 if ( defined( 'WP_PLUGIN_URL' ) ) {
567 if ( file_exists( dirname( __FILE__ ) . '/ext/' . get_locale() . '/class.php' ) ) {
568 require_once dirname( __FILE__ ) . '/ext/' . get_locale() . '/class.php';
569 $GLOBALS['wpmp'] = new multibyte_patch_ext();
570 }
571 elseif ( file_exists( dirname( __FILE__ ) . '/ext/default/class.php' ) ) {
572 require_once dirname( __FILE__ ) . '/ext/default/class.php';
573 $GLOBALS['wpmp'] = new multibyte_patch_ext();
574 }
575 else
576 $GLOBALS['wpmp'] = new multibyte_patch();
577 }
578