Carbon_Fields\Field\Association_Field::get_title_by_type PHP Метод

get_title_by_type() публичный Метод

Can be overriden or extended by the carbon_relationship_title filter.
public get_title_by_type ( integer $id, string $type, string $subtype = '' ) : string
$id integer The database ID of the item.
$type string Item type (post, term, user, comment, or a custom one).
$subtype string The subtype - "page", "post", "category", etc.
Результат string $title The title of the item.
    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);
    }