最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

callbacks - Code works, but warning about call_user_func_array() appears

programmeradmin4浏览0评论

I'm a newbie to Wordpress. I'm trying to make custom page that displays contact info for all users. I use code snippet provided by THIS POST.

<ul>
<?php
    $blogusers = get_users('blog_id=1&orderby=nicename');
    foreach ($blogusers as $user) {
        echo '<li>Nick: ' . $user->user_nicename . '</li>';
        echo '<li>Name: ' . $user->display_name. '</li>';
        echo '<li>Email: ' . $user->user_email. '</li>';
    }
?>
</ul>

It works, but it also shows this warning at the top:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'yoursite_pre_user_query' not found or invalid function name in C:\xampp\htdocs\mytheme\wordpress\wp-includes\class-wp-hook.php on line 287

What should I do to resolve this?

I'm a newbie to Wordpress. I'm trying to make custom page that displays contact info for all users. I use code snippet provided by THIS POST.

<ul>
<?php
    $blogusers = get_users('blog_id=1&orderby=nicename');
    foreach ($blogusers as $user) {
        echo '<li>Nick: ' . $user->user_nicename . '</li>';
        echo '<li>Name: ' . $user->display_name. '</li>';
        echo '<li>Email: ' . $user->user_email. '</li>';
    }
?>
</ul>

It works, but it also shows this warning at the top:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'yoursite_pre_user_query' not found or invalid function name in C:\xampp\htdocs\mytheme\wordpress\wp-includes\class-wp-hook.php on line 287

What should I do to resolve this?

Share Improve this question edited Sep 17, 2020 at 19:17 Sev. asked Sep 12, 2020 at 14:21 Sev.Sev. 32 bronze badges 1
  • The cause of that warning is not in the code block you added – Tom J Nowell Commented Sep 13, 2020 at 0:02
Add a comment  | 

1 Answer 1

Reset to default 1

Somewhere in your theme or plugins, you must have a line like this add_action( 'something', 'yoursite_pre_user_query' ). Find it and remove or fix it.

Also, the get_users function has since been updated. Your first parameter must be an array.

<ul>
<?php
    $blogusers = get_users( array('blog_id' => 1, 'orderby' => 'nicename') );
    foreach ( $blogusers as $user ) {
        echo '<li>Nick: ' . $user->user_nicename . '</li>';
        echo '<li>Name: ' . $user->display_name. '</li>';
        echo '<li>Email: ' . $user->user_email. '</li>';
    }
?>
</ul>
发布评论

评论列表(0)

  1. 暂无评论