<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[35325] trunk/src: Filesystem: Following the introduction of the `KB|MB|GB|TB_IN_BYTES` constants in [35286], use them in various places in core.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/35325">35325</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/35325","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>DrewAPicture</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-21 14:02:59 +0000 (Wed, 21 Oct 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Filesystem: Following the introduction of the `KB|MB|GB|TB_IN_BYTES` constants in <a href="https://core.trac.wordpress.org/changeset/35286">[35286]</a>, use them in various places in core.
Props sudar.
Fixes <a href="https://core.trac.wordpress.org/ticket/22405">#22405</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesmsphp">trunk/src/wp-admin/includes/ms.php</a></li>
<li><a href="#trunksrcwpincludescachephp">trunk/src/wp-includes/cache.php</a></li>
<li><a href="#trunksrcwpincludesdeprecatedphp">trunk/src/wp-includes/deprecated.php</a></li>
<li><a href="#trunksrcwpincludesfunctionsphp">trunk/src/wp-includes/functions.php</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunksrcwpincludesmsfunctionsphp">trunk/src/wp-includes/ms-functions.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesmsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/ms.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/ms.php 2015-10-21 13:47:12 UTC (rev 35324)
+++ trunk/src/wp-admin/includes/ms.php 2015-10-21 14:02:59 UTC (rev 35325)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -28,13 +28,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $space_left = get_upload_space_available();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $file_size = filesize( $file['tmp_name'] );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $space_left < $file_size )
- $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
- if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
- $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $space_left < $file_size ) {
+ $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
+ }
+
+ if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
+ $file['error'] = sprintf( __( 'This file is too big. Files must be less than %1$s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( upload_is_user_over_quota( false ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -443,7 +448,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $percent_used = ( $space_used / $space_allowed ) * 100;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $space_allowed > 1000 ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $space = number_format( $space_allowed / 1024 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $space = number_format( $space_allowed / KB_IN_BYTES );
</ins><span class="cx" style="display: block; padding: 0 10px"> /* translators: Gigabytes */
</span><span class="cx" style="display: block; padding: 0 10px"> $space .= __( 'GB' );
</span><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1104,4 +1109,4 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px"> </script>
</span><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-}
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+}
</ins></span></pre></div>
<a id="trunksrcwpincludescachephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/cache.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/cache.php 2015-10-21 13:47:12 UTC (rev 35324)
+++ trunk/src/wp-includes/cache.php 2015-10-21 14:02:59 UTC (rev 35325)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -691,7 +691,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> echo "</p>";
</span><span class="cx" style="display: block; padding: 0 10px"> echo '<ul>';
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ($this->cache as $group => $cache) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / 1024, 2 ) . 'k )</li>';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ echo "<li><strong>Group:</strong> $group - ( " . number_format( strlen( serialize( $cache ) ) / KB_IN_BYTES, 2 ) . 'k )</li>';
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> echo '</ul>';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesdeprecatedphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/deprecated.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/deprecated.php 2015-10-21 13:47:12 UTC (rev 35324)
+++ trunk/src/wp-includes/deprecated.php 2015-10-21 14:02:59 UTC (rev 35325)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3284,9 +3284,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> _deprecated_function( __FUNCTION__, '3.6', 'size_format()' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $log = log( $bytes, 1024 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $log = log( $bytes, KB_IN_BYTES );
</ins><span class="cx" style="display: block; padding: 0 10px"> $power = (int) $log;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $size = pow( 1024, $log - $power );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $size = pow( KB_IN_BYTES, $log - $power );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $unit = $units[ $power ];
</span></span></pre></div>
<a id="trunksrcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/functions.php 2015-10-21 13:47:12 UTC (rev 35324)
+++ trunk/src/wp-includes/functions.php 2015-10-21 14:02:59 UTC (rev 35325)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,12 +210,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function size_format( $bytes, $decimals = 0 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $quant = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // ========================= Origin ====
- 'TB' => 1099511627776, // pow( 1024, 4)
- 'GB' => 1073741824, // pow( 1024, 3)
- 'MB' => 1048576, // pow( 1024, 2)
- 'kB' => 1024, // pow( 1024, 1)
- 'B' => 1, // pow( 1024, 0)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'TB' => TB_IN_BYTES,
+ 'GB' => GB_IN_BYTES,
+ 'MB' => MB_IN_BYTES,
+ 'kB' => KB_IN_BYTES,
+ 'B' => 1,
</ins><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( $quant as $unit => $mag ) {
</span></span></pre></div>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media.php 2015-10-21 13:47:12 UTC (rev 35324)
+++ trunk/src/wp-includes/media.php 2015-10-21 14:02:59 UTC (rev 35325)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2638,11 +2638,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $size = strtolower( $size );
</span><span class="cx" style="display: block; padding: 0 10px"> $bytes = (int) $size;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( strpos( $size, 'k' ) !== false )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $bytes = intval( $size ) * 1024;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bytes = intval( $size ) * KB_IN_BYTES;
</ins><span class="cx" style="display: block; padding: 0 10px"> elseif ( strpos( $size, 'm' ) !== false )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $bytes = intval($size) * 1024 * 1024;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bytes = intval($size) * MB_IN_BYTES;
</ins><span class="cx" style="display: block; padding: 0 10px"> elseif ( strpos( $size, 'g' ) !== false )
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $bytes = intval( $size ) * 1024 * 1024 * 1024;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $bytes = intval( $size ) * GB_IN_BYTES;
</ins><span class="cx" style="display: block; padding: 0 10px"> return $bytes;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunksrcwpincludesmsfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/ms-functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/ms-functions.php 2015-10-21 13:47:12 UTC (rev 35324)
+++ trunk/src/wp-includes/ms-functions.php 2015-10-21 14:02:59 UTC (rev 35325)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1874,8 +1874,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_array( $upload ) || defined( 'WP_IMPORTING' ) || get_site_option( 'upload_space_check_disabled' ) )
</span><span class="cx" style="display: block; padding: 0 10px"> return $upload;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( strlen( $upload['bits'] ) > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
- return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( strlen( $upload['bits'] ) > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
+ return sprintf( __( 'This file is too big. Files must be less than %d KB in size.' ) . '<br />', get_site_option( 'fileupload_maxk', 1500 ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $upload;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2278,7 +2279,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $space_used = apply_filters( 'pre_get_space_used', false );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false === $space_used ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $upload_dir = wp_upload_dir();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $space_used = get_dirsize( $upload_dir['basedir'] ) / MB_IN_BYTES;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $space_used;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2322,11 +2323,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $allowed < 0 ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $allowed = 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $space_allowed = $allowed * 1024 * 1024;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $space_allowed = $allowed * MB_IN_BYTES;
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_site_option( 'upload_space_check_disabled' ) )
</span><span class="cx" style="display: block; padding: 0 10px"> return $space_allowed;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $space_used = get_space_used() * 1024 * 1024;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $space_used = get_space_used() * MB_IN_BYTES;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ( $space_allowed - $space_used ) <= 0 )
</span><span class="cx" style="display: block; padding: 0 10px"> return 0;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2353,7 +2354,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return int of upload size limit in bytes
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function upload_size_limit_filter( $size ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( get_site_option( 'upload_space_check_disabled' ) )
</span><span class="cx" style="display: block; padding: 0 10px"> return min( $size, $fileupload_maxk );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>