Skip to content

Commit

Permalink
Remove < 4.5 back-compat code (#514)
Browse files Browse the repository at this point in the history
No longer needed as we're on 4.7
  • Loading branch information
mjangda committed Mar 16, 2017
1 parent fe9c010 commit de78a0c
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions a8c-files.php
Expand Up @@ -32,17 +32,8 @@ function __construct() {
add_filter( 'load-importer-wordpress', array( &$this, 'check_to_download_file' ), 10 );
add_filter( 'wp_insert_attachment_data', array( &$this, 'check_to_upload_file' ), 10, 2 );

// WP 4.5 introduced a new filter, which simplifies how we generate unique filenames
// We retain test sites on the version that precedes the current stable release, making this necessary
global $wp_version;

if ( version_compare( $wp_version, '4.5', '>=' ) ) {
add_filter( 'wp_unique_filename', array( $this, 'filter_unique_filename' ), 10, 4 );
add_filter( 'wp_check_filetype_and_ext', array( $this, 'filter_filetype_check' ), 10, 4 );
} else {
add_filter( 'wp_handle_upload_prefilter', array( &$this, 'get_unique_filename' ), 10, 1 );
add_filter( 'wp_handle_sideload_prefilter', array( &$this, 'get_unique_filename' ), 10, 1 );
}
add_filter( 'wp_unique_filename', array( $this, 'filter_unique_filename' ), 10, 4 );
add_filter( 'wp_check_filetype_and_ext', array( $this, 'filter_filetype_check' ), 10, 4 );

add_filter( 'upload_dir', array( &$this, 'get_upload_dir' ), 10, 1 );

Expand Down Expand Up @@ -243,40 +234,6 @@ public function filter_filetype_check( $filetype_data, $file, $filename, $mimes
return $filetype_data;
}

/**
* Ensure filename uniqueness prior to WP 4.5's wp_unique_filename filter
*/
function get_unique_filename( $file ) {
$filename = strtolower( $file['name'] );
$info = pathinfo( $filename );
$ext = $info['extension'];
$name = basename( $filename, ".{$ext}" );

if( $name === ".$ext" )
$name = '';
$number = '';
if ( empty( $ext ) )
$ext = '';
else
$ext = strtolower( ".$ext" );

$filename = $this->_sanitize_filename( $filename, $ext );

$check = $this->_check_uniqueness_with_backend( $filename );

if ( 200 == $check['http_code'] ) {
$obj = json_decode( $check['content'] );
if ( isset( $obj->filename ) && basename( $obj->filename ) != basename( $post_url ) )
$file['name'] = $obj->filename;
} else if ( 406 == $check['http_code'] ) {
$file['error'] = __( 'The file type you uploaded is not supported.' );
} else {
$file['error'] = sprintf( __( 'Error getting the file name from the remote servers: Code %d' ), $check['http_code'] );
}

return $file;
}

/**
* Ensure consistent filename sanitization
*
Expand Down

0 comments on commit de78a0c

Please sign in to comment.