Skip to content

Commit

Permalink
fixes for network location save
Browse files Browse the repository at this point in the history
  • Loading branch information
benbalter committed Apr 28, 2012
1 parent c02f3fc commit b3a653a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
43 changes: 21 additions & 22 deletions includes/admin.php
Expand Up @@ -53,8 +53,8 @@ function __construct( &$instance = null) {
//settings
add_action( 'admin_init', array( &$this, 'settings_fields') );
add_action( 'update_wpmu_options', array( &$this, 'network_upload_location_save' ) );
add_action( 'update_wpmu_options', array( &$this, 'network_document_slug_save' ) );
add_action( 'wpmu_options', array( &$this, 'network_upload_location_cb' ) );
add_action( 'update_wpmu_options', array( &$this, 'network_slug_save' ) );
add_action( 'wpmu_options', array( &$this, 'network_settings_cb' ) );
add_action( 'network_admin_notices', array( &$this, 'network_settings_errors' ) );
add_filter( 'wp_redirect', array( &$this, 'network_settings_redirect' ) );

Expand Down Expand Up @@ -453,7 +453,7 @@ function settings_fields() {
register_setting( 'media', 'document_upload_directory', array( &$this, 'sanitize_upload_dir') );
register_setting( 'media', 'document_slug', array( &$this, 'sanitize_document_slug') );
add_settings_field( 'document_upload_directory', 'Document Upload Directory', array( &$this, 'upload_location_cb' ), 'media', 'uploads' );
add_settings_field( 'document_slug', 'Document Slug', array( &$this, 'document_slug_cb' ), 'media', 'uploads' );
add_settings_field( 'document_slug', __( 'Document Slug', 'wp-document-revisions' ), array( &$this, 'document_slug_cb' ), 'media', 'uploads' );

}

Expand All @@ -467,32 +467,24 @@ function settings_fields() {
*/
function sanitize_upload_dir( $dir ) {

//empty string passed
if ( $dir == '' )
return $this->document_upload_dir();

//if the path is not absolute, assume it's relative to ABSPATH
if ( substr( $dir, 0, 1) != '/' )
$dir = ABSPATH . $dir;

//directory does not exist
if ( !is_dir( $dir ) ) {

//attempt to make the directory
if ( !mkdir( $dir ) ) {

//could not make the directory
$msg = __( 'Please enter a valid document upload directory.', 'wp-document-revisions' );
add_settings_error( 'document_upload_directory', 'invalid-document-upload-dir', $msg, 'error' );
return false;

}

}

//dir didn't change
if ( $dir == $this->document_upload_dir() )
return $dir;

//dir changed, throw warning
$msg = __( 'Document upload directory changed, but existing uploads may need to be moved to the new folder to ensure they remain accessible.', 'wp-document-revisions' );
add_settings_error( 'document_upload_directory', 'document-upload-dir-change', $msg, 'updated' );

//don't fire more than once
if ( sizeof( get_settings_errors( 'document_upload_directory' ) ) == 0 )
add_settings_error( 'document_upload_directory', 'document-upload-dir-change', $msg, 'updated' );

//trim and return
return rtrim($dir, "/");
Expand All @@ -513,7 +505,9 @@ function sanitize_document_slug( $slug ) {
if ( $slug == $this->document_slug() )
return $slug;

flush_rewrite_rules();
//new slug isn't yet stored
// but queue up a rewrite rule flush to ensure slug takes effect on next request
add_action( 'shutdown', 'flush_rewrite_rules' );

$msg = __( 'Document slug changed, but some previously published URLs may now be broken.', 'wp-document-revisions' );
add_settings_error( 'document_slug', 'document-slug-change', $msg, 'updated' );
Expand All @@ -527,14 +521,19 @@ function sanitize_document_slug( $slug ) {
* Adds upload directory and document slug options to network admin page
* @since 1.0
*/
function network_upload_location_cb() { ?>
function network_settings_cb() { ?>
<h3><?php _e( 'Document Settings', 'wp-document-revisions'); ?></h3>
<table id="document_settings" class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Document Upload Directory', 'wp-document-revisions'); ?></th>
<td>
<?php $this->upload_location_cb(); ?>
<?php wp_nonce_field( 'network_document_upload_location', 'document_upload_location_nonce' ); ?>
</td>
</tr>
<tr>
<th scope="row"><?php _e('Document Slug', 'wp-document-revisions'); ?></th>
<td>
<?php $this->document_slug_cb(); ?>
<?php wp_nonce_field( 'network_document_slug', 'document_slug_nonce' ); ?>
</td>
Expand Down Expand Up @@ -646,7 +645,7 @@ function upload_location_cb() { ?>
<input name="document_upload_directory" type="text" id="document_upload_directory" value="<?php echo esc_attr( $this->document_upload_dir() ); ?>" class="large-text code" /><br />
<span class="description"><?php _e( 'Directory in which to store uploaded documents. The default is in your <code>wp_content/uploads</code> folder (or another default uploads folder defined elsewhere), but it may be moved to a folder outside of the <code>htdocs</code> or <code>public_html</code> folder for added security.', 'wp-document-revisions' ); ?></span>
<?php if ( is_multisite() ) { ?>
<span class="description"><?php _e( 'Hint: You may optionally include the string <code>%site_id%</code> within the path to separate files by site', 'wp-document-revisions' ); ?></span>
<span class="description"><?php _e( 'You may optionally include the string <code>%site_id%</code> within the path to separate files by site.', 'wp-document-revisions' ); ?></span>
<?php } ?>
<?php }

Expand Down
6 changes: 5 additions & 1 deletion wp-document-revisions.php
Expand Up @@ -893,7 +893,11 @@ function document_upload_dir() {
if ( !is_multisite() )
return $dir;

return str_replace( '%site_id%', $wpdb->blogid, $dir );
//make site specific on multisite
if ( is_multisite() && !is_network_admin() )
$dir = str_replace( '%site_id%', $wpdb->blogid, $dir );

return $dir;

}

Expand Down

0 comments on commit b3a653a

Please sign in to comment.