wp_schedule_single_event()现有动作

发布于 2025-02-10 14:29:49 字数 744 浏览 2 评论 0原文

不幸的是,尝试做这项工作,没有成功。 注册后5分钟,用户应收到一条消息。 有解决方案吗?

function bp_messages_first_message( $user_id = false, $key = false, $user = false ){
    if ( ! function_exists( 'BP_Better_Messages' ) ) return false;

    $args = array(
        'sender_id'  => 88,
        'thread_id'  => false,
        'recipients' => $user_id,
        'content'    => "test",
        'date_sent'  => bp_core_current_time()
    );
    
    $result = BP_Better_Messages()->functions->new_message( $args );
}

function do_this_in_5_minutes() {
    add_action('bp_core_activated_user', 'bp_messages_first_message', 10, 3);
}
add_action( 'message_5','do_this_in_5_minutes' );
wp_schedule_single_event( time() + 300, 'message_5' );

Trying do make this work, unfortunately without success.
The user should receive a message 5 minutes after registration.
Any solutions?

function bp_messages_first_message( $user_id = false, $key = false, $user = false ){
    if ( ! function_exists( 'BP_Better_Messages' ) ) return false;

    $args = array(
        'sender_id'  => 88,
        'thread_id'  => false,
        'recipients' => $user_id,
        'content'    => "test",
        'date_sent'  => bp_core_current_time()
    );
    
    $result = BP_Better_Messages()->functions->new_message( $args );
}

function do_this_in_5_minutes() {
    add_action('bp_core_activated_user', 'bp_messages_first_message', 10, 3);
}
add_action( 'message_5','do_this_in_5_minutes' );
wp_schedule_single_event( time() + 300, 'message_5' );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听闻余生 2025-02-17 14:29:49

然后,在注册发生时安排事件是有意义的。

未测试:

<?php

function do_this_in_5_minutes($user_id) {
    if ( ! function_exists( 'BP_Better_Messages' ) ) return false;

    $args = array(
        'sender_id'  => 88,
        'thread_id'  => false,
        'recipients' => $user_id,
        'content'    => "test",
        'date_sent'  => bp_core_current_time()
    );
    
    $result = BP_Better_Messages()->functions->new_message( $args );
}


add_action('bp_core_activated_user', function($user_id = false, $key = false, $user = false) {
    add_action( 'message_5','do_this_in_5_minutes');
    wp_schedule_single_event( time() + 300, 'message_5', [$user_id]);

}, 10, 3);

Then it would make sense to schedule the event when the registration happens.

Not tested:

<?php

function do_this_in_5_minutes($user_id) {
    if ( ! function_exists( 'BP_Better_Messages' ) ) return false;

    $args = array(
        'sender_id'  => 88,
        'thread_id'  => false,
        'recipients' => $user_id,
        'content'    => "test",
        'date_sent'  => bp_core_current_time()
    );
    
    $result = BP_Better_Messages()->functions->new_message( $args );
}


add_action('bp_core_activated_user', function($user_id = false, $key = false, $user = false) {
    add_action( 'message_5','do_this_in_5_minutes');
    wp_schedule_single_event( time() + 300, 'message_5', [$user_id]);

}, 10, 3);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文