Skip to content

Instantly share code, notes, and snippets.

@mt8
Last active July 9, 2020 09:55
Show Gist options
  • Save mt8/dab1465dec701b6112b308076e892bc7 to your computer and use it in GitHub Desktop.
Save mt8/dab1465dec701b6112b308076e892bc7 to your computer and use it in GitHub Desktop.
[WordPress] #WordPress の #Auth0 プラグインで、Twitter認証したときにプロフィール名がカタカナだとWordPressユーザー作成に失敗してログインできない問題を回避する
<?php
add_filter( 'auth0_create_user_data', 'my_auth0_create_user_data' , 10, 2 );
function my_auth0_create_user_data( $user_data, $userinfo )
{
if ( ! is_null( $userinfo ) && is_object( $userinfo ) ) {
$identities = property_exists( $userinfo, 'identities' ) ? $userinfo->identities : [];
if ( is_array( $identities ) && ! empty( $identities ) ) {
$identitiy = $identities[0];
if ( ! is_null( $identitiy ) && is_object( $identitiy ) ) {
$provider = property_exists( $identitiy, 'provider' ) ? $identitiy->provider : '';
if ( 'twitter' == $provider ) {
//twitterのアカウント名@exampleをWordPressユーザー名にする
$user_data['user_login'] = $userinfo->screen_name;
}
}
}
}
return $user_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment