Improve author array validation

This commit is contained in:
Tetrakern 2023-09-21 23:26:22 +02:00
parent ef5b584241
commit 6aae419a27
2 changed files with 10 additions and 0 deletions

View File

@ -144,6 +144,10 @@ if ( ! function_exists( 'fictioneer_get_author_node' ) ) {
$author_name = get_the_author_meta( 'display_name', $author_id );
$author_url = get_author_posts_url( $author_id );
if ( ! $author_name ) {
return '';
}
return "<a href='{$author_url}' class='author {$classes}'>{$author_name}</a>";
}
}
@ -531,6 +535,9 @@ if ( ! function_exists( 'fictioneer_get_multi_author_nodes' ) ) {
$author_nodes[] = fictioneer_get_author_node( $author );
}
// Remove empty items
$author_nodes = array_filter( $author_nodes );
// Build and return HTML
return implode( ', ', array_unique( $author_nodes ) );
}

View File

@ -711,6 +711,9 @@ function fictioneer_save_story_metabox( $post_id ) {
$co_authors = fictioneer_explode_list( $_POST['fictioneer_story_co_authors'] ?? '' );
$co_authors = array_map( 'absint', $co_authors );
$co_authors = array_filter ($co_authors, function( $user_id ) {
return get_userdata( $user_id ) !== false;
});
$fields['fictioneer_story_co_authors'] = array_unique( $co_authors );
if ( current_user_can( 'fcn_make_sticky', $post_id ) && FICTIONEER_ENABLE_STICKY_CARDS ) {