79a6c4d724
- Add TMDO_Promotion_Guard: HivePress models read every meta key with an empty-key get_*_meta() and WooCommerce does the same for products (and writes stock/sales with direct SQL), so on those sites native meta must stay authoritative. Promotion to aeav_only is refused in TMDO_Mode_Manager::set() (covers REST, CLI, phases, auto-promoter) for post/user/term/comment with HivePress and post/user with WooCommerce; TMDO_Post_Migration::cleanup() and the cleanup phase refuse too. Demotion stays open; filter tmdo_promotion_guard_allow overrides. - Admin notice lists guarded entities already in aeav_only with the restore-native command (no forced demotion on read). - Verify: PromotionGuardTest 8 OK; unit 668 OK, integration 480 OK, phpcs (phpcs.xml) 0, stan OK; dev36 live: 4 promotions + post-cleanup refused, wpdo_bridge_modes unchanged - PR: PR-053
64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
||
/**
|
||
* Admin notice when an entity is in aeav_only on a HivePress / WooCommerce site.
|
||
*
|
||
* Those plugins read native meta directly, so on an aeav_only entity they read
|
||
* stale (or, after cleanup, missing) values. The Promotion Guard refuses new
|
||
* promotions; sites promoted before it existed are only warned — demoting on
|
||
* read would leave them reading whatever native meta is left.
|
||
*
|
||
* @package WP_Data_Optimizer
|
||
*/
|
||
|
||
declare(strict_types=1);
|
||
|
||
if ( ! defined( 'ABSPATH' ) ) {
|
||
exit;
|
||
}
|
||
|
||
/**
|
||
* Warns administrators about guarded entities that are already in aeav_only.
|
||
*/
|
||
final class TMDO_Promotion_Guard_Notice {
|
||
|
||
/**
|
||
* Hook the notice.
|
||
*
|
||
* @return void
|
||
*/
|
||
public static function register(): void {
|
||
add_action( 'admin_notices', array( __CLASS__, 'render' ) );
|
||
}
|
||
|
||
/**
|
||
* Print the notice for administrators when a guarded entity is in aeav_only.
|
||
*
|
||
* @return void
|
||
*/
|
||
public static function render(): void {
|
||
if ( ! current_user_can( 'manage_options' ) ) {
|
||
return;
|
||
}
|
||
$violations = TMDO_Promotion_Guard::violations();
|
||
if ( empty( $violations ) ) {
|
||
return;
|
||
}
|
||
|
||
$lines = array();
|
||
foreach ( $violations as $entity_type => $integrations ) {
|
||
$lines[] = sprintf( '%s(%s):wp tmdo bridge-restore-native %s --demote', $entity_type, implode( ' / ', $integrations ), $entity_type );
|
||
}
|
||
printf(
|
||
'<div class="notice notice-error"><p><strong>%s</strong> %s</p></div>',
|
||
esc_html__( '2meet Data Optimizer:', '2meet-data-optimizer' ),
|
||
esc_html(
|
||
sprintf(
|
||
/* translators: %s: "entity (integrations): command" list */
|
||
__( '以下實體處於 aeav_only,但這些外掛會直接讀取原生 meta,可能讀到過期或遺失的資料。請先備份,再把扁平資料寫回原生並降級:%s', '2meet-data-optimizer' ),
|
||
implode( ';', $lines )
|
||
)
|
||
)
|
||
);
|
||
}
|
||
}
|