Make WordPress Core

Changeset 4569 for trunk/xmlrpc.php


Ignore:
Timestamp:
12/01/2006 04:34:59 AM (18 years ago)
Author:
ryan
Message:

Create attachments for xmlrpc uploads. Props donncha. fixes #3400

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/xmlrpc.php

    r4537 r4569  
    396396        return new IXR_Error(500, 'Sorry, your entry could not be posted. Something wrong happened.');
    397397      }
     398      $this->attach_uploads( $post_ID, $post_content );
    398399
    399400      logIO('O', "Posted ! ID: $post_ID");
     
    445446        return new IXR_Error(500, 'For some strange yet very annoying reason, this post could not be edited.');
    446447      }
     448      $this->attach_uploads( $ID, $post_content );
    447449
    448450      return true;
     
    565567      }
    566568
     569      $this->attach_uploads( $post_ID, $post_content );
     570
    567571      logIO('O', "Posted ! ID: $post_ID");
    568572
     
    570574    }
    571575
     576    function attach_uploads( $post_ID, $post_content ) {
     577        global $wpdb;
     578
     579        // find any unattached files
     580        $attachments = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts} WHERE post_parent = '-1' AND post_type = 'attachment'" );
     581        if( is_array( $attachments ) ) {
     582            foreach( $attachments as $file ) {
     583                if( strpos( $post_content, $file->guid ) !== false ) {
     584                    $wpdb->query( "UPDATE {$wpdb->posts} SET post_parent = '$post_ID' WHERE ID = '{$file->ID}'" );
     585                }
     586            }
     587        }
     588    }
    572589
    573590    /* metaweblog.editPost ...edits a post */
     
    644661        return new IXR_Error(500, 'Sorry, your entry could not be edited. Something wrong happened.');
    645662      }
     663      $this->attach_uploads( $ID, $post_content );
    646664
    647665      logIO('O',"(MW) Edited ! ID: $post_ID");
     
    842860            return new IXR_Error(500, 'Could not write file '.$name);
    843861        }
     862        // Construct the attachment array
     863        // attach to post_id -1
     864        $post_id = -1;
     865        $attachment = array(
     866            'post_title' => $name,
     867            'post_content' => '',
     868            'post_type' => 'attachment',
     869            'post_parent' => $post_id,
     870            'post_mime_type' => $type,
     871            'guid' => $upload[ 'url' ]
     872        );
     873        // Save the data
     874        $id = wp_insert_attachment($attachment, $upload[ 'file' ], $post_id);
     875        add_post_meta($id, '_wp_attachment_metadata', array());
     876
    844877        return apply_filters( 'wp_handle_upload', array( 'file' => $upload[ 'file' ], 'url' => $upload[ 'url' ], 'type' => $type ) );
    845878    }
Note: See TracChangeset for help on using the changeset viewer.