Advertisement
retesere20

wp-uploads-dir-filter-example

May 17th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2.  
  3.  
  4. /*
  5.  
  6. function directory_control_uploads( $uploads ) {
  7. if ( defined( 'WP_UPLOAD_DIR' ) ) {
  8. $uploads['path'] = str_replace( WP_CONTENT_DIR . '/uploads', WP_UPLOAD_DIR, $uploads['path'] );
  9. $uploads['basedir'] = str_replace( WP_CONTENT_DIR . '/uploads', WP_UPLOAD_DIR, $uploads['basedir'] );
  10. }
  11. if ( defined( 'WP_UPLOAD_URL' ) ) {
  12. $uploads['url'] = str_replace( WP_CONTENT_URL . '/uploads', WP_UPLOAD_URL, $uploads['url'] );
  13. $uploads['baseurl'] = str_replace( WP_CONTENT_URL . '/uploads', WP_UPLOAD_URL, $uploads['baseurl'] );
  14. }
  15. return $uploads;
  16. }
  17.  
  18. function directory_control_theme_dir( $dir ) {
  19. if ( defined( 'WP_THEME_DIR' ) ) {
  20. $dir = str_replace( WP_CONTENT_DIR . '/themes', WP_THEME_DIR, $dir );
  21. }
  22. return $dir;
  23. }
  24.  
  25. function directory_control_theme_url( $url ) {
  26. if ( defined( 'WP_THEME_URL' ) ) {
  27. $search = set_url_scheme( WP_CONTENT_URL . '/themes' );
  28. $replace = set_url_scheme( WP_THEME_URL );
  29. $url = str_replace( $search, $replace, $url );
  30. }
  31. return $url;
  32. }
  33.  
  34. add_filter( 'upload_dir', 'directory_control_uploads', 1 );
  35. add_filter( 'theme_root', 'directory_control_theme_dir', 1 );
  36. add_filter( 'theme_root_uri', 'directory_control_theme_url', 1 );
  37.  
  38. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement