To enable local system avatars in a template that uses avatars, you need to replace whenever the avatar is requested. This works for Customizr, but the concept is similar for others that use an avatar. The alternative is to change every template where you want to display an avatar and add it in using the “echo” command.
This describes the process to override the ‘get_avatar’ function used in many themes, including customizr.
To do this, you need to create a child template (so your changes don’t get overridden every time you update your template) and implement the runkit extension in php. I know this is complicated, but I couldn’t find anything less.
Also NOTE the recommended statement by the authors of this plugin will only give you YOUR icon:
$imgURL = get_cupp_meta($user_id, $size); // wrong
You need to use the following:
$imgURL = get_the_author_meta(‘cupp_upload_meta’, $id, $size); // correct
Step-by-step guide (For Customizr on Ubuntu/Apache)
- Install ‘Childify Me’ plugin to enable modifications to the template that will not be lost and create a child template
- Install ‘Custom User Profile Photo’ to enable custom photo uploads and associate with user profiles
- Install https://github.com/zenovich/runkit for php (note: had to use master, the current release had build errors)
wget https://github.com/zenovich/runkit/archive/master.zip
unzip master.zip
mv master runkit-1.0.4
tar -zcvf runkit-1.0.4.tgz runkit-1.0.4
pecl install runkit-1.0.4.tgz
- Create a
/etc/php5/apache2/ mods-available/runkit.ini
with extension=runkit.ini
- Create a 20-runkit.ini -> ../../mods-available/runkit.ini simlink (ln –s)
- Restart the apache server
- Add the following using the Appearance->editor->Theme Functions to override the Customizr display avatar code:
<?php
// Your amazing code here (post parent load)
if ( function_exists( 'get_avatar' ) ) :
runkit_function_remove ( 'get_avatar' );
endif;
/**
* These functions can be replaced via plugins. If plugins do not redefine these
* functions, then these will be used instead.
*
* @package WordPress
*/
if ( !function_exists( 'get_avatar' ) ) :
/**
* Retrieve the avatar for a user who provided a user ID or email address.
*
* @since 2.5.0
*
* @param int|string|object $id_or_email A user ID, email address, or comment object
* @param int $size Size of the avatar image
* @param string $default URL to a default image to use if no avatar is available
* @param string $alt Alternative text to use in image tag. Defaults to blank
* @return false|string
<img>
tag for the user’s avatar.
*/
function get_avatar( $id_or_email, $size = ’96’, $default = ”, $alt = false ) {
if ( ! get_option(‘show_avatars’) )
return false;
if ( false === $alt)
$safe_alt = ”;
else
$safe_alt = esc_attr( $alt );
if ( !is_numeric($size) )
$size = ’96’;
$email = ”;
if ( is_numeric($id_or_email) ) {
$id = (int) $id_or_email;
$user = get_userdata($id);
if ( $user )
$email = $user->user_email;
} elseif ( is_object($id_or_email) ) {
// No avatar for pingbacks or trackbacks
/**
* Filter the list of allowed comment types for retrieving avatars.
*
* @since 3.0.0
*
* @param array $types An array of content types. Default only contains ‘comment’.
*/
$allowed_comment_types = apply_filters( ‘get_avatar_comment_types’, array( ‘comment’ ) );
if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) )
return false;
if ( ! empty( $id_or_email->user_id ) ) {
$id = (int) $id_or_email->user_id;
$user = get_userdata($id);
if ( $user )
$email = $user->user_email;
}
if ( ! $email && ! empty( $id_or_email->comment_author_email ) )
$email = $id_or_email->comment_author_email;
} else {
$email = $id_or_email;
}
$imgURL = get_the_author_meta(‘cupp_upload_meta’, $id, $size);
// Print the image on the page
return(‘<img src=”‘. $imgURL .'” alt=””>’);
}
endif;