Skip to content

Commit

Permalink
Remove deprecated from WP_Auth0_UsersRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed Dec 6, 2019
1 parent cc96137 commit 58eb756
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions lib/WP_Auth0_UsersRepo.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
<?php

/**
* Contains class WP_Auth0_UsersRepo.
*
* @package WP-Auth0
*
* @since 1.2.0
*/

/**
* Class WP_Auth0_UsersRepo.
*/
class WP_Auth0_UsersRepo {

/**
* Options instance used in this class.
*
* @var WP_Auth0_Options
*/
protected $a0_options;

/**
* WP_Auth0_UsersRepo constructor.
*
* @param WP_Auth0_Options $a0_options - Options instance used in this class.
*/
public function __construct( WP_Auth0_Options $a0_options ) {
$this->a0_options = $a0_options;
}

/**
* Create or join a WP user with an incoming Auth0 one or reject with an exception.
*
* @param object $userinfo - Profile object from Auth0.
* @param string $token - ID token from Auth0.
* @param null|string $access_token - @deprecated - 3.8.0.
* @param null|string $role - @deprecated - 3.8.0.
* @param bool $skip_email_verified - @deprecated - 3.8.0.
* @param object $userinfo - Profile object from Auth0.
* @param string $token - ID token from Auth0.
*
* @return int|null|WP_Error
*
* @throws WP_Auth0_CouldNotCreateUserException
* @throws WP_Auth0_EmailNotVerifiedException
* @throws WP_Auth0_RegistrationNotEnabledException
* @throws WP_Auth0_CouldNotCreateUserException - When the user could not be created.
* @throws WP_Auth0_EmailNotVerifiedException - When a users's email is not verified but the site requires it.
* @throws WP_Auth0_RegistrationNotEnabledException - When registration is not turned on for this site.
*/
public function create( $userinfo, $token, $access_token = null, $role = null, $skip_email_verified = false ) {

if ( func_num_args() > 2 ) {
// phpcs:ignore
@trigger_error(
sprintf(
__( '$access_token, $role, and $skip_email_verified params are deprecated.', 'wp-auth0' ),
__METHOD__
),
E_USER_DEPRECATED
);
}
public function create( $userinfo, $token ) {

$auth0_sub = $userinfo->sub;
list($strategy) = explode( '|', $auth0_sub );
$opts = WP_Auth0_Options::Instance();
$wp_user = null;
$user_id = null;

Expand All @@ -55,8 +60,7 @@ public function create( $userinfo, $token, $access_token = null, $role = null, $

// Email is considered verified if flagged as such, if we ignore the requirement, or if the strategy is skipped.
$email_verified = ! empty( $userinfo->email_verified )
|| $skip_email_verified
|| $opts->strategy_skips_verified_email( $strategy );
|| $this->a0_options->strategy_skips_verified_email( $strategy );

// WP user to join with incoming Auth0 user.
if ( ! empty( $userinfo->email ) ) {
Expand All @@ -77,11 +81,11 @@ public function create( $userinfo, $token, $access_token = null, $role = null, $
if ( ! empty( $current_auth0_id ) && $auth0_sub !== $current_auth0_id ) {
throw new WP_Auth0_CouldNotCreateUserException( __( 'There is a user with the same email.', 'wp-auth0' ) );
}
} elseif ( $opts->is_wp_registration_enabled() || $opts->get( 'auto_provisioning' ) ) {
} elseif ( $this->a0_options->is_wp_registration_enabled() || $this->a0_options->get( 'auto_provisioning' ) ) {
// WP user does not exist and registration is allowed.
$user_id = WP_Auth0_Users::create_user( $userinfo, $role );
$user_id = WP_Auth0_Users::create_user( $userinfo );

// Check if user was created
// Check if user was created.
if ( is_wp_error( $user_id ) ) {
throw new WP_Auth0_CouldNotCreateUserException( $user_id->get_error_message() );
} elseif ( -2 === $user_id ) {
Expand All @@ -103,7 +107,7 @@ public function create( $userinfo, $token, $access_token = null, $role = null, $
/**
* Look for and return a user with an Auth0 ID
*
* @param string $id - An Auth0 user ID, like "provider|id"
* @param string $id - An Auth0 user ID, like "provider|id".
*
* @return null|WP_User
*/
Expand Down

0 comments on commit 58eb756

Please sign in to comment.