=') && version_compare($wp_version, '2.6', '<')) { add_action( 'init', 'wp25_login_openid' ); } /** * If we're doing openid authentication ($_POST['openid_identifier'] is set), start the consumer & redirect * Otherwise, return and let WordPress handle the login and/or draw the form. * * @param string $credentials username and password provided in login form */ function openid_wp_authenticate(&$credentials) { if (!empty($_POST['openid_identifier'])) { $finish_url = $_REQUEST['redirect_to']; openid_start_login($_POST['openid_identifier'], 'login', $finish_url); // if we got this far, something is wrong global $error; $error = openid_message(); } } /** * Setup OpenID errors to be displayed to the user. */ function openid_login_errors() { $self = basename( $GLOBALS['pagenow'] ); if ($self != 'wp-login.php') return; if ($_REQUEST['openid_error']) { global $error; $error = $_REQUEST['openid_error']; } if ($_REQUEST['registration_closed']) { global $error; $error = __('Your have entered a valid OpenID, but this site is not currently accepting new accounts.', 'openid'); } } /** * Add style and script to login page. */ function openid_wp_login_head() { openid_style(); wp_enqueue_script('jquery.xpath', openid_plugin_url() . '/f/jquery.xpath.min.js', array('jquery'), OPENID_PLUGIN_REVISION); wp_print_scripts(array('jquery.xpath')); } /** * Add OpenID input field to wp-login.php * * @action: login_form **/ function openid_wp_login_form() { global $wp_version; echo '
'.__('Learn about OpenID', 'openid').'
'; } /** * Add information about registration to wp-login.php?action=register * * @action: register_form **/ function openid_wp_register_form() { global $wp_version; if (get_option('openid_required_for_registration')) { $label = __('Register using an OpenID:', 'openid'); echo ' '; } else { $label = __('Or register using an OpenID:', 'openid'); echo ''; } /** * Action method for completing the 'login' action. This action is used when a user is logging in from * wp-login.php. * * @param string $identity_url verified OpenID URL */ function openid_finish_login($identity_url, $action) { if ($action != 'login') return; $redirect_to = $_SESSION['openid_finish_url']; if (empty($identity_url)) { $url = get_option('siteurl') . '/wp-login.php?openid_error=' . urlencode(openid_message()); wp_safe_redirect($url); exit; } openid_set_current_user($identity_url); if (!is_user_logged_in()) { if ( get_option('users_can_register') ) { $user_data =& openid_get_user_data($identity_url); $user = openid_create_new_user($identity_url, $user_data); openid_set_current_user($user->ID); } else { // TODO - Start a registration loop in WPMU. $url = get_option('siteurl') . '/wp-login.php?registration_closed=1'; wp_safe_redirect($url); exit; } } if (empty($redirect_to)) { $redirect_to = 'wp-admin/'; } if ($redirect_to == 'wp-admin/') { if (!current_user_can('edit_posts')) { $redirect_to .= 'profile.php'; } } if (!preg_match('#^(http|\/)#', $redirect_to)) { $wpp = parse_url(get_option('siteurl')); $redirect_to = $wpp['path'] . '/' . $redirect_to; } wp_safe_redirect( $redirect_to ); exit; } /** * Intercept login requests on wp-login.php if they include an 'openid_identifier' * value and start OpenID authentication. This hook is only necessary in * WordPress 2.5.x because it has the 'wp_authenticate' action call in the * wrong place. */ function wp25_login_openid() { $self = basename( $GLOBALS['pagenow'] ); if ($self == 'wp-login.php' && !empty($_POST['openid_identifier'])) { wp_signon(array('user_login'=>'openid', 'user_password'=>'openid')); } } /** * Clean out registration errors that don't apply. */ function openid_clean_registration_errors($errors) { if (get_option('openid_required_for_registration') || !empty($_POST['openid_identifier'])) { $new = new WP_Error(); foreach ($errors->get_error_codes() as $code) { if (in_array($code, array('empty_username', 'empty_email'))) continue; $message = $errors->get_error_message($code); $data = $errors->get_error_data($code); $new->add($code, $message, $data); } $errors = $new; } if (get_option('openid_required_for_registration') && empty($_POST['openid_identifier'])) { $errors->add('openid_only', __('ERROR: ', 'openid') . __('New users must register using OpenID.', 'openid')); } return $errors; } /** * Handle WordPress registration errors. */ function openid_registration_errors($errors) { if (!empty($_POST['openid_identifier'])) { $errors->add('invalid_openid', __('ERROR: ', 'openid') . openid_message()); } return $errors; } /** * Handle WordPress registrations. */ function openid_register_post($username, $password, $errors) { if (!empty($_POST['openid_identifier'])) { wp_signon(array('user_login'=>'openid', 'user_password'=>'openid')); } } ?>