wpbridge/templates/admin/tabs/projects.php
feibisi 4c4c11d356 fix: 修复 Codex 评审发现的问题
安全性修复:
- ajax_save_defaults() 添加 sanitize_text_field() 清理输入
- ajax_batch_set_source() 添加操作类型白名单验证
- projects.php 子 Tab 参数添加白名单验证

Bug 修复:
- 修复 CSS 多余闭合括号导致的样式解析错误
- 修复主题截图 URL 获取方式(使用完整 URL)

用户体验改进:
- 搜索功能添加 300ms 防抖,避免频繁 DOM 操作
- 批量操作添加确认对话框
- 单个项目源变更后即时更新 UI 状态(无需刷新)
- 源选择时显示加载状态

错误处理改进:
- FAIR 请求失败时记录错误日志(WP_DEBUG 模式)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 23:42:16 +08:00

77 lines
2.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* 项目管理 Tab 内容
*
* 方案 B项目优先架构 - 显示已安装的插件/主题列表
*
* @package WPBridge
* @since 0.6.0
*/
// 防止直接访问
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use WPBridge\Core\SourceRegistry;
use WPBridge\Core\ItemSourceManager;
use WPBridge\Core\DefaultsManager;
// 获取管理器实例
$source_registry = new SourceRegistry();
$item_manager = new ItemSourceManager( $source_registry );
$defaults_manager = new DefaultsManager();
// 获取所有可用源
$all_sources = $source_registry->get_enabled();
// 获取已安装的插件
if ( ! function_exists( 'get_plugins' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$installed_plugins = get_plugins();
// 获取已安装的主题
$installed_themes = wp_get_themes();
// 当前子 Tab - 白名单验证
$allowed_subtabs = [ 'plugins', 'themes', 'defaults' ];
$current_subtab = 'plugins';
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- 仅用于 UI 显示
if ( isset( $_GET['subtab'] ) && in_array( $_GET['subtab'], $allowed_subtabs, true ) ) {
$current_subtab = $_GET['subtab'];
}
?>
<!-- 子 Tab 导航 -->
<div class="wpbridge-subtabs">
<a href="#" class="wpbridge-subtab <?php echo $current_subtab === 'plugins' ? 'wpbridge-subtab-active' : ''; ?>" data-subtab="plugins">
<span class="dashicons dashicons-admin-plugins"></span>
<?php esc_html_e( '插件', 'wpbridge' ); ?>
<span class="wpbridge-subtab-count"><?php echo count( $installed_plugins ); ?></span>
</a>
<a href="#" class="wpbridge-subtab <?php echo $current_subtab === 'themes' ? 'wpbridge-subtab-active' : ''; ?>" data-subtab="themes">
<span class="dashicons dashicons-admin-appearance"></span>
<?php esc_html_e( '主题', 'wpbridge' ); ?>
<span class="wpbridge-subtab-count"><?php echo count( $installed_themes ); ?></span>
</a>
<a href="#" class="wpbridge-subtab <?php echo $current_subtab === 'defaults' ? 'wpbridge-subtab-active' : ''; ?>" data-subtab="defaults">
<span class="dashicons dashicons-admin-settings"></span>
<?php esc_html_e( '默认规则', 'wpbridge' ); ?>
</a>
</div>
<!-- 插件列表 -->
<div id="subtab-plugins" class="wpbridge-subtab-pane <?php echo $current_subtab === 'plugins' ? 'wpbridge-subtab-pane-active' : ''; ?>">
<?php include WPBRIDGE_PATH . 'templates/admin/partials/project-list-plugins.php'; ?>
</div>
<!-- 主题列表 -->
<div id="subtab-themes" class="wpbridge-subtab-pane <?php echo $current_subtab === 'themes' ? 'wpbridge-subtab-pane-active' : ''; ?>">
<?php include WPBRIDGE_PATH . 'templates/admin/partials/project-list-themes.php'; ?>
</div>
<!-- 默认规则 -->
<div id="subtab-defaults" class="wpbridge-subtab-pane <?php echo $current_subtab === 'defaults' ? 'wpbridge-subtab-pane-active' : ''; ?>">
<?php include WPBRIDGE_PATH . 'templates/admin/partials/defaults-config.php'; ?>
</div>