/** * Output our custom quota column content. * * @param string $column_name The registered column name that the list table is currently on. * @param int $user_id The blog ID associated with the current blog row. */ public function setup_column($column_name, $blog_id) { if ($this->column_name !== $column_name) { return; } switch_to_blog($blog_id); // You might recognize this from wp_dashboard_quota(). $quota = get_space_allowed(); $used = get_space_used(); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $text = sprintf(__('%1$s MB / %2$s MB (%3$s%%)'), number_format_i18n(round($used, 2), 2), number_format_i18n($quota, 2), number_format($percentused)); printf('<a href="%1$s" title="%2$s" class="musublink">%3$s</a>', esc_url(admin_url('upload.php')), __('Manage Uploads'), $text); restore_current_blog(); }
/** * Display file upload quota on dashboard. * * Runs on the activity_box_end hook in wp_dashboard_right_now(). * * @since 3.0.0 * * @return bool|null True if not multisite, user can't upload files, or the space check option is disabled. */ function wp_dashboard_quota() { if (!is_multisite() || !current_user_can('upload_files') || get_network_option('upload_space_check_disabled')) { return true; } $quota = get_space_allowed(); $used = get_space_used(); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_class = $percentused >= 70 ? ' warning' : ''; $used = round($used, 2); $percentused = number_format($percentused); ?> <h4 class="mu-storage"><?php _e('Storage Space'); ?> </h4> <div class="mu-storage"> <ul> <li class="storage-count"> <?php $text = sprintf(__('%s MB Space Allowed'), number_format_i18n($quota)); printf('<a href="%1$s" title="%2$s">%3$s</a>', esc_url(admin_url('upload.php')), __('Manage Uploads'), $text); ?> </li><li class="storage-count <?php echo $used_class; ?> "> <?php $text = sprintf(__('%1$s MB (%2$s%%) Space Used'), number_format_i18n($used, 2), $percentused); printf('<a href="%1$s" title="%2$s" class="musublink">%3$s</a>', esc_url(admin_url('upload.php')), __('Manage Uploads'), $text); ?> </li> </ul> </div> <?php }
/** * Determines if there is any upload space left in the current blog's quota. * * @since 3.0.0 * * @return int of upload space available in bytes */ function get_upload_space_available() { $allowed = get_space_allowed(); if ($allowed < 0) { $allowed = 0; } $space_allowed = $allowed * 1024 * 1024; if (get_site_option('upload_space_check_disabled')) { return $space_allowed; } $space_used = get_space_used() * 1024 * 1024; if ($space_allowed - $space_used <= 0) { return 0; } return $space_allowed - $space_used; }
function test_get_space_used_pre_get_spaced_used_filter() { add_filter('pre_get_space_used', array($this, '_filter_space_used')); $this->assertEquals(300, get_space_used()); remove_filter('pre_get_space_used', array($this, '_filter_space_used')); }
/** * Display file upload quota on dashboard. * * Runs on the activity_box_end hook in wp_dashboard_right_now(). * * @since 3.0.0 * * @return bool True if not multisite, user can't upload files, or the space check option is disabled. */ function wp_dashboard_quota() { if (!is_multisite() || !current_user_can('upload_files') || get_site_option('upload_space_check_disabled')) { return true; } $quota = get_space_allowed(); $used = get_space_used(); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_color = $percentused >= 70 ? ' spam' : ''; $used = round($used, 2); $percentused = number_format($percentused); ?> <p class="sub musub"><?php _e('Storage Space'); ?> </p> <div class="table table_content musubtable"> <table> <tr class="first"> <td class="first b b-posts"><?php printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>'), esc_url(admin_url('upload.php')), number_format_i18n($quota)); ?> </td> <td class="t posts"><?php _e('Space Allowed'); ?> </td> </tr> </table> </div> <div class="table table_discussion musubtable"> <table> <tr class="first"> <td class="b b-comments"><?php printf(__('<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>'), esc_url(admin_url('upload.php')), number_format_i18n($used, 2), $percentused); ?> </td> <td class="last t comments<?php echo $used_color; ?> "><?php _e('Space Used'); ?> </td> </tr> </table> </div> <br class="clear" /> <?php }
/** * Displays the amount of disk space used by the current site. Not used in core. * * @since MU */ function display_space_usage() { $space_allowed = get_space_allowed(); $space_used = get_space_used(); $percent_used = $space_used / $space_allowed * 100; if ($space_allowed > 1000) { $space = number_format($space_allowed / KB_IN_BYTES); /* translators: Gigabytes */ $space .= __('GB'); } else { $space = number_format($space_allowed); /* translators: Megabytes */ $space .= __('MB'); } ?> <strong><?php printf(__('Used: %1$s%% of %2$s'), number_format($percent_used), $space); ?> </strong> <?php }
/** * Determines if there is any upload space left in the current blog's quota. * * @since 3.0.0 * * @return int of upload space available in bytes */ function get_upload_space_available() { $space_allowed = get_space_allowed() * 1024 * 1024; if ( get_site_option( 'upload_space_check_disabled' ) ) return $space_allowed; $space_used = get_space_used() * 1024 * 1024; if ( ( $space_allowed - $space_used ) <= 0 ) return 0; return $space_allowed - $space_used; }
public function add_quota_to_library() { global $psts; $quota = get_space_allowed(); $used = get_space_used(); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used_class = $percentused >= 70 ? 'class="warning"' : ''; $used = round($used, 2); $percentused = number_format($percentused); $text = sprintf(__('%1$s MB (%2$s%%) of %3$s MB used.', 'psts'), number_format_i18n($used, 2), $percentused, number_format_i18n($quota, 2)); ?> <div id="prosites-media-quota-display" style="display:none;" <?php echo $used_class; ?> ><div class="size-text"><?php echo $text; ?> </div><?php echo $this->message(false, 'media-upload'); ?> </div><?php global $psts; wp_enqueue_style('psts-quota-style', $psts->plugin_url . 'css/quota.css', $psts->version); wp_enqueue_script('psts-quota', $psts->plugin_url . 'js/quota.js', array('jquery'), $psts->version); }
/** * "This blog" widget callback */ public function blog_info_widget_cb() { $comments_count = wp_count_comments(); ?> <table cellpadding="5" cellspacing="0" width="100%" class="siw_tbl"> <tr> <th><?php _e('Title', 'siw'); ?> </th> <td><?php bloginfo('name'); ?> </td> </tr> <tr> <th><?php _e('Tagline', 'siw'); ?> </th> <td><?php bloginfo('description'); ?> </td> </tr> <tr> <th><?php _e('Theme', 'siw'); ?> </th> <td><?php echo get_current_theme(); ?> </td> </tr> <tr> <th><?php _e('Privacy', 'siw'); ?> </th> <td><?php echo get_option('blog_public') == 1 ? __('Blog is visible to everyone, including search engines (like Google, Sphere, Technorati) and archivers.', 'siw') : __('Blog is invisible to search engines, but allow normal visitors.', 'siw'); ?> </td> </tr> <tr> <th><?php _e('Comments', 'siw'); ?> </th> <td><?php printf(__('%s Pending | %s Spam', 'siw'), $comments_count->moderated, $comments_count->spam); ?> </td> </tr> </table> <?php // Check if WPMU pro sites plugin activated if (class_exists('ProSites')) { global $psts; $blog_id = get_current_blog_id(); $levels = (array) get_site_option('psts_levels'); $current_level = $psts->get_level($blog_id); $expire = $psts->get_expire($blog_id); $trialing = ProSites_Helper_Registration::is_trial($blog_id); $active_trial = $trialing ? __('(Active trial)', 'siw') : ''; $quota = get_space_allowed(); $used = get_space_used(); if ($used > $quota) { $percentused = '100'; } else { $percentused = $used / $quota * 100; } $used = round($used, 2); $percentused = number_format($percentused); ?> <table cellpadding="5" cellspacing="0" width="100%" class="siw_tbl"> <tr> <th><?php _e('Level', 'siw'); ?> </th> <td> <?php echo $current_level . ' - ' . @$levels[$current_level]['name']; ?> <a class="manage_pro" href="<?php echo $psts->checkout_url($blog_id); ?> "><?php _e('Manage Pro Account', 'siw'); ?> </a> </td> </tr> <tr> <th><?php _e('Renewal Date', 'siw'); ?> </th> <td><?php echo date_i18n(get_option('date_format'), $expire) . ' ' . $active_trial; ?> </td> </tr> <tr> <th><?php _e('Storage', 'siw'); ?> </th> <td> <?php echo $percentused; _e('% used of ', 'siw'); echo number_format_i18n($quota); _e('M total', 'siw'); ?> </td> </tr> </table> <?php } }
/** * Displays the amount of disk space used by the current site. Not used in core. * * @since MU */ function display_space_usage() { $space_allowed = get_space_allowed(); $space_used = get_space_used(); $percent_used = $space_used / $space_allowed * 100; if ($space_allowed > 1000) { $space = number_format($space_allowed / KB_IN_BYTES); /* translators: Gigabytes */ $space .= __('GB'); } else { $space = number_format($space_allowed); /* translators: Megabytes */ $space .= __('MB'); } ?> <strong><?php /* translators: Storage space that's been used. 1: Percentage of used space, 2: Total space allowed in megabytes or gigabytes */ printf(__('Used: %1$s%% of %2$s'), number_format($percent_used), $space); ?> </strong> <?php }