// Envía una notificación automática a redes sociales cuando se publica una nota nueva
function auto_publicar_redes_sociales( $ID, $post ) {
// Evita que se dispare si es una revisión automática
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// Solo enviar si es una entrada común (post) recién publicada
if ( $post->post_type != 'post' ) return;
// URL del Webhook de Make o Zapier (Aquí pegarás tu enlace de conexión)
$webhook_url = 'https://hook.eu1.make.com/rqagp9gsiovyofggn4d12lr2yf2fjbi2';
// Preparamos los datos de la nota
$body = array(
'titulo' => get_the_title($ID),
'enlace' => get_permalink($ID),
'imagen' => get_the_post_thumbnail_url($ID, 'large'),
'extracto' => wp_strip_all_tags(get_the_excerpt($ID))
);
// Enviamos los datos de forma segura en segundo plano sin ralentizar al redactor
wp_remote_post( $webhook_url, array(
'method' => 'POST',
'timeout' => 45,
'blocking' => false, // No congela la pantalla al publicar
'headers' => array( 'Content-Type' => 'application/json' ),
'body' => json_encode( $body )
));
}
add_action( 'publish_post', 'auto_publicar_redes_sociales', 10, 2 );