Files
packs/wordpress/mu-plugin-d0a1-editorial.php
T

44 lines
1.6 KiB
PHP

<?php
/**
* Plugin Name: d0a1 — Instrucciones editoriales IA (mu-plugin)
* Description: Inyecta el estilo editorial (editorial-style.php del pack) en las instrucciones de sistema del plugin "AI".
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
function d0a1_editorial_style() {
$file = WP_CONTENT_DIR . '/editorial-style.php';
if ( ! file_exists( $file ) ) { return null; }
$s = include $file;
return is_array( $s ) ? $s : null;
}
function d0a1_editorial_block() {
$s = d0a1_editorial_style();
if ( ! $s ) { return ''; }
$out = "\n\nESTILO EDITORIAL DEL SITIO (prioridad sobre instrucciones anteriores):\n";
if ( ! empty( $s['estilo'] ) ) { $out .= 'Tono: ' . $s['estilo'] . "\n"; }
if ( ! empty( $s['reglas'] ) ) {
$out .= "Normas:\n";
foreach ( $s['reglas'] as $r ) { $out .= '- ' . $r . "\n"; }
}
if ( ! empty( $s['prohibido'] ) ) {
$out .= "Prohibido:\n";
foreach ( $s['prohibido'] as $p ) { $out .= '- ' . $p . "\n"; }
}
return $out;
}
// Global: todas las funciones IA del plugin (titulos, extractos, alt text, moderacion...).
add_filter( 'wpai_system_instruction', function ( $instruction ) {
return $instruction . d0a1_editorial_block();
}, 10, 1 );
// Afinar titulares: max chars configurable en editorial-style.php.
add_filter( 'wpai_title_generation_system_instruction', function ( $instruction ) {
$s = d0a1_editorial_style();
if ( $s && ! empty( $s['titulares_max_chars'] ) && $s['titulares_max_chars'] !== 80 ) {
$instruction = preg_replace( '/Be no more than \d+ characters/', 'Be no more than ' . (int) $s['titulares_max_chars'] . ' characters', $instruction );
}
return $instruction;
}, 10, 1 );