Skip to content

Instantly share code, notes, and snippets.

@ramseyp
Created November 3, 2011 17:36
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 ramseyp/1337144 to your computer and use it in GitHub Desktop.
Save ramseyp/1337144 to your computer and use it in GitHub Desktop.
Modify User Profile to include an active checkbox
<?php
//Extra Author Profile Meta
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<h3>Is this an active author?</h3>
<table class="form-table">
<tr>
<td>
<?php $agree = get_the_author_meta( 'active_author', $user->ID ); ?>
<label for="active_author">Active Author <input value="true" name="active_author" id="active_author" <?php if ($agree == 'true' ) { ?>checked="checked"<?php }?> type="checkbox" /></label>
<?php //var_export($agree); ?>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
/* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
update_usermeta( $user_id, 'active_author', $_POST['active_author'] );
}
//Meet the authors Page
add_action('genesis_after_post_title', 'biz_authors_list');
function biz_authors_list() {
if(is_page('meet-the-authors')) {
//echo'<h2 class="pagetitle">Our Authors</h2>';
$blogusers = get_users_of_blog();
if ($blogusers) {
$au = array();
foreach ($blogusers as $bloguser) {
$user = get_userdata($bloguser->user_id);
//$active = get_user_meta ( $user, 'active_author', $single );
$post_count = count_user_posts($user->ID);
$au[] = array(
'user_id' => $user->ID ,
'nicename' => $user->user_nicename,
'display_name' => $user->display_name,
'email' => $user->user_email,
'bio' => $user->description,
'post_count' => $post_count,
'active' => $user->active_author
);
}
}
//then loop through the authors
echo'<div>';
foreach ($au as $aut){
if ( $aut['active'] == 'true' ) {
if ($aut['post_count'] > 0) {
echo '<div class="author-box author-'.$aut['user_id'].'">';
echo '<a href="'.get_bloginfo('url').'/author/' . $aut['nicename'] . '">'.get_avatar($aut['email'], '70').'';
echo '<h2>'.$aut['display_name'] .'</a></h2>';
echo '<div><p>'.$aut['bio'].'</p></div>';
echo'</div>';
}
}
}
echo '</div>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment