Changeset 12371
- Timestamp:
- 12/11/2009 12:14:18 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/press-this.php
r12370 r12371 44 44 $quick['post_status'] = 'draft'; // set as draft first 45 45 $quick['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : null; 46 $quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';47 $quick['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';48 $quick['post_content'] = '';46 $quick['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : null; 47 $quick['post_title'] = ( trim($_POST['title']) != '' ) ? $_POST['title'] : ' '; 48 $quick['post_content'] = isset($_POST['post_content']) ? $_POST['post_content'] : ''; 49 49 50 50 // insert the post with nothing in it, to get an ID 51 51 $post_ID = wp_insert_post($quick, true); 52 if ( is_wp_error($post_ID) ) 53 wp_die($post_ID); 54 52 55 $content = isset($_POST['content']) ? $_POST['content'] : ''; 53 56 54 57 $upload = false; 55 if( !empty($_POST['photo_src']) && current_user_can('upload_files') ) 56 foreach( (array) $_POST['photo_src'] as $key => $image) 58 if( !empty($_POST['photo_src']) && current_user_can('upload_files') ) { 59 foreach( (array) $_POST['photo_src'] as $key => $image) { 57 60 // see if files exist in content - we don't want to upload non-used selected files. 58 if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {61 if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) { 59 62 $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : ''; 60 63 $upload = media_sideload_image($image, $post_ID, $desc); 61 64 62 65 // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes 63 if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content); 66 if( !is_wp_error($upload) ) 67 $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content); 64 68 } 65 69 } 70 } 66 71 // set the post_content and status 67 72 $quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft'; 68 73 $quick['post_content'] = $content; 69 // error handling for $post 70 if ( is_wp_error($post_ID)) { 71 wp_die($id); 74 // error handling for media_sideload 75 if ( is_wp_error($upload) ) { 72 76 wp_delete_post($post_ID); 73 // error handling for media_sideload74 } elseif ( is_wp_error($upload)) {75 77 wp_die($upload); 76 wp_delete_post($post_ID);77 78 } else { 78 79 $quick['ID'] = $post_ID;
Note: See TracChangeset
for help on using the changeset viewer.