Skip to content

Instantly share code, notes, and snippets.

@michael-sumner
Created September 16, 2024 12:36
Show Gist options
  • Save michael-sumner/4e71dd734779bf7d5cf05ff4f7482a26 to your computer and use it in GitHub Desktop.
Save michael-sumner/4e71dd734779bf7d5cf05ff4f7482a26 to your computer and use it in GitHub Desktop.
Co-Authors Plus - add custom "guest-author" fields
<?php
add_filter( 'coauthors_guest_author_fields', 'add_guest_author_fields', 10, 2 );
/**
* Adds the custom guest author fields to the coauthors guest author fields array.
*
* @param array $fields_to_return The fields to return.
* @param array $groups The groups to return.
* @return array The fields to return.
*/
function add_guest_author_fields( $fields_to_return, $groups ) {
$global_fields = array();
$socials = array(
__( 'Twitter', 'my-text-domain' ),
__( 'LinkedIn', 'my-text-domain' ),
);
foreach ( $socials as $social ) {
$global_fields[] = array(
'key' => sanitize_key( $social ),
'label' => $social,
'group' => 'contact-info',
'input' => 'url',
);
}
foreach ( $global_fields as $single_field ) {
if ( in_array( $single_field['group'], $groups ) || 'all' === $groups[0] && 'hidden' !== $single_field['group'] ) {
$fields_to_return[] = $single_field;
}
}
return $fields_to_return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment