PluginProbe
Polylang / 2.3.6
Polylang v2.3.6
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | admin/admin-strings.php +35 -21 2.9.12.3.6 View file →
@@ -1,30 +1,27 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * A fully static class to manage strings translations on admin side
4 + * a fully static class to manage strings translations on admin side
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 - * Add filters
13 + * init: add filters
17 14 *
18 15 * @since 1.6
19 16 */
20 - public static function init() {
17 + static public function init() {
21 18 // default strings translations sanitization
22 19 add_filter( 'pll_sanitize_string_translation', array( __CLASS__, 'sanitize_string_translation' ), 10, 2 );
23 20 }
24 21
25 22 /**
26 - * Register strings for translation making sure it is not duplicate or empty
23 + * register strings for translation making sure it is not duplicate or empty
27 24 *
28 25 * @since 0.6
29 26 *
30 27 * @param string $name A unique name for the string
@@ -31,10 +28,10 @@
31 28 * @param string $string The string to register
32 29 * @param string $context Optional, the group in which the string is registered, defaults to 'polylang'
33 30 * @param bool $multiline Optional, whether the string table should display a multiline textarea or a single line input, defaults to single line
34 31 */
35 - public static function register_string( $name, $string, $context = 'Polylang', $multiline = false ) {
36 - // Backward compatibility with Polylang older than 1.1
32 + static public function register_string( $name, $string, $context = 'Polylang', $multiline = false ) {
33 + // backward compatibility with Polylang older than 1.1
37 34 if ( is_bool( $context ) ) {
38 35 $multiline = $context;
39 36 $context = 'Polylang';
40 37 }
@@ -44,21 +41,32 @@
44 41 }
45 42 }
46 43
47 44 /**
48 - * Get registered strings
45 + * get registered strings
49 46 *
50 47 * @since 0.6.1
51 48 *
52 49 * @return array list of all registered strings
53 50 */
54 - public static function &get_strings() {
51 + static public 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
60 - // Widgets titles
63 + // WP strings
64 + foreach ( self::$default_strings['options'] as $option => $string ) {
65 + self::register_string( $string, get_option( $option ), 'WordPress' );
66 + }
67 +
68 + // widgets titles
61 69 global $wp_registered_widgets;
62 70 $sidebars = wp_get_sidebars_widgets();
63 71 foreach ( $sidebars as $sidebar => $widgets ) {
64 72 if ( 'wp_inactive_widgets' == $sidebar || empty( $widgets ) ) {
@@ -65,10 +73,10 @@
65 73 continue;
66 74 }
67 75
68 76 foreach ( $widgets as $widget ) {
69 - // Nothing can be done if the widget is created using pre WP2.8 API :(
70 - // There is no object, so we can't access it to get the widget options
77 + // nothing can be done if the widget is created using pre WP2.8 API :(
78 + // there is no object, so we can't access it to get the widget options
71 79 if ( ! isset( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! is_object( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! method_exists( $wp_registered_widgets[ $widget ]['callback'][0], 'get_settings' ) ) {
72 80 continue;
73 81 }
74 82
@@ -74,9 +82,9 @@
74 82
75 83 $widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings();
76 84 $number = $wp_registered_widgets[ $widget ]['params'][0]['number'];
77 85
78 - // Don't enable widget translation if the widget is visible in only one language or if there is no title
86 + // don't enable widget translation if the widget is visible in only one language or if there is no title
79 87 if ( empty( $widget_settings[ $number ]['pll_lang'] ) ) {
80 88 if ( isset( $widget_settings[ $number ]['title'] ) && $title = $widget_settings[ $number ]['title'] ) {
81 89 self::register_string( self::$default_strings['widget_title'], $title, 'Widget' );
82 90 }
@@ -100,9 +108,9 @@
100 108 return self::$strings;
101 109 }
102 110
103 111 /**
104 - * Performs the sanitization ( before saving in DB ) of default strings translations
112 + * performs the sanitization ( before saving in DB ) of default strings translations
105 113 *
106 114 * @since 1.6
107 115 *
108 116 * @param string $translation translation to sanitize
@@ -108,15 +116,21 @@
108 116 * @param string $translation translation to sanitize
109 117 * @param string $name unique name for the string
110 118 * @return string
111 119 */
112 - public static function sanitize_string_translation( $translation, $name ) {
120 + static public 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 }