| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * A fully static class to manage strings translations on admin side |
| 8 | 5 | * |
| @@ -8,10 +5,10 @@ | ||
| 8 | 5 | * |
| 9 | 6 | * @since 1.6 |
| 10 | 7 | */ |
| 11 | 8 | class PLL_Admin_Strings { |
| 12 | - protected static $strings = array(); // strings to translate | |
| 13 | - protected static $default_strings; // default strings to register | |
| 9 | + static protected $strings = array(); // strings to translate | |
| 10 | + static protected $default_strings; // default strings to register | |
| 14 | 11 | |
| 15 | 12 | /** |
| 16 | 13 | * Add filters |
| 17 | 14 | * |
| @@ -52,12 +49,23 @@ | ||
| 52 | 49 | * @return array list of all registered strings |
| 53 | 50 | */ |
| 54 | 51 | public static function &get_strings() { |
| 55 | 52 | self::$default_strings = array( |
| 53 | + 'options' => array( | |
| 54 | + 'blogname' => __( 'Site Title' ), | |
| 55 | + 'blogdescription' => __( 'Tagline' ), | |
| 56 | + 'date_format' => __( 'Date Format' ), | |
| 57 | + 'time_format' => __( 'Time Format' ), | |
| 58 | + ), | |
| 56 | 59 | 'widget_title' => __( 'Widget title', 'polylang' ), |
| 57 | 60 | 'widget_text' => __( 'Widget text', 'polylang' ), |
| 58 | 61 | ); |
| 59 | 62 | |
| 63 | + // WP strings | |
| 64 | + foreach ( self::$default_strings['options'] as $option => $string ) { | |
| 65 | + self::register_string( $string, get_option( $option ), 'WordPress' ); | |
| 66 | + } | |
| 67 | + | |
| 60 | 68 | // Widgets titles |
| 61 | 69 | global $wp_registered_widgets; |
| 62 | 70 | $sidebars = wp_get_sidebars_widgets(); |
| 63 | 71 | foreach ( $sidebars as $sidebar => $widgets ) { |
| @@ -109,14 +117,20 @@ | ||
| 109 | 117 | * @param string $name unique name for the string |
| 110 | 118 | * @return string |
| 111 | 119 | */ |
| 112 | 120 | public static function sanitize_string_translation( $translation, $name ) { |
| 121 | + $translation = wp_unslash( trim( $translation ) ); | |
| 122 | + | |
| 123 | + if ( false !== ( $option = array_search( $name, self::$default_strings['options'], true ) ) ) { | |
| 124 | + $translation = sanitize_option( $option, $translation ); | |
| 125 | + } | |
| 126 | + | |
| 113 | 127 | if ( $name == self::$default_strings['widget_title'] ) { |
| 114 | - $translation = sanitize_text_field( $translation ); | |
| 128 | + $translation = strip_tags( $translation ); | |
| 115 | 129 | } |
| 116 | 130 | |
| 117 | 131 | if ( $name == self::$default_strings['widget_text'] && ! current_user_can( 'unfiltered_html' ) ) { |
| 118 | - $translation = wp_kses_post( $translation ); | |
| 132 | + $translation = wp_unslash( wp_filter_post_kses( addslashes( $translation ) ) ); // wp_filter_post_kses() expects slashed | |
| 119 | 133 | } |
| 120 | 134 | |
| 121 | 135 | return $translation; |
| 122 | 136 | } |