Skip to content

Instantly share code, notes, and snippets.

@carlodaniele
Created April 3, 2016 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlodaniele/ebea4690378ed5bb8eca8510ad24c61d to your computer and use it in GitHub Desktop.
Save carlodaniele/ebea4690378ed5bb8eca8510ad24c61d to your computer and use it in GitHub Desktop.
<?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