Make WordPress Core

Changeset 12371


Ignore:
Timestamp:
12/11/2009 12:14:18 AM (15 years ago)
Author:
azaozz
Message:

Press This empty title fix, props noel, see #11390, fixes #10715

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/press-this.php

    r12370 r12371  
    4444    $quick['post_status'] = 'draft'; // set as draft first
    4545    $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'] : '';
    4949
    5050    // insert the post with nothing in it, to get an ID
    5151    $post_ID = wp_insert_post($quick, true);
     52    if ( is_wp_error($post_ID) )
     53        wp_die($post_ID);
     54
    5255    $content = isset($_POST['content']) ? $_POST['content'] : '';
    5356
    5457    $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) {
    5760            // 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 ) {
    5962                $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
    6063                $upload = media_sideload_image($image, $post_ID, $desc);
    6164
    6265                // 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);
    6468            }
    65 
     69        }
     70    }
    6671    // set the post_content and status
    6772    $quick['post_status'] = isset($_POST['publish']) ? 'publish' : 'draft';
    6873    $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) ) {
    7276        wp_delete_post($post_ID);
    73     // error handling for media_sideload
    74     } elseif ( is_wp_error($upload)) {
    7577        wp_die($upload);
    76         wp_delete_post($post_ID);
    7778    } else {
    7879        $quick['ID'] = $post_ID;
Note: See TracChangeset for help on using the changeset viewer.