Advertisement
wclovers

Product dowloadable file size minimum 320kbps

Nov 26th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.06 KB | None | 0 0
  1. add_filter( 'wcfm_form_custom_validation', function( $form_data, $screen ) {
  2.     if( 'product_manage' == $screen ) {
  3.         if( isset( $form_data['is_downloadable'] ) && isset( $form_data['downloadable_files'] ) ) {
  4.             if( !class_exists( 'getID3' ) ) {
  5.                 require(ABSPATH.WPINC.'/ID3/getid3.php' );
  6.             }
  7.  
  8.             foreach( $form_data['downloadable_files'] as $downloadable_file ) {
  9.                 $getID3 = new getID3;
  10.                 $file = $getID3->analyze( ABSPATH . str_replace( get_site_url(), '', $downloadable_file['file'] ) );
  11.  
  12.                 if( is_array( $file ) && 'mp3' == $file['fileformat'] ) {
  13.                     if( isset( $file['audio'] ) && isset( $file['audio']['bitrate'] ) && $file['audio']['bitrate'] < 320*1000 ) {
  14.                         $form_data['has_error'] = true;
  15.                         $form_data['message'] = __( 'mp3 files should not be less than 320kbps', 'wc-frontend-manager' );
  16.                     }
  17.                 }
  18.             }
  19.         }
  20.     }
  21.     return $form_data;
  22. }, 999, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement