• Resolved Mark Howells-Mead

    (@markhowellsmead)


    I have a WP CLI script which migrates a site into a staging environment, and all that’s missing is that it should install this plugin (if not installed), activate it and set a password. Do you have any experience of doing this? I’d be grateful of a pointer how to set a password. For example, using bash to convert a password to MD5 and then storing it in the database as a meta entry doesn’t seem to work.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Have you tried finding what option is used for the password and then setting it with the wp option group of commands?

    Also, would love to see that code, if it’s public ??

    Thread Starter Mark Howells-Mead

    (@markhowellsmead)

    Yes, that was the method I mentioned didn’t work.

    Ahh, you are probably running into an issue with the hash’s trailing characters. I don’t know why they do that. I tested this in the command line and it updated the password correctly. I had set one up initially, so that may be your issue, since the option did not exist right after installing the plugin. At least the database got updated as expected with the expected characters ??

    wp option update password_protected_password $(echo -n "pass" | md5sum | cut -d " " -f 1 | tr -d "\n")

    Best of luck.

    Thread Starter Mark Howells-Mead

    (@markhowellsmead)

    Not sure why it needed that, but it works ?? Setting the other options — password_protected_status etc. — works fine with the regular method. Thanks for your suggestion!

    The script information for cloning a site is here: https://permanenttourist.ch/2021/02/how-to-clone-a-wordpress-website-with-wp-cli-and-rsync/

    What happens is that echo -n "pass" | md5sum outputs

    1a1dc91c907325c69271ddf0c944bc72 –

    so the rest of the command strips out every thing after the hash. I tried to figure out how to have md5sum not do that, but better to just cut it out ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to activate and set password using WP CLI’ is closed to new replies.