Replace wp_upload_dir() with the new wp_get_upload_dir() in all cases where a file is not being uploaded. Deprecate _wp_upload_dir_baseurl(), and replace it with wp_get_upload_dir().

See #34359.
Built from https://develop.svn.wordpress.org/trunk@36569


git-svn-id: http://core.svn.wordpress.org/trunk@36536 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2016-02-18 00:24:27 +00:00
parent c6ee6246ef
commit 2d94e025a2
7 changed files with 31 additions and 34 deletions

View File

@ -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' );
/**

View File

@ -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;

View File

@ -3716,3 +3716,17 @@ function popuplinks( $text ) {
$text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $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'];
}

View File

@ -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'];

View File

@ -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'] );

View File

@ -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.

View File

@ -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.