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.

git-svn-id: https://develop.svn.wordpress.org/trunk@36569 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2016-02-18 00:23:04 +00:00
parent e2dd03abd4
commit bb49a958d2
6 changed files with 30 additions and 33 deletions

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.