Pass overrides. Allow ref array calling. Props tychay. fixes #12278
git-svn-id: http://svn.automattic.com/wordpress/trunk@13290 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
0ec732b34a
commit
a55b30dcaf
|
@ -227,7 +227,7 @@ function validate_file_to_edit( $file, $allowed_files = '' ) {
|
||||||
*/
|
*/
|
||||||
function wp_handle_upload( &$file, $overrides = false, $time = null ) {
|
function wp_handle_upload( &$file, $overrides = false, $time = null ) {
|
||||||
// The default error handler.
|
// The default error handler.
|
||||||
if (! function_exists( 'wp_handle_upload_error' ) ) {
|
if ( ! function_exists( 'wp_handle_upload_error' ) ) {
|
||||||
function wp_handle_upload_error( &$file, $message ) {
|
function wp_handle_upload_error( &$file, $message ) {
|
||||||
return array( 'error'=>$message );
|
return array( 'error'=>$message );
|
||||||
}
|
}
|
||||||
|
@ -262,6 +262,7 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) {
|
||||||
// All tests are on by default. Most can be turned off by $override[{test_name}] = false;
|
// All tests are on by default. Most can be turned off by $override[{test_name}] = false;
|
||||||
$test_form = true;
|
$test_form = true;
|
||||||
$test_size = true;
|
$test_size = true;
|
||||||
|
$test_upload = true;
|
||||||
|
|
||||||
// If you override this, you must provide $ext and $type!!!!
|
// If you override this, you must provide $ext and $type!!!!
|
||||||
$test_type = true;
|
$test_type = true;
|
||||||
|
@ -273,19 +274,24 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) {
|
||||||
|
|
||||||
// A correct form post will pass this test.
|
// A correct form post will pass this test.
|
||||||
if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
|
if ( $test_form && (!isset( $_POST['action'] ) || ($_POST['action'] != $action ) ) )
|
||||||
return $upload_error_handler( $file, __( 'Invalid form submission.' ));
|
return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' ));
|
||||||
|
|
||||||
// A successful upload will pass this test. It makes no sense to override this one.
|
// A successful upload will pass this test. It makes no sense to override this one.
|
||||||
if ( $file['error'] > 0 )
|
if ( $file['error'] > 0 )
|
||||||
return $upload_error_handler( $file, $upload_error_strings[$file['error']] );
|
return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']] );
|
||||||
|
|
||||||
// A non-empty file will pass this test.
|
// A non-empty file will pass this test.
|
||||||
if ( $test_size && !($file['size'] > 0 ) )
|
if ( $test_size && !($file['size'] > 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.' ));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
// A properly uploaded file will pass this test. There should be no reason to override this one.
|
// A properly uploaded file will pass this test. There should be no reason to override this one.
|
||||||
if (! @ is_uploaded_file( $file['tmp_name'] ) )
|
if ( $test_upload && ! @ is_uploaded_file( $file['tmp_name'] ) )
|
||||||
return $upload_error_handler( $file, __( 'Specified file failed upload test.' ));
|
return call_user_func($upload_error_handler, $file, __( 'Specified file failed upload test.' ));
|
||||||
|
|
||||||
// A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
|
// A correct MIME type will pass this test. Override $mimes or use the upload_mimes filter.
|
||||||
if ( $test_type ) {
|
if ( $test_type ) {
|
||||||
|
@ -294,7 +300,7 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) {
|
||||||
extract( $wp_filetype );
|
extract( $wp_filetype );
|
||||||
|
|
||||||
if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
|
if ( ( !$type || !$ext ) && !current_user_can( 'unfiltered_upload' ) )
|
||||||
return $upload_error_handler( $file, __( 'File type does not meet security guidelines. Try another.' ));
|
return call_user_func($upload_error_handler, $file, __( 'File type does not meet security guidelines. Try another.' ));
|
||||||
|
|
||||||
if ( !$ext )
|
if ( !$ext )
|
||||||
$ext = ltrim(strrchr($file['name'], '.'), '.');
|
$ext = ltrim(strrchr($file['name'], '.'), '.');
|
||||||
|
@ -307,15 +313,14 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) {
|
||||||
|
|
||||||
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
|
||||||
if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) )
|
if ( ! ( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ) )
|
||||||
return $upload_error_handler( $file, $uploads['error'] );
|
return call_user_func($upload_error_handler, $file, $uploads['error'] );
|
||||||
|
|
||||||
$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
|
$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
|
||||||
|
|
||||||
// Move the file to the uploads dir
|
// Move the file to the uploads dir
|
||||||
$new_file = $uploads['path'] . "/$filename";
|
$new_file = $uploads['path'] . "/$filename";
|
||||||
if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) ) {
|
if ( false === @ move_uploaded_file( $file['tmp_name'], $new_file ) )
|
||||||
return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
|
return $upload_error_handler( $file, sprintf( __('The uploaded file could not be moved to %s.' ), $uploads['path'] ) );
|
||||||
}
|
|
||||||
|
|
||||||
// Set correct file permissions
|
// Set correct file permissions
|
||||||
$stat = stat( dirname( $new_file ));
|
$stat = stat( dirname( $new_file ));
|
||||||
|
|
|
@ -177,13 +177,13 @@ win.send_to_editor('<?php echo addslashes($html); ?>');
|
||||||
*
|
*
|
||||||
* @since unknown
|
* @since unknown
|
||||||
*
|
*
|
||||||
* @param unknown_type $file_id
|
* @param string $file_id Index into the {@link $_FILES} array of the upload
|
||||||
* @param unknown_type $post_id
|
* @param int $post_id The post ID the media is associated with
|
||||||
* @param unknown_type $post_data
|
* @param array $post_data allows you to overwrite some of the attachment
|
||||||
* @return unknown
|
* @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
|
||||||
|
* @return int the ID of the attachment
|
||||||
*/
|
*/
|
||||||
function media_handle_upload($file_id, $post_id, $post_data = array()) {
|
function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
|
||||||
$overrides = array('test_form'=>false);
|
|
||||||
|
|
||||||
$time = current_time('mysql');
|
$time = current_time('mysql');
|
||||||
if ( $post = get_post($post_id) ) {
|
if ( $post = get_post($post_id) ) {
|
||||||
|
@ -461,6 +461,7 @@ function media_upload_form_handler() {
|
||||||
|
|
||||||
$html = $attachment['post_title'];
|
$html = $attachment['post_title'];
|
||||||
if ( !empty($attachment['url']) ) {
|
if ( !empty($attachment['url']) ) {
|
||||||
|
$rel = '';
|
||||||
if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
|
if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
|
||||||
$rel = " rel='attachment wp-att-" . esc_attr($send_id)."'";
|
$rel = " rel='attachment wp-att-" . esc_attr($send_id)."'";
|
||||||
$html = "<a href='{$attachment['url']}'$rel>$html</a>";
|
$html = "<a href='{$attachment['url']}'$rel>$html</a>";
|
||||||
|
|
Loading…
Reference in New Issue