style: fix WPCS tab indentation in pubchem, error, post-type, template classes

This commit is contained in:
peptiderepo
2026-04-08 18:44:45 +07:00
parent 0a2d7aeb4a
commit 5e0830a744
3 changed files with 317 additions and 317 deletions

View File

@@ -6,57 +6,57 @@
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
class PSA_Post_Type { class PSA_Post_Type {
/** Meta field keys used throughout the plugin. */ /** Meta field keys used throughout the plugin. */
const META_FIELDS = array( const META_FIELDS = array(
'psa_sequence' => 'Amino Acid Sequence', 'psa_sequence' => 'Amino Acid Sequence',
'psa_molecular_weight' => 'Molecular Weight', 'psa_molecular_weight' => 'Molecular Weight',
'psa_molecular_formula' => 'Molecular Formula', 'psa_molecular_formula' => 'Molecular Formula',
'psa_aliases' => 'Aliases / Synonyms', 'psa_aliases' => 'Aliases / Synonyms',
'psa_mechanism' => 'Mechanism of Action', 'psa_mechanism' => 'Mechanism of Action',
'psa_research_apps' => 'Research Applications', 'psa_research_apps' => 'Research Applications',
'psa_safety_profile' => 'Safety & Side Effects', 'psa_safety_profile' => 'Safety & Side Effects',
'psa_dosage_info' => 'Dosage Information', 'psa_dosage_info' => 'Dosage Information',
'psa_references' => 'References & Citations', 'psa_references' => 'References & Citations',
'psa_source' => 'Data Source', 'psa_source' => 'Data Source',
'psa_pubchem_cid' => 'PubChem CID', 'psa_pubchem_cid' => 'PubChem CID',
); );
/** /**
* Register admin-only hooks (meta boxes, save). * Register admin-only hooks (meta boxes, save).
*/ */
public static function init_admin() { public static function init_admin() {
add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) ); add_action( 'add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ) );
add_action( 'save_post_peptide', array( __CLASS__, 'save_meta' ) ); add_action( 'save_post_peptide', array( __CLASS__, 'save_meta' ) );
} }
/** /**
* Register the peptide CPT. * Register the peptide CPT.
*/ */
public static function register_peptide_post_type() { public static function register_peptide_post_type() {
if ( post_type_exists( 'peptide' ) ) { if ( post_type_exists( 'peptide' ) ) {
return; return;
} }
$labels = array( $labels = array(
'name' => 'Peptides', 'name' => 'Peptides',
'singular_name' => 'Peptide', 'singular_name' => 'Peptide',
'menu_name' => 'Peptides', 'menu_name' => 'Peptides',
'add_new' => 'Add Peptide', 'add_new' => 'Add Peptide',
'add_new_item' => 'Add New Peptide', 'add_new_item' => 'Add New Peptide',
'edit_item' => 'Edit Peptide', 'edit_item' => 'Edit Peptide',
'new_item' => 'New Peptide', 'new_item' => 'New Peptide',
'view_item' => 'View Peptide', 'view_item' => 'View Peptide',
'search_items' => 'Search Peptides', 'search_items' => 'Search Peptides',
'not_found' => 'No peptides found', 'not_found' => 'No peptides found',
'not_found_in_trash' => 'No peptides found in Trash', 'not_found_in_trash' => 'No peptides found in Trash',
); );
register_post_type( register_post_type(
'peptide', 'peptide',
array( array(
'labels' => $labels, 'labels' => $labels,
@@ -70,89 +70,89 @@ class PSA_Post_Type {
'hierarchical' => false, 'hierarchical' => false,
) )
); );
} }
/** /**
* Add meta boxes to the peptide editor. * Add meta boxes to the peptide editor.
*/ */
public static function add_meta_boxes() { public static function add_meta_boxes() {
add_meta_box( add_meta_box(
'psa_peptide_data', 'psa_peptide_data',
'Peptide Scientific Data', 'Peptide Scientific Data',
array( __CLASS__, 'render_meta_box' ), array( __CLASS__, 'render_meta_box' ),
'peptide', 'peptide',
'normal', 'normal',
'high' 'high'
); );
} }
/** /**
* Render the meta box fields. * Render the meta box fields.
* *
* @param WP_Post $post The current post object. * @param WP_Post $post The current post object.
*/ */
public static function render_meta_box( $post ) { public static function render_meta_box( $post ) {
wp_nonce_field( 'psa_save_meta', 'psa_meta_nonce' ); wp_nonce_field( 'psa_save_meta', 'psa_meta_nonce' );
$textarea_fields = array( $textarea_fields = array(
'psa_sequence', 'psa_mechanism', 'psa_research_apps', 'psa_sequence', 'psa_mechanism', 'psa_research_apps',
'psa_safety_profile', 'psa_dosage_info', 'psa_references', 'psa_safety_profile', 'psa_dosage_info', 'psa_references',
); );
echo '<table class="form-table">'; echo '<table class="form-table">';
foreach ( self::META_FIELDS as $key => $label ) { foreach ( self::META_FIELDS as $key => $label ) {
$value = get_post_meta( $post->ID, $key, true ); $value = get_post_meta( $post->ID, $key, true );
echo '<tr>'; echo '<tr>';
echo '<th><label for="' . esc_attr( $key ) . '">' . esc_html( $label ) . '</label></th>'; echo '<th><label for="' . esc_attr( $key ) . '">' . esc_html( $label ) . '</label></th>';
echo '<td>'; echo '<td>';
if ( $key === 'psa_source' ) { if ( $key === 'psa_source' ) {
$options = array( $options = array(
'' => '— Select —', '' => '— Select —',
'ai-generated' => 'AI Generated', 'ai-generated' => 'AI Generated',
'pubchem' => 'PubChem Verified', 'pubchem' => 'PubChem Verified',
'manual' => 'Manual Entry', 'manual' => 'Manual Entry',
'pending' => 'Pending Generation', 'pending' => 'Pending Generation',
); );
echo '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '">'; echo '<select name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '">';
foreach ( $options as $opt_val => $opt_label ) { foreach ( $options as $opt_val => $opt_label ) {
echo '<option value="' . esc_attr( $opt_val ) . '"' . selected( $value, $opt_val, false ) . '>' . esc_html( $opt_label ) . '</option>'; echo '<option value="' . esc_attr( $opt_val ) . '"' . selected( $value, $opt_val, false ) . '>' . esc_html( $opt_label ) . '</option>';
} }
echo '</select>'; echo '</select>';
} elseif ( in_array( $key, $textarea_fields, true ) ) { } elseif ( in_array( $key, $textarea_fields, true ) ) {
echo '<textarea name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" rows="4" class="large-text">' . esc_textarea( $value ) . '</textarea>'; echo '<textarea name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" rows="4" class="large-text">' . esc_textarea( $value ) . '</textarea>';
} else { } else {
echo '<input type="text" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" class="regular-text" />'; echo '<input type="text" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" value="' . esc_attr( $value ) . '" class="regular-text" />';
} }
echo '</td></tr>'; echo '</td></tr>';
} }
echo '</table>'; echo '</table>';
} }
/** /**
* Save meta field values. * Save meta field values.
* *
* @param int $post_id The post ID. * @param int $post_id The post ID.
*/ */
public static function save_meta( $post_id ) { public static function save_meta( $post_id ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
if ( ! isset( $_POST['psa_meta_nonce'] ) || if ( ! isset( $_POST['psa_meta_nonce'] ) ||
! wp_verify_nonce( wp_unslash( $_POST['psa_meta_nonce'] ), 'psa_save_meta' ) ) { ! wp_verify_nonce( wp_unslash( $_POST['psa_meta_nonce'] ), 'psa_save_meta' ) ) {
return; return;
} }
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return; return;
} }
if ( ! current_user_can( 'edit_post', $post_id ) ) { if ( ! current_user_can( 'edit_post', $post_id ) ) {
return; return;
} }
foreach ( self::META_FIELDS as $key => $label ) { foreach ( self::META_FIELDS as $key => $label ) {
if ( isset( $_POST[ $key ] ) ) { if ( isset( $_POST[ $key ] ) ) {
$value = sanitize_textarea_field( wp_unslash( $_POST[ $key ] ) ); $value = sanitize_textarea_field( wp_unslash( $_POST[ $key ] ) );
update_post_meta( $post_id, $key, $value ); update_post_meta( $post_id, $key, $value );
} }
} }
} }
} }

