function coauthors__echo($tag, $type = 'tag', $separators = array(), $tag_args = null, $echo = true) { // Define the standard output separator. Constant support is for backwards compat. // @see https://github.com/danielbachhuber/Co-Authors-Plus/issues/12 $default_before = defined('COAUTHORS_DEFAULT_BEFORE') ? COAUTHORS_DEFAULT_BEFORE : ''; $default_between = defined('COAUTHORS_DEFAULT_BETWEEN') ? COAUTHORS_DEFAULT_BETWEEN : ', '; $default_between_last = defined('COAUTHORS_DEFAULT_BETWEEN_LAST') ? COAUTHORS_DEFAULT_BETWEEN_LAST : __(' and ', 'co-authors-plus'); $default_after = defined('COAUTHORS_DEFAULT_AFTER') ? COAUTHORS_DEFAULT_AFTER : ''; if (!isset($separators['before']) || $separators['before'] === NULL) { $separators['before'] = apply_filters('coauthors_default_before', $default_before); } if (!isset($separators['between']) || $separators['between'] === NULL) { $separators['between'] = apply_filters('coauthors_default_between', $default_between); } if (!isset($separators['betweenLast']) || $separators['betweenLast'] === NULL) { $separators['betweenLast'] = apply_filters('coauthors_default_between_last', $default_between_last); } if (!isset($separators['after']) || $separators['after'] === NULL) { $separators['after'] = apply_filters('coauthors_default_after', $default_after); } $output = ''; $i = new CoAuthorsIterator(); $output .= $separators['before']; $i->iterate(); do { $author_text = ''; if ($type == 'tag') { $author_text = $tag($tag_args); } elseif ($type == 'field' && isset($i->current_author->{$tag})) { $author_text = $i->current_author->{$tag}; } elseif ($type == 'callback' && is_callable($tag)) { $author_text = call_user_func($tag, $i->current_author); } // Fallback to user_login if we get something empty if (empty($author_text)) { $author_text = $i->current_author->user_login; } // Append separators if (!$i->is_first() && $i->count() > 2) { $output .= $separators['between']; } if ($i->is_last() && $i->count() > 1) { $output = rtrim($output, $separators['between']); $output .= $separators['betweenLast']; } $output .= $author_text; } while ($i->iterate()); $output .= $separators['after']; if ($echo) { echo $output; } return $output; }