/* =========================================================
RECRUITMENT HERO
FORM RECIPIENTS
========================================================= */
function rh_get_form_recipients() {
return array(
'moe@sentrixmedia.com',
'habib@sentrixmedia.com',
);
}
/* =========================================================
GET VISITOR IP
========================================================= */
function rh_get_visitor_ip() {
if (!empty($_SERVER['REMOTE_ADDR'])) {
return sanitize_text_field(
wp_unslash($_SERVER['REMOTE_ADDR'])
);
}
return 'unknown';
}
/* =========================================================
BASIC RATE LIMIT
========================================================= */
function rh_check_form_rate_limit($form_name) {
$ip = rh_get_visitor_ip();
$rate_key =
'rh_' .
sanitize_key($form_name) .
'_' .
md5($ip);
$count =
(int) get_transient($rate_key);
/*
* Max 5 submissions
* per 10 minutes per IP.
*/
if ($count >= 5) {
return new WP_Error(
'rh_rate_limit',
'Too many submissions. Please wait a few minutes and try again.',
array(
'status' => 429,
)
);
}
set_transient(
$rate_key,
$count + 1,
10 * MINUTE_IN_SECONDS
);
return true;
}
/* =========================================================
CONTACT FORM REST API
========================================================= */
add_action('rest_api_init', function () {
register_rest_route(
'recruitment-hero/v1',
'/contact',
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'rh_handle_contact_submission',
'permission_callback' => '__return_true',
)
);
});
/* =========================================================
CONTACT FORM HANDLER
========================================================= */
function rh_handle_contact_submission(
WP_REST_Request $request
) {
/* -----------------------------------------------------
GET DATA
----------------------------------------------------- */
$data =
$request->get_json_params();
if (!is_array($data)) {
$data =
$request->get_params();
}
/* -----------------------------------------------------
HONEYPOT
----------------------------------------------------- */
$website =
isset($data['website'])
? sanitize_text_field(
wp_unslash($data['website'])
)
: '';
if (!empty($website)) {
return new WP_REST_Response(
array(
'success' => true,
'message' =>
'Your message has been sent successfully.',
),
200
);
}
/* -----------------------------------------------------
SANITIZE
----------------------------------------------------- */
$first_name =
isset($data['first_name'])
? sanitize_text_field(
wp_unslash($data['first_name'])
)
: '';
$last_name =
isset($data['last_name'])
? sanitize_text_field(
wp_unslash($data['last_name'])
)
: '';
$email =
isset($data['email'])
? sanitize_email(
wp_unslash($data['email'])
)
: '';
$phone =
isset($data['phone'])
? sanitize_text_field(
wp_unslash($data['phone'])
)
: '';
$organization =
isset($data['organization'])
? sanitize_text_field(
wp_unslash($data['organization'])
)
: '';
$help_type =
isset($data['help_type'])
? sanitize_key(
wp_unslash($data['help_type'])
)
: '';
$message =
isset($data['message'])
? sanitize_textarea_field(
wp_unslash($data['message'])
)
: '';
/* -----------------------------------------------------
VALIDATION
----------------------------------------------------- */
if (
empty($first_name) ||
empty($last_name) ||
empty($email) ||
empty($help_type) ||
empty($message)
) {
return new WP_Error(
'rh_required_fields',
'Please complete all required fields.',
array(
'status' => 422,
)
);
}
if (!is_email($email)) {
return new WP_Error(
'rh_invalid_email',
'Please enter a valid email address.',
array(
'status' => 422,
)
);
}
/* -----------------------------------------------------
VALID INQUIRY TYPES
----------------------------------------------------- */
$allowed_help_types = array(
'demo' =>
'Request a Demo',
'support' =>
'Product Support',
'partnership' =>
'Partnership Opportunity',
'general' =>
'General Question',
);
if (
!isset(
$allowed_help_types[$help_type]
)
) {
return new WP_Error(
'rh_invalid_help_type',
'Please select a valid inquiry type.',
array(
'status' => 422,
)
);
}
$help_label =
$allowed_help_types[$help_type];
/* -----------------------------------------------------
RATE LIMIT
----------------------------------------------------- */
$rate_limit =
rh_check_form_rate_limit(
'contact'
);
if (is_wp_error($rate_limit)) {
return $rate_limit;
}
/* -----------------------------------------------------
EMAIL
----------------------------------------------------- */
$recipients =
rh_get_form_recipients();
$subject =
sprintf(
'[Recruitment Hero] New Contact Inquiry - %s',
$help_label
);
$submitted_at =
current_time(
'F j, Y - g:i A'
);
$email_body = '
RECRUITMENT HERO
New Contact Inquiry
A new Contact Us form submission has been
received through the Recruitment Hero website.
|
Name
|
'
.
esc_html(
$first_name .
' ' .
$last_name
)
.
' |
|
Email
|
'
.
esc_html($email)
.
'
|
|
Phone
|
'
.
esc_html(
$phone
?: 'Not provided'
)
.
' |
|
Organization
|
'
.
esc_html(
$organization
?: 'Not provided'
)
.
' |
|
Inquiry Type
|
'
.
esc_html(
$help_label
)
.
' |
|
Submitted
|
'
.
esc_html(
$submitted_at
)
.
' |
Message
'
.
nl2br(
esc_html($message)
)
.
'
Reply directly to this email to contact
' .
esc_html($first_name) .
' at ' .
esc_html($email) .
'.
';
$headers = array(
'Content-Type: text/html; charset=UTF-8',
sprintf(
'Reply-To: %s %s <%s>',
$first_name,
$last_name,
$email
),
);
$sent =
wp_mail(
$recipients,
$subject,
$email_body,
$headers
);
if (!$sent) {
return new WP_Error(
'rh_email_failed',
'Your message could not be sent right now. Please try again shortly.',
array(
'status' => 500,
)
);
}
return new WP_REST_Response(
array(
'success' => true,
'message' =>
'Your message has been sent successfully. Our team will get back to you shortly.',
),
200
);
}
/* =========================================================
REQUEST DEMO REST API
========================================================= */
add_action('rest_api_init', function () {
register_rest_route(
'recruitment-hero/v1',
'/demo',
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => 'rh_handle_demo_request',
'permission_callback' => '__return_true',
)
);
});
/* =========================================================
REQUEST DEMO HANDLER
========================================================= */
function rh_handle_demo_request(
WP_REST_Request $request
) {
/* -----------------------------------------------------
GET DATA
----------------------------------------------------- */
$data =
$request->get_json_params();
if (!is_array($data)) {
$data =
$request->get_params();
}
/* -----------------------------------------------------
HONEYPOT
----------------------------------------------------- */
$website =
isset($data['website'])
? sanitize_text_field(
wp_unslash($data['website'])
)
: '';
if (!empty($website)) {
return new WP_REST_Response(
array(
'success' => true,
'message' =>
'Thank you! Your demo request has been submitted successfully.',
),
200
);
}
/* -----------------------------------------------------
SANITIZE
----------------------------------------------------- */
$first_name =
isset($data['first_name'])
? sanitize_text_field(
wp_unslash($data['first_name'])
)
: '';
$last_name =
isset($data['last_name'])
? sanitize_text_field(
wp_unslash($data['last_name'])
)
: '';
$email =
isset($data['email'])
? sanitize_email(
wp_unslash($data['email'])
)
: '';
$phone =
isset($data['phone'])
? sanitize_text_field(
wp_unslash($data['phone'])
)
: '';
$organization =
isset($data['organization'])
? sanitize_text_field(
wp_unslash($data['organization'])
)
: '';
$role =
isset($data['role'])
? sanitize_key(
wp_unslash($data['role'])
)
: '';
$team_size =
isset($data['team_size'])
? sanitize_text_field(
wp_unslash($data['team_size'])
)
: '';
$message =
isset($data['message'])
? sanitize_textarea_field(
wp_unslash($data['message'])
)
: '';
/* -----------------------------------------------------
REQUIRED FIELDS
----------------------------------------------------- */
if (
empty($first_name) ||
empty($last_name) ||
empty($email) ||
empty($organization) ||
empty($role)
) {
return new WP_Error(
'rh_missing_fields',
'Please complete all required fields.',
array(
'status' => 422,
)
);
}
if (!is_email($email)) {
return new WP_Error(
'rh_invalid_email',
'Please enter a valid email address.',
array(
'status' => 422,
)
);
}
/* -----------------------------------------------------
VALID ROLES
----------------------------------------------------- */
$allowed_roles = array(
'physician' =>
'Physician / Doctor',
'research-site' =>
'Research Site',
'coordinator' =>
'Clinical Research Coordinator',
'sponsor-cro' =>
'Sponsor / CRO',
'operations' =>
'Research Operations',
'other' =>
'Other',
);
if (
!isset(
$allowed_roles[$role]
)
) {
return new WP_Error(
'rh_invalid_role',
'Please select a valid role.',
array(
'status' => 422,
)
);
}
$role_label =
$allowed_roles[$role];
/* -----------------------------------------------------
TEAM SIZE
----------------------------------------------------- */
$allowed_team_sizes = array(
'' =>
'Not provided',
'1-5' =>
'1-5',
'6-20' =>
'6-20',
'21-50' =>
'21-50',
'51-plus' =>
'51+',
);
if (
!array_key_exists(
$team_size,
$allowed_team_sizes
)
) {
return new WP_Error(
'rh_invalid_team_size',
'Please select a valid team size.',
array(
'status' => 422,
)
);
}
$team_size_label =
$allowed_team_sizes[$team_size];
/* -----------------------------------------------------
RATE LIMIT
----------------------------------------------------- */
$rate_limit =
rh_check_form_rate_limit(
'demo'
);
if (is_wp_error($rate_limit)) {
return $rate_limit;
}
/* -----------------------------------------------------
EMAIL
----------------------------------------------------- */
$recipients =
rh_get_form_recipients();
$subject =
sprintf(
'[Recruitment Hero] New Demo Request - %s %s - %s',
$first_name,
$last_name,
$organization
);
$submitted_at =
current_time(
'F j, Y - g:i A'
);
$email_body = '
RECRUITMENT HERO
New Demo Request
A new Request a Demo form has been
submitted through the Recruitment Hero website.
|
Name
|
'
.
esc_html(
$first_name .
' ' .
$last_name
)
.
' |
|
Work Email
|
'
.
esc_html($email)
.
'
|
|
Phone
|
'
.
esc_html(
$phone
?: 'Not provided'
)
.
' |
|
Organization
|
'
.
esc_html(
$organization
)
.
' |
|
Role
|
'
.
esc_html(
$role_label
)
.
' |
|
Team Size
|
'
.
esc_html(
$team_size_label
)
.
' |
|
Submitted
|
'
.
esc_html(
$submitted_at
)
.
' |
What would they like to learn about?
'
.
(
!empty($message)
? nl2br(
esc_html($message)
)
: 'No additional message provided.'
)
.
'
Reply directly to this email to contact
' .
esc_html($first_name) .
' at ' .
esc_html($email) .
'.
';
$headers = array(
'Content-Type: text/html; charset=UTF-8',
sprintf(
'Reply-To: %s %s <%s>',
$first_name,
$last_name,
$email
),
);
$sent =
wp_mail(
$recipients,
$subject,
$email_body,
$headers
);
if (!$sent) {
return new WP_Error(
'rh_mail_failed',
'Your demo request could not be sent right now. Please try again.',
array(
'status' => 500,
)
);
}
return new WP_REST_Response(
array(
'success' => true,
'message' =>
'Thank you! Your demo request has been submitted successfully. Our team will contact you soon.',
),
200
);
}
/* =========================================================
EMAIL TABLE STYLES
========================================================= */
function rh_email_label_style() {
return '
width:145px;
padding:11px 12px;
border-bottom:1px solid #edf1f5;
background:#f8fbfe;
color:#082d75;
font-weight:600;
vertical-align:top;
';
}
function rh_email_value_style() {
return '
padding:11px 12px;
border-bottom:1px solid #edf1f5;
color:#52657f;
vertical-align:top;
';
}
Page not found – Recruitment Hero
Skip to content
It looks like the link pointing here was faulty. Maybe try searching?