From 41eeb07634869a053eb4c904ed3b8555a2224a55 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 23 Jan 2010 18:06:37 +0000 Subject: [PATCH] comment_form(), first pass. Props beaulebens. see #10910 git-svn-id: http://svn.automattic.com/wordpress/trunk@12810 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/comment-template.php | 86 +++++++++++++++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index f48dc91fbd..fcf37e7225 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -833,7 +833,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false if ( empty($file) ) $file = '/comments.php'; - + $req = get_option('require_name_email'); /** @@ -1416,4 +1416,88 @@ function wp_list_comments($args = array(), $comments = null ) { $in_comment_loop = false; } +/** + * Outputs a complete commenting form for use within a template. + * Most strings and form fields may be controlled through the $args array passed + * into the function, while you may also choose to use the comments_form_default_fields + * filter to modify the array of default fields if you'd just like to add a new + * one or remove a single field. All fields are also individually passed through + * a filter of the form comments_form_field_$name where $name is the key used + * in the array of fields. + * + * @since x.x + * @param array $args Options for strings, fields etc in the form + * @param mixed $post_id Post ID to generate the form for, uses the current post if null + * @return void + */ +function comment_form( $args = array(), $post_id = null ) { + global $user_identity, $id; + + if ( null === $post_id ) + $post_id = $id; + else + $id = $post_id; + + $commenter = wp_get_current_commenter(); + + $req = get_option( 'require_name_email' ); + $aria_req = ( $req ? " aria-required='true'" : '' ); + $req_str = ( $req ? __( ' (required)' ) : '' ); + $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '

', + 'email' => '

', + 'url' => '

' ) ), + 'comment_field' => '

', + 'must_log_in' => '

' . sprintf( __( 'You must be logged in to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '

', + 'logged_in_as' => '

' . sprintf( __( 'Logged in as %s. Log out »

' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ), + 'id_form' => 'commentform', + 'id_submit' => 'submit', + 'title_reply' => __( 'Leave a Reply' ), + 'title_reply_to' => __( 'Leave a Reply to %s'), + 'cancel_reply_link' => '', + 'label_submit' => __( 'Submit Comment' ), + ); + $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) ); + + ?> + + +
+

+
+ +
+ + + + +
+ + + + + + $field ) { + echo apply_filters( "comment_form_field_{$name}", $field ) . "\n"; + } + do_action( 'comment_form_after_fields' ); + ?> + + +

+ + +

+ +
+ +
+ + + + +