Make WordPress Core

Ticket #24068: link-template.php.diff

File link-template.php.diff, 1.3 KB (added by westonruter, 11 years ago)

Patch to content_url() to allow absolute paths to be passed in

  • wp-includes/link-template.php

     
    20362036 * @package WordPress
    20372037 * @since 2.6.0
    20382038 *
    2039  * @param string $path Optional. Path relative to the content url.
     2039 * @param string $path Optional. Path relative to the content url, or an absolute real path pointing inside WP_CONTENT_DIR
    20402040 * @return string Content url link with optional path appended.
    20412041*/
    20422042function content_url($path = '') {
    20432043        $url = set_url_scheme( WP_CONTENT_URL );
     2044        $original_path = $path;
    20442045
    2045         if ( $path && is_string( $path ) )
     2046        if ( $path && is_string( $path ) ) {
     2047                // Handle absolute path pointing inside WP_CONTENT_DIR
     2048                if ( strpos( $path, WP_CONTENT_DIR ) === 0 ) {
     2049                        $path = realpath($path);
     2050                        $content_dir_segment = DIRECTORY_SEPARATOR . basename( WP_CONTENT_DIR ) . DIRECTORY_SEPARATOR;
     2051                        $until_content_dir_pattern = sprintf( '#^.+%s#', preg_quote( $content_dir_segment, '#' ) );
     2052                        $path = preg_replace( $until_content_dir_pattern, '', $path );
     2053                        $path = str_replace('\\', '/', $path); // sanitize for Win32 installs
     2054                }
    20462055                $url .= '/' . ltrim($path, '/');
     2056        }
    20472057
    2048         return apply_filters('content_url', $url, $path);
     2058        return apply_filters('content_url', $url, $original_path);
    20492059}
    20502060
    20512061/**