Created
May 26, 2022 00:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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