Created
January 7, 2020 08:48
-
-
Save webdevs-pro/1f8ed947be07dc8fd429a5a3f5bca360 to your computer and use it in GitHub Desktop.
Ultimate Member custom fields for account tab + custom tabs
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 | |
// 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