<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[13290] trunk/wp-admin/includes: Pass overrides.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13290">13290</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2010-02-22 16:54:51 +0000 (Mon, 22 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Pass overrides. Allow ref array calling. Props tychay. fixes <a href="http://trac.wordpress.org/ticket/12278">#12278</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesfilephp">trunk/wp-admin/includes/file.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesfilephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/file.php (13289 => 13290)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/file.php        2010-02-22 08:36:32 UTC (rev 13289)
+++ trunk/wp-admin/includes/file.php        2010-02-22 16:54:51 UTC (rev 13290)
</span><span class="lines">@@ -227,7 +227,7 @@
</span><span class="cx">  */
</span><span class="cx"> function wp_handle_upload( &amp;$file, $overrides = false, $time = null ) {
</span><span class="cx">         // The default error handler.
</span><del>-        if (! function_exists( 'wp_handle_upload_error' ) ) {
</del><ins>+        if ( ! function_exists( 'wp_handle_upload_error' ) ) {
</ins><span class="cx">                 function wp_handle_upload_error( &amp;$file, $message ) {
</span><span class="cx">                         return array( 'error'=&gt;$message );
</span><span class="cx">                 }
</span><span class="lines">@@ -262,6 +262,7 @@
</span><span class="cx">         // All tests are on by default. Most can be turned off by $override[{test_name}] = false;
</span><span class="cx">         $test_form = true;
</span><span class="cx">         $test_size = true;
</span><ins>+        $test_upload = true;
</ins><span class="cx"> 
</span><span class="cx">         // If you override this, you must provide $ext and $type!!!!
</span><span class="cx">         $test_type = true;
</span><span class="lines">@@ -273,19 +274,24 @@
</span><span class="cx"> 
</span><span class="cx">         // A correct form post will pass this test.
</span><span class="cx">         if ( $test_form &amp;&amp; (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
</span><del>-                return $upload_error_handler( $file, __( 'Invalid form submission.' ));
</del><ins>+                return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' ));
</ins><span class="cx"> 
</span><span class="cx">         // A successful upload will pass this test. It makes no sense to override this one.
</span><span class="cx">         if ( $file['error'] &gt; 0 )
</span><del>-                return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
</del><ins>+                return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']] );
</ins><span class="cx"> 
</span><span class="cx">         // A non-empty file will pass this test.
</span><del>-        if ( $test_size &amp;&amp; !($file['size'] &gt; 0 ) )
-                return $upload_error_handler( $file, __( '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.' ));
</del><ins>+        if ( $test_size &amp;&amp; !($file['size'] &gt; 0 ) ) {
+                if ( is_multisite() )
+                        $error_msg = __( 'File is empty. Please upload something more substantial.' );
+                else
+                        $error_msg = __( '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.' );
+                return call_user_func($upload_error_handler, $file, $error_msg);
+        }
</ins><span class="cx"> 
</span><span class="cx">         // A properly uploaded file will pass this test. There should be no reason to override this one.
</span><del>-        if (! @ is_uploaded_file( $file['tmp_name'] ) )
-                return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
</del><ins>+        if ( $test_upload &amp;&amp; ! @ is_uploaded_file( $file['tmp_name'] ) )
+                return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' ));
</ins><span class="cx"> 
</span><span class="cx">         // A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
</span><span class="cx">         if ( $test_type ) {
</span><span class="lines">@@ -294,7 +300,7 @@
</span><span class="cx">                 extract( $wp_filetype );
</span><span class="cx"> 
</span><span class="cx">                 if ( ( !$type || !$ext ) &amp;&amp; !current_user_can( 'unfiltered_upload' ) )
</span><del>-                        return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
</del><ins>+                        return call_user_func($upload_error_handler, $file, __( 'File type does not meet security guidelines. Try another.' ));
</ins><span class="cx"> 
</span><span class="cx">                 if ( !$ext )
</span><span class="cx">                         $ext = ltrim(strrchr($file['name'], '.'), '.');
</span><span class="lines">@@ -307,15 +313,14 @@
</span><span class="cx"> 
</span><span class="cx">         // A writable uploads dir will pass this test. Again, there's no point overriding this one.
</span><span class="cx">         if ( ! ( ( $uploads = wp_upload_dir($time) ) &amp;&amp; false === $uploads['error'] ) )
</span><del>-                return $upload_error_handler( $file, $uploads['error'] );
</del><ins>+                return call_user_func($upload_error_handler, $file, $uploads['error'] ); 
</ins><span class="cx"> 
</span><span class="cx">         $filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
</span><span class="cx"> 
</span><span class="cx">         // Move the file to the uploads dir
</span><span class="cx">         $new_file = $uploads['path'] . &quot;/$filename&quot;;
</span><del>-        if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) {
</del><ins>+        if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
</ins><span class="cx">                 return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
</span><del>-        }
</del><span class="cx"> 
</span><span class="cx">         // Set correct file permissions
</span><span class="cx">         $stat = stat( dirname( $new_file ));
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (13289 => 13290)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2010-02-22 08:36:32 UTC (rev 13289)
+++ trunk/wp-admin/includes/media.php        2010-02-22 16:54:51 UTC (rev 13290)
</span><span class="lines">@@ -177,13 +177,13 @@
</span><span class="cx">  *
</span><span class="cx">  * @since unknown
</span><span class="cx">  *
</span><del>- * @param unknown_type $file_id
- * @param unknown_type $post_id
- * @param unknown_type $post_data
- * @return unknown
</del><ins>+ * @param string $file_id Index into the {@link $_FILES} array of the upload
+ * @param int $post_id The post ID the media is associated with
+ * @param array $post_data allows you to overwrite some of the attachment
+ * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
+ * @return int the ID of the attachment
</ins><span class="cx">  */
</span><del>-function media_handle_upload($file_id, $post_id, $post_data = array()) {
-        $overrides = array('test_form'=&gt;false);
</del><ins>+function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' =&gt; false )) {
</ins><span class="cx"> 
</span><span class="cx">         $time = current_time('mysql');
</span><span class="cx">         if ( $post = get_post($post_id) ) {
</span><span class="lines">@@ -461,6 +461,7 @@
</span><span class="cx"> 
</span><span class="cx">                 $html = $attachment['post_title'];
</span><span class="cx">                 if ( !empty($attachment['url']) ) {
</span><ins>+                        $rel = '';
</ins><span class="cx">                         if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
</span><span class="cx">                                 $rel = &quot; rel='attachment wp-att-&quot; . esc_attr($send_id).&quot;'&quot;;
</span><span class="cx">                         $html = &quot;&lt;a href='{$attachment['url']}'$rel&gt;$html&lt;/a&gt;&quot;;
</span></span></pre>
</div>
</div>

</body>
</html>