[wp-trac] [WordPress Trac] #17604: wp.uploadFile overwrite doesn't work

WordPress Trac noreply at wordpress.org
Wed Jun 24 14:39:24 UTC 2015


#17604: wp.uploadFile overwrite doesn't work
---------------------------------+-----------------------------
 Reporter:  M66B                 |       Owner:
     Type:  defect (bug)         |      Status:  new
 Priority:  normal               |   Milestone:  Future Release
Component:  XML-RPC              |     Version:
 Severity:  normal               |  Resolution:
 Keywords:  has-patch 3.6-early  |     Focuses:
---------------------------------+-----------------------------

Comment (by tohokuaiki):

 I create wp.uploadFile wrapper XML-RPC method.

 {{{
 <?php
 add_filter('xmlrpc_methods', 'add_junoe_xmlrpc_methods');

 function add_junoe_xmlrpc_methods($methods)
 {
     return array_merge($methods, array(
         'wp.JuploadFile'        => 'junoe_wp_uploadFile',
         ));
 }

 function junoe_wp_uploadFile($args)
 {
     global $wp_xmlrpc_server;

     if (isset($args[3])) {
         $data = $args[3];

         if ((isset($data['overwrite']) && $data['overwrite']) &&
             (isset($data['post_id'])   && $data['post_id'])){
             $attachments = get_posts(array(
                 'post_type' => array(
                     'attachment'
                     ),
                 'post_parent' => $data['post_id'],
                 'posts_per_page' => -1,
                 'post_status' => 'inherit',
                 ));
             foreach ($attachments as $attachment){
                 if ($attachment->post_title == $data['name'] ||
                     $attachment->post_title == "wpid-".$data['name']){
                     wp_delete_attachment($attachment->ID, true);
                 }
             }
         }
     }

     return $wp_xmlrpc_server->mw_newMediaObject($args);
 }

 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/17604#comment:11>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list