Skip to content

Commit

Permalink
Add option to show or hide the job title in bylines and partials/auth…
Browse files Browse the repository at this point in the history
…or-bio-description, defaulting to hide.

Affects both normal users and Co-Authors Plus guest authors.
  • Loading branch information
benlk committed Jan 26, 2016
1 parent d83ce3d commit ad85b51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions inc/post-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function largo_byline( $echo = true, $exclude_date = false, $post = null ) {
$coauthors = get_coauthors( $post_id );
foreach( $coauthors as $author ) {
$byline_text = $author->display_name;
if ( $job = $author->job_title )
if ( $author->show_job_title && $job = $author->job_title )
$byline_text .= ', ' . $job;
if ( $org = $author->organization )
$byline_text .= ' (' . $org . ')';
Expand All @@ -128,7 +128,8 @@ function largo_byline( $echo = true, $exclude_date = false, $post = null ) {
} else {
$authors = largo_author_link( false, $post_id );
$author_id = get_post_meta( $post_id, 'post_author', true );
if ( $job = get_the_author_meta( 'job_title' , $author_id )) {
$show_job_title = get_the_author_meta( 'show_job_title', $author_id);
if ( $show_job_title === 'on' && $job = get_the_author_meta( 'job_title' , $author_id )) {
$authors .= ', ' . $job;
}

Expand Down
22 changes: 22 additions & 0 deletions inc/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ function largo_filter_guest_author_fields( $fields_to_return, $groups ) {
'label' => 'Job Title',
'group' => 'name',
);
$fields_to_return[] = array(
'key' => 'show_job_title',
'label' => 'Show Job Title',
'group' => 'contact-info',
'input' => 'checkbox',
'type' => 'checkbox',
);
$fields_to_return[] = array(
'key' => 'organization',
'label' => 'Organization',
Expand Down Expand Up @@ -265,6 +272,7 @@ function largo_render_staff_list_shortcode($atts=array()) {
*/
function more_profile_info($user) {
$show_email = get_user_meta( $user->ID, "show_email", true );
$show_job_title = get_user_meta( $user->ID, "show_job_title", true );
$hide = get_user_meta( $user->ID, "hide", true );
?>
<h3><?php _e( 'More profile information', 'largo' ); ?></h3>
Expand All @@ -277,6 +285,15 @@ function more_profile_info($user) {
</td>
</tr>

<tr>
<th><label for="show_job_title"><?php _e( 'Show Job Title', 'largo' ); ?></label></th>
<td>
<input type="checkbox" name="show_job_title" id="show_job_title"
<?php if ( esc_attr($show_job_title) === "on" ) { ?>checked<?php } ?> />
<label for="show_job_title"><?php _e( 'Show job title publicly?', 'largo' ); ?></label><br />
</td>
</tr>

<tr>
<th><label for="show_email"><?php _e( 'Show Email Address', 'largo' ); ?></label></th>
<td>
Expand Down Expand Up @@ -312,6 +329,10 @@ function save_more_profile_info($user_id) {
if (!current_user_can('edit_user', $user_id ))
return false;

if ( ! isset($_POST['show_job_title']) ) {
$_POST['show_job_title'] = 'off';
}

if ( ! isset($_POST['show_email']) ) {
$_POST['show_email'] = 'off';
}
Expand All @@ -325,6 +346,7 @@ function save_more_profile_info($user_id) {

update_user_meta($user_id, 'job_title', $job_title);
update_user_meta($user_id, 'show_email', $show_email);
update_user_meta($user_id, 'show_job_title', $show_job_title);
update_user_meta($user_id, 'hide', $hide);
}
add_action('personal_options_update', 'save_more_profile_info');
Expand Down
6 changes: 6 additions & 0 deletions partials/author-bio-description.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
}

// Description
var_log($author_obj);
if ( $author_obj->job_title && $author_obj->show_job_title ) {
if ( $author_obj->show_job_title === 'on' || $author_obj->show_job_title == '1' ) {
echo '<p class="job-title">' . esc_attr( $author_obj->job_title ) . '</p>';
}
}
if ( $author_obj->description ) {
echo '<p>' . esc_attr( $author_obj->description ) . '</p>';
}

0 comments on commit ad85b51

Please sign in to comment.