Support » Developing with WordPress » update_user_meta() usage is highly discouraged

  • Resolved siddhartha

    (@siddhartha10jun)



    update_user_meta() usage is highly discouraged, check VIP documentation on Working with wp_users

    i got this error in theme sniffer plugin how i can resolve

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Well, you could update the usermeta table directly by using $wpdb object methods like $wpdb->update(). Then you are not using update_user_meta(). I’m not sure you are gaining anything though, it sort of amounts to the same thing. The only other alternative is don’t use user meta at all for storing user data. Except that’s what the table is there for.

    I don’t understand why it’s discouraged. It’s not that simple. Used appropriately, there’s nothing wrong with the function. Like most things, it can be misused to the detriment of performance. What does the VIP documentation on Working with wp_users have to say on the subject?

    siddhartha

    (@siddhartha10jun)

    Thanks

    The message comes from the WordPress Coding Standards. They link to this page: https://vip.wordpress.com/documentation/vip/code-review-what-we-look-for/#working-with-wp_users-and-user_meta, which doesn’t appear to exist anymore.

    Searching for “Working with wp_users” on Google returns this URL: https://vip.wordpress.com/documentation/code-review-what-we-look-for/, but it appears to be private.

    Searching the coding standards repo turns up this issue which proposed flagging the use of user meta for this reason:

    This table is huge on WordPress.com and queries on it can easily cause performance issues. This includes doing any JOIN or meta operations against this set of tables.

    For storing user additional user metadata, you should look at User Attributes.

    Further searching revealed the responsible code was in the WordPress/Sniffs/VIP/RestrictedFunctionsSniff.php file.

    Note that the original proposal mentions WordPress.com, and that the file responsible for the message is in the VIP folder. This means that the issue is specific to the WordPress.com VIP coding standards, and is for reasons that are specific to that service.

    Are you developing for WordPress.com VIP? If you are you should be able to access the link above for the documentation on what you’re supposed to do. If you’re not then you shouldn’t be sniffing your theme with the WordPress-VIP coding standards.

    • This reply was modified 2 months, 2 weeks ago by  Jacob Peattie.
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.