diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php
index d588e15..eb6dd0e 100644
|
|
|
function _wp_handle_upload( &$file, $overrides, $time, $action ) { |
| 378 | 378 | $url = $uploads['url'] . "/$filename"; |
| 379 | 379 | |
| 380 | 380 | if ( is_multisite() ) { |
| 381 | | delete_transient( 'dirsize_cache' ); |
| | 381 | clear_dirsize_cache( $new_file ); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
diff --git src/wp-includes/ms-functions.php src/wp-includes/ms-functions.php
index f41d2b6..55d3d51 100644
|
|
|
function get_most_recent_post_of_user( $user_id ) { |
| 1658 | 1658 | * @return int Size of the directory in MB. |
| 1659 | 1659 | */ |
| 1660 | 1660 | function get_dirsize( $directory ) { |
| 1661 | | $dirsize = get_transient( 'dirsize_cache' ); |
| 1662 | | if ( is_array( $dirsize ) && isset( $dirsize[ $directory ][ 'size' ] ) ) |
| 1663 | | return $dirsize[ $directory ][ 'size' ]; |
| 1664 | | |
| 1665 | | if ( ! is_array( $dirsize ) ) |
| 1666 | | $dirsize = array(); |
| 1667 | | |
| 1668 | 1661 | // Exclude individual site directories from the total when checking the main site, |
| 1669 | 1662 | // as they are subdirectories and should not be counted. |
| 1670 | 1663 | if ( is_main_site() ) { |
| 1671 | | $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory, $directory . '/sites' ); |
| | 1664 | $size = recurse_dirsize( $directory, $directory . '/sites' ); |
| 1672 | 1665 | } else { |
| 1673 | | $dirsize[ $directory ][ 'size' ] = recurse_dirsize( $directory ); |
| | 1666 | $size = recurse_dirsize( $directory ); |
| 1674 | 1667 | } |
| 1675 | 1668 | |
| 1676 | | set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); |
| 1677 | | return $dirsize[ $directory ][ 'size' ]; |
| | 1669 | return $size; |
| 1678 | 1670 | } |
| 1679 | 1671 | |
| 1680 | 1672 | /** |
| … |
… |
function get_dirsize( $directory ) { |
| 1686 | 1678 | * @since MU |
| 1687 | 1679 | * @since 4.3.0 $exclude parameter added. |
| 1688 | 1680 | * |
| 1689 | | * @param string $directory Full path of a directory. |
| 1690 | | * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. |
| | 1681 | * @param string $directory Full path of a directory. |
| | 1682 | * @param string $exclude Optional. Full path of a subdirectory to exclude from the total. |
| | 1683 | * @param array $directory_cache Optional. Array of cached directory paths. |
| 1691 | 1684 | * @return int|false Size in MB if a valid directory. False if not. |
| 1692 | 1685 | */ |
| 1693 | | function recurse_dirsize( $directory, $exclude = null ) { |
| | 1686 | function recurse_dirsize( $directory, $exclude = null, &$directory_cache = null ) { |
| 1694 | 1687 | $size = 0; |
| 1695 | 1688 | |
| 1696 | | $directory = untrailingslashit( $directory ); |
| | 1689 | $directory = untrailingslashit( $directory ); |
| | 1690 | $cache_path = normalize_dirsize_cache_path( $directory ); |
| | 1691 | $save_cache = false; |
| | 1692 | |
| | 1693 | if ( ! isset( $directory_cache ) ) { |
| | 1694 | $directory_cache = get_transient( 'dirsize_cache' ); |
| | 1695 | $save_cache = true; |
| | 1696 | } |
| | 1697 | |
| | 1698 | if ( isset( $directory_cache[ $cache_path ] ) ) { |
| | 1699 | return $directory_cache[ $cache_path ]; |
| | 1700 | } |
| 1697 | 1701 | |
| 1698 | 1702 | if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) { |
| 1699 | 1703 | return false; |
| … |
… |
function recurse_dirsize( $directory, $exclude = null ) { |
| 1706 | 1710 | if (is_file($path)) { |
| 1707 | 1711 | $size += filesize($path); |
| 1708 | 1712 | } elseif (is_dir($path)) { |
| 1709 | | $handlesize = recurse_dirsize( $path, $exclude ); |
| | 1713 | $handlesize = recurse_dirsize( $path, $exclude, $directory_cache ); |
| 1710 | 1714 | if ($handlesize > 0) |
| 1711 | 1715 | $size += $handlesize; |
| 1712 | 1716 | } |
| … |
… |
function recurse_dirsize( $directory, $exclude = null ) { |
| 1714 | 1718 | } |
| 1715 | 1719 | closedir($handle); |
| 1716 | 1720 | } |
| | 1721 | |
| | 1722 | $directory_cache[ $cache_path ] = $size; |
| | 1723 | |
| | 1724 | if ( $save_cache ) { |
| | 1725 | set_transient( 'dirsize_cache', $directory_cache ); |
| | 1726 | } |
| | 1727 | |
| 1717 | 1728 | return $size; |
| 1718 | 1729 | } |
| 1719 | 1730 | |
| 1720 | 1731 | /** |
| | 1732 | * Clear dirsize_cache |
| | 1733 | * |
| | 1734 | * Remove the current directory and all parent directories |
| | 1735 | * from the dirsize_cache transient. |
| | 1736 | * |
| | 1737 | * @param string $path Full path of a directory. |
| | 1738 | */ |
| | 1739 | function clear_dirsize_cache( $path ) { |
| | 1740 | $directory_cache = get_transient( 'dirsize_cache' ); |
| | 1741 | |
| | 1742 | if ( empty( $directory_cache ) ) { |
| | 1743 | return; |
| | 1744 | } |
| | 1745 | |
| | 1746 | $cache_path = normalize_dirsize_cache_path( $path ); |
| | 1747 | unset( $directory_cache[ $cache_path ] ); |
| | 1748 | |
| | 1749 | while ( DIRECTORY_SEPARATOR !== $cache_path && '.' !== $cache_path ) { |
| | 1750 | $cache_path = dirname( $cache_path ); |
| | 1751 | unset( $directory_cache[ $cache_path ] ); |
| | 1752 | } |
| | 1753 | |
| | 1754 | set_transient( 'dirsize_cache', $directory_cache ); |
| | 1755 | } |
| | 1756 | |
| | 1757 | /** |
| | 1758 | * Normalize dirsize cache path. |
| | 1759 | * |
| | 1760 | * Ensures array keys follow the same format. |
| | 1761 | * |
| | 1762 | * @param string $path |
| | 1763 | * @return string |
| | 1764 | */ |
| | 1765 | function normalize_dirsize_cache_path( $path ) { |
| | 1766 | $path = str_replace( ABSPATH, '', $path ); |
| | 1767 | |
| | 1768 | return untrailingslashit( $path ); |
| | 1769 | } |
| | 1770 | |
| | 1771 | /** |
| 1721 | 1772 | * Check an array of MIME types against a whitelist. |
| 1722 | 1773 | * |
| 1723 | 1774 | * WordPress ships with a set of allowed upload filetypes, |
diff --git src/wp-includes/post.php src/wp-includes/post.php
index d0bc1a3..254de80 100644
|
|
|
function wp_delete_attachment( $post_id, $force_delete = false ) { |
| 4704 | 4704 | $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); |
| 4705 | 4705 | $file = get_attached_file( $post_id ); |
| 4706 | 4706 | |
| 4707 | | if ( is_multisite() ) |
| 4708 | | delete_transient( 'dirsize_cache' ); |
| | 4707 | if ( is_multisite() ) { |
| | 4708 | clear_dirsize_cache( $file ); |
| | 4709 | } |
| 4709 | 4710 | |
| 4710 | 4711 | /** |
| 4711 | 4712 | * Fires before an attachment is deleted, at the start of wp_delete_attachment(). |