has_cap( 'use_openid_provider' ) ) { add_action( 'show_user_profile', 'openid_extend_profile', 5 ); add_action( 'profile_update', 'openid_profile_update' ); add_action( 'user_profile_update_errors', 'openid_profile_update_errors', 10, 3 ); add_action( 'load-profile.php', 'openid_style' ); if ( ! get_user_meta( $user->ID, 'openid_delegate', true ) ) { $hookname = add_submenu_page( 'profile.php', __( 'Your Trusted Sites', 'openid' ), __( 'Your Trusted Sites', 'openid' ), 'read', 'openid_trusted_sites', 'openid_manage_trusted_sites' ); add_action( "load-$hookname", 'openid_style' ); add_action( "load-$hookname", function() { wp_enqueue_script( 'admin-forms' ); } ); } } if ( function_exists( 'is_site_admin' ) ) { // add OpenID options to WPMU Site Admin page add_action( 'wpmu_options', 'openid_wpmu_options' ); add_action( 'update_wpmu_options', 'openid_update_wpmu_options' ); } else { // add OpenID options to General Settings page. For now, the only option on this page is dependent on the // 'users_can_register' option, so only add the OpenID Settings if that is set. If additional OpenID settings // are added to the General Settings page, this check may no longer be necessary if ( get_option( 'users_can_register' ) ) { add_settings_field( 'openid_general_settings', __( 'OpenID Settings', 'openid' ), 'openid_general_settings', 'general', 'default' ); } } // add OpenID options to Discussion Settings page add_settings_field( 'openid_disucssion_settings', __( 'OpenID Settings', 'openid' ), 'openid_discussion_settings', 'discussion', 'default' ); } /** * Register OpenID admin settings. */ function openid_admin_register_settings() { register_setting( 'general', 'openid_required_for_registration' ); register_setting( 'discussion', 'openid_no_require_name' ); register_setting( 'discussion', 'openid_enable_approval' ); register_setting( 'discussion', 'openid_enable_commentform' ); register_setting( 'openid', 'openid_blog_owner' ); register_setting( 'openid', 'openid_cap' ); } /** * Intercept the call to set the openid_cap option. Instead of storing * this in the options table, set the capability on the appropriate roles. */ function openid_set_cap( $newvalue, $oldvalue ) { global $wp_roles; $newvalue = (array) $newvalue; foreach ( $wp_roles->role_names as $key => $name ) { $role = $wp_roles->get_role( $key ); if ( array_key_exists( $key, $newvalue ) && 'on' == $newvalue[ $key ] ) { $option_set = true; } else { $option_set = false; } if ( $role->has_cap( 'use_openid_provider' ) ) { if ( ! $option_set ) { $role->remove_cap( 'use_openid_provider' ); } } else { if ( $option_set ) { $role->add_cap( 'use_openid_provider' ); } } } return $oldvalue; } /** * Add settings link to plugin page. */ function openid_plugin_action_links( $links, $file ) { $this_plugin = openid_plugin_file(); if ( $file == $this_plugin ) { $links[] = '' . __( 'Settings' ) . ''; } return $links; } /* * Display and handle updates from the Admin screen options page. * * @options_page */ function openid_options_page() { global $wpdb, $wp_roles; if ( isset( $_REQUEST['action'] ) ) { switch ( $_REQUEST['action'] ) { case 'rebuild_tables': check_admin_referer( 'rebuild_tables' ); $store = openid_getStore(); $store->reset(); echo '

' . __( 'OpenID cache refreshed.', 'openid' ) . '

'; break; } } // Display the options page form ?>

General Settings and Discussion Settings pages.', 'openid' ); ?>

ID ); ?>

ID ); return $u->has_cap( 'use_openid_provider' ); } ); if ( ! empty( $users ) ) : ?>

role_names as $key => $name ) { $name = _x( $name, null ); $role = $wp_roles->get_role( $key ); $checked = $role->has_cap( 'use_openid_provider' ) ? ' checked="checked"' : ''; $option_name = 'openid_cap[' . htmlentities( $key ) . ']'; echo '
' . PHP_EOL; } ?>

%1$s) as an OpenID. ' . 'The Blog Owner will be able to use the blog address (%2$s) as their OpenID. If this is a ' . 'single-user blog, you should set this to your account.', 'openid' ), sprintf( '%1$s', $current_user_url ), sprintf( '%1$s', trailingslashit( get_option( 'home' ) ) ) ); ?>

' . __( 'A Blog Owner cannot be set for this blog. To set a Blog Owner, ' . 'first remove the following line from your wp-config.php:', 'openid' ) . '
define("OPENID_DISALLOW_OWNER", 1);

'; } else { $blog_owner = get_option( 'openid_blog_owner' ); if ( empty( $blog_owner ) || $blog_owner == $current_user->user_login ) { echo ''; } else { echo '

' . sprintf( __( 'Only the current Blog Owner (%s) can change this setting.', 'openid' ), $blog_owner ) . '

'; } } ?>

', '' ); ?>

' . __( 'Success:', 'openid' ) . ' ' . openid_message() . '

'; } elseif ( 'warning' == $status ) { echo '

' . __( 'Warning:', 'openid' ) . ' ' . openid_message() . '

'; } elseif ( 'error' == $status ) { echo '

' . __( 'Error:', 'openid' ) . ' ' . openid_message() . '

'; } if ( ! empty( $error ) ) { echo '

' . __( 'Error:', 'openid' ) . ' ' . $error . '

'; unset( $error ); } ?>

Learn more...', 'openid' ) ?>

ID ); if ( empty( $urls ) ) { echo ''; } else { foreach ( $urls as $url ) { echo ' '; } } ?>
' . __( 'No Verified Accounts.', 'openid' ) . '
' . openid_display_identity( $url ) . '

ID, 'openid_trusted_sites', true ); if ( ! is_array( $trusted_sites ) ) { $trusted_sites = array(); } $sites = explode( PHP_EOL, $_REQUEST['sites'] ); $count = 0; foreach ( $sites as $site ) { $site = trim( $site ); if ( empty( $site ) ) { continue; } if ( strpos( $site, 'http' ) === false || strpos( $site, 'http' ) != 0 ) { $site = 'http://' . $site; } $site = esc_url( $site ); $site_hash = md5( $site ); if ( array_key_exists( $site_hash, $trusted_sites ) ) { continue; } $count++; $trusted_sites[ $site_hash ] = array( 'url' => $site ); } if ( $count ) { update_user_meta( $user->ID, 'openid_trusted_sites', $trusted_sites ); echo '

'; printf( _n( 'Added %d trusted site.', 'Added %d trusted sites.', $count, 'openid' ), $count ); echo '

'; } break; case 'delete': if ( empty( $_REQUEST['delete'] ) ) { break; } check_admin_referer( 'openid-delete_trusted_sites' ); $trusted_sites = get_user_meta( $user->ID, 'openid_trusted_sites', true ); $count = 0; foreach ( $_REQUEST['delete'] as $site_hash ) { if ( array_key_exists( $site_hash, $trusted_sites ) ) { $trusted_sites[ $site_hash ] = null; $count++; } } update_user_meta( $user->ID, 'openid_trusted_sites', array_filter( $trusted_sites ) ); if ( $count ) { echo '

'; printf( _n( 'Deleted %d trusted site.', 'Deleted %d trusted sites.', $count, 'openid' ), $count ); echo '

'; } break; } ?>

ID, 'openid_trusted_sites', true ); if ( empty( $trusted_sites ) ) { echo ''; } else { foreach ( $trusted_sites as $site_hash => $site ) { if ( array_key_exists( 'last_login', $site ) && $site['last_login'] ) { $last_login = date( get_option( 'date_format' ) . ' - ' . get_option( 'time_format' ), $site['last_login'] ); } else { $last_login = '-'; } echo ' '; } } ?>
' . __( 'No Trusted Sites.', 'openid' ) . '
' . $site['url'] . ' ' . $last_login . '



