add_cap('edit_theme_options'); // 编辑主题选项 $role->add_cap('customize'); // 自定义器 $role->add_cap('switch_themes'); // 切换主题 $role->add_cap('edit_themes'); // 编辑主题 $role->add_cap('update_themes'); // 更新主题 $role->add_cap('install_themes'); // 安装主题 $role->add_cap('delete_themes'); // 删除主题 $role->add_cap('upload_themes'); // 上传主题 } } // 在主题激活时运行一次 add_action('after_switch_theme', 'enhance_editor_capabilities'); // 确保在插件加载后运行一次 add_action('init', 'enhance_editor_capabilities'); // 在导航菜单管理页面显示菜单ID function nenghui_show_menu_id_in_nav_menus() { // 只在nav-menus.php页面加载 global $pagenow; if ($pagenow !== 'nav-menus.php') { return; } // 获取所有菜单 $menus = wp_get_nav_menus(); if (empty($menus)) { return; } ?> id === 'nav-menus') { $screen->add_help_tab(array( 'id' => 'nenghui-menu-ids', 'title' => '菜单ID使用', 'content' => '
每个菜单都有一个唯一的数字ID,您可以在短代码中使用这些ID来指定特定的菜单。
' . '[nenghui_about_nav] - 使用自定义器中设置的默认菜单[nenghui_about_nav menu_id="2"] - 使用ID为2的菜单[nenghui_about_nav menu_id="5"] - 使用ID为5的菜单注意:菜单ID在页面顶部的信息框中显示,请使用正确的ID。
' )); } } add_action('current_screen', 'nenghui_add_menu_help_info'); // 导入主题配置文件 // require_once 'theme-options.php'; // 暂时注释掉,文件不存在 // 导入小工具配置 require_once 'widgets/widgets-config.php'; // 刷新重写规则以确保FAQ归档页面正常工作 function nenghui_flush_rewrite_rules() { // 只在主题激活时执行一次 if (get_option('nenghui_rewrite_rules_flushed') !== '1') { flush_rewrite_rules(); update_option('nenghui_rewrite_rules_flushed', '1'); } } add_action('after_switch_theme', 'nenghui_flush_rewrite_rules'); // 当FAQ文章类型注册后刷新重写规则 function nenghui_flush_rewrite_rules_on_init() { static $flushed = false; if (!$flushed && get_option('nenghui_faq_rewrite_flushed') !== '1') { flush_rewrite_rules(); update_option('nenghui_faq_rewrite_flushed', '1'); $flushed = true; } } add_action('init', 'nenghui_flush_rewrite_rules_on_init', 999); // 所有功能已拆分到独立的配置文件中: // - 主题设置: inc/theme-setup.php // - 后台管理: inc/admin-config.php // - 资源加载: inc/assets-loader.php // - 媒体配置: inc/media-config.php // - 初始化配置: inc/init-config.php // - 清理优化: inc/cleanup.php // - 性能配置: inc/performance-config.php // - 自定义器: inc/customizer.php // - 短代码: inc/shortcode.php /** * 自定义导航菜单Walker类,支持多级下拉菜单 */ class Nenghui_Walker_Nav_Menu extends Walker_Nav_Menu { // 开始输出子菜单 function start_lvl(&$output, $depth = 0, $args = null) { $indent = str_repeat("\t", $depth); $output .= "\n$indent\n"; } // 显示元素 function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) { $id_field = $this->db_fields['id']; if (is_object($args[0])) { $args[0]->has_children = !empty($children_elements[$element->$id_field]); } return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output); } // 开始输出菜单项 function start_el(&$output, $item, $depth = 0, $args = null, $id = 0) { $indent = ($depth) ? str_repeat("\t", $depth) : ''; $classes = empty($item->classes) ? array() : (array) $item->classes; $classes[] = 'menu-item-' . $item->ID; // 检查是否有子菜单 $has_children = !empty($args->has_children); if ($has_children) { $classes[] = 'menu-item-has-children'; } $class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item, $args)); $class_names = $class_names ? ' class="' . esc_attr($class_names) . '"' : ''; $id = apply_filters('nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args); $id = $id ? ' id="' . esc_attr($id) . '"' : ''; $output .= $indent . '