Your code has 2 major issues:
-
It’s missing a
return $fields;
or a return value — Filter callbacks must always return something, which is normally the first parameter after it’s filtered (regardless it’s actually modified or not by your callback). -
Do not call
comment_form()
becausecomment_form_fields
is fired in that function, hence you’ll run into a never-ending loop, just like you’ve seen it yourself.
And looking at your code which calls comment_form()
, I believe the hook you should be using is comment_form_defaults
and not comment_form_fields
.
So try the following instead:
// Use comment_form_defaults and not comment_form_fields.
add_filter( 'comment_form_defaults', 'comment_form_args' );
function comment_form_args( $args ) {
if ( ! is_user_logged_in() ) {
return array_merge( $args, array(
'label_submit' => __( 'Submit for Approval' ),
'comment_notes_before' => '',
'title_reply' => 'Need to ask something? Go ahead.',
'title_reply_to' => 'Your reply to %s',
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( '', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>',
'comment_notes_after' => '<p>Be polite and specific. Spam will be deleted.</p>'
) );
} else {
return array_merge( $args, array(
'label_submit' => __( 'Submit' ),
'comment_notes_before' => '',
'title_reply' => '',
'title_reply_to' => 'Answer %s',
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( '', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>',
'comment_notes_after' => ''
) );
}
}