codepress / admin-columns

Admin Columns allows you to manage and organize columns in the posts, users, comments, and media lists tables in the WordPress admin panel. Transform the WordPress admin screens into beautiful, clear overviews.
http://www.admincolumns.com
GNU General Public License v3.0
68 stars 26 forks source link

Is it possible to add a filter for unsupported value columns? #403

Open andruxnet opened 6 months ago

andruxnet commented 6 months ago

I have a custom ACF field that represents a MongoDB object. In the Admin Columns UI I can add the column for this field, but it renders as "Unsupported value format". I was looking for a hook that would let me manipulate this $value before it being rendered (like grabbing a Mongo object property), but couldn't find a way.

It would be very helpful if the Unsupported column class would filter the value before returning.. something like this:

class Unsupported extends Column {

    public function get_value( $id ) {
        $value = get_field( $this->get_meta_key(), $id );

        // new filter to try and parse the unsupported value before giving up with the "unsupported format" message
        $value = apply_filters( 'ac/column/unsupported_value', $value, $id, $this );

        return is_scalar( $value ) ? (string) $value : __( 'Unsupported value format', 'codepress-admin-columns' );
    }

...

}

Then, we could use it like this:

  add_filter( 'ac/column/unsupported_value', function( $value, $id, $column ) {
    if ($value instanceof \MongoDB\Model\BSONDocument) {
      return $value->title;
    }

    return $value;
  }, 10, 3 );

Any chance this change is included in the plugin?

Thanks.