esc_html__('WordPress 链接(书签)列表,适合友链/导航。', 'aksrt'), 'classname' => 'widget_aksrt_bookmark_links', ] ); } public function widget($args, $instance): void { $limit = max(0, min(100, (int) ($instance['links_limit'] ?? 12))); $orderby = sanitize_key((string) ($instance['links_orderby'] ?? 'name')); if (!in_array($orderby, ['name', 'updated', 'rating', 'rand', 'id'], true)) { $orderby = 'name'; } $order = strtoupper((string) ($instance['links_order'] ?? 'ASC')) === 'DESC' ? 'DESC' : 'ASC'; $type = sanitize_key((string) ($instance['type'] ?? 'card')); if (!in_array($type, ['card', 'image', 'simple'], true)) { $type = 'card'; } $go_link = !empty($instance['go_link']); $blank = !isset($instance['blank']) || !empty($instance['blank']); $nofollow = !empty($instance['nofollow']); $show_box = !empty($instance['show_box']); $bm_args = [ 'orderby' => $orderby === 'rand' ? 'rand' : $orderby, 'order' => $order, 'limit' => $limit > 0 ? $limit : -1, ]; $cats = trim((string) ($instance['links_cats'] ?? '')); if ($cats !== '' && $cats !== 'all') { $bm_args['category'] = $cats; } $bookmarks = get_bookmarks($bm_args); if (!$bookmarks) { return; } echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base); if ($title !== '') { echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } $wrap = 'aksrt-bookmark-links style-' . $type . ($show_box ? ' has-box' : ''); echo '