WordPress.org

Make WordPress Core

Changeset 29249


Ignore:
Timestamp:
07/19/2014 11:06:54 PM (6 years ago)
Author:
wonderboymusic
Message:

Call untrailingslashit() when adding a theme directory in register_theme_directory(). This prevents double-slashing in generated URLs. Don't add a directory if it is already present.

Adds unit tests.
Props obenland, wonderboymusic.
Fixes #28662.

Location:
trunk
Files:
2 edited

Legend:

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

    r29176 r29249  
    371371        $directory = WP_CONTENT_DIR . '/' . $directory;
    372372        // If this directory does not exist, return and do not register
    373         if ( ! file_exists( $directory ) )
     373        if ( ! file_exists( $directory ) ) {
    374374            return false;
    375     }
    376 
    377     $wp_theme_directories[] = $directory;
     375        }
     376    }
     377
     378    if ( ! is_array( $wp_theme_directories ) ) {
     379        $wp_theme_directories = array();
     380    }
     381
     382    $untrailed = untrailingslashit( $directory );
     383    if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) {
     384        $wp_theme_directories[] = $untrailed;
     385    }
    378386
    379387    return true;
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r28706 r29249  
    235235    }
    236236
     237    /**
     238     * @ticket 28662
     239     */
     240    function test_theme_dir_slashes() {
     241        $size = count( $GLOBALS['wp_theme_directories'] );
     242
     243        @mkdir( WP_CONTENT_DIR . '/themes/foo' );
     244        @mkdir( WP_CONTENT_DIR . '/themes/foo-themes' );
     245
     246        $this->assertTrue( file_exists( WP_CONTENT_DIR . '/themes/foo' ) );
     247        $this->assertTrue( file_exists( WP_CONTENT_DIR . '/themes/foo-themes') );
     248
     249        register_theme_directory( '/' );
     250
     251        $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     252
     253        register_theme_directory( 'themes/' );
     254
     255        $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     256
     257        register_theme_directory( '/foo/' );
     258
     259        $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     260
     261        register_theme_directory( 'foo/' );
     262
     263        $this->assertCount( $size, $GLOBALS['wp_theme_directories'] );
     264
     265        register_theme_directory( 'themes/foo/' );
     266
     267        $this->assertCount( $size + 1, $GLOBALS['wp_theme_directories'] );
     268
     269        register_theme_directory( WP_CONTENT_DIR . '/foo-themes/' );
     270
     271        $this->assertCount( $size + 1, $GLOBALS['wp_theme_directories'] );
     272
     273        foreach ( $GLOBALS['wp_theme_directories'] as $dir ) {
     274            $this->assertNotEquals( '/', substr( $dir, -1 ) );
     275        }
     276
     277        rmdir( WP_CONTENT_DIR . '/themes/foo' );
     278        rmdir( WP_CONTENT_DIR . '/themes/foo-themes' );
     279    }
    237280}
Note: See TracChangeset for help on using the changeset viewer.