Support » Plugin: Add Local Avatar » [Plugin: Add Local Avatar] PHP Notice: Undefined index: in function generate_avatar_in_posts

  • Great plugin, thanx.

    the function generate_avatar_in_posts() is doing a str_replace on the content although there are no matches. You should add a check to see if the preg_match_all returns empty before or not before doing an empty str_replace.

    presently the code is the following:

    preg_match_all("/<!-- avatar ([^>]+) -->/", $content, $matches);
    			// For each instance, let's try to parse it...
    			foreach($matches['1'] as $email) {
    				// Check if we should replace with an avatar or with 'nothing' (to protect email addresses from prying eyes/robots.
    				if(!get_option('show_avatars') || $this->avatar_options['in_posts'] != 'on') $replacement[$counter] = '';
    				else $replacement[$counter] = get_avatar($email, $this->avatar_options['size'], $this->avatar_options['default'], true);
    			// Replace...
    			for($i = 0; $i <= $counter; $i++) {
    				    $content = str_replace($matches[0][$i], $replacement[$i], $content);

    Solution for the user, you can disable this function if you do not use the hacked shortcode in your posts, by commenting out line 142:

    //add_filter('the_content', array(&$this, 'generate_avatar_in_posts'));

    I recommend that you do this, otherwise every post is being scanned looking for this:

    <!-- avatar -->

  • The topic ‘[Plugin: Add Local Avatar] PHP Notice: Undefined index: in function generate_avatar_in_posts’ is closed to new replies.