• Hi – I have a use case (password protected FAQ) for which I’d like to automatically generate links via wp-cli.
    Do you have a suggestions for the wp-cli <-> autologin-links shim?
    It looks like a call to pkg_autologin_generate_code() followed by the wp_usermetadata update is all that’s needed?
    If you think this is helpful, I’m happy to submit a PR.

    TIA,

Viewing 1 replies (of 1 total)
  • Plugin Author WPAutoLogin

    (@wpautologin)

    Since you are already in the weeds this is easy for me to answer, thanks for doing your own research! Yes, updating the meta data is the last thing you need to do. This is the section of the plugin you might be interested in:

    
          if (!add_user_meta($user_id, PKG_AUTOLOGIN_USER_META_KEY, $cleanedKey, True)) {
            if (!update_user_meta($user_id, PKG_AUTOLOGIN_USER_META_KEY, $cleanedKey)) {
              // Check if the key was changed at all - if not this is an error of update_user_meta
              if (get_user_meta($user_id, PKG_AUTOLOGIN_USER_META_KEY, True) != $cleanedKey) {
                wp_die(__('Failed to update autologin link.', PKG_AUTOLOGIN_LANGUAGE_DOMAIN));
              }
            }
          }
    

    So just set the code for the user and you are done! I consider the functions pkg_autologin_generate_code() as well as the constants like PKG_AUTOLOGIN_USER_META_KEY public API, so those should not change in the foreseeable future. Good luck with implementing (if you did not already do it).

Viewing 1 replies (of 1 total)
  • The topic ‘Automatically generate links via wp-cli’ is closed to new replies.