Delete/trash associated post along with entry

Trash (or delete) post created by entry when an entry is trashed/deleted using GP Entry Blocks.

Code

Filename: gpeb-delete-associated-post-along-with-entry.php

<?php
/**
 * Gravity Perks // Entry Blocks // Delete/trash associated post along with entry
 *
 * Trash (or delete) post created by entry when an entry is trashed/deleted using GP Entry Blocks.
 *
 * https://gravitywiz.com/documentation/gravity-forms-entry-blocks/
 */
add_action( 'gpeb_trash_entry', function( $entry ) {
	$post_id = rgar( $entry, 'post_id' );

	if ( $post_id ) {
		wp_trash_post( $post_id );
	}
} );

add_action( 'gpeb_delete_entry', function( $entry ) {
	$post_id = rgar( $entry, 'post_id' );

	if ( $post_id ) {
		wp_delete_post( $post_id, true );
	}
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.