Skip to content

Instantly share code, notes, and snippets.

@roborourke
Last active December 27, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roborourke/7369768 to your computer and use it in GitHub Desktop.
Save roborourke/7369768 to your computer and use it in GitHub Desktop.
Adds all contact methods to co-authors-plus plugin guest authors screen
<?php
// Adds all contact methods to co-authors-plus plugin guest authors screen
add_filter( 'coauthors_guest_author_fields', 'coauthors_contactmethods', 10, 2 );
function coauthors_contactmethods( $fields, $groups ) {
if ( ! in_array( 'contact-info', $groups ) && $groups[ 0 ] !== 'all' )
return $fields;
$contact_methods = apply_filters( 'user_contactmethods', array() );
$existing_keys = array_map( function( $item ) {
return $item[ 'key' ];
}, $fields );
foreach( $contact_methods as $key => $label ) {
if ( $index = array_search( $key, $existing_keys ) )
unset( $fields[ $index ] );
$fields[] = array(
'key' => $key,
'label' => $label,
'group' => 'contact-info',
'sanitize_function' => 'sanitize_text_field'
);
}
return array_values( $fields );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment