diff --git a/inc/avatars.php b/inc/avatars.php
index bf3731884..cdd3ae991 100644
--- a/inc/avatars.php
+++ b/inc/avatars.php
@@ -2,3 +2,50 @@
// Include avatars module
include_once dirname(__FILE__) . '/avatars/functions.php';
+
+/**
+ * Determine whether or not an author has a valid gravatar image
+ * see: http://codex.wordpress.org/Using_Gravatars
+ *
+ * @param $email string an author's email address
+ * @return bool true if a gravatar is available for this user
+ * @since 0.3
+ */
+function largo_has_gravatar( $email ) {
+ // Craft a potential url and test its headers
+ $hash = md5( strtolower( trim( $email ) ) );
+
+ $cache_key = 'largo_has_gravatar_' . $hash;
+ if ( false !== ( $cache_value = get_transient( $cache_key ) ) ) {
+ return (bool) $cache_value;
+ }
+
+ $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
+ $response = wp_remote_head( $uri );
+ if ( 200 == wp_remote_retrieve_response_code( $response ) ) {
+ $cache_value = '1';
+ } else {
+ $cache_value = '0';
+ }
+ set_transient( $cache_key, $cache_value );
+ return (bool) $cache_value;
+}
+
+/**
+ * Determine whether or not a user has an avatar. Fallback checks if user has a gravatar.
+ *
+ * @param $email string an author's email address
+ * @return bool true if an avatar is available for this user
+ * @since 0.4
+ */
+function largo_has_avatar($email) {
+ $user = get_user_by('email', $email);
+ $result = largo_get_user_avatar_id($user->ID);
+ if (!empty($result))
+ return true;
+ else {
+ if (largo_has_gravatar($email))
+ return true;
+ }
+ return false;
+}
\ No newline at end of file
diff --git a/inc/helpers.php b/inc/helpers.php
index 940257624..a18b863ec 100644
--- a/inc/helpers.php
+++ b/inc/helpers.php
@@ -27,6 +27,7 @@ function largo_fb_url_to_username( $url ) {
return $username;
}
+
/**
* Checks to see if a given Facebook username or ID has following enabled by
* checking the iframe of that user's "Follow" button for
.
@@ -53,6 +54,65 @@ function largo_fb_user_is_followable( $username ) {
}
}
+/**
+ * Cleans a Facebook url to the bare username or id when the user is edited
+ *
+ * Edits $_POST directly because there's no other way to save the corrected username
+ * from this callback. The action hooks this is used for run before edit_user in
+ * wp-admin/user-edit.php, which overwrites the user's contact methods. edit_user
+ * reads from $_POST.
+ *
+ * @param object $user_id the WP_User object being edited
+ * @param array $_POST
+ * @since 0.4
+ * @uses largo_fb_url_to_username
+ * @link http://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update
+ * @link http://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
+ */
+function clean_user_fb_username($user_id) {
+
+ if ( current_user_can('edit_user', $user_id) ) {
+ $fb = largo_fb_url_to_username( $_POST['fb'] );
+ if ( preg_match( '/[^a-zA-Z0-9\.\-]/', $fb ) ) {
+ // it's not a valid Facebook username, because it uses an invalid character
+ $fb = "";
+ }
+ update_user_meta($user_id, 'fb', $fb);
+ if ( get_user_meta($user_id, 'fb', true) != $fb ) {
+ wp_die(__('An error occurred.'));
+ }
+ $_POST['fb'] = $fb;
+ }
+}
+
+/**
+ * Checks that the Facebook URL submitted is valid and the user is followable and causes an error if not
+ *
+ * @uses largo_fb_url_to_username
+ * @uses largo_fb_user_is_followable
+ * @param $errors the error object
+ * @param bool $update whether this is a user update
+ * @param object $user a WP_User object
+ * @link http://codex.wordpress.org/Plugin_API/Action_Reference/user_profile_update_errors
+ * @since 0.4
+ */
+function validate_fb_username( $errors, $update, $user ) {
+
+ if ( isset( $_POST["fb"] ) ) {
+ $fb_suspect = trim( $_POST["fb"] );
+ if( ! empty( $fb_suspect ) ) {
+ $fb_user = largo_fb_url_to_username( $fb_suspect );
+ if ( preg_match( '/[^a-zA-Z0-9\.\-]/', $fb_user ) ) {
+ // it's not a valid Facebook username, because it uses an invalid character
+ $errors->add('fb_username', '' . $fb_suspect . ' ' . __('is an invalid Facebook username.') . '' . '' . __('Facebook usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), periods (.) and dashes (-)') );
+ }
+ if ( ! largo_fb_user_is_followable( $fb_user ) ) {
+ $errors->add('fb_username',' ' . $fb_suspect . ' ' . __('does not allow followers on Facebook.') . '
' . '' . __('Follow these instructions to allow others to follow you.') );
+ }
+ }
+ }
+}
+
/**
* Returns a Twitter username (without the @ symbol)
*
@@ -76,6 +136,61 @@ function largo_twitter_url_to_username( $url ) {
return $username;
}
+/**
+ * Cleans a Twitter url or an @username to the bare username when the user is edited
+ *
+ * Edits $_POST directly because there's no other way to save the corrected username
+ * from this callback. The action hooks this is used for run before edit_user in
+ * wp-admin/user-edit.php, which overwrites the user's contact methods. edit_user
+ * reads from $_POST.
+ *
+ * @param object $user_id the WP_User object being edited
+ * @param array $_POST
+ * @since 0.4
+ * @uses largo_twitter_url_to_username
+ * @link http://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update
+ * @link http://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
+ */
+function clean_user_twitter_username($user_id) {
+
+ if ( current_user_can('edit_user', $user_id) ) {
+ $twitter = largo_twitter_url_to_username( $_POST['twitter'] );
+ if ( preg_match( '/[^a-zA-Z0-9_]/', $twitter ) ) {
+ // it's not a valid twitter username, because it uses an invalid character
+ $twitter = "";
+ }
+ update_user_meta($user_id, 'twitter_link', $twitter);
+ if ( get_user_meta($user_id, 'twitter_link', true) != $twitter ) {
+ wp_die(__('An error occurred.'));
+ }
+ $_POST['twitter'] = $twitter;
+ }
+}
+
+/**
+ * Checks that the Twitter URL is composed of valid characters [a-zA-Z0-9_] and
+ * causes an error if there is not.
+ *
+ * @param $errors the error object
+ * @param bool $update whether this is a user update
+ * @param object $user a WP_User object
+ * @uses largo_twitter_url_to_username
+ * @link http://codex.wordpress.org/Plugin_API/Action_Reference/user_profile_update_errors
+ * @since 0.4
+ */
+function validate_twitter_username( $errors, $update, $user ) {
+
+ if ( isset( $_POST["twitter"] ) ) {
+ $tw_suspect = trim( $_POST["twitter"] );
+ if( ! empty( $tw_suspect ) ) {
+ if ( preg_match( '/[^a-zA-Z0-9_]/', largo_twitter_url_to_username( $tw_suspect ) ) ) {
+ // it's not a valid twitter username, because it uses an invalid character
+ $errors->add('twitter_username', '' . $tw_suspect . '' . __('is an invalid Twitter username.') . '
' . '' . __('Twitter usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), and underscores (_).') );
+ }
+ }
+ }
+}
+
/**
* Give it a YouTube URL, it'll give you just the video ID
*
diff --git a/inc/post-tags.php b/inc/post-tags.php
index 9aff98b73..f009bfc9e 100644
--- a/inc/post-tags.php
+++ b/inc/post-tags.php
@@ -258,52 +258,6 @@ function largo_post_social_links( $echo = true ) {
}
}
-/**
- * Determine whether or not an author has a valid gravatar image
- * see: http://codex.wordpress.org/Using_Gravatars
- *
- * @param $email string an author's email address
- * @return bool true if a gravatar is available for this user
- * @since 0.3
- */
-function largo_has_gravatar( $email ) {
- // Craft a potential url and test its headers
- $hash = md5( strtolower( trim( $email ) ) );
-
- $cache_key = 'largo_has_gravatar_' . $hash;
- if ( false !== ( $cache_value = get_transient( $cache_key ) ) ) {
- return (bool) $cache_value;
- }
-
- $uri = 'http://www.gravatar.com/avatar/' . $hash . '?d=404';
- $response = wp_remote_head( $uri );
- if ( 200 == wp_remote_retrieve_response_code( $response ) ) {
- $cache_value = '1';
- } else {
- $cache_value = '0';
- }
- set_transient( $cache_key, $cache_value );
- return (bool) $cache_value;
-}
-/**
- * Determine whether or not a user has an avatar. Fallback checks if user has a gravatar.
- *
- * @param $email string an author's email address
- * @return bool true if an avatar is available for this user
- * @since 0.4
- */
-function largo_has_avatar($email) {
- $user = get_user_by('email', $email);
- $result = largo_get_user_avatar_id($user->ID);
- if (!empty($result))
- return true;
- else {
- if (largo_has_gravatar($email))
- return true;
- }
- return false;
-}
-
/**
* Replaces the_content() with paginated content (if is used in the post)
*
diff --git a/inc/users.php b/inc/users.php
index b6eb10a78..d338a95c5 100644
--- a/inc/users.php
+++ b/inc/users.php
@@ -5,7 +5,7 @@
* Remove old contact methods (yahoo, aol and jabber)
* Add new ones (twitter, facebook, linkedin)
*
- * @since 1.0
+ * @since 0.1
*/
function largo_contactmethods( $contactmethods ) {
@@ -32,12 +32,20 @@ function largo_contactmethods( $contactmethods ) {
}
add_filter( 'user_contactmethods', 'largo_contactmethods' );
+// clean and validate fb and twitter usernames when user profiles are updated
+add_action('edit_user_profile_update', 'clean_user_twitter_username');
+add_action('personal_options_update', 'clean_user_twitter_username');
+add_action( 'user_profile_update_errors', 'validate_twitter_username', 10, 3);
+
+add_action( 'edit_user_profile_update', 'clean_user_fb_username' );
+add_action( 'personal_options_update', 'clean_user_fb_username' );
+add_action( 'user_profile_update_errors', 'validate_fb_username', 10, 3);
/**
* Same deal, but for guest authors in the Co-Authors Plus plugin
* @TODO: figure out if there's a way to remove fields as we do for regular users above
*
- * @since 1.0
+ * @since 0.1
*/
function largo_filter_guest_author_fields( $fields_to_return, $groups ) {
@@ -78,9 +86,9 @@ function largo_filter_guest_author_fields( $fields_to_return, $groups ) {
/**
* In a multisite network, allow site admins to edit user profiles
- * props: http://thereforei.am/2011/03/15/how-to-allow-administrators-to-edit-users-in-a-wordpress-network/
+ * @link http://thereforei.am/2011/03/15/how-to-allow-administrators-to-edit-users-in-a-wordpress-network/
*
- * @since 1.0
+ * @since 0.3
*/
function largo_admin_users_caps( $caps, $cap, $user_id, $args ){
@@ -113,6 +121,8 @@ function largo_admin_users_caps( $caps, $cap, $user_id, $args ){
/**
* Checks that both the editing user and the user being edited are
* members of the blog and prevents the super admin being edited.
+ *
+ * @since 0.3
*/
function largo_edit_permission_check() {
global $current_user, $profileuser;
@@ -132,131 +142,6 @@ function largo_edit_permission_check() {
}
add_filter( 'admin_head', 'largo_edit_permission_check', 1, 4 );
-
-/**
- * Cleans a Twitter url or an @username to the bare username when the user is edited
- *
- * Edits $_POST directly because there's no other way to save the corrected username
- * from this callback. The action hooks this is used for run before edit_user in
- * wp-admin/user-edit.php, which overwrites the user's contact methods. edit_user
- * reads from $_POST.
- *
- * @param object $user_id the WP_User object being edited
- * @param array $_POST
- * @since 0.4
- * @uses largo_twitter_url_to_username
- * @link http://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update
- * @link http://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
- */
-
-add_action('edit_user_profile_update', 'clean_user_twitter_username');
-add_action('personal_options_update', 'clean_user_twitter_username');
-
-function clean_user_twitter_username($user_id) {
-
- if ( current_user_can('edit_user', $user_id) ) {
- $twitter = largo_twitter_url_to_username( $_POST['twitter'] );
- if ( preg_match( '/[^a-zA-Z0-9_]/', $twitter ) ) {
- // it's not a valid twitter username, because it uses an invalid character
- $twitter = "";
- }
- update_user_meta($user_id, 'twitter_link', $twitter);
- if ( get_user_meta($user_id, 'twitter_link', true) != $twitter ) {
- wp_die(__('An error occurred.'));
- }
- $_POST['twitter'] = $twitter;
- }
-}
-
-/**
- * Checks that the Twitter URL is composed of valid characters [a-zA-Z0-9_] and
- * causes an error if there is not.
- *
- * @param $errors the error object
- * @param bool $update whether this is a user update
- * @param object $user a WP_User object
- * @uses largo_twitter_url_to_username
- * @link http://codex.wordpress.org/Plugin_API/Action_Reference/user_profile_update_errors
- * @since 0.4
- */
-
-add_action( 'user_profile_update_errors', 'validate_twitter_username', 10, 3);
-
-function validate_twitter_username( $errors, $update, $user ) {
-
- if ( isset( $_POST["twitter"] ) ) {
- $tw_suspect = trim( $_POST["twitter"] );
- if( ! empty( $tw_suspect ) ) {
- if ( preg_match( '/[^a-zA-Z0-9_]/', largo_twitter_url_to_username( $tw_suspect ) ) ) {
- // it's not a valid twitter username, because it uses an invalid character
- $errors->add('twitter_username', '' . $tw_suspect . '' . __('is an invalid Twitter username.') . '
' . '' . __('Twitter usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), and underscores (_).') );
- }
- }
- }
-}
-
-/**
- * Cleans a Facebook url to the bare username or id when the user is edited
- *
- * Edits $_POST directly because there's no other way to save the corrected username
- * from this callback. The action hooks this is used for run before edit_user in
- * wp-admin/user-edit.php, which overwrites the user's contact methods. edit_user
- * reads from $_POST.
- *
- * @param object $user_id the WP_User object being edited
- * @param array $_POST
- * @since 0.4
- * @uses largo_fb_url_to_username
- * @link http://codex.wordpress.org/Plugin_API/Action_Reference/edit_user_profile_update
- * @link http://codex.wordpress.org/Plugin_API/Action_Reference/personal_options_update
- */
-add_action('edit_user_profile_update', 'clean_user_fb_username');
-add_action('personal_options_update', 'clean_user_fb_username');
-
-function clean_user_fb_username($user_id) {
-
- if ( current_user_can('edit_user', $user_id) ) {
- $fb = largo_fb_url_to_username( $_POST['fb'] );
- if ( preg_match( '/[^a-zA-Z0-9\.\-]/', $fb ) ) {
- // it's not a valid Facebook username, because it uses an invalid character
- $fb = "";
- }
- update_user_meta($user_id, 'fb', $fb);
- if ( get_user_meta($user_id, 'fb', true) != $fb ) {
- wp_die(__('An error occurred.'));
- }
- $_POST['fb'] = $fb;
- }
-}
-/**
- * Checks that the Facebook URL submitted is valid and the user is followable and causes an error if not
- *
- * @uses largo_fb_url_to_username
- * @uses largo_fb_user_is_followable
- * @param $errors the error object
- * @param bool $update whether this is a user update
- * @param object $user a WP_User object
- * @link http://codex.wordpress.org/Plugin_API/Action_Reference/user_profile_update_errors
- * @since 0.4
- */
-add_action( 'user_profile_update_errors', 'validate_fb_username', 10, 3);
-
-function validate_fb_username( $errors, $update, $user ) {
-
- if ( isset( $_POST["fb"] ) ) {
- $fb_suspect = trim( $_POST["fb"] );
- if( ! empty( $fb_suspect ) ) {
- $fb_user = largo_fb_url_to_username( $fb_suspect );
- if ( preg_match( '/[^a-zA-Z0-9\.\-]/', $fb_user ) ) {
- // it's not a valid Facebook username, because it uses an invalid character
- $errors->add('fb_username', '' . $fb_suspect . ' ' . __('is an invalid Facebook username.') . '
' . '' . __('Facebook usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), periods (.) and dashes (-)') );
- }
- if ( ! largo_fb_user_is_followable( $fb_user ) ) {
- $errors->add('fb_username',' ' . $fb_suspect . ' ' . __('does not allow followers on Facebook.') . '
' . '' . __('Follow these instructions to allow others to follow you.') );
- }
- }
- }
-}
/**
* Get users based on a role. Defaults to fetching all authors for the current blog.
*
@@ -369,44 +254,33 @@ function largo_render_staff_list_shortcode($atts=array()) {
function more_profile_info($user) {
$show_email = get_user_meta( $user->ID, "show_email", true );
$hide = get_user_meta( $user->ID, "hide", true );
- $emeritus = get_user_meta( $user->ID, "emeritus", true );
- $honorary = get_user_meta( $user->ID, "honorary", true );
-
?>
-
More profile information
+