Guest User

Untitled

a guest
Sep 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2. add_filter( 'sanitize_file_name', 'cb_sanitize_file_name' );
  3. /**
  4. * {@internal Missing short description}}
  5. *
  6. * @link wp-includes|formatting.php
  7. * @todo causing errors at media-new.php
  8. */
  9. function cb_sanitize_file_name( $filename ) {
  10. if ( isset( $_REQUEST['post_id'] ) )
  11. $post_id = $_REQUEST['post_id'];
  12. else
  13. $post_id = false;
  14.  
  15. // fetch the file extension
  16. $info = pathinfo( $filename );
  17. $ext = empty( $info['extension'] ) ? '' : '.' . $info['extension'];
  18.  
  19. // get the post object
  20. $post_obj = get_post( $post_id );
  21.  
  22. // get the post title
  23. $post_title = sanitize_title_with_dashes( $post_obj->post_title );
  24.  
  25. // random number
  26. $random_number = rand( 10000, 99999 );
  27.  
  28. return $post_title . '-' . $random_number . $ext;
  29. }
Add Comment
Please, Sign In to add comment