Make WordPress Core

Opened 17 years ago

Closed 17 years ago

#8960 closed enhancement (wontfix)

Post edit form is missing enctype field

Reported by: chrisnorthwood's profile chrisnorthwood Owned by:
Milestone: Priority: normal
Severity: minor Version: 2.7
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

The post edit form does not have an enctype, so if you have a plugin that wants to upload a photo or other file alongside a blog post, it does not work. This is documented at http://www.tanzilo.com/2009/01/15/wordpress-adding-a-custom-option-box-and-developing-file-upload-plugin/#comment-446, with a workaround, and a similar problem is discussed in #3890.

I've attached a patch. Adding an enctype has no ill effects, and makes life for plugin authors easier.

Attachments (1)

wordpress-post-form.patch (589 bytes) - added by chrisnorthwood 17 years ago.
Patch against revision 10437 to fix the problem

Download all attachments as: .zip

Change History (6)

@chrisnorthwood
17 years ago

Patch against revision 10437 to fix the problem

#1 @chrisnorthwood
17 years ago

  • Cc chrisnorthwood added

#2 @Denis-de-Bernardy
17 years ago

You can use an output buffer to set it.

#3 @chrisnorthwood
17 years ago

Sorry if I'm being dumb, but I'm fairly new to plugin development - could you be more specific?

#4 @Denis-de-Bernardy
17 years ago

Personally, I use:

if ( !function_exists('ob_multipart_entry_form') ) :
#
# ob_multipart_entry_form_callback()
#

function ob_multipart_entry_form_callback($buffer)
{
	$buffer = str_replace(
		'<form name="post"',
		'<form enctype="multipart/form-data" name="post"',
		$buffer
		);

	return $buffer;
} # ob_multipart_entry_form_callback()


#
# ob_multipart_entry_form()
#

function ob_multipart_entry_form()
{
	if ( $GLOBALS['editing'] )
	{
		ob_start('ob_multipart_entry_form_callback');
	}
} # ob_multipart_entry_form()

add_action('admin_head', 'ob_multipart_entry_form');


#
# add_file_max_size()
#

function add_file_max_size()
{
	$bytes = apply_filters( 'import_upload_size_limit', wp_max_upload_size() );
	
	echo  "\n" . '<input type="hidden" name="MAX_FILE_SIZE" value="' . $bytes .'" />' . "\n";
}

add_action('edit_form_advanced', 'add_file_max_size');
add_action('edit_page_form', 'add_file_max_size');
endif;

(that being said, I fully agree that this form tag should be pluginable.)

#5 @Denis-de-Bernardy
17 years ago

  • Milestone 2.8 deleted
  • Resolution set to wontfix
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.