WordPress.org

Plugin Directory

Changeset 549679


Ignore:
Timestamp:
05/28/12 07:16:24 (2 years ago)
Author:
yoavf
Message:

rtl-tester:1.0.2

Location:
rtl-tester
Files:
7 added
2 edited

Legend:

Unmodified
Added
Removed
  • rtl-tester/trunk/readme.txt

    r381367 r549679  
    33Tags: RTL, testing 
    44Requires at least: 3.1 
    5 Stable tag: 1.0.1 
    6 Tested up to: 3.2 
     5Stable tag: 1.0.2 
     6Tested up to: 3.4 
    77 
    88Test your themes and plugins in RTL mode. 
     
    1818== Changelog == 
    1919 
     20= 1.0.2 = 
     21Cleanup, bug fix 
    2022 
    2123= 1.0.1 = 
  • rtl-tester/trunk/rtl-tester.php

    r381367 r549679  
    11<?php 
    22/** 
     3 * RTL-Tester plugin. 
     4 * 
     5 * Adds a button to the admin bar that allow super admins to switch the text direction of the site. 
     6 * 
    37 * @package RTL_Tester 
    4  * @version 1.0.1 
     8 * @author Automattic 
     9 * @author Yoav Farhi 
     10 * @version 1.0.2 
     11 * 
     12 * @wordpress 
     13 * Plugin Name: RTL Tester 
     14 * Plugin URI: http://wordpress.org/extend/plugins/rtl-tester/ 
     15 * Description: This plugin adds a button to the admin bar that allow super admins to switch the text direction of the site. It can be used to test WordPress themes and plugins with Right To Left (RTL) text direction. 
     16 * Author: <a href="http://blog.yoavfarhi.com">Yoav Farhi</a>, <a href="http://automattic.com">Automattic</a> 
     17 * Version: 1.0.2 
    518 */ 
    6 /* 
    7 Plugin Name: RTL Tester 
    8 Plugin URI: http://wordpress.org/extend/plugins/rtl-tester/ 
    9 Description: This plugin adds a button to the admin bar that allow super admins to switch the text direction of the site. It can be used to test WordPress themes and plugins with Right To Left (RTL) text direction. 
    10 Author: <a href="http://blog.yoavfarhi.com">Yoav Farhi</a>, <a href="http://automattic.com">Automattic</a> 
    11 Version: 1.0.1 
    12 */ 
    1319 
    14  
     20/** 
     21 * Plugin class for RTL Tester plugin 
     22 * 
     23 * @package RTL_Tester 
     24 */ 
    1525class RTLTester { 
    1626 
     27    /** 
     28     * Loads plugin textdomain, and hooks in further actions. 
     29     */ 
    1730    function __construct() { 
    1831 
    1932        load_plugin_textdomain( 'rtl-tester', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
    2033 
     34        add_action( 'init', array( $this, 'set_direction' ) ); 
    2135        add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); 
    22         add_action( 'init', array( $this, 'set_direction' ) ); 
    2336    } 
    2437 
     38    /** 
     39     * Adds button to admin bar. 
     40     * 
     41     * @global object $wp_admin_bar Most likely instance of WP_Admin_Bar but this is filterable. 
     42     *  
     43     * @return null Retuns early if not site admin, or admin bar should not be showing.  
     44     */ 
    2545    function admin_bar_rtl_switcher() { 
    2646        global $wp_admin_bar; 
    2747 
    28         if ( !is_super_admin() || !is_admin_bar_showing() ) 
     48        if ( ! is_super_admin() || ! is_admin_bar_showing() ) 
    2949          return; 
    3050 
    31         $direction = $this->get_direction(); 
    32         $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; 
     51        // Get opposite direction for button text 
     52        $direction = is_rtl() ? 'ltr' : 'rtl'; 
    3353 
    34         $wp_admin_bar->add_menu(array( 
    35             'id' => 'RTL', 
    36             'title' => sprintf( __('Switch to %s', 'rtl-tester'), strtoupper( $direction ) ), 
    37             'href' => add_query_arg( array( 'd' => $direction ) ) 
    38         ) ); 
     54        $wp_admin_bar->add_menu( 
     55            array( 
     56                'id'    => 'RTL', 
     57                'title' => sprintf( __( 'Switch to %s', 'rtl-tester' ), strtoupper( $direction ) ), 
     58                'href'  => add_query_arg( array( 'd' => $direction ) ) 
     59            ) 
     60        ); 
    3961    } 
    4062 
     63    /** 
     64     * Save the currently chosen direction on a per-user basis. 
     65     * 
     66     * @global WP_Locale $wp_locale Locale object. 
     67     * @global WP_Styles $wp_styles Styles object. 
     68     */ 
    4169    function set_direction() { 
    42         global $wp_locale; 
     70        global $wp_locale, $wp_styles; 
    4371 
    4472        $_user_id = get_current_user_id(); 
     
    5280                $direction = $wp_locale->text_direction; 
    5381        } 
    54  
    55         $wp_locale->text_direction = $direction; 
    56  
     82        $wp_locale->text_direction = $direction;         
     83        $wp_styles->text_direction = $direction; 
    5784    } 
    5885 
    59     function get_direction() { 
    60         $direction = is_rtl() ? 'rtl' : 'ltr'; 
    61         return $direction; 
    62     } 
    6386} 
    6487 
    6588new RTLTester; 
    66  
    67 ?> 
Note: See TracChangeset for help on using the changeset viewer.