Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta Box Custom Table - Hook for replace List_Table #1593

Open
giuliodelmastro opened this issue Jul 2, 2024 · 6 comments
Open

Meta Box Custom Table - Hook for replace List_Table #1593

giuliodelmastro opened this issue Jul 2, 2024 · 6 comments

Comments

@giuliodelmastro
Copy link

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
Copy link
Member

rilwis commented Jul 3, 2024

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
Copy link
Author

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
Copy link
Member

rilwis commented Sep 7, 2024

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
Copy link
Author

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

@rilwis
Copy link
Member

rilwis commented Sep 9, 2024

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

@giuliodelmastro
Copy link
Author

Sure. Check your mail, I send a message.

Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants