From 7faf52d18e4051fd7c7f6762dc4a868b9efd7dff Mon Sep 17 00:00:00 2001 From: champsupertramp Date: Wed, 24 Feb 2016 13:16:01 +0800 Subject: [PATCH] Add gravatar transfer tool --- addons/gravatar_transfer.php | 84 ++++++++++++++++++++++++++++++++++++ core/um-filters-avatars.php | 17 ++++---- um-init.php | 5 +++ 3 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 addons/gravatar_transfer.php diff --git a/addons/gravatar_transfer.php b/addons/gravatar_transfer.php new file mode 100644 index 00000000..263c2c82 --- /dev/null +++ b/addons/gravatar_transfer.php @@ -0,0 +1,84 @@ +query('DELETE FROM '.$wpdb->usermeta.' WHERE meta_key = "synced_gravatar_hashed_id" '); + + $wpdb->query('INSERT INTO '.$wpdb->usermeta.'(user_id, meta_key, meta_value) + SELECT ID, "synced_gravatar_hashed_id", MD5( LOWER( TRIM(user_email) ) ) + FROM '.$wpdb->users.' '); + + return true; + } + + function admin_menu() { + + global $ultimatemember; + $this->addon = $ultimatemember->addons['gravatar_transfer']; + add_submenu_page('ultimatemember', $this->addon[0], $this->addon[0], 'manage_options', 'gravatar_transfer', array(&$this, 'content') ); + + } + + function um_admin_addon_hook( $hook ) { + global $ultimatemember; + switch( $hook ) { + case 'gravatar_transfer': + if( $this->gravatar_hash() ){ + $this->content = '

Done. Process completed!

'; + $result = count_users(); + $this->content .= $result['total_users'] . ' user(s) changed.

'; + } + break; + } + } + + function admin_init() { + if ( isset( $_REQUEST['um-addon-hook'] ) ) { + $hook = $_REQUEST['um-addon-hook']; + do_action("um_admin_addon_hook", $hook); + } + } + + function content() { + + $this->process_link = add_query_arg('um-addon-hook','gravatar_transfer'); + + ?> + +
+ +

Ultimate Member

+ +

addon[0]; ?>

+ + content ) ) { + echo $this->content; + } else { ?> + +

This tool allows you to add gravatars to Ultimate Member users. This can help you to link gravatar photos to user accounts with their email address.

+

Depending on your users database, this could take a few moments. To start the process, click the following button.

+ +

Start adding gravatars

+ + + +
+ + '; + + $avatar_url = um_get_domain_protocol().'gravatar.com/avatar/'.um_user('synced_gravatar_hashed_id'); + + $avatar = ''; }else if( empty( $avatar ) ){ $default_avatar_uri = um_get_default_avatar_uri(); + $avatar = ''; } return $avatar; - } \ No newline at end of file + } + diff --git a/um-init.php b/um-init.php index 152ac699..18a2d90d 100644 --- a/um-init.php +++ b/um-init.php @@ -52,6 +52,11 @@ class UM_API { __('This add-on enables you to migrate your custom user photos from BuddyPress to use with Ultimate Member.', 'ultimatemember'), ); + $this->addons['gravatar_transfer'] = array( + __('Gravatar Transfer', 'ultimatemember'), + __('This add-on enables you to link gravatar photos to user accounts with their email address.', 'ultimatemember'), + ); + } /***