Skip to content

Commit

Permalink
Multisite compatibility
Browse files Browse the repository at this point in the history
Create our own multisite folder structure when it is a multisite and the current site is NOT the main site.
  • Loading branch information
JoryHogeveen committed May 20, 2016
1 parent c458894 commit ca8a5a5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions image-watermark.php
Expand Up @@ -411,11 +411,18 @@ public function attachment_fields_to_edit( $form_fields, $post ) {
$form_fields['image_watermark'] = array(
'show_in_edit' => false,
'tr' => '

This comment has been minimized.

Copy link
@JoryHogeveen

JoryHogeveen May 20, 2016

Author Owner

Not show the options unless our javascript file is loaded

<div id="image_watermark_buttons" class="' . $class . '" data-id="' . $post->ID . '">
<div id="image_watermark_buttons" class="' . $class . '" data-id="' . $post->ID . '" style="display: none;">
<h3>' . __( 'Image Watermark', 'image-watermark' ) . '</h3>
<button class="iw-watermark-action" data-action="applywatermark" data-id="' . $post->ID . '">' . __( 'Apply watermark', 'image-watermark' ) . '</button>
<button class="iw-watermark-action" data-action="removewatermark" data-id="' . $post->ID . '">' . __( 'Remove watermark', 'image-watermark' ) . '</button>
</div>

This comment has been minimized.

Copy link
@JoryHogeveen

JoryHogeveen May 20, 2016

Author Owner

Not show the options unless our javascript file is loaded

<script>
jQuery( document ).ready( function ( $ ) {
if ( typeof watermarkImageActions != "undefined" ) {
$("#image_watermark_buttons").show();
}
});
</script>
',
);
}
Expand Down Expand Up @@ -863,8 +870,8 @@ public function do_watermark( $attachment_id, $image_path, $image_size, $upload_
* $return bool
*/
private function do_backup( $data, $upload_dir, $attachment_id ) {
$backupfolder = IMAGE_WATERMARK_BACKUP_DIR;
$backup_filepath = $backupfolder . DIRECTORY_SEPARATOR . $data['file'];
// get the filepath for the backup image we're creating
$backup_filepath = $this->get_image_backup_filepath( $data['file'] );

// Make sure the backup isn't created yet
if ( ! file_exists( $backup_filepath ) ) {
Expand All @@ -879,6 +886,7 @@ private function do_backup( $data, $upload_dir, $attachment_id ) {
// create backup directory if needed
wp_mkdir_p( $this->get_image_backup_folder_location( $data['file'] ) );


// save backup image
$this->save_image_file( $image, $mime['type'], $backup_filepath, $this->options['backup']['backup_quality'] );

Expand Down Expand Up @@ -956,6 +964,10 @@ private function get_image_backup_folder_location( $filepath ) {
$path = explode( DIRECTORY_SEPARATOR, $filepath );
array_pop( $path );
$path = implode( DIRECTORY_SEPARATOR, $path );
// Multisite?
if ( is_multisite() && ! is_main_site() ) {
$path = 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR . $path;
}
return IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . $path;
}

Expand All @@ -966,6 +978,10 @@ private function get_image_backup_folder_location( $filepath ) {
* @return string $backup_filepath
*/
private function get_image_backup_filepath( $filepath ) {
// Multisite?
if ( is_multisite() && ! is_main_site() ) {
$filepath = 'sites' . DIRECTORY_SEPARATOR . get_current_blog_id() . DIRECTORY_SEPARATOR . $filepath;
}
return IMAGE_WATERMARK_BACKUP_DIR . DIRECTORY_SEPARATOR . $filepath;
}

Expand Down

0 comments on commit ca8a5a5

Please sign in to comment.