WordPress.org

Make WordPress Core

Ticket #16294: wrx_import.patch

File wrx_import.patch, 2.4 KB (added by belaraka, 3 years ago)

Adds the ability to import wrx files through a URL, rather then upload.

  • wp-admin/includes/import.php

     
    5959 * @return array Uploaded file's details on success, error message on failure 
    6060 */ 
    6161function wp_import_handle_upload() { 
    62         if ( !isset($_FILES['import']) ) { 
    63                 $file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ); 
    64                 return $file; 
    65         } 
     62  if($_POST['import_url']) { 
     63    $wrx_url = esc_url($_POST['import_url'], null, 'url'); 
     64    if($wrx_url) { 
     65      $wrx_content = wp_remote_fopen($wrx_url); 
     66      $file = wp_upload_bits(basename($wrx_url) . ".txt", null, $wrx_content); 
     67    } else { 
     68      $file['error'] = __( 'The URL you entered is empty or invalid.' ); 
     69      return $file; 
     70    } 
     71  } else { 
     72        if ( !isset($_FILES['import']) ) { 
     73                $file['error'] = __( 'File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.' ); 
     74                return $file; 
     75        } else { 
     76      $overrides = array( 'test_form' => false, 'test_type' => false ); 
     77      $_FILES['import']['name'] .= '.txt'; 
     78      $file = wp_handle_upload( $_FILES['import'], $overrides ); 
     79      if ( isset( $file['error'] ) ) 
     80        return $file; 
     81    } 
     82  } 
    6683 
    67         $overrides = array( 'test_form' => false, 'test_type' => false ); 
    68         $_FILES['import']['name'] .= '.txt'; 
    69         $file = wp_handle_upload( $_FILES['import'], $overrides ); 
    70  
    71         if ( isset( $file['error'] ) ) 
    72                 return $file; 
    73  
    7484        $url = $file['url']; 
    7585        $type = $file['type']; 
    7686        $file = $file['file']; 
  • wp-admin/includes/template.php

     
    847847<input type="hidden" name="action" value="save" /> 
    848848<input type="hidden" name="max_file_size" value="<?php echo $bytes; ?>" /> 
    849849</p> 
     850<p> 
     851<label for="wxr_url"><?php _e( 'OR enter the url for your WXR file:' ); ?></label> 
     852<input type="text" id="wxr_url" name="import_url" size="50" /> 
     853</p> 
    850854<?php submit_button( __('Upload file and import'), 'button' ); ?> 
    851855</form> 
    852856<?php