Skip to content

Instantly share code, notes, and snippets.

@landbryo
Created April 28, 2021 20:39
Show Gist options
  • Save landbryo/9efd7bc0939deb1e8abc37e669f001da to your computer and use it in GitHub Desktop.
Save landbryo/9efd7bc0939deb1e8abc37e669f001da to your computer and use it in GitHub Desktop.
add_filter( 'as3cf_pre_upload_attachment', [ $this, 'pre_upload_attachment' ], 99, 3 );
/**
* Abort uploading media to S3 if attachment isn't old enough
*
* @param $abort
* @param $post_id
* @param $meta
*
* @return bool
* @author Landon Otis
*/
public function pre_upload_attachment( $abort, $post_id, $meta ) {
$age = apply_filters( 'sunday_abort_attachment_age', '2 months ago' );
$age = strtotime( $age );
$time_ago = gmdate( 'Y-m-d h:i:s', $age );
$attachment = get_post( $post_id );
// If 2 month ago is less than post_date then abort upload
if ( $time_ago < $attachment->post_date_gmt ) {
$abort = true;
}
return $abort;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment