'; $user_id = get_current_user_id(); if (!$user_id) { return '' . $icon . ''; } $level = function_exists('aksrt_get_user_vip_level') ? (int) aksrt_get_user_vip_level($user_id) : 0; if ($level && !($level < 2 && $vip2_s)) { return ''; } $title = 1 === $level ? __('升级会员', 'aksrt') : __('开通会员', 'aksrt'); $open_level = $vip2_s ? 2 : 1; return '' . $icon . ''; } endif; if (!function_exists('aksrt_get_float_add_html')) : /** * 发布按钮:当前仅文章投稿,对应参考主题单按钮分支(直接链接)。 */ function aksrt_get_float_add_html(string $icon, string $style, bool $is_mobile): string { if (!function_exists('aksrt_get_new_add_actions')) { return ''; } if (class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::close_sign()) { return ''; } $actions = aksrt_get_new_add_actions(['post']); if (!$actions) { return ''; } $a = $actions[0]; $icon_html = $icon !== '' ? aksrt_icon_markup($icon) : ''; if ($icon_html === '') { $icon_html = ''; } return '' . $icon_html . ''; } endif; if (!function_exists('aksrt_get_float_more_html')) : /** * 更多(自定义)按钮组。 */ function aksrt_get_float_more_html(array $buttons, bool $is_mobile): string { $html = ''; foreach ($buttons as $opt) { if (!is_array($opt)) { continue; } if (!(($is_mobile && !empty($opt['m_s'])) || (!$is_mobile && !empty($opt['pc_s'])))) { continue; } $style = aksrt_float_btn_style_attr($opt['color'] ?? []); $class = 'float-btn more-btn'; $hover = ''; $tag = 'a'; $tooltip = true; $hover_html = (string) ($opt['hover'] ?? ''); if ($hover_html !== '') { $tag = 'span'; $tooltip = false; $class .= ' hover-show'; $width = (int) ($opt['hover_width'] ?? 200); $hover_style = $width && 200 !== $width ? ' style="width:' . $width . 'px;"' : ''; $hover = '' . wp_kses_post($hover_html) . ''; } $icon = aksrt_icon_markup((string) ($opt['icon'] ?? '')); if ($icon === '') { $icon = ''; } $url = (string) ($opt['link']['url'] ?? ''); $href = ($tag === 'a' && $url !== '') ? esc_url($url) : 'javascript:;'; $target = ($tag === 'a' && $url !== '' && ($opt['link']['target'] ?? '') === '_blank') ? ' target="_blank" rel="noopener"' : ''; $desc = (string) ($opt['desc'] ?? ''); $title = $desc !== '' ? ($tooltip ? aksrt_float_btn_tooltip_attr($desc, $is_mobile) : ' title="' . esc_attr($desc) . '"') : ''; if ('javascript:;' === $href) { $class .= ' nowave'; } $href_attr = $tag === 'a' ? ' href="' . $href . '"' : ''; $html .= '<' . $tag . $style . ' class="' . esc_attr($class) . '"' . $target . $title . $href_attr . '>' . $icon . $hover . ''; } return $html; } endif; if (!function_exists('aksrt_float_right')) : /** * 输出右侧悬浮按钮。 */ function aksrt_float_right(): void { if (!class_exists('\AKSRT\Settings\Settings') || is_page_template('templates/pages/page-submit.php')) { return; } $settings = \AKSRT\Settings\Settings::get_floating_buttons_settings(); $items = is_array($settings['items'] ?? null) ? $settings['items'] : []; $is_mobile = wp_is_mobile(); $btn = ''; foreach ($items as $opt) { $type = (string) ($opt['type'] ?? ''); if ('more' !== $type && ((empty($opt['pc_s']) && !$is_mobile) || (empty($opt['m_s']) && $is_mobile))) { continue; } $style = aksrt_float_btn_style_attr($opt['color'] ?? []); switch ($type) { case 'theme_mode': $btn .= ''; break; case 'back_top': $btn .= ''; break; case 'service_qq': $qq = (string) ($opt['qq'] ?? ''); if ($qq !== '') { $href = 'https://wpa.qq.com/msgrd?v=3&uin=' . $qq . '&site=qq&menu=yes'; $btn .= ''; } break; case 'pay_vip': $btn .= aksrt_get_float_pay_vip_html($style, $is_mobile); break; case 'service_wechat': $img = (string) ($opt['wechat_img'] ?? ''); if ($img !== '') { $alt = sprintf(__('扫码添加微信%s', 'aksrt'), ' - ' . get_bloginfo('name')); $img_attr = function_exists('aksrt_get_lazy_attr') ? aksrt_get_lazy_attr('lazy_other', $img, 'radius4 relative') : ' class="radius4 relative" src="' . esc_url($img) . '"'; $btn .= '' . ''; } break; case 'qrcode': $desc = (string) ($opt['desc'] ?? ''); $desc = $desc !== '' ? '
' . esc_html($desc) . '
' : ''; $btn .= '' . ''; break; case 'add': // 当前仅支持文章投稿,发布类型固定为 post。 $btn .= aksrt_get_float_add_html((string) ($opt['icon'] ?? ''), $style, $is_mobile); break; case 'more': $btn .= aksrt_get_float_more_html((array) ($opt['buttons'] ?? []), $is_mobile); break; } } if ($btn === '') { return; } // 扩展点(对齐参考主题 zib_float_right filter):模块可注入自定义悬浮按钮。 $btn = (string) apply_filters('aksrt_float_right_buttons', $btn, $is_mobile); if ($btn === '') { return; } $filter = (array) ($settings['filter_blur'] ?? []); $class = ($settings['style'] ?? 'round') . ' position-' . ($settings['position'] ?? 'bottom'); $class .= (($is_mobile && in_array('m_s', $filter, true)) || (!$is_mobile && in_array('pc_s', $filter, true))) ? ' filter' : ''; $class .= !empty($settings['scroll_hide']) ? ' scrolling-hide' : ''; $class .= !empty($settings['scroll_down_hide']) ? ' scroll-down-hide' : ''; echo '
' . $btn . '
'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- 各片段已转义 } add_action('wp_footer', 'aksrt_float_right'); endif;