feat(float): rebuild right floating buttons 1:1 with reference theme
- Storage: aksrt_floating_buttons now uses reference float_btn shape (fixed 8 sortable types, more-buttons group); single source of defaults/sanitize in AKSRT\Settings\FloatButtons - Admin SPA: CSF-parity page split into components/floating/* - Frontend: aksrt_float_right() on wp_footer mirrors zib_float_right() (wp_is_mobile, PC tooltip, toggle-theme, ontop/scrollTopTo, qrcode, wechat/qq, pay_vip, add, more) - CSS: floating-buttons.css rewritten from reference rules; legacy float rules removed from main/part/shell/overlay-primitives - Remove dead code: reorder route/API, get_floating_buttons_items, floatingSchema, floatActionsId, float-theme-toggle bindings, common/floating.css, aksrt-runtime-win.php, .aksrt-float-btn
This commit is contained in:
@@ -47,11 +47,6 @@ class GlobalController extends ControllerBase {
|
||||
'callback' => [$this, 'rest_handle_floating_buttons'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
]);
|
||||
register_rest_route(self::API_NAMESPACE, '/settings/floating-buttons/reorder', [
|
||||
'methods' => 'POST',
|
||||
'callback' => [$this, 'rest_reorder_floating_buttons'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
]);
|
||||
|
||||
// Friend Links
|
||||
register_rest_route(self::API_NAMESPACE, '/friend-links', [
|
||||
|
||||
@@ -93,188 +93,17 @@ trait GlobalControllerPart1 {
|
||||
|
||||
public function rest_handle_floating_buttons(\WP_REST_Request $request): \WP_REST_Response {
|
||||
if ($request->get_method() === 'GET') {
|
||||
$settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_floating_buttons_settings()
|
||||
: [
|
||||
'enabled' => true,
|
||||
'style' => 'round',
|
||||
'position' => 'bottom',
|
||||
'scroll_hide' => false,
|
||||
'scroll_down_hide' => true,
|
||||
'filter_blur' => [],
|
||||
'items' => [],
|
||||
];
|
||||
|
||||
return rest_ensure_response(['code' => 'success', 'data' => $settings]);
|
||||
return rest_ensure_response(['code' => 'success', 'data' => \AKSRT\Settings\FloatButtons::get()]);
|
||||
}
|
||||
|
||||
$params = $this->get_json_params($request);
|
||||
$items = isset($params['items']) ? array_map([$this, 'sanitize_floating_button_item'], (array) $params['items']) : [];
|
||||
$settings = \AKSRT\Settings\FloatButtons::sanitize($this->get_json_params($request));
|
||||
update_option(\AKSRT\Settings\FloatButtons::OPTION, $settings);
|
||||
\AKSRT\Settings\Settings::flush_settings_cache();
|
||||
|
||||
$filter_blur = [];
|
||||
if (!empty($params['filter_blur']) && is_array($params['filter_blur'])) {
|
||||
foreach ($params['filter_blur'] as $device) {
|
||||
$device = sanitize_text_field((string) $device);
|
||||
if (in_array($device, ['pc', 'mobile'], true)) {
|
||||
$filter_blur[] = $device;
|
||||
}
|
||||
}
|
||||
$filter_blur = array_values(array_unique($filter_blur));
|
||||
}
|
||||
|
||||
$settings = [
|
||||
'enabled' => !empty($params['enabled']),
|
||||
'style' => in_array($params['style'] ?? '', ['round', 'square'], true) ? $params['style'] : 'round',
|
||||
'position' => in_array($params['position'] ?? '', ['bottom', 'center'], true) ? $params['position'] : 'bottom',
|
||||
'scroll_hide' => !empty($params['scroll_hide']),
|
||||
'scroll_down_hide' => !empty($params['scroll_down_hide']),
|
||||
'max' => max(1, min(10, (int) ($params['max'] ?? 5))),
|
||||
'size' => max(32, min(64, (int) ($params['size'] ?? 44))),
|
||||
'spacing' => max(4, min(24, (int) ($params['spacing'] ?? 10))),
|
||||
'shadow' => !empty($params['shadow']),
|
||||
'animation' => !empty($params['animation']),
|
||||
'opacity' => max(30, min(100, (int) ($params['opacity'] ?? 100))),
|
||||
'active_color' => sanitize_hex_color($params['active_color'] ?? '') ?: '',
|
||||
'bg_color' => sanitize_hex_color($params['bg_color'] ?? '') ?: '',
|
||||
'pc_show' => !empty($params['pc_show']),
|
||||
'm_show' => !empty($params['m_show']),
|
||||
'filter_blur' => $filter_blur,
|
||||
'items' => $items,
|
||||
];
|
||||
|
||||
update_option('aksrt_floating_buttons', $settings);
|
||||
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
\AKSRT\Settings\Settings::flush_settings_cache();
|
||||
}
|
||||
|
||||
return rest_ensure_response(['code' => 'success', 'message' => __('Floating button settings saved.', 'aksrt')]);
|
||||
}
|
||||
|
||||
public function rest_reorder_floating_buttons(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$params = $this->get_json_params($request);
|
||||
$ordered_ids = $params['ids'] ?? [];
|
||||
|
||||
if (!is_array($ordered_ids)) {
|
||||
return new \WP_REST_Response(['code' => 'error', 'message' => __('参数错误', 'aksrt')], 400);
|
||||
}
|
||||
|
||||
$settings = get_option('aksrt_floating_buttons', []);
|
||||
$items = $settings['items'] ?? [];
|
||||
|
||||
$order_map = array_flip($ordered_ids);
|
||||
usort($items, function ($a, $b) use ($order_map) {
|
||||
$idx_a = $order_map[($a['id'] ?? '')] ?? 999;
|
||||
$idx_b = $order_map[($b['id'] ?? '')] ?? 999;
|
||||
return $idx_a <=> $idx_b;
|
||||
});
|
||||
|
||||
foreach ($items as $index => &$item) {
|
||||
$item['sort_order'] = $index;
|
||||
}
|
||||
unset($item);
|
||||
|
||||
$settings['items'] = $items;
|
||||
update_option('aksrt_floating_buttons', $settings);
|
||||
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
\AKSRT\Settings\Settings::flush_settings_cache();
|
||||
}
|
||||
|
||||
return rest_ensure_response(['code' => 'success', 'message' => __('Order saved.', 'aksrt')]);
|
||||
}
|
||||
|
||||
private function sanitize_floating_button_item(array $item): array {
|
||||
$valid_types = ['back_top', 'theme_mode', 'qrcode', 'service_qq', 'service_wechat', 'pay_vip', 'custom', 'add'];
|
||||
$type = sanitize_text_field($item['type'] ?? 'custom');
|
||||
if (!in_array($type, $valid_types, true)) {
|
||||
$type = 'custom';
|
||||
}
|
||||
|
||||
$hover_width = (int) ($item['hover_width'] ?? 200);
|
||||
if ($hover_width < 120) {
|
||||
$hover_width = 120;
|
||||
}
|
||||
if ($hover_width > 480) {
|
||||
$hover_width = 480;
|
||||
}
|
||||
|
||||
$qq = preg_replace('/\D+/', '', (string) ($item['qq'] ?? ''));
|
||||
$action_mode = sanitize_text_field($item['action_mode'] ?? 'link');
|
||||
if (!in_array($action_mode, ['link', 'qrcode'], true)) {
|
||||
$action_mode = 'link';
|
||||
}
|
||||
$qr_size = (int) ($item['qr_size'] ?? 120);
|
||||
if ($qr_size < 80) {
|
||||
$qr_size = 80;
|
||||
}
|
||||
if ($qr_size > 240) {
|
||||
$qr_size = 240;
|
||||
}
|
||||
|
||||
$add_items = [];
|
||||
if (!empty($item['add_items']) && is_array($item['add_items'])) {
|
||||
foreach ($item['add_items'] as $add_item) {
|
||||
if (!is_array($add_item)) {
|
||||
continue;
|
||||
}
|
||||
$label = sanitize_text_field($add_item['label'] ?? '');
|
||||
$url = esc_url_raw($add_item['url'] ?? '');
|
||||
$icon_item = aksrt_sanitize_icon_value((string) ($add_item['icon'] ?? ''));
|
||||
if ($label === '' && $url === '') {
|
||||
continue;
|
||||
}
|
||||
$add_items[] = [
|
||||
'id' => sanitize_text_field($add_item['id'] ?? uniqid('add_')),
|
||||
'label' => $label,
|
||||
'url' => $url,
|
||||
'icon' => $icon_item,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$icon = aksrt_sanitize_icon_value((string) ($item['icon'] ?? ''));
|
||||
$icon_dark = aksrt_sanitize_icon_value((string) ($item['icon_dark'] ?? ''));
|
||||
$icon_light = aksrt_sanitize_icon_value((string) ($item['icon_light'] ?? ''));
|
||||
if ($type === 'theme_mode') {
|
||||
$icon = 'fa fas fa-sun';
|
||||
$icon_dark = '';
|
||||
$icon_light = '';
|
||||
}
|
||||
// VIP float always uses modal path; drop stale link/hover and normalize icons.
|
||||
$link = esc_url_raw($item['link'] ?? '');
|
||||
$hover = wp_kses_post($item['hover'] ?? '');
|
||||
if ($type === 'pay_vip') {
|
||||
$link = '';
|
||||
$hover = '';
|
||||
if ($icon === '' || str_contains($icon, 'fa-gem')) {
|
||||
$icon = 'fa fas fa-gem';
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => sanitize_text_field($item['id'] ?? uniqid('float_')),
|
||||
'type' => $type,
|
||||
'icon' => $icon,
|
||||
'icon_dark' => $icon_dark,
|
||||
'icon_light' => $icon_light,
|
||||
'text' => sanitize_text_field($item['text'] ?? ''),
|
||||
'desc' => sanitize_text_field($item['desc'] ?? ''),
|
||||
'action_mode' => $action_mode,
|
||||
'qq' => $qq,
|
||||
'qrcode_img' => esc_url_raw($item['qrcode_img'] ?? ''),
|
||||
'wechat_img' => esc_url_raw($item['wechat_img'] ?? ''),
|
||||
'link' => $link,
|
||||
'add_items' => $add_items,
|
||||
'hover' => $hover,
|
||||
'qr_size' => $qr_size,
|
||||
'hover_width' => $hover_width,
|
||||
'pc_s' => !empty($item['pc_s']),
|
||||
'm_s' => !empty($item['m_s']),
|
||||
'color' => sanitize_text_field($item['color'] ?? ''),
|
||||
'bg' => sanitize_text_field($item['bg'] ?? ''),
|
||||
'enabled' => !empty($item['enabled']),
|
||||
'sort_order' => (int) ($item['sort_order'] ?? 0),
|
||||
];
|
||||
return rest_ensure_response([
|
||||
'code' => 'success',
|
||||
'message' => __('Floating button settings saved.', 'aksrt'),
|
||||
'data' => $settings,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,7 +532,6 @@ trait ScriptsPart1c {
|
||||
'searchPanelId' => 'nav-search-panel',
|
||||
'drawerId' => 'mobile-navbar',
|
||||
'userMenuId' => 'sub-user-box',
|
||||
'floatActionsId' => 'float-right-btns',
|
||||
'tabbarId' => 'footer-tabbar',
|
||||
],
|
||||
'themeUri' => get_template_directory_uri(),
|
||||
|
||||
@@ -131,7 +131,7 @@ class InlineStyleBuilder {
|
||||
}
|
||||
|
||||
if (class_exists('\AKSRT\Settings\Settings') && !empty(\AKSRT\Settings\Settings::get_value('close_backdrop', false))) {
|
||||
echo '<style id="aksrt-no-backdrop">.aksrt-header,.header-inner,.site-header,.header,.mobile-nav-overlay,.modal-backdrop,.aksrt-drawer-overlay,.aksrt-float-btn,.sidebar-inner{backdrop-filter:none!important;-webkit-backdrop-filter:none!important;background-color:var(--bg-card,#fff)!important}</style>' . "\n";
|
||||
echo '<style id="aksrt-no-backdrop">.aksrt-header,.header-inner,.site-header,.header,.mobile-nav-overlay,.modal-backdrop,.aksrt-drawer-overlay,.sidebar-inner{backdrop-filter:none!important;-webkit-backdrop-filter:none!important;background-color:var(--bg-card,#fff)!important}</style>' . "\n";
|
||||
}
|
||||
echo '<style id="aksrt-runtime-components">'
|
||||
. '.aksrt-search-hot-keywords{display:flex;align-items:center;gap:10px;flex-wrap:wrap;margin-top:12px;font-family:var(--font-ui);}'
|
||||
|
||||
@@ -106,21 +106,12 @@ trait CategoryIntegrationGroups {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右侧浮动按钮完整配置
|
||||
* @return array {enabled, style, position, scroll_hide, scroll_down_hide, filter_blur, items}
|
||||
* 获取右侧浮动按钮完整配置(结构见 FloatButtons::defaults())。
|
||||
*/
|
||||
public static function get_floating_buttons_settings(): array {
|
||||
return Integration::get_floating_buttons_settings();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右侧浮动按钮项(仅返回启用的,按排序)
|
||||
* @return array
|
||||
*/
|
||||
public static function get_floating_buttons_items(): array {
|
||||
return Integration::get_floating_buttons_items();
|
||||
}
|
||||
|
||||
/**
|
||||
* Customizer 注册(可选)
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* 右侧悬浮按钮:唯一的默认值 + 规范化来源(读取与保存共用)。
|
||||
*
|
||||
* 结构对齐参考主题 float_btn(sortable,固定类型,数组顺序即显示顺序)。
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
namespace AKSRT\Settings;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
class FloatButtons {
|
||||
|
||||
public const OPTION = 'aksrt_floating_buttons';
|
||||
|
||||
/** 固定按钮类型(默认显示顺序)。 */
|
||||
public const TYPES = ['more', 'pay_vip', 'add', 'service_qq', 'service_wechat', 'theme_mode', 'qrcode', 'back_top'];
|
||||
|
||||
/** 发布按钮可选类型。 */
|
||||
public const ADD_BTNS = ['post'];
|
||||
|
||||
/**
|
||||
* 默认配置。
|
||||
*/
|
||||
public static function defaults(): array {
|
||||
$empty_color = ['color' => '', 'bg' => ''];
|
||||
return [
|
||||
'style' => 'round',
|
||||
'position' => 'bottom',
|
||||
'filter_blur' => ['m_s'],
|
||||
'scroll_hide' => false,
|
||||
'scroll_down_hide' => true,
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'more',
|
||||
'buttons' => [self::default_more_button()],
|
||||
],
|
||||
['type' => 'pay_vip', 'pc_s' => true, 'm_s' => true, 'color' => ['color' => '#f2c97d', 'bg' => 'rgba(62,62,67,0.9)']],
|
||||
['type' => 'add', 'pc_s' => true, 'm_s' => false, 'color' => $empty_color, 'btns' => ['post'], 'icon' => 'fa fas fa-pencil-alt'],
|
||||
['type' => 'service_qq', 'pc_s' => false, 'm_s' => false, 'color' => $empty_color, 'qq' => ''],
|
||||
['type' => 'service_wechat', 'pc_s' => true, 'm_s' => true, 'color' => $empty_color, 'wechat_img' => ''],
|
||||
['type' => 'theme_mode', 'pc_s' => false, 'm_s' => false, 'color' => $empty_color],
|
||||
['type' => 'qrcode', 'pc_s' => true, 'm_s' => false, 'color' => $empty_color, 'desc' => __('在手机上浏览此页面', 'aksrt')],
|
||||
['type' => 'back_top', 'pc_s' => true, 'm_s' => true, 'color' => $empty_color],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认「更多按钮」子项。
|
||||
*/
|
||||
public static function default_more_button(): array {
|
||||
return [
|
||||
'desc' => '',
|
||||
'icon' => 'fa fas fa-heart',
|
||||
'link' => ['url' => '', 'target' => ''],
|
||||
'hover' => '',
|
||||
'hover_width' => 200,
|
||||
'pc_s' => false,
|
||||
'm_s' => false,
|
||||
'color' => ['color' => '', 'bg' => 'rgba(255, 111, 6, 0.2)'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取已规范化的配置。
|
||||
*/
|
||||
public static function get(): array {
|
||||
$saved = get_option(self::OPTION, []);
|
||||
if (!is_array($saved) || $saved === []) {
|
||||
return self::defaults();
|
||||
}
|
||||
return self::sanitize($saved);
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化完整配置(REST 保存与读取共用)。
|
||||
*/
|
||||
public static function sanitize(array $raw): array {
|
||||
$defaults = self::defaults();
|
||||
|
||||
$filter_blur = [];
|
||||
foreach ((array) ($raw['filter_blur'] ?? []) as $device) {
|
||||
$device = (string) $device;
|
||||
if (in_array($device, ['pc_s', 'm_s'], true) && !in_array($device, $filter_blur, true)) {
|
||||
$filter_blur[] = $device;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'style' => in_array($raw['style'] ?? '', ['round', 'square'], true) ? $raw['style'] : 'round',
|
||||
'position' => in_array($raw['position'] ?? '', ['bottom', 'center'], true) ? $raw['position'] : 'bottom',
|
||||
'filter_blur' => $filter_blur,
|
||||
'scroll_hide' => !empty($raw['scroll_hide']),
|
||||
'scroll_down_hide' => !empty($raw['scroll_down_hide']),
|
||||
'items' => self::sanitize_items((array) ($raw['items'] ?? []), $defaults['items']),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按提交顺序保留已知类型,重复丢弃,缺失类型用默认值补到末尾。
|
||||
*/
|
||||
private static function sanitize_items(array $raw_items, array $default_items): array {
|
||||
$default_map = [];
|
||||
foreach ($default_items as $item) {
|
||||
$default_map[$item['type']] = $item;
|
||||
}
|
||||
|
||||
$out = [];
|
||||
$seen = [];
|
||||
foreach ($raw_items as $item) {
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
$type = (string) ($item['type'] ?? '');
|
||||
if (!isset($default_map[$type]) || isset($seen[$type])) {
|
||||
continue;
|
||||
}
|
||||
$seen[$type] = true;
|
||||
$out[] = self::sanitize_item($type, $item, $default_map[$type]);
|
||||
}
|
||||
foreach ($default_items as $item) {
|
||||
if (!isset($seen[$item['type']])) {
|
||||
$out[] = $item;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
private static function sanitize_item(string $type, array $item, array $default): array {
|
||||
if ($type === 'more') {
|
||||
$buttons = [];
|
||||
foreach ((array) ($item['buttons'] ?? []) as $button) {
|
||||
if (is_array($button)) {
|
||||
$buttons[] = self::sanitize_more_button($button);
|
||||
}
|
||||
}
|
||||
// 参考主题:至少保留一个。
|
||||
if ($buttons === []) {
|
||||
$buttons[] = self::default_more_button();
|
||||
}
|
||||
return ['type' => 'more', 'buttons' => $buttons];
|
||||
}
|
||||
|
||||
$out = [
|
||||
'type' => $type,
|
||||
'pc_s' => !empty($item['pc_s']),
|
||||
'm_s' => !empty($item['m_s']),
|
||||
'color' => self::sanitize_color_group($item['color'] ?? []),
|
||||
];
|
||||
|
||||
switch ($type) {
|
||||
case 'add':
|
||||
$btns = [];
|
||||
foreach ((array) ($item['btns'] ?? []) as $btn) {
|
||||
$btn = (string) $btn;
|
||||
if (in_array($btn, self::ADD_BTNS, true) && !in_array($btn, $btns, true)) {
|
||||
$btns[] = $btn;
|
||||
}
|
||||
}
|
||||
$out['btns'] = $btns;
|
||||
$out['icon'] = aksrt_sanitize_icon_value((string) ($item['icon'] ?? ''));
|
||||
break;
|
||||
case 'service_qq':
|
||||
$out['qq'] = (string) preg_replace('/\D+/', '', (string) ($item['qq'] ?? ''));
|
||||
break;
|
||||
case 'service_wechat':
|
||||
$out['wechat_img'] = esc_url_raw((string) ($item['wechat_img'] ?? ''));
|
||||
break;
|
||||
case 'qrcode':
|
||||
$out['desc'] = sanitize_text_field((string) ($item['desc'] ?? ''));
|
||||
break;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
private static function sanitize_more_button(array $button): array {
|
||||
$link = is_array($button['link'] ?? null) ? $button['link'] : [];
|
||||
$target = (string) ($link['target'] ?? '');
|
||||
|
||||
return [
|
||||
'desc' => sanitize_text_field((string) ($button['desc'] ?? '')),
|
||||
'icon' => aksrt_sanitize_icon_value((string) ($button['icon'] ?? '')),
|
||||
'link' => [
|
||||
'url' => esc_url_raw((string) ($link['url'] ?? '')),
|
||||
'target' => $target === '_blank' ? '_blank' : '',
|
||||
],
|
||||
'hover' => wp_kses_post((string) ($button['hover'] ?? '')),
|
||||
'hover_width' => max(50, min(500, (int) ($button['hover_width'] ?? 200))),
|
||||
'pc_s' => !empty($button['pc_s']),
|
||||
'm_s' => !empty($button['m_s']),
|
||||
'color' => self::sanitize_color_group($button['color'] ?? []),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $group
|
||||
* @return array{color:string,bg:string}
|
||||
*/
|
||||
private static function sanitize_color_group($group): array {
|
||||
$group = is_array($group) ? $group : [];
|
||||
return [
|
||||
'color' => self::sanitize_color((string) ($group['color'] ?? '')),
|
||||
'bg' => self::sanitize_color((string) ($group['bg'] ?? '')),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 允许 #hex(3/4/6/8 位)与 rgb()/rgba()。
|
||||
*/
|
||||
public static function sanitize_color(string $value): string {
|
||||
$value = trim($value);
|
||||
if ($value === '') {
|
||||
return '';
|
||||
}
|
||||
if (preg_match('/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/', $value)) {
|
||||
return $value;
|
||||
}
|
||||
if (preg_match('/^rgba?\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*(?:,\s*(?:0|1|0?\.\d+)\s*)?\)$/', $value)) {
|
||||
return $value;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -260,122 +260,10 @@ class Integration {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右侧浮动按钮完整配置
|
||||
* @return array {enabled, style, position, scroll_hide, scroll_down_hide, filter_blur, items}
|
||||
* 获取右侧浮动按钮完整配置(结构见 FloatButtons::defaults())。
|
||||
*/
|
||||
public static function get_floating_buttons_settings(): array {
|
||||
$defaults = [
|
||||
'enabled' => true,
|
||||
'style' => 'round',
|
||||
'position' => 'bottom',
|
||||
'scroll_hide' => false,
|
||||
'scroll_down_hide' => true,
|
||||
'max' => 5,
|
||||
'size' => 44,
|
||||
'spacing' => 10,
|
||||
'shadow' => true,
|
||||
'animation' => true,
|
||||
'opacity' => 100,
|
||||
'active_color' => '',
|
||||
'bg_color' => '',
|
||||
'pc_show' => true,
|
||||
'm_show' => true,
|
||||
'filter_blur' => ['mobile'],
|
||||
'items' => [
|
||||
[
|
||||
'id' => 'btn_wechat',
|
||||
'type' => 'service_wechat',
|
||||
'icon' => 'fa fab fa-weixin',
|
||||
'icon_dark' => '',
|
||||
'icon_light' => '',
|
||||
'text' => __('微信', 'aksrt'),
|
||||
'desc' => '',
|
||||
'action_mode'=> 'qrcode',
|
||||
'qq' => '',
|
||||
'qrcode_img' => '',
|
||||
'wechat_img' => '',
|
||||
'link' => '',
|
||||
'add_items' => [],
|
||||
'hover' => '',
|
||||
'qr_size' => 120,
|
||||
'hover_width' => 200,
|
||||
'pc_s' => true,
|
||||
'm_s' => true,
|
||||
'color' => '',
|
||||
'bg' => '',
|
||||
'enabled' => true,
|
||||
'sort_order' => 0,
|
||||
],
|
||||
[
|
||||
'id' => 'btn_theme',
|
||||
'type' => 'theme_mode',
|
||||
'icon' => 'fa fas fa-sun',
|
||||
'icon_dark' => '',
|
||||
'icon_light' => '',
|
||||
'text' => __('主题', 'aksrt'),
|
||||
'desc' => __('切换主题', 'aksrt'),
|
||||
'action_mode'=> 'link',
|
||||
'qq' => '',
|
||||
'qrcode_img' => '',
|
||||
'wechat_img' => '',
|
||||
'link' => '',
|
||||
'add_items' => [],
|
||||
'hover' => '',
|
||||
'qr_size' => 120,
|
||||
'hover_width' => 200,
|
||||
'pc_s' => true,
|
||||
'm_s' => false,
|
||||
'color' => '',
|
||||
'bg' => '',
|
||||
'enabled' => true,
|
||||
'sort_order' => 1,
|
||||
],
|
||||
[
|
||||
'id' => 'btn_top',
|
||||
'type' => 'back_top',
|
||||
'icon' => 'fa fas fa-chevron-up',
|
||||
'icon_dark' => '',
|
||||
'icon_light' => '',
|
||||
'text' => __('顶部', 'aksrt'),
|
||||
'desc' => __('返回顶部', 'aksrt'),
|
||||
'action_mode'=> 'link',
|
||||
'qq' => '',
|
||||
'qrcode_img' => '',
|
||||
'wechat_img' => '',
|
||||
'link' => '',
|
||||
'add_items' => [],
|
||||
'hover' => '',
|
||||
'qr_size' => 120,
|
||||
'hover_width' => 200,
|
||||
'pc_s' => true,
|
||||
'm_s' => true,
|
||||
'color' => '',
|
||||
'bg' => '',
|
||||
'enabled' => true,
|
||||
'sort_order' => 2,
|
||||
],
|
||||
],
|
||||
];
|
||||
$saved = get_option('aksrt_floating_buttons', []);
|
||||
if (!is_array($saved)) {
|
||||
$saved = [];
|
||||
}
|
||||
return array_merge($defaults, $saved);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取右侧浮动按钮项(仅返回启用的,按排序)
|
||||
* @return array
|
||||
*/
|
||||
public static function get_floating_buttons_items(): array {
|
||||
$settings = self::get_floating_buttons_settings();
|
||||
if (empty($settings['enabled'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$items = array_filter($settings['items'], fn($item) => !empty($item['enabled']));
|
||||
usort($items, fn($a, $b) => ($a['sort_order'] ?? 0) <=> ($b['sort_order'] ?? 0));
|
||||
return array_values($items);
|
||||
return FloatButtons::get();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user