Skip to content

Instantly share code, notes, and snippets.

@rbenvenuto
Last active February 11, 2017 12:59
Show Gist options
  • Save rbenvenuto/eb086864d05538f1a76785c805cf4ea4 to your computer and use it in GitHub Desktop.
Save rbenvenuto/eb086864d05538f1a76785c805cf4ea4 to your computer and use it in GitHub Desktop.
/** Gerar ID's para usuários **/
add_action( 'user_register', 'my_on_user_register' );
function my_on_user_register( $user_id ) {
$unique_id = 6395730800131050 + $user_id;
update_user_meta( $user_id, 'my_unique_id', $unique_id );
}
//display decal code on profile
add_action('show_user_profile', 'my_extra_user_profile_fields');
add_action('edit_user_profile', 'my_extra_user_profile_fields');
function my_extra_user_profile_fields($user){
$unique_number = get_the_author_meta('my_unique_id', $user->ID);
?>
<h3><?php _e('Decal Info'); ?></h3>
<table class="form-table">
<tr>
<th><label for="address"><?php _e('Code:'); ?></label></th> -->
<td><?php echo $unique_number; ?></td>
</tr>
</table>
<?php
}
// Dar echo na variável que contém o número
add_action('num_card_print', 'num_card', 10);
function num_card() {
$cartao_id = get_user_meta('my_unique_id', 'my_unique_id', true);
echo $cartao_id;
}
//send email with decal code to admin on new user
function registration_email_alert($user_id) {
$message = strip_tags($_POST['user_login']). ' - ' . strip_tags($_POST['user_email']) . ' Decal Code: ' . strip_tags($user_id['my_unique_id']) . ' Has Registered To Your Website';
wp_mail( '[email protected]', 'New User Has Been Registered', $message );
}
add_action('user_register', 'registration_email_alert');
//add decal code to user list
function new_modify_user_table( $column ) {
$column['my_unique_id'] = 'Decal Code';
return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );
function new_modify_user_table_row( $val, $column_name, $user_id ) {
$user = get_userdata( $user_id );
switch ($column_name) {
case 'my_unique_id' :
return get_the_author_meta( 'my_unique_id', $user_id );
break;
default:
}
return $return;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );
@rodrigomanara
Copy link

veja este numero : 11 caracteres se for maior da error
$unique_id = 6395730800131050 + $user_id;

o corretor seria:
$unique_id = rand(999,999999) + $user_id;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment