true, 'text' => __('发布', 'aksrt'), 'radius' => 20, 'class' => '']; $all = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_all() : []; // Prefer publish_btn from header nav when newposts not explicitly set. $nav = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_header_nav_settings() : ['publish_btn' => true]; if (empty($cfg['enabled']) && !empty($nav['publish_btn'])) { $cfg['enabled'] = true; } $types = []; if (!empty($all['header_newposts_types']) && is_array($all['header_newposts_types'])) { $types = array_values(array_filter(array_map('sanitize_key', $all['header_newposts_types']))); } if (!$types) { $types = ['post']; if (class_exists('\AKSRT\Settings\Settings')) { $forum = \AKSRT\Settings\Settings::get_forum_settings(); $shop = \AKSRT\Settings\Settings::get_shop_settings(); if (!empty($forum['enabled'])) { $types[] = 'topic'; } if (!empty($shop['enabled'])) { $types[] = 'product'; } } } $cfg['types'] = $types; return $cfg; } endif; if (!function_exists('aksrt_get_new_add_actions')) : /** * Build multi-type publish actions. * * @param string[] $types post|topic|product * @return list */ function aksrt_get_new_add_actions(array $types = ['post']): array { $out = []; foreach ($types as $type) { $type = sanitize_key((string) $type); if ($type === 'post') { $url = function_exists('aksrt_get_new_post_url') ? aksrt_get_new_post_url() : admin_url('post-new.php'); if ($url === '') { continue; } $out[] = [ 'type' => 'post', 'url' => $url, 'label' => __('写文章', 'aksrt'), 'icon' => 'fa fa-file-text-o', ]; } elseif ($type === 'topic') { $url = function_exists('aksrt_get_forum_compose_url') ? aksrt_get_forum_compose_url() : ''; if ($url === '') { continue; } $out[] = [ 'type' => 'topic', 'url' => $url, 'label' => __('发帖', 'aksrt'), 'icon' => 'fa fa-comments-o', ]; } elseif ($type === 'product') { // Prefer front product edit page when registered. $url = ''; if (function_exists('aksrt_get_product_edit_url')) { $url = (string) aksrt_get_product_edit_url(); } if ($url === '') { // Fallback: product-edit page template lookup is optional. $url = home_url('/?page_id=0'); // Use admin product CPT if available. $url = admin_url('post-new.php?post_type=aksrt_product'); } $out[] = [ 'type' => 'product', 'url' => $url, 'label' => __('发布商品', 'aksrt'), 'icon' => 'fa fa-shopping-bag', ]; } } return $out; } endif; if (!function_exists('aksrt_render_new_add_btns')) : /** * Multi-type publish button (zibll newadd-btns). * * @param string[] $types */ function aksrt_render_new_add_btns(array $types, string $class = '', string $label = ''): string { $actions = aksrt_get_new_add_actions($types); if (!$actions) { return ''; } if ($label === '') { $label = __('发布', 'aksrt'); } $class = trim('newadd-btns ' . $class); if (count($actions) === 1) { $a = $actions[0]; return '' . ' ' . wp_kses_post($label) . ''; } $html = ''; $html .= '' . wp_kses_post($label) . ' '; $html .= ''; return $html; } endif; if (!function_exists('aksrt_render_header_menu_buttons')) : /** * Publish + optional VIP open button for header CTA. */ function aksrt_render_header_menu_buttons(): string { $cfg = aksrt_get_header_newposts_config(); $html = ''; if (!empty($cfg['enabled'])) { $class = 'btn-primary navbar-newposts'; if (!empty($cfg['class'])) { $class .= ' ' . $cfg['class']; } $radius = (int) ($cfg['radius'] ?? 20); $style = $radius > 0 ? ' style="border-radius:' . $radius . 'px"' : ''; $label = (string) ($cfg['text'] ?? __('发布', 'aksrt')); // Strip outer if present in settings HTML text — keep simple. $btn = aksrt_render_new_add_btns($cfg['types'] ?? ['post'], $class, $label); if ($btn !== '') { $html .= ''; } } // VIP open CTA for guests / non-VIP. $user_id = get_current_user_id(); $vip_url = function_exists('aksrt_get_vip_purchase_url') ? aksrt_get_vip_purchase_url() : (function_exists('aksrt_get_user_center_url') ? aksrt_get_user_center_url('vip') : '#'); $show_vip = true; if (class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'get_vip_settings')) { $vs = \AKSRT\Settings\Settings::get_vip_settings(); $show_vip = !empty($vs['enabled']) || !empty($vs['vip1_enabled']) || !empty($vs['vip2_enabled']); } 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 ? 'pay-vip' : 'signin-loader'; $html .= ''; } } return $html; } endif;