View File

@@ -6,82 +6,82 @@
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
class PSA_PubChem { class PSA_PubChem {
const API_BASE = 'https://pubchem.ncbi.nlm.nih.gov/rest/pug'; const API_BASE = 'https://pubchem.ncbi.nlm.nih.gov/rest/pug';
/** /**
* Look up a peptide/compound by name and return molecular properties. * Look up a peptide/compound by name and return molecular properties.
* Results are cached in transients to respect PubChem rate limits. * Results are cached in transients to respect PubChem rate limits.
* *
* @param string $name Peptide or compound name. * @param string $name Peptide or compound name.
* @return array|WP_Error|null Array of properties, WP_Error on failure, or null if not found. * @return array|WP_Error|null Array of properties, WP_Error on failure, or null if not found.
*/ */
public static function lookup( $name ) { public static function lookup( $name ) {
$options = get_option( 'psa_settings', array() ); $options = get_option( 'psa_settings', array() );
$use_pubchem = $options['use_pubchem'] ?? '1'; $use_pubchem = $options['use_pubchem'] ?? '1';
if ( '1' !== $use_pubchem ) { if ( '1' !== $use_pubchem ) {
return null; return null;
} }
// Check cache first (respect PubChem's 5 req/sec limit). // Check cache first (respect PubChem's 5 req/sec limit).
$cache_key = 'psa_pubchem_' . md5( strtolower( trim( $name ) ) ); $cache_key = 'psa_pubchem_' . md5( strtolower( trim( $name ) ) );
$cached = get_transient( $cache_key ); $cached = get_transient( $cache_key );
if ( false !== $cached ) { if ( false !== $cached ) {
// We store 'not_found' string to differentiate from cache miss. // We store 'not_found' string to differentiate from cache miss.
if ( 'not_found' === $cached ) { if ( 'not_found' === $cached ) {
return null; return null;
} }
if ( is_wp_error( $cached ) ) { if ( is_wp_error( $cached ) ) {
return $cached; return $cached;
} }
return $cached; return $cached;
} }
// Step 1: Get the CID by compound name. // Step 1: Get the CID by compound name.
$cid = self::get_cid_by_name( $name ); $cid = self::get_cid_by_name( $name );
if ( is_wp_error( $cid ) ) { if ( is_wp_error( $cid ) ) {
set_transient( $cache_key, $cid, 1 * HOUR_IN_SECONDS ); set_transient( $cache_key, $cid, 1 * HOUR_IN_SECONDS );
return $cid; return $cid;
} }
if ( ! $cid ) { if ( ! $cid ) {
set_transient( $cache_key, 'not_found', 12 * HOUR_IN_SECONDS ); set_transient( $cache_key, 'not_found', 12 * HOUR_IN_SECONDS );
return null; return null;
} }
// Step 2: Get properties by CID. // Step 2: Get properties by CID.
$properties = self::get_properties( $cid ); $properties = self::get_properties( $cid );
if ( is_wp_error( $properties ) ) { if ( is_wp_error( $properties ) ) {
set_transient( $cache_key, $properties, 1 * HOUR_IN_SECONDS ); set_transient( $cache_key, $properties, 1 * HOUR_IN_SECONDS );
return $properties; return $properties;
} }
if ( ! $properties ) { if ( ! $properties ) {
set_transient( $cache_key, 'not_found', 12 * HOUR_IN_SECONDS ); set_transient( $cache_key, 'not_found', 12 * HOUR_IN_SECONDS );
return null; return null;
} }
$properties['cid'] = $cid; $properties['cid'] = $cid;
// Cache successful lookups for 7 days. // Cache successful lookups for 7 days.
set_transient( $cache_key, $properties, PSA_Config::PUBCHEM_CACHE_TTL ?: 7 * DAY_IN_SECONDS ); set_transient( $cache_key, $properties, PSA_Config::PUBCHEM_CACHE_TTL ?: 7 * DAY_IN_SECONDS );
return $properties; return $properties;
} }
/** /**
* Get PubChem Compound ID (CID) by name. * Get PubChem Compound ID (CID) by name.
* *
* @param string $name Compound name. * @param string $name Compound name.
* @return int|WP_Error|null CID, WP_Error on API failure, or null if not found. * @return int|WP_Error|null CID, WP_Error on API failure, or null if not found.
*/ */
private static function get_cid_by_name( $name ) { private static function get_cid_by_name( $name ) {
$url = self::API_BASE . '/compound/name/' . rawurlencode( $name ) . '/cids/JSON'; $url = self::API_BASE . '/compound/name/' . rawurlencode( $name ) . '/cids/JSON';
$response = wp_remote_get( $response = wp_remote_get(
$url, $url,
array( array(
'timeout' => 15, 'timeout' => 15,
@@ -89,33 +89,33 @@ class PSA_PubChem {
) )
); );
if ( is_wp_error( $response ) ) { if ( is_wp_error( $response ) ) {
return new WP_Error( 'pubchem_api_error', 'PubChem API request failed: ' . $response->get_error_message() ); return new WP_Error( 'pubchem_api_error', 'PubChem API request failed: ' . $response->get_error_message() );
} }
$code = wp_remote_retrieve_response_code( $response ); $code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $code ) { if ( 200 !== $code ) {
return new WP_Error( 'pubchem_http_error', 'PubChem returned HTTP ' . $code ); return new WP_Error( 'pubchem_http_error', 'PubChem returned HTTP ' . $code );
} }
$body = json_decode( wp_remote_retrieve_body( $response ), true ); $body = json_decode( wp_remote_retrieve_body( $response ), true );
return isset( $body['IdentifierList']['CID'][0] ) return isset( $body['IdentifierList']['CID'][0] )
? (int) $body['IdentifierList']['CID'][0] ? (int) $body['IdentifierList']['CID'][0]
: null; : null;
} }
/** /**
* Get molecular properties for a given CID. * Get molecular properties for a given CID.
* *
* @param int $cid PubChem Compound ID. * @param int $cid PubChem Compound ID.
* @return array|WP_Error|null Properties array, WP_Error on failure, or null if not found. * @return array|WP_Error|null Properties array, WP_Error on failure, or null if not found.
*/ */
private static function get_properties( $cid ) { private static function get_properties( $cid ) {
$props = 'MolecularFormula,MolecularWeight,IUPACName,CanonicalSMILES,InChI'; $props = 'MolecularFormula,MolecularWeight,IUPACName,CanonicalSMILES,InChI';
$url = self::API_BASE . '/compound/cid/' . (int) $cid . '/property/' . $props . '/JSON'; $url = self::API_BASE . '/compound/cid/' . (int) $cid . '/property/' . $props . '/JSON';
$response = wp_remote_get( $response = wp_remote_get(
$url, $url,
array( array(
'timeout' => 15, 'timeout' => 15,
@@ -123,29 +123,29 @@ class PSA_PubChem {
) )
); );
if ( is_wp_error( $response ) ) { if ( is_wp_error( $response ) ) {
return new WP_Error( 'pubchem_api_error', 'PubChem API request failed: ' . $response->get_error_message() ); return new WP_Error( 'pubchem_api_error', 'PubChem API request failed: ' . $response->get_error_message() );
} }
$code = wp_remote_retrieve_response_code( $response ); $code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $code ) { if ( 200 !== $code ) {
return new WP_Error( 'pubchem_http_error', 'PubChem returned HTTP ' . $code ); return new WP_Error( 'pubchem_http_error', 'PubChem returned HTTP ' . $code );
} }
$body = json_decode( wp_remote_retrieve_body( $response ), true ); $body = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! isset( $body['PropertyTable']['Properties'][0] ) ) { if ( ! isset( $body['PropertyTable']['Properties'][0] ) ) {
return null; return null;
} }
$p = $body['PropertyTable']['Properties'][0]; $p = $body['PropertyTable']['Properties'][0];
return array( return array(
'molecular_formula' => $p['MolecularFormula'] ?? '', 'molecular_formula' => $p['MolecularFormula'] ?? '',
'molecular_weight' => isset( $p['MolecularWeight'] ) ? $p['MolecularWeight'] . ' Da' : '', 'molecular_weight' => isset( $p['MolecularWeight'] ) ? $p['MolecularWeight'] . ' Da' : '',
'iupac_name' => $p['IUPACName'] ?? '', 'iupac_name' => $p['IUPACName'] ?? '',
'smiles' => $p['CanonicalSMILES'] ?? '', 'smiles' => $p['CanonicalSMILES'] ?? '',
'inchi' => $p['InChI'] ?? '', 'inchi' => $p['InChI'] ?? '',
); );
} }
} }

