Make WordPress Core


Ignore:
Timestamp:
02/17/2026 05:48:04 AM (7 months ago)
Author:
westonruter
Message:

Users: Ensure user data supplied to wp_insert_user() is normalized to an array.

This fixes an issue where PHPStan hangs when analyzing the containing users.php file.

Developed in https://github.com/WordPress/wordpress-develop/pull/10953

Follow-up to [60650].

Props westonruter, justlevine, peterwilsoncc.
See #64238, #61175.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r61644 r61656  
    22102210        } elseif ( $userdata instanceof WP_User ) {
    22112211                $userdata = $userdata->to_array();
     2212        } elseif ( $userdata instanceof Traversable ) {
     2213                $userdata = iterator_to_array( $userdata );
     2214        } elseif ( $userdata instanceof ArrayAccess ) {
     2215                $userdata_obj = $userdata;
     2216                $userdata     = array();
     2217                foreach (
     2218                        array(
     2219                                'ID',
     2220                                'user_pass',
     2221                                'user_login',
     2222                                'user_nicename',
     2223                                'user_url',
     2224                                'user_email',
     2225                                'display_name',
     2226                                'nickname',
     2227                                'first_name',
     2228                                'last_name',
     2229                                'description',
     2230                                'rich_editing',
     2231                                'syntax_highlighting',
     2232                                'comment_shortcuts',
     2233                                'admin_color',
     2234                                'use_ssl',
     2235                                'user_registered',
     2236                                'user_activation_key',
     2237                                'spam',
     2238                                'show_admin_bar_front',
     2239                                'role',
     2240                                'locale',
     2241                                'meta_input',
     2242                        ) as $key
     2243                ) {
     2244                        if ( isset( $userdata_obj[ $key ] ) ) {
     2245                                $userdata[ $key ] = $userdata_obj[ $key ];
     2246                        }
     2247                }
     2248        } else {
     2249                $userdata = (array) $userdata;
    22122250        }
    22132251
     
    22452283        }
    22462284
    2247         $sanitized_user_login = sanitize_user( $userdata['user_login'], true );
     2285        $sanitized_user_login = sanitize_user( $userdata['user_login'] ?? '', true );
    22482286
    22492287        /**
Note: See TracChangeset for help on using the changeset viewer.