M
M
mcs_ae2017-10-03 15:52:30
Python
mcs_ae, 2017-10-03 15:52:30

How to change the display name of wordpress users to the required ones and make them the default?

The next question is how to implement it so that the name and the first letter of the user's last name are automatically selected in the Display name by default, of course you can manually change it in the WordPress settings and there the system sets the attribute it wants, but it is necessary that it be set automatically. Also, in the admin panel, you can only display either the last name, or the first name, or the mail, or the login, or the last name and first name together, but is it necessary that only the first name and the first letter of the last name become an automatic machine for each registered user?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
longclaps, 2019-06-25
@Rushpil

It is possible to search for a connection between points using the DSU algorithm (disjoint set method), but I did not succeed.

Yeah. You do not have to persevere, but your code goes straight to the trash.
N = 5
data = (
    ((0, 1),),
    ((1, 2), (3, 2)),
    ((4, 3),),
    ((1, 3), (4, 2))
)
root = list(range(N))


def chain_root(a):
    res = []
    while a != root[a]:
        res.append(a)
        a = root[a]
    return res, a


for pairs in data:
    for a, b in pairs:
        aa, ra = chain_root(a)
        bb, rb = chain_root(b)
        if ra > rb:
            ra, rb = rb, ra
        for node in [*aa, *bb, rb]:
            root[node] = ra
    aa, ra = chain_root(N - 1)
    if ra:
        for node in aa:
            root[node] = ra
        print('WAIT')
    else:
        print('ATTACK')
        break

Learn a python - you still have it below the plinth. And yes - how is the progress in the previous task ?

A
aRegius, 2019-06-25
@aRegius

Tell me what is wrong in my program?

Check for a redefinition of the variable k here:
for k, v in ribsDict.items()

M
mcs_ae, 2017-10-03
@mcs_ae

The code to display the default first and last names in display name after registration could be
class myUsers {
static function init() {
// Change the user's display name after insertion
add_action( 'user_register', array( __CLASS__, 'change_display_name' ) );
}
static function change_display_name( $user_id ) {
$info = get_userdata( $user_id );
$args = array(
'ID' => $user_id,
'display_name' => $info->first_name . ' ' . $info->last_name
);
wp_update_user( $args );
}
myUsers::init();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question