Skip to content

Instantly share code, notes, and snippets.

@mauriciogofas
Created May 26, 2022 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciogofas/ee3c2ac49182a6bc49b804ecbea66504 to your computer and use it in GitHub Desktop.
Save mauriciogofas/ee3c2ac49182a6bc49b804ecbea66504 to your computer and use it in GitHub Desktop.
Disables jpg jpeg png gif image upload to Amazon S3 from WP Offload plugin on the site of the multi site network where it is activated
<?php
/*
Plugin Name: Gofas Disable WP Offload S3 on this site
Plugin URI: http://github.com/deliciousbrains/wp-amazon-s3-and-cloudfront-tweaks
Description: Disables jpg jpeg png gif image upload to Amazon S3
Author: Gofas Software
Version: 0.0.1
Author URI: https://gofas.net
Network: False
*/
class Gofas_Disables_S3_uploads {
function __construct() {
add_filter( 'gofas_pre_update_attachment_metadata', array( $this, 'pre_update_attachment_metadata' ), 10, 4 );
}
function gofas_pre_update_attachment_metadata( $abort, $data, $post_id, $old_as3cf_item ) {
$file = get_post_meta( $post_id, '_wp_attached_file', true );
$extension = is_string( $file ) ? pathinfo( $file, PATHINFO_EXTENSION ) : false;
if ( is_string( $extension ) && in_array( $extension, array('jpg','jpeg','png' ) ) ) {
$abort = true; // abort the upload
}
return $abort;
}
}
new Gofas_Disables_S3_uploads();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment