Image sideload and wp_upload_dir() fixes from noel. fixes #7342 for trunk

git-svn-id: http://svn.automattic.com/wordpress/trunk@8369 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-07-18 03:19:12 +00:00
parent 8f29cb96e7
commit cdcd6ffdf6
2 changed files with 9 additions and 7 deletions

View File

@ -34,13 +34,14 @@ function press_it() {
$content = $_REQUEST['content'];
foreach( (array) $_REQUEST['photo_src'] as $key => $image) {
// escape quote for matching
$quoted = preg_quote2($image);
// see if files exist in content - we don't want to upload non-used selected files.
if( strpos($_REQUEST['content'], $quoted) !== false ) {
if( strpos($_REQUEST['content'], $image) !== false ) {
$upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]);
// Replace the POSTED content <img> with correct uploaded ones.
// escape quote for matching
$quoted = preg_quote2($image);
if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content);
}
}

View File

@ -1491,7 +1491,7 @@ function wp_upload_dir( $time = NULL ) {
$dir = path_join( ABSPATH, $dir );
if ( !$url = get_option( 'upload_url_path' ) ) {
if ( empty($upload_path) )
if ( empty($upload_path) or ( $upload_path == $dir ) )
$url = WP_CONTENT_URL . '/uploads';
else
$url = trailingslashit( $siteurl ) . $upload_path;
@ -1525,6 +1525,7 @@ function wp_upload_dir( $time = NULL ) {
}
$uploads = array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false );
return apply_filters( 'upload_dir', $uploads );
}