Developer Examples
Learn how to extend and customize Viscribe using our built-in hooks.
1. Skip Renaming for Specific User Roles
php
add_filter( 'viscribe_should_process_upload', function( $should, $file, $mime_type ) {
if ( current_user_can( 'administrator' ) ) return false;
return $should;
}, 10, 3 );2. Branding: Prepend a Prefix
php
add_filter( 'viscribe_new_filename', function( $filename, $base, $ext, $file, $desc ) {
return 'my-brand-' . $base . '.' . $ext;
}, 10, 5 );3. Restrict to JPEG Only
php
add_filter( 'viscribe_allowed_file_types', function( $types, $mime ) {
return [ 'image/jpeg', 'image/jpg' ];
}, 10, 2 );4. German Keywords
php
add_filter( 'viscribe_prompt', function( $prompt, $max_keywords, $set_alt ) {
return "Beschreibe dieses Bild in maximal $max_keywords Wörtern. Antworte nur auf Deutsch.";
}, 10, 3 );5. Clean Up Common Filler Phrases
php
add_filter( 'viscribe_generated_description', function( $desc, $tmp_path, $file ) {
return str_ireplace( [ 'a photo of', 'an image of', 'photograph of' ], '', $desc );
}, 10, 3 );6. Force a Specific AI Model
php
add_filter( 'viscribe_api_payload', function( $payload ) {
$payload['model'] = 'meta-llama/llama-4-scout-17b-16e-instruct';
return $payload;
} );7. Slack Notification on Rename
php
add_action( 'viscribe_image_renamed', function( $new, $original, $desc, $file ) {
wp_remote_post( 'https://hooks.slack.com/services/YOUR/WEBHOOK', [
'body' => json_encode( [
'text' => "�� Image renamed!\nOriginal: `$original`\nNew: `$new`"
] )
] );
}, 10, 4 );8. Log API Transactions
php
add_action( 'viscribe_api_response', function( $decoded, $code, $image_path ) {
$log = sprintf( "[%s] %d for %s\n", current_time( 'mysql' ), $code, basename( $image_path ) );
file_put_contents( WP_CONTENT_DIR . '/viscribe-api.log', $log, FILE_APPEND );
}, 10, 3 );9. Increase File Size Limit
php
add_filter( 'viscribe_max_file_size', function( $max, $path ) {
return 20 * MB_IN_BYTES; // 20 MB
}, 10, 2 );10. Custom Alt Text Format
php
add_filter( 'viscribe_alt_text', function( $text, $desc, $file ) {
return 'Photo description: ' . ucfirst( $text );
}, 10, 3 );