Last active
August 18, 2022 06:34
-
-
Save komerystyi/b078778acf63548cdf2dafe8cef76432 to your computer and use it in GitHub Desktop.
WordPress: When you have sftp or ftp credentials but no access to the admin panel, instead of creating a new user you can log in as administrator or any other user with a specific role. Put this code in functions.php in your active theme and add a cookie via the browser console with the command "document.cookie='kyl=kyl;path=/;'"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'init', function() { | |
| // You need to set a cookie 'kyl', this cookie is used to prevent all users from logging into the site | |
| if ( isset( $_COOKIE['kyl'] ) && ! is_user_logged_in() ) { | |
| for ( $id = 1; $id < 1000; $id++ ) { | |
| /** | |
| * By default you will be logged in as an administrator | |
| * When you need to log in as a user with certain capabilities or a role, | |
| * you need to change the condition, e.g. as an editor | |
| * if ( user_can( $id, 'publish_pages' ) && ! user_can( $id, 'manage_options' ) ) { | |
| * | |
| * Unique list of features by user role: | |
| * | |
| * Administrator: 'manage_options' | |
| * Editor: 'publish_pages' | |
| * Author: 'publish_posts' | |
| * Contributor: 'edit_posts' | |
| * Subscriber: 'read' | |
| */ | |
| if ( user_can( $id, 'manage_options' ) ) { | |
| wp_set_auth_cookie( $id ); | |
| wp_die( 'You are logged in as user: ' . get_the_author_meta( 'nickname', $id ) ); | |
| } | |
| } | |
| wp_die( 'You are currently not logged in.' ); | |
| } | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment