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:
parent
33f4d65bed
commit
b3246b8549
1 changed files with 7 additions and 2 deletions
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue