feat(meta): consolidate save logic for article meta boxes

Merged saving logic for article authors and DOI into a single function
to streamline and reduce redundant code. This ensures that both
meta fields are consistently handled during post save operations.
This commit is contained in:
Kumi 2024-06-20 14:47:10 +02:00
parent 33f4d65bed
commit b3246b8549
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -334,16 +334,21 @@ function render_article_doi_meta_box($post)
<?php
}
function save_article_authors_meta_box($post_id)
function save_article_meta_boxes($post_id)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
if (!isset($_POST['article_authors'])) return;
$authors = array_map('sanitize_text_field', $_POST['article_authors']);
update_post_meta($post_id, 'article_authors', $authors);
if (isset($_POST['article_doi'])) {
$doi = sanitize_text_field($_POST['article_doi']);
update_post_meta($post_id, 'article_doi', $doi);
}
}
add_action('save_post', 'save_article_authors_meta_box');
add_action('save_post', 'save_article_meta_boxes');
function add_doi_rewrite_rule()
{