__('Certificate ID is required', 'academic-certificate-verification')));
}
$options = get_option('acceve_certificate_verification_options');
$enabled = ! empty($options['enable_date_of_birth']);
if ($enabled){
if (class_exists( 'ACCEVE_Academic_Certificate_Verification_Pro' )){
$certificate = $this->verify_certificate_with_birth_date($certificate_id, $birth_date);
}else{
wp_send_json_error(array('message' => 'Date is not required'));
}
}else{
$certificate = $this->verify_certificate($certificate_id);
}
if ($certificate && !is_string($certificate)) {
// Certificate is valid - generate HTML
ob_start();
$this->render_certificate_details($certificate);
$html = ob_get_clean();
wp_send_json_success(array('html' => $html, 'certificate' => $certificate));
} elseif ($certificate === 'expired') {
$html = '
' . esc_html__('This certificate has expired.', 'academic-certificate-verification') . '
' . esc_html__('If you believe this is an error, please contact the issuing institution.', 'academic-certificate-verification') . '
';
wp_send_json_error(array('message' => $html));
} elseif ($certificate === 'inactive') {
$html = '
' . esc_html__('This certificate is no longer valid.', 'academic-certificate-verification') . '
' . esc_html__('If you believe this is an error, please contact the issuing institution.', 'academic-certificate-verification') . '
';
wp_send_json_error(array('message' => $html));
} else {
$html = '
' . esc_html__('Certificate not found. Please check the ID and date of birth', 'academic-certificate-verification') . '
' . esc_html__('If you believe this is an error, please contact the issuing institution.', 'academic-certificate-verification') . '
';
wp_send_json_error(array('message' => $html));
}
}
/**
* Render certificate details HTML.
*
* @param object $certificate Certificate object.
* @return void
* @since 1.0.0
*/
private function render_certificate_details($certificate) {
?>
certificate_id); ?>
student_name); ?>
course_name)) : ?>
course_name); ?>
issue_date)) : ?>
issue_date))); ?>
expiry_date)) : ?>
expiry_date))); ?>
grade)) : ?>
grade); ?>
institution)) : ?>
institution); ?>
student_email)) : ?>
student_email); ?>
duration)) : ?>
duration); ?>
description)) : ?>
description); ?>
get_certificate_with_date($certificate_id, $birth_date);
if (!$certificate) {
return false;
}
if ($certificate->expiry_date && strtotime($certificate->expiry_date) < time()) {
return 'expired';
}
if (!$certificate->is_active) {
return 'inactive';
}
return $certificate;
}
/**
* Verify certificate status for display.
*
* Checks whether a certificate exists and determines its current status:
* - Returns the certificate object if it is valid and active
* - Returns 'expired' if the certificate has passed its expiry date
* - Returns 'inactive' if the certificate is disabled
* - Returns false if the certificate does not exist or verification fails
*
* @since 1.0.0
*
* @param string|int $certificate_id Certificate ID to verify.
* @param string $verification_code Optional verification code.
*
* @return object|string|false Certificate object on success,
* 'expired' if expired,
* 'inactive' if inactive,
* false if not found or invalid.
*/
public function verify_certificate($certificate_id, $verification_code = '') {
$db = ACCEVE_Certificate_Verification_Database::get_instance();
$certificate = $db->get_certificate($certificate_id, $verification_code);
if (!$certificate) {
return false;
}
if ($certificate->expiry_date && strtotime($certificate->expiry_date) < time()) {
return 'expired';
}
if (!$certificate->is_active) {
return 'inactive';
}
return $certificate;
}
}