Skip to content

Commit 92748df

Browse files
committed
Avoid filtering solution and just swp from deprecated to new
1 parent 358c265 commit 92748df

File tree

1 file changed

+2
-41
lines changed

1 file changed

+2
-41
lines changed

src/User_Command.php

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ class User_Command extends CommandWithDBObject {
5050
'name',
5151
];
5252

53-
/** Intermediate storage for a BC filter */
54-
private $value_for_spam;
55-
5653
public function __construct() {
5754
$this->fetcher = new UserFetcher();
5855
$this->sitefetcher = new SiteFetcher();
@@ -1234,27 +1231,8 @@ private function update_msuser_status( $user_ids, $pref, $value ) {
12341231
}
12351232

12361233
if ( Utils\wp_version_compare( '5.3', '<' ) ) {
1237-
/*
1238-
* Provide fallback for WP < 5.3 so as to use the preferred
1239-
* method wp_update_user().
1240-
* See https://core.trac.wordpress.org/ticket/45747
1241-
*/
1242-
$this->value_for_spam = $value;
1243-
add_filter( 'wp_pre_insert_user_data', [ $this, 'set_spam_value' ], 10, 3 );
1244-
wp_update_user(
1245-
[
1246-
'ID' => $user_id,
1247-
$pref => $value,
1248-
]
1249-
);
1250-
remove_filter( 'wp_pre_insert_user_data', [ $this, 'set_spam_value' ], 10 );
1251-
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- We want to fake Core actions.
1252-
if ( 1 === (int) $value ) {
1253-
do_action( 'make_spam_user', $user_id );
1254-
} else {
1255-
do_action( 'make_ham_user', $user_id );
1256-
}
1257-
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
1234+
// phpcs:ignore WordPress.WP.DeprecatedFunctions.update_user_statusFound -- Fallback for older versions.
1235+
update_user_status( $user_id, $pref, $value );
12581236
} else {
12591237
wp_update_user(
12601238
[
@@ -1271,23 +1249,6 @@ private function update_msuser_status( $user_ids, $pref, $value ) {
12711249
Utils\report_batch_operation_results( 'user', $verb, count( $user_ids ), $successes, $errors );
12721250
}
12731251

1274-
/**
1275-
* Filter the user data to provide support spam user data value.
1276-
*
1277-
* This is only needed on WP < 5.3.
1278-
*
1279-
* See https://core.trac.wordpress.org/ticket/45747
1280-
*
1281-
* @param array $data Associative array of user data.
1282-
* @param bool $update Whether this is an update or a new user.
1283-
* @param int|null $id ID of the user in case of an update, null if not.
1284-
* @return array Modified associative array of user data.
1285-
*/
1286-
public function set_spam_value( $data, $update, $id ) {
1287-
$data['spam'] = $this->value_for_spam;
1288-
return $data;
1289-
}
1290-
12911252
/**
12921253
* Checks if a user's password is valid or not.
12931254
*

0 commit comments

Comments
 (0)