mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 17:18:32 +01:00
Press This image linking fixes from noel. see #6813
git-svn-id: http://svn.automattic.com/wordpress/trunk@8172 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
94183a25cd
commit
cdc53fcb86
@ -151,11 +151,9 @@ function media_handle_sideload($file_array, $post_id, $desc = null, $post_data =
|
||||
$id = wp_insert_attachment($attachment, $file, $post_parent);
|
||||
if ( !is_wp_error($id) ) {
|
||||
wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
|
||||
return $src;
|
||||
return $url;
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -321,21 +319,20 @@ function media_sideload_image($file, $post_id, $desc = null) {
|
||||
$desc = @$desc;
|
||||
|
||||
$id = media_handle_sideload($file_array, $post_id, $desc);
|
||||
$src = $id;
|
||||
|
||||
unset($file_array);
|
||||
|
||||
if ( is_wp_error($id) ) {
|
||||
$errors['upload_error'] = $id;
|
||||
return $id;
|
||||
} else {
|
||||
$src = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($src) && !strpos($src, '://') ) {
|
||||
$src = "http://$src";
|
||||
$alt = @$desc;
|
||||
}
|
||||
if ( !empty($src) ) {
|
||||
if ( !strpos($src, '://') )
|
||||
$src = "http://$src";
|
||||
$alt = @$desc;
|
||||
$html = "<img src='$src' alt='$alt' />";
|
||||
return $html;
|
||||
}
|
||||
|
@ -4,15 +4,19 @@ require_once('admin.php');
|
||||
if ( ! current_user_can('publish_posts') ) wp_die( __( 'Cheatin’ uh?' )); ?>
|
||||
|
||||
<?php
|
||||
|
||||
function preg_quote2($string) {
|
||||
return str_replace('/', '\/', preg_quote($string));
|
||||
}
|
||||
function press_it() {
|
||||
#define some basic variables
|
||||
// define some basic variables
|
||||
$quick['post_status'] = $_REQUEST['post_status'];
|
||||
$quick['post_category'] = $_REQUEST['post_category'];
|
||||
$quick['tags_input'] = $_REQUEST['tags_input'];
|
||||
$quick['post_title'] = $_REQUEST['post_title'];
|
||||
$quick['post_content'] = '';
|
||||
|
||||
# insert the post with nothing in it, to get an ID
|
||||
// insert the post with nothing in it, to get an ID
|
||||
$post_ID = wp_insert_post($quick, true);
|
||||
|
||||
$content = '';
|
||||
@ -23,16 +27,21 @@ function press_it() {
|
||||
break;
|
||||
|
||||
case 'photo':
|
||||
foreach($_REQUEST['photo_src'] as $key => $data) {
|
||||
#quote for matching
|
||||
$quoted = str_replace('/', '\/', preg_quote($data));
|
||||
|
||||
# see if files exist in content - we don't want to upload non-used selected files.
|
||||
preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
|
||||
if($matches[0])
|
||||
$upload = media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]);
|
||||
}
|
||||
$content = $_REQUEST['content'];
|
||||
|
||||
foreach($_REQUEST['photo_src'] as $key => $image) {
|
||||
#quote for matching
|
||||
$quoted = preg_quote2($image);
|
||||
|
||||
// see if files exist in content - we don't want to upload non-used selected files.
|
||||
preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
|
||||
if($matches[0]) {
|
||||
$upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]);
|
||||
// Replace the POSTED content <img> with correct uploaded ones.
|
||||
if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "video":
|
||||
|
Loading…
Reference in New Issue
Block a user