Skip Navigation

[Resolved] custom hook for removing Toolset defined post types

This support ticket is created 3 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 3 replies, has 3 voices.

Last updated by Jamal 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#2094517

in our site we are hooking into the register_post_type function to execute code for each of our custom post types, and then we want to undo that code when removing a custom post type via the Toolset UI but Toolset doesn't seem to execute the unregister_post_type action when removing a custom post type. Can you please share any insights on how we can execute code when a custom post type is removed via the Toolset UI? Thanks in advance!

#2096137

Good afternoon,

Just wanted to follow up on this question we had - thanks!

#2096901

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there,

Jamal doesn't work Weds/Thurs, so let me jump in and answer you directly.

There isn't an action equivalent to delete_post_type fired by Types when a post type is deleted.

But looking at the source code, I did spot a filter that is applied during the process of deleting a post type which I think should serve your needs.

This is a filter rather than an action, and so needs to return the first parameter.

In this case I simply dumped the second parameter to the log to check what it contains, and it is a string with the slug of the post type being deleted.

add_filter( 'wpcf_delete_relation_meta', 'ts_on_delete_post_type', 10, 2 );
function ts_on_delete_post_type( $bool, $post_type ){

	error_log('post_type: ' . print_r($post_type, true));

	return $bool;
}

If that works for you, please go ahead and mark this as resolved, thanks.

#2099099

Hello again, I wonder if you had the time to check Nigel's reply! Please let us know if it suits your use case.

Otherwise, please provide more details on your use case. You explained that your hook makes sure there is an entry for each custom post type in a repeating field group. Can you provide more details, or share the custom code you use. I am setting your next reply as private in case you don't want the code to be public. Just enter fake credentials to validate the form.