diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index 8c2f8224d8..2583f9d157 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -108,7 +108,7 @@ function wpmu_delete_blog( $blog_id, $drop = false ) { } if ( $drop ) { - $uploads = wp_upload_dir(); + $uploads = wp_get_upload_dir(); $tables = $wpdb->tables( 'blog' ); /** diff --git a/wp-includes/comment.php b/wp-includes/comment.php index e3cabe5a13..11a550b56c 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -2205,7 +2205,7 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) { return false; //Do not search for a pingback server on our own uploads - $uploads_dir = wp_upload_dir(); + $uploads_dir = wp_get_upload_dir(); if ( 0 === strpos($url, $uploads_dir['baseurl']) ) return false; diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 202ad84463..4729b062d7 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -3716,3 +3716,17 @@ function popuplinks( $text ) { $text = preg_replace('//i', "", $text); return $text; } + +/** + * Returns the base URL of the uploads directory. + * + * @since 4.4.0 + * @access private + * @deprecated 4.5.0 + * + * @return string The base URL. + */ +function _wp_upload_dir_baseurl() { + $upload_dir = wp_get_upload_dir(); + return $upload_dir['baseurl']; +} diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 17d60c4865..f46bd2c913 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1885,7 +1885,7 @@ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; } - $uploads['error'] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $error_path ); + $uploads['error'] = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), esc_html( $error_path ) ); } $tested_paths[ $path ] = $uploads['error']; diff --git a/wp-includes/media.php b/wp-includes/media.php index 4fa3cf5809..cf730815f5 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -902,27 +902,6 @@ function _wp_get_attachment_relative_path( $file ) { return $dirname; } -/** - * Caches and returns the base URL of the uploads directory. - * - * @since 4.4.0 - * @access private - * - * @return string The base URL, cached. - */ -function _wp_upload_dir_baseurl() { - static $baseurl = array(); - - $blog_id = get_current_blog_id(); - - if ( empty( $baseurl[$blog_id] ) ) { - $uploads_dir = wp_upload_dir(); - $baseurl[$blog_id] = $uploads_dir['baseurl']; - } - - return $baseurl[$blog_id]; -} - /** * Get the image size as array from its meta data. * @@ -1045,8 +1024,8 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac $dirname = trailingslashit( $dirname ); } - $image_baseurl = _wp_upload_dir_baseurl(); - $image_baseurl = trailingslashit( $image_baseurl ) . $dirname; + $upload_dir = wp_get_upload_dir(); + $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname; /* * Images that have been edited in WordPress after being uploaded will @@ -3739,7 +3718,7 @@ function wp_maybe_generate_attachment_metadata( $attachment ) { function attachment_url_to_postid( $url ) { global $wpdb; - $dir = wp_upload_dir(); + $dir = wp_get_upload_dir(); $path = $url; $site_url = parse_url( $dir['url'] ); diff --git a/wp-includes/post.php b/wp-includes/post.php index 3154fa722a..636073559f 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -186,11 +186,15 @@ function create_initial_post_types() { */ function get_attached_file( $attachment_id, $unfiltered = false ) { $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); + // If the file is relative, prepend upload dir. - if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) ) + if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) { $file = $uploads['basedir'] . "/$file"; - if ( $unfiltered ) + } + + if ( $unfiltered ) { return $file; + } /** * Filter the attached file based on the given ID. @@ -248,7 +252,7 @@ function update_attached_file( $attachment_id, $file ) { function _wp_relative_upload_path( $path ) { $new_path = $path; - $uploads = wp_upload_dir(); + $uploads = wp_get_upload_dir(); if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) { $new_path = str_replace( $uploads['basedir'], '', $new_path ); $new_path = ltrim( $new_path, '/' ); @@ -4847,7 +4851,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { /** This action is documented in wp-includes/post.php */ do_action( 'deleted_post', $post_id ); - $uploadpath = wp_upload_dir(); + $uploadpath = wp_get_upload_dir(); if ( ! empty($meta['thumb']) ) { // Don't delete the thumb if another attachment uses it. @@ -4964,9 +4968,9 @@ function wp_get_attachment_url( $post_id = 0 ) { $url = ''; // Get attached file. - if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { + if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true ) ) { // Get upload directory. - if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { + if ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) { // Check that the upload base exists in the file location. if ( 0 === strpos( $file, $uploads['basedir'] ) ) { // Replace file location with url location. diff --git a/wp-includes/version.php b/wp-includes/version.php index fc6a118e31..32994e6b60 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36568'; +$wp_version = '4.5-alpha-36569'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.