Add gravatar transfer tool

This commit is contained in:
champsupertramp
2016-02-24 13:16:01 +08:00
parent f7d7b118a6
commit 7faf52d18e
3 changed files with 97 additions and 9 deletions
+84
View File
@@ -0,0 +1,84 @@
<?php
class UM_ADDON_gravatar_transfer {
function __construct() {
add_action('admin_menu', array(&$this, 'admin_menu'), 1001);
add_action('admin_init', array(&$this, 'admin_init'), 1);
add_action('um_admin_addon_hook', array(&$this, 'um_admin_addon_hook') );
}
function gravatar_hash(){
global $wpdb;
$wpdb->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 = '<p><strong>Done. Process completed!</p>';
$result = count_users();
$this->content .= $result['total_users'] . ' user(s) changed.</strong></p>';
}
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');
?>
<div class="wrap">
<h2>Ultimate Member <sup style="font-size:15px"><?php echo ultimatemember_version; ?></sup></h2>
<h3><?php echo $this->addon[0]; ?></h3>
<?php if ( isset( $this->content ) ) {
echo $this->content;
} else { ?>
<p>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.</p>
<p>Depending on your users database, this could take a few moments. To start the process, click the following button.</p>
<p><a href="<?php echo $this->process_link; ?>" class="button button-primary">Start adding gravatars</a></p>
<?php } ?>
</div><div class="clear"></div>
<?php
}
}
$UM_ADDON_gravatar_transfer = new UM_ADDON_gravatar_transfer();
+8 -9
View File
@@ -28,12 +28,7 @@
$avatar = um_user('profile_photo', $size);
if ( !um_profile('profile_photo') && um_get_option('use_gravatars') ) {
if ( is_ssl() ) {
$protocol = 'https://';
} else {
$protocol = 'http://';
}
if ( ! $avatar && um_get_option('use_gravatars') ) {
$default = get_option( 'avatar_default', 'mystery' );
if ( $default == 'gravatar_default' ) {
@@ -45,14 +40,18 @@
$rating = "&amp;r={$rating}";
}
$avatar = '<img src="' . $protocol . 'gravatar.com/avatar/' . md5( um_user('user_email') ) .
'?d='. $default . '&amp;s=' . $size . $rating .'" class="gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="" />';
$avatar_url = um_get_domain_protocol().'gravatar.com/avatar/'.um_user('synced_gravatar_hashed_id');
$avatar = '<img src="' .$avatar_url .'?d='. $default . '&amp;s=' . $size . $rating .'" class="func-um_get_avatar gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="" />';
}else if( empty( $avatar ) ){
$default_avatar_uri = um_get_default_avatar_uri();
$avatar = '<img src="' .$default_avatar_uri .'" class="gravatar avatar avatar-'.$size.' um-avatar" width="'.$size.'" height="'.$size.'" alt="" />';
}
return $avatar;
}
}
+5
View File
@@ -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'),
);
}
/***