public function get_title_by_type($id, $type, $subtype = '')
{
$title = '';
if ($type === 'post') {
$title = get_the_title($id);
} elseif ($type === 'term') {
$term = get_term_by('id', $id, $subtype);
$title = $term->name;
} elseif ($type === 'user') {
$title = get_the_author_meta('user_login', $id);
} elseif ($type === 'comment') {
$title = get_comment_text($id);
$max = apply_filters('carbon_relationship_comment_length', 30, $this->get_name());
if (strlen($title) > $max) {
$title = substr($title, 0, $max) . '...';
}
}
if (!$title) {
$title = '(no title) - ID: ' . $id;
}
/**
* Filter the title of the relationship item.
*
* @param string $title The unfiltered item title.
* @param string $name Name of the relationship field.
* @param int $id The database ID of the item.
* @param string $type Item type (post, term, user, comment, or a custom one).
* @param string $subtype Subtype - "page", "post", "category", etc.
*/
return apply_filters('carbon_relationship_title', $title, $this->get_name(), $id, $type, $subtype);
}