我在前端有一个按钮,它将通过AJAX触发一个函数来跟踪另一个用户。当流程完成/成功时,它将运行最后一个函数,即do_action.
尽管手动传递静态值,但仍返回以下错误:
函数sa\\u post\\u follow\\u user\\u callback()的参数太少,传递了1个
我显然通过了两次:
do_action( \'sa_post_follow_user\', 1, 16 );
以下是ajax运行的部分代码:
if ( $followed ) {
do_action( \'sa_post_follow_user\', 1, 16 );
return true;
}
The
add_action:
function sa_post_follow_user_callback( $user_id, $user_to_follow ) {
// Get user data from follower and followee.
$followee_user_data = get_userdata( $user_to_follow );
$follower_user_data = get_userdata( $user_id );
// Compile user data into array to pass to function.
$data = [
\'followee_username\' => $followee_user_data->user_login,
\'followee_email\' => $followee_user_data->user_email,
\'follower_username\' => $follower_user_data->user_login,
\'follower_profile_link\' => get_home_url() . \'/user/\' . $follower_user_data->user_login,
];
// Send email
send_follow_email( $data );
}
add_action( \'sa_post_follow_user\', \'sa_post_follow_user_callback\' );
错误:
PHP致命错误:Uncaught ArgumentCounter错误:函数sa\\u post\\u follow\\u user\\u callback()的参数太少,传入/srv/www/$
Stack trace:
#0 sa_post_follow_user_callback(1)
#1 WP_Hook->apply_filters(\'\', Array)
#2 WP_Hook->do_action(Array)
#3 do_action(\'sa_post_follow_...\', 1, 16)
#4 sa_follow_user(1, 17)