b4400a68e5
Baseline before backporting wp-data-optimizer v3.0.1-v3.4.6. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
165 lines
5.6 KiB
PHP
165 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* Admin tab renderer for the HivePress integration.
|
|
*
|
|
* Read-only tab. Shows:
|
|
*
|
|
* 1. Conflict guard status (hp-custom-tables / hp-info-cards)
|
|
* 2. 13 known addons + detected/bound state
|
|
* 3. 8-D suitability aggregate + per-adapter scores
|
|
*
|
|
* Mutating actions (migrate / rollback) are CLI-only — see
|
|
* `wp wpdo hivepress migrate <slug>`. The admin tab links to the CLI in its
|
|
* footer (Karpathy: blast-radius-aware UI design).
|
|
*
|
|
* Plugged into `TMDO_Admin::render_page()` switch via `'hivepress' =>
|
|
* 'HivePress 整合'` tab entry.
|
|
*
|
|
* @package WP_Data_Optimizer
|
|
* @since 3.0.0
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
if ( ! class_exists( 'TMDO_Admin_HivePress' ) ) {
|
|
|
|
/**
|
|
* Static renderer for the HivePress admin tab.
|
|
*/
|
|
final class TMDO_Admin_HivePress {
|
|
|
|
/**
|
|
* Render the tab body.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function render(): void {
|
|
$detected = class_exists( 'TMDO_HivePress_Detector' )
|
|
? TMDO_HivePress_Detector::detect()
|
|
: array();
|
|
$catalog = class_exists( 'TMDO_HivePress_Detector' )
|
|
? TMDO_HivePress_Detector::catalog()
|
|
: array();
|
|
$bound = class_exists( 'TMDO_HivePress_Bootstrap' )
|
|
? array_keys( TMDO_HivePress_Bootstrap::adapters() )
|
|
: array();
|
|
$conflicts = class_exists( 'TMDO_HivePress_Conflict_Guard' )
|
|
? TMDO_HivePress_Conflict_Guard::detect_conflicts()
|
|
: array();
|
|
$report = class_exists( 'TMDO_HivePress_Suitability_Scorer' )
|
|
? TMDO_HivePress_Suitability_Scorer::report()
|
|
: array(
|
|
'aggregate' => 0.0,
|
|
'adapter_count' => 0,
|
|
'adapters' => array(),
|
|
'per_dimension' => array(),
|
|
);
|
|
|
|
?>
|
|
<div class="wpdo-hp-tab">
|
|
<h2><?php esc_html_e( 'HivePress 家族整合', 'tmdo-hivepress' ); ?></h2>
|
|
|
|
<?php self::render_conflict_section( $conflicts ); ?>
|
|
|
|
<h3><?php esc_html_e( '已偵測 addon', 'tmdo-hivepress' ); ?></h3>
|
|
<table class="widefat striped">
|
|
<thead>
|
|
<tr>
|
|
<th><?php esc_html_e( 'Slug', 'tmdo-hivepress' ); ?></th>
|
|
<th><?php esc_html_e( '名稱', 'tmdo-hivepress' ); ?></th>
|
|
<th><?php esc_html_e( '偵測', 'tmdo-hivepress' ); ?></th>
|
|
<th><?php esc_html_e( '版本', 'tmdo-hivepress' ); ?></th>
|
|
<th><?php esc_html_e( 'Adapter 已綁定', 'tmdo-hivepress' ); ?></th>
|
|
<th><?php esc_html_e( '8-D Score', 'tmdo-hivepress' ); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ( $catalog as $slug => $name ) : ?>
|
|
<?php
|
|
$is_detected = isset( $detected[ $slug ] );
|
|
$is_bound = in_array( $slug, $bound, true );
|
|
$score = $report['adapters'][ $slug ]['aggregate'] ?? null;
|
|
?>
|
|
<tr>
|
|
<td><code><?php echo esc_html( $slug ); ?></code></td>
|
|
<td><?php echo esc_html( $name ); ?></td>
|
|
<td><?php echo $is_detected ? '✅' : '⚪'; ?></td>
|
|
<td><?php echo esc_html( $detected[ $slug ] ?? '—' ); ?></td>
|
|
<td><?php echo $is_bound ? '✅' : '—'; ?></td>
|
|
<td><?php echo null === $score ? '—' : esc_html( (string) $score ); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<h3 style="margin-top:24px;"><?php esc_html_e( '8 維度反 EAV 評分', 'tmdo-hivepress' ); ?></h3>
|
|
<p>
|
|
<?php
|
|
echo esc_html(
|
|
sprintf(
|
|
/* translators: %1$s: aggregate score, %2$d: adapter count. */
|
|
__( 'Aggregate: %1$s / 10 · Active adapters: %2$d', 'tmdo-hivepress' ),
|
|
(string) $report['aggregate'],
|
|
(int) $report['adapter_count']
|
|
)
|
|
);
|
|
?>
|
|
</p>
|
|
|
|
<?php self::render_dimension_table( $report['per_dimension'] ); ?>
|
|
|
|
<h3 style="margin-top:24px;"><?php esc_html_e( '操作 (CLI)', 'tmdo-hivepress' ); ?></h3>
|
|
<p><?php esc_html_e( '為避免誤觸生產資料,遷移與 rollback 僅透過 CLI 執行:', 'tmdo-hivepress' ); ?></p>
|
|
<pre style="background:#f6f7f7;padding:12px;border-left:4px solid #2271b1;">wp wpdo hivepress detect
|
|
wp wpdo hivepress score
|
|
wp wpdo hivepress doctor
|
|
wp wpdo hivepress migrate <addon-slug>
|
|
wp wpdo hivepress rollback <addon-slug>
|
|
wp wpdo hivepress benchmark</pre>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
/**
|
|
* Render the conflict-guard banner (if applicable).
|
|
*
|
|
* @param array<int,string> $conflicts Conflicting plugin slugs.
|
|
*/
|
|
private static function render_conflict_section( array $conflicts ): void {
|
|
if ( empty( $conflicts ) ) {
|
|
echo '<div class="notice notice-success inline"><p>'
|
|
. esc_html__( 'Conflict guard: clean — hp-custom-tables / hp-info-cards 未啟用。', 'tmdo-hivepress' )
|
|
. '</p></div>';
|
|
return;
|
|
}
|
|
echo '<div class="notice notice-warning inline"><p><strong>'
|
|
. esc_html__( '偵測到衝突外掛:', 'tmdo-hivepress' ) . '</strong> '
|
|
. esc_html( implode( ', ', $conflicts ) )
|
|
. '</p><p>'
|
|
. esc_html__( 'WPDO HivePress integration 已自動退讓。請執行 `wp wpdo hivepress migrate-from-hpct` 後停用舊外掛。', 'tmdo-hivepress' )
|
|
. '</p></div>';
|
|
}
|
|
|
|
/**
|
|
* Render per-dimension averages table.
|
|
*
|
|
* @param array<string,float> $dimensions Dimension key → average.
|
|
*/
|
|
private static function render_dimension_table( array $dimensions ): void {
|
|
if ( empty( $dimensions ) ) {
|
|
return;
|
|
}
|
|
echo '<table class="widefat striped" style="max-width:520px;"><thead><tr><th>'
|
|
. esc_html__( '維度', 'tmdo-hivepress' ) . '</th><th>'
|
|
. esc_html__( '平均', 'tmdo-hivepress' ) . '</th></tr></thead><tbody>';
|
|
foreach ( $dimensions as $key => $avg ) {
|
|
echo '<tr><td><code>' . esc_html( $key ) . '</code></td><td>' . esc_html( (string) $avg ) . '</td></tr>';
|
|
}
|
|
echo '</tbody></table>';
|
|
}
|
|
}
|
|
|
|
} // end if ( ! class_exists )
|