array( array( 'handle' => 'aiforya-sm-tab-health', 'src' => AIFORYA_SM_URL . 'assets/css/tab-health.css', 'ver' => AIFORYA_SM_VERSION, ), ), ); } public function render( array $args = array() ): void { $service = Aiforya_Schema_Markup_Health::get_instance(); $report = $service->compute_score(); $history = $service->get_history( 90 ); $nonce = wp_create_nonce( 'aiforya_sm_admin_nonce' ); $score = (int) $report['score']; $status = $score >= 90 ? 'excellent' : ( $score >= 70 ? 'good' : ( $score >= 50 ? 'partial' : 'weak' ) ); /* * V786-B — le comportement part par wp_add_inline_script() (grief n°2 de wordpress.org, * compté ERREUR par le Plugin Check). NOWDOC obligatoire : le corps contient $btn, $host, * $t, $status, $ — un heredoc les remplacerait par du vide, en silence. */ $handle = 'aiforya-sm-tab-health-js'; wp_register_script( $handle, false, array( 'jquery' ), AIFORYA_SM_VERSION, true ); wp_enqueue_script( $handle ); wp_localize_script( $handle, 'aiforyaSmHealthL10n', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => $nonce, 'recomputing' => __( 'Recalculating…', 'aiforya-schema-markup' ), 'recomputed' => __( 'Score recalculated.', 'aiforya-schema-markup' ), 'recomputedOk' => __( 'Health Score recalculated.', 'aiforya-schema-markup' ), 'failed' => __( 'Failed.', 'aiforya-schema-markup' ), 'network' => __( 'Network error.', 'aiforya-schema-markup' ), ) ); $js = <<<'JS' jQuery(function($){ var L = window.aiforyaSmHealthL10n || {}; var ajaxUrl = window.ajaxurl || L.ajaxUrl; var nonce = L.nonce; $('#aiforya-sm-health-toast-host').appendTo('body'); function smToast(message, type, ttl) { type = type || 'info'; ttl = ttl || 4500; var $host = $('.aiforya-sm-toast-host').last(); var $t = $('
', { 'class': 'aiforya-sm-toast aiforya-sm-toast--' + type, role: 'status' }).text(message); $host.append($t); setTimeout(function(){ $t.addClass('is-visible'); }, 10); setTimeout(function(){ $t.removeClass('is-visible'); setTimeout(function(){ $t.remove(); }, 300); }, ttl); } $('#aiforya-sm-health-recompute').on('click', function(){ var $btn = $(this); var $status = $('.aiforya-sm-health-status-text'); $btn.prop('disabled', true); $status.text(L.recomputing).css('color', '#94a3b8'); $.post(ajaxUrl, { action: 'aiforya_sm_health_compute', nonce: nonce }).done(function(r){ if (r && r.success) { $status.text(L.recomputed).css('color', '#4ade80'); smToast(L.recomputedOk, 'success'); setTimeout(function(){ location.reload(); }, 600); } else { $status.text((r && r.data && r.data.message) || L.failed).css('color', '#f87171'); } }).fail(function(){ $status.text(L.network).css('color', '#f87171'); }).always(function(){ $btn.prop('disabled', false); }); }); }); JS; wp_add_inline_script( $handle, $js ); // Helper D2 : pastille d'aide « ? » charte (AiforyaTooltip). $text déjà traduit. $tip = static function ( $text ) { printf( '', esc_attr( $text ) ); }; ?>