function ml_push_notification_manual_send_callback() { if (isset($_POST['ml_push_notification_msg'])) { $platform = array(); switch ($_POST['ml_push_notification_os']) { case 'all': $platform = array(0, 1); break; case 'android': $platform = array(1); break; case 'ios': $platform = array(0); break; } $tags = array(); $tagNames = array(); $postId = null; if (strlen($_POST['ml_push_notification_data_id']) > 0) { if (strpos($_POST['ml_push_notification_data_id'], 'custom') !== false) { $postId = $_POST['ml_push_notification_post_id']; } else { $postId = substr($_POST['ml_push_notification_data_id'], 8); } } if ($postId != null) { $tags = ml_get_post_tag_ids($postId); $tagNames = ml_get_post_tags($postId); } $tags[] = 'all'; $tagNames[] = 'all'; $payload = array(); if ($postId !== null) { $image = wp_get_attachment_image_src(get_post_thumbnail_id($postId), 'single-post-thumbnail'); $payload = array('post_id' => $postId); if (is_array($image)) { $payload['featured_image'] = $image[0]; } } $data = array('platform' => $platform, 'msg' => trim($_POST['ml_push_notification_msg']), 'sound' => 'default', 'badge' => null, 'notags' => true, 'tags' => $tags, 'payload' => $payload); ml_pb_send_batch_notification($data, $tagNames); Mobiloud_Admin::track_user_event('push_notification'); } ml_push_notification_manual_send(); die; }
function ml_pb_post_published_notification($new_status, $old_status, $post) { if (ml_is_notified($post->ID) || !ml_check_post_notification_required($post->ID)) { return; } $push_types = Mobiloud::get_option("ml_push_post_types", "post"); if (strlen($push_types) > 0) { $push_types = explode(",", $push_types); if ($new_status == 'publish' && $old_status != 'publish' && in_array($post->post_type, $push_types)) { // only send push if it's a new publish $payload = array('post_id' => strval($post->ID)); $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'single-post-thumbnail'); if (is_array($image)) { $payload['featured_image'] = $image[0]; } $tags = ml_get_post_tag_ids($post->ID); $tags[] = 'all'; $tagNames = ml_get_post_tags($post->ID); $tagNames[] = 'all'; $data = array('platform' => array(0, 1), 'msg' => strip_tags(trim($post->post_title)), 'sound' => 'default', 'badge' => null, 'notags' => true, 'tags' => $tags, 'payload' => $payload, "chunk" => 1000, "rate" => 120); ml_pb_send_batch_notification($data, $tagNames); } } }