Comments (1)
Hi @scrobbleme,
Not sure if you're still looking for this to work, but we are doing something similar to what you're asking for. In our case, we want to check users who haven't logged in for a while and then deactivate them.
The functionality doesn't really seem central to what this plugin is about, but rather it provides the concept of "enable/disable" and then you can do what you want with it. To disable users, you want to grab the user meta key and then set it to true.
Here's some code that would do what you're asking
public function disableUsers(): void
{
// get the plugin
$loginPlugin = SSDUL();
// get all user ids
$users = get_users(array( 'fields' => array( 'id' ) ));
$user_ids = array_map(function ($users) {
return $users->id;
}, $users);
// remove superadmins
$user_ids = array_filter(
$user_ids,
function ($user_id) {
return ! is_super_admin($user_id);
}
);
foreach ($user_ids as $user_id) {
$disabled = true;
$originally_disabled = get_user_meta($user_id, $loginPlugin->user_meta_key(), true);
// Update the user's disabled status
update_user_meta($user_id, $loginPlugin->user_meta_key(), $disabled);
// Trigger an action when a user's account is enabled
if (!$originally_disabled) {
do_action('disable_user_login.user_disabled', $user_id);
}
}
}
Hope that helps!
from disable-user-login.
Related Issues (8)
- Synchronization with the database HOT 3
- [Feature Request] Custom message via control panel
- Cross-Site Forgery Request Issue
- Create a new "release" tag for version 1.3.2 HOT 1
- Disable Application passwords HOT 1
- Wipe all capabilities and disable password reset for the user
- Add quick action to disable a user on users table HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from disable-user-login.