public function __construct()
 {
     parent::__construct(site_url('pnfw/unregister/'), 'POST');
     global $wpdb;
     $push_tokens = $wpdb->get_blog_prefix() . 'push_tokens';
     $user_id = $wpdb->get_var($wpdb->prepare("SELECT user_id FROM {$push_tokens} WHERE token = %s AND os = %s", $this->token, $this->os));
     $res = $wpdb->delete($push_tokens, array("token" => $this->token, "os" => $this->os));
     if ($res === false) {
         $this->json_error('500', __('Unable to delete token', 'pnfw'));
     }
     $user = new WP_User($user_id);
     if (in_array(PNFW_Push_Notifications_for_WordPress_Lite::USER_ROLE, $user->roles) && empty($user->user_email)) {
         pnfw_log(PNFW_SYSTEM_LOG, sprintf(__("Automatically deleted the anonymous user %s (%s) since left without tokens.", 'pnfw'), $user->user_login, $user_id));
         require_once ABSPATH . 'wp-admin/includes/user.php';
         if (is_multisite()) {
             require_once ABSPATH . 'wp-admin/includes/ms.php';
             if (is_user_member_of_blog($user_id)) {
                 wpmu_delete_user($user_id);
             }
         } else {
             wp_delete_user($user_id);
         }
     }
     exit;
 }
 public function __construct($url, $http_method = null)
 {
     parent::__construct($url, $http_method);
     // Check token is activated
     if (!$this->is_token_activated()) {
         $this->json_error('401', __('Your email needs to be verified. Go to your email inbox and find the message from us asking you to confirm your address. Or make sure your email address is entered correctly.', 'pnfw'));
     }
 }
 public function __construct()
 {
     parent::__construct(site_url('pnfw/categories/'));
     // Optional
     $timestamp = $this->opt_parameter('timestamp', FILTER_SANITIZE_NUMBER_INT);
     if ($timestamp == $this->get_last_modification_timestamp()) {
         $this->header_error('304');
     }
     switch ($this->get_method()) {
         case 'GET':
             $object_taxonomies = get_option('pnfw_enabled_object_taxonomies', array());
             $raw_terms = get_terms($object_taxonomies, array('hide_empty' => false));
             $categories = array();
             foreach ($raw_terms as $raw_term) {
                 // Mandatory fields
                 $category = array('id' => (int) $raw_term->term_id, 'name' => $raw_term->name);
                 // Optional fields
                 $description = $raw_term->description;
                 if (!empty($description)) {
                     $category['description'] = $description;
                 }
                 $category['exclude'] = $this->isCategoryExcluded(pnfw_get_normalized_term_id((int) $raw_term->term_id));
                 $categories[] = $category;
             }
             header('Content-Type: application/json');
             echo json_encode(array('categories' => $categories, 'timestamp' => $this->get_last_modification_timestamp()));
             break;
         case 'POST':
             $this->category_id = pnfw_get_normalized_term_id((int) $this->get_parameter('id', FILTER_SANITIZE_NUMBER_INT));
             $excluded = $this->get_parameter('exclude', FILTER_VALIDATE_BOOLEAN);
             $this->setCategoryExcluded($excluded);
             break;
         default:
             $this->json_error('401', __('Invalid HTTP method', 'pnfw'));
     }
     exit;
 }