$post_id,
'source' => $source,
'pubchem_cid' => $pubchem_cid,
);
// Allow filtering of template data before rendering.
$data = apply_filters( 'psa_template_data', $data, $post_id );
// Restore values from possibly filtered data.
$post_id = $data['post_id'] ?? $post_id;
$source = $data['source'] ?? $source;
$pubchem_cid = $data['pubchem_cid'] ?? $pubchem_cid;
$html = '
';
// Quick facts box.
$weight = get_post_meta( $post_id, 'psa_molecular_weight', true );
$formula = get_post_meta( $post_id, 'psa_molecular_formula', true );
$seq = get_post_meta( $post_id, 'psa_sequence', true );
$aliases = get_post_meta( $post_id, 'psa_aliases', true );
if ( $weight || $formula || $seq ) {
$html .= '
';
$html .= '
Quick Facts
';
$html .= '
';
if ( $aliases ) {
$html .= '| Also Known As | ' . esc_html( $aliases ) . ' |
';
}
if ( $seq ) {
$html .= '| Sequence | ' . esc_html( $seq ) . ' |
';
}
if ( $formula ) {
$html .= '| Molecular Formula | ' . esc_html( $formula ) . ' |
';
}
if ( $weight ) {
$html .= '| Molecular Weight | ' . esc_html( $weight ) . ' |
';
}
if ( $pubchem_cid ) {
$cid_int = intval( $pubchem_cid );
$html .= '| PubChem CID | ' . $cid_int . ' |
';
}
$html .= '
';
$html .= '
';
}
// Detailed sections.
$detail_fields = array(
'psa_mechanism' => 'Mechanism of Action',
'psa_research_apps' => 'Research Applications',
'psa_safety_profile' => 'Safety & Side Effects',
'psa_dosage_info' => 'Dosage Information',
'psa_references' => 'References',
);
foreach ( $detail_fields as $key => $label ) {
$value = get_post_meta( $post_id, $key, true );
if ( ! empty( $value ) ) {
$html .= '
';
$html .= '
' . esc_html( $label ) . '
';
$html .= '
' . wp_kses_post( wpautop( $value ) ) . '
';
$html .= '
';
}
}
// Source badge.
if ( $source && 'pending' !== $source ) {
$badges = array(
'ai-generated' => array(
'label' => 'AI-Generated Content',
'class' => 'psa-badge-ai',
),
'pubchem' => array(
'label' => 'PubChem Verified',
'class' => 'psa-badge-verified',
),
'manual' => array(
'label' => 'Manually Curated',
'class' => 'psa-badge-manual',
),
);
$badge = $badges[ $source ] ?? $badges['ai-generated'];
$html .= '
';
$html .= esc_html( $badge['label'] );
if ( 'ai-generated' === $source ) {
$html .= ' — This entry was automatically generated and may contain inaccuracies. Please verify critical information with primary sources.';
}
$html .= '
';
}
$html .= '
';
return $content . $html;
}
}