[wp-hackers] edit comment form

Otto otto at ottodestruct.com
Tue May 1 16:11:15 GMT 2007

If I wanted to modify the comment form, I'd do it in one of two ways.
Both of them require that the theme is at least semi-standard.

Method 1:
Both the default and classic themes have this code in them, after the
comment form:
do_action('comment_form', $post->ID);
You could use that to insert new fields, but they're going to show up
below the comment box itself. Maybe not preferable, but it will work
in a pinch. It'd be fine for hidden fields.

Method 2:
Both the default and classic themes display the comments template by
calling the comments_template() function. This function actually gets
the comments and then requires the comments.php file from the theme.
However, it passes that file through this filter first:
$include = apply_filters('comments_template', TEMPLATEPATH . $file );
You could write a filter there to intercept that file and replace it
with the name of your own file. By putting the original filename in a
global somewhere, your file could read that file, modify the contents
of it as you see fit, and then output it. Sort of a roundabout way of
modifying the comments.php, but it would work well.

Both methods rely on the theme in question doing the right thing. All
themes should include the comment_form action hook (because that is
what allows the wp_comment_form_unfiltered_html_nonce to work, which
allows authorized users to include html code in comments). And all
theme should be using the comments_template() call to include comments
(as opposed to retrieving comments from the DB themselves).


On 4/27/07, Will Norris <will at willnorris.com> wrote:
> I maintain a port of Alan Castonguay's openid plugin at <http://
> wordpress.org/extend/plugins/openid/> and was recently made aware of
> a problem when using the plugin with PHP 5.2.  Part of what the
> plugin does is to modify the comment form to include an additional
> input field for a user's OpenID.  To do this, it uses output
> buffering to capture the form, then some regex magic to make the
> necessary changes.  The problem is that it appears the callback
> method specified in ob_start() no longer has access to global
> variables in recent versions of PHP; this is not considered a bug
> <http://bugs.php.net/bug.php?id=40104>.  So I'm now looking for
> suggestions for how one might modify the comment form.
> One possibility would be to attempt a new filter, but I'm not
> completely sure that would work.  Even if it did, this whole thing
> feels kinda weird... it feels much cleaner to have the user modify
> their theme directly, as most plugins require.  I guess another
> option would be to push it to the client side and modify the DOM with
> some javascript... still not ideal, but a little cleaner.  Does
> anyone have other ideas on modifying the comment form?  Alan, I'd
> love to hear your thoughts, since you can definitely shed some light
> on alternatives you might have considered when you first wrote this.
> Thanks,
> will
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list