Skip to content

Instantly share code, notes, and snippets.

@cryptexvinci
Last active April 29, 2020 16:23
Show Gist options
  • Select an option

  • Save cryptexvinci/2831827bc0ff23206a85fee1650b229e to your computer and use it in GitHub Desktop.

Select an option

Save cryptexvinci/2831827bc0ff23206a85fee1650b229e to your computer and use it in GitHub Desktop.
Display Ultimate Member field with a shortcode.
<?php
/*
Code snippet of Plugin Ultimate Member
URL: https://wordpress.org/plugins/ultimate-member/
*/
// Display field data of Ultimate Member
// e.g. [um_field_data userid="10' field="company_name"]
add_shortcode( 'um_field_data', 'um_custom_field_shortcode' );
if ( ! function_exists( 'um_custom_field_shortcode' ) ) {
function um_custom_field_shortcode( $atts = array() ){
$defaults = array(
'field' => NULL,
'userid' => NULL,
);
$atts = wp_parse_args( $atts, $defaults );
extract( $atts );
ob_start();
$user_id = um_user($atts['userid']);
um_fetch_user( $user_id );
$meta_value = um_user($atts['field']);
print_r($meta_value);
$shortcode_content = ob_get_contents();
ob_end_clean();
return $shortcode_content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment