IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 928 | 928 | $url = $uploads['url'] . "/$filename"; |
| 929 | 929 | |
| 930 | 930 | if ( is_multisite() ) { |
| 931 | | delete_transient( 'dirsize_cache' ); |
| | 931 | clear_dirsize_cache( $new_file ); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | /** |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 5827 | 5827 | $file = get_attached_file( $post_id ); |
| 5828 | 5828 | |
| 5829 | 5829 | if ( is_multisite() ) { |
| 5830 | | delete_transient( 'dirsize_cache' ); |
| | 5830 | clear_dirsize_cache( $file ); |
| 5831 | 5831 | } |
| 5832 | 5832 | |
| 5833 | 5833 | /** |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
|
|
|
|
| 7500 | 7500 | * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. |
| 7501 | 7501 | */ |
| 7502 | 7502 | function get_dirsize( $directory, $max_execution_time = null ) { |
| 7503 | | $dirsize = get_transient( 'dirsize_cache' ); |
| 7504 | | |
| 7505 | | if ( is_array( $dirsize ) && isset( $dirsize[ $directory ]['size'] ) ) { |
| 7506 | | return $dirsize[ $directory ]['size']; |
| 7507 | | } |
| 7508 | | |
| 7509 | | if ( ! is_array( $dirsize ) ) { |
| 7510 | | $dirsize = array(); |
| 7511 | | } |
| 7512 | 7503 | |
| 7513 | 7504 | // Exclude individual site directories from the total when checking the main site of a network, |
| 7514 | 7505 | // as they are subdirectories and should not be counted. |
| 7515 | 7506 | if ( is_multisite() && is_main_site() ) { |
| 7516 | | $dirsize[ $directory ]['size'] = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time ); |
| | 7507 | $size = recurse_dirsize( $directory, $directory . '/sites', $max_execution_time ); |
| 7517 | 7508 | } else { |
| 7518 | | $dirsize[ $directory ]['size'] = recurse_dirsize( $directory, null, $max_execution_time ); |
| | 7509 | $size = recurse_dirsize( $directory, null, $max_execution_time ); |
| 7519 | 7510 | } |
| 7520 | 7511 | |
| 7521 | | set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS ); |
| 7522 | | return $dirsize[ $directory ]['size']; |
| | 7512 | return $size; |
| 7523 | 7513 | } |
| 7524 | 7514 | |
| 7525 | 7515 | /** |
| … |
… |
|
| 7531 | 7521 | * @since MU (3.0.0) |
| 7532 | 7522 | * @since 4.3.0 $exclude parameter added. |
| 7533 | 7523 | * @since 5.2.0 $max_execution_time parameter added. |
| | 7524 | * @since 5.6.0 $directory_cache parameter added. |
| 7534 | 7525 | * |
| 7535 | 7526 | * @param string $directory Full path of a directory. |
| 7536 | 7527 | * @param string|array $exclude Optional. Full path of a subdirectory to exclude from the total, |
| 7537 | 7528 | * or array of paths. Expected without trailing slash(es). |
| 7538 | 7529 | * @param int $max_execution_time Maximum time to run before giving up. In seconds. The timeout is global |
| 7539 | 7530 | * and is measured from the moment WordPress started to load. |
| | 7531 | * @param array $directory_cache Optional. Array of cached directory paths. |
| | 7532 | * |
| 7540 | 7533 | * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout. |
| 7541 | 7534 | */ |
| 7542 | | function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) { |
| | 7535 | function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null, &$directory_cache = null ) { |
| 7543 | 7536 | $size = 0; |
| 7544 | 7537 | |
| 7545 | 7538 | $directory = untrailingslashit( $directory ); |
| | 7539 | $cache_path = normalize_dirsize_cache_path( $directory ); |
| | 7540 | $save_cache = false; |
| | 7541 | |
| | 7542 | if ( ! isset( $directory_cache ) ) { |
| | 7543 | $directory_cache = get_transient( 'dirsize_cache' ); |
| | 7544 | $save_cache = true; |
| | 7545 | } |
| | 7546 | |
| | 7547 | if ( isset( $directory_cache[ $cache_path ] ) ) { |
| | 7548 | return $directory_cache[ $cache_path ]; |
| | 7549 | } |
| 7546 | 7550 | |
| 7547 | 7551 | if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) { |
| 7548 | 7552 | return false; |
| … |
… |
|
| 7578 | 7582 | if ( is_file( $path ) ) { |
| 7579 | 7583 | $size += filesize( $path ); |
| 7580 | 7584 | } elseif ( is_dir( $path ) ) { |
| 7581 | | $handlesize = recurse_dirsize( $path, $exclude, $max_execution_time ); |
| | 7585 | $handlesize = recurse_dirsize( $path, $exclude, $max_execution_time, $directory_cache ); |
| 7582 | 7586 | if ( $handlesize > 0 ) { |
| 7583 | 7587 | $size += $handlesize; |
| 7584 | 7588 | } |
| … |
… |
|
| 7593 | 7597 | } |
| 7594 | 7598 | closedir( $handle ); |
| 7595 | 7599 | } |
| | 7600 | |
| | 7601 | $directory_cache[ $cache_path ] = $size; |
| | 7602 | |
| | 7603 | // Only write the transient on the top level call and not on recursive calls |
| | 7604 | if ( $save_cache ) { |
| | 7605 | set_transient( 'dirsize_cache', $directory_cache ); |
| | 7606 | } |
| | 7607 | |
| 7596 | 7608 | return $size; |
| 7597 | 7609 | } |
| 7598 | 7610 | |
| | 7611 | /** |
| | 7612 | * Clear dirsize_cache |
| | 7613 | * |
| | 7614 | * Remove the current directory and all parent directories |
| | 7615 | * from the dirsize_cache transient. |
| | 7616 | * |
| | 7617 | * @since 5.6.0 |
| | 7618 | * |
| | 7619 | * @param string $path Full path of a directory. |
| | 7620 | */ |
| | 7621 | function clear_dirsize_cache( $path ) { |
| | 7622 | $directory_cache = get_transient( 'dirsize_cache' ); |
| | 7623 | |
| | 7624 | if ( empty( $directory_cache ) ) { |
| | 7625 | return; |
| | 7626 | } |
| | 7627 | |
| | 7628 | $cache_path = normalize_dirsize_cache_path( $path ); |
| | 7629 | unset( $directory_cache[ $cache_path ] ); |
| | 7630 | |
| | 7631 | while ( DIRECTORY_SEPARATOR !== $cache_path && '.' !== $cache_path ) { |
| | 7632 | $cache_path = dirname( $cache_path ); |
| | 7633 | unset( $directory_cache[ $cache_path ] ); |
| | 7634 | } |
| | 7635 | |
| | 7636 | set_transient( 'dirsize_cache', $directory_cache ); |
| | 7637 | } |
| | 7638 | |
| | 7639 | /** |
| | 7640 | * Normalize dirsize cache path. |
| | 7641 | * |
| | 7642 | * Ensures array keys follow the same format. |
| | 7643 | * |
| | 7644 | * @param string $path |
| | 7645 | * |
| | 7646 | * @since 5.6.0 |
| | 7647 | * |
| | 7648 | * @return string |
| | 7649 | */ |
| | 7650 | function normalize_dirsize_cache_path( $path ) { |
| | 7651 | $path = str_replace( ABSPATH, '', $path ); |
| | 7652 | |
| | 7653 | return untrailingslashit( $path ); |
| | 7654 | } |
| | 7655 | |
| 7599 | 7656 | /** |
| 7600 | 7657 | * Checks compatibility with the current WordPress version. |
| 7601 | 7658 | * |