wp_dashboard_quota

函式
wp_dashboard_quota ( No parameters )
返回值
  • (true|void) True if not multisite, user can't upload files, or the space check option is disabled.
定義位置
相關方法
wp_dashboardwp_dashboard_emptywp_dashboard_setupwp_dashboard_secondarywp_dashboard_php_nag
引入
3.0.0
棄用
-

wp_dashboard_quota:此鉤子用於向WordPress儀表盤新增配額指示器,顯示站點媒體庫的當前使用情況和可用空間。此掛鉤可用於向配額指示器新增自定義功能或樣式。

在儀表盤上顯示檔案上傳配額。

在wp_dashboard_right_now()的{@see ‘activity_box_end’}掛鉤上執行。

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_class  = ( $percentused >= 70 ) ? ' warning' : '';
	$used        = round( $used, 2 );
	$percentused = number_format( $percentused );

	?>
	<h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3>
	<div class="mu-storage">
	<ul>
		<li class="storage-count">
			<?php
			$text = sprintf(
				/* translators: %s: Number of megabytes. */
				__( '%s MB Space Allowed' ),
				number_format_i18n( $quota )
			);
			printf(
				'<a href="%1$s">%2$s <span class="screen-reader-text">(%3$s)</span></a>',
				esc_url( admin_url( 'upload.php' ) ),
				$text,
				__( 'Manage Uploads' )
			);
			?>
		</li><li class="storage-count <?php echo $used_class; ?>">
			<?php
			$text = sprintf(
				/* translators: 1: Number of megabytes, 2: Percentage. */
				__( '%1$s MB (%2$s%%) Space Used' ),
				number_format_i18n( $used, 2 ),
				$percentused
			);
			printf(
				'<a href="%1$s" class="musublink">%2$s <span class="screen-reader-text">(%3$s)</span></a>',
				esc_url( admin_url( 'upload.php' ) ),
				$text,
				__( 'Manage Uploads' )
			);
			?>
		</li>
	</ul>
	</div>
	<?php
}

常見問題

FAQs
檢視更多 >