डेवलपर्स के लिए हुक और फिल्टर

5 मिनट पढ़ें

स्टैंडर्ड WordPress हुक से TTSWP को बढ़ाएं या कस्टमाइज़ करें। इन्हें अपने थीम के functions.php या किसी कस्टम प्लगइन में जोड़ें। हर हुक स्थिर और दस्तावेज़ीकृत है।

फिल्टर हुक

सिंथेसिस से पहले टेक्स्ट संशोधित करें

इसका उपयोग कंटेंट साफ करने, कस्टम मार्कअप जोड़ने, या ऑडियो बनने से पहले कुछ हिस्से हटाने के लिए करें।

add_filter( 'mementor_tts_pre_synthesize_text', function( $text, $post_id ) {
    // आपके संशोधन
    $text = str_replace( 'WP', 'WordPress', $text );
    return $text;
}, 10, 2 );

विशिष्ट पोस्ट के लिए ऑडियो छोड़ें

ऑटो-जनरेशन से किसी पोस्ट को छोड़ने के लिए true लौटाएं।

add_filter( 'mementor_tts_skip_auto_generation', function( $skip, $post_id ) {
    // "archive" श्रेणी की पोस्ट छोड़ें
    if ( has_category( 'archive', $post_id ) ) {
        return true;
    }
    return $skip;
}, 10, 2 );

कैश कुंजी बदलें

TTSWP की ऑडियो कैश कुंजी बनाने के तरीके को ओवरराइड करें। तब उपयोगी होता है जब आप प्रति-उपयोगकर्ता या कस्टम संदर्भ के अनुसार अलग कैशिंग चाहते हों।

add_filter( 'mementor_tts_audio_cache_key', function( $key, $text, $voice ) {
    return $key . '_' . get_current_user_id();
}, 10, 3 );

डिफ़ॉल्ट वॉयस कस्टमाइज़ करें

विशिष्ट पोस्ट के लिए कौन सी वॉयस उपयोग होगी, यह बदलें।

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 );

कॉलम मार्कअप रेंडर करें

पोस्ट सूची में कस्टम कॉलम कंटेंट रेंडर करने के लिए मल्टी-लैंग्वेज इंटीग्रेशन द्वारा उपयोग किया जाता है।

add_filter( 'mementor_tts_render_column', function( $rendered, $post_id, $audio_exists, $audio_url, $processing, $post_status ) {
    // डिफ़ॉल्ट छोड़ने के लिए अपना मार्कअप रेंडर करने के बाद true लौटाएं
    return $rendered;
}, 10, 6 );

एक्शन हुक

ऑडियो बनने से पहले

add_action( 'mementor_tts_before_generate', function( $post_id, $text, $voice ) {
    // लॉग करें, सूचित करें, या कुछ तैयार करें
}, 10, 3 );

ऑडियो बनने के बाद

add_action( 'mementor_tts_audio_generated', function( $post_id, $audio_url, $characters ) {
    // सूचित करें, कस्टम फील्ड अपडेट करें, बाहरी क्यू में भेजें
}, 10, 3 );

ऑडियो डिलीट होने के बाद

add_action( 'mementor_tts_audio_deleted', function( $post_id ) {
    // संबंधित डेटा साफ करें
} );

साइट कनेक्ट होने पर

add_action( 'mementor_tts_site_connected', function( $site_token ) {
    // अपनी टीम को सूचित करें, वेलकम ईमेल भेजें, आदि
} );

कॉन्स्टेंट जो आप परिभाषित कर सकते हैं

wp-config.php में परिभाषित करें:

डीबग लॉगिंग सक्षम करें

define( 'MEMENTOR_TTS_DEBUG', true );

सेट होने पर, विस्तृत लॉग wp-content/debug.log में लिखे जाते हैं।

API एंडपॉइंट ओवरराइड करें

स्टेजिंग या टेस्टिंग वातावरण के लिए:

define( 'MEMENTOR_TTS_API_URL', 'https://staging.ttswp.com' );

सामान्य कस्टमाइज़ेशन रेसिपी

ब्लॉक एडिटर साइडबार में प्रति-पोस्ट वॉयस पिकर जोड़ें

प्लगइन पहले से एडिटर में TTS पैनल जोड़ता है। आप इसे बढ़ा सकते हैं:

add_filter( 'mementor_tts_editor_sidebar_fields', function( $fields ) {
    $fields[] = [
        'key' => 'speaking_speed',
        'label' => 'Speaking speed',
        'type' => 'number',
    ];
    return $fields;
} );

हर जनरेशन 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( 'Generated %d chars for post %s: %s', $characters, get_the_title( $post_id ), $audio_url ),
        ] ),
    ] );
}, 10, 3 );

स्थिरता का वादा

इस पेज पर सूचीबद्ध हुक स्थिर पब्लिक API हैं। हम इन्हें changelog में कम से कम एक मेजर वर्शन नोटिस और पिछले मेजर वर्शन के लिए डेप्रिकेशन चेतावनी के बिना हटाते या नाम नहीं बदलते।