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