Also known as “How to hack your own website”.
Sometimes you need to log into WordPress as an administrator but don’t have the means to do so. Working for an agency at my 9-to-5, this happens all too often. The client, or potential client, wants you to do some work on their website but doesn’t have any information to allow you to help you help them. Asking for “control panel” access (aka: Plesk, cPanel, or something similar) is met with confused looks and/or mutterings, and all the client knows is “this is what I have for FTP access if I want to upload something”.
Disclaimer: Running code which automatically takes a site visitor and logs them in as a admin user is a potentially dangerous operation. Use this code at your own risk, obviously I accept no responsibility for anything that should happen from you using it.
Fortunately, access to the website via FTP is all you need to gain Administrator access to the WordPress admin area. All you need is a little code: