Last active
February 10, 2017 01:51
-
-
Save gatespace/d84564150e5960313d106ba45649c6bf to your computer and use it in GitHub Desktop.
WordPress ユーザー情報の拡張とアバター画像とその表示 ref: http://qiita.com/gatespace/items/9a586da6b724107727ad
This file contains hidden or 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
<?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' ); |
This file contains hidden or 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
<?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