Limit Photo Uploads to Listing Owner

To restrict photo uploads to only the current listing owner add the following code to your child theme’s functions.php file.

If you have existing code in your functions.php be sure to omit the first line (<?php) when adding the code to your file.

<?php

function limit_upload_size_limit_for_non_admin( $limit ) {
if ( ! current_user_can( 'manage_options' ) ) {
$limit = 1000000; // 1mb in bytes
}
return $limit;
}

add_filter( 'upload_size_limit', 'limit_upload_size_limit_for_non_admin' );


function apply_wp_handle_upload_prefilter( $file ) {
if ( ! current_user_can( 'manage_options' ) ) {
$limit = 1000000; // 1mb in bytes
if ( $file['size'] > $limit ) {
$file['error'] = __( 'Maximum filesize is 1mb', 'wp-job-manager' );
}
}
return $file;
}

add_filter( 'wp_handle_upload_prefilter', 'apply_wp_handle_upload_prefilter' );

?>

Was this article helpful?

Related Articles