Wordpress: starting the function after login to check if the user is a subscriber

I am developing an application in Wordpress. I would like to check after logging in with OAuth with Twitch TV if the user is a subscriber to the channel for role assignment. I think this can be done using the Twitch API calling the object with the user, and then checking if this user is a suppressor with a different GET, but if I print $ twitchuser and $ suscript are not valid. I'm new to PHP, do you know where the error is or if there is any other approach? My function is included at the end of the wp-includes / user.php file:

function your_function() {
// Check if the user is Twitch suscriptor

 if ( !is_super_admin() ) {
    $twitchuser = $_GET["https://api.twitch.tv/kraken/user"];
    $twitchname = $twitchuser['name'];

    $suscript = $_GET["https://api.twitch.tv/kraken/channels/mychannel/subscriptions/{$twitchname}"];

    if ($suscript == "404 Not Found") {
        $current_user = wp_get_current_user();
        // Remove role
        $u->remove_role( 'subscriber' );
        // Add role
        $u->add_role( 'nomember' );
    }
 }
}
add_action('wp_login', 'your_function');
+4
source share

All Articles