Commit a26247bc authored by Ryan McCue's avatar Ryan McCue
Browse files

Move filter callbacks to the class

This ensures that we can remove the filters at a later date.
parent 5bcfc665
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -23,9 +23,6 @@ class S3_Uploads {

	public function __construct( $bucket, $key, $secret ) {
		
		add_filter( 'upload_dir', array( $this, 'filter_upload_dir' ) );
		remove_filter( 'admin_notices', 'wpthumb_errors' );
		
		$this->bucket = $bucket;
		$this->key = $key;
		$this->secret = $secret;
@@ -73,4 +70,13 @@ class S3_Uploads {

		return $this->s3;
	}

	public function filter_editors( $editors ) {

		if ( ( $position = array_search( 'WP_Image_Editor_Imagick', $editors ) ) !== false ) {
			unset($editors[$position]);
		}

		return $editors;
	}
}
 No newline at end of file
+5 −10
Original line number Diff line number Diff line
@@ -15,14 +15,9 @@ if ( defined( 'WP_CLI' ) && WP_CLI ) {
}

add_action( 'plugins_loaded', function() {
	S3_Uploads::get_instance();
});

add_filter( 'wp_image_editors', function( $editors ) {
	$instance = S3_Uploads::get_instance();

	if ( ( $position = array_search( 'WP_Image_Editor_Imagick', $editors ) ) !== false ) {
		unset($editors[$position]);
	}

	return $editors;
}, 9 );
 No newline at end of file
	add_filter( 'upload_dir', array( $instance, 'filter_upload_dir' ) );
	add_filter( 'wp_image_editors', array( $instance, 'filter_editors' ), 9 );
	remove_filter( 'admin_notices', 'wpthumb_errors' );
});