__('在侧栏显示多语言切换按钮。', 'aksrt'), 'classname' => 'widget_aksrt_lang_switch', ] ); } /** * @param array $args * @param array $instance */ public function widget($args, $instance): void { $title = !empty($instance['title']) ? (string) $instance['title'] : ''; $style = sanitize_key((string) ($instance['style'] ?? 'dropdown')); if (!in_array($style, ['dropdown', 'flags', 'inline'], true)) { $style = 'dropdown'; } $show_name = !isset($instance['show_name']) || !empty($instance['show_name']); $hide_current = !empty($instance['hide_current']); if (!function_exists('aksrt_has_multilingual') || !aksrt_has_multilingual()) { if (current_user_can('manage_options')) { echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '
' . esc_html__('语言切换:', 'aksrt') . '' . esc_html__('未检测到多语言插件(Polylang/WPML)或可用语言不足。', 'aksrt') . '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } return; } // inline style: treat as flags row without dropdown chrome. $render_style = $style === 'inline' ? 'flags' : $style; $html = function_exists('aksrt_render_language_switcher') ? aksrt_render_language_switcher($render_style) : ''; if ($html === '') { if (current_user_can('manage_options')) { echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo function_exists('aksrt_get_widget_null') ? aksrt_get_widget_null(__('暂无可用语言', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped : '

' . esc_html__('暂无可用语言', 'aksrt') . '

'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } return; } // Optional modifiers via wrapper classes. $wrap = 'aksrt-lang-switch-widget style-' . esc_attr($style); if (!$show_name) { $wrap .= ' hide-name'; } if ($hide_current) { $wrap .= ' hide-current'; } echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped if ($title !== '') { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo '
' . $html . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * @param array $instance */ public function form($instance): void { $title = !empty($instance['title']) ? (string) $instance['title'] : ''; $style = !empty($instance['style']) ? (string) $instance['style'] : 'dropdown'; ?>


render_common_form_section($instance); } /** * @param array $new_instance * @param array $old_instance * @return array */ public function update($new_instance, $old_instance): array { $style = sanitize_key((string) ($new_instance['style'] ?? 'dropdown')); if (!in_array($style, ['dropdown', 'flags', 'inline'], true)) { $style = 'dropdown'; } $business = [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'style' => $style, 'show_name' => !empty($new_instance['show_name']) ? 1 : 0, 'hide_current' => !empty($new_instance['hide_current']) ? 1 : 0, ]; return $this->update_common_fields($new_instance, $old_instance, $business); } }