Perluas atau sesuaikan TTSWP dengan hooks WordPress standar. Tambahkan kode berikut ke functions.php tema Anda atau plugin kustom. Setiap hook stabil dan terdokumentasi.
Filter hooks
Modifikasi teks sebelum sintesis
Gunakan ini untuk membersihkan konten, menyisipkan markup kustom, atau menghapus bagian tertentu sebelum audio dibuat.
add_filter( 'mementor_tts_pre_synthesize_text', function( $text, $post_id ) {
// Modifikasi Anda
$text = str_replace( 'WP', 'WordPress', $text );
return $text;
}, 10, 2 );
Lewati audio untuk post tertentu
Kembalikan true untuk melewati post dari pembuatan otomatis.
add_filter( 'mementor_tts_skip_auto_generation', function( $skip, $post_id ) {
// Lewati post dalam kategori "arsip"
if ( has_category( 'archive', $post_id ) ) {
return true;
}
return $skip;
}, 10, 2 );
Ubah cache key
Override cara TTSWP membuat cache key audio. Berguna jika Anda ingin caching berbeda per pengguna atau per konteks kustom.
add_filter( 'mementor_tts_audio_cache_key', function( $key, $text, $voice ) {
return $key . '_' . get_current_user_id();
}, 10, 3 );
Sesuaikan suara default
Ubah suara yang digunakan untuk post tertentu.
add_filter( 'mementor_tts_voice_for_post', function( $voice_id, $post_id ) {
if ( get_post_type( $post_id ) === 'podcast' ) {
return 'my-podcast-voice-id';
}
return $voice_id;
}, 10, 2 );
Render markup kolom
Digunakan oleh integrasi multi-bahasa untuk merender konten kolom kustom pada daftar post.
add_filter( 'mementor_tts_render_column', function( $rendered, $post_id, $audio_exists, $audio_url, $processing, $post_status ) {
// Kembalikan true setelah merender markup Anda sendiri untuk melewati default
return $rendered;
}, 10, 6 );
Action hooks
Sebelum audio dibuat
add_action( 'mementor_tts_before_generate', function( $post_id, $text, $voice ) {
// Log, beri notifikasi, atau siapkan sesuatu
}, 10, 3 );
Setelah audio dibuat
add_action( 'mementor_tts_audio_generated', function( $post_id, $audio_url, $characters ) {
// Beri notifikasi, perbarui field kustom, kirim ke antrian eksternal
}, 10, 3 );
Setelah audio dihapus
add_action( 'mementor_tts_audio_deleted', function( $post_id ) {
// Bersihkan data terkait
} );
Saat situs terhubung
add_action( 'mementor_tts_site_connected', function( $site_token ) {
// Beri tahu tim Anda, kirim email sambutan, dll.
} );
Konstanta yang dapat Anda definisikan
Definisikan di wp-config.php:
Aktifkan debug logging
define( 'MEMENTOR_TTS_DEBUG', true );
Jika diset, log lengkap akan ditulis ke wp-content/debug.log.
Override endpoint API
Untuk lingkungan staging atau pengujian:
define( 'MEMENTOR_TTS_API_URL', 'https://staging.ttswp.com' );
Resep kustomisasi umum
Tambahkan pemilih suara per-post ke sidebar block editor
Plugin sudah menambahkan panel TTS ke editor. Anda bisa memperluas:
add_filter( 'mementor_tts_editor_sidebar_fields', function( $fields ) {
$fields[] = [
'key' => 'speaking_speed',
'label' => 'Kecepatan bicara',
'type' => 'number',
];
return $fields;
} );
Kirim setiap pembuatan audio ke Slack
add_action( 'mementor_tts_audio_generated', function( $post_id, $audio_url, $characters ) {
wp_remote_post( 'https://hooks.slack.com/your-webhook', [
'body' => json_encode( [
'text' => sprintf( 'Dibuat %d karakter untuk post %s: %s', $characters, get_the_title( $post_id ), $audio_url ),
] ),
] );
}, 10, 3 );
Jaminan stabilitas
Hooks yang tercantum di halaman ini adalah API publik yang stabil. Kami tidak menghapus atau mengubah namanya tanpa setidaknya satu pemberitahuan versi mayor di changelog dan peringatan deprecation untuk versi mayor sebelumnya.