WordPress.org

Plugin Directory

Changeset 381205


Ignore:
Timestamp:
05/05/11 11:35:53 (3 years ago)
Author:
yoavf
Message:

Overhaul: the plugin is now activated via the admin bar - settings are saved per user (for admins only). The one string used is also translatable

Location:
rtl-tester/trunk
Files:
4 added
2 edited

Legend:

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

    r248628 r381205  
    22Contributors: automattic, yoavf 
    33Tags: RTL, testing 
    4 Requires at least: 2.8 
    5 Stable tag: 0.2 
    6 Tested up to: 3.0 
     4Requires at least: 3.1 
     5Stable tag: 1 
     6Tested up to: 3.2 
    77 
    88Test your themes and plugins in RTL mode. 
     
    1010== Description == 
    1111 
    12 This plugin can be used to test WordPress themes and plugins with Right To Left (RTL) text direction. 
    13 Simply activate this plugin to enable RTL and deactivate to return to normal operation. 
     12This 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.  
    1413 
    1514== Installation == 
     
    1918== Changelog == 
    2019 
    21 = 0.1 = 
    22 Initial version. 
     20 
     21= 1 = 
     22Activate RTL/LTR via the admin bar. Settings are per user, for admins only. 
    2323 
    2424= 0.2 = 
    2525No more hooks - sets the text_direction variable on load. 
    2626Probably the simplest, yet useful, plugin in the repository :) 
     27 
     28= 0.1 = 
     29Initial version. 
     30 
     31 
  • rtl-tester/trunk/rtl-tester.php

    r247820 r381205  
    22/** 
    33 * @package RTL_Tester 
    4  * @version 0.1 
     4 * @version 1.0 
    55 */ 
    66/* 
    77Plugin Name: RTL Tester 
    88Plugin URI: http://wordpress.org/extend/plugins/rtl-tester/ 
    9 Description: This plugin can be used to test WordPress themes and plugins with Right To Left (RTL) text direction. Simply activate this plugin to enable RTL and deactivate to return to normal operation. Yes, this is simplest plugin in the world. 
     9Description: 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. 
    1010Author: <a href="http://blog.yoavfarhi.com">Yoav Farhi</a>, <a href="http://automattic.com">Automattic</a> 
    11 Version: 0.2 
     11Version: 1.0 
    1212*/ 
    1313 
    14 $text_direction = 'rtl'; 
     14 
     15class RTLTester { 
     16 
     17    function __construct() { 
     18 
     19        load_plugin_textdomain( 'rtl-tester', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 
     20 
     21        add_action( 'admin_bar_menu', array( $this, 'admin_bar_rtl_switcher' ), 999 ); 
     22        add_action( 'init', array( $this, 'set_direction' ) ); 
     23    } 
     24 
     25    function admin_bar_rtl_switcher() { 
     26        global $wp_admin_bar; 
     27 
     28        if ( !is_super_admin() || !is_admin_bar_showing() ) 
     29          return; 
     30 
     31        $direction = $this->get_direction(); 
     32        $direction = $direction == 'rtl' ? 'ltr' : 'rtl'; 
     33 
     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        ) ); 
     39    } 
     40 
     41    function set_direction() { 
     42        global $wp_locale; 
     43 
     44        $_user_id = get_current_user_id(); 
     45 
     46        if ( isset( $_GET['d'] ) ) { 
     47            $direction = $_GET['d'] == 'rtl' ? 'rtl' : 'ltr'; 
     48            update_user_meta( $_user_id, 'rtladminbar', $direction ); 
     49        } else { 
     50            $direction = get_user_meta( $_user_id, 'rtladminbar', true ); 
     51            if ( false === $direction ) 
     52                $direction = $wp_locale->text_direction; 
     53        } 
     54 
     55        $wp_locale->text_direction = $direction; 
     56 
     57    } 
     58 
     59    function get_direction() { 
     60        $direction = is_rtl() ? 'rtl' : 'ltr'; 
     61        return $direction; 
     62    } 
     63} 
     64 
     65new RTLTester; 
    1566 
    1667?> 
Note: See TracChangeset for help on using the changeset viewer.