WordPress

Fix for: Fatal error: Call to undefined function get_avatar_url() in /wp-content/plugins/jetpack/functions.opengraph.php on line 104

Do you use the JetPack plugin (from WordPress) on your website? Did you just start seeing an error when you visit the Authors page on your WordPress blog? Or did you see the following error anywhere on your blog: Fatal error: Call to undefined function get_avatar_url() in public_html/wp-content/plugins/jetpack/functions.opengraph.php on line 104? If yes, then just note that until this issue is fixed your blog would continue to show such an error, which is not nice to look at and does not provide any value to your visitors. So in this article, I am going to share with you few ways to fix this problem. Read on to find the solution.

Root of the problem: JetPack Plugin

Ok, so if you have recently started to see this error on your blog, then just know that this problem is occurring because of the JetPack plugin (from WordPress). Although I can’t give an exact reason why that happened, but it seems like when the developers updated the plugin, somehow they forgot to include the get_avatar_url() function or accidentally deleted it. Either ways, it renders plugin useless for you and your visitors. So if you would like to fix this error yourself, here are a couple of ways.

Solution 1 to fix the fatal error: Call to undefined function get_avatar_url()

This solution is by far, the simplest & would not need any technical expertise on your part. Simply navigate to the Plugins menu option from within the Admin panel links & browse to the JetPack plugin & click Deactivate. This will deactivate the plugin & this problem should be resolved if you visit the page & reload it.

Solution 2 to fix the fatal error: Call to undefined function get_avatar_url()

This solution is technical & I suggest you to go with the Solution 1 above, unless you are familiar with at least a bit of technical coding or if you really want to avoid making any changes to any files yourself. Should you want to go ahead & make this change yourself, here’s what you should do:

1. You will need to add some code to functions.php file of your theme. If you have your theme locally, then navigate to your theme folder and edit the functions.php file. If you don’t have the theme locally and you have your blog online, navigate to the theme of your blog using FTP.  So for example, it would be something like:

/wp-content/themes/my_theme/

Download the functions.php file from the folder to your desktop and then edit it using a HTML editor. If you have Notepad installed in your system, that shall suffice.

2. Once you have opened the functions.php file in your software, simply paste the following code on the last line of the file, if the last line does not have the following symbols “?>” (without quotes). The ?> means that it is the closing tag for PHP. So if that ending tag exists, then you will need to paste the code, just above that line. Of if that closing tag is missing, then you may paste the following code on the last line:

if ( !function_exists('get_avatar_url') )
{
function get_avatar_url($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
$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; }
}

elseif ( !empty($id_or_email->comment_author_email) ) { $email = $id_or_email->comment_author_email; }
}

else { $email = $id_or_email; }

if (empty($default)) {
$avatar_default = get_option('avatar_default');
if (empty($avatar_default)) { $default = 'mystery'; }
else { $default = $avatar_default; }
}

if (!empty($email)) { $email_hash = md5(strtolower($email)); }

if (is_ssl()) { $host = 'https://secure.gravatar.com'; }
else {
if (!empty($email)) { $host = sprintf( "http://%d.gravatar.com", ( hexdec( $email_hash{0} ) % 2 ) ); }
else { $host = 'http://0.gravatar.com'; }
}

if ('mystery' == $default) {
$default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
}
elseif ('blank' == $default) { $default = includes_url('images/blank.gif'); }
elseif (!empty($email) && 'gravatar_default' == $default) { $default = ''; }
elseif ('gravatar_default' == $default) { $default = "$host/avatar/s={$size}"; }
elseif (empty($email)) { $default = "$host/avatar/?d=$default&s={$size}"; }
elseif (strpos($default, 'http://') === 0) { $default = add_query_arg('s', $size, $default); }

if (!empty($email)) {
$out = "$host/avatar/";
$out .= $email_hash;
$out .= '?s='.$size;
$out .= '&d=' . urlencode($default);

$rating = get_option('avatar_rating');
if (!empty($rating)) { $out .= "&r={$rating}"; }

//$avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
$avatar = $out;
}

else {
//$avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
$avatar = $default;
}

return $avatar;

}
}

3. Once you have added the above code to functions.php file, save it. Then upload this file back to the your theme folder of your blog.

4. Visit the author page and reload it. If you have done everything correctly, the problem should now be resolved!

Now that you can use any of the above methods to solve the issue, don’t let this create a negative impression of the plugin on you. The developers at WordPress are great & I do respect them for all the hard work, time & efforts they have put in to develop a product that we all can use and especially because it’s free. I am a developer myself so I totally understand that such accidents can happen once in a while & occurrence of the problem was unintentional. And now would be the right time for us all to show our appreciation to the WordPress guys by supporting them in such a time of crisis.

So just don’t go about deleting the plugin & don’t go about making a promise to yourself not to use their plugin(s) in future. Rather, I suggest you wait for them to release an official patch or update so that the problem can be fixed & just continue to use the plugin if you really like the way it works for you.

Happy blogging!

Did you use any of the above solutions to fix the Fatal error: Call to undefined function get_avatar_url() in /plugins/jetpack/functions.opengraph.php on line 104 problem in WordPress? If yes, feel free to share your experiences by commenting below.

Share your thoughts, comment below now!

*

*