/**
  * Create a term field instance.
  *
  * @param string $field_slug Slug of existing field definition.
  * @param int $term_id ID of the term where the field belongs.
  *
  * @return null|WPCF_Field_Instance Field instance or null if an error occurs.
  * @since 1.9
  */
 public static function create_term_field_instance($field_slug, $term_id)
 {
     try {
         return new WPCF_Field_Instance(WPCF_Field_Term_Definition_Factory::load($field_slug), $term_id);
     } catch (Exception $e) {
         return null;
     }
 }
 /**
  * Render single cell in a term listing table.
  *
  * Catch field columns by their name prefix and render field values with preview renderer.
  *
  * @param mixed $value ""
  * @param string $column_name
  * @param int $term_id
  * @link https://make.wordpress.org/docs/plugin-developer-handbook/10-plugin-components/custom-list-table-columns/
  * @return string Rendered HTML with the table cell content.
  * @since 1.9.1
  */
 public function manage_term_listing_cell($value, $column_name, $term_id)
 {
     // Deal only with our custom columns.
     $is_term_field_cell = substr($column_name, 0, strlen(self::LISTING_COLUMN_PREFIX)) == self::LISTING_COLUMN_PREFIX;
     if ($is_term_field_cell) {
         try {
             $field_slug = substr($column_name, strlen(self::LISTING_COLUMN_PREFIX));
             $field_definition = WPCF_Field_Term_Definition_Factory::load($field_slug);
             $field = new WPCF_Field_Instance_Term($field_definition, $term_id);
             $renderer_args = array('maximum_item_count' => 5, 'maximum_item_length' => 30, 'maximum_total_length' => 100);
             $renderer = WPCF_Field_Renderer_Factory::get_instance()->create_preview_renderer($field, $renderer_args);
             $value = $renderer->render();
         } catch (Exception $e) {
             // Do nothing when we're unable to load the field.
         }
     }
     return $value;
 }