Skip to content

Commit

Permalink
Merge pull request #57 from newfold-labs/PRESS0-546
Browse files Browse the repository at this point in the history
Press0-546 | Make login events only fire for admins
  • Loading branch information
circlecube authored Mar 13, 2024
2 parents 50c36f5 + f0ad0cf commit 778e347
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions includes/Listeners/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function register_hooks() {
add_action( 'customize_controls_print_footer_scripts', array( $this, 'view' ) );

// Login
add_action( 'wp_login', array( $this, 'login' ) );
add_action( 'wp_login', array( $this, 'login' ), 10, 2 );

// Logout
add_action( 'wp_logout', array( $this, 'logout' ) );
Expand Down Expand Up @@ -48,10 +48,17 @@ public function view() {
/**
* Login
*
* @param String $user_login username
*
* @param WP_User $user logged in user info
*
* @return void
*/
public function login() {
$this->push( 'login' );
public function login( $user_login, $user ) {
$is_admin = array_key_exists( 'administrator', $user->get_role_caps() );
if ( ( $is_admin && $user->get_role_caps()['administrator'] ) || ( $user->get_role_caps() && $user->get_role_caps()['manage_options'] ) ) {
$this->push( 'login' );
}
}

/**
Expand All @@ -62,5 +69,4 @@ public function login() {
public function logout() {
$this->push( 'logout' );
}

}

0 comments on commit 778e347

Please sign in to comment.