Support » Plugin: Add Local Avatar » Impossible to add Twitter API Credentials after upgrade

  • You added support for OAuth and Twitter API Version 1.1

    Unfortunately the form that asks for those credentials is loaded AFTER the list of avatars on the avatars page, and both pages on the site that have Avatars And the avatars admin page throw an uncaught exception (i.e. php fatal error) if it tries to load an avatar from twitter but doesn’t have the credentials filled out

    [12-Aug-2013 18:02:49] PHP Fatal error:  Uncaught exception 'Exception' with message 'Make sure you are passing in the correct parameters' in /data/blogs/test/wp-content/plugins/add-local-avatar/TwitterAPIExchange.php:45
    Stack trace:
    #0 /data/blogs/test/wp-content/plugins/add-local-avatar/avatars.php(173): TwitterAPIExchange->__construct(Array)
    #1 /data/blogs/test/wp-content/plugins/add-local-avatar/avatars.php(1393): add_local_avatars->get_twitter_avatar('testuser')
    #2 /data/blogs/test/wp-content/themes/test/loop.php(152): get_avatar('usertest@example...', 60)
    #3 /data/blogs/test/wp-includes/template.php(409): require('/data/blogs/test...')
    #4 /data/blogs/test/wp-includes/template.php(383): load_template('/data/blogs/test...', false)
    #5 /data/blogs/test/wp-includes/general-template.php(132): locate_template(Array, true, false)
    #6 /data/blogs/test/wp-content/themes/test/index.php(25): get_template_part('loop', 'index')
    #7 /data/blogs/test/wp-includes/template-loader.php( in /data/blogs/otest/wp-content/plugins/add-local-avatar/TwitterAPIExchange.php on line 45

    I would modify get_twitter_avatar() to before the require_once line check that all 4 of the required settings are there and if not return false.

    // Try to get a Twitter avatar.
    function get_twitter_avatar($id)
    	if (!$this->avatar_options['access_token'] || !$this->avatar_options['access_token_secret'] || !$this->avatar_options['consumer_key'] || !$this->avatar_options['consumer_secret']) return false;
    	$settings = array(
    		'oauth_access_token' => $this->avatar_options['access_token'],
    		'oauth_access_token_secret' => $this->avatar_options['access_token_secret'],
    		'consumer_key' => $this->avatar_options['consumer_key'],
    		'consumer_secret' => $this->avatar_options['consumer_secret']
    	$twitter = new TwitterAPIExchange($settings);
    	$dat = json_decode($twitter->setGetfield(sprintf('?screen_name=%s', $id)) ->buildOauth('', 'GET') ->performRequest(), true);
    	// Check Twitter URI for default Twitter (little birdie) icon use.
    	if(strpos($dat['profile_image_url'], TWITTER_STATIC) !== false) return '';
    	return $dat['profile_image_url'];

    This will prevent the fatal error (naturally there will be no twitter avatar either, but at least there won’t be a fatal error and the form will load).

  • The topic ‘Impossible to add Twitter API Credentials after upgrade’ is closed to new replies.