• Resolved africanalex

    (@africanalex)


    I have added a must use plugin with a hook into the onesignal plugin. everything works fine until I add the send_after field. This causes the notifications not to appear in the console. Here is my code:

    add_filter(‘onesignal_send_notification’, ‘onesignal_send_notification_filter’, 10, 4);

    function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
    {

    date_default_timezone_set(‘UTC’);
    $newTime = date(“M d Y H:i:s e+0000”,strtotime(date(“Y-m-d H:i:s”).”+2 minutes”));
    $fields[‘send_after’] = (string)$newTime;

    $fields[‘isAndroid’] = true;
    $fields[‘isIos’] = true;
    $fields[‘isAnyWeb’] = false;
    $fields[‘isChrome’] = false;
    $fields[‘data’] = array(
    “myappurl” => $fields[‘url’]
    );
    /* Unset the URL to prevent opening the browser when the notification is clicked */
    unset($fields[‘url’]);
    return $fields;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author OneSignal Push Notifications

    (@onesignal)

    Hi there,

    Most of your code looks correct, and I ran the send_after code successfully on phpfiddle.org. It looks like all of your quotation marks got copied incorrectly, and maybe this is how it looks like in your code as well? The single and double quotation marks should be plain and not curved.

    e.g.

    Corrected:

    <?php
    date_default_timezone_set(‘UTC’);
    $newTime = date(“M d Y H:i:s e+0000”,strtotime(date(“Y-m-d H:i:s”).”+2 minutes”));
    $fields[‘send_after’] = (string)$newTime;
    print_r($fields);
    ?>

    Your Code:

    <?php
    date_default_timezone_set(‘UTC’);
    $newTime = date(“M d Y H:i:s e+0000”,strtotime(date(“Y-m-d H:i:s”).”+2 minutes”));
    $fields[‘send_after’] = (string)$newTime;
    ?>

    Marking as resolved. If not, please contact [email protected].

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Onesignal send_after field’ is closed to new replies.