<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[51399] trunk/src/wp-includes/user.php: Coding Standards: Rename the `$ID` variable to `$user_id` in `wp_insert_user()` and `wp_update_user()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/51399">51399</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/51399","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-07-10 12:20:55 +0000 (Sat, 10 Jul 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Coding Standards: Rename the `$ID` variable to `$user_id` in `wp_insert_user()` and `wp_update_user()`.
This fixes a "Variable `$ID` is not in valid snake_case format" WPCS warning.
Follow-up to <a href="https://core.trac.wordpress.org/changeset/2872">[2872]</a>.
See <a href="https://core.trac.wordpress.org/ticket/53359">#53359</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesuserphp">trunk/src/wp-includes/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/user.php 2021-07-10 12:00:01 UTC (rev 51398)
+++ trunk/src/wp-includes/user.php 2021-07-10 12:20:55 UTC (rev 51399)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1773,9 +1773,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Are we updating or creating?
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $userdata['ID'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $ID = (int) $userdata['ID'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_id = (int) $userdata['ID'];
</ins><span class="cx" style="display: block; padding: 0 10px"> $update = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $old_user_data = get_userdata( $ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $old_user_data = get_userdata( $user_id );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! $old_user_data ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2031,10 +2031,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * the current UTC timestamp.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $update Whether the user is being updated rather than created.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int|null $id ID of the user to be updated, or NULL if the user is being created.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int|null $user_id ID of the user to be updated, or NULL if the user is being created.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @param array $userdata The raw array of data passed to wp_insert_user().
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? (int) $ID : null ), $userdata );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = apply_filters( 'wp_pre_insert_user_data', $data, $update, ( $update ? $user_id : null ), $userdata );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $data ) || ! is_array( $data ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'empty_data', __( 'Not enough data to create this user.' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2044,8 +2044,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $user_email !== $old_user_data->user_email || $user_pass !== $old_user_data->user_pass ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $data['user_activation_key'] = '';
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $wpdb->update( $wpdb->users, $data, compact( 'ID' ) );
- $user_id = (int) $ID;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $wpdb->update( $wpdb->users, $data, array( 'ID' => $user_id ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> } else {
</span><span class="cx" style="display: block; padding: 0 10px"> $wpdb->insert( $wpdb->users, $data );
</span><span class="cx" style="display: block; padding: 0 10px"> $user_id = (int) $wpdb->insert_id;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2177,13 +2176,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $userdata = $userdata->to_array();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $ID = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
- if ( ! $ID ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_id = isset( $userdata['ID'] ) ? (int) $userdata['ID'] : 0;
+ if ( ! $user_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // First, get all of the original fields.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user_obj = get_userdata( $ID );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user_obj = get_userdata( $user_id );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $user_obj ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2192,7 +2191,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Add additional custom fields.
</span><span class="cx" style="display: block; padding: 0 10px"> foreach ( _get_additional_user_keys( $user_obj ) as $key ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $user[ $key ] = get_user_meta( $ID, $key, true );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $user[ $key ] = get_user_meta( $user_id, $key, true );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Escape data pulled from DB.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2373,7 +2372,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Update the cookies if the password changed.
</span><span class="cx" style="display: block; padding: 0 10px"> $current_user = wp_get_current_user();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $current_user->ID == $ID ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( $current_user->ID == $user_id ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $plaintext_pass ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> wp_clear_auth_cookie();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2381,13 +2380,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // If it's greater than this, then we know the user checked 'Remember Me' when they logged in.
</span><span class="cx" style="display: block; padding: 0 10px"> $logged_in_cookie = wp_parse_auth_cookie( '', 'logged_in' );
</span><span class="cx" style="display: block; padding: 0 10px"> /** This filter is documented in wp-includes/pluggable.php */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $ID, false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $default_cookie_life = apply_filters( 'auth_cookie_expiration', ( 2 * DAY_IN_SECONDS ), $user_id, false );
</ins><span class="cx" style="display: block; padding: 0 10px"> $remember = false;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false !== $logged_in_cookie && ( $logged_in_cookie['expiration'] - time() ) > $default_cookie_life ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $remember = true;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_auth_cookie( $ID, $remember );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_auth_cookie( $user_id, $remember );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2550,8 +2549,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.7.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool $allow Whether to allow the password to be reset. Default true.
- * @param int $ID The ID of the user attempting to reset a password.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool $allow Whether to allow the password to be reset. Default true.
+ * @param int $user_id The ID of the user attempting to reset a password.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> $allow = apply_filters( 'allow_password_reset', $allow, $user->ID );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>