PluginProbe
Polylang / 3.7.7
Polylang v3.7.7
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 +44 -23 2.9.23.7.7 View file →
@@ -8,19 +8,37 @@
8 8 *
9 9 * @since 1.6
10 10 */
11 11 class PLL_Admin_Strings {
12 - protected static $strings = array(); // strings to translate
13 - protected static $default_strings; // default strings to register
12 + /**
13 + * Stores the strings to translate.
14 + *
15 + * @var array {
16 + * @type string $name A unique name for the string.
17 + * @type string $string The actual string to translate.
18 + * @type string $context The group in which the string is registered.
19 + * @type bool $multiline Whether the string table should display a multiline textarea or a single line input.
20 + * }
21 + */
22 + protected static $strings = array();
14 23
15 24 /**
25 + * The strings to register by default.
26 + *
27 + * @var string[]|null
28 + */
29 + protected static $default_strings;
30 +
31 + /**
16 32 * Add filters
17 33 *
18 34 * @since 1.6
35 + *
36 + * @return void
19 37 */
20 38 public static function init() {
21 39 // default strings translations sanitization
22 - add_filter( 'pll_sanitize_string_translation', array( __CLASS__, 'sanitize_string_translation' ), 10, 2 );
40 + add_filter( 'pll_sanitize_string_translation', array( self::class, 'sanitize_string_translation' ), 10, 2 );
23 41 }
24 42
25 43 /**
26 44 * Register strings for translation making sure it is not duplicate or empty
@@ -30,16 +48,11 @@
30 48 * @param string $name A unique name for the string
31 49 * @param string $string The string to register
32 50 * @param string $context Optional, the group in which the string is registered, defaults to 'polylang'
33 51 * @param bool $multiline Optional, whether the string table should display a multiline textarea or a single line input, defaults to single line
52 + * @return void
34 53 */
35 54 public static function register_string( $name, $string, $context = 'Polylang', $multiline = false ) {
36 - // Backward compatibility with Polylang older than 1.1
37 - if ( is_bool( $context ) ) {
38 - $multiline = $context;
39 - $context = 'Polylang';
40 - }
41 -
42 55 if ( $string && is_scalar( $string ) ) {
43 56 self::$strings[ md5( $string ) ] = compact( 'name', 'string', 'context', 'multiline' );
44 57 }
45 58 }
@@ -56,9 +69,8 @@
56 69 'widget_title' => __( 'Widget title', 'polylang' ),
57 70 'widget_text' => __( 'Widget text', 'polylang' ),
58 71 );
59 72
60 - // Widgets titles
61 73 global $wp_registered_widgets;
62 74 $sidebars = wp_get_sidebars_widgets();
63 75 foreach ( $sidebars as $sidebar => $widgets ) {
64 76 if ( 'wp_inactive_widgets' == $sidebar || empty( $widgets ) ) {
@@ -65,26 +77,35 @@
65 77 continue;
66 78 }
67 79
68 80 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
71 - 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' ) ) {
81 + // Nothing can be done if the widget is created using pre WP2.8 API. There is no object, so we can't access it to get the widget options.
82 + if ( ! isset( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! $wp_registered_widgets[ $widget ]['callback'][0] instanceof WP_Widget ) {
72 83 continue;
73 84 }
74 85
75 - $widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings();
76 - $number = $wp_registered_widgets[ $widget ]['params'][0]['number'];
86 + $widget_instance = $wp_registered_widgets[ $widget ]['callback'][0];
87 + $widget_settings = $widget_instance->get_settings();
88 + $number = $wp_registered_widgets[ $widget ]['params'][0]['number'];
77 89
78 - // Don't enable widget translation if the widget is visible in only one language or if there is no title
79 - if ( empty( $widget_settings[ $number ]['pll_lang'] ) ) {
80 - if ( isset( $widget_settings[ $number ]['title'] ) && $title = $widget_settings[ $number ]['title'] ) {
81 - self::register_string( self::$default_strings['widget_title'], $title, 'Widget' );
82 - }
90 + // Don't enable widget translation if the widget is visible in only one language or if there is no title.
91 + if ( ! empty( $widget_settings[ $number ]['pll_lang'] ) ) {
92 + continue;
93 + }
83 94
84 - if ( isset( $widget_settings[ $number ]['text'] ) && $text = $widget_settings[ $number ]['text'] ) {
85 - self::register_string( self::$default_strings['widget_text'], $text, 'Widget', true );
86 - }
95 + // Widget title.
96 + if ( ! empty( $widget_settings[ $number ]['title'] ) ) {
97 + self::register_string( self::$default_strings['widget_title'], $widget_settings[ $number ]['title'], 'Widget' );
98 + }
99 +
100 + // Text of the Widget text.
101 + if ( ! empty( $widget_settings[ $number ]['text'] ) ) {
102 + self::register_string( self::$default_strings['widget_text'], $widget_settings[ $number ]['text'], 'Widget', true );
103 + }
104 +
105 + // Content of the widget custom html.
106 + if ( $widget_instance instanceof WP_Widget_Custom_HTML && ! empty( $widget_settings[ $number ]['content'] ) ) {
107 + self::register_string( self::$default_strings['widget_text'], $widget_settings[ $number ]['content'], 'Widget', true );
87 108 }
88 109 }
89 110 }
90 111