base_prefix ) ? $wpdb->base_prefix : $wpdb->prefix ); if ( extension_loaded( 'suhosin' ) ) { $status[] = array( 'Curl', false, 'Hardened php (suhosin) extension active -- curl version checking skipped.' ); } else { $curl_message = ''; if ( function_exists( 'curl_version' ) ) { $curl_version = curl_version(); if ( isset( $curl_version['version'] ) ) { $curl_message .= 'Version ' . $curl_version['version'] . '. '; } if ( isset( $curl_version['ssl_version'] ) ) { $curl_message .= 'SSL: ' . $curl_version['ssl_version'] . '. '; } if ( isset( $curl_message['libz_version'] ) ) { $curl_message .= 'zlib: ' . $curl_version['libz_version'] . '. '; } if ( isset( $curl_version['protocols'] ) ) { if ( is_array( $curl_version['protocols'] ) ) { $curl_message .= 'Supports: ' . implode( ', ', $curl_version['protocols'] ) . '. '; } else { $curl_message .= 'Supports: ' . $curl_version['protocols'] . '. '; } } } else { $curl_message = 'This PHP installation does not have support for libcurl. Some functionality, such as ' . 'fetching https:// URLs, will be missing and performance will slightly impared. See ' . 'php.net/manual/en/ref.curl.php about ' . 'enabling libcurl support for PHP.'; } $status[] = array( 'Curl Support', isset( $curl_version ), $curl_message ); } if ( extension_loaded( 'gmp' ) and @gmp_add( 1, 1 ) == 2 ) { $status[] = array( 'Big Integer support', true, 'GMP is installed.' ); } elseif ( extension_loaded( 'bcmath' ) and @bcadd( 1, 1 ) == 2 ) { $status[] = array( 'Big Integer support', true, 'BCMath is installed (though GMP is preferred).' ); } elseif ( defined( 'Auth_OpenID_NO_MATH_SUPPORT' ) ) { $status[] = array( 'Big Integer support', false, 'The OpenID Library is operating in Dumb Mode. Recommend installing GMP support.' ); } $status[] = array( 'Plugin Revision', 'info', OPENID_PLUGIN_REVISION ); $status[] = array( 'Plugin Database Revision', 'info', get_option( 'openid_db_revision' ) ); if ( function_exists( 'xrds_meta' ) ) { $status[] = array( 'XRDS-Simple', 'info', 'XRDS-Simple plugin is installed.' ); } else { $status[] = array( 'XRDS-Simple', false, 'XRDS-Simple plugin is not installed. Some features may not work properly (including providing OpenIDs).' ); } $openid_enabled = openid_enabled(); $status[] = array( 'Overall Plugin Status', ( $openid_enabled ), ( $openid_enabled ? '' : 'There are problems above that must be dealt with before the plugin can be used.' ), ); if ( $openid_enabled ) { // Display status information echo'

' . __( 'Status information:', 'openid' ) . ' ' . __( 'All Systems Nominal', 'openid' ) . ' (' . __( 'Toggle More/Less', 'openid' ) . ')

'; } else { echo '

' . __( 'Plugin is currently disabled. Fix the problem, then Deactivate/Reactivate the plugin.', 'openid' ) . '

'; } echo '
'; foreach ( $status as $s ) { list ($name, $state, $message) = $s; echo '
'; if ( $state === false ) { echo "[" . __( 'FAIL', 'openid' ) . "] $name"; } elseif ( $state === true ) { echo "[" . __( 'OK', 'openid' ) . "] $name"; } else { echo "[" . __( 'INFO', 'openid' ) . "] $name"; } echo ( $message ? ': ' : '' ) . ''; echo ( is_array( $message ) ? '' : $message ); echo '
'; } echo '
'; } /** * Handle OpenID profile management. */ function openid_profile_management() { global $action; wp_reset_vars( array( 'action' ) ); switch ( $action ) { case 'add': check_admin_referer( 'openid-add_openid' ); $user = wp_get_current_user(); $auth_request = openid_begin_consumer( $_POST['openid_identifier'] ); $userid = get_user_by_openid( $auth_request->endpoint->claimed_id ); if ( $userid ) { global $error; if ( $user->ID == $userid ) { $error = __( 'You already have this OpenID!', 'openid' ); } else { $error = __( 'This OpenID is already associated with another user.', 'openid' ); } return; } $finish_url = admin_url( current_user_can( 'edit_users' ) ? 'users.php' : 'profile.php' ); $finish_url = add_query_arg( 'page', $_REQUEST['page'], $finish_url ); openid_start_login( $_POST['openid_identifier'], 'verify', $finish_url ); break; case 'delete': openid_profile_delete_openids( $_REQUEST['delete'] ); break; default: if ( array_key_exists( 'message', $_REQUEST ) ) { $message = $_REQUEST['message']; $messages = array( '', __( 'Unable to authenticate OpenID.', 'openid' ), __( 'OpenID assertion successful, but this URL is already associated with another user on this blog.', 'openid' ), __( 'Added association with OpenID.', 'openid' ), ); if ( is_numeric( $message ) ) { $message = $messages[ $message ]; } else { $message = htmlentities2( $message ); } $message = __( $message, 'openid' ); if ( array_key_exists( 'update_url', $_REQUEST ) && $_REQUEST['update_url'] ) { $message .= '
' . __( 'Note: For security reasons, your profile URL has been updated to match your OpenID.', 'openid' ); } openid_message( $message ); openid_status( $_REQUEST['status'] ); } break; } } /** * Remove identity URL from current user account. * * @param int $id id of identity URL to remove */ function openid_profile_delete_openids( $delete ) { if ( empty( $delete ) || array_key_exists( 'cancel', $_REQUEST ) ) { return; } check_admin_referer( 'openid-delete_openids' ); $user = wp_get_current_user(); $urls = get_user_openids( $user->ID ); if ( sizeof( $urls ) == sizeof( $delete ) && ! @$_REQUEST['confirm'] ) { $html = '

' . __( 'OpenID Warning', 'openid' ) . '

' . __( 'Are you sure you want to delete all of your OpenID associations? Doing so may prevent you from logging in.', 'openid' ) . '

'; foreach ( $delete as $d ) { $html .= ''; } $html .= wp_nonce_field( 'openid-delete_openids', '_wpnonce', true, false ) . '
'; openid_page( $html, __( 'OpenID Warning', 'openid' ) ); return; } $count = 0; foreach ( $urls as $url ) { if ( in_array( md5( $url ), $_REQUEST['delete'] ) ) { if ( openid_drop_identity( $user->ID, $url ) ) { $count++; } } } if ( $count ) { openid_message( sprintf( _n( 'Deleted %d OpenID association.', 'Deleted %d OpenID associations.', $count, 'openid' ), $count ) ); openid_status( 'success' ); // ensure that profile URL is still a verified OpenID require_once 'Auth/OpenID.php'; @include_once( ABSPATH . WPINC . '/registration.php' ); // WP < 2.3 @include_once( ABSPATH . 'wp-admin/includes/admin.php' ); // WP >= 2.3 if ( ! openid_ensure_url_match( $user ) ) { $identities = get_user_openids( $user->ID ); wp_update_user( array( 'ID' => $user->ID, 'user_url' => $identities[0], ) ); openid_message( openid_message() . '
' . __( 'Note: For security reasons, your profile URL has been updated to match your OpenID.', 'openid' ) ); } return; } openid_message( __( 'OpenID association delete failed: Unknown reason.', 'openid' ) ); openid_status( 'error' ); } /** * Action method for completing the 'verify' action. This action is used adding an identity URL to a * WordPress user through the admin interface. * * @param string $identity_url verified OpenID URL */ function openid_finish_verify( $identity_url, $action ) { if ( $action != 'verify' ) { return; } $message; $user = wp_get_current_user(); if ( empty( $identity_url ) ) { $message = openid_message(); if ( empty( $message ) ) { $message = 1; } } else { if ( ! openid_add_identity( $user->ID, $identity_url ) ) { $message = 2; } else { $message = 3; // ensure that profile URL is a verified OpenID require_once 'Auth/OpenID.php'; require_once( ABSPATH . 'wp-admin/includes/admin.php' ); if ( ! openid_ensure_url_match( $user ) ) { wp_update_user( array( 'ID' => $user->ID, 'user_url' => $identity_url, ) ); $update_url = 1; } } } $finish_url = $_SESSION['openid_finish_url']; $finish_url = add_query_arg( 'status', openid_status(), $finish_url ); $finish_url = add_query_arg( 'message', $message, $finish_url ); if ( isset( $update_url ) && $update_url ) { $finish_url = add_query_arg( 'update_url', $update_url, $finish_url ); } wp_safe_redirect( $finish_url ); exit; } /** * hook in and call when user is updating their profile URL... make sure it is an OpenID they control. */ function openid_personal_options_update() { $user = wp_get_current_user(); if ( ! openid_ensure_url_match( $user, $_POST['url'] ) ) { wp_die( sprintf( __( 'For security reasons, your profile URL must be one of your claimed OpenIDs: %s', 'openid' ), '' ) ); } } /** * Ensure that the user's profile URL matches one of their OpenIDs */ function openid_ensure_url_match( $user, $url = null ) { $identities = get_user_openids( $user->ID ); if ( empty( $identities ) ) { return true; } require_once 'Auth/OpenID.php'; if ( $url == null ) { $url = $user->user_url; } $url = Auth_OpenID::normalizeUrl( $url ); foreach ( $identities as $id ) { $id = Auth_OpenID::normalizeUrl( $id ); if ( $id == $url ) { return true; } } return false; } /** * Add OpenID options to the WordPress user profile page. */ function openid_extend_profile() { $user = wp_get_current_user(); echo '

' . __( 'OpenID Delegation allows you to use an external OpenID provider of your choice.', 'openid' ) . '

' . __( 'To delegate, enter a valid OpenID. Otherwise leave this blank.', 'openid' ) . '

'; } /** * Update OpenID options set from the WordPress user profile page. */ function openid_profile_update( $user_id ) { global $openid_user_delegation_info; if ( empty( $_POST['openid_delegate'] ) ) { delete_user_meta( $user_id, 'openid_delegate' ); delete_user_meta( $user_id, 'openid_delegate_services' ); } else { update_user_meta( $user_id, 'openid_delegate', $openid_user_delegation_info['url'] ); update_user_meta( $user_id, 'openid_delegate_services', $openid_user_delegation_info['services'] ); } } /** * Report any OpenID errors during user profile updating. */ function openid_profile_update_errors( $errors, $update, $user ) { global $openid_user_delegation_info; $delegate = Auth_OpenID::normalizeUrl( $_POST['openid_delegate'] ); if ( empty( $delegate ) ) { return $errors; } $openid_user_delegation_info = openid_server_get_delegation_info( $user->ID, $delegate ); if ( ! $openid_user_delegation_info ) { $errors->add( 'openid_delegate', sprintf( __( 'Unable to find any OpenID information for delegate URL %s', 'openid' ), '' . $delegate . '' ) ); } else { $id_select_count = 0; foreach ( $openid_user_delegation_info['services'] as $service ) { if ( array_key_exists( 'LocalID', $service ) && $service['LocalID'] == Auth_OpenID_IDENTIFIER_SELECT ) { $id_select_count++; } } if ( count( $openid_user_delegation_info['services'] ) <= $id_select_count ) { $errors->add( 'openid_delegate', sprintf( __( 'You cannot delegate to an OpenID provider which uses Identifier Select.', 'openid' ) ) ); } } return $errors; } /** * Add OpenID options to the WordPress MU site options page. */ function openid_wpmu_options() { $registration = get_site_option( 'registration' ); if ( $registration == 'all' || $registration == 'user' ) : ?>