Skip to content

Commit 051856d

Browse files
authored
Merge pull request #237 from auth0/dev
3.2.5 - Lock 10 custom fields + added avatars + bugfixes
2 parents 8e8ec8f + 6c76aa2 commit 051856d

12 files changed

+160
-17
lines changed

WP_Auth0.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin Name: PLUGIN_NAME
44
* Description: PLUGIN_DESCRIPTION
5-
* Version: 3.2.4
5+
* Version: 3.2.5
66
* Author: Auth0
77
* Author URI: https://auth0.com
88
*/
@@ -12,7 +12,7 @@
1212
define( 'WPA0_PLUGIN_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
1313
define( 'WPA0_LANG', 'wp-auth0' );
1414
define( 'AUTH0_DB_VERSION', 11 );
15-
define( 'WPA0_VERSION', '3.2.4' );
15+
define( 'WPA0_VERSION', '3.2.5' );
1616

1717
/**
1818
* Main plugin class
@@ -48,6 +48,8 @@ public function init() {
4848

4949
add_action( 'activated_plugin', array( $this, 'on_activate_redirect' ) );
5050

51+
add_filter( 'get_avatar' , array( $this, 'my_custom_avatar') , 1 , 5 );
52+
5153
// Add an action to append a stylesheet for the login page.
5254
add_action( 'login_enqueue_scripts', array( $this, 'render_auth0_login_css' ) );
5355

@@ -155,6 +157,19 @@ function check_signup_status() {
155157
}
156158
}
157159

160+
function my_custom_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
161+
$auth0Profile = get_auth0userinfo($id_or_email);
162+
163+
if ($this->a0_options->get('override_wp_avatars')) {
164+
if ($auth0Profile && isset($auth0Profile->picture)) {
165+
$avatar_url = $auth0Profile->picture;
166+
$avatar = "<img alt='{$alt}' src='{$avatar_url}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
167+
}
168+
}
169+
170+
return $avatar;
171+
}
172+
158173
function on_activate_redirect( $plugin ) {
159174

160175
if ( $plugin == plugin_basename( __FILE__ ) ) {
@@ -296,6 +311,11 @@ public function render_verify_email_page($html, $userinfo, $id_token) {
296311
}
297312

298313
public function render_form( $html ) {
314+
315+
if ( isset( $_GET['action'] ) && $_GET['action'] == 'lostpassword' ) {
316+
return $html;
317+
}
318+
299319
$client_id = WP_Auth0_Options::Instance()->get( 'client_id' );
300320

301321
if ( trim( $client_id ) === '' ) {
@@ -390,7 +410,7 @@ function get_currentauth0userinfo() {
390410

391411
$current_user = wp_get_current_user();
392412

393-
$currentauth0_user = get_auth0userinfo($current_user);
413+
$currentauth0_user = get_auth0userinfo($current_user->ID);
394414

395415
return $currentauth0_user;
396416
}
@@ -428,3 +448,4 @@ function get_auth0_curatedBlogName() {
428448

429449
$a0_plugin = new WP_Auth0();
430450
$a0_plugin->init();
451+

lib/WP_Auth0_DBManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public function get_auth0_users( $user_ids = null ) {
162162
'compare' => 'IN',
163163
) );
164164
}
165+
$query['blog_id'] = 0;
165166

166167
$results = get_users( $query );
167168

lib/WP_Auth0_EditProfile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function override_email_update() {
332332
}
333333
wp_update_user( array(
334334
'ID' => $current_user->ID,
335-
'user_email' => $user_email,
335+
'user_email' => $user_email
336336
) );
337337

338338
if ($requires_verified_email) {

lib/WP_Auth0_Lock10_Options.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function build_settings( $settings ) {
128128
$options_obj['language'] = $settings['language'];
129129
}
130130
if (isset($settings['language_dictionary']) && !empty($settings['language_dictionary'])) {
131-
$options_obj['languageDictionary'] = $settings['language_dictionary'];
131+
$options_obj['languageDictionary'] = json_decode($settings['language_dictionary']);
132132
}
133133

134134
if ( isset( $settings['form_title'] ) && trim( $settings['form_title'] ) !== '' ) {
@@ -180,6 +180,19 @@ protected function build_settings( $settings ) {
180180
return $options_obj;
181181
}
182182

183+
public function get_custom_signup_fields() {
184+
$fields = $this->wp_options->get('custom_signup_fields');
185+
186+
if (trim($fields) === '') {
187+
return "[]";
188+
}
189+
190+
return $fields;
191+
}
192+
public function has_custom_signup_fields() {
193+
return $this->wp_options->get('custom_signup_fields');
194+
}
195+
183196
public function get_sso_options() {
184197
$options = $this->get_lock_options();
185198

@@ -188,7 +201,7 @@ public function get_sso_options() {
188201
if ( $this->get_auth0_implicit_workflow() ) {
189202
$options["callbackOnLocationHash"] = true;
190203
$options["callbackURL"] = $this->get_implicit_callback_url();
191-
$options["scope"] .= "name email nickname email_verified identities";
204+
$options["scope"] .= "name email picture nickname email_verified identities";
192205
} else {
193206
$options["callbackOnLocationHash"] = false;
194207
$options["callbackURL"] = $this->get_code_callback_url();
@@ -230,7 +243,9 @@ public function get_lock_options() {
230243
$extraOptions["auth"]["params"]["scope"] = "openid ";
231244

232245
if ( $this->get_auth0_implicit_workflow() ) {
233-
$extraOptions["auth"]["params"]["scope"] .= "name email nickname email_verified";
246+
$extraOptions["auth"]["params"]["scope"] .= "name email picture nickname email_verified";
247+
$extraOptions["auth"]["responseType"] = 'token';
248+
$extraOptions["auth"]["redirectUrl"] = $this->get_implicit_callback_url();
234249
} else {
235250
$extraOptions["auth"]["responseType"] = 'code';
236251
$extraOptions["auth"]["redirectUrl"] = $this->get_code_callback_url();

lib/WP_Auth0_LoginManager.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,29 @@ public function login_user( $userinfo, $id_token, $access_token ) {
403403
if ( ! is_null( $user ) ) {
404404
// User exists! Log in
405405
if ( isset( $userinfo->email ) && $user->data->user_email !== $userinfo->email ) {
406-
$user_id = wp_update_user( array( 'ID' => $user->data->ID, 'user_email' => $userinfo->email ) );
406+
407+
$description = $user->data->description;
408+
409+
if (empty($description)){
410+
if (isset($userinfo->headline)) {
411+
$description = $userinfo->headline;
412+
}
413+
if (isset($userinfo->description)) {
414+
$description = $userinfo->description;
415+
}
416+
if (isset($userinfo->bio)) {
417+
$description = $userinfo->bio;
418+
}
419+
if (isset($userinfo->about)) {
420+
$description = $userinfo->about;
421+
}
422+
}
423+
424+
$user_id = wp_update_user( array(
425+
'ID' => $user->data->ID,
426+
'user_email' => $userinfo->email,
427+
'description' => $description,
428+
) );
407429
}
408430

409431
$this->users_repo->update_auth0_object( $user->data->ID, $userinfo );

lib/WP_Auth0_Options.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ protected function defaults() {
7171
'language' => '',
7272
'language_dictionary' => '',
7373

74+
'custom_signup_fields' => '',
75+
7476
'social_big_buttons' => false,
7577
'username_style' => 'username',
7678
'extra_conf' => '',
@@ -92,6 +94,8 @@ protected function defaults() {
9294
'link_auth0_users' => null,
9395
'remember_users_session' => false,
9496

97+
'override_wp_avatars' => true,
98+
9599
'migration_ws' => false,
96100
'migration_token' => null,
97101
'migration_token_id' => null,

lib/WP_Auth0_Serializer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<?php
22
class WP_Auth0_Serializer {
33

4-
public static function serialize( $o ) {
4+
public static function serialize( $o )
5+
{
56
return json_encode( $o );
67
}
7-
public static function unserialize( $s ) {
8-
if ( $s[0] === '{' ) {
8+
9+
public static function unserialize( $s )
10+
{
11+
if (!is_string($s) || trim($s) === '')
12+
{
13+
return null;
14+
}
15+
16+
if ( $s[0] === '{' )
17+
{
918
return json_decode( $s );
1019
}
1120

lib/WP_Auth0_Users.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ public static function create_user( $userinfo, $role = null ) {
4646
while ( username_exists( $username ) ) {
4747
$username = $username . rand( 0, 9 );
4848
}
49+
50+
$description = '';
51+
52+
if (empty($description)){
53+
if (isset($userinfo->headline)) {
54+
$description = $userinfo->headline;
55+
}
56+
if (isset($userinfo->description)) {
57+
$description = $userinfo->description;
58+
}
59+
if (isset($userinfo->bio)) {
60+
$description = $userinfo->bio;
61+
}
62+
if (isset($userinfo->about)) {
63+
$description = $userinfo->about;
64+
}
65+
}
4966
// Create the user data array for updating first- and lastname
5067
$user_data = array(
5168
'user_email' => $email,
@@ -54,6 +71,7 @@ public static function create_user( $userinfo, $role = null ) {
5471
'first_name' => $firstname,
5572
'last_name' => $lastname,
5673
'display_name' => $username,
74+
'description' => $description,
5775
);
5876

5977
if ( $role ) {

lib/WP_Auth0_UsersRepo.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function create( $userinfo, $token, $access_token = null, $role = null, $
9494
$joinUser = get_user_by( 'email', $userinfo->email );
9595

9696
$auto_provisioning = WP_Auth0_Options::Instance()->get('auto_provisioning');
97-
$allow_signup = WP_Auth0_Options::Instance()->is_wp_registration_enabled() && $auto_provisioning;
97+
$allow_signup = WP_Auth0_Options::Instance()->is_wp_registration_enabled() || $auto_provisioning;
9898

9999
$user_id = null;
100100

@@ -148,7 +148,11 @@ public function create( $userinfo, $token, $access_token = null, $role = null, $
148148
public function find_auth0_user( $id ) {
149149
global $wpdb;
150150

151-
$users = get_users( array( 'meta_key' => $wpdb->prefix.'auth0_id', 'meta_value' => $id) );
151+
$users = get_users( array(
152+
'meta_key' => $wpdb->prefix.'auth0_id',
153+
'meta_value' => $id,
154+
'blog_id' => 0)
155+
);
152156

153157
if ( $users instanceof WP_Error ) {
154158
WP_Auth0_ErrorManager::insert_auth0_error( '_find_auth0_user', $userRow );

lib/admin/WP_Auth0_Admin_Advanced.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function init() {
5252
array( 'id' => 'wpa0_ip_range_check', 'name' => 'Enable on IP Ranges', 'function' => 'render_ip_range_check' ),
5353
array( 'id' => 'wpa0_ip_ranges', 'name' => 'IP Ranges', 'function' => 'render_ip_ranges' ),
5454
array( 'id' => 'wpa0_valid_proxy_ip', 'name' => 'Valid Proxy IP', 'function' => 'render_valid_proxy_ip' ),
55+
array( 'id' => 'wpa0_custom_signup_fields', 'name' => 'Custom signup fields', 'function' => 'render_custom_signup_fields' ),
5556
array( 'id' => 'wpa0_extra_conf', 'name' => 'Extra settings', 'function' => 'render_extra_conf' ),
5657
array( 'id' => 'wpa0_auth0_server_domain', 'name' => 'Auth0 server domain', 'function' => 'render_auth0_server_domain' ),
5758
array( 'id' => 'wpa0_metrics', 'name' => 'Anonymous data', 'function' => 'render_metrics' ),
@@ -134,6 +135,36 @@ public function render_extra_conf() {
134135
</span>
135136
</div>
136137
<?php
138+
}
139+
140+
public function render_custom_signup_fields() {
141+
$v = $this->options->get( 'custom_signup_fields' );
142+
?>
143+
144+
<textarea name="<?php echo $this->options->get_options_name(); ?>[custom_signup_fields]" id="wpa0_custom_signup_fields"><?php echo esc_attr( $v ); ?></textarea>
145+
<div class="subelement">
146+
<span class="description">
147+
<?php echo __( 'This field is the Json that describes the custom signup fields for lock. It should be a valida json and allows the use of functions (for validation). More info', WPA0_LANG ); ?>
148+
<a target="_blank" href="https://auth0.com/docs/libraries/lock/v10/new-features#custom-sign-up-fields"><?php echo __( 'here', WPA0_LANG ); ?></a>
149+
150+
<code><pre>[
151+
{
152+
name: "address", // required
153+
placeholder: "enter your address", // required
154+
icon: "https://example.com/address_icon.png", // optional
155+
prefill: "street 123", // optional
156+
validator: function(value) { // optional
157+
// only accept addresses with more than 10 chars
158+
return value.length > 10;
159+
}
160+
},
161+
{
162+
... // more fields could be specified
163+
}
164+
]</pre></code>
165+
</span>
166+
</div>
167+
<?php
137168
}
138169

139170
public function render_link_auth0_users() {
@@ -154,8 +185,8 @@ public function render_auto_provisioning() {
154185
?>
155186

156187
<div class="subelement">
157-
<span class="description"><?php echo __( 'The plugin will automatically add new users if they do not exist in the WordPress database.(Even with signups disabled, the plugin will create users if they already exists in your Auth0 account, enabling this setting will disable this behaviour).', WPA0_LANG ); ?></span>
158-
</div>
188+
<span class="description"><?php echo __( 'The plugin will automatically add new users if they do not exist in the WordPress database if the signups are enabled (enabling this setting will enable this behaviour when signups are disabled).', WPA0_LANG ); ?></span>
189+
</div>
159190
<?php
160191
}
161192

@@ -280,7 +311,8 @@ public function render_ip_ranges() {
280311
?>
281312
<textarea cols="25" name="<?php echo $this->options->get_options_name(); ?>[ip_ranges]" id="wpa0_ip_ranges"><?php echo esc_textarea( $v ); ?></textarea>
282313
<div class="subelement">
283-
<span class="description"><?php echo __( 'Only one range per line! Range format should be as follows: <code>xx.xx.xx.xx - yy.yy.yy.yy</code> (spaces will be trimmed)', WPA0_LANG ); ?></span>
314+
<span class="description"><?php echo __( 'Only one range per line! Range format should be as follows (spaces will be trimmed):', WPA0_LANG ); ?></span>
315+
<code>xx.xx.xx.xx - yy.yy.yy.yy</code>
284316
</div>
285317
<?php
286318
}
@@ -399,8 +431,9 @@ public function basic_validation( $old_options, $input ) {
399431
$input['jwt_auth_integration'] = ( isset( $input['jwt_auth_integration'] ) ? $input['jwt_auth_integration'] : 0 );
400432
$input['auth0_implicit_workflow'] = ( isset( $input['auth0_implicit_workflow'] ) ? $input['auth0_implicit_workflow'] : 0 );
401433
$input['metrics'] = ( isset( $input['metrics'] ) ? $input['metrics'] : 0 );
434+
$input['use_lock_10'] = ( isset( $input['use_lock_10'] ) ? $input['use_lock_10'] : 0 );
402435
$input['default_login_redirection'] = esc_url_raw( $input['default_login_redirection'] );
403-
436+
404437
if ( isset( $input['connections'] ) ) {
405438
if ( isset( $input['connections']['social_twitter_key'] ) ) $input['connections']['social_twitter_key'] = sanitize_text_field( $input['connections']['social_twitter_key'] );
406439
if ( isset( $input['connections']['social_twitter_secret'] ) ) $input['connections']['social_twitter_secret'] = sanitize_text_field( $input['connections']['social_twitter_secret'] );
@@ -414,6 +447,7 @@ public function basic_validation( $old_options, $input ) {
414447
$input['valid_proxy_ip'] = ( isset( $input['valid_proxy_ip'] ) ? $input['valid_proxy_ip'] : null );
415448

416449
$input['lock_connections'] = trim( $input['lock_connections'] );
450+
$input['custom_signup_fields'] = trim( $input['custom_signup_fields'] );
417451

418452
if ( $input['passwordless_enabled'] && empty( $input['lock_connections'] ) && strpos( strtolower( $input['passwordless_method'] ), 'social' ) !== false ) {
419453
$error = __( "Please complete the list of connections to be used by Lock in social mode.", WPA0_LANG );

0 commit comments

Comments
 (0)