Skip to content

Commit

Permalink
Fix multisite image renders (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephfusco authored Aug 12, 2020
1 parent a58ea2a commit ebb4810
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.6.1] - 2020-08-12

## Fixed

- Fixes a bug where certain images are being rendered incorrectly within a multisite setup.

## [2.6.0] - 2020-08-05

### Added
Expand Down
13 changes: 10 additions & 3 deletions lib/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,17 @@ public function add_image_to_library(): void {
public static function get_widen_url_path( $url ) {
$url_arr = wp_parse_url( $url );
$url_path = $url_arr['path'];
$path = '';

$path = ltrim( $url_path, '/wp-content/uploads/' );
// Remove the WordPress uploads base path from the URL.
if ( is_multisite() ) {
$blog_id = get_current_blog_id();
$path = preg_replace( "/^\/wp-content\/uploads\/sites\/$blog_id\//", '', $url_path );
} else {
$path = preg_replace( '/^\/wp-content\/uploads\//', '', $url_path );
}

return $path;
return ltrim( $path, '/' );
}

/**
Expand All @@ -625,7 +632,7 @@ public function fix_widen_attachment_url( $url, $attachment_id ) {
if ( ! empty( $widen_media_id ) ) {
$base_url = Widen::$base_url;
$url_path = self::get_widen_url_path( $url );
$widen_attachment_url = trailingslashit( $base_url ) . $url_path;
$widen_attachment_url = trailingslashit( $base_url ) . ltrim( $url_path, '/' );

return $widen_attachment_url;
}
Expand Down
2 changes: 1 addition & 1 deletion widen-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Widen Media
* Description: Search and add Widen digital assets to your WordPress media library.
* Version: 2.6.0
* Version: 2.6.1
* Author: Masonite
* Author URI: https://www.masonite.com/
* License: GPL-2.0+
Expand Down

0 comments on commit ebb4810

Please sign in to comment.