Drush provides an API that allows developers to write their own commands. These commands can be part of a module and loaded through a Drupal installation, or they can be placed in the local user's Drush folder for general purposes.
Often, contributed modules create commands to automate user interface operations. However, creating a custom Drush command can be useful for specific operations. In this recipe, we will create a command that loads all the users who have not logged in in the last 10 days and resets their password.
For this recipe, you will need Drush available. We will be creating a command in a local user directory.
- Create a file named
disable_users.drush.inc
in the~/.drush
folder for your user:
<?php /** * @file * Loads all users who have not logged in within 10 days and disables them. */
- Add the Drush command hook that will allow Drush to discover our commands provided by the file:
/** * Implements hook_drush_command(). ...