| 1 |
<?php |
| 2 |
|
| 3 |
add_shortcode('user_meta', 'wppb_toolbox_usermeta_handler'); |
| 4 |
function wppb_toolbox_usermeta_handler( $atts, $content=null){ |
| 5 |
|
| 6 |
if ( !isset( $atts['user_id'] ) ){ |
| 7 |
$user = wp_get_current_user(); |
| 8 |
$atts['user_id'] = $user->ID; |
| 9 |
} |
| 10 |
if ( !isset( $atts['size'] ) ){ |
| 11 |
$atts['size'] = '50'; |
| 12 |
} |
| 13 |
if ( !isset( $atts['pre'] ) ) { |
| 14 |
$atts['pre'] = ''; |
| 15 |
} |
| 16 |
if ( !isset( $atts['post'] ) ) { |
| 17 |
$atts['post'] = ''; |
| 18 |
} |
| 19 |
if ( !isset( $atts['wpautop'] ) ) { |
| 20 |
$atts['wpautop'] = ''; |
| 21 |
} |
| 22 |
|
| 23 |
if( in_array( $atts['key'], array( 'user_pass', 'user_activation_key' ) ) ) |
| 24 |
return; |
| 25 |
|
| 26 |
$user = new WP_User( $atts['user_id'] ); |
| 27 |
|
| 28 |
if ( !$user->exists() ) return; |
| 29 |
|
| 30 |
if ( !array_key_exists( 'key', $atts ) ) return; |
| 31 |
|
| 32 |
if( $atts['key'] == 'avatar' ){ |
| 33 |
return $atts['pre'] . get_avatar( $user->ID, $atts['size']) . $atts['post'] ; |
| 34 |
} |
| 35 |
|
| 36 |
if( $atts['key'] === 'id' ){ |
| 37 |
$atts['key'] = 'ID'; |
| 38 |
} |
| 39 |
|
| 40 |
if ( $user->has_prop( $atts['key'] ) ){ |
| 41 |
|
| 42 |
if ($atts['wpautop'] == 'on'){ |
| 43 |
$value = wpautop( $user->get( $atts['key'] ) ); |
| 44 |
} else { |
| 45 |
$value = $user->get( $atts['key'] ); |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
if (!empty( $value )){ |
| 51 |
return $atts['pre'] . $value . $atts['post'] ; |
| 52 |
} |
| 53 |
|
| 54 |
return; |
| 55 |
} |
| 56 |
|