Skip to:
Content

BuddyPress.org

Changeset 14157


Ignore:
Timestamp:
12/18/2025 10:54:12 PM (10 months ago)
Author:
espellcaste
Message:

Core: improve PHP8 compatibility by only calling closedir() on proper opendir() resources.

The intent of this change is to avoid closedir() producing warnings & errors when opendir() had previously returned false.

It also adds a missing closedir() call to the bp_attachments_cover_image_generate_file() function.

Props GaryJ.

Fixes #9307 (14.0)

Location:
branches/14.0/src/bp-core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/14.0/src/bp-core/bp-core-attachments.php

    r14151 r14157  
    531531                $file = false;
    532532
    533                 // Open the directory and get the first file.
     533                // Open the directory.
    534534                $att_dir = opendir( $type_dir );
    535535                if ( $att_dir ) {
    … …  
    542542                                }
    543543                        }
     544
     545                        // Close the directory.
     546                        closedir( $att_dir );
    544547                }
    545548
    … …  
    13461349        $cover_basename = wp_basename( $cover_file );
    13471350
    1348         if ( $att_dir = opendir( $args['cover_image_dir'] ) ) {
     1351        // Open the directory.
     1352        $att_dir = opendir( $args['cover_image_dir'] );
     1353        if ( $att_dir ) {
    13491354                while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) {
    13501355                        // Skip directories and the new cover image.
    … …  
    13531358                        }
    13541359                }
     1360
     1361                // Close the directory.
     1362                closedir( $att_dir );
    13551363        }
    13561364
  • branches/14.0/src/bp-core/bp-core-avatars.php

    r14155 r14157  
    526526        if ( ! $params['force_default'] && file_exists( $avatar_folder_dir ) ) {
    527527
    528                 // Open directory.
    529                 if ( $av_dir = opendir( $avatar_folder_dir ) ) {
     528                // Open the directory.
     529                $av_dir = opendir( $avatar_folder_dir );
     530                if ( $av_dir ) {
    530531
    531532                        // Stash files in an array once to check for one that matches.
    … …  
    566567                                }
    567568                        }
    568                 }
    569 
    570                 // Close the avatar directory.
    571                 closedir( $av_dir );
     569
     570                        // Close the directory.
     571                        closedir( $av_dir );
     572                }
    572573
    573574                // If we found a locally uploaded avatar.
    … …  
    856857        }
    857858
    858         if ( $av_dir = opendir( $avatar_folder_dir ) ) {
     859        $av_dir = opendir( $avatar_folder_dir );
     860        if ( $av_dir ) {
    859861                while ( false !== ( $avatar_file = readdir( $av_dir ) ) ) {
    860862                        if ( ( preg_match( '/-bpfull/', $avatar_file ) || preg_match( '/-bpthumb/', $avatar_file ) ) && '.' !== $avatar_file && '..' !== $avatar_file ) {
    … …  
    862864                        }
    863865                }
    864         }
    865         closedir( $av_dir );
     866
     867                // Close the directory.
     868                closedir( $av_dir );
     869        }
    866870
    867871        @rmdir( $avatar_folder_dir );
Note: See TracChangeset for help on using the changeset viewer.