Files
wordpress-theme-aksrt/inc/helpers/aksrt-header-menu-buttons.php
T
kate522 4f2edebab6 fix(header): align publish and VIP CTAs with reference theme
The top-nav publish chip and open-membership chip carried an AKSRT-only
class layer (navbar-cta / navbar-cta-text / navbar-newposts /
navbar-vip-hover) plus a matching set of CSS overrides that replaced the
legacy .but geometry: margin 0.4em -> 0, an extra min-height and flex gap,
an FA5 pencil glyph that is not the reference pencil, and label text
wrapped in a span. The VIP hover card also had its own positioning
override instead of the reference static position.

Drop that layer and emit the reference class combination verbatim so the
already byte-identical legacy stylesheet owns the geometry again:

- publish chip renders newadd-btns but nowave <skin> [radius] btn-newadd
  with the label echoed as saved (no injected icon, no span)
- VIP chip renders pay-vip|signin-loader but jb-red radius payvip-icon
  with the vip_1 SVG at em12 mr3, inside span.hover-show.inline-block
- user-card CTA uses the vip_1 SVG (em12 mr6) instead of fa-gem and drops
  vip-level, matching zib_get_header_payvip_icon()
- both buttons now honour Settings::close_sign(), matching the reference
  zib_is_close_sign() gate and the floating publish button
- header-userbox.css keeps one rule that restores the hover wrapper to a
  plain block container so .sub-vip-card takes its reference static
  position; every other override is gone
- nav_newposts_text default drops the duplicated fas and uses the FA5
  spelling of the reference pencil (fa-pencil-alt, not fa-pen)

Dead code removed: aksrt_normalize_header_cta_label(), the unreachable
multi-type dropdown branch of aksrt_render_new_add_btns() (only 'post' is
supported and only ['post'] is ever passed), and the
newadd-btns__toggle / newadd-btns__item / drop-newadd markup it emitted.

ml10 is no longer set on the VIP anchor: .aksrt-navbar-actions already
supplies the 10px gap the reference gets from ml10, and keeping both
would double it to 20px.

No migration for sites that already stored the old nav_newposts_text.

Verified: node --test across tests/ (603 passing), php -l on the changed
PHP files, and a stubbed render of every publish/VIP branch.
2026-10-15 11:54:54 +08:00

131 lines
4.4 KiB
PHP

<?php
/**
* Header multi-function cluster (legacy publish/VIP subset).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_get_new_add_actions')) :
/**
* Build multi-type publish actions.
*
* @param string[] $types Currently only post is supported.
* @return list<array{type:string,url:string,label:string,icon:string}>
*/
function aksrt_get_new_add_actions(array $types = ['post']): array {
$out = [];
foreach ($types as $type) {
$type = sanitize_key((string) $type);
if ($type === 'post') {
// Front submit page may be unset → aksrt_get_new_post_url() returns ''.
// Never drop the publish chip for that: fall back to WP post-new.
$url = function_exists('aksrt_get_new_post_url') ? (string) aksrt_get_new_post_url() : '';
if ($url === '') {
$url = admin_url('post-new.php');
}
$out[] = [
'type' => 'post',
'url' => $url,
'label' => __('写文章', 'aksrt'),
'icon' => 'fa fas fa-file-alt',
];
}
}
return $out;
}
endif;
if (!function_exists('aksrt_render_new_add_btns')) :
/**
* Publish chip (legacy newadd-btns, single action).
*
* Mirrors the single-button branch of the reference zib_get_new_add_btns():
* the paint classes ride on the anchor itself and the label is emitted
* verbatim. Only the post action exists, so there is no dropdown branch.
*
* @param string[] $types
*/
function aksrt_render_new_add_btns(array $types, string $class = '', string $label = ''): string {
if (class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::close_sign()) {
return '';
}
$actions = aksrt_get_new_add_actions($types);
if (!$actions) {
return '';
}
$a = $actions[0];
if ($label === '') {
$label = __('发布', 'aksrt');
}
return '<a rel="nofollow" class="newadd-btns ' . esc_attr($class) . ' btn-newadd" href="' . esc_url($a['url']) . '">'
. $label . '</a>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Saved through sanitize_type 'html' (wp_kses_post).
}
endif;
if (!function_exists('aksrt_render_header_menu_buttons')) :
/**
* Publish + optional VIP open button for header CTA.
*/
function aksrt_render_header_menu_buttons(): string {
$settings = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::read_domain('page_display', 'header-nav') : [];
$enabled = !isset($settings['nav_newposts']) || !empty($settings['nav_newposts']);
$text = trim((string) ($settings['nav_newposts_text'] ?? ''));
$pill = !isset($settings['nav_newposts_radius']) || !empty($settings['nav_newposts_radius']);
$skin = sanitize_html_class((string) (($settings['nav_newposts_class'] ?? '') ?: 'jb-blue'));
$html = '';
if ($enabled) {
// legacy default: but nowave jb-blue (+ radius).
$class = 'but nowave ' . $skin;
if ($pill && !str_contains($class, 'radius')) {
$class .= ' radius';
}
$label = $text !== '' ? $text : __('发布', 'aksrt');
$btn = aksrt_render_new_add_btns(['post'], $class, $label);
if ($btn !== '') {
$html .= $btn;
}
}
// VIP open CTA for guests / non-VIP (legacy: .pay-vip modal).
$user_id = get_current_user_id();
$show_vip = false;
if (class_exists('\AKSRT\Settings\Settings')) {
$vs = \AKSRT\Settings\Settings::get_payment_vip_settings();
$show_vip = !empty($vs['enabled']) && !empty($vs['nav_pay_vip'])
&& !\AKSRT\Settings\Settings::close_sign();
}
if ($show_vip) {
$is_vip = false;
if ($user_id > 0 && function_exists('aksrt_get_user_vip_level')) {
$is_vip = (int) aksrt_get_user_vip_level($user_id) > 0;
}
if (!$is_vip) {
$cls = $user_id > 0 ? 'pay-vip' : 'signin-loader';
$hover = '';
if (class_exists('\AKSRT\Content\VipService')) {
$svc = \AKSRT\Content\VipService::get_instance();
if (method_exists($svc, 'render_vip_card')) {
$cards = $svc->render_vip_card(1, $user_id) . $svc->render_vip_card(2, $user_id);
if ($cards !== '') {
$hover = '<div class="sub-menu hover-show-con sub-vip-card">' . $cards . '</div>';
}
}
}
// legacy: span.hover-show wraps button + .sub-menu.sub-vip-card
$html .= '<span class="hover-show inline-block">';
$html .= '<a class="' . esc_attr($cls) . ' but jb-red radius payvip-icon" href="javascript:;">'
. '<svg class="em12 mr3" aria-hidden="true"><use xlink:href="#icon-vip_1"></use></svg>'
. esc_html__('开通会员', 'aksrt') . '</a>' . $hover . '</span>';
}
}
return $html;
}
endif;