function ap_add_history($userid = false, $actionid, $parent_id, $param = NULL) { if (!$userid) { $userid = get_current_user_id(); } $opts = array('userid' => $userid, 'actionid' => $actionid, 'parent_id' => $parent_id, 'param' => $param); $opts = apply_filters('ap_add_history_parms', $opts); extract($opts); $last_history = ap_get_latest_history($parent_id); if ($last_history && $last_history['user_id'] == $userid && $last_history['type'] == $param && $last_history['parent_id'] == $parent_id && $last_history['action_id'] == $actionid) { $row = ap_update_meta(array('apmeta_userid' => $userid, 'apmeta_actionid' => $actionid, 'apmeta_value' => $parent_id, 'apmeta_param' => $param), array('apmeta_userid' => $last_history['user_id'], 'apmeta_actionid' => $last_history['action_id'], 'apmeta_value' => $last_history['parent_id'], 'apmeta_param' => $last_history['type'])); } else { $row = ap_add_meta($userid, 'history', $actionid, $parent_id, $param); } do_action('ap_after_history_' . $parent_id, $userid, $actionid, $param); do_action('ap_after_inserting_history', $userid, $actionid, $parent_id, $param); return $row; }
/** * Mark a notification as read * @param integer $id notification id * @return integer|boolean Return FALSE on failure */ function ap_notification_mark_as_read($id) { $row = ap_update_meta(array('apmeta_type' => 'notification'), array('apmeta_id' => (int) $id)); if ($row !== false) { do_action('ap_notification_marked_as_read', $id); } return $row; }
public function markread_notification() { $id = (int) $_POST['id']; if (isset($_POST['id']) && !wp_verify_nonce($_POST['__nonce'], 'ap_markread_notification_' . $id) && !is_user_logged_in()) { ap_send_json(ap_ajax_responce('something_wrong')); return; } elseif (!wp_verify_nonce($_POST['__nonce'], 'ap_markread_notification_' . get_current_user_id()) && !is_user_logged_in()) { ap_send_json(ap_ajax_responce('something_wrong')); return; } if (isset($_POST['id'])) { $notification = ap_get_notification_by_id($id); if ($notification && ($notification['apmeta_actionid'] == get_current_user_id() || is_super_admin())) { $row = ap_update_meta(array('apmeta_type' => 'notification'), array('apmeta_id' => $notification['apmeta_id'])); if ($row !== false) { ap_send_json(ap_ajax_responce(array('message' => 'mark_read_notification', 'action' => 'mark_read_notification', 'container' => '.ap-notification-' . $notification['apmeta_id'], 'view' => array('notification_count' => ap_get_total_unread_notification())))); } } } else { $row = ap_notification_mark_all_read(get_current_user_id()); if ($row !== false) { ap_send_json(ap_ajax_responce(array('message' => 'mark_read_notification', 'action' => 'mark_all_read', 'container' => '#ap-notification-dropdown', 'view' => array('notification_count' => '0')))); } } //if process reached here then there must be something wrong ap_send_json(ap_ajax_responce('something_wrong')); }
function ap_notification_mark_all_read($user_id) { return ap_update_meta(array('apmeta_type' => 'notification'), array('apmeta_type' => 'unread_notification', 'apmeta_actionid' => (int) $user_id)); }
/** * Handle ajax callback for mark all notification as read */ public function markread_notification() { $id = (int) $_POST['id']; if (isset($_POST['id']) && !ap_verify_nonce('ap_markread_notification_' . $id) && !is_user_logged_in()) { $this->something_wrong(); } elseif (!ap_verify_nonce('ap_markread_notification_' . get_current_user_id()) && !is_user_logged_in()) { $this->something_wrong(); } if (isset($_POST['id'])) { $notification = ap_get_notification_by_id($id); if ($notification && (get_current_user_id() == $notification['apmeta_actionid'] || is_super_admin())) { $row = ap_update_meta(array('apmeta_type' => 'notification'), array('apmeta_id' => $notification['apmeta_id'])); if (false !== $row) { $this->send(array('message' => 'mark_read_notification', 'action' => 'mark_read_notification', 'container' => '.ap-notification-' . $notification['apmeta_id'], 'view' => array('notification_count' => ap_get_total_unread_notification()))); } } } else { $row = ap_notification_mark_all_read(get_current_user_id()); if (false !== $row) { $this->send(array('message' => 'mark_read_notification', 'action' => 'mark_all_read', 'container' => '#ap-notification-dropdown', 'view' => array('notification_count' => '0'))); } } $this->something_wrong(); }