Skip to:
Content

BuddyPress.org

Changeset 14140


Ignore:
Timestamp:
10/13/2025 08:00:53 PM (9 months ago)
Author:
johnjamesjacoby
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.

Location:
trunk/src/bp-core
Files:
2 edited

Legend:

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

    r14077 r14140  
    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 ) {
     1354
    13491355                while ( false !== ( $attachment_file = readdir( $att_dir ) ) ) {
    13501356                        // Skip directories and the new cover image.
     
    13531359                        }
    13541360                }
     1361
     1362                // Close the directory.
     1363                closedir( $att_dir );
    13551364        }
    13561365
  • trunk/src/bp-core/bp-core-avatars.php

    r14057 r14140  
    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        // Open the directory.
     860        $av_dir = opendir( $avatar_folder_dir );
     861        if ( $av_dir ) {
     862
    859863                while ( false !== ( $avatar_file = readdir( $av_dir ) ) ) {
    860864                        if ( ( preg_match( '/-bpfull/', $avatar_file ) || preg_match( '/-bpthumb/', $avatar_file ) ) && '.' !== $avatar_file && '..' !== $avatar_file ) {
     
    862866                        }
    863867                }
    864         }
    865         closedir( $av_dir );
     868
     869                // Close the directory.
     870                closedir( $av_dir );
     871        }
    866872
    867873        @rmdir( $avatar_folder_dir );
Note: See TracChangeset for help on using the changeset viewer.