esc_html__('自定义标题 + 副标题区块,支持逐字入场动画。', 'aksrt'), 'classname' => 'widget_aksrt_text_title', ] ); } /** * @param array $args * @param array $instance */ public function widget($args, $instance): void { $title = trim((string) ($instance['title'] ?? '')); $desc = trim((string) ($instance['desc'] ?? '')); if ($title === '' && $desc === '') { 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; } $align = sanitize_key((string) ($instance['align'] ?? 'center')); if (!in_array($align, ['left', 'center', 'right'], true)) { $align = 'center'; } $icon_left = sanitize_text_field((string) ($instance['title_icon_left'] ?? '')); $icon_right = sanitize_text_field((string) ($instance['title_icon_right'] ?? '')); $title_size = max(12, min(48, (int) ($instance['title_size'] ?? 22))); $desc_size = max(11, min(24, (int) ($instance['desc_size'] ?? 14))); $title_color = sanitize_hex_color((string) ($instance['title_color'] ?? '')) ?: ''; $desc_color = sanitize_hex_color((string) ($instance['desc_color'] ?? '')) ?: ''; $anim = sanitize_key((string) ($instance['obs_animation'] ?? '')); $anim_repeat = !empty($instance['animation_repeat']); $icon_width = max(0, min(64, (int) ($instance['title_icon_width'] ?? 0))); echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $style = sprintf( '--aksrt-tt-title-size:%dpx;--aksrt-tt-desc-size:%dpx;%s%s', $title_size, $desc_size, $title_color !== '' ? '--aksrt-tt-title-color:' . $title_color . ';' : '', $desc_color !== '' ? '--aksrt-tt-desc-color:' . $desc_color . ';' : '' ); $icon_w_attr = $icon_width > 0 ? ' style="--icon-width:' . (int) $icon_width . 'px;"' : ''; $left_html = $icon_left !== '' ? '' : ''; $right_html = $icon_right !== '' ? '' : ''; $title_html = ''; if ($title !== '' && $anim !== '' && function_exists('aksrt_obs_animate_attrs')) { // Split title into per-char spans with staggered delay (zibll). $chars = preg_split('//u', $title, -1, PREG_SPLIT_NO_EMPTY) ?: []; $pieces = []; if ($left_html !== '') { $pieces[] = $left_html; } foreach ($chars as $ch) { $pieces[] = $ch; } if ($right_html !== '') { $pieces[] = $right_html; } foreach ($pieces as $i => $piece) { $pack = aksrt_obs_animate_attrs($anim, $anim_repeat, $i * 0.05); $is_html = str_starts_with((string) $piece, '<'); $inner = $is_html ? $piece : esc_html((string) $piece); $title_html .= '' . $inner . ''; } } elseif ($title !== '') { $title_html = $left_html . esc_html($title) . $right_html; } $desc_html = ''; if ($desc !== '') { if ($anim !== '' && function_exists('aksrt_obs_animate_attrs')) { $pack = aksrt_obs_animate_attrs($anim, $anim_repeat, 0.6); $desc_html = '
' . esc_html($desc) . '
'; } else { $desc_html = '
' . esc_html($desc) . '
'; } } $in_affix = !empty($instance['in_affix']); $box = 'aksrt-text-title text-title align-' . esc_attr($align) . ($in_affix ? ' is-affix' : ''); echo '
'; if ($title_html !== '') { echo '
' . $title_html . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } echo $desc_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo '
'; echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * @param array $instance */ public function form($instance): void { ?>

$new_instance * @param array $old_instance * @return array */ public function update($new_instance, $old_instance): array { return [ 'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')), 'desc' => sanitize_text_field((string) ($new_instance['desc'] ?? '')), 'align' => in_array(($new_instance['align'] ?? ''), ['left', 'center', 'right'], true) ? $new_instance['align'] : 'center', 'title_icon_left' => sanitize_text_field((string) ($new_instance['title_icon_left'] ?? '')), 'title_icon_right' => sanitize_text_field((string) ($new_instance['title_icon_right'] ?? '')), 'title_size' => max(12, min(48, (int) ($new_instance['title_size'] ?? 22))), 'desc_size' => max(11, min(24, (int) ($new_instance['desc_size'] ?? 14))), 'title_color' => sanitize_hex_color((string) ($new_instance['title_color'] ?? '')) ?: '', 'desc_color' => sanitize_hex_color((string) ($new_instance['desc_color'] ?? '')) ?: '', 'obs_animation' => sanitize_key((string) ($new_instance['obs_animation'] ?? '')), 'animation_repeat' => !empty($new_instance['animation_repeat']) ? 1 : 0, 'title_icon_width' => max(0, min(64, (int) ($new_instance['title_icon_width'] ?? 0))), ]; } }