$post_id, 'source' => $source, 'pubchem_cid' => $pubchem_cid, ); $data = apply_filters( 'psa_template_data', $data, $post_id ); $post_id = $data['post_id'] ?? $post_id; $source = $data['source'] ?? $source; $pubchem_cid = $data['pubchem_cid'] ?? $pubchem_cid; $html = '
'; // Quick facts box. $html .= self::render_quick_facts( $post_id, $pubchem_cid ); // Extended research data box (half-life, stability, storage, etc.). $html .= self::render_extended_data( $post_id ); // Detailed sections. $html .= self::render_detail_sections( $post_id ); // Source badge. $html .= self::render_source_badge( $source ); // Integration hook: allow Peptide Community and other plugins to append content. ob_start(); do_action( 'psa_after_peptide_detail', $post_id ); $html .= ob_get_clean(); $html .= '
'; return $content . $html; } /** * Render the quick facts table. * * @param int $post_id Post ID. * @param string $pubchem_cid PubChem CID (may be empty). * @return string HTML. */ private static function render_quick_facts( int $post_id, string $pubchem_cid ): string { $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 ) { return ''; } $html = '
'; $html .= '

Quick Facts

'; $html .= ''; if ( $aliases ) { $html .= ''; } if ( $seq ) { $html .= ''; } if ( $formula ) { $html .= ''; } if ( $weight ) { $html .= ''; } if ( $pubchem_cid ) { $cid_int = intval( $pubchem_cid ); $html .= ''; } $html .= '
Also Known As' . esc_html( $aliases ) . '
Sequence' . esc_html( $seq ) . '
Molecular Formula' . esc_html( $formula ) . '
Molecular Weight' . esc_html( $weight ) . '
PubChem CID' . $cid_int . '
'; return $html; } /** * Render the extended research data table (v4.3.0 fields). * * @param int $post_id Post ID. * @return string HTML (empty string if no extended data). */ private static function render_extended_data( int $post_id ): string { $fields = array( 'psa_half_life' => 'Half-Life', 'psa_stability' => 'Stability', 'psa_solubility' => 'Solubility', 'psa_vial_size_mg' => 'Vial Size', 'psa_storage_lyophilized' => 'Storage (Lyophilized)', 'psa_storage_reconstituted' => 'Storage (Reconstituted)', 'psa_typical_dose_mcg' => 'Typical Research Dose', 'psa_cycle_parameters' => 'Cycle Parameters', 'psa_amino_acid_count' => 'Amino Acid Count', ); $rows = ''; foreach ( $fields as $key => $label ) { $value = get_post_meta( $post_id, $key, true ); if ( ! empty( $value ) ) { $display = $value; if ( 'psa_vial_size_mg' === $key ) { $display = floatval( $value ) . ' mg'; } $rows .= '' . esc_html( $label ) . '' . esc_html( $display ) . ''; } } if ( empty( $rows ) ) { return ''; } return '
' . '

Research Parameters

' . '' . $rows . '
' . '
'; } /** * Render detailed text sections (mechanism, research apps, safety, etc.). * * @param int $post_id Post ID. * @return string HTML. */ private static function render_detail_sections( int $post_id ): string { $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', ); $html = ''; 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 .= '
'; } } return $html; } /** * Render the source badge. * * @param string $source The data source value. * @return string HTML (empty if source is empty or 'pending'). */ private static function render_source_badge( string $source ): string { if ( ! $source || 'pending' === $source ) { return ''; } $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 .= '
'; return $html; } }