Advertisement
phpface

Filter Better Messages file meta

Jan 6th, 2023
1,349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. /**
  2.  *
  3.  * Filter Better Messages file meta
  4.  *
  5.  */
  6. add_filter( 'better_messages_rest_message_meta', function( $meta, $message_id, $thread_id, $content ){
  7.  
  8.     if( $meta['files'] ){
  9.         $files = $meta['files'];
  10.  
  11.         for ( $i = 0;  $i <  count( $files ); $i++)  {
  12.  
  13.             if( wp_attachment_is( 'video', $files[$i]['id'] ) || wp_attachment_is( 'audio', $files[$i]['id'] ) ){
  14.  
  15.                 global $streamtube;
  16.  
  17.                 remove_filter( 'wp_get_attachment_url', array( $streamtube->get()->bunnycdn, 'filter_wp_get_attachment_url' ), 100, 2 );
  18.  
  19.                 $files[$i]['url'] = wp_get_attachment_url( $files[$i]['id'] );
  20.             }
  21.  
  22.         }
  23.  
  24.         $meta['files'] = $files;
  25.     }
  26.  
  27.     return $meta;
  28.  
  29. }, 20, 4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement