Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active March 14, 2021 23:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Shelob9/6504376 to your computer and use it in GitHub Desktop.
Save Shelob9/6504376 to your computer and use it in GitHub Desktop.
<?php if ( have_posts() ) : ?>
<?php
/**Get all of the data about the author from the WordPress and Pods generated user profile fields.**/
//First get the_post so WordPress knows who's author page this is
the_post();
//get the author's meta data and store in array $user
$user = get_userdata( get_the_author_meta('ID') );
//Escape all of the meta data we need into variables
$name = esc_attr($user->user_firstname) . '&nbsp;' . esc_attr($user->user_lastname);
$title = esc_attr($user->title);
$email = esc_attr($user->user_email);
$phone = esc_attr($user->phone_number);
$street_1 = esc_attr($user->street_address_line_1);
$street_2 = esc_attr($user->street_address_line_2);
$city = esc_attr($user->city);
$state = esc_attr($user->state);
$zip = esc_attr($user->zip_code);
$website = esc_url($user->user_url);
$twitter = esc_url($user->twitter);
$linkedin = esc_url($user->linkedin);
?>
<article>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'User Profile', 'twentytwelve' ); ?></h1>
</header>
<div class="author-info">
<h2><?php echo $name; ?></h1>
<div class="author-avatar">
<?php echo '<a href="' . pods_image_url( $user->picture, 'large') . '">' . pods_image ( $user->picture, 'thumbnail') . '</a>';
?>
</div><!-- .author-avatar -->
<div class="author-description">
<p><strong><?php _e('Email:', 'twentytwelve'); ?></strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?></p>
<p><strong><?php _e('Phone:', 'twentytwelve'); ?></strong> <?php echo $phone; ?></p>
<div><p><strong><?php _e('Address:', 'twentytwelve'); ?> </strong></p>
<?php echo
'<p>' . $street_1 . '</p>' .
'<p>' . $street_2 . '</p>' .
'<p>' . $city . ', ' . $state . ' ' . $zip . '</p>';
?></div>
<p><strong><?php _e('Website:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $website . '">' . $website . '</a>'; ?></p>
<p><strong><?php _e('Twitter:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $twitter . '">' . $twitter . '</a>'; ?></p>
<p><strong><?php _e('LinkedIn:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $linkedin . '">' . $linkedin . '</a>'; ?></p>
</div><!-- .author-description -->
</div><!-- .author-info -->
</article>
<?php
/**
*
* User profile page.
*
*/
get_header(); ?>
<section id="primary" class="site-content">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php
/**Get all of the data about the author from the WordPress and Pods generated user profile fields.**/
//First get the_post so WordPress knows who's author page this is
the_post();
//get the author's meta data and store in array $user
$user = get_userdata( get_the_author_meta('ID') );
//Escape all of the meta data we need into variables
$name = esc_attr($user->user_firstname) . '&nbsp;' . esc_attr($user->user_lastname);
$title = esc_attr($user->title);
$email = esc_attr($user->user_email);
$phone = esc_attr($user->phone_number);
$street_1 = esc_attr($user->street_address_line_1);
$street_2 = esc_attr($user->street_address_line_2);
$city = esc_attr($user->city);
$state = esc_attr($user->state);
$zip = esc_attr($user->zip_code);
$website = esc_url($user->user_url);
$twitter = esc_url($user->twitter);
$linkedin = esc_url($user->linkedin);
?>
<article>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'User Profile', 'twentytwelve' ); ?></h1>
</header>
<div class="author-info">
<h2><?php echo $name; ?></h1>
<div class="author-avatar">
<?php echo '<a href="' . pods_image_url( $user->picture, 'large') . '">' . pods_image ( $user->picture, 'thumbnail') . '</a>';
?>
</div><!-- .author-avatar -->
<div class="author-description">
<p><strong><?php _e('Email:', 'twentytwelve'); ?></strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?></p>
<p><strong><?php _e('Phone:', 'twentytwelve'); ?></strong> <?php echo $phone; ?></p>
<div><p><strong><?php _e('Address:', 'twentytwelve'); ?> </strong></p>
<?php echo
'<p>' . $street_1 . '</p>' .
'<p>' . $street_2 . '</p>' .
'<p>' . $city . ', ' . $state . ' ' . $zip . '</p>';
?></div>
<p><strong><?php _e('Website:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $website . '">' . $website . '</a>'; ?></p>
<p><strong><?php _e('Twitter:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $twitter . '">' . $twitter . '</a>'; ?></p>
<p><strong><?php _e('LinkedIn:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $linkedin . '">' . $linkedin . '</a>'; ?></p>
</div><!-- .author-description -->
</div><!-- .author-info -->
<?php
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
?>
<?php twentytwelve_content_nav( 'nav-above' ); ?>
<div class="author-info">
<h2><?php _e('Post By:', 'twentytwelve'); echo '&nbsp;' . get_the_author(); ?></h2>
</div>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentytwelve_content_nav( 'nav-below' ); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</article>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<ul>
<?php
$users = new WP_User_Query(array(
'meta_key'=>'last_name',
'orderby'=>'meta_value',
'fields'=>'all_with_meta'
));
if ( ! empty( $users->results ) ) {
foreach ( $users->results as $user ) {
echo '<li><a href="' . esc_url( get_author_posts_url($user->ID) ) . '">' . esc_attr( $user->last_name ) . ', ' . esc_attr( $user->first_name ) . '</a></li>';
}
}
else {
echo 'No users found.';
}
?>
</ul>
<?php
/*
Template Name: Users List
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<article>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'User Directory', 'twentytwelve' ); ?></h1>
</header>
<div class="entry-content">
<ul>
<?php
$users = new WP_User_Query(array(
'meta_key'=>'last_name',
'orderby'=>'meta_value',
'fields'=>'all_with_meta'
));
if ( ! empty( $users->results ) ) {
foreach ( $users->results as $user ) {
echo '<li><a href="' . esc_url( get_author_posts_url($user->ID) ) . '">' . esc_attr( $user->last_name ) . ', ' . esc_attr( $user->first_name ) . '</a></li>';
}
}
else {
echo 'No users found.';
}
?>
</ul>
</div>
</article>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
function pods_user_profile_display($user) {
//Escape all of the meta data we need into variables
$name = esc_attr($user->user_firstname) . '&nbsp;' . esc_attr($user->user_lastname);
$title = esc_attr($user->title);
$email = esc_attr($user->user_email);
$phone = esc_attr($user->phone_number);
$street_1 = esc_attr($user->street_address_line_1);
$street_2 = esc_attr($user->street_address_line_2);
$city = esc_attr($user->city);
$state = esc_attr($user->state);
$zip = esc_attr($user->zip_code);
$website = esc_url($user->user_url);
$twitter = esc_url($user->twitter);
$linkedin = esc_url($user->linkedin);
?>
<div class="author-info">
<h2><?php echo $name; ?></h1>
<div class="author-avatar">
<?php echo '<a href="' . pods_image_url( $user->picture, 'large') . '">' . pods_image ( $user->picture, 'thumbnail') . '</a>';
?>
</div><!-- .author-avatar -->
<div class="author-description">
<p><strong><?php _e('Email:', 'twentytwelve'); ?></strong> <?php echo '<a href="mailto:' . $email . '">' . $email . '</a>'; ?></p>
<p><strong><?php _e('Phone:', 'twentytwelve'); ?></strong> <?php echo $phone; ?></p>
<div><p><strong><?php _e('Address:', 'twentytwelve'); ?> </strong></p>
<?php echo
'<p>' . $street_1 . '</p>' .
'<p>' . $street_2 . '</p>' .
'<p>' . $city . ', ' . $state . ' ' . $zip . '</p>';
?></div>
<p><strong><?php _e('Website:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $website . '">' . $website . '</a>'; ?></p>
<p><strong><?php _e('Twitter:', 'twentytwelve'); ?></strong> <?php echo '<a href="' . $twitter . '">' . $twitter . '</a>'; ?></p>
<p><strong><?php _e('LinkedIn:', 'twentytwelve'); ?> </strong> <?php echo '<a href="' . $linkedin . '">' . $linkedin . '</a>'; ?></p>
</div><!-- .author-description -->
</div><!-- .author-info -->
<?php
}
?>
<ul>
<?php
$users = new WP_User_Query(array(
'meta_key'=>'last_name',
'orderby'=>'meta_value',
'fields'=>'all_with_meta'
));
foreach ($users as $user) {
pods_user_profile_display($user);
}
?>
</ul>
<?php
/*
Template Name: Users List
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<article>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'User Directory', 'twentytwelve' ); ?></h1>
</header>
<div class="entry-content">
<ul>
<?php
$users = get_users('orderby=user_lastname');
foreach ($users as $user) {
pods_user_profile_display($user);
}
?>
</ul>
</div>
</article>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php
/**
*
* User profile page.
*
*/
get_header(); ?>
<section id="primary" class="site-content">
<div id="content" role="main">
<?php
if ( have_posts() ) :
//First get the_post so WordPress knows who's author page this is
the_post();
?>
<article>
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'User Profile', 'twentytwelve' ); ?></h1>
</header>
<?php
//get the author's meta data and store in array $user
$user = get_userdata( get_the_author_meta('ID') );
//show the user's profile.
pods_user_profile_display($user);
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
?>
<?php twentytwelve_content_nav( 'nav-above' ); ?>
<div class="author-info">
<h2><?php _e('Post By:', 'twentytwelve'); echo '&nbsp;' . get_the_author(); ?></h2>
</div>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentytwelve_content_nav( 'nav-below' ); ?>
<?php else : ?>
<?php get_template_part( 'content', 'none' ); ?>
<?php endif; ?>
</article>
</div><!-- #content -->
</section><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<ul>
<?php
$args = array(
'orderby' => 'user_lastname',
'role' => 'contributor'
'meta_key' => 'hide_from_directory',
'meta_value' => '',
);
$users = get_users($args);
foreach ($users as $user) {
echo '<li><a href="' . esc_url( get_author_posts_url($user->ID) ) . '">' . esc_attr($user->user_lastname) . ', ' . esc_attr($user->user_firstname) . '</a></li>';
}
?>
</ul>
<?php
$current_user_id = get_current_user_id();
$current_user = new WP_User ( $current_user_id );
if ($current_user->roles[0] == 'contributor' || 'administrator') {
//show profile
}
elseif ( ! is_user_logged_in() ) {
echo '<p><strong>You must be logged in to view the user directory.</strong></p>'
else {
echo '<p><strong>Sorry, but you do not have sufficient privileges to view the user directory.</p></strong>'
}
?>
<?php
//Output a twitter follow button for post author. Must be used in loop
//See https://twitter.com/about/resources/buttons#follow for more info
function pods_twitter_follow() {
$twitter = get_the_author_meta('twitter');
$name = get_author_meta('user_firstname');
?>
<a class="twitter-follow-button" data-show-count="false" href="<?php echo $twitter; ?>">Follow <?php echo $name; ?></a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<?php
}
//Output a link to a user's twitter page
function pods_show_twitter_link($id) {
$twitter = get_user_meta($id, 'twitter', true);
echo esc_html($twitter);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment