Add Upload Limit Notice for Single Site

Advertisement

Show individual site upload limit notice on media page WordPress (Only for Multisite)

Eg.

Add Upload Limit Notice for Single Site 1

Snippet


<?php
/**
* [ONLY FOR MULTISITE]
*
* Show individual site upload limit notice.
*
* E.g.
*
* 1. Max upload limit 1024 MB and available limit 258 MB.
* 2. Max upload limit 1024 MB and available limit 15 MB.
* 3. Max upload limit 1024 MB and available limit 814 KB.
* 4. Max upload limit 1024 MB and available limit 29 KB.
*
* @since 1.0.0
*
* @todo Change `prefix_` with your own unique prefix.
*
* @return void
*/
if( ! function_exists( 'prefix_available_upload_space' ) ) :
function prefix_available_upload_space()
{
// Not a Multisite? return;
if( ! is_multisite() ) {
return;
}
// Show notice only on 'Media' page.
if ( 'upload' !== get_current_screen()->id ) {
return;
}
$remaining_space = get_upload_space_available();
// Show remaining space is MB.
if ( 1000000 < $remaining_space ) {
/* translators: %s: Upload limit. */
$remaining_space = sprintf( __( '%1$s MB', 'text-domain' ), absint( ( get_upload_space_available() / MB_IN_BYTES ) ) );
// Show remaining space is KB.
} else {
/* translators: %s: Upload limit. */
$remaining_space = sprintf( __( '%1$s KB', 'text-domain' ), absint( ( get_upload_space_available() / KB_IN_BYTES ) ) );
}
/* translators: %1$s max limit %2$s available limit. */
$message = sprintf( esc_html__( 'Max upload limit %1$s MB and available limit %2$s.', 'text-domain' ), get_space_allowed(), $remaining_space );
$html_message = sprintf( '<div class="notice notice-warning">%s</div>', wpautop( $message ) );
echo wp_kses_post( $html_message );
}
add_action( 'admin_notices', 'prefix_available_upload_space' );
endif;

Leave a Reply