| @@ -23,9 +23,9 @@ | ||
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * The strings to register by default. |
| 26 | 26 | * |
| 27 | - * @var string[] | |
| 27 | + * @var string[]|null | |
| 28 | 28 | */ |
| 29 | 29 | protected static $default_strings; |
| 30 | 30 | |
| 31 | 31 | /** |
| @@ -36,9 +36,9 @@ | ||
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | 38 | public static function init() { |
| 39 | 39 | // default strings translations sanitization |
| 40 | - 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 ); | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | 44 | * Register strings for translation making sure it is not duplicate or empty |
| @@ -69,9 +69,8 @@ | ||
| 69 | 69 | 'widget_title' => __( 'Widget title', 'polylang' ), |
| 70 | 70 | 'widget_text' => __( 'Widget text', 'polylang' ), |
| 71 | 71 | ); |
| 72 | 72 | |
| 73 | - // Widgets titles | |
| 74 | 73 | global $wp_registered_widgets; |
| 75 | 74 | $sidebars = wp_get_sidebars_widgets(); |
| 76 | 75 | foreach ( $sidebars as $sidebar => $widgets ) { |
| 77 | 76 | if ( 'wp_inactive_widgets' == $sidebar || empty( $widgets ) ) { |
| @@ -78,26 +77,35 @@ | ||
| 78 | 77 | continue; |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | foreach ( $widgets as $widget ) { |
| 82 | - // Nothing can be done if the widget is created using pre WP2.8 API :( | |
| 83 | - // There is no object, so we can't access it to get the widget options | |
| 84 | - 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 ) { | |
| 85 | 83 | continue; |
| 86 | 84 | } |
| 87 | 85 | |
| 88 | - $widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings(); | |
| 89 | - $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']; | |
| 90 | 89 | |
| 91 | - // Don't enable widget translation if the widget is visible in only one language or if there is no title | |
| 92 | - if ( empty( $widget_settings[ $number ]['pll_lang'] ) ) { | |
| 93 | - if ( isset( $widget_settings[ $number ]['title'] ) && $title = $widget_settings[ $number ]['title'] ) { | |
| 94 | - self::register_string( self::$default_strings['widget_title'], $title, 'Widget' ); | |
| 95 | - } | |
| 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 | + } | |
| 96 | 94 | |
| 97 | - if ( isset( $widget_settings[ $number ]['text'] ) && $text = $widget_settings[ $number ]['text'] ) { | |
| 98 | - self::register_string( self::$default_strings['widget_text'], $text, 'Widget', true ); | |
| 99 | - } | |
| 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 ); | |
| 100 | 108 | } |
| 101 | 109 | } |
| 102 | 110 | } |
| 103 | 111 | |