wordpress - Customize upload folder for sites -
i´ve installed wordpress multisite installation (version 4.2.1) mapped domains.
for each site url uploaded image shown in browser http://url/wp-content/uploads/sites/sitenumber/date/...
, folder /path/to/wordpress/wp-content/uploads/sites/sitenumber/date/...
. want use local path /path/to/wordpress/wp-content/uploads/sites/sitenumber/...
, want see in browser http://url/wp-content/uploads/date/...
(like in single wordpress site).
i´ve read , think know option "upload url path" should rewrite this, doesn´t it? me doesn´t work. how customize wordpress fit it?
update: i´ve found out in functions.php define multisites rewrite of url:
// if multisite (and if not main site in post-mu network) if ( is_multisite() && ! ( is_main_network() && is_main_site() && defined( 'multisite' ) ) ) { if ( ! get_site_option( 'ms_files_rewriting' ) ) { /* * if ms-files rewriting disabled (networks created post-3.5), * straightforward: append sites/%d if we're not on main site (for post-mu * networks). (the directory prevents four-digit id conflicting * year-based directory main site. if mu-era network has disabled * ms-files rewriting manually, don't need directory, never * had wp-content/uploads main site.) */ if ( defined( 'multisite' ) ) $ms_dir = '/sites/' . get_current_blog_id(); else $ms_dir = '/' . get_current_blog_id(); $dir .= $ms_dir; $url .= $ms_dir; ... }}
but didn´t know how change needed behavior.
yes can change upload directory in wordpress using below function.
add_filter( 'upload_dir', 'upload_dir_filter' ); function upload_dir_filter( $upload ) { $dir = $_server['document_root']; $upload_dir = $dir['basedir'] . '/uploads/date'; $upload_url = $dir['baseurl'] . '/uploads/date'; wp_mkdir_p( $upload_dir ); //wordpress check if dir exists , can write it. $upload['path'] = $upload_dir; $upload['url'] = $upload_url; return $upload; }
Comments
Post a Comment