Skip to content

Instantly share code, notes, and snippets.

@webdevs-pro
Created January 7, 2020 08:48
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 webdevs-pro/1f8ed947be07dc8fd429a5a3f5bca360 to your computer and use it in GitHub Desktop.
Save webdevs-pro/1f8ed947be07dc8fd429a5a3f5bca360 to your computer and use it in GitHub Desktop.
Ultimate Member custom fields for account tab + custom tabs
<?php
// add custom registration fields to UM account tab
add_action('um_after_account_general', 'AAshowUMExtraFields', 100);
function AAshowUMExtraFields() {
$id = um_user('ID');
$output = '';
$names = array('birth_date', 'height', 'football_club', 'phone_number');
$fields = array();
foreach( $names as $name ) {
$fields[ $name ] = UM()->builtin()->get_specific_field( $name );
}
$fields = apply_filters('um_account_secure_fields', $fields, $id);
foreach( $fields as $key => $data ) {
$output .= UM()->fields()->edit_field( $key, $data );
}
echo $output;
}
add_action('um_account_pre_update_profile', 'getUMFormData', 100);
function getUMFormData(){
$id = um_user('ID');
$names = array('birth_date', 'height', 'football_club', 'phone_number');
foreach( $names as $name ) {
update_user_meta( $id, $name, $_POST[$name] );
}
}
// remove unnessesary account tabs
function aa_remove_um_tabs( $tabs ) {
// unset
unset( $tabs[210]);
unset( $tabs[220]);
unset( $tabs[250]);
unset( $tabs[300]);
// add new
$tabs[1000]['logout']['icon'] = 'um-icon-log-out';
$tabs[1000]['logout']['title'] = 'Logout';
$tabs[1000]['logout']['custom'] = true;
return $tabs;
}
add_filter( 'um_account_page_default_tabs_hook', 'aa_remove_um_tabs',100 );
// new tab content
add_action('um_account_tab__logout', 'um_account_tab__logout');
function um_account_tab__logout( $info ) {
global $ultimatemember;
extract( $info );
$output = $ultimatemember->account->get_tab_output('logout');
if ( $output ) { echo $output; }
}
add_filter('um_account_content_hook_logout', 'um_account_content_hook_logout');
function um_account_content_hook_logout( $output ){
ob_start();
?>
<div class="um-field">
<a class="account_logout_link" href="/logout"><i class="fas fa-sign-out-alt"></i> Logout</a>
</div>
<?php
$output .= ob_get_contents();
ob_end_clean();
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment