Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6767295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:56:02+00:00 2026-05-26T14:56:02+00:00

On my website, I have user accounts that are configurable with forms that allow

  • 0

On my website, I have user accounts that are configurable with forms that allow users to update everything from first and last names to privacy settings. I use the following function to update the database with that input. (Note that the following code uses WordPress-specific features.)

function update_account() {
    global $current_user; get_currentuserinfo();
    require_once( ABSPATH . WPINC . '/registration.php' );

    $uid = $current_user->ID;

    // First Name
    if(isset($_POST['first_name']) && $_POST['first_name'] <> $current_user->first_name) {
        wp_update_user( array( 
            'ID' => $uid, 'first_name' => esc_attr($_POST['first_name'])
        ));
    }

    // ...and so on 43 more times...

}

This feels like the wrong way to process forms. This also looks like it will negatively impact server performance when there are multiple users and frequent updates, given that the if-then-else conditions for every field, even fields not on a particular page, force checking each field for input.

Moreover, since form data can be expected to remain relatively constant, I added the <> operator to prevent the function from updating fields where there has not been any change, but I suspect this also means that every field is still evaluated for change. To make matters worse, adding new fields — there are already 44 fields in total — is an unwieldy process.

What’s a better way to process form data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:56:03+00:00Added an answer on May 26, 2026 at 2:56 pm

    Keep an array of the fields you will be processing with this code, and iterate over it. This works if all your attributes are strings, for example. If you have different data types such as boolean flags to handle differently from the strings, you may wish to group them into their own array.

    // All the fields you wish to process are in this array
    $fields = array('first_name', 'last_name', 'others',...'others99');
    
    // Loop over the array and process each field with the same block
    foreach ($fields as $field) {
        if(isset($_POST[$field]) && $_POST[$field] != $current_user->{$field}) {
            wp_update_user( array( 
                'ID' => $uid, $field => esc_attr($_POST[$field])
            ));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that's using forms authentication and membership. A user must have
I have a website that requires some secure pages for logging in, user accounts,
So, I have a user driven website. Users can post whatever they want, even
I have a website that allows a user to upload a spreadsheet of items
I have a website going that takes a user's uploaded image, and makes three
I have a website that holds a dictionary of data sets. When a user
Right now I have a website that only accepts OpenIDs. Each user's account is
So, I have a website that figures out the users location when they load
I have a fully functioning website with user accounts/profiles and admin area. I would
We currently have a website that has user account functionality, but we are looking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.