type: update name: Instant Login description: Login to your WordPress site as an administrator with a single click. targetNodes: nodeGroup: cp onInstall: cmd[${nodes.cp.master.id}]: - cd /var/www/webroot/ROOT/ - wp package install aaemnnosttv/wp-cli-login-command - mkdir -p /var/www/webroot/ROOT/wp-content/mu-plugins - cd /var/www/webroot/ROOT/wp-content/mu-plugins - wget https://raw.githubusercontent.com/aaemnnosttv/wp-cli-login-server/master/wp-cli-login-server.php setGlobals: userToLoginAs: 1 onUninstall: cmd[${nodes.cp.master.id}]: rm -f /var/www/webroot/ROOT/wp-content/mu-plugins/wp-cli-login-server.php actions: instant_login: cmd[${nodes.cp.master.id}]: - cd /var/www/webroot/ROOT/ - wp login create ${globals.userToLoginAs} --url-only #- user=$(wp user list --field=user_login --format=csv) #- wp login create $user --url-only return: type: success message: | [Click to login as user ${globals.userToLoginAs}](${response.out}) *(Link will expire in 15 minutes)* save_config: cmd[${nodes.cp.master.id}]: - cd /var/www/webroot/ROOT/ - user=$(wp user get ${settings.userToLoginAs} --field=ID) # see if number (user ID) returned or not. Return 1 if yes. - re='^[0-9]+$' - if ! [[ $user =~ $re ]]; then echo 0; else echo 1; fi #check if the user was found # returns ID if so # returns 'Error: Invalid user ID, email or login: '24342'' if (response.out == 0): return: type: error message: User '${settings.userToLoginAs}' not found. Try again. else: setGlobals: userToLoginAs: ${settings.userToLoginAs} return: type: success message: | settings.userToLoginAs: ${settings.userToLoginAs} globals.userToLoginAs: ${globals.userToLoginAs} settings: configure: fields: - type: string name: userToLoginAs caption: User to login as placeholder: Enter user ID, user email, or user login buttons: - caption: Instant Login loadingText: Generating login... confirmText: Generate a login link for the configured user? This will log you out of any existing sessions. action: instant_login - caption: Configure action: save_config settings: configure # problem - only saves the user name/id/email on initial creation. Since adding custom code to save_config, it will not update with new user value after saving again # tried to use setGlobals but doesn't seem like that works any better #SOLUTION: Combine these two options into one button - the button shows the input form, filled out with the username that was previously used. Then upon saving, it checks to see if that's a real user and if so it generates the login for that user.