Instantly share code, notes, and snippets.
Forked from jp1971/guest_authors_extend
Created
June 7, 2012 13:17
-
Star
1
(1)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save danielbachhuber/2888759 to your computer and use it in GitHub Desktop.
Extending guest author profiles
This file contains 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
//From functions_thought_catalog.php | |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
/** | |
* Let's add a meta box for author links to the guest authors profile pages | |
* | |
*/ | |
add_action( 'add_meta_boxes', 'coauthors_add_on_the_web_box' ); | |
function coauthors_add_on_the_web_box() { | |
add_meta_box( | |
'coauthors-manage-guest-author-on-the-web', | |
__( 'On the Web', 'co-authors-plus'), | |
'metabox_manage_guest_author_on_the_web', | |
$post_type, | |
'normal', | |
'low' | |
); | |
} | |
function metabox_manage_guest_author_on_the_web() { | |
global $post; | |
global $coauthors_plus; | |
$fields = $coauthors_plus->guest_authors->get_guest_author_fields( 'on-the-web' ); | |
echo '<table class="form-table"><tbody>'; | |
foreach( $fields as $field ) { | |
$pm_key = $coauthors_plus->guest_authors->get_post_meta_key( $field['key'] ); | |
$value = get_post_meta( $post->ID, $pm_key, true ); | |
echo '<tr><th>'; | |
echo '<label for="' . esc_attr( $pm_key ) . '">' . $field['label'] . '</label>'; | |
echo '</th><td>'; | |
echo '<input type="text" name="' . esc_attr( $pm_key ) . '" value="' . esc_attr( $value ) . '" class="regular-text" />'; | |
echo '</td></tr>'; | |
} | |
echo '</tbody></table>'; | |
} | |
//add_filter( 'coauthors_guest_author_fields', 'add_guest_author_on_the_web_fields', 10, 2); | |
// function add_guest_author_on_the_web_fields( $groups, $global_fields ) { | |
// | |
// } | |
//From modified class-coauthors-guest-authors.php | |
function get_guest_author_fields( $groups = 'all' ) { | |
$groups = (array)$groups; | |
$global_fields = array( | |
// Hidden (included in object, no UI elements) | |
array( | |
'key' => 'ID', | |
'label' => __( 'ID', 'co-authors-plus' ), | |
'group' => 'hidden', | |
), | |
// Name | |
array( | |
'key' => 'display_name', | |
'label' => __( 'Display Name', 'co-authors-plus'), | |
'group' => 'name', | |
), | |
array( | |
'key' => 'first_name', | |
'label' => __( 'First Name', 'co-authors-plus'), | |
'group' => 'name', | |
), | |
array( | |
'key' => 'last_name', | |
'label' => __( 'Last Name', 'co-authors-plus'), | |
'group' => 'name', | |
), | |
array( | |
'key' => 'user_login', | |
'label' => __( 'Slug', 'co-authors-plus'), | |
'group' => 'slug', | |
), | |
// Contact info | |
array( | |
'key' => 'user_email', | |
'label' => __( 'E-mail', 'co-authors-plus' ), | |
'group' => 'contact-info', | |
), | |
array( | |
'key' => 'linked_account', | |
'label' => __( 'Linked Account', 'co-authors-plus' ), | |
'group' => 'slug', | |
), | |
array( | |
'key' => 'website', | |
'label' => __( 'Website', 'co-authors-plus' ), | |
'group' => 'contact-info', | |
), | |
array( | |
'key' => 'aim', | |
'label' => __( 'AIM', 'co-authors-plus' ), | |
'group' => 'contact-info', | |
), | |
array( | |
'key' => 'yahooim', | |
'label' => __( 'Yahoo IM', 'co-authors-plus' ), | |
'group' => 'contact-info', | |
), | |
array( | |
'key' => 'jabber', | |
'label' => __( 'Jabber / Google Talk', 'co-authors-plus' ), | |
'group' => 'contact-info', | |
), | |
array( | |
'key' => 'description', | |
'label' => __( 'Biographical Info', 'co-authors-plus' ), | |
'group' => 'about', | |
'sanitize_function' => 'wp_filter_post_kses', | |
), | |
//I added these arrays. I need to use add_filter to handle this in a theme file. | |
array( | |
'key' => 'url_1', | |
'label' => __( 'URL', 'co-authors-plus' ), | |
'group' => 'on-the-web', | |
), | |
array( | |
'key' => 'title_1', | |
'label' => __( 'Title', 'co-authors-plus'), | |
'group' => 'on-the-web', | |
) | |
); | |
$fields_to_return = array(); | |
foreach( $global_fields as $single_field ) { | |
if ( in_array( $single_field['group'], $groups ) || $groups[0] == 'all' && $single_field['group'] != 'hidden' ) | |
$fields_to_return[] = $single_field; | |
} | |
return apply_filters( 'coauthors_guest_author_fields', $fields_to_return, $groups ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment