Introduce is_rtl(). Use it in core. It only becomes defined when locale is loaded, so it's impossible to use it too early. Deprecate the get_bloginfo('text_direction') call. fixes #13206.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14360 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-05-03 05:49:19 +00:00
parent 2764e19bc5
commit 4d7c88f4a4
9 changed files with 34 additions and 21 deletions

View File

@ -62,7 +62,7 @@ add_action('admin_footer', 'hello_dolly');
// We need some CSS to position the paragraph
function dolly_css() {
// This makes sure that the posinioning is also good for right-to-left languages
$x = ( 'rtl' == get_bloginfo( 'text_direction' ) ) ? 'left' : 'right';
$x = ( is_rtl() ) ? 'left' : 'right';
echo "
<style type='text/css'>

View File

@ -2605,8 +2605,6 @@ function wp_die( $message, $title = '', $args = array() ) {
* @param string|array $args Optional arguements to control behaviour.
*/
function _default_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_locale;
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
@ -2661,7 +2659,7 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) {
$text_direction = 'ltr';
if ( isset($r['text_direction']) && 'rtl' == $r['text_direction'] )
$text_direction = 'rtl';
elseif ( isset($wp_locale ) && 'rtl' == $wp_locale->text_direction )
elseif ( function_exists( 'is_rtl' ) && is_rtl() )
$text_direction = 'rtl';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@ -2743,9 +2741,7 @@ function _config_wp_siteurl( $url = '' ) {
* @return array Direction set for 'rtl', if needed by locale.
*/
function _mce_set_direction( $input ) {
global $wp_locale;
if ( 'rtl' == $wp_locale->text_direction ) {
if ( is_rtl() ) {
$input['directionality'] = 'rtl';
$input['plugins'] .= ',directionality';
$input['theme_advanced_buttons1'] .= ',ltr';

View File

@ -398,7 +398,7 @@ function get_bloginfo( $show = '', $filter = 'raw' ) {
switch( $show ) {
case 'home' : // DEPRECATED
case 'siteurl' : // DEPRECATED
_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%1$s</code> option is deprecated for the family of <code>bloginfo()</code> functions. Use the <code>%2$s</code> option instead.'), $show, 'url' ) );
_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> option instead.' ), 'url' ) );
case 'url' :
$output = home_url();
break;
@ -458,11 +458,8 @@ function get_bloginfo( $show = '', $filter = 'raw' ) {
$output = str_replace('_', '-', $output);
break;
case 'text_direction':
global $wp_locale;
if ( isset( $wp_locale ) )
$output = $wp_locale->text_direction;
else
$output = 'ltr';
//_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> function instead.' ), 'is_rtl()' ) );
return function_exists( 'is_rtl' ) ? is_rtl() : 'ltr';
break;
case 'name':
default:
@ -1874,8 +1871,8 @@ function language_attributes($doctype = 'html') {
$attributes = array();
$output = '';
if ( $dir = get_bloginfo('text_direction') )
$attributes[] = "dir=\"$dir\"";
if ( function_exists( 'is_rtl' ) )
$attributes[] = 'dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"';
if ( $lang = get_bloginfo('language') ) {
if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
@ -2112,7 +2109,7 @@ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
}
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . wp_admin_css_uri( $file ) . "' type='text/css' />\n", $file );
if ( 'rtl' == get_bloginfo( 'text_direction' ) )
if ( is_rtl() )
echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . wp_admin_css_uri( "$file-rtl" ) . "' type='text/css' />\n", "$file-rtl" );
}

View File

@ -128,7 +128,7 @@ wp_admin_css( 'wp-admin', true );
border-bottom: 0px;
}
</style>
<?php if ( ('rtl' == $wp_locale->text_direction) ) : ?>
<?php if ( is_rtl() ) : ?>
<style type="text/css">
#wphead, #tabs {
padding-left: auto;

View File

@ -326,6 +326,26 @@ class WP_Locale {
$this->init();
$this->register_globals();
}
/**
* Checks if current locale is RTL.
*
* @since 3.0.0
* @return bool Whether locale is RTL.
*/
function is_rtl() {
return 'rtl' == $this->text_direction;
}
}
/**
* Checks if current locale is RTL.
*
* @since 3.0.0
* @return bool Whether locale is RTL.
*/
function is_rtl() {
global $wp_locale;
return $wp_locale->is_rtl();
}
?>

View File

@ -781,7 +781,7 @@ function gallery_shortcode($attr) {
$captiontag = tag_escape($captiontag);
$columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$float = $wp_locale->text_direction == 'rtl' ? 'right' : 'left';
$float = is_rtl() ? 'right' : 'left';
$selector = "gallery-{$instance}";

View File

@ -372,7 +372,7 @@ function get_body_class( $class = '' ) {
$classes = array();
if ( 'rtl' == get_bloginfo( 'text_direction' ) )
if ( is_rtl() )
$classes[] = 'rtl';
if ( is_front_page() )

View File

@ -433,7 +433,7 @@ function wp_default_styles( &$styles ) {
$styles->base_url = $guessurl;
$styles->content_url = defined('WP_CONTENT_URL')? WP_CONTENT_URL : '';
$styles->default_version = get_bloginfo( 'version' );
$styles->text_direction = 'rtl' == get_bloginfo( 'text_direction' ) ? 'rtl' : 'ltr';
$styles->text_direction = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
$styles->default_dirs = array('/wp-admin/');
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '.dev' : '';

View File

@ -1580,7 +1580,7 @@ function add_editor_style( $stylesheet = 'editor-style.css' ) {
global $editor_styles;
$editor_styles = (array) $editor_styles;
$stylesheet = (array) $stylesheet;
if ('rtl' == get_bloginfo('text_direction') ) {
if ( is_rtl() ) {
$rtl_stylesheet = str_replace('.css', '-rtl.css', $stylesheet[0]);
$stylesheet[] = $rtl_stylesheet;
}