';
foreach ( PSA_Post_Type::META_FIELDS as $key => $label ) {
$value = get_post_meta( $post->ID, $key, true );
echo '
';
echo ' | ';
echo '';
if ( 'psa_source' === $key ) {
$options = array(
'' => '— Select —', 'ai-generated' => 'AI Generated',
'pubchem' => 'PubChem Verified', 'manual' => 'Manual Entry', 'pending' => 'Pending Generation',
);
echo '';
} elseif ( in_array( $key, $textarea_fields, true ) ) {
echo '';
} else {
echo '';
}
echo ' |
';
}
echo '';
}
/**
* Render extended meta box fields (half-life, stability, storage, etc.).
*
* @param WP_Post $post The current post object.
*/
public static function render_extended_meta_box( $post ): void {
echo '';
}
/**
* Save meta field values (core + extended) on post save.
*
* @param int $post_id The post ID.
*/
public static function save_meta( int $post_id ): void {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
if ( ! isset( $_POST['psa_meta_nonce'] ) ||
! wp_verify_nonce( wp_unslash( $_POST['psa_meta_nonce'] ), 'psa_save_meta' ) ) {
return;
}
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return;
}
$numeric_fields = array( 'psa_vial_size_mg', 'psa_amino_acid_count' );
$all_fields = array_merge( PSA_Post_Type::META_FIELDS, PSA_Post_Type::EXTENDED_META_FIELDS );
foreach ( $all_fields as $key => $label ) {
if ( isset( $_POST[ $key ] ) ) {
$raw = wp_unslash( $_POST[ $key ] );
if ( in_array( $key, $numeric_fields, true ) ) {
$value = ( '' === trim( $raw ) ) ? '' : (string) max( 0, floatval( $raw ) );
} else {
$value = sanitize_textarea_field( $raw );
}
update_post_meta( $post_id, $key, $value );
}
}
}
}