wp_dashboard_quota

Display file upload quota on dashboard.

Description

(bool|null) wp_dashboard_quota(); 

Runs on the hook in wp_dashboard_right_now().

Returns (bool|null)

True if not multisite, user can't upload files, or the space check option is disabled.


Usage

  1. if ( !function_exists( 'wp_dashboard_quota' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/dashboard.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_dashboard_quota(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/dashboard.php  
  1. function wp_dashboard_quota() { 
  2. if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) 
  3. return true; 
  4.  
  5. $quota = get_space_allowed(); 
  6. $used = get_space_used(); 
  7.  
  8. if ( $used > $quota ) 
  9. $percentused = '100'; 
  10. else 
  11. $percentused = ( $used / $quota ) * 100; 
  12. $used_class = ( $percentused >= 70 ) ? ' warning' : ''; 
  13. $used = round( $used, 2 ); 
  14. $percentused = number_format( $percentused ); 
  15.  
  16. ?> 
  17. <h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3> 
  18. <div class="mu-storage"> 
  19. <ul> 
  20. <li class="storage-count"> 
  21. <?php $text = sprintf( 
  22. /** translators: number of megabytes */ 
  23. __( '%s MB Space Allowed' ),  
  24. number_format_i18n( $quota ) 
  25. ); 
  26. printf( 
  27. '<a href="%1$s">%2$s <span class="screen-reader-text">(%3$s)</span></a>',  
  28. esc_url( admin_url( 'upload.php' ) ),  
  29. $text,  
  30. __( 'Manage Uploads' ) 
  31. ); ?> 
  32. </li><li class="storage-count <?php echo $used_class; ?>"> 
  33. <?php $text = sprintf( 
  34. /** translators: 1: number of megabytes, 2: percentage */ 
  35. __( '%1$s MB (%2$s%%) Space Used' ),  
  36. number_format_i18n( $used, 2 ),  
  37. $percentused 
  38. ); 
  39. printf( 
  40. '<a href="%1$s" class="musublink">%2$s <span class="screen-reader-text">(%3$s)</span></a>',  
  41. esc_url( admin_url( 'upload.php' ) ),  
  42. $text,  
  43. __( 'Manage Uploads' ) 
  44. ); ?> 
  45. </li> 
  46. </ul> 
  47. </div> 
  48. <?php