HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_email_subscribe.php
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include_once '../../../../wp-config.php';


if (is_user_logged_in()) {

    global $current_user;
    $user_id = $current_user->ID;

    global $wpdb;

    date_default_timezone_set("Asia/Calcutta");
    $curDateTime = date('Y-m-d H:i:s'); // add 5 hrs 30 min in curr time

    $PSY_SUBSCRIBE_MAIL = $wpdb->prefix . PSY_SUBSCRIBE_MAIL;

    $email_get = $_REQUEST['email'];

    if (filter_var($email_get, FILTER_VALIDATE_EMAIL)) {

        $ExistEmail = $wpdb->get_var("SELECT count(email_id) FROM $PSY_SUBSCRIBE_MAIL WHERE email_id='$email_get'");
        if ($email_get == "") {
            $array[] = array("status" => "0", "message" => "Enter Email Address.");
        } else  if (!preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $email_get)) {
            $array = array('status' => 0, 'msg' => 'Invalid email address');
        } else if ($ExistEmail > 0) {
            $array[] = array("status" => "0", "message" => "Email Address Already Exists.");
        } else {
            $subscribeQuery = "INSERT INTO $PSY_SUBSCRIBE_MAIL SET user_id='$user_id', email_id='$email_get',status='1', added_date='$curDateTime'";
            if ($wpdb->query($subscribeQuery)) {
                $array[] = array("status" => "1", "message" => "Sucessfully Subscribed.");
            } else {
                $array[] = array("status" => "0", "message" => "Something went wrong,Please try again later");
            }
        }
    } else {
        $array[] = array("status" => "0", "message" => "Something went wrong,Please try again later");
    }
} else {
    $array[] = array("status" => "0", "message" => "Please logged in to subscribe");
}


echo json_encode($array);