wpmetabox / meta-box

The best plugin for WordPress custom fields and custom meta boxes
https://metabox.io
1.19k stars 423 forks source link

Meta Box Custom Table - Hook for replace List_Table #1593

Open giuliodelmastro opened 3 months ago

giuliodelmastro commented 3 months ago

Using the extension MB Custom table is currently not possible to replace the table List_Table. It would therefore be useful to have a hook to replace it with a custom.

rilwis commented 3 months ago

Thanks for your feedback.

Do you mean replacing the instance of the list table class with your own? Or ability to change the class name?

I'd love to hear more details on this. And what exactly do you need with that? Can't the current class satisfy the needs?

giuliodelmastro commented 1 month ago

Oh excuse me for the late answer! I really appreciate your interest!

I would like to replace the class instance with mine. This is possible in the core through the hook

apply_filters( 'wp_list_table_class_name', string $class_name, array $args )

But using custom templates instead of the classic post type this hook obviously doesn’t work anymore.

Your table has no problem on simple CRUD, but working on complex architectures or with a lot of logic becomes a little limiting and with a result "dirty" approach to customize it using hooks

rilwis commented 4 weeks ago

Hi @giuliodelmastro

Currently, the code to create an instance of list table class is this:

$this->list_table = new ListTable( [
    'model' => $this->model,
] );

I'm going to change it to:

$args = [ 
    'model' => $this->model,
];
$list_table = new ListTable( $args );
$this->list_table = apply_filters( 'mbct_list_table_object', $list_table, $args );

So this adds a filter to the object of the list table class (not the class name as in your code). This way, you can modify the object (create your own class, instantiate it and then pass to the filter).

Does that help you?

giuliodelmastro commented 4 weeks ago

Thank you!!! This is great news! Can I test it and give you feedback?

rilwis commented 3 weeks ago

Can you send me your email so I can send you the beta version?

giuliodelmastro commented 3 weeks ago

Sure. Check your mail, I send a message.

Thank you!!