ThemeShaper Forums » Thematic

[closed]

default avatar setting?

(6 posts)
  • Started 4 years ago by helgatheviking
  • Latest reply from helgatheviking
  • This topic is resolved

Tags:

  1. is there a way to set the default avatar to something custom and theme-specific?

    i saw this neat post at:
    http://www.problogdesign.com/general-tips/how-to-make-your-own-default-avatar-in-5-minutes/

    and so i tried to filter in a new $avatar to thematic_commenter_link which didn't work. i was only successful when i totally replaced that function w/ a child version in my custom comments callback. that just seems excessive if i only wanted to change the default.

    Posted 4 years ago #
  2. @helgatheviking thanks for the info. I would also like to add a custom default avatar, but have been unsuccessful in my attempts. Any further help would be greatly appreciated!

    Posted 4 years ago #
  3. i actually implemented this on my last project. however i ended up copying and modding the entire comments.php. would be nice for default avatar to be a simple filter.

    //define constant
    define('THEME_URI', get_stylesheet_directory_uri());
    
    /* ********************************************** */
    
    /* Comments */
    
    /* ********************************************** */
    
    //Avatar size
    
    function childtheme_avatarsize() {
        return '68';
    }
    
    add_action( 'avatar_size', 'childtheme_avatarsize' );
    
    // Custom callback to list comments in my style
    
    function child_comments($comment, $args, $depth) {
    
    	$GLOBALS['comment'] = $comment;
    	$GLOBALS['comment_depth'] = $depth;
    
    	?>
    
    	<li id="comment-<?php comment_ID() ?>" class="<?php thematic_comment_class() ?>">
    
    	<div class="comment-wrap clearfix">
    
    		<div class="comment-author vcard"><?php child_commenter_link() ?></div>
    
    		<?php child_commentmeta(); ?>
    
    		<?php if ($comment->comment_approved == '0') _e("\t\t\t\t\t<span class='unapproved'>Your comment is awaiting moderation.</span>\n", 'thematic') ?>
    
    		<div class="comment-content">
    
    			<span class="speech-bubble"></span>
    
    			<?php comment_text() ?>
    
    			<?php // echo the comment reply link with help from Justin Tadlock http://justintadlock.com/ and Will Norris http://willnorris.com/
    
    			if($args['type'] == 'all' || get_comment_type() == 'comment') :
    			comment_reply_link(array_merge($args, array(
    			'reply_text' => __('Reply','thematic'),
    			'login_text' => __('Log in to reply.','thematic'),
    			'depth' => $depth,
    			'before' => '<div class="comment-reply-link">',
    			'after' => '</div>'
    
    			)));
    
    			endif;
    
    ?>
    
    	</div><!-- .comment-content -->
    
    	</div><!-- .comment-wrap clearfix-->
    
    <?php }
    
    // Produces an avatar image with the hCard-compliant photo class, and using my custom default
    
    function child_commenter_link() {
    
                  $commenter = get_comment_author_link();
    
                  if ( ereg( '<a[^>]* class=[^>]+>', $commenter ) ) {
    
                                $commenter = ereg_replace( '(<a[^>]* class=[\'"]?)', '\\1url ' , $commenter );
    
                  } else {
    
                                $commenter = ereg_replace( '(<a )/', '\\1class="url "' , $commenter );
    
                  }
    
                  $avatar_email = get_comment_author_email();
                  $avatar_size = apply_filters( 'avatar_size', '80' ); // Available filter: avatar_size
                  $avatar = get_avatar( $avatar_email, $avatar_size, THEME_URI . '/images/default_avatar.png' );
                  $avatar = str_replace( "class='avatar", "class='photo avatar", $avatar );
                  echo ' <span class="fn n">' . $commenter . '</span>' . $avatar ;
    
    } // end thematic_commenter_link
    
    function child_commentmeta() {
    
    	$content = '<div class="comment-meta">' .
    	sprintf( __('%1$s <br /> %2$s <br /> <a href="%3$s" title="Permalink to this comment">Permalink</a>', 'thematic' ),
    	get_comment_date('M d, Y'),
    	get_comment_time(),
    	'#comment-' . get_comment_ID() ) .
    	'</div>' . "\n";
    
    echo $content;
    
    }
    
    // end thematic_commentmeta
    
    function my_callback() {
        $content = 'type=comment&callback=child_comments';
        return $content;
    }
    
    add_filter('list_comments_arg', 'my_callback');
    Posted 4 years ago #
  4. Thanks so much, it worked great! Yes I would definitely love a simple filter for this.

    Posted 4 years ago #
  5. I submitted a request for a filter for default avatar and Chris provided me w/ the following simpler, more elegant code for default avatars

    if (!function_exists('t4u_avatar')) { function t4u_avatar($avatar_defaults) {
    $new_default_icon = get_bloginfo('stylesheet_directory') .'/images/default_avatar.png';
    $avatar_defaults[$new_default_icon] = 't4u';
    return $avatar_defaults;
    }
    add_filter( 'avatar_defaults' , 't4u_avatar' ); }

    now the default_avatar.png image will be called 't4u' and appear as an option for default avatars in the Discussion Settings of WP.

    Posted 4 years ago #
  6. you can also select the avatar at theme activation (as well as set any other options you'd like)

    // Change some options and redirect on activate
    if ( is_admin() && isset($_GET['activated'] ) && $pagenow == 'themes.php' ) {
    
    	//update default avatar
    	update_option( 'avatar_default', get_bloginfo('stylesheet_directory') .'/images/default_avatar.png');
    
    }
    Posted 4 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.