=')) { return; } } deactivate_plugins(basename(__FILE__)); // Deactivate ourself wp_die("The base STC plugin must be activated before this plugin will run."); } register_activation_hook(__FILE__, 'stc_login_activation_check'); // add the section on the user profile page add_action('profile_personal_options','stc_login_profile_page'); function stc_login_profile_page($profile) { $options = get_option('stc_options'); ?> ID, 'twuid'); if (empty($twuid)) { ?>

Connected as

ID, 'twuid'); if ($twuid == $_POST['twuid']) { delete_usermeta($user->ID, 'twuid'); } echo 1; exit(); } add_action('stc_login_connect','stc_login_connect'); function stc_login_connect() { if (!is_user_logged_in()) return; // this only works for logged in users $user = wp_get_current_user(); $tw = stc_get_credentials(); if ($tw) { // we have a user, update the user meta update_usermeta($user->ID, 'twuid', $tw->screen_name); } } add_action('login_form','stc_login_add_login_button'); function stc_login_add_login_button() { global $action; if ($action == 'login') echo '

'.stc_get_connect_button('login').'


'; } add_filter('authenticate','stc_login_check'); function stc_login_check($user) { if ( is_a($user, 'WP_User') ) { return $user; } // check if user is already logged in, skip $tw = stc_get_credentials(); if ($tw) { global $wpdb; $twuid = $tw->screen_name; $user_id = $wpdb->get_var( $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'twuid' AND meta_value = '%s'", $twuid) ); if ($user_id) { $user = new WP_User($user_id); } else { do_action('stc_login_new_tw_user',$tw); // hook for creating new users if desired global $error; $error = 'ERROR: Twitter user not recognized.'; } } return $user; } add_action('wp_logout','stc_login_logout'); function stc_login_logout() { session_unset(); }