Created
April 3, 2016 13:53
-
-
Save carlodaniele/ebea4690378ed5bb8eca8510ad24c61d to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** | |
* Create [usermeta] shortcode | |
* | |
* @param $atts An array of attributes | |
* | |
* @return string A single user meta field | |
* | |
* @link https://codex.wordpress.org/Shortcode_API | |
* @link https://codex.wordpress.org/Function_Reference/shortcode_atts | |
* @link https://codex.wordpress.org/Function_Reference/get_user_meta | |
*/ | |
function wpmu_user_meta_shortcode( $atts ){ | |
if ( !is_user_logged_in() ) { | |
return; | |
} | |
$a = shortcode_atts( array( 'field' => 'nickname' ), $atts, 'usermeta' ); | |
$user = wp_get_current_user(); | |
$field = $user->get( $a['field'] ); | |
if( null !== $field && is_string( $field ) ){ | |
return esc_attr( $field ); | |
}else{ | |
return ''; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment