Created
September 16, 2024 12:36
-
-
Save michael-sumner/4e71dd734779bf7d5cf05ff4f7482a26 to your computer and use it in GitHub Desktop.
Co-Authors Plus - add custom "guest-author" fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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