Profile section is messed up after using a code

After using the code from here on my Wordpress 4.9.7 website I thought initially that everything is fine, it was showing First Name & Last Name First Initial , but then I noticed that my other website functionalities are affect like /profile , clients are unable to change their profile, when click on profile its just refreshing the website while it adds /profile on link, but the most important thing is that I cannot reverse the effect. I have removed the code from child them function.php file with no effect , its still showing showing First Name & Last Name First Initial , and clients are unable to edit their profile anymore. I have downloaded the entire website and searched for the code, its not present. It seems like your code altered the entire database, if I restore an old database backup the problem is gone but the backup its too old, I Need to fix the problem on the actual DB. I have also tried to run the code again by replacing 'hide' with 'show' but it has no effect ! The big problem is that no one is able now to edit their profile, I need solution to resolve that, if not, PLEASE HELP to restore everything as before!

Actually I have used most of the codes on this thread, I'm not sure which one altered the DB but I need the reverse code to fully restore it.

It seems like custom slags set on theme are also affected, they only work the default preset, if change it is saying 404 error page not found. How to fix that now ..? Incredible how much damage the code has done.

Original Code:

add_action( 'admin_init', 'fix_display_name' );
function fix_display_name() {
	$users = get_users();
	foreach( $users as $user ){
		if( $user->first_name != '' && $user->last_name != '' ){
			$display_name = $user->first_name . ' ' . substr( $user->last_name, 0, 1 ) . '.';
			wp_update_user(
				array(
				      'ID' => $user->ID,
				      'display_name' => $display_name
				      )
			);
		}
	}
}

add_action( 'admin_head', 'hide_profile_field' );
function hide_profile_field() {
    ?>
    <script type="text/javascript">
    jQuery(function($) {
        $('.user-nickname-wrap, .user-display-name-wrap').hide();
    });
    </script>
    <?php
}
  • Ash
    • WordPress Hacker

    Hello mircea

    I have made an initial reply on the other thread here: https://premium.wpmudev.org/forums/topic/show-first-name-last-name-first-initial-with-period-only?replies=26#post-1330527

    But let me help you with the issue in detail.

    1. Do you want to FORCE the display name to be First Name and Last Name initial? Or you changed your mind?
    2. Please list the other issue with bullet/number points, would be easier for me to understand :slight_smile:
    3. Would you please send me your admin login and cPanel details so that I can check and modify?

    You can send me privately in the following format:
    1. Please go to https://premium.wpmudev.org/contact/#i-have-a-different-question
    2. Select "I have a different question" if not selected
    3. In subject line put "Attn-Ash" (this will ensure that the email is assigned to me)
    4. Provide the wanted details.
    5. Add the thread link in the message so that I can track.

    IMPORTANT: Please DO TAKE A BACKUP of your site of current state, so that if anything goes wrong we can restore immediately.

    Have a nice day!

    Cheers,
    Ash

  • Superhero 19
    • Deleted User

    All is fixed now, I have replaced database wp_users from backup. I just need proper solution for my case with the possibility to disable it/remove the code and restore it as previously. Your code effect is permanent, once removed nothing can be done or maybe additional code used which is not nice.

    On my theme this is the part of the code that forces to show author full name:

    <h2>post_author ); ?>"><?php the_author_meta( 'display_name', $convert->post_author ); ?></h2>

    I can change display_name with first_name but I also need Last Name First Initial with Period. Can I alter above line on child theme to achieve what I need, if so how ? It would be the easiest way. Or maybe some easy plugin that will not affect the website speed.

    Thank you

  • Ash
    • WordPress Hacker

    Hello mircea

    All is fixed now, I have replaced database wp_users from backup.

    Glad to know that :slight_smile:

    Your code effect is permanent, once removed nothing can be done or maybe additional code used which is not nice.

    That's why we always suggest creating a new thread, every case is different. For his case, it was the permanent change because he asked to. Also, he needed that change to affect every corner of his site, not just in a page of the website.

    Instead of spending time opening this new thread you could just simply reply with the solution.

    We also encourage to create a new thread instead of jumping, that's how the original poster won't be bothered with email notification.

    Going this way with this slowness in basic support would lead me to cancel further subscription with you.

    We always try to reply all tickets as soon as possible, but we maintain a queue. This is a general wordpress support query and not directly related to any of our products but we don't deprioritize that. You can check the main support forum that we are 24 hours replying to our members. Sometimes it takes a bit of time due to tickets overloading, but we are trying out best.

    Back to the original issue, yes you can make the change if you are using a child theme. Please replace the following part:

    <?php the_author_meta( 'display_name', $convert->post_author ); ?>

    with this:

    <?php
    $first_name = get_the_author_meta( 'first_name', $convert->post_author );
    $last_name = substr( get_the_author_meta( 'last_name', $convert->post_author ), 0, 1 ) . '.';
    $display_name = $first_name . ' ' . $last_name;
    echo $display_name;
    ?>

    It should show as Ashok N. or James F.

    But note that, this will show only where the code is printed, not other parts of the website.

    Please let us know if that works for you. Have a nice day!

    Cheers,
    Ash

  • Superhero 19
    • Deleted User

    I did it myself using your code as example, its working but you you confirm its the right way ?

    $first_name = get_the_author_meta('first_name', $author_id);
    $last_name = substr( get_the_author_meta( 'last_name', $author_id), 0, 1 ) . '.';
    $author_name = $first_name . ' ' . $last_name;

    Thank you

  • Superhero 19
    • Deleted User

    Thank you,

    How about this one, is working fine but I didn't added $bid->post_author because I dindn't knew how, so I don't really know the real impact.. :

    $author = get_the_author_meta( 'display_name', $bid->post_author );

    Result:

    $first_name = get_the_author_meta('first_name', $author_id);
    $last_name = substr( get_the_author_meta( 'last_name', $author_id), 0, 1 ) . '.';
    $author  = $first_name . ' ' . $last_name;
  • Ash
    • WordPress Hacker

    Hello mircea

    $bid->post_author and $author_id both are variables. For any reason, in a specific case, values are same for those variables, that's why you are getting the same data. But what if the values are different?

    So, it's wise to use the variable that the theme originally used for that specific purpose. Change it like the following:

    $first_name = get_the_author_meta('first_name', $bid->post_author );
     $last_name = substr( get_the_author_meta( 'last_name', $bid->post_author ), 0, 1 ) . '.';
    $author  = $first_name . ' ' . $last_name;

    This would be correct code :slight_smile: Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

  • Ash
    • WordPress Hacker

    Great ! I tried to copy that php file on child theme folder 'includes' because its the same location on theme itself but it fails to work but only if I alter original file in theme. Is this normal ?

    Nope, it's not normal. A standard theme is designed in such way so that every file can be replaced within the child theme.

    I think for that file the theme is checking in the parent theme only. That's why the file is ignored.

    Also, please double check the file path is same. I mean, if the file path is in parent theme: /themes/parent/xx/yy/zz/includes/file.php and then in child theme it should be same in a standard theme: /themes/child/xx/yy/zz/includes/file.php

    Hope it helps! Please feel free to ask more questions if you have any.

    Have a nice day!

    Cheers,
    Ash

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.