Make WordPress Core

Changeset 53253


Ignore:
Timestamp:
04/25/2022 09:45:00 AM (14 months ago)
Author:
audrasjb
Message:

Themes: Ensure WP_Theme::get_files() doesn't return unexpected values.

This change filters out empty entries from WP_Theme::get_files() before returning the array of files. This avoid returning an entry with false value when the directory of the theme does not exist.

Props dd32, opurockey, Rahmohn, audrasjb.
Fixes #53599.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r53190 r53253  
    12111211        }
    12121212
    1213         return $files;
     1213        return array_filter( $files );
    12141214    }
    12151215
  • trunk/tests/phpunit/tests/theme/wpTheme.php

    r52391 r53253  
    263263
    264264    /**
     265     * Test get_files for an existing theme.
     266     *
     267     * @ticket 53599
     268     */
     269    public function test_get_files_theme() {
     270        $theme = new WP_Theme( 'theme1', $this->theme_root );
     271        $files = $theme->get_files();
     272
     273        $this->assertIsArray( $files );
     274        $this->assertCount( 3, $files );
     275        $this->assertArrayHasKey( 'functions.php', $files );
     276        $this->assertArrayHasKey( 'index.php', $files );
     277        $this->assertArrayHasKey( 'style.css', $files );
     278    }
     279
     280    /**
     281     * Test get_files for a non-existing theme.
     282     *
     283     * @ticket 53599
     284     */
     285    public function test_get_files_nonexistent_theme() {
     286        $theme = new WP_Theme( 'nonexistent', $this->theme_root );
     287        $files = $theme->get_files();
     288
     289        $this->assertIsArray( $files );
     290        $this->assertEmpty( $files );
     291    }
     292
     293    /**
    265294     * Data provider.
    266295     *
Note: See TracChangeset for help on using the changeset viewer.