Skip to content

Instantly share code, notes, and snippets.

@gatespace
Last active February 10, 2017 01:51
Show Gist options
  • Save gatespace/d84564150e5960313d106ba45649c6bf to your computer and use it in GitHub Desktop.
Save gatespace/d84564150e5960313d106ba45649c6bf to your computer and use it in GitHub Desktop.
WordPress ユーザー情報の拡張とアバター画像とその表示 ref: http://qiita.com/gatespace/items/9a586da6b724107727ad
<?php
// Register User Contact Methods
function custom_user_contact_methods( $user_contact_method ) {
$user_contact_method['facebook'] = __( 'Facebook Username', 'text_domain' );
$user_contact_method['twitter'] = __( 'Twitter Username', 'text_domain' );
$user_contact_method['gplus'] = __( 'Google Plus', 'text_domain' );
$user_contact_method['skype'] = __( 'Skype Username', 'text_domain' );
return $user_contact_method;
}
add_filter( 'user_contactmethods', 'custom_user_contact_methods' );
<?php
// Website
if ( get_the_author_meta( 'user_url' ) ) {
echo '<a href="' . esc_url( get_the_author_meta( 'user_url' ) ) . '"><span class="genericon genericon-website"></span></a>';
}
// Facebook
if ( get_the_author_meta( 'facebook' ) ) {
echo '<a href="' . esc_url( 'https://www.facebook.com/' . get_the_author_meta( 'facebook' ) ) . '"><span class="genericon genericon-facebook"></span></a>';
}
// Twitter
if ( get_the_author_meta( 'twitter' ) ) {
echo '<a href="' . esc_url( 'https://twitter.com/' . get_the_author_meta( 'twitter' ) ) . '"><span class="genericon genericon-twitter"></span></a>';
}
// Google Plus
if ( get_the_author_meta( 'gplus' ) ) {
echo '<a href="' . esc_url( get_the_author_meta( 'gplus' ) ) . '"><span class="genericon genericon-googleplus"></span></a>';
}
// Skype
if ( get_the_author_meta( 'skype' ) ) {
echo '<a href="skype:' . esc_attr( get_the_author_meta( 'skype' ) ) . '?call"><span class="genericon genericon-skype"></span></a>';
}
?>
<?php
function writerlist_shortcode( $atts ) {
$output = '';
// Attributes
extract( shortcode_atts(
array(
'role' => 'Author',
),
$atts
) );
$role = str_replace( array( " ", " " ), "", $role );
$role = explode( ',', $role );
// WP_User_Query arguments
$user_args = array (
'role__in' => $role,
'order' => 'ASC',
'orderby' => 'display_name',
);
// Create the WP_User_Query object
$wp_user_query = new WP_User_Query( $user_args );
// Get the results
$authors = $wp_user_query->get_results();
if ( ! empty( $authors ) ) {
$output .= '<ul class="author-lists">' . "\n";
// loop through each author
foreach ( $authors as $author ) {
// get all the user's data
$output .= '<li class="author-info">' . "\n";
$output .= '<div class="author-avatar">' . get_avatar( get_the_author_meta( 'user_email', $author->ID ) ) . '</div>' . "\n";
$output .= '<div class="author-bio">'. "\n";
$output .= '<div class="author-title">' . get_the_author_meta( 'display_name', $author->ID ) . '</div>' . "\n";
$output .= '<div class="author-description">' . nl2br( get_the_author_meta( 'description', $author->ID ) ) . '</div>' . "\n";
$output .= '</div>'. "\n";
$output .= '</li>' . "\n";
}
$output .= '</ul>' . "\n";
}
return $output;
}
add_shortcode( 'writerlist', 'writerlist_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment