Skip to content
This repository has been archived by the owner on Aug 27, 2018. It is now read-only.

Commit

Permalink
Store subscription info in the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-c committed Jan 8, 2016
1 parent 7c12e3c commit 86aa3ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 9 additions & 0 deletions wp-web-push-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ public static function getInstance() {
return self::$instance;
}

public static function add_subscription($endpoint, $userKey) {
global $wpdb;

$wpdb->insert($wpdb->prefix . 'webpush_subscription', array(
'endpoint' => $endpoint,
'userKey' => $userKey,
));
}

public static function on_activate() {
global $wpdb;

Expand Down
5 changes: 2 additions & 3 deletions wp-web-push-main.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

require_once(plugin_dir_path(__FILE__) . 'web-push.php' );
require_once(plugin_dir_path(__FILE__) . 'wp-web-push-db.php');

class WebPush_Main {
private static $instance;
Expand Down Expand Up @@ -30,9 +31,7 @@ public function handle_webpush_register() {
// TODO: Enable nonce verification.
// check_ajax_referer('register_nonce');

// TODO: Use $_POST['endpoint'] and $_POST['key']

echo $_POST['endpoint'] . ' & ' . $_POST['key'];
WebPush_DB::add_subscription($_POST['endpoint'], $_POST['key']);

wp_die();
}
Expand Down

0 comments on commit 86aa3ba

Please sign in to comment.