0

I'm trying to write a function that will allow me more control over the display of comments on a post page. However I'm confused about how to set it up so WordPress can use it. right now I get the following error:

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'custom_comments()' not found or invalid function name in /Users/Brent/Desktop/Web Design/WP Playground/wordpress/wp-includes/comment-template.php on line 1711

Here is the call to the function:

<div class="comment-list">
    <?php
    wp_list_comments('type=comment&callback=custom_comments()');
    ?>
</div><!-- .comment-list -->

And here is what that section of my functions.php file looks like:

add_action('load_comments', 'custom_comments');

function custom_comments($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    ?>

        <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">

            <div class="comment-intro">
                <em>commented on</em> 
                <a class="comment-permalink" href="<?php echo htmlspecialchars(get_comment_link($comment->comment_ID)) ?>"><?php printf(__('%1$s'), get_comment_date(), get_comment_time()) ?></a>
                <em>by</em> 
        <?php printf(__('%s'), get_comment_author_link()) ?>
            </div>

        <?php if ($comment->comment_approved == '0') : ?>
                    <em><php _e('Your comment is awaiting moderation.') ?></em><br />
        <?php endif; ?>

            <?php comment_text(); ?>

            <div class="reply">
        <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
            </div>

<?php } ?>

Could anyone tell me what I'm doing wrong here to get this error? I know from my research on this issue that sometimes you need to remove_action from another function that may be conflicting with this function, but I'm not even sure I'm calling this function correctly. Please help, I'm having a hard time finding good resources on how to use a custom comment function.

This is the only good resource I've found so I've been following this but it doesn't say anything about the errors: Custom Comments HTML Output

When I googled the error I found this page slightly helpful, but I haven't been able to identify the culprit function: wordpress.org

I've checked out a few other questions on here but they mostly seem to be asking about other specific problems. Help is greatly GREATLY appreciated!

0

You should not have the () on the callback field. You shouldn't need the add_action so remove

add_action('load_comments', 'custom_comments');

And try:

 wp_list_comments('type=comment&callback=custom_comments');

Also, you should extract the $args so they are available in your function:

function custom_comments($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment;
    extract($args, EXTR_SKIP);
    //etc

http://codex.wordpress.org/Function_Reference/wp_list_comments

  • ps: using extract is not considered the best PHP practice. There's an ongoing effort to remove it from the WordPress core, check for example this answer and ticket #22400 – birgire Dec 29 '14 at 21:28
  • birgire: thanks for the links. I'm guessing lots of codex pages need tweaking too! – shanebp Dec 29 '14 at 22:02
  • I first noticed this ticket from the answer by toscho, so I just wanted to pass it on. yes, I guess the cleaning might take couple of years ;-) – birgire Dec 30 '14 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.