Delete Descendant Galleries Automatically
If you have created a hierarchy of sub galleries in Sunshine, you may want to delete all child galleries if you delete the top most level gallery. This does not happen by default in WordPress (thus Sunshine). In this code snippet, you can have all child and descendant galleries deleted as well.
add_action( 'wp_trash_post', 'sunshine_trash_descendant_galleries' );
function sunshine_trash_descendant_galleries( $post_id ) {
if ( get_post_type( $post_id ) !== 'sunshine-gallery' ) {
return;
}
static $is_trashing = false;
if ( $is_trashing ) {
return;
}
$is_trashing = true;
$descendant_ids = sunshine_get_gallery_descendant_ids( $post_id );
if ( ! empty( $descendant_ids ) && is_array( $descendant_ids ) ) {
foreach ( $descendant_ids as $descendant_id ) {
wp_trash_post( $descendant_id );
}
}
$is_trashing = false;
}
Learn how to add this custom code to your WordPress website
Still need help?
If you have not yet found your answer in the documentation articles, please contact support