Make WordPress Core

Ticket #19879: 19879_WordPress_56.patch

File 19879_WordPress_56.patch, 5.6 KB (added by janthiel, 5 years ago)

Updated patch against WordPress 5.5 master

  • wp-admin/includes/file.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    928928        $url = $uploads['url'] . "/$filename";
    929929
    930930        if ( is_multisite() ) {
    931                 delete_transient( 'dirsize_cache' );
     931                clear_dirsize_cache( $new_file );
    932932        }
    933933
    934934        /**
  • wp-includes/post.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    58275827        $file         = get_attached_file( $post_id );
    58285828
    58295829        if ( is_multisite() ) {
    5830                 delete_transient( 'dirsize_cache' );
     5830                clear_dirsize_cache( $file );
    58315831        }
    58325832
    58335833        /**
  • wp-includes/functions.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    75007500 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
    75017501 */
    75027502function 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         }
    75127503
    75137504        // Exclude individual site directories from the total when checking the main site of a network,
    75147505        // as they are subdirectories and should not be counted.
    75157506        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 );
    75177508        } else {
    7518                 $dirsize[ $directory ]['size'] = recurse_dirsize( $directory, null, $max_execution_time );
     7509                $size = recurse_dirsize( $directory, null, $max_execution_time );
    75197510        }
    75207511
    7521         set_transient( 'dirsize_cache', $dirsize, HOUR_IN_SECONDS );
    7522         return $dirsize[ $directory ]['size'];
     7512        return $size;
    75237513}
    75247514
    75257515/**
     
    75317521 * @since MU (3.0.0)
    75327522 * @since 4.3.0 $exclude parameter added.
    75337523 * @since 5.2.0 $max_execution_time parameter added.
     7524 * @since 5.6.0 $directory_cache parameter added.
    75347525 *
    75357526 * @param string       $directory          Full path of a directory.
    75367527 * @param string|array $exclude            Optional. Full path of a subdirectory to exclude from the total,
    75377528 *                                         or array of paths. Expected without trailing slash(es).
    75387529 * @param int          $max_execution_time Maximum time to run before giving up. In seconds. The timeout is global
    75397530 *                                         and is measured from the moment WordPress started to load.
     7531 * @param array        $directory_cache    Optional. Array of cached directory paths.
     7532 *
    75407533 * @return int|false|null Size in bytes if a valid directory. False if not. Null if timeout.
    75417534 */
    7542 function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null ) {
     7535function recurse_dirsize( $directory, $exclude = null, $max_execution_time = null, &$directory_cache = null ) {
    75437536        $size = 0;
    75447537
    75457538        $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        }
    75467550
    75477551        if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) ) {
    75487552                return false;
     
    75787582                                if ( is_file( $path ) ) {
    75797583                                        $size += filesize( $path );
    75807584                                } elseif ( is_dir( $path ) ) {
    7581                                         $handlesize = recurse_dirsize( $path, $exclude, $max_execution_time );
     7585                                        $handlesize = recurse_dirsize( $path, $exclude, $max_execution_time, $directory_cache );
    75827586                                        if ( $handlesize > 0 ) {
    75837587                                                $size += $handlesize;
    75847588                                        }
     
    75937597                }
    75947598                closedir( $handle );
    75957599        }
     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
    75967608        return $size;
    75977609}
    75987610
     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 */
     7621function 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 */
     7650function normalize_dirsize_cache_path( $path ) {
     7651        $path = str_replace( ABSPATH, '', $path );
     7652
     7653        return untrailingslashit( $path );
     7654}
     7655
    75997656/**
    76007657 * Checks compatibility with the current WordPress version.
    76017658 *