View File

@@ -6,117 +6,117 @@
*/ */
if ( ! defined( 'ABSPATH' ) ) { if ( ! defined( 'ABSPATH' ) ) {
exit; exit;
} }
class PSA_Template { class PSA_Template {
public static function init() { public static function init() {
add_filter( 'the_content', array( __CLASS__, 'append_peptide_data' ) ); add_filter( 'the_content', array( __CLASS__, 'append_peptide_data' ) );
} }
/** /**
* Append structured peptide data below the post content on single peptide pages. * Append structured peptide data below the post content on single peptide pages.
* *
* @param string $content The post content. * @param string $content The post content.
* @return string Modified content. * @return string Modified content.
*/ */
public static function append_peptide_data( $content ) { public static function append_peptide_data( $content ) {
if ( ! is_singular( 'peptide' ) || ! in_the_loop() || ! is_main_query() ) { if ( ! is_singular( 'peptide' ) || ! in_the_loop() || ! is_main_query() ) {
return $content; return $content;
} }
$post_id = get_the_ID(); $post_id = get_the_ID();
$source = get_post_meta( $post_id, 'psa_source', true ); $source = get_post_meta( $post_id, 'psa_source', true );
$pubchem_cid = get_post_meta( $post_id, 'psa_pubchem_cid', true ); $pubchem_cid = get_post_meta( $post_id, 'psa_pubchem_cid', true );
// Build template data for filtering. // Build template data for filtering.
$data = array( $data = array(
'post_id' => $post_id, 'post_id' => $post_id,
'source' => $source, 'source' => $source,
'pubchem_cid' => $pubchem_cid, 'pubchem_cid' => $pubchem_cid,
); );
// Allow filtering of template data before rendering. // Allow filtering of template data before rendering.
$data = apply_filters( 'psa_template_data', $data, $post_id ); $data = apply_filters( 'psa_template_data', $data, $post_id );
// Restore values from possibly filtered data. // Restore values from possibly filtered data.
$post_id = $data['post_id'] ?? $post_id; $post_id = $data['post_id'] ?? $post_id;
$source = $data['source'] ?? $source; $source = $data['source'] ?? $source;
$pubchem_cid = $data['pubchem_cid'] ?? $pubchem_cid; $pubchem_cid = $data['pubchem_cid'] ?? $pubchem_cid;
$html = '<div class="psa-peptide-data">'; $html = '<div class="psa-peptide-data">';
// Quick facts box. // Quick facts box.
$weight = get_post_meta( $post_id, 'psa_molecular_weight', true ); $weight = get_post_meta( $post_id, 'psa_molecular_weight', true );
$formula = get_post_meta( $post_id, 'psa_molecular_formula', true ); $formula = get_post_meta( $post_id, 'psa_molecular_formula', true );
$seq = get_post_meta( $post_id, 'psa_sequence', true ); $seq = get_post_meta( $post_id, 'psa_sequence', true );
$aliases = get_post_meta( $post_id, 'psa_aliases', true ); $aliases = get_post_meta( $post_id, 'psa_aliases', true );
if ( $weight || $formula || $seq ) { if ( $weight || $formula || $seq ) {
$html .= '<div class="psa-quick-facts">'; $html .= '<div class="psa-quick-facts">';
$html .= '<h3>Quick Facts</h3>'; $html .= '<h3>Quick Facts</h3>';
$html .= '<table class="psa-facts-table">'; $html .= '<table class="psa-facts-table">';
if ( $aliases ) { if ( $aliases ) {
$html .= '<tr><th>Also Known As</th><td>' . esc_html( $aliases ) . '</td></tr>'; $html .= '<tr><th>Also Known As</th><td>' . esc_html( $aliases ) . '</td></tr>';
} }
if ( $seq ) { if ( $seq ) {
$html .= '<tr><th>Sequence</th><td><code class="psa-sequence">' . esc_html( $seq ) . '</code></td></tr>'; $html .= '<tr><th>Sequence</th><td><code class="psa-sequence">' . esc_html( $seq ) . '</code></td></tr>';
} }
if ( $formula ) { if ( $formula ) {
$html .= '<tr><th>Molecular Formula</th><td>' . esc_html( $formula ) . '</td></tr>'; $html .= '<tr><th>Molecular Formula</th><td>' . esc_html( $formula ) . '</td></tr>';
} }
if ( $weight ) { if ( $weight ) {
$html .= '<tr><th>Molecular Weight</th><td>' . esc_html( $weight ) . '</td></tr>'; $html .= '<tr><th>Molecular Weight</th><td>' . esc_html( $weight ) . '</td></tr>';
} }
if ( $pubchem_cid ) { if ( $pubchem_cid ) {
$cid_int = intval( $pubchem_cid ); $cid_int = intval( $pubchem_cid );
$html .= '<tr><th>PubChem CID</th><td><a href="https://pubchem.ncbi.nlm.nih.gov/compound/' . $cid_int . '" target="_blank" rel="noopener">' . $cid_int . '</a></td></tr>'; $html .= '<tr><th>PubChem CID</th><td><a href="https://pubchem.ncbi.nlm.nih.gov/compound/' . $cid_int . '" target="_blank" rel="noopener">' . $cid_int . '</a></td></tr>';
} }
$html .= '</table>'; $html .= '</table>';
$html .= '</div>'; $html .= '</div>';
} }
// Detailed sections. // Detailed sections.
$detail_fields = array( $detail_fields = array(
'psa_mechanism' => 'Mechanism of Action', 'psa_mechanism' => 'Mechanism of Action',
'psa_research_apps' => 'Research Applications', 'psa_research_apps' => 'Research Applications',
'psa_safety_profile' => 'Safety & Side Effects', 'psa_safety_profile' => 'Safety & Side Effects',
'psa_dosage_info' => 'Dosage Information', 'psa_dosage_info' => 'Dosage Information',
'psa_references' => 'References', 'psa_references' => 'References',
); );
foreach ( $detail_fields as $key => $label ) { foreach ( $detail_fields as $key => $label ) {
$value = get_post_meta( $post_id, $key, true ); $value = get_post_meta( $post_id, $key, true );
if ( ! empty( $value ) ) { if ( ! empty( $value ) ) {
$html .= '<div class="psa-section">'; $html .= '<div class="psa-section">';
$html .= '<h3>' . esc_html( $label ) . '</h3>'; $html .= '<h3>' . esc_html( $label ) . '</h3>';
$html .= '<div class="psa-section-content">' . wp_kses_post( wpautop( $value ) ) . '</div>'; $html .= '<div class="psa-section-content">' . wp_kses_post( wpautop( $value ) ) . '</div>';
$html .= '</div>'; $html .= '</div>';
} }
} }
// Source badge. // Source badge.
if ( $source && 'pending' !== $source ) { if ( $source && 'pending' !== $source ) {
$badges = array( $badges = array(
'ai-generated' => array( 'label' => 'AI-Generated Content', 'class' => 'psa-badge-ai' ), 'ai-generated' => array( 'label' => 'AI-Generated Content', 'class' => 'psa-badge-ai' ),
'pubchem' => array( 'label' => 'PubChem Verified', 'class' => 'psa-badge-verified' ), 'pubchem' => array( 'label' => 'PubChem Verified', 'class' => 'psa-badge-verified' ),
'manual' => array( 'label' => 'Manually Curated', 'class' => 'psa-badge-manual' ), 'manual' => array( 'label' => 'Manually Curated', 'class' => 'psa-badge-manual' ),
); );
$badge = $badges[ $source ] ?? $badges['ai-generated']; $badge = $badges[ $source ] ?? $badges['ai-generated'];
$html .= '<div class="psa-source-badge ' . esc_attr( $badge['class'] ) . '">'; $html .= '<div class="psa-source-badge ' . esc_attr( $badge['class'] ) . '">';
$html .= esc_html( $badge['label'] ); $html .= esc_html( $badge['label'] );
if ( 'ai-generated' === $source ) { if ( 'ai-generated' === $source ) {
$html .= ' &mdash; This entry was automatically generated and may contain inaccuracies. Please verify critical information with primary sources.'; $html .= ' &mdash; This entry was automatically generated and may contain inaccuracies. Please verify critical information with primary sources.';
} }
$html .= '</div>'; $html .= '</div>';
} }
$html .= '</div>'; $html .= '</div>';
return $content . $html; return $content . $html;
} }
} }