Make WordPress Core

Ticket #16918: 16918.2.diff

File 16918.2.diff, 1.2 KB (added by aaroncampbell, 14 years ago)

Add compat.php back with _() & mb_substr()

  • wp-includes/compat.php

     
     1<?php
     2/**
     3 * WordPress implementation for PHP functions missing from older PHP versions.
     4 *
     5 * @package PHP
     6 * @access private
     7 */
     8
     9// Added in PHP 5.0
     10
     11// If gettext isn't available
     12if ( !function_exists('_') ) {
     13        function _($string) {
     14                return $string;
     15        }
     16}
     17
     18if ( !function_exists('mb_substr') ):
     19        function mb_substr( $str, $start, $length=null, $encoding=null ) {
     20                // the solution below, works only for utf-8, so in case of a different
     21                // charset, just use built-in substr
     22                $charset = get_option( 'blog_charset' );
     23                if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) {
     24                        return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length);
     25                }
     26                // use the regex unicode support to separate the UTF-8 characters into an array
     27                preg_match_all( '/./us', $str, $match );
     28                $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
     29                return implode( '', $chars );
     30        }
     31endif;