post_class()
echos so that’s you’re problem.
From the codex:
If you would prefer to have the post classes returned instead of echoed, you would want to use
get_post_class()
.
So just do this:
$the_post_classes = get_post_class( 'clearfix' );
$the_post_class_string = '';
foreach( $the_post_classes as $post_class ) {
$the_post_class_string .= $post_class . ' ';
}
$defaults = array (
'before' => 'article id="post-' .get_the_ID(). '"' .$the_post_class_string. 'role="main">',
// etc...
UPDATE: Sorry. I forgot this returns an array and not a string. You just need to iterate through the results before spitting them out. Code above is updated and tested.