Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Commit

Permalink
Better multi-site support
Browse files Browse the repository at this point in the history
  • Loading branch information
junaidbhura committed May 6, 2018
1 parent 01fb278 commit 2fef7cf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fly-dynamic-image-resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: Fly Dynamic Image Resizer
Description: Dynamically create image sizes on the fly!
Version: 2.0.4
Version: 2.0.5
Author: Junaid Bhura
Author URI: https://junaidbhura.com
Text Domain: fly-images
Expand Down
12 changes: 12 additions & 0 deletions inc/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function init() {
add_action( 'admin_menu', array( $this, 'admin_menu_item' ) );
add_filter( 'media_row_actions', array( $this, 'media_row_action' ), 10, 2 );
add_action( 'delete_attachment', array( $this, 'delete_attachment_fly_images' ) );

add_action( 'switch_blog', array( $this, 'blog_switched' ) );
}

/**
Expand Down Expand Up @@ -402,4 +404,14 @@ public function get_fly_absolute_path( $path = '' ) {
$wp_upload_dir = wp_upload_dir();
return $wp_upload_dir['basedir'] . str_replace( $wp_upload_dir['baseurl'], '', $path );
}

/**
* Update Fly Dir when a blog is switched.
*
* @return void
*/
public function blog_switched() {
$this->_fly_dir = '';
$this->_fly_dir = apply_filters( 'fly_dir_path', $this->get_fly_dir() );
}
}
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<php>
<const name="WP_TESTS_MULTISITE" value="1" />
</php>
<testsuites>
<testsuite>
<directory prefix="test-" suffix=".php">./tests/</directory>
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: junaidbhura
Tags: media library, images, resize, dynamic, on the fly
Requires at least: 3.0
Tested up to: 4.9
Stable tag: 2.0.4
Stable tag: 2.0.5

Dynamically create image sizes on the fly!

Expand Down Expand Up @@ -126,6 +126,9 @@ Create dynamic image sizes in your PHP code!

== Changelog ==

= 2.0.5 =
* Better multi-site support [#19](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/19)

= 2.0.4 =
* Performance improvements [#15](https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/15)

Expand Down
21 changes: 21 additions & 0 deletions tests/test-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ class JB_Test_Fly_Plugin extends WP_UnitTestCase {

private static $_core;
private static $_image_id = 0;
private static $blog_2_id = 0;

/**
* Setup.
*/
static function setUpBeforeClass() {
self::$_core = \JB\FlyImages\Core::get_instance();
self::$_image_id = self::upload_image();
self::$blog_2_id = wpmu_create_blog( 'example.org', 'blog-2', 'Blog 2', 1 );
}

/**
* Tear down.
*/
static function tearDownAfterClass() {
wp_delete_attachment( self::$_image_id, true );
wpmu_delete_blog( self::$blog_2_id, true );
}

/**
Expand Down Expand Up @@ -167,4 +170,22 @@ function test_delete_all_fly_images() {
$this->assertTrue( self::$_core->delete_all_fly_images(), 'Cannot delete all fly images.' );
}

/**
* @covers JB\FlyImages\Core::blog_switched
*/
function test_multisite() {
$wp_upload_dir = wp_upload_dir();
$path_1 = $wp_upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'fly-images';
$this->assertEquals( self::$_core->get_fly_dir(), $path_1 );

switch_to_blog( self::$blog_2_id );

$wp_upload_dir = wp_upload_dir();
$path_2 = $wp_upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'fly-images';
$this->assertEquals( self::$_core->get_fly_dir(), $path_2 );

restore_current_blog();
$this->assertEquals( self::$_core->get_fly_dir(), $path_1 );
}

}

0 comments on commit 2fef7cf

Please sign in to